Page 1 of 1

Suggested Feature - Article PDF File Name

Posted: 21 Aug 2009, 20:28
by big-pete
Currently, the plgSystemPhocaPDFContent plug-in defaults to a PDF filename of 'Phoca PDF' if the plug-in parameter 'PDF Name:' (as set in the back-end component) is left blank. This is set on line 125 of the \plugins\system\phocapdfcontent.php file:

Code: Select all

$content->pdf_name = $pluginP->get('pdf_name', 'Phoca PDF');
While this works I would suggest that it would make more sense for the $content->pdf_name to be set to the title of the article itself IF the 'PDF Name:' parameter is left blank. i.e. An article titled 'My Favorite Things' would get a $content->pdf_name of something like 'my-favorite-things.pdf'. In my case I'd prefer users to download PDF documents with file names that make it somewhat clear (for later recall) what it is.

An additional parameter of 'Use Article Title for File Name' could be included in the backed if that sort of default behavior is not to Phoca's liking. FWIW, I was able to implement this behavior with a simple code change (use at your own risk):

File: \libraries\joomla\document\phocapdf\phocapdf.php
Line: 142
Change:

Code: Select all

switch ($option) {
  case 'com_content':

    $results = $dispatcher->trigger('onBeforeDisplayPDFContent', array (&$pdf, &$content, &$this));

    break;
To:

Code: Select all

switch ($option) {
  case 'com_content':

    $results = $dispatcher->trigger('onBeforeDisplayPDFContent', array (&$pdf, &$content, &$this));
    if($content->pdf_name == 'Phoca PDF') $content->pdf_name = $this->getName();

    break;
NOTE: I've also change the setName function in the \libraries\joomla\document\phocapdf\phocapdf.php to:

Code: Select all

function setName($name = 'Phoca') {
  $this->_name = JString::strtolower(JFile::makeSafe(JString::str_ireplace(' ', '-', $name)));
}
so as to attempt to eliminate any wacky characters that might be in the article Title.

While this may not be the absolute best way to go about it (you guys know your code much better than I do) I think implementing something like this would be quite easy and potentially improve the product. Thanks for listening.

PS: Almost forget: Sticking on a '.pdf' file extension to the $content->pdf_name probably wouldn't hurt as well but not sure it's absolutely necessary.

Re: Suggested Feature - Article PDF File Name

Posted: 21 Aug 2009, 23:27
by Jan
Hi, thank you for this info, the problem can be diacritics in article names, so then it should be alias used (As aliases have problems with diacritics - not correctly translated diacritics). I will take a look at it.

Jan

Re: Suggested Feature - Article PDF File Name

Posted: 22 Aug 2009, 02:18
by big-pete
Jan, no problem. As a side note it seems most joomla components use the following to make safe aliases:

Code: Select all

$this->alias = JFilterOutput::stringURLSafe($this->alias);
In the end changing the setName function to apply this function (as well as any others you feel warranted might be the trick. Good luck and thanks for a great product!

Pete

PS: I've changed my various setName functions to now use the JFilterOutput::stringURLSafe method instead of what I posted earlier. Eat my own dog food so to speak. :wink:

Re: Suggested Feature - Article PDF File Name

Posted: 02 Dec 2009, 16:06
by Jan
Hi, there is a problem with the $this->getName(), It seems like the name is not allways loaded, so then the name is empty. So because of it the "Phoca PDF" name is added instead of empty name :(

Re: Suggested Feature - Article PDF File Name

Posted: 24 Jun 2011, 17:46
by motofzr1000
Hi,

I've implemented this code, and it seems to work.
However, it only works for me with the direct download option enabled.
When I open the pdf in a popup window, and try to save the pdf, it's called index.pdf, and not the article title.
Is there a way to get this to work with a popup window also?

Re: Suggested Feature - Article PDF File Name

Posted: 29 Jun 2011, 23:38
by Jan
Hi, index.php is set by the PDF plugin in OS, this cannot be changed :-(

Jan

Re: Suggested Feature - Article PDF File Name

Posted: 30 May 2013, 20:25
by hamss
Hi,

there is no \libraries\joomla\document\phocapdf\phocapdf.php in J2.5 / PhocaPDF 2.0.7 any more.
Is there any possibility to implement this to the new one?

I would be greateful if sb could help me.
Regards

Re: Suggested Feature - Article PDF File Name

Posted: 07 Jun 2013, 14:23
by Jan
Hi, then just ftp it again (get in the installation ZIP file)

Jan