Leaderboard
Popular Content
Showing content with the highest reputation on 04/18/2013 in all areas
-
You're mixing vanilla PHP with PW API. Selectors are PW specific. I don't know you guys know that you can also do this in PW (usually people miss this) if($page->is("template=home|basic-page")) echo "has template";8 points
-
Here you go: http://modules.processwire.com/modules/fieldtype-text-unique/6 points
-
.. or optionally this way, especially if there are more than two options: <?php if ( in_array($page->template, array('home', 'basic-page')) ) echo "something"; In your example syntax you're comparing value of $page->template (which here returns template name as a string) with regular PHP string "home|basic-page". You can't include conditional logic within strings, they're essentially just chunks of plain text4 points
-
The simple PHP OR comparison solution is very common. The in_array solution is more flexible. The PW solution owns them all =)3 points
-
I found a documentation about the famous silk road by the swiss journalist Peter Gysling. Watch it: http://seidenstrasse.srf.ch/de/home.html You just have to scroll down, unfortunatly the site is in german but the pics and the technical realisation is just worth it.2 points
-
2 points
-
@pwired - i'm sure everyone has a different approach to this. This is how i have approached the last few sites: 1.) in the admin, define fields and templates, and add content. I stay in the backend for a while (and don't bother making the actual php files for the templates). Once the backend is stable (data structure of fields and templates, page tree) and there is enough content then i will start to 'wire up' the front end. 2.) Separately design the frontend, using whatever tools you would usually use, optionally on whatever framework you prefer (foundation, bootstrap); sometimes this part can be as simple as using html5 kickstart, or as complex as going through wireframing process etc.. i like to work with a design that is close to finished before 'wiring' it. 3.) the wiring part is pretty easy; it's good to have a list of all your field names and templates...you can configure the files in various ways, have a look at some of the site profiles for examples of this...2 points
-
Ah no, sorry those images are being auto-generated from hhhhold.com! (Not my fault) this is purely for dev purposes! Sorry about the confusing explanation, it's kind of hard to explain in words. If you hover over "Gallery", it shifts left so you need to be able to click on the whole thing (otherwise it's annoying for the user). Your (Diogo) code worked great but when you click Gallery again to close it, you have to click twice for some reason. I'm just looking for a simple way of having the hover and two click methods working smoothly. I do appreciate you taking a look, thanks again!2 points
-
this would be pretty common <?php if ( ($page->template == 'home') || ($page->template == 'basic-page') ) echo "something"; ?>2 points
-
Here is a recent site done in processwire: http://licoriceensemble.com/ modules used include formbuilder procache cropimage version control for text fields after save actions based on a template by the great team at Elemis.2 points
-
Just wanted to share what I recently used to create forms in modules and in frontend using the API and Inputfield modules PW provides and uses on its own. I think many newcomers or also advanced user aren't aware what is already possible in templates with some simple and flexible code. Learning this can greatly help in any aspect when you develop with PW. It's not as easy and powerful as FormBuilder but a great example of what can be archieved within PW. Really? Tell me more The output markup generated with something like echo $form->render(); will be a like the one you get with FormBuilder or admin forms in backend. It's what PW is made of. Now since 2.2.5~ somewhere, the "required" option is possible for all fields (previous not) and that makes it easier a lot for validation and also it renders inline errors already nicely (due to Ryan FormBuilder yah!). For example the Password inputfield already provides two field to confirm the password and will validate it. De- and encryption method also exists. Or you can also use columns width setting for a field, which was added not so long ago. Some fields like Asm MultiSelect would require to also include their css and js to work but haven't tried. Also file uploads isn't there, but maybe at some point there will be more options. It would be still possible to code your own uploader when the form is submitted. Validation? If you understand a little more how PW works with forms and inputfields you can simply add you own validation, do hooks and lots of magic with very easy code to read and maintain. You can also use the processInput($input->post) method of a form that PW uses itself to validate a form. So getting to see if there was any errors is simply checking for $form->getErrors();. Also the $form->processInput($input->post) will prevent CSRF attacks and the form will append a hidden field automaticly. It's also worth noting that processInput() will work also with an array (key=>value) of data it doesn't have to be the one from $input->post. Styling? It works well if you take your own CSS or just pick the inputfields.css from the templates-admin folder as a start. Also the CSS file from the wire/modules/InputfieldRadios module can be helpful to add. And that's it. It's not very hard to get it display nicely. Here an code example of a simple form. <?php $out = ''; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'subscribe-form'); // create a text input $field = $modules->get("InputfieldText"); $field->label = "Name"; $field->attr('id+name','name'); $field->required = 1; $form->append($field); // append the field to the form // create email field $field = $modules->get("InputfieldEmail"); $field->label = "E-Mail"; $field->attr('id+name','email'); $field->required = 1; $form->append($field); // append the field // you get the idea $field = $modules->get("InputfieldPassword"); $field->label = "Passwort"; $field->attr("id+name","pass"); $field->required = 1; $form->append($field); // oh a submit button! $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Subscribe"); $submit->attr("id+name","submit"); $form->append($submit); // form was submitted so we process the form if($input->post->submit) { // user submitted the form, process it and check for errors $form->processInput($input->post); // here is a good point for extra/custom validation and manipulate fields $email = $form->get("email"); if($email && (strpos($email->value,'@hotmail') !== FALSE)){ // attach an error to the field // and it will get displayed along the field $email->error("Sorry we don't accept hotmail addresses for now."); } if($form->getErrors()) { // the form is processed and populated // but contains errors $out .= $form->render(); } else { // do with the form what you like, create and save it as page // or send emails. to get the values you can use // $email = $form->get("email")->value; // $name = $form->get("name")->value; // $pass = $form->get("pass")->value; // // to sanitize input // $name = $sanitizer->text($input->post->name); // $email = $sanitizer->email($form->get("email")->value); $out .= "<p>Thanks! Your submission was successful."; } } else { // render out form without processing $out .= $form->render(); } include("./head.inc"); echo $out; include("./foot.inc"); Here the code snippet as gist github: https://gist.github.com/4027908 Maybe there's something I'm not aware of yet, so if there something to still care about just let me know. Maybe some example of hooks could be appended here too. Thanks Edit March 2017: This code still works in PW2.8 and PW3.1 point
-
1 point
-
Here is a simple script I wrote for my project and I thought maybe someone will find it useful just to avoid writing obvious things. If you use File type field in your template and want to display added files in nice graphic manner instead of ordinary file name this code may help. The script - when included to the template - recognizes extension of added file and displays apprioprate icon as an output on the page. In present form the script can deal with these file extensions: pdf doc docx xls xlsx xlsm mp3 txt ppt pptx wmv mp4 mpeg html The file extensions mentioned above must of course be added in "Details" section of File field in admin panel. <?php $fsize = 90; //icon px width in output $field = 'file'; //name of the field in ProcessWire panel $pdfImg = 'http://cdn1.iconfinder.com/data/icons/CrystalClear/128x128/mimetypes/pdf.png'; $docImg = 'http://cdn2.iconfinder.com/data/icons/sleekxp/Microsoft%20Office%202007%20Word.png'; $pptImg = 'http://cdn2.iconfinder.com/data/icons/sleekxp/Microsoft%20Office%202007%20PowerPoint.png'; $txtImg = 'http://cdn1.iconfinder.com/data/icons/CrystalClear/128x128/mimetypes/txt2.png'; $xlsImg = 'http://cdn2.iconfinder.com/data/icons/sleekxp/Microsoft%20Office%202007%20Excel.png'; $audioImg = 'http://cdn2.iconfinder.com/data/icons/oxygen/128x128/mimetypes/audio-x-pn-realaudio-plugin.png'; $videoImg = 'http://cdn4.iconfinder.com/data/icons/Pretty_office_icon_part_2/128/video-file.png'; $htmlImg = 'http://cdn1.iconfinder.com/data/icons/nuove/128x128/mimetypes/html.png'; $fileImg = 'http://cdn3.iconfinder.com/data/icons/musthave/128/New.png'; $files = $page->$field; foreach ($files as $f) { switch (get_file_extension($f)) { case 'pdf': $img = $pdfImg; break; case 'doc': $img = $docImg; break; case 'docx': $img = $docImg; break; case 'txt': $img = $txtImg; break; case 'xls': $img = $xlsImg; break; case 'xlsx': $img = $xlsImg; break; case 'xlsm': $img = $xlsImg; break; case 'ppt': $img = $pptImg; break; case 'pptx': $img = $pptImg; break; case 'mp3': $img = $audioImg; break; case 'wmv': $img = $videoImg; break; case 'mp4': $img = $videoImg; break; case 'mpeg': $img = $videoImg; break; case 'html': $img = $htmlImg; break; default: $img = $fileImg; break; } echo "<a href='{$f->url}' target='_blank'><img src='$img' title='$f' width='$fsize' /></a><p>{$f->description}</p>"; } function get_file_extension($f) { $ftype = pathinfo($f); return $extension = $ftype['extension']; } ?> show-filetype-icon.php1 point
-
I just switched form CodeKit to Guard. I have more control over how things work, it’s cross platform and more team friendly, and it's free. Might be worth a look for you guys as well: "Guard is a command line tool to easily handle events on file system modifications." https://github.com/guard/guard Here's a nice intro by Jeffrey Way on Nettuts+ http://net.tutsplus.com/tutorials/tools-and-tips/guard-is-your-best-friend/ Cheers1 point
-
Welcome jzvanenk! Answering directly to your question. The snippets don't go inside the fields, they go directly on the template files. The code you have on the template files is PHP, just like the snippets yo are talking about. So, when you have this on the planets tutorial: <html> <head> <title><?php echo $page->title; ?></title> </head> <body> <h1><?php echo $page->title; ?></h1> <h2>Type: <?php echo $page->planet_type; ?>, Age: <?php echo $page->planet_age; ?> years</h2> <p><?php echo $page->planet_summary; ?></p> </body> </html> You can also have this: <html> <head> <title><?php echo $page->title; ?></title> </head> <body> <header> <ul id="all-planets"> <?php // list all planets and link to their pages foreach($pages->get("/planets/")->children as $planet){ echo "<li><a href='{$planet->url}'>{$planet->title}</a></li>"; } ?> </ul> </header> <h1><?php echo $page->title; ?></h1> <h2>Type: <?php echo $page->planet_type; ?>, Age: <?php echo $page->planet_age; ?> years</h2> <p><?php echo $page->planet_summary; ?></p> </body> </html> edit: that is the same as this (entering and leaving php to write html): <html> <head> <title><?php echo $page->title; ?></title> </head> <body> <header> <ul id="all-planets"> <?php foreach($pages->get("/planets/")->children as $planet): ?> <li> <a href="<?php echo $planet->url; ?>"><?php echo $planet->title; ?></a> </li> <?php endforeach; ?> </ul> </header> <h1><?php echo $page->title; ?></h1> <h2>Type: <?php echo $page->planet_type; ?>, Age: <?php echo $page->planet_age; ?> years</h2> <p><?php echo $page->planet_summary; ?></p> </body> </html>1 point
-
Ryan, considering the PHP versions after 5.3.7 have the Blowfish problem solved shouldn't the check as follows? public function supportsBlowfish() { return version_compare(PHP_VERSION, '5.3.7') >= 0 && defined("CRYPT_BLOWFISH") && CRYPT_BLOWFISH; }1 point
-
1 point
-
1 point
-
I'm guessing maybe the subtle silhouetted figure in the background.. She was there a minute ago...now she's gone...1 point
-
Ryan, I'm really impressed, amazed at your level of productivity, responsiveness (and generosity)!1 point
-
1 point
-
You don't need it to be a real link. just give the whole area a class and bind the click event to that class. then, remove the class when the area is clicked. To style that class to look like a link you only need cursor:pointer. $('.linkClass').click(function(){ $(this). animate({'margin-left':0}). removeClass('linkClass'); });1 point
-
I've looked into this, and don't think it's got anything to do with use of a language pack or admin theme. I tried executing the query manually in PhpMyAdmin and MySQL simply doesn't trigger an error when inserting duplicate values. It just skips the query. Maybe there are some conditions under which it will report an error, but not that I could find. I think the problem is that the query for inserting/updating fields looks like this: The "ON DUPLICATE KEY" part is where it's at. But we need that, otherwise we'd have to add another select to every insert/update just to see if something is already present. So it looks like any future fieldtype that supports a UNIQUE index would have to implement it's own savePageField() method with some more overhead to check things out and decide whether to insert or update. As a result, you can have a UNIQUE index right now, but it's just being enforced rather than reported. But making a new FieldtypeTextUnique or something like that would be a way to solve it pretty easily.1 point
-
I like your idea, but it's also very simple to do this only with css http://www.hongkiat.com/blog/css3-attribute-selector/, or if you really want it to be crossbrowser you can also do this in php: echo "<a href='{$f->url}' class='file-". get_file_extension($f) . "'>" and use the class on the css. edit: not saying my solutions are better though1 point
-
Blowfish hashing was added to PHP in 5.3, so any version 5.3 and newer supports it. However, a security problem was found in versions of PHP 5.3 prior to 5.3.7, so they fixed it. Newer versions of PHP are still compatible with the old, but versions prior to 5.3.7 are not compatible with passwords generated on newer versions of PHP. Since your host is using PHP 5.3.3, this is likely why you ran into an issue. But a commercial hosting provider should probably not be using a PHP version earlier than 5.3.7 due to that security issue. So the workaround is probably not a good idea since it is circumventing that. I strongly recommend asking your host to upgrade the PHP version.1 point
-
Soma, while I wasn't able to duplicate that here, I was able to find a bug when using just parent.title, so I'm wondering if it might also be responsible for the result you were getting. Can you try the latest dev branch and let me know if you are still experiencing the error?1 point
-
$fredi should work from both, but it might be you need to load $fredi again ($fredi = $modules->get("Fredi")) in your child template. <?php $fredi = $modules->get("Fredi"); foreach($page->children as $child) { echo $fredi->render("body", $child); echo $child->render(); } Code snippet above doesn't show edit links even for superuser? How about changing it to $fredi->body($child)?1 point
-
This depend on your needs for project. I always deleting default pages, fields, .... You can use blank profile for this too.1 point
-
This is true as the requests are delivered as static HTML files. So it doesn't touch the DB unless the request isn't cached. It is a great way to let your server handle a lot more traffic. But regardless of what caching is in place, if you start to see a "too many connections" message regularly, then it's time to talk to your web host to see if the amount of traffic you are getting would benefit from a higher-end hosting plan. There are also cases with some web hosts where the resources are simply oversold and you might see those kinds of MySQL error messages even if you aren't getting a lot of traffic. In those cases, it's a good idea to find a new web host.1 point
-
1 point
-
It has been there since 1500BC (Ryan added it on launch): http://modules.processwire.com/modules/process-redirects/1 point
-
@totoff: that was just the name of the variable Ryan used in his example. See how he checks and sets it in the first code block? You can store any custom variables you might need in $session and then use them on any other page for that particular (user-specific) session: $session->referrer_id = $page->id; $session->interesting_fact = "Chuck norris can slam a revolving door.";1 point
-
You can use the InputfieldMarkup to add custom markup. $field = $modules->get("InputfieldMarkup"); $field->markupText = "<p>your html string here</p>";1 point
-
For what it's worth, I always put semicolons after even single lines, not so much in the case @pwired cites above, but in more general cases. Say I have this <?php $foo = "bar"; ?> and then I realise I need to add another line <?php $foo = "bar"; $baz = "qux"; ?> I don't need to remember to add a semicolon to the first line when editing to add the second line, because it's already there.1 point
-
@photoman I'm not sure if this is what you want, but here goes: <?php foreach($page->children as $child) { echo $fredi->render("all|the|fields|you|want", $child); echo $child->render(); } ?>1 point
-
I'm with teppo - I always use the semicolon, and he's right on it being optional (though I would suggest it should be standardised on the default template for those not as familiar with PHP as well as for consistency). But then again I always stick my curly brackets at the end of a line as well rather than on their own like all the cool kids, so I'm a heathen1 point
-
1 point
-
My little workaround <?php if(!$input->post->import && !$fieldsImport && !$input->post->generate): ?> <hr /> <h4>Separate Fields by comma like this: i,am,a,new,field</h4> <form name="importform" method="post" action="./"> <div class="span3"> <p><label>Field Prefix?</label> <input type="text" name="prefix" /></p> </div> <div class="span3"> <p><label>Field Tag?</label> <input type="text" name="fieldtag" /></p> </div> <div class="span3"> <p><label>assign to </label> <select name="template"> <option></option> <?php foreach($templates as $singleTemplate): ?> <option value="<?php echo $singleTemplate->name ?>"><?php echo $singleTemplate->name ?></option> <?php endforeach ?> </select> </p> </div> <div class="span12"><textarea name="string"><?php echo $input->post->string ?></textarea><p><input type="submit" name="import" value="import" /></p></div> </form> <?php endif ?> <?php if($input->post->import){ $fieldsImport = $input->post->string; $fieldsImport = explode(',', $fieldsImport); } if($fieldsImport): ?> <hr /> <form name="fieldform" method="post" action="./"> <div class="row"><div class="span12"><hr /></div></div> <ul> <?php foreach($fieldsImport as $fieldNew): ?> <?php $alleTypes = '<select class="required" name="'.$fieldNew.'"> <option selected="selected" value=""/> <option value="Checkbox">Checkbox</option> <option value="Email">Email</option> <option value="File">File</option> <option value="Image">Image</option> <option value="Page">Page</option> <option value="Text">Text</option> <option value="Textarea">Textarea</option> <option value="URL">URL</option> </select>'; ?> <li><?php echo $fieldNew ?> <?php echo $alleTypes ?></li> <?php endforeach ?> </ul> <input type="hidden" value="<?php echo $input->post->prefix ?>" name="prefix" /> <input type="hidden" value="<?php echo $input->post->template ?>" name="template" /> <input type="hidden" value="<?php echo $input->post->fieldtag ?>" name="tag" /> <input type="submit" name="generate" value="generate" /> </form> <?php endif ?> <?php if($input->post->generate){ $prefix = $input->post->prefix; $tags = $input->post->tag; $template = $input->post->template; $addedFields = $fieldgroups->get('name='.$template); foreach($input->post as $key => $val){ if($key != 'prefix' && $key != 'tag' && $key != 'generate' && $key != 'template'){ $f = new Field; if($prefix){$f->name = $prefix.'_'.$key;}else{$f->name = $key;} $f->type = $val; $f->save(); $f->tags = '-'.$tags; $f->save(); $addedFields->add($f); $addedFields->save(); echo "$key = $val <br />"; } } } ?>1 point
-
I'm planning to bring the same import/export system that's in FormBuilder to Fields and Templates.1 point
-
Thanks Ryan. Ok I think I can work around it. It's not a massive requirement to get it working without Javascript it's just I was trying to build an admin theme which was as lean as possible and I don't see the need for Javascript being used to generate the PageList. Also there is a weird arrow that appears when the list loads. My thinking was to go back to basics and start from scratch. Nico. I'll send you a PM, and maybe you can help me get round some of the issues I'm having.1 point
-
have had some hours last evening (exactly 8 'til now) I think I can finish the import next time I get 2-3 hours. So, don't know when now. There is some trouble with chars in filenames and ID3-Tags that want not get into the DB, so I have played around with sanitizer, but have to go deeper and change the current behave. Here are a screencast of the backend, starting with an empty DB (no mp3 data in it) set one or more pathes, do a quick filesystem scan (without parsing ID3 etc) envoke a command line script to perform scan with parsing mp3 files and pull data into DB: (please look fullscreen or otherwise enlarge Video) https://youtu.be/Re08fuNFRao1 point
-
Also look at core modules if you arent sure about something. Look up ProcessPageList.module which is configurable.1 point
-
No idea what this is unless it's what it seems (too many people hitting your site at once?). But I assume the ProCache module would avoid this happening as, I think, it means most people are served content without PHP or DB hits. I've no idea how it does it and like a high quality magic trick I am quite content never knowing I'm just glad it's excellent.1 point
-
http://wonder-tonic.com/geocitiesizer/content.php?theme=2&music=8&url=http://processwire.com/ or indeed http://wonder-tonic.com/geocitiesizer/content.php?theme=3&music=5&url=http://processwire.com/talk/topic/3267-simply-interesting-for-processwire/ (2nd one is a bit meta)1 point
-
Have you looked in the modules download area for site profiles? I haven't used it but maybe you are after something like what Soma submitted.1 point
-
Funnily enough I'm building one currently in ProcessWire but will be a while before it's ready1 point
-
Some $_SERVER variables like HTTP_REFERER can be manipulated by the client, so it's probably not safe to utilize without sanitization. However, since you are trying to keep track of the last page, I'd suggest using the $session variable. Place this at the top of your page before output: if($session->referrer_id) $page->referrer_page = $pages->get($session->referrer_id); $session->referrer_id = $page->id; Now anytime you want to access the last page, you'd do this: if($page->referrer_page) { echo "Last page you visited was: " echo "<a href='{$page->referrer_page->url}'>{$page->referrer_page->title}</a>"; }1 point
-
While it may be okay to do once in awhile, I would avoid structuring your site in a way that requires uploading the same image in multiple places. Instead, pull from the source page via the API and use the image. An example of this would be a site structure like this: /about/ /contact/ /press/ /history/ Lets say that you want all these pages to have the same header image. Rather than populating a header_image field on each page with the same image, populate it on just your /about/ page and let the others pull from it. Even if all the pages use the same template file, you can achieve it with this: $image = $page->header_image; if(!$image) $image = $page->rootParent->header_image; if($image) echo "<img src='{$image->url}'>"; The approach here is to give each page the ability to define it's header image, but make it optional. When it's not populated, it grabs the default from the root parent page (/about/). But lets say your structure is a little deeper than that: /about/ /contact/ /directions/ /press/ /history/ In that case, you may want to have it inherit the header image from the nearest parent that has it defined. So /about/contact/directions/ would show the header image from /about/contact/ (if it had one) rather than the one from /about/: $parent = $page; do { $image = $parent->header_image; $parent = $parent->parent; } while(!$image && $parent->id); if($image) echo "<img src='{$image->url}'>"; There may be other cases outside of the example above where you might have the need of using an image defined on another specific page. In that case, use a page reference field. You might call it header_image_page. It would essentially say "I want to display the header image from that page". This is a little better than a direct file reference because your image will still work even if the source page changes it. $image = $page->header_image_page->header_image; if($image) echo "<img src='{$image->url}'>";1 point