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

edited October 2011 in Vanilla 2.0 - 2.8
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...
Tagged:

Best Answers

  • x00x00 MVP
    edited October 2011 Answer ✓
    You 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.

  • AFNAFN New
    edited October 2011 Answer ✓
    The 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.
  • x00x00 MVP
    edited October 2011 Answer ✓
    these 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.

Answers

  • x00x00 MVP
    edited October 2011 Answer ✓
    You 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.

  • yes i want to provide the links on the discussions list or one discussion, but i need to find the object or class that return ID...

    how to request in xml?
  • AFNAFN New
    edited October 2011 Answer ✓
    The 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.
  • thanks @AFN but i'll try to do!!
  • x00x00 MVP
    edited October 2011 Answer ✓
    these 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.

  • @00 thank you! I'll try :D
  • AFNAFN New
    edited December 2011

    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:

    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.

    Basically I'm lost.

  • x00x00 MVP
    edited December 2011

    @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.

  • AFNAFN New
    edited December 2011

    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?

  • candymancandyman ✭✭
    edited December 2011

    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?

  • x00x00 MVP
    edited December 2011

    @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.

  • AFNAFN New
    edited December 2011

    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.

Sign In or Register to comment.