Leaderboard
Popular Content
Showing content with the highest reputation on 04/23/2013 in all areas
-
Diogo's code above taught me a lot and saved me lots of time, but I just noticed one tweak that I think should be made: foreach($mypage->fields as $f) { $mypage->set($f->name, $form->get($f->name)->value); } should really be: foreach($mypage->fields as $f) { if (!in_array($f->name, $myfields)){ $mypage->set($f->name, $form->get($f->name)->value); } } so as to avoid "Notice: Trying to get property of non-object" errors on any fields that were excluded. Also, I had to include: $mypage->of(false); // turn off output formatting before setting values $mypage->save(); I don't know whether this is something specific to my use, or whether it's just obvious and so wasn't included, but though it might help someone else.2 points
-
I was working over this code from apeisa http://processwire.c...t__20#entry1364 and wanted to share the result with you all. Basically, this allows you to mirror the admin form from a given page to the frontend. To give some flexibility, you can fill an array with the fields to exclude —or else, the fields to include— on the output. EDIT: I forgot to tell... this works well with regular fields (text, textareas, checkboxes, radios, multiple choice, etc), but didn't manage to make it work well with images, for instance. So, here is the code: <?php // Get the page you need to edit $mypage = $pages->get('/some/page/'); // Populate with the names of the fields you want to exclude OR include (see instructions below) // Leave empty to output all the fields $myfields = array('body', 'email'); $form = $modules->get('InputfieldForm'); $fields = $mypage->getInputfields(); // If array is not empty use it to filter the fields if ($myfields){ foreach($fields as $f){ // Output all the fields minus the ones listed in the $myfields array // Instead, to output only the fields that are in the array, remove the (!) from the condition if (!in_array($f->name, $myfields)){ $form->append($f); } } } // Else, include all the fields else { $form->append($fields); } // Add save button $field = $this->modules->get('InputfieldSubmit'); $field->attr('id+name', 'submit_save'); $field->attr('value', 'Save'); $field->label = "submit herei"; $form->append($field); // Process the form // (code replaced by a new one provided by Ryan) if($input->post->submit_save) { $form->processInput($input->post); if(!$form->getErrors()) { $mypage->of(false); // turn off output formatting before setting values foreach($mypage->fields as $f) { $mypage->set($f->name, $form->get($f->name)->value); } } } include("./head.inc"); // Render the form echo $form->render(); include("./foot.inc");2 points
-
Hi Everone - I'm still a quite new to PW (currently using mostly CMS Made Simple) and loving it due to amazing flexibility it offers! My case is a little weird and despite being quite simple, I haven't quite yet figured out the best way to achieve this with PW. I have a simple website (6 pages only), that needs to offer content in two languages. The two versions have a similar sitemap, but not quite the same. In one of the languages there won't be the news section, the rest will be the same - but we would like to keep the structure independent from each other, so other pages can be added on each separately. Taking this in consideration, the "two roots" approach would probably the best one and I've been looking on how to do that in the last couple of days and found a lot of scattered information in the forums, for example: Using two separate roots: http://codeordie.posterous.com/multi-lingual-sites-with-the-processwire-cms Multi language Page names/URLS: http://processwire.com/talk/topic/2979-multi-language-page-names-urls/page-3 etc... Can someone help by pointing me out to one doc that has it all - if there is one? I've also looked around on the tutorials section, but wasn't too lucky. In my opinion, this doc should be something like this, should live withing Tutorials and stay fresh as Ryan develops new modules: =========================================================== Approach 1) Multilingual website with Same Pagetree a) How to install: this would be a great example http://processwire.com/talk/topic/2979-multi-language-page-names-urls/?p=33412 b) Language Switcher code examples: Some code examples on how to do that c) Conditional static elements (for templating purposes): If en then -> ... show this else -> show this... d) Special Cases: Hide page from tree in specific language (hide from menu and backend if possible) Remember what language user chose (cookie?) Static content blocks that are diferent based on language and aren't based on templates (ie: editable footers) Real examples: http://www.tripsite.comApproach 2) Multilingual website with Separate Pagetrees a) How to install: this would be a great example http://codeordie.posterous.com/multi-lingual-sites-with-the-processwire-cms (haven't found any reference in PW's forums) and it would be good to have an example that doens't need YAML. b) Language Switcher code examples: Some code examples on how to do that c) Conditional static elements (for templating purposes): If "en" then -> ... show this else -> show this.. d) Special Cases: Hide root reference form urls (en/about-us --> /about-us) Remember what language user chose (cookie?) Static content blocks that are diferent based on language and aren't based on templates (ie: editable footers) Real examples: ?=========================================================== Could somene help me getting this doc together to publich it in the tutorials section? I appologize if this got a little confusing. Thanks! jw1 point
-
Hello professional PW world! Not being a developer/designer myself (its rather my hobby), I've liked PW for its simplicity and flexibility and even developed simple site with it. However more complex sites require time to grow professionalism in PHP/JS/design/etc - something that I can't get quickly and without impact on my main work. As a result, I'd like to post job here. In brief - I'm looking for professional PW + PHP developer for full-cycle PW-powered site development. Site will be analogy of coachup.com. Differences come from content that will be provided during development (another business area, specifically, education + content language is Russian (but I'll need to leave possibility to easily switch to other languages)). All the rest (front-end design concept, site structure, frond-end and back-end functionality, etc) is the same. Please check this site to get full picture and understand scope of work. Take into account that functionality includes work with external APIs: authorization from social sites, Google maps, payment gateway, support chat. Hope this helps to estimate budget and time. Please contact me with questions and proposals at andrey.valiev@hotmail.com. Or leave comments here. Thank you! Best regards, Andrey P.S. As I plan to develop few other PW-powered sites, more job may come.1 point
-
@Henning: The Google documentation about creating sitemaps says: So basically each domain has one sitemap.xml. You put all of the pages in it.1 point
-
Teppo, thanks, will give that a try. For now I got Radek's solution working. I only need this one redirect so just made one extra template for this, without adding an extra field. The url is now hard coded like Radek showed. Radek thanks again!1 point
-
Hi, i made quick test and redirecting outside PW working good. For quick test put this code at begining of your home template. $url = "http://www.google.com"; $session->redirect($url);1 point
-
If it's a multiple page field (or no output formatting!) you just do $page->invoice_terms->add((int) $input->post->edit_status); add() works with page array, page or id's1 point
-
@jmartsch, I think you encounter the same as the previous poster? is openssl installed? I just pulled in an update from petsagouris with multitude of changes, one of which checks for the openssl module being installed. udpate 1.0.7 - multitude of fixed and code cleanup (@petsagouris) - added check for openssl module required for https download stream (@petsagouris) - added back to Modules Manager button on download/update screen1 point
-
Ah the config object from Pw is missing. Can you add this line of javascript anywhere before you include the JqueryWireTabs.js var config = {}; /* If it's not working, try adding the following lines too */ config.JqueryWireTabs = {}; config.JqueryWireTabs.rememberTabs = 1;1 point
-
Dear Soma, Thanks for that! Hey, now I'm using my Very First Hook! Woohoo! Your code works like a charm. Am I correct in thinking that I can rename the 3rd parameter, i.e. the local function? That's what I did, and it seems to work. Here's my code: function redirect_url_target_fix(HookEvent $event) { $page = $event->arguments[1]; if($page->open_in_new_tab) { $event->return = str_replace('href=','target="_blank" href=', $event->return); } } $treeMenu->addHookAfter('getTagsString', null, "redirect_url_target_fix"); echo $treeMenu->render($tree_menu_options); Best regards, Peter1 point
-
Thanks apeisa I didn't think of that. For anyone else who's interested just add this to your header instead of the usual call. Nice and simple. <?php $fredi = $modules->get("Fredi"); if ($user->isLoggedin()) { echo $fredi->renderScript(); };?> Totally understand your reasons for making the column widths 100% as the original concept was about editing on a field by field basis. My sites are built in blocks and I find myself grouping fields on a block by block basis as it's quicker for the client to edit and means I can output less edit links. It would be great to have the markup available to target with css even if it's not used in your default css file but either way I'm very happy. So good to have fredi.1 point
-
I have written a little module that extends Somas awesome Images Manager. Also it's written with Somas kind help, (thanks!) It adds auto filling of EXIF or IPTC fields where available on upload of new images through Images Manager. How to use it: You, of course have Images Manager installed and ready to run. Now you have to create some fields that should take your exif data: fieldname prefix is exif_ followed by the original exif-fieldname but lowercase! ( exif_author, exif_copyright, etc.) ALSO you have to create one TextArea field called (by default) image_exif, - this one and ... (not needed, only optional to get the full raw EXIF-data stored) all your exif_fields you have to add to the image-template that is used by Images Manager for creating the new Image Pages. then download and install the ImagesManagerMetadata module. here are a little screencast I've done with it: https://youtu.be/wjhJdT7Tf5Y this is alpha, version 0.0.2 ImagesManagerMetadata.zip1 point
-
The post isellsoap linked to above has Ryan's explanation on why it's not straightforward to compare two fields - and yes, there's a solution also. But I'd like to propose another solution as well in case you'd need better performance or native pagination (lots of pages for example). You could add a helper field "f1_f2_difference" and populate it on page save with the difference of field1 and field2 (field2-field1). Then you'd be able to do this: echo $pages->find("has_parent=/features/, f1_f2_difference>0"); There's an example of pretty much the same thing in the final post of this thread and for some more information read also this thread. But you've got a working solution already so there's probably no need to take this route . -- @adrian: your suggestion would be fine when the fields are in the same database table (like created and modified are). Here field1 and field2 are presumably custom fields and thus in their own tables. An SQL JOIN would still do it, but using selectors gives the advantage of grants and visibility being taken care of.1 point
-
1 point
-
What I've been doing in another module is removing all templates flagged as system. That's probably what you want to do here too. foreach ($this->templates as $t) { // skip system templates if (!($t->flags & Template::flagSystem)) { $f->addOption($t->id, $t->name); } }1 point
-
I recently had to setup front-end system to handle logins, password resets and changing passwords, so here's about how it was done. This should be functional code, but consider it pseudocode as you may need to make minor adjustments here and there. Please let me know if anything that doesn't compile and I'll correct it here. The template approach used here is the one I most often use, which is that the templates may generate output, but not echo it. Instead, they stuff any generated output into a variable ($page->body in this case). Then the main.php template is included at the end, and it handles sending the output. This 'main' template approach is preferable to separate head/foot includes when dealing with login stuff, because we can start sessions and do redirects before any output is actually sent. For a simple example of a main template, see the end of this post. 1. In Admin > Setup > Fields, create a new text field called 'tmp_pass' and add it to the 'user' template. This will enable us to keep track of a temporary, randomly generated password for the user, when they request a password reset. 2a. Create a new template file called reset-pass.php that has the following: /site/templates/reset-pass.php $showForm = true; $email = $sanitizer->email($input->post->email); if($email) { $u = $users->get("email=$email"); if($u->id) { // generate a random, temporary password $pass = ''; $chars = 'abcdefghjkmnopqrstuvwxyz23456789'; // add more as you see fit $length = mt_rand(9,12); // password between 9 and 12 characters for($n = 0; $n < $length; $n++) $pass .= $chars[mt_rand(0, strlen($chars)-1)]; $u->of(false); $u->tmp_pass = $pass; // populate a temporary pass to their profile $u->save(); $u->of(true); $message = "Your temporary password on our web site is: $pass\n"; $message .= "Please change it after you login."; mail($u->email, "Password reset", $message, "From: noreply@{$config->httpHost}"); $page->body = "<p>An email has been dispatched to you with further instructions.</p>"; $showForm = false; } else { $page->body = "<p>Sorry, account doesn't exist or doesn't have an email.</p>"; } } if($showForm) $page->body .= " <h2>Reset your password</h2> <form action='./' method='post'> <label>E-Mail <input type='email' name='email'></label> <input type='submit'> </form> "; // include the main HTML/markup template that outputs at least $page->body in an HTML document include('./main.php'); 2b. Create a page called /reset-pass/ that uses the above template. 3a. Create a login.php template. This is identical to other examples you may have seen, but with one major difference: it supports our password reset capability, where the user may login with a temporary password, when present. When successfully logging in with tmp_pass, the real password is changed to tmp_pass. Upon any successful authentication tmp_pass is cleared out for security. /site/templates/login.php if($user->isLoggedin()) $session->redirect('/profile/'); if($input->post->username && $input->post->pass) { $username = $sanitizer->username($input->post->username); $pass = $input->post->pass; $u = $users->get($username); if($u->id && $u->tmp_pass && $u->tmp_pass === $pass) { // user logging in with tmp_pass, so change it to be their real pass $u->of(false); $u->pass = $u->tmp_pass; $u->save(); $u->of(true); } $u = $session->login($username, $pass); if($u) { // user is logged in, get rid of tmp_pass $u->of(false); $u->tmp_pass = ''; $u->save(); // now redirect to the profile edit page $session->redirect('/profile/'); } } // present the login form $headline = $input->post->username ? "Login failed" : "Please login"; $page->body = " <h2>$headline</h2> <form action='./' method='post'> <p> <label>Username <input type='text' name='username'></label> <label>Password <input type='password' name='pass'></label> </p> <input type='submit'> </form> <p><a href='/reset-pass/'>Forgot your password?</a></p> "; include("./main.php"); // main markup template 3b. Create a /login/ page that uses the above template. 4a. Build a profile editing template that at least lets them change their password (but take it further if you want): /site/templates/profile.php // if user isn't logged in, then we pretend this page doesn't exist if(!$user->isLoggedin()) throw new Wire404Exception(); // check if they submitted a password change $pass = $input->post->pass; if($pass) { if(strlen($pass) < 6) { $page->body .= "<p>New password must be 6+ characters</p>"; } else if($pass !== $input->post->pass_confirm) { $page->body .= "<p>Passwords do not match</p>"; } else { $user->of(false); $user->pass = $pass; $user->save(); $user->of(true); $page->body .= "<p>Your password has been changed.</p>"; } } // display a password change form $page->body .= " <h2>Change password</h2> <form action='./' method='post'> <p> <label>New Password <input type='password' name='pass'></label><br> <label>New Password (confirm) <input type='password' name='pass_confirm'></label> </p> <input type='submit'> </form> <p><a href='/logout/'>Logout</a></p> "; include("./main.php"); 4b. Create a page called /profile/ that uses the template above. 5. Just to be complete, make a logout.php template and create a page called /logout/ that uses it. /site/templates/logout.php if($user->isLoggedin()) $session->logout(); $session->redirect('/'); 6. The above templates include main.php at the end. This should just be an HTML document that outputs your site's markup, like a separate head.inc or foot.inc would do, except that it's all in one file and called after the output is generated, and we leave the job of sending the output to main.php. An example of the simplest possible main.php would be: /site/templates/main.php <html> <head> <title><?=$page->title?></title> </head> <body> <?=$page->body?> </body> </html>1 point