Jump to content

Can

Members
  • Posts

    350
  • Joined

  • Last visited

Everything posted by Can

  1. Wow, just checked those examples on github. they're looking really good..maybe I'll change my custom mpdf thing to your wirepdf. But I'm doing screencasts for the customer and we're going live pretty soon, so no time right now.. nice work again wanze headsup
  2. It's discussed over here https://processwire.com/talk/topic/5286-switching-fields-to-language-fields-produces-fatal-errors/ I'm just editing the database in Adminer (PHPMyAdmin or any other db tool will do it) table for the field and add a cell 'data1027'. Then I reload the page with errors and everything's fine
  3. Just implemented tags as well and thought about showing 5 top pages of each tag directly on the tag page So for anyone stumbling across this thread and is curious how this could work. And to extend the code snippets in this forum <?php $content = ''; foreach($tags = $pages->find("parent={$page->id},limit=30") as $t) { $content .= "<h2><a href='{$t->url}'>{$t->title}</a></h2> <strong>5 Top Pages with tag '{$t->title}'</strong> <ul class='tags'>"; foreach($pages->find("tags.title={$t->title},sort=pageviews,limit=5") as $p){ $content .= "<li><a href='{$p->url}'>{$p->title}</a></li>"; } $content .= "</ul>"; } $content .= $tags->renderPager(); this comes into tags.php assuming your tag field is called tags and you have an pageview counter (as discussed here) called pageviews
  4. Don't needed images so far, so can't help you with this one. But have you checked out this one http://mpdf1.com/manual/index.php?tid=245 scroll a bit down to Float and Text wrapping. maybe it helps
  5. I'm really glad it helped you muzzer
  6. Can

    Bookmarking

    this is awesome! made something like this couple of weeks ago myself but it's really basic at the moment I made a little JS bookmarklet for sharing things to PW but jealous for your chrome app main thing why I stopped is because I need to have a simple sharing option from my mobile (android) was just looking for a wrapper app or something because I'm not going to start digging into app programming at the moment Probably I'll just use the bookmarklet on mobile as well Ah I made the sharer saving the bookmark directly when calling it, so the window is more for editing and deletion if needed thought it's faster, like pressing the star in Chrome
  7. Thank you Gerhard, really fast As I mentioned I changed it a bit for this tut and missed this one, thanks to you it's corrected I would like to know how it works for you in the end, so hopefully your customer likes the feature
  8. Here you go Macrura https://processwire.com/talk/topic/7025-how-to-create-pdfs-with-pw-and-mpdf/ Any tips are highly appreciated
  9. Hey guys, got asked to share how to set up mpdf with processwire so it's time to make a little tutorial Disclaimer: ( ) This is my first tutorial and I'm not a real coder yet so every tips and hints are highly appreciated Grab a copy of mPDF unzip it and put it in a nice place outside of your Processwire folder(s) - (as far as I remember is has to be outside or within a module to work, but I could be wrong?!) Open the template from which you want to create the PDF from In my case I have a "course.php" which is showing a page with a weekly schedule table and I wanted to provide this schedule as pdf next to the website version. I turned on urlSegments for "course" template, because I find it nicer than a get variable Then in my course.php template file after the normal website output I added the following It's probably better to have this logic at the very top of the template file to prevent unnecessary code execution right?? Aha, now I remember why it's at the bottom. I have some more logic above it which I wanted to share for browser output and pdf creation and this was the easiest way, probably I'll rearrange everything to make it faster At least the if( file_exists logic could go at the very top <?php // In case you don't have other urlSegments it's better to throw a 404 when someone types a non existing url, // could be managed better but at the moment it's easier if($input->urlSegment1 && $sanitizer->pageName($input->urlSegment1) != 'pdf') throw new Wire404Exception(); // if urlSegment /pdf/ output course table as PDF file if($sanitizer->pageName($input->urlSegment1) === 'pdf') { // $config->paths->files = PWs /assets/files/ folder, page ID and the title of the page could be any field or anything else // maybe you want to add the date $pdfPath = $config->paths->files . $page->id . "/" . $page->title.'.pdf'; // Options for wireSendFile because they're needed more then once $wireSendOptions = array('exit' => true, 'forceDownload' => true, 'downloadFilename' => ''); // If file already exists force download it and stop further execution which is handled $wireSendOptions 'exit' => true if(file_exists( $pdfPath )) wireSendFile($config->paths->files . $page->id . "/" . $headline.'.pdf', $wireSendOptions ); // include mPDF.php conditionally for localhost and productive website, you probably don't need it if structure is the same // included it at this point because we don't need it to provide an existing file // you could even include it after your output logic just before PDF creation.. if($config->httpHost == 'localhost') { include("../../../../classes/MPDF57/mpdf.php") } else { include("../../../classes/MPDF57/mpdf.php"); } // at this point you create the logic for your output // I'm not sure wether mPDF understands single 'quotes' properly // TCPDF doesn't really liked them so I stick to double "quotes" for now // just a little example how it might look you can of course have a loop populate everything from $page or somewhere else ;-) $pdfOutput = '<table class="data"> <tr> <th>Entry Header 1</th> <th>Entry Header 2</th> <th>Entry Header 3</th> <th>Entry Header 4</th> </tr> <tr> <td>Entry First Line 1</td> <td>Entry First Line 2</td> <td>Entry First Line 3</td> <td>Entry First Line 4</td> </tr> <tr> <td>Entry Line 1</td> <td>Entry Line 2</td> <td>Entry Line 3</td> <td>Entry Line 4</td> </tr> <tr> <td>Entry Last Line 1</td> <td>Entry Last Line 2</td> <td>Entry Last Line 3</td> <td>Entry Last Line 4</td> </tr> </table>'; // now the best part // the next comment explains the mPDF() parameters as in the manual http://mpdf1.com/manual/index.php?tid=184 // mode, format, default_font_size, default_font, margin_left, margin_right, // margin_top, margin_bottom, margin_header, margin_footer, orientation $mpdf = new mPDF('utf-8','A4-L', 0, '', 5, 5, 16, 6, 5, 5, 'L'); // The header is repeated on all pages, it's possibly to have different headers (even/odd) and other fancy stuff // You can have images as well, just have a look at the documentation it's pretty good $mpdf->SetHTMLHeader("<h2>{$page->title}</h2>"); // this one puts your table, created above, into the file $mpdf->WriteHTML($pdfOutput); // I'm saving the PDF file to the disc first as set in line 9 // 'D' would output the file inline in the browser window but then we're not able to store it for faster serving $mpdf->Output($pdfPath,'F'); // Thanks to Ryan and his nice functions we can use wireSendFile (as above) to get the created file and force download it wireSendFile($pdfPath, $wireSendOptions ); } // End if /pdf/ If you want to create the file everytime it's called and don't want the it to get stored just strip line 12, 15 and 67 and change the 'F' in line 64 to 'D' If you want to have a newly created file each time you change the page you have to install a little module to hookAfter page save It's just one file, I called it like hooks.module because maybe I will add some hooks later and there is no need to have each hook in a separate module. <?php class Hooks extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Custom Hooks', 'summary' => 'Hooks, PDF deletion on page save for example', 'version' => 1, 'autoload' => true, // You want it to autoload, otherwise it would never get called ); } public function init() { $this->pages->addHookAfter('save', $this, 'deletePDF'); //initialise the hook } // Most of it is just copied from Pages2PDF module from Wanze, a little 'simplified' though^^ public function deletePDF(HookEvent $event) { $page = $event->arguments[0]; $pdf = wire('config')->paths->files . $page->id . "/" . $page->title.'.pdf'; if (file_exists($pdf) && is_file($pdf)) { $name = $page->title.'.pdf'; if (@unlink($pdf)) { $this->message($this->_(sprintf("The following file got deleted '%s'", $name))); } else { $this->error($this->_(sprintf("Failed to delete '%s'", $name))); } } } } Hope you can follow the steps. Please let me know if not and why Any improvements are welcome because I would love to learn more as well
  10. <ashamed> Still didn't got it </ashamed> tried to throw a 404 if urlSegment1 isn't pdf as mentioned when activating urlSegments if($input->urlSegment1 && $sanitizer->pageName($input->urlSegment1) != 'pdf') throw new Wire404Exception(); tried in _init.php, _main.php and in the page template as well nothing works It says "Fatal error: Cannot redeclare myFancyFunctions() .." Update: changed "include("./includes/functions.php");" to "include_once("./includes/functions.php");" seems to work Or is there anything I'm missing or a better way?
  11. what do you mean by "without having to actually separate them?" Don't really get what you're trying to achieve
  12. @benbyf it worked for me, but I had to change the field in the settings everytime I changed any setting. once set it works. By the way I just changed to mpdf without any module and it's working really great really easy to set up file caching is the only thing missing at the moment. but that shouldn't be too hard, maybe I'll can dig into pages2pdf and "copy" this part or something
  13. Already liked your post but wanted to thank you in person diogo Made a little gist mainly for my private archive and added few lines to auto delete all fields matching the given selector. https://gist.github.com/CanRau/d92ed6baaa84d305bca1
  14. Thanks to you Horst it's not needed anymore right
  15. Thanks for clarification Horst It's actually not transparent, at least not visible though. Of course this line wouldn't be there without purpose hehe But as I'm not having any other gifs at the moment I'll leave it commented for now.
  16. @purwa do you added the textformatter to your textfield? http://wiki.processwire.com/index.php/Text_Formatters#Adding_text_formatters_to_fields if you'd done this already maybe another formatter disturbs it, then try rearranging them
  17. Got another thing Just tried to upload an animated gif. First it's not uploading properly, means the bar stays at 100% and will not go further until saving the page. The gif is then showing correctly but I get an error at the very top of the page Warning: imagecolorsforindex(): Color index 126 out of range in /Users/admin/Can/htdocs/processwire/yogalounge/wire/core/ImageSizer.php on line 279 Warning: imagecolorsforindex(): Color index 126 out of range in /Users/admin/Can/htdocs/processwire/yogalounge/wire/core/ImageSizer.php on line 279 Just commented the line out and it's working 279: //$transparentColor = $transparentIndex != -1 ? ImageColorsForIndex($image, $transparentIndex) : 0; Created a normal image field (without CropImage) without this error. At the moment everything seems to be fine with this hacky fix, but I don't even know what this line is doing.. By the way, still got my weird cropping issue :/
  18. Wished I could just count.images or images.count or something but you made my day Horst!
  19. Pete, in this case you could include a file conditionally like with the "head-dev.inc" diogo mentioned so your changing the main template only once oh, pretty old here..but maybe still helpful for someone
  20. Think you could make your own little "cart" just a littly form with a hidden field for storing the page->id or if this form is on the same page you want to add to the cart you don't even need the hidden field. if($input->post->addtocart && !$cart) { $cart = new Page(); $cart->parent = $pages->get(5771); $cart->template = 'cart'; $cart->title = 'session_id()'; //for example $cart->save(); $cart->of(false); $cart->items = $pages->id; //not a hundred percent sure right now but should work (think I've done it like this already) } } items field would be multi page fieldtype you would then include this "$modules->get('Pages2Pdf')->render();" into the page template you want to generate the pdf's from on the cart page you add a link for the customer, think it should work when you just link to one of the pages and append ?pdf=1 to the url, which will then create the pdf create a new template under /templates/pages2pdf/ with the same name as the template you put the "$modules->get('Pages2Pdf')->render();" in in this template you iterate through the pages in the cart like you would on a blog page or similar and output everything you need for me the final output worked only with heredoc syntax, seems that proper double quotes are needed by tcpdf (you could echo as "normal" but then you would need to escape the double quotes) hoffe es ist einigermaßen verständlich und klappt (hope it's understandable and works)
  21. Should be possible to have it like a search, kind off. You store selected pages via page field in the cart and then in the pdf template you iterate through them and output as pdf just ask if you need more help
  22. good to know about the cleaning thank you It starts a session for every visitor, so at the moment I think it's not worse than the counter discussed in this thread ? It's tracking bots as well, but this could be filtered out.. what ever, maybe I'm wrong, but at the moment it's nice to know. at least for me
  23. got a little question on this. how about counting the session table entries/id's? like so echo $db->query("SELECT id FROM sessions")->num_rows For now I´m doing it only in admin dashboard to have a clue what's going on How about using this on frontpage? Probably it's not the best to "count" everytime? Is there any "auto" deletion of expired/old session data going on somewhere in PW? Ah, the JS based counter is nice of course, but is there any reason to prefer template cache over markup cache? So I could markup cache any part I want to cache and everything else can still do it's job.
  24. yeah pdf generation seems to be kind of 1980. it probably get's better after wanze's update do you created a page specific template under /templates/pages2pdf/ ? it was important for me and and hat to tweak a lot I'm outputting only via heredoc to keep all "double quotes" instead of 'single quotes' (you could escape them of course)
  25. You can do this directly in your template pwFoo. I have this in the template I want to generate the PDF from if($sanitizer->text($input->get->pdf) === '1') $modules->get('Pages2Pdf')->render(); And in the template where I´m linking to the page I just add ?pdf=1 at the end of the link. like <a href="{$chlid->url}?pdf=1">PDF Version</a> You probably need to create a PDF template in /site/templates/pages2pdf folder That's it.
×
×
  • Create New...