Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/26/2013 in all areas

  1. A quick tutorial how to create file downloads using pages You will be able to create a new page using template "PDF" (or any you setup), upload a pdf file. You then can select this page using page fields, or links in Wysiwyg. The url will be to the page and NOT the file itself. This will allow to keep a readable permanent unique url (as you define it), unlike /site/assets/files/1239/download-1.pdf, and you'll be able to update/replace the uploaded file without worring about its filename. Further more the file will also have an id, the one of the page where it lives. Clicking those links will download or open the file (when target="_blank") like it would be a real file on server with a path like /downloads/project/yourfile.pdf. You'll be also able to use the "view" action directly in the page list tree to view the file. Further more you'll be able to esaily track downloads simply by adding a counter integer field to the template and increase it every time the page is viewed. Since the file is basicly a page. This all works very well and requires only minimal setup, no modules and best of it it works in the same way for multi-language fields: Just create the language alternative fields like "pdf, pdf_de, pdf_es" and it will work without modifying any code! Still with me? ok PW setup Download folder: Create a template "folder" or "download-folder" with only a title needed. Create pages in the root like /downloads/project/ using this template. Setup the template for the pdf files 1. Create a new template in PW. Name it pdf 2. Goto template -> URLs tab and set the URL end with slash to no. (So we can have /path/myfile.pdf as the URL) 3. Create a new custom file field, name it pdf. Set its maximal count to 1 under -> Details tab. 4. Add the pdf field created to the pdf template. Easy. 5. Create a new "pdf" page using the pdf template under a download folder you created earlier. 6. Give it the title and in the name field add ".pdf" to the end (could also leave as is) Template PHP file for the pdf files 1. Create the template file pdf.php in your /site/templates folder 2. add the following code: <?php // pdf.php if($page->pdf){ wireSendFile($page->pdf->filename); } Done. To see the options you have with PW's wireSendFile() you can also overwrite defaults <?php // pdf.php if($page->pdf){ $options = array( // boolean: halt program execution after file send 'exit' => true, // boolean|null: whether file should force download (null=let content-type header decide) 'forceDownload' => false, // string: filename you want the download to show on the user's computer, or blank to use existing. 'downloadFilename' => '', ); wireSendFile($page->pdf->filename, $options); } Simple and powerful isn't it? Try it out. Some thoughts advanced Create as many file types as you like. It might also be possible to use one "filedownload" template that isn't restricted to one field type but evaluate it when being output using $page->file->ext, or save the file extension to the page name after uploading using a hook. One last thing. You can add other meta fields or preview images to the template and use those to create lists or detail pages. It's all open to goodness. Again all without "coding" and third-party modules. Further more you can use the excellent TemplateDecorator to add icons per template and have a nice pdf icon for those pages. This as a base one could also easily create a simple admin page for mass uploading files in a simple manner, and create the pages for the files automaticly. ImagesManager work in the same way. Cheers
    6 points
  2. http://www.michael-wessel.de/ - the website of a german IT service provider - is now powered by processwire. By the way: Some of the most recent work of the agency i work for is and (most likely) will be done using processwire. Me and my colleagues (some of them are registered here, also ) are pretty excited about it's speed, simplicity, community, ease of use and last but not least: the awesome API. So: Expect some more examples (as well as plugins and admin-themes) to come! Best regards Felix
    5 points
  3. From that point of view you're right. But I think there are more people then me that always use the HelperFields, no exception. Essentially wished that Ryan will make it core and integrate it better. LIke he has done it with your terrific Language Labels. Still big thanks for that ! <adam>I'm probably missing something based on how confusing I find your last sentence...</adam> The last sentence is a mystery (for most), that was the intension.
    2 points
  4. Does this help? http://processwire.com/talk/topic/4570-implementing-small-tweet-like-thoughts/?p=44925
    2 points
  5. Ok, A new version has been pushed to GitHub. This takes care of the first two enhancements mentioned in the first post There are a few new options in the field's Input tab: Number of poster images to generate Images will be captured at intervals from throughout the video. This determines how many will be created. The user can choose which one is available to templates via $page->video_field_name->poster NB - if you change this to more than one (default), I would recommend also checking: "Display thumbnails in page editor?" to keep things looking manageable. Copy poster image to dedicated image field? This will create a copy of the poster images in an image field of your choice. NB This is not necessary for accessing the image. Name of the field that you want to have the poster image copied into This is only relevant if you have the checkbox above checked. Lots more to do, but thought you might like to see the next iteration. I am not sure on some of the behavior regarding copying all created thumbs to an images field (if selected). It might be better to just copy the one selected by the user. Code is still a bit of a mess - want to get features created first, then will clean up.
    2 points
  6. At the computer now. It would be more efficient if you would do this instead: $urlcat = $pages->get("/categories/")->get("name=$name"); // <- get instead of find echo "<h3>Category: <i>" . $urlcat->title . "</i></h3>"; or this: $urlcat = $pages->get("/categories/$name"); echo "<h3>Category: <i>" . $urlcat->title . "</i></h3>";
    2 points
  7. You are using a find to get the page. That gives you a page array instead of the page object. for trying, $urlcat->first()->title should do the job, but you should change your find to a get. (on mobile) edit: teppo, not fair, I'm in disadvantage here
    2 points
  8. Just guessing, but could it be that $urlcat is actually PageArray? Try $urlcat->first()->title instead (or change that "find" to "get".)
    2 points
  9. Hi everyone, This new video fieldtype extends FieldtypeFile. Video is available via: $page->video_field->url Module automatically creates a poster image of the video on upload and makes this available via: $page->video_field->poster Shows the duration of the video on the title bar, next to the filesize Stores VTT files for subtitles accessed via: $page->video_field->subtitles Formats a transcript from the subtitles, accessed via: $page->video_field->transcript Users can easily upload videos and enter VTT files. The following code is used in the template file. <video src='{$page->video_field->eq(1)->url}' poster='{$page->video_field->eq(1)->poster}' width='720' height='408' ><track kind='subtitles' src='{$page->video_field->eq(1)->subtitles}' srclang='en' /></video> Additional Settings You can additionally set a few different options in the field's Input tab: Number of poster images to generate - if you change from the default of 1, the editing user will be able to select which image they want to use for the poster image Copy poster image to dedicated image field - not necessary but gives you more options of interacting with the poster image(s) Field that you want poster images copied into - only relevant if the option above is checked Try it out (NB: the code is rough - it works, but needs cleaning up. Github: https://github.com/adrianbj/FieldtypeVideo NB: Requirements The module requires ffmpeg and ffmpeg-php, although I can make the latter optional fairly easily. I don't have any requirement checking implemented yet, so if you don't have these, you'll get php errors. Possible future enhancements Ability to specify what frame is used for the poster - either by number, and/or by offering several options to choose from Done! Push poster image to a dedicated image field Done, although could be improved Field for pasting in or uploading closed captions Done, but need to look into multi-language options etc Support for uploading multiple formats of the same video (mp4, webm, etc) and/or automated video format conversion My biggest concern, is how useful this will be to people - how many hosts actually have ffmpeg setup? Do any have ffmpeg-php? Anyone have any ideas for features they'd like to see?
    1 point
  10. Hi everyone! With Batcher you can batch-edit and create Pages in the Pw Admin. If you install this module, you get a new Page "Batcher" under Setup. Modules page: http://modules.processwire.com/modules/process-batcher/ Github: https://github.com/wanze/ProcessBatcher Editing How does it work? Search your pages with a selector. You can check if you want to include also hidden/unpublished pages with the filters. Select the pages you want to execute an action (the action only gets executed on "checked" pages). Select the action and if necessary, additional data like the new parent or the new template. Execute. Supported actions: Publish/Unpublish Pages Hide/Unhide Pages Lock/Unlock Pages Trash Pages Delete Pages Change Parent Change Template Batcher does the following permission checkings for the current user: Don't display pages that are not editable Remove Actions if the user doesn't have the permissions (page-delete, page-move, page-template, page-lock) Important notes: When changing a template, data in fields of the old template which are not assigned to the new template gets deleted. When changing the parent, the template of the new parent must accept the pages template as children. This is a setting in the template under "family". Creating How does it work? Select a parent where your new pages will be added as children Add as many pages as you want by clicking "add Page" Click "Create Pages" You must enter a title and choose a template. The name is optional: If left empty, Pw will generate this for you. Includes permission checking and Family template restrictions. This means in detail: The selected parent must accept children and their template The pages template must accept the parents template User needs the permission to add children to the selected parents template User needs the permission to create Pages for the chosen Template Batch-creating tips The chosen template and the statuses are always cloned from the last row. So if you need to add 30 pages with the same template, define it first and the click "add Page" - it'll make your life easier ;-) You can drag & drop the table rows should you want to change the order. The dragging looks ugly but it works. For the lazy dogs and keybord hackers among us, you can add a new row by pressing "ctrl+n". This works (at least in firefox) only if no input has focus. After adding a new row, the title input gets the focus. By pressing 3 times tab you arrive at the published-checkbox, here the short-cut works. Restrict Batcher for a user to only allow editing or creating Create permissions "batcher-edit" and/or "batcher-add". As soon those exists, the module checks if the current user has the permissions. If you only need batch creating, check out the following module by Soma: http://processwire.com/talk/topic/2138-process-tools-create-pages-wip/ Cheers
    1 point
  11. Hi folks This isn't a new concept, but since I use this on several sites and was getting frustrated by having to add the fields and put the CSS in the admin template's CSS file to have it overwritten on updates I thought I'd make it into a module where it should work regardless of which admin template you use and shouldn't be affected by updates since the CSS to hide the fieldset's container styles is now in a separate CSS file completely. Unfortunately I can't find the original topic where this concept was introduced (if anyone can find it, please link to it as I can't take credit for the idea), but essentially what the module does is create a left and right columns that are actually fieldsets, and you simply add the fieldsets to your template and place fields in each of the columns to suit yourself. Enough chit-chat, the screenshot below will explain it better: I think when this was originally discussed it was back before ryan had introduced field widths, but I think this still has a place for where you have differing heights of field (as per the ASMSelect field on the right of the shot) where using field widths would result in a space before the next row of fields. In fact, this works especially well on pages where you have small bits of information to enter and want to leave a larger left column for text editor, image and file fields. The beauty of now having variable width columns per-template now as well is that you can change the fieldsets from their set widths of 70% and 30% respectively to whatever suits your needs on a particular template. Download from the modules directory. Usage Download and install the module above Add admin_column_left and admin_column_right fieldsets to your template and put the fields in the relevant column fieldsets (Optional) change the field width for either column, taking care to leave 1% for a gap between the two columns (default is left column at 70%, right column at 29%) That's it!
    1 point
  12. Hi all, I just released my first module on github called Template Data Providers. This module lets you create simple data provider classes for templates and chunks (a.k.a. partials, blocks, includes, ...) to gather and prepare data for templates and/or handling form data and other actions outside of the templates ("separation of concerns"). But even if you've installed the module the usage of the new functionality is merely optional. You may define your simple templates and chunks as usuals, adding custom classes (PageDataProvider for pages/templates, ChunkDataProvider for chunks) for more complex data handling on demand. I provided detailed instructions in the README.md and encourage you to read it for further information. Just some sample code here: Defining a data provider for a home template: class HomePage extends \nw\DataProviders\PageDataProvider { public function populate() { $this->foo = 'bar'; // definevariable $foo to use within the page's template $this->page->foo = 'baz'; // provides page member $page->foo to use within the page's template } } Calling a chunk from within a template: $page->renderChunk('path/to/primary-navigation.php'); // relative to site/templates/ Calling a chunk providing contextual data: $news = $pages->get('template=news'); foreach ($news as $newsItem) { $page->renderChunk('path/to/news-item.php', $newsItem); // additional arguments provided will be avaiable within the chunk in a closed scope } Defining an example chunk data provider: class ExampleChunk extends \nw\DataProviders\ChunkDataProvider { public function setContext(array $context = array()) { // store first context argument in $this->foo $this->foo = isset($context[0]) ? $context[0] : null; // store second context argument in $this->bar if instance of \Page $this->bar = null; if (isset($context[1]) && $context[1] instanceof \Page) { $this->bar = $context[1]; } } public function populate() { $this->foo = 'bar'; // provides variable $foo to use within the chunk } } Please leave your questions, remarks, error reports here in the forum or at github and I'll try to answer as soon as possible. This module is a preparation for another module coming soon. This will be an alternative Twig template engine module that will interact with Template Data Providers or could be used as stonde-alone module. Regards from Hanover/Germany, Marco
    1 point
  13. Greetings Everyone, ************************************************* ************************************************* EDIT NOTE: This post started as a work-in-progress discussion as I was working out the elements of a successful form. After contributions from participants in this discussion, the code below has been tested and works well. You can use the code as shown below in your ProcessWire templates! Feel free to follow up with additional quesations/comments! ************************************************* ************************************************* I have successfully built front-end forms with ProcessWire to add pages via the API. It works great -- until I had to include image uploads along with the "regular" form fields. Then it temporarily got a bit complicated. In this discussion, I show how to handle front-end submissions in ProcessWire with the goal of allowing us to create pages from custom forms. I then go a step further and show how to use the same form to upload files (images and other files). I'm hoping this discussion can illustrate the whole process. I know a lot of people are interested in using ProcessWire to do front-end submissions, and my goal for this discussion is to benefit others as well as myself! First, here's my original contact form (no file uploads): <form action="/customer-service/contact/contact-success/" method="post"> <p><label for="contactname">Name:</label></p> <p><input type="text" name="contactname"></p> <p><label for="email">E-Mail:</label></p> <p><input type="email" name="email"></p> <p><label for="comments">Comments:</label></p> <p><textarea name="comments" cols="25" rows="6"></textarea></p> <button type="submit">Submit</button></form> And here's the "contact-success" page that picks up the form entry to create ProcessWire pages: <?php // First, confirm that a submission has been made if ($input->post->contactname) { // Save in the ProcessWire page tree; map submission to the template fields $np = new Page(); // create new page object $np->template = $templates->get("contact_submission"); $np->parent = $pages->get("/customer-service/contact-us/contact-submission-listing/"); // Send all form submissions through ProcessWire sanitization $title = $sanitizer->text($input->post->contactname); $name = $sanitizer->text($input->post->contactname); $contactname = $sanitizer->text($input->post->contactname); $email = $sanitizer->email($input->post->email); $comments = $sanitizer->textarea($input->post->comments); // Match up the sanitized inputs we just got with the template fields $np->of(false); $np->title = $contactname; $np->name = $contactname; $np->contactname = $contactname; $np->email = $email; $np->comments = $comments; // Save/create the page $np->save(); } ?> This works great! After submitting the form, we go to the "Success" page, and new submissions show up in the ProcessWire page tree right away. Excellent! Now I need to add a photo field. I altered the above form so it looks like this: <form action="/customer-service/contact/contact-success/" method="post" enctype="multipart/form-data"> <p><label for="contactname">Name:</label></p> <p><input type="text" name="contactname"></p> <p><label for="email">E-Mail:</label></p> <p><input type="email" name="email"></p> <p><label for="comments">Comments:</label></p> <p><textarea name="comments" cols="25" rows="6"></textarea></p> <p>Click the "Select Files" button below to upload your photo.</p> <input type="file" name="contact_photo" /> <button type="submit">Submit</button> </form> And here's the updated "contact-success" page: <?php // First, confirm that a submission has been made if($input->post->contactname) { // Set a temporary upload location where the submitted files are stored during form processing $upload_path = $config->paths->assets . "files/contact_files/"; // New wire upload $contact_photo = new WireUpload('contact_photo'); // References the name of the field in the HTML form that uploads the photo $contact_photo->setMaxFiles(5); $contact_photo->setOverwrite(false); $contact_photo->setDestinationPath($upload_path); $contact_photo->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); // execute upload and check for errors $files = $contact_photo->execute(); // Run a count($files) test to make sure there are actually files; if so, proceed; if not, generate getErrors() if(!count($files)) { $contact_photo->error("Sorry, but you need to add a photo!"); return false; } // Do an initial save in the ProcessWire page tree; set the necessary information (template, parent, title, and name) $np = new Page(); // create new page object $np->template = $templates->get("contact_submission"); // set the template that applies to pages created from form submissions $np->parent = $pages->get("/customer-service/contact-us/contact-submission-listing/"); // set the parent for the page being created here // Send all the form's $_POST submissions through ProcessWire's sanitization and/or map to a variable with the same name as the template fields we'll be populating $np->title = $sanitizer->text($input->post->contactname); $np->name = $np->title; $np->contactname = $sanitizer->text($input->post->contactname); $np->email = $sanitizer->email($input->post->email); $np->comments = $sanitizer->textarea($input->post->comments); $np->save(); // Run photo upload foreach($files as $filename) { $pathname = $upload_path . $filename; $np->contact_photo->add($pathname); $np->message("Added file: $filename"); unlink($pathname); } // Save page again $np->save(); ?> <p>Thank you for your contact information.</p> <?php return true; } else { ?> <p> Sorry, your photo upload was not successful...</P> <?php } ?> Replace the field references with your own field names, make sure to change the various paths to match yours, and change the various messages to be what you need for your project. Read the entire discussion to see how we worked through getting to the solution shown above. Thanks, Matthew
    1 point
  14. Hi celfred, You could easily add the checkbox field to the page yourself. Create a new field called: "disable_comments". Choose checkbox as the fieldtype. Add this field to the required template. In your template have some code like this: if($page->disable_comments !== 1){ echo $page->comments->render() . $page->comments->renderForm(); } That should be close to what you need!
    1 point
  15. Thanks Adrian, that was the answer. Just to clarify for anyone else reading this, the admin.php file in the templates folder should have been modified to add this code when the module was installed, but for some reason it did not happen, so I manually added it and it now works. What I mean is the child page is now rendered in the parent in the admin. // line added for the Custom Admin Pages Module if($page->template->id !== 2) $page->process = "ProcessAdminCustomPages"; I wonder if someone could clarify if this is the right 'tool' for my needs: I would like to have an admin only page that produces a report (table), effectively a report generator where you select the fields (all existing fields) you want in the report from dropdowns in each column or just select the fields and the table is created based on the selected fields, one field per column. I haven't thought this through 100% but any ideas are welcome.
    1 point
  16. I like the idea of this. Though my need is less the part of reusing existing fields, but creating a fieldgroup bundled with its fields. For sure it would a nice if I could even reuse existing fields like "title" and access them like somehow like this "$page->myfieldgroup->title", but I never missed this feature. I try to explain my usecase: I have some templates with a fieldgroup "metainfo" with the fields "browsertitle" and "meta_description". Currently I have to assign all these fields one by one to my templates. And if I later need some additional meta infos for facebook like "og_image" and "og_title" I have to edit all my templates to add these fields. If we would have some kind of defined fieldset, I could just assign my new fields to this fieldset and all my templates would have the new fields.
    1 point
  17. I thought maybe you were just talking styling, do I think it should be core, for sure, very useful, I think there is a lot of value in small usability advantages for the superuser.
    1 point
  18. Another vote for submitting this to the modules directory
    1 point
  19. Nope - you've still lost me on why you would want to re-use fields that make up an article (which is a single thing) within the same template. It doesn't make sense to me. Many (infinite, within reason) separate pages can use the same template, each article would surely be a separate page using that same template? I still don't see the reason to re-use those fields within the same template.
    1 point
  20. make sure you sanitize that value before using it in the selector and throw a 404 if the page is not found.
    1 point
  21. Hi all, New changes / features under the hood, check it out! http://modules.processwire.com/modules/indexer/
    1 point
  22. Saw your checkout Font Awesome Page Label. I love Font Awesome too !
    1 point
  23. Thanks for this Soma! Very elegant solution What type of field please?
    1 point
  24. @adrian: this sounds awesome and definitely fits some of our needs just fine.. so thank you very much for working on this! Regarding ffmpeg and ffmpeg-php, I've just tested two hosts and one had both of those installed. Other host is my Linode VPS which, as expected, didn't (and shouldn't) have them yet. I don't think this kind of requirement is such a big problem really, especially since this kind of field can IMHO be most useful in slightly larger projects, where getting a proper host shouldn't be an issue. YouTube is just fine for most others. Have you seen https://github.com/CodeScaleInc/ffmpeg-php, by the way? I can't speak for it's quality as I've never tried it, but it might be worth considering as an option to ffmpeg-php. Probably not a good default though, as a PHP extension would most likely have some advantages, such as speed (C vs. PHP.) From your feature list "automated video format conversion" sounds like the most important one to me. Unless I'm mistaken, video element only takes us halfway there; visitor's browser still needs to support each video format used and thus conversion + some kind of player sounds like the best option. One system I've been working with has something similar as this, though it by default converts all other formats to FLV and then uses Flowplayer to play those -- this has been in use for years and seems like a solid option. Anyway, I'll be sure to check your code better as soon as I can. Would love to help somehow, too. Edit: almost forgot to add that having an optional, built-in player would be a nice addition. Something like the Flowplayer integration I mentioned above, so that $page->video_field->render() would simply output the player. Just saying
    1 point
  25. Here is another thread where we talked about frameworks. If size and flexibility matters, PocketGrid could be a good choice? It's only a grid, nothing more. Very minimal and seems to be very flexible. Looks like you can do anything with it (like doing with PW). But haven't tested it.
    1 point
  26. Next to this, wrapping block elements in links, can reduce markup, create a bigger click area & you get a styleable container for free This is great!
    1 point
  27. Plus mine is more about creating two columns where variable-height fields will play nicely if you check the screenshot
    1 point
  28. Martijn - no, it wasn't that one, it was renobird's idea that thistimj linked to above - I like renobird's solution as it should work with any admin theme now it's a module
    1 point
  29. Pete, I think you're referring to this post by renobird: http://processwire.com/talk/topic/2002-repeating-events-multiple-datestimes-for-datepicker/?p=18862
    1 point
  30. You could output a json config object using php , then it will be available in your js. before your scripts in the header: <?php $jsconfig = array( 'root' => $config->urls->root, 'domain' => $config->httpHost ); echo "<script>var config = " . json_encode($jsconfig) . ";</script>"; ?> this will output an json object <script>var config = {"root":"\/","domain":"pw2-dev.ch"};</script> you can access in js like this <script> $(document).ready(function() { $('#header').click(function(){ window.location = "http://"+config.domain;; }); $('#search_form').click(function(event){ event.stopPropagation(); }); }); url = config.root; </script> This is the most easy and convenient way for me.
    1 point
×
×
  • Create New...