Leaderboard
Popular Content
Showing content with the highest reputation on 05/30/2015 in all areas
-
Just a heads-up: As mentioned, lot's on the plate these days. But I've made a decision regarding the module going forward. When the next one or two PW minor stables come out, I'm going to start making Jumplinks 2.6-only. Lots of goodies I want to use, and as stated earlier in this thread, Jumplinks is mostly for new sites resulting from migrations. Of course, Jumplinks won't upgrade for anyone using it on 2.5.3. Also, and because of this decision, I'll be switching over to some kind of autoload solution so I can split up logic etc. It's essentially going to be a rewrite. Nonetheless, it will function exactly the same, sans the 404 Monitor, which I'll try to release at the same time. Speaking of the 404 monitor, I've already drawn out some blueprints and flow charts - ideas have come to mind, and I think it's going to be a really helpful module. As said, it will mesh well with Jumplinks. Edit: Okay, I see that 2.6.1 is already on stable (of course, it should be). I'll need some time before I start this up.3 points
-
Yeah baby, this is what i wanted. I love ya! This system dosen't stop amaze me day after day. Cheers for your answer2 points
-
Where do i get? From here: https://github.com/IDT-media/Pages2JSON (thanks to LostKobrakai for "bug" report) What does this do? Simply adds method toJSON() to Page and PageArray elements, is capable to converting image and file arrays to URL containers, travels recursively all objects before outputs actual JSON. How to use? Simply install this module, configure data you want it to export in JSON result (similar to Ryan's ServicePages, thanks btw used some of ur code here). in templates or anywhere you need JSON output, call: $page->toJSON(); or $pages->toJSON(); Live example with template: search.php /***************************************************************** Do search *****************************************************************/ $term = $sanitizer->text($input->term); $results = array(); if($term) { $input->whitelist('term', $term); $term = $sanitizer->selectorValue($term); $limit = (int)$input->limit; $limit = $limit ? $limit : 50; $limit = $sanitizer->selectorValue($limit); $selector = "title|categories|content*=$term, limit=$limit, template=default|product"; // Prevent admin pages. if($user->isLoggedin()) $selector .= ", has_parent!=2"; // Find pages that match the selector $results = $pages->find($selector); } /***************************************************************** Output *****************************************************************/ header("Content-type: application/json"); echo $results->toJSON(); exit(); Customizing values: if(wire('config')->ajax) { wire()->addHookAfter('Pages2JSON::getValue', function($event) { $value = $event->arguments(0); if(!is_object($value)) return; $page = wire('page'); if($page->template == 'thumbs' && $value->className == 'Pageimage') $event->return = $value->size(28,28)->url; }); } Here i swap URL of all Pageimage objects in JSON response to match thumbs. Simple hu?1 point
-
Hi Ryan, i would like an alternative Spamprotection for the Commentfield. Akismat is expensive and criticle for german users. I use the Plugin Antispambee on my WordPress Blogs, which protects the comments very well! On my projekt i get more than 300 spam comments per day and not one gets published but the real comments are published without any effort on my part. Thats a great work and i found it is one of the best way to protect the comments from spam. All of this works without an external service like Akismet and without JavaScript. The Functions: trust authorized comments can trust comments with gravatar classify BBcode as spam validate the IP-Adress use regular expression use a locale spam database optional: can use a public spam database block or allow certain countries Allow comments only in one language Delete existing spam after X days delete immediately according to defined spam reasons all this is optional and can be activated by the user manually. Is there a API for the Comment Module to implement this functions?1 point
-
New to ProcessWire (came over from PyroCMS) and really liking it so far. The flexibility in page building is amazing! Anyway, as part of the first site I am building I need an Upcoming Events list. After looking through the forums and docs, I ended up building a page with children pages where each child is a different upcoming event. Each child has title, description, start and end date fields. I have the page working and displaying everything now and am very happy! However, I have one last piece that I cannot figure out. How do I filter the events? Specifically, how do I only show upcoming events and not ones that have already ended? I am displaying individual events with this: $events = wire('pages')->get("/events/")->children("sort=event_start_date"); $singleevent = $events->first; With a full list I can do a comparison in a for loop, but would prefer to just return the valid objects in the initial call. Basically, is there a way to add a "where" ("where event_start_date > $today") type statement?1 point
-
This is even better as it's using less or at least more optimized database calls (depending on the exact selector): $events = wire('pages')->find("parent=/events/, event_start_date>today, sort=event_start_date");1 point
-
Ah, so you can stack selectors! Cool! Liking PW more and more! Thanks for the quick responses!1 point
-
Hi- this is a very basic version, i can provide more details later, but in short you first define today as a timestamp and then add your selector. $today = date(); $events = wire('pages')->get("/events/")->children("event_start_date > $today, sort=event_start_date");1 point
-
1 point
-
Greetings, What makes ProcessWire so excellent is the ability to do all kinds of work at the API level, so that you can essentially create a custom admin for your projects. Editing a page is of course a crucial part of any custom admin. NOTES: Of course, you must cutomize this to your project. Also, in my code I am editing the page directly inside the page itself. In other words, you display a page as usual, but inside it you have your edit code, as well as code to save the page after editing. The other option would be to link to another page just for editing. Editing does get rather involved. Below is a technique I've used. I'll break editing down to several steps, then later I'll put it all together as one. Here goes... Step 1: Isolate Who Has Editing Rights You don't want anyone who can view the page editing it! I use code like this to limit editing to people with either an "editor" or "superuser" role. We open it here, and close it later in Step 6: <?php if ($user->isSuperuser() OR $user->hasRole("editor")) { Step 2: Set the $page Variables (Except Title) to Hold Edited Values Take inputs received from a submitted form and use those values to replace current $page values. For this example, I am only using two fields to keep it simple. And they are text fields. We hold off on setting the title, since that needs special handling: <?php if ($input->post->title) { $page->set("first_name", $sanitizer->text($input->post->first_name)); $page->set("last_name", $sanitizer->text($input->post->last_name)); } Step 3: Edit Title Field, but Only if the Title is Unique, Then Save the Page You need something like this so you don't get an error if the title you apply to the edited page collides with the title of an existing page. The code below confirms that the title is unique and allows you to set the title, and only then save the page: $thistitle = $page->title; $matchedtitle = $input->post->title; $checktitles = $pages->find("parent=/[path]/[to]/[parent]/, title=$matchedtitle|$thistitle"); $titlecount = count($checktitles); if($titlecount < 2) { $page->of(false); $page->set("title", $sanitizer->text($input->post->title)); $page->set("name", $sanitizer->text($input->post->title)); $page->save(); Step 4: Refresh URL Think about it... If while editing this page we changed the title, the URL you are on is no longer valid. Here's a simple bit of Javascript to handle this. The code below also closes out the conditional set in Step 3: $refresh=$page->url; ?> <script type="text/javascript"> window.location = '<?php echo $refresh ?>'; </script> <?php } Step 5: Handle the Scenario When the Page Title Collides In Step 3, we edited the page title because it passed the "unique" test. But what if it fails that test? We would move to this section of code, where a message lets the user know there is a problem. A bit of Javascript helps make the warning fade in so it is more noticeable: else { ?> <div class="admin_error_box"> <p>Sorry, there is already a page using this title: <?php echo $input->post->title?>!</p> <p>Please enter a different title in the form.</p> </div> <script> $(function() { $('.admin_error_box').hide().fadeIn(3000); }); </script> <?php } Step 6: The Edit Form We need a form to capture the submission of edits. It would look the same as your page-creation form, but would have to be pre-populated with the current values of the page, which will also change upon submission of the form. The last bit of code closes out the check on user roles set in Step 1: <div class="page_create_form_box"> <p class="form_heading">EDIT THIS PAGE USING THE FORM BELOW</p> <form action="<?php echo $page->url ?>" method="post"> <ul> <li><label class="label_class" for="title">Page Title:</label> <input type="text" class="input_class" name="title" value="<?php echo $page->title ?>"></li> <li><label class="label_class" for="first_name">First Name:</label> <input type="text" class="input_class" name="first_name" value="<?php echo $page->first_name ?>"></li> <li><label class="label_class" for="last_name">Last Name:</label> <input type="text" class="input_class" name="last_name" value="<?php echo $page->last_name ?>"></li> </ul> <button class="admin_submit" type="submit" name="submit">SAVE EDITED PAGE</button> </form> <?php } ?> Step 7: Putting it all Together Now let's put all of this code into one continuous routine. <?php if ($user->isSuperuser() OR $user->hasRole("editor")) { ?> <?php if ($input->post->title) { $page->set("first_name", $sanitizer->text($input->post->first_name)); $page->set("last_name", $sanitizer->text($input->post->last_name)); } $thistitle = $page->title; $matchedtitle = $input->post->title; $checktitles = $pages->find("parent=/[path]/[to]/[parent]/, title=$matchedtitle|$thistitle"); $titlecount = count($checktitles); if($titlecount < 2) { $page->of(false); $page->set("title", $sanitizer->text($input->post->title)); $page->set("name", $sanitizer->text($input->post->title)); $page->save(); $refresh=$page->url; ?> <script type="text/javascript"> window.location = '<?php echo $refresh ?>'; </script> <?php } else { ?> <div class="admin_error_box"> <p>Sorry, there is already a page using this title: <?php echo $input->post->title?>!</p> <p>Please enter a different title in the form.</p> </div> <script> $(function() { $('.admin_error_box').hide().fadeIn(3000); }); </script> <?php } ?> <div class="page_create_form_box"> <p class="form_heading">EDIT THIS PAGE USING THE FORM BELOW</p> <form action="<?php echo $page->url ?>" method="post"> <ul> <li><label class="label_class" for="title">Page Title:</label> <input type="text" class="input_class" name="title" value="<?php echo $page->title ?>"></li> <li><label class="label_class" for="first_name">First Name:</label> <input type="text" class="input_class" name="first_name" value="<?php echo $page->first_name ?>"></li> <li><label class="label_class" for="last_name">Last Name:</label> <input type="text" class="input_class" name="last_name" value="<?php echo $page->last_name ?>"></li> </ul> <button class="admin_submit" type="submit" name="submit">SAVE EDITED PAGE</button> </form> <?php } ?> My apologies for any problems with the formatting of the code above (please use your editor to assure proper tabs). Notes: - If you include checkboxes or other field types in your page, the editing is a bit more involved. - If you have image fields, you would have separate actions connected with those. For more information on handling image fields in custom forms, take a look at this: http://processwire.com/talk/topic/3105-create-pages-with-file-upload-field-via-api/ That should get you started! Follow up if you have more questions! Thanks, Matthew1 point