Leaderboard
Popular Content
Showing content with the highest reputation on 03/13/2013 in all areas
-
Okay this was very short notice so it is incredibly rough! But this is for Diogo and all those others wedded to PW http://21stcenturyblues.co.uk/pwdream1.mp3 (Organized, try listening at less than 120db!)5 points
-
This is a companion tutorial to the Basic Website Tutorial and the Simple News Tutorial. This tutorial teaches you how to create a multiple album gallery system in processwire using a lightbox plugin (colorbox) and a slideshow plugin (Flexslider). As with all tutorials, it is meant as a starting point for you to create your own system rather than an instant plugin. This can be used standalone on a new installation of ProcessWire, but it was initially designed on top of the Basic Website Tutorial structure. If you are new to ProcessWire, then I suggest doing that tutorial first. http://wiki.processwire.com/index.php/Simple_Gallery_System Joss4 points
-
Hey Alan, I think it is just that you need to use wire('input')-> when inside a function.4 points
-
Thanks VERY much teppo and adrian; I am relieved to say I actually understand the concept of scope (a bit) and so I totally get the distinction. I had just never realized until now that the PW API stuff such as $input->urlSegment1 were not somehow 'god-mode' things that worked everywhere, now I know they are (sensibly now I think about it) limited by scope in a similar way to variables I can totally see that some other construct such as wire is needed to show I need to look 'outside' the function. Brilliant! I feel I have learnt something subtle but significant thanks to you helpful fellows, thanks again!2 points
-
Slightly longer explanation is that it's a problem with scope; you might want to take a closer look at PHP manual entry about variable scope. Essentially you need to use wire() (which is a function) instead of $input (which is an object and thus subject to same scope rules as variables) when you're in the context of a function. You could also pass the function a copy of (or reference to) whatever object or variable you want: function fDtest($input) { if(isset($input->urlSegment1)) echo ":)"; else echo ":("; } echo fDtest($input); .. but that's probably not what you want here. Anyway, hope this helps clear things out a bit Edit: removed reference sign from function call, that way of using references has been deprecated in PHP 5.3.0 and removed from 5.4.0.. and it wasn't even necessary step here, since in PHP 5 objects are by default passed by reference (kind of.) Because of this you need to be very careful when making any changes to objects such as $input inside a function since it'll affect global scope too. To pass an object by value you'd need to use clone instead. Variables, on the other hand, need to be prefixed with reference sign "&" in function definition in order to pass them by reference -- by default they're passed by value.. Thanks to @Nik for pointing these out, my information was outdated!2 points
-
$select1 = 'template=bluskchug, ...whtevr u want'; $select2 = 'template=chishpahjung, ...whaevr u.like'; $select3 = 'sort=...you say, limit=10'; $select3 .= ", id="; // leav.thi s $findre = new PageFinder(); $res1 = $findre->find(new Selectors($select1)); $res2 = $findre->find(new Selectors($select2)); foreach(array_merge($res1, $res2) as $hi) $select3 .= "$hi[id]|" $res3 = $findre->find(new Selectors(rtrim($select3, '|')); $ids = array(); foreach($res3 as $hi) $ids[] = $hi['id']; $yopages = $pages->getById($ids); or.u jus.use sql.queery2 points
-
I think finding a balance here is quite important. If you did too much via a settings page it could get very unmanageable! On another demo I am doing, I am creating alternate style sheets in my CSS directory and then using a page select field to include them into a page. So: create alternate CSS styles sheets for specific classes (try to keep it carefully defined rather than do everything) create a template without a file with two fields - title and another text field. Call it "my-themes" or something Use that template to create a series of pages - in the Title put s friendly description of the style sheet (blue one with a fringe!), and in the other text field put the actually name of the style sheet Create a page field that looks for your my-themes pages and use that in your normal templates. In your header template file, look for this page field - if it exists then use the value to link to that style sheet, if it doesn't, then make it use a default version. This way you can create lots of style sheets and the user can just pick the one they want - and then leave fields for specific classes just for the occasional bits, like the background in a box or something.2 points
-
Here is the new Simple Gallery tutorial http://processwire.com/talk/topic/3046-simple-gallery-tutorial-for-processwire/2 points
-
Do you hate dislike TinyMCE and heart Markdown? Or Textile? Or HTML? Do you wish there was better way to create content than textarea? Well there is! Content creation oriented, syntax highlighted and easy on the eyes, that is this new plugin I made. And I know you'll love it! And did I mention it supports HTML, Markdown and Textile? Download/fork/star here: GitHub PW Modules Your local modules manager Features Syntax highlight your text, for easier preparation of content Nice light, readable theme Supports Textile, Markdown & HTML Auto selects mode, based on field's textformatters (last found is used) Works with multiple fields on page, each with different settings Features inspired by iA writer Blue Cursor Focus mode We are still kind-of in beta, so please, test your browsers and let me know… Thank you! <3 PW1 point
-
hi there! after playing a bit with pw, i decided to choose my own new website as a first project to test it. im realy happy with it and i will use it as my number 1 choice for my own clients in the future. the first time working with an cms i've got not the feeling that i need to "fight" against it. i was realy suprised how easy it is to use ajax with pw, which i did for my references page, i'm still looking for an easy to implement url/hashbang ajax-solution - this is something i will add in the future to the site. a little blog will follow:) http://chrisvaupel.de constructive critics are welcome PS: it's a small site, but i bought procache and formbuilder, becouse i was curious and wanted to give a little bit of money support - anyway, i just like to say that booth are working realy well1 point
-
Well it is all about variable scope. None of the PW variables (http://processwire.com/api/variables/) are available inside a php function. So you can use the wire function for any of those PW variables inside a function. If you're going to be using a variable more than once inside the function, it can be worth doing this at the top of the function: $input = wire('input'); and for any other PW variables you might need access to.1 point
-
If something I learned over the years, it's to watch your css for navigations ... as simple as possible pays out. However since older browsers are left behind it good to move on. I updated the Module to 1.1.7 to fix the warning. Thx for mention.1 point
-
Under category "revolutionary features": Delete all files and database tables in a single click. Isn't that nice and cozy? .. seriously speaking: haven't heard of this before so can't recommend. In our case Site Profile Exporter makes backups quite simple already, but not that simple, so I guess this could be useful in some cases. Especially if you don't want to / for some reason can't set up server-side automated backups etc. Edit: after taking a slightly closer look at this thing I must say that I'm not exactly pleased, to say the least. They claim it's a free software PHP script, but as far as I can tell only way to see it in action and/or view it's code seems to be by downloading a Windows installer, the size of which is nearly 50MB. Now that's suspicious. Anyway, even if it's not a fake, that's one heck of a horrible way to distribute free software. Horrible enough to keep me away, at least1 point
-
You're right Soma, it's my css that's messed up and i'm stuck in the old way of styling the navigation. I just have to rethink it. Thanks for all your help!1 point
-
I dont really get what the problem is. You have the current parent and the section. list_field_class => 'p{id}' Then in css li.parent.p1001{..} Or li.parent.p1001 > a { ..} To style active section item with parent id 10011 point
-
Try this: $allPages = $pages->find("anySelector"); foreach($allPages as $p) if($p->modified == $p->created) $allPages->remove($p); //I'm using == instead of <= because modified would never be smaller than created $allPages should hold your desired results now1 point
-
Yep, I have had that problem too. My workround was to look for the first() image (even though I am not using it as such) and check that. If no image is uploaded then it will return false. I have a suspicion that if($page->images) on a multi images field (one that is set as having more than one possible image) that all you are checking is if the array is there - even if it is an empty array. Or something like that. Me long-haired hippy muso - there is no such thing as emptiness!1 point
-
Thanks mats for the heads up. I think It was late when doing this. Have to take a look a again at that $class variable. I should practice what I preach As for the wish, I'm not sure what you mean because you can aleady define what you want: parent_class : class for all active parents has_children_class : class for parents that have children now new list_field_class: add classes like {name} to each item (which is what you need not?) so a active parent of the current page will have <li class="parent has_children about">... I didn't just add this new feature to "parent_class" because adding the possibility to add {fieldname} to all items covers all needs and not just for parents.1 point
-
If you will use superscripts, be aware that they can affect the height of that line. Read the solution to prevent this here http://css-tricks.com/snippets/css/prevent-superscripts-and-subscripts-from-affecting-line-height/ Another thing you can do is activate the "Insert Special Character" button in TinyMCE on the field settings. Then you just have to insert the ™ character where wanted. You'll find instructions to customize tinyMCE here http://wiki.processwire.com/index.php/TinyMCE1 point
-
I looked again at the images examples on the docs and, as you told, Ryan also uses if($page->images) on a multiple images field. I tested it and, as expected, it does return true even if there is no image uploaded, making the test not very useful... Ryan?1 point
-
On that example the field being checked has a maximum of 1 image: In this case, the field returns the image itself or false NULL (in case it's empty) instead of an array. edit: //if empty count($page->field_name) === 0 count($page->field_name)>0 === false both forms are good1 point
-
An image field always holds a wireArray, wish returns true even if empty. To have a false in an if statement you want it to return false or 0. if (count($page->field_name)){ This will return 0 in case the wireArray is empty.1 point
-
This happens because "repeaterPageId" is a variable, and "#repeaterPageId a" is a string (notice that it is inside quotes on your code). Javascript has no way to know that it should use "repeaterPageId" as a variable instead as part of the string. What you would have to do here would be add the string "#" plus the string that "repeaterPageId" is holding plus the string " a" by concatenating them: $("#" + repeaterPageId + " a") // <-the space inside the quotes before the "a" is important This will result in: $("#1234 a") edit: This may be confusing when you can use variables inside of double quotation marks in PHP like echo "this $variable will work"; , but PHP has a way of knowing that $variable should be treated as a variable because of the $. So what we are doing there is exactly the same as doing echo 'this ' . $variable . ' will work'; in PHP.1 point
-
Ah se you already found a solution... Here how it would be done. Simple. // html output echo "<ul id='$repeaterPageId' class='gallery'>"; ... <script> $(function(){ var options = {}; $("#<?php echo $repeaterPageId;?> a").photoSwipe(options); }); </script>1 point
-
Add photoswipe init once through a class you then give to all galleries and be done. <script language="javascript" type="text/javascript"> (function(window, $, PhotoSwipe){ $(document).ready(function(){ var options = {}; $(".gallery a").photoSwipe(options); }); }(window, window.jQuery, window.Code.PhotoSwipe)); </script> No need to create a javascript code with an unique id for each gallery you add in html.1 point
-
have a look at this post http://processwire.com/talk/topic/2210-help-getting-a-custom-styles-php-file-working/?p=206411 point
-
<script language="javascript" type="text/javascript"> (function(window, $, PhotoSwipe){ $(document).ready(function(){ var galleryId = '<?php echo $repeaterPageId; ?>'; // <- the quotation marks were missing here console.log(galleryId); // <- I assume here you want to log "galleryId" and not "repeaterPageId" var options = {}; $("#galleryId a").photoSwipe(options); // I'm confused, do you have an HTML element with the id "galleryId" in your code? }); }(window, window.jQuery, window.Code.PhotoSwipe)); </script> I corrected two things in your code that were definitely wrong, but even with them corrected I don't really understand what's going on there because your not really using the variable that you defined with the help of PHP. What you are using that seems similar, is this element "#galleryId", but this is not the same thing, because "galleryId" is a javascript variable while "#galleryId" is the way that jQuery calls the id of an html element. Two completely distinct things.1 point
-
I have just added a new simple gallery/album tutorial to the wiki which includes using Flexslider in both carousel and slideshow mode. By "just added" I mean that I added it a couple of minutes ago and haven't proof read it fully! But it may still be useful http://wiki.processwire.com/index.php/Simple_Gallery_System1 point
-
That is only because php looks unfamiliar to a designer who thinks that php is only for experienced coders. That was my cms thinking also for a long time. Until I saw how easy you can mix html and php tags in Processwire. After playing for a while with simple php tags in processwire your opinion will change. The thing with php (and any other programming language) is that you "have to get into it". Just start with the PW tutorials and first learn to use simple php tags like <?php echo $page->title; ?> Here is a good start http://processwire.com/api/templates/ Later on you can learn something more like a for each in php. Check this post also http://processwire.com/talk/topic/2994-learning-php/#entry294991 point
-
Thank you so much for your considerations and guiding! You see me diving into another phase of learning stuff for the first time. I think I'll try to build a module. Should I ever finish it and anyone might possibly find it useful, I'll publish it on your site.1 point
-
Thanks Antti. I merged your pull request. All seems to be working well after a brief test. Not sure why, but the 'Source' option still doesn't work in inline mode, even though they apparently fixed that in 4.1. The problem is it isn't semantic. It's one of those things that technically belongs with a site's styles rather than in the RTE. I'm hesitant to have anything non-semantic in our default set. This could be a good idea for the future, so I'll make note of it. But the scope of it would stretch beyond just the CKEditor module, so this is something I'd like to revisit later.1 point
-
Just made pull request to update this for using ckeditor 4.1. It's automatic content cleaning is just fabulous. There might be cases (is there?) where we want to allow elements pasted that are not available from toolbar, then we need a setting for that. Still few minor quirks with image field (loses possible link when changing alignment).1 point
-
OK, it's been a while since I looked at this, and much of it was inspired or guided by Ryan. I had to boil it down a little to make it generic enough to make sense, so this exact code hasn't been tested, but it should get you started. Here's a proof of concept that works. Template for your calendar page <?php function pagesToJSON(PageArray $events) { $json = array(); foreach($events as $event) { $json[] = pageToArray($event); } return json_encode($json); } function pageToArray(Page $event) { $data = array( 'id' => $event->id, 'title' => $event->title, 'start' => date("Y-m-d H:i:s",$event->start_date), 'end' => date("Y-m-d H:i:s",$event->end_date), 'url' => "./$event->id", // event ID is the url segment ); return $data; } if($input->urlSegment1) { // event ID provided as a URL segment to this page $event = $pages->get("id=$input->urlSegment1"); include("./includes/head.inc"); echo $event->title; echo $event->body; include("./includes/footer.inc"); } else if($config->ajax && $input->get->start && $input->get->end) { // fullCalendar making an ajax request of events $start = (int) $input->get->start; $end = (int) $input->get->end; $events = $pages->get("/calendar/")->children("sort=start_date"); $events = pagesToJSON($events); echo $events; } else { //display the calendar $config->scripts->add('/site/templates/assets/js/fullcalendar.min.js'); $config->styles->add('/site/templates/assets/css/fullcalendar.css'); $config->styles->add('/site/templates/assets/css/calendar.css'); $config->scripts->add('/site/templates/assets/js/cal.js'); include("./includes/head.inc");?> <div id="calendar"></div> <? include("./includes/footer.inc"); } // end else ?> head.inc <!DOCTYPE HTML> <html> <head> <title><?=$page->title?></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- CSS includes defined via $config->styles->add --> <?php foreach($config->styles as $url) echo "<link rel='stylesheet' type='text/css' href='$url' />";?> <!-- include jQuery --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type="text/javascript"></script> <script>!window.jQuery && document.write(unescape('%3Cscript src="/site/templates/assets/js/jquery-1.6.3.min.js"%3E%3C/script%3E'))</script> <!--js includes defined via $config->scripts->add --> <?php foreach($config->scripts as $url) echo "<script type='text/javascript' src='$url'></script>";?> </head> <body> footer.inc </body> </html>1 point
-
After too many hours busy with the same site, start to feel groggy and inspiration dries up, I need to see again how relative everything is and give my head a fresh reboot:1 point
-
That is pretty nice way to do it. Usually my sites have lots of metadata pages, so I collect them all under page called /tools/1 point
-
Yes addHook is to add a new method to whatever you like. addHookProperty is to add a property to the object. addHookAfter/Before is hooking into events like save etc. You could also go with something like $page->image->greyscale(100,100)->url; and just leave out the size() and do it in greyscale. Endless possibilities.1 point
-
Hi Giovanni and welcome! This is a very interesting first question You can write an autoload module which adds the greyscale method with a Hook to the PageImage class. Check out the /site/modules/Helloworld.module for examples. I have never used these hooks which extend a class with methods, but it would be something like this: Edit: I don't know if you can access variables from the Pageimage class inside the makeGreyscale method. So sample code below could be completely wrong. Ryan, Soma, Apeisa, Nik, Teppo etc. where are you? //In your module... public function init() { $this->addHook('Pageimage::greyscale', $this, 'makeGreyscale'); } //This is only sample code... public function makeGreyscale(HookEvent $event) { $img = $event->object; //Make a new image file that is greyscale. Otherwise you could apply your image filter directly to $img $basename = basename($img->basename(), '.' . $img->ext()); $basename .= '-greyscale.' . $img->ext(); $filename = $img->pagefiles->path() . $basename; $greyscale = clone $img; $greyscale->setFilename($filename); //Make it greyscale //... $event->return = $greyscale; }1 point
-
Wow. I just stumbled on this: http://processwire.com/api/variables/user/ It looks like I don't even *need* to know the structure behind user accounts. By using the PW API, I can generate user accounts all day long... Am I right? So. Awesome. Thanks, Ryan! And everyone else here, of course. lol1 point
-
Updated Ryans/drilonbs code to include marker cluster and custom icons. Marker clusters need this script to work. Here are the updated scripts: https://gist.github.com/4648340 Use at your own risk... If anyone with actual javascript skills could take a look at it, i'd appreciate it. /Mats1 point
-
1 point
-
Based on what I'm understanding from your last message, I think you should skip keeping the separate table. It just sounds like extra, unnecessary work, unless there's something more to this project that I don't yet understand. Instead, I think you should have your cron job execute a script that bootstraps ProcessWire and takes care of all the adding, updating and deleting of records consistent with the web service you are reading from. This is something that I think ProcessWire is particularly good at, because it's been designed for this from the beginning (it's something I have to do with a lot of my client work). Whether XML or JSON doesn't matter much, as PHP includes the ability to read from either type quite easily. Though like the other guys here, I generally prefer JSON just because it's less verbose and less fuss. If JSON, you'll pull the feed and use PHP's json_decode() to convert it to an array. If XML, you'll use PHP's SimpleXML to convert it to an array. Once you've got the array of raw data, you'll iterate through it and add, update, or delete pages in ProcessWire to make it consistent with the data you are pulling from the web service. Live, working example I think that the best way to demonstrate it is with a live, working example. This one uses the existing modules.processwire.com/export-json/ feed. You might also want to see the feed in human-readable mode to get a better look at the format. Below is a shell script that bootstraps ProcessWire, reads from that feed and maintains a mini "modules directory" site, on your own site. I made this feed so that it can be tested and used on a brand new installation using the basic profile (included with PW). If left how it is, it'll create a mini modules directory site below the '/about/what/' page and use the template 'basic-page' for any pages it adds. But you can run this on any ProcessWire installation by just editing the script and changing the parent from '/about/what/' to something else, and changing the template from 'basic-page' to something else, if necessary. This script assumes that the template used has 3 fields: title, body, and summary. The 'basic-page' template in PW's default profile already has these. If you adapt this for your own use, you'd probably want to change it to use more specific fields consistent with what you need to store on your pages. In this example, I'm just building a 'body' field with some combined data in it, but that's just to minimize the amount of setup necessary for you or others to test this… The purpose is that this is something you can easily run in the default profile without adding any new templates, fields, pages, etc. 1. Paste the following script into the file import-json.php (or download the attachment below). For testing purposes, just put it in the same directory where you have ProcessWire installed. (If you place it elsewhere, update the include("./index.php"); line at the top to load ProcessWire's index.php file). 2. Edit the import-json.php file and update the first line: "#!/usr/bin/php", to point to where you have PHP installed (if not /usr/bin/php). Save. 3. Make the file executable as a shell script: chmod +x ./import-json.php 4. Run the file at the command line by typing "./import-json.php" and hit enter. It should create about 95 or so pages under /about/what/. Take a look at them. Run it again, and you'll find it reports no changes. Try making some changes to the text on 1 or 2 of the pages it added and run it again, it should update them. Try deleting some of it's pages, and it should add them back. Try adding some pages below /about/what/ on your own, run it again, and it should delete them. import-json.php #!/usr/bin/php <?php // replace the path in the shabang line above with the path to your PHP // bootstrap ProcessWire. Update the path in the include if this script is not in the same dir include("./index.php"); // if you want to run this as a PW page/template instead, remove everything above (except the PHP tag) // save our start time, so we can find which pages should be removed $started = time(); // keep track of how many changes we've made so we can report at the end $numChanged = 0; $numAdded = 0; $numTrashed = 0; // URL to our web service data $url = 'http://modules.processwire.com/export-json/?apikey=pw223&limit=100'; // get the data and decode it to an array $data = json_decode(file_get_contents($url), true); // if we couldn't load the data, then abort if(!$data || $data['status'] != 'success') throw new WireException("Can't load data from $url"); // the parent page of our items: /about/what/ is a page from the basic profile // update this to be whatever parent you want it to populate... $parent = wire('pages')->get('/about/what/'); if(!$parent->id) throw new WireException("Parent page does not exist"); // iterate each item in the feed and create or update pages with the data foreach($data['items'] as $item) { // see if we already have this item $page = $parent->child("name=$item[name]"); // if we don't have this item already then create it if(!$page->id) { $page = new Page(); $page->parent = $parent; $page->template = 'basic-page'; // template new pages should use $page->name = $item['name']; echo "\nAdding new page: $item[name]"; $numAdded++; } // now populate our page fields from data in the feed $page->of(false); // ensure output formatting is off $page->title = $item['title']; $page->summary = $item['summary']; // To keep it simple, we'll just populate our $page->body field with some combined // data from the feed. Outside of this example context, you'd probably want to // populate separate fields that you'd created on the page's template. $body = "<h2>$item[summary]</h2>"; $body .= "<p>Version: $item[module_version]</p>"; foreach($item['categories'] as $category) $body .= "<p>Category: $category[title]</p>"; $body .= "<p><a href='$item[download_url]'>Download</a> / <a href='$item[url]'>More Details</a></p>"; $page->body = $body; // print what changed $changes = $page->getChanges(); if(count($changes)) { $numChanged++; foreach($changes as $change) echo "\nUpdated '$change' on page: $page->name"; } // save the page $page->save(); } // now find pages that were not updated above, which indicates they // weren't in the feed and should probably be trashed $expired = $parent->children("modified<$started"); foreach($expired as $page) { echo "\nTrashing expired page: $page->name"; $page->trash(); // move to trash $numTrashed++; } echo "\n\n$numAdded page(s) were added"; echo "\n$numChanged page(s) were changed"; echo "\n$numTrashed page(s) were trashed\n"; import-json.php.txt Running the script as a cron job: You can instruct your cron job to run the script and it should be ready to go. You may want to move it to a non web accessible location for more permanent use. You'll also want to update your bootstrap "include()" line at the top to have the full path to your ProcessWire index.php file, as your cron job probably isn't executing it from the web root dir like you were manually. Running the script as a template file: You can run this script as a template file on a page by removing the include() line and everything above it with this line: <pre><?php Place it in your /site/templates/ directory, add the template from PW admin, and create a page that uses it, then view it.1 point