summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoao Ventura2008-12-08 15:09:55 (GMT)
committer Joao Ventura2008-12-08 15:09:55 (GMT)
commit6814740abd24a49245a4e3a2a770850550d2cb81 (patch)
tree847577a8e9f8f4c6c3f358cf211e2584290984d8
parentb88aa72102e07232e1751eb768e4ab9c059ac70e (diff)
Fix #344036 by eMPee584: generated PDF filename configurable via tokens (requires the token module)
-rw-r--r--print_pdf/print_pdf.admin.inc25
-rw-r--r--print_pdf/print_pdf.install1
-rw-r--r--print_pdf/print_pdf.module1
-rw-r--r--print_pdf/print_pdf.pages.inc11
4 files changed, 36 insertions, 2 deletions
diff --git a/print_pdf/print_pdf.admin.inc b/print_pdf/print_pdf.admin.inc
index 2a74628..ae38137 100644
--- a/print_pdf/print_pdf.admin.inc
+++ b/print_pdf/print_pdf.admin.inc
@@ -168,6 +168,31 @@ function print_pdf_settings() {
'#maxlength' => 3,
'#description' => t('(TCPDF only) Set the font size to be used for normal text. This is the base value for the scaling applied to other text styles.'),
);
+ if (module_exists('token')) {
+ $form['settings']['print_pdf_filename'] = array(
+ '#type' => 'textfield',
+ '#title' => t('PDF File Name'),
+ '#default_value' => variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT),
+ '#description' => t("If left empty the generated filename defaults to the node's path. Tokens may be used to build the filename (see following list). The .pdf extension will be appended automatically."),
+ );
+ $form['settings']['print_pdf_filename_patterns'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Replacement Patterns'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $descriptions = '';
+ $tokens = token_get_list('node');
+ foreach ($tokens as $token) {
+ foreach ($token as $key => $val) {
+ $descriptions .= '<dt>['. $key .']</dt><dd>'. $val ."</dd>\n";
+ }
+ }
+ $form['settings']['print_pdf_filename_patterns']['descriptions'] = array(
+ '#type' => 'markup',
+ '#value' => "<dl>\n". $descriptions ."</dl>\n",
+ );
+ }
$form['#validate']['_print_pdf_settings_validate'] = array();
}
else {
diff --git a/print_pdf/print_pdf.install b/print_pdf/print_pdf.install
index 5ea3825..f71dd78 100644
--- a/print_pdf/print_pdf.install
+++ b/print_pdf/print_pdf.install
@@ -69,6 +69,7 @@ function print_pdf_uninstall() {
variable_del('print_pdf_font_size');
variable_del('print_pdf_link_text');
variable_del('print_pdf_link_use_alias');
+ variable_del('print_pdf_filename');
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_pdf\_display\_%'");
while ($variable = db_fetch_object($settings)) {
variable_del($variable->name);
diff --git a/print_pdf/print_pdf.module b/print_pdf/print_pdf.module
index e31e1ba..f187b2e 100644
--- a/print_pdf/print_pdf.module
+++ b/print_pdf/print_pdf.module
@@ -28,6 +28,7 @@ define('PRINT_PDF_PAPER_SIZE_DEFAULT', 'A4');
define('PRINT_PDF_PAGE_ORIENTATION_DEFAULT', 'portrait');
define('PRINT_PDF_FONT_FAMILY_DEFAULT', 'dejavusans');
define('PRINT_PDF_FONT_SIZE_DEFAULT', 10);
+define('PRINT_PDF_FILENAME_DEFAULT', '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]');
/**
* Implementation of hook_init().
diff --git a/print_pdf/print_pdf.pages.inc b/print_pdf/print_pdf.pages.inc
index 339bc95..d1e4655 100644
--- a/print_pdf/print_pdf.pages.inc
+++ b/print_pdf/print_pdf.pages.inc
@@ -55,11 +55,18 @@ function print_pdf_controller() {
$html = ob_get_contents();
ob_end_clean();
+ $pdf_filename = variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT);
+ if (function_exists('token_replace') && !empty($pdf_filename)) {
+ $pdf_filename = token_replace($pdf_filename, 'node', $node) .'.pdf';
+ }
+ else {
+ $pdf_filename = str_replace('/', '_', $path) .'.pdf';
+ }
if (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
- _print_pdf_dompdf($print, $html, $path .'.pdf');
+ _print_pdf_dompdf($print, $html, $pdf_filename);
}
elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
- _print_pdf_tcpdf($print, $html, $path .'.pdf');
+ _print_pdf_tcpdf($print, $html, $pdf_filename);
}
else {
return drupal_not_found();