Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
plugin: download discussion in PDF
Hello, I need to create a plugin to allow download discussions and comments in pdf format, to create it I'll use a library called DOMPDF, this library allows you to convert HTML to PDF ... so I need to find the ID of the discussion, I am a beginner developer and still do not understand how the tree of classes, if they have more documentation on this part I would greatly appreciate if they can share...
0
Best Answers
-
x00 MVPYou can already request the discussions in various formats, like rss, xml, json, etc in a RESTful (ish) way. So I would extend this for pdf.
Presumably you will want to provide the links on the discussions list, as well one on the discussion?
If you are a total novice programmer it might be a bit of a learning curve.grep is your friend.
0 -
AFN NewThe U.S. Army's forum does allow people to save the discussion in PDF . I wonder if they are using Vanilla forums because theirs looks very similar. I think I will contact them and ask.
A temporary fix, you might want to see http://pdf-ace.com and you can enable a button. The only down side is they put a watermark on the PDF file, and it make the whole page in PDF including the background(s) logo(s), but if you do not mind having a small watermark and it saving everything than that would be a good temporary fix.
But still that would be a cool plugin.0 -
x00 MVPthese are equivalent:
http://vanillaforums.org/discussion.xml?DiscussionID=13789
http://vanillaforums.org/discussion.xml/3789/
so you will have
http://vanillaforums.org/discussion.pdf/13789/some+title
Although you could allow
http://vanillaforums.org/discussion/13789/some+title.pdf
this will give you a rough idea but I'm not doing all the work for you.<?php $PluginInfo['DiscussionPDF'] = array( 'Name' => 'DiscussionPDF', 'Description' => "DiscussionPDF", 'Version' => '0.1', 'Author' => 'me' ); define('DELIVERY_METHOD_PDF', 'PDF'); require_once( dirname(__FILE__)."/dompdf/dompdf_config.inc.php"); class DiscussionPDF extends Gdn_Plugin { public function DiscussionController_Render_Before(&$Sender){ $Path = explode('/',$Sender->Request->Path()); if(substr_compare($Sender->RequestArgs[1],'.pdf',-4,4,true)===0 || substr_compare($Path[0],'.pdf',-4,4,true)===0){ $Sender->DeliveryMethod(DELIVERY_METHOD_PDF); } if($Sender->DeliveryMethod()==DELIVERY_METHOD_PDF){ if(substr_compare($Sender->RequestArgs[1],'.pdf',-4,4,true)===0 ){ $FileName = $Sender->RequestArgs[1]; }else{ $FileName = $Sender->RequestArgs[1].'.pdf'; } $Output =''.$Sender->Data['Discussion']->Name.''; $Output .=''.$Sender->Data['Discussion']->Body.''; $Output .=''; foreach ($Sender->CommentData->Result() As $Comment){ $Output .=''.$Comment->Body.''; } $dompdf = new DOMPDF(); $dompdf->load_html($Output); $dompdf->render(); $dompdf->stream($FileName); exit; } } }
You can use var_dump($Sender->Data['Discussion']); and var_dump($Comment); to see what data is available to put in the pdf.
Use eventi plugin to see which hooks to use to add the Anchor, and or look in other plugins for help. Obviously use DOMPDF docs as well.
I would also look into caching as this is moderate overhead.grep is your friend.
0
Answers
Presumably you will want to provide the links on the discussions list, as well one on the discussion?
If you are a total novice programmer it might be a bit of a learning curve.
grep is your friend.
how to request in xml?
http://localhost/acane/index.php?p=/discussion/3/seguridad-en-los-puertos-vty#Item_1
in API appears like that...
http://vanillaforums.org/discussion.xml?DiscussionID=13789
but in my server only the title
A temporary fix, you might want to see http://pdf-ace.com and you can enable a button. The only down side is they put a watermark on the PDF file, and it make the whole page in PDF including the background(s) logo(s), but if you do not mind having a small watermark and it saving everything than that would be a good temporary fix.
But still that would be a cool plugin.
http://vanillaforums.org/discussion.xml?DiscussionID=13789
http://vanillaforums.org/discussion.xml/3789/
so you will have
http://vanillaforums.org/discussion.pdf/13789/some+title
Although you could allow
http://vanillaforums.org/discussion/13789/some+title.pdf
this will give you a rough idea but I'm not doing all the work for you.
<?php $PluginInfo['DiscussionPDF'] = array( 'Name' => 'DiscussionPDF', 'Description' => "DiscussionPDF", 'Version' => '0.1', 'Author' => 'me' ); define('DELIVERY_METHOD_PDF', 'PDF'); require_once( dirname(__FILE__)."/dompdf/dompdf_config.inc.php"); class DiscussionPDF extends Gdn_Plugin { public function DiscussionController_Render_Before(&$Sender){ $Path = explode('/',$Sender->Request->Path()); if(substr_compare($Sender->RequestArgs[1],'.pdf',-4,4,true)===0 || substr_compare($Path[0],'.pdf',-4,4,true)===0){ $Sender->DeliveryMethod(DELIVERY_METHOD_PDF); } if($Sender->DeliveryMethod()==DELIVERY_METHOD_PDF){ if(substr_compare($Sender->RequestArgs[1],'.pdf',-4,4,true)===0 ){ $FileName = $Sender->RequestArgs[1]; }else{ $FileName = $Sender->RequestArgs[1].'.pdf'; } $Output =''.$Sender->Data['Discussion']->Name.''; $Output .=''.$Sender->Data['Discussion']->Body.''; $Output .=''; foreach ($Sender->CommentData->Result() As $Comment){ $Output .=''.$Comment->Body.''; } $dompdf = new DOMPDF(); $dompdf->load_html($Output); $dompdf->render(); $dompdf->stream($FileName); exit; } } }
You can use var_dump($Sender->Data['Discussion']); and var_dump($Comment); to see what data is available to put in the pdf.
Use eventi plugin to see which hooks to use to add the Anchor, and or look in other plugins for help. Obviously use DOMPDF docs as well.
I would also look into caching as this is moderate overhead.
grep is your friend.
I have no idea how to go about creating a php file that makes PDFs and getting it to work.
Can you please explain what you mean by:
Basically I'm lost.
@AFN I don't have the time to provide programming lessons. This is beyond what is expected with Q&A.
If you are interested in sponsoring me, to provide a proper PDF plugin with caching, some sort of easy template system and all the rest of it I'm sure others would be grateful. Perhaps @maga and anyone else interested would like to provide their share.
grep is your friend.
What do you mean by sponsoring you? You mean voting for you and the plugin? If so I would vote and sponsor you.
I mean pay for my time. If you are interested, then you can pay for me to develop it. Then afterwards anyone is free to enjoy.
grep is your friend.
If I was to pay for your time in developing it, what would you use for the payment transaction? Would you use PayPal? Also how much would you be asking for?
They are called ransom plugin: x00 program the software and release it when sufficient donations are collected. Usually they are refunded if the software is not published.
PayPal is very popular but I remind a specific site for ransom plugin: unfortunately I can't remember the url... Anyone?
@AFN 60GBP would be a fair price. For that I'd provide the PDF conversion infrastructure, caching to economise overhead, and a template system similar to the current one used for views.
Paypal is fine. I can send an invoice.
@candyman I have not heard that term, but I plan to set up something similar. Escrow account adjudication would honour the work.
grep is your friend.
I do apologies, but paying 60GBP witch is 93.82 USDs is a little to high for me, nor would I be able to afford it. If it was something in the 30's than I would be more open to even take about money.