Jump to content

pwFoo

Members
  • Posts

    708
  • Joined

  • Last visited

Everything posted by pwFoo

  1. After long time haven't take a look at this try... In the above example I use two find() to get the chain reference current page -> assigned groups -> current user assigned? If the current user is referenced to the current loading page via a group membership, access will be allowed. It seems possible to do this check with one count() with Processwire?! $pages->count("id={$refPage}, refGroups.refUser={$user->id}"); $refPage = "current page" the user asking for access refGroups = the groups referenced with $refPage (page reference field) refUser = page reference field to manage "group memberships", field is added to group pages $curUser = current user / user to check access for Don't know if the reference is to complex for good performance? Two find() vs. one complex(?) count
  2. New branch with removed FormHelper dependency. Instead it uses the new form api array input support. Works in my local test environment. Simple frontend login module with error handling. After some time playing with JavaScript / ajax I should finish some basic modules *g*
  3. skipLabel I try to skip the form field label, but don't get it working... Field is based on an array array( 'type' => 'submit', 'value' => $this->_('Login'), 'id' => 'submit', 'name' => 'submit', 'skipLabel' => Inputfield::skipLabelHeader, ) Second try... getthe form field an set it after added to the form. $submit = $this->form->get('submit'); $submit->set('skipLabel', 2); // Inputfield::skipLabelHeader; https://processwire.com/talk/topic/5488-checkbox-other-text-in-header-than-label-text/?p=53528 https://processwire.com/talk/topic/2089-create-simple-forms-using-api/?p=69445 type password I try to build a login form, but there seems no way to set it the field information array array( 'type' => 'text', // 'password' <-- InputfieldPassword != type password 'label' => $this->_('Password'), 'name' => 'password', 'id' => 'password', 'name' => 'password', 'required' => true, ) As solution I get the field from the form and modify it, but is there a clean way to define it? $passField = $this->form->get('password'); $passField->attr('type', 'password');
  4. As described at FormHelper module topic create forms based on template object (with a "fake page") stops working with PW dev Fatal error: Exception: New page '/pw//' must be saved before files can be accessed from it (in /volume1/web/pw/wire/core/PagefilesManager.php line 260) #0 /volume1/web/pw/wire/core/PagefilesManager.php(251): PagefilesManager->___path() #1 /volume1/web/pw/wire/core/PagefilesManager.php(211): PagefilesManager->path() #2 /volume1/web/pw/wire/core/PagefilesManager.php(67): PagefilesManager->createPath() #3 /volume1/web/pw/wire/core/PagefilesManager.php(55): PagefilesManager->init(Object(Page)) #4 /volume1/web/pw/wire/core/Page.php(1752): PagefilesManager->__construct(Object(Page)) #5 /volume1/web/pw/wire/core/Pagefiles.php(74): Page->filesManager() #6 /volume1/web/pw/wire/core/Pagefiles.php(58): Pagefiles->setPage(Object(Page)) #7 /volume1/web/pw/wire/modules/Fieldtype/FieldtypeImage.module(33): Pagefiles->__construct(Object(Page)) #8 /volume1/web/pw/wire/core/Fieldtype.php(390): FieldtypeImage->getBlankValue(Object(Page), Object(Field)) #9 /volume1/web/pw/wire/core/Page.php(817): Fieldtype->getDefaultValue(Object(Page), Ob in /volume1/web/pw/index.php on line 243 Error: Exception: New page '/pw//' must be saved before files can be accessed from it (in /volume1/web/pw/wire/core/PagefilesManager.php line 260) #0 /volume1/web/pw/wire/core/PagefilesManager.php(251): PagefilesManager->___path() #1 /volume1/web/pw/wire/core/PagefilesManager.php(211): PagefilesManager->path() #2 /volume1/web/pw/wire/core/PagefilesManager.php(67): PagefilesManager->createPath() #3 /volume1/web/pw/wire/core/PagefilesManager.php(55): PagefilesManager->init(Object(Page)) #4 /volume1/web/pw/wire/core/Page.php(1752): PagefilesManager->__construct(Object(Page)) #5 /volume1/web/pw/wire/core/Pagefiles.php(74): Page->filesManager() #6 /volume1/web/pw/wire/core/Pagefiles.php(58): Pagefiles->setPage(Object(Page)) #7 /volume1/web/pw/wire/modules/Fieldtype/FieldtypeImage.module(33): Pagefiles->__construct(Object(Page)) #8 /volume1/web/pw/wire/core/Fieldtype.php(390): FieldtypeImage->getBlankValue(Object(Page), Object(Field)) #9 /volume1/web/pw/wire/core/Page.php(817): Fieldtype->getDefaultValue(Object(Page), Ob This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. I used template based forms to create new pages in the frontend. Is there a way to get image fields working in a form without an still existing page? There was no problem in older / stable PW versions if page is created before the temp uploaded file is added to the page image field (after form process...). In current dev I get the error during form creating before submit.
  5. I rewrite FormHelper to use the native array support of form api and noticed that form based on a template won't work with newer PW dev version. I get an error message from PagefilesManager. Fatal error: Exception: New page '/pw//' must be saved before files can be accessed from it (in /volume1/web/pw/wire/core/PagefilesManager.php line 260) #0 /volume1/web/pw/wire/core/PagefilesManager.php(251): PagefilesManager->___path() #1 /volume1/web/pw/wire/core/PagefilesManager.php(211): PagefilesManager->path() #2 /volume1/web/pw/wire/core/PagefilesManager.php(67): PagefilesManager->createPath() #3 /volume1/web/pw/wire/core/PagefilesManager.php(55): PagefilesManager->init(Object(Page)) #4 /volume1/web/pw/wire/core/Page.php(1752): PagefilesManager->__construct(Object(Page)) #5 /volume1/web/pw/wire/core/Pagefiles.php(74): Page->filesManager() #6 /volume1/web/pw/wire/core/Pagefiles.php(58): Pagefiles->setPage(Object(Page)) #7 /volume1/web/pw/wire/modules/Fieldtype/FieldtypeImage.module(33): Pagefiles->__construct(Object(Page)) #8 /volume1/web/pw/wire/core/Fieldtype.php(390): FieldtypeImage->getBlankValue(Object(Page), Object(Field)) #9 /volume1/web/pw/wire/core/Page.php(817): Fieldtype->getDefaultValue(Object(Page), Ob in /volume1/web/pw/index.php on line 243 Error: Exception: New page '/pw//' must be saved before files can be accessed from it (in /volume1/web/pw/wire/core/PagefilesManager.php line 260) #0 /volume1/web/pw/wire/core/PagefilesManager.php(251): PagefilesManager->___path() #1 /volume1/web/pw/wire/core/PagefilesManager.php(211): PagefilesManager->path() #2 /volume1/web/pw/wire/core/PagefilesManager.php(67): PagefilesManager->createPath() #3 /volume1/web/pw/wire/core/PagefilesManager.php(55): PagefilesManager->init(Object(Page)) #4 /volume1/web/pw/wire/core/Page.php(1752): PagefilesManager->__construct(Object(Page)) #5 /volume1/web/pw/wire/core/Pagefiles.php(74): Page->filesManager() #6 /volume1/web/pw/wire/core/Pagefiles.php(58): Pagefiles->setPage(Object(Page)) #7 /volume1/web/pw/wire/modules/Fieldtype/FieldtypeImage.module(33): Pagefiles->__construct(Object(Page)) #8 /volume1/web/pw/wire/core/Fieldtype.php(390): FieldtypeImage->getBlankValue(Object(Page), Object(Field)) #9 /volume1/web/pw/wire/core/Page.php(817): Fieldtype->getDefaultValue(Object(Page), Ob This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. In the past it was possible to work with a "fake Page object" to get a working form and take care about page save later... $fakePage = new Page(); $fakePage->template = $tpl; So maybe form based on a template won't work and so won't implemented in future versions Or is there a solution to get it working again without an existing page? I used template based forms to create new pages, but page is saved after form is processed and data is checked...
  6. Hi adrian, thank's. I know this way and have decided to use it again / furthermore You're right, should be the easiest way to do it. Tried another way which also works, but because of missing page / template context (I think...) there are some limitations (missing options,...) and so there should be no real gain compared to array created fields. Example from inside a testing module.
  7. As before I'll generate a field list before I add to form... Instead of use getInputfields() I'll use a find to select / remove fields. Selector part will be generated dynamic to make it flexible. Because PW form api works with array input I'll simplify my FormHelper to use the existing array syntax instead of my own.
  8. At first... I wish you all a happy new year!!! I testing the dev updates to form api (array input) and also would try to remove a required field before send / render the form. In the past version(s) a previously added field couldn't simply removed if it was a required field. During form process the removed field input was checked because it's required... But the field was removed before render it... Now I updated to the latest dev to test array field input and also the remove field from form behavior... Why the title field isn't removed from the form Is it a bug at PW dev? Or is there an error at my code? Because field isn't removed at the moment I can't test if a removed required field is handled as required during form process... So that would be the second step to test
  9. Thanks, I always use $sanitizer, but now need to use purifier the first time. So I want to know if it is really needed or implemented into the field save process based on field type.
  10. User input should be sanitized... If I use CKEditor at PW admin to change a field value it should be sanitized by CKEditor Advanced Content Filter (ACF) and HTML Purifier (activated at CKEditor Settings). At the moment I play with frontend edit solutions. Frontend form (based on form api and PW inputfields) with a custom save process (set and save field value with PW api) Inline edit (jquery plugins jEditable, x-editable, jinplace) and a custom save process (see above) So the values not saved by the PW admin / backend process and would be saved without sanitizing in both ways above... right?
  11. Because I don't know how PW work with the database and internal data... Would the code above perform better, equal or will it be slower? Two find calls outside of the loop. Inside it working with the page arrays (will that also fire db queries?)
  12. As posted at https://processwire.com/talk/topic/8501-problem-with-ajax-jeditable-process-module/ I'm playing around with frontend edit plugins... While FCM (FrontendContentManager) was a simple frontend form based on PW form api and inputfields now I'm play with inline edit plugins / modules. Instead of jEditable my last test was based on jQuery inplace edit plugin ("Jinplace"). Jinplace makes a element editable on click and sends object (pageID), attribute (fieldname) and value (the new value) via ajax to a process module. Features editable textfield and textarea page reference field as select (drop down) checkbox and labeled checkbox (Yes / No, translateable) a (buggy / testing) jquery tokeninput tagging widget with autocomplete as jinplace plugin/ extension: add, remove and create new tags (buggy click to close event, but jinplace plugin is just a first self written testing version) The process module also take care about missing required values (page id, field name) to identify the field to work with unchanged values (at the moment returns a json error message inside the editable field) not save empty values to required fields input sanitizing save/ create new tags (pages) via tokeninput fields ToDo bug fixes (dirty javascript code) tokeninput themes (mac, facebook, default) via parameter and also useable as not editable style in the frontend error handling (show a message, ignore and reset, ...?) sync initial value with "default" return value (initial could be "Like" / "Don't linke" but process module returns true / false or "Yes" / "No"...) file / image fields (maybe should be done with another module and PW inputfields - form with inline ckeditor and hidden image / file upload field) Bitbucket Repo: https://bitbucket.org/pwFoo/frontendjinplaceedit Really basic demo! Login: http://samarium-pit.lightningpw.com/processwire/ as demo / demo123 Testing page: http://samarium-pit.lightningpw.com/frontendjinplaceedit/ Don't know if I'll do some more work to create a full usable module. But let me know what you think about it
  13. Reply moved to a new topic... https://processwire.com/talk/topic/8641-some-tests-with-frontend-inplace-inline-edit/
  14. Updated version 0.5.3 for a better performance with a simple tagclout (without need to get tagged pages). public function parse($tagRoot = null, $tagField = null, $backRef = null, $tagsSelector = null, $backRefSelector = null) { $tagRoot = ($tagRoot ? $tagRoot : $this->tagRoot); $tagField = ($tagField ? $tagField : $this->tagField); $tagsSelector = ($tagsSelector ? "parent={$tagRoot},{$tagsSelector}" : "parent={$tagRoot}"); $backRefSelector = ($backRefSelector ? "$backRefSelector" : ''); // get pages as PageArray $tags = $this->pages->find($tagsSelector); foreach ($tags as $tag) { if (!$backRef) { // only count tagged / referenced pages for better performance $tagCount = $this->pages->count("{$tagField}={$tag},{$backRefSelector}"); $tag->set('useCount', $tagCount); } else { // pages tagged / referenced to this tag $tagged = $this->pages->find("{$tagField}={$tag},{$backRefSelector}"); $tag->set('use', $tagged); $tag->set('useCount', $tagged->count()); } } $this->tags = $tags; return $this; }
  15. Played with jEditable and build a proof of concept module... https://bitbucket.org/pwFoo/jeditable/overview Works fine with text input. Checks empty parameters (pid, field name). Also checks editable permission and do some error handling. Error handling logged out user should be moved from js file to process module (guest check...)
  16. Would it better to have two finds and work with the page arrays? $tags = $this->pages->find("parent=/tags"); $tagged = $this->pages->find("tags={$tags}"); foreach ($tags as $tag) { if ($match = $tagged->filter($tag)) { $tag->use->add($match->id); } }
  17. Hi Soma, I used a count only in the first version, but I also use the module to build a list of tags with tagged content. That's why I need the PageArray "$tagged". But you're right. Dependent on the use case I should use a count (tagcloud) or a find / count combination (tag list with tagged pages)... Is there a better way to get the "tagged pages" of a tag? Thanks!
  18. Updated to 0.5.2 removed selector method (convert array key => value to a PW selector string) use plain PW selector string as parse() param3 instead of an assoc array minor fixes
  19. MarkupTagcloud The module generates a simple tagcloud based an page references as tags and a default template. Settings and template can be easily changed to fit your needs. Version 0.5.2Download Processwire module page: http://modules.processwire.com/modules/markup-tagcloud/ Bitbucket Repo: https://bitbucket.org/pwFoo/markuptagcloud/ Usage Readme fileExample output <ul> <li class="tag3"> <a class="tag3" href="/pw/tags/mytag/">myTag</a> </li> <li class="tag1"> <a class="tag1" href="/pw/tags/tag123/">tag123</a> </li> <li class="tag2"> <a class="tag2" href="/pw/tags/hello/">Hello</a> </li> <li class="tag2"> <a class="tag2" href="/pw/tags/tagged/">Tagged</a> </li> <li class="tag1"> <a class="tag1" href="/pw/tags/template/">Template</a> </li> <li class="tag1"> <a class="tag1" href="/pw/tags/template2/">Template2</a> </li> </ul> Tagcloud / list can be styled by css via weight / class.
  20. Nice module It looks like Piwik isn't integrated yet? Will you write some more documentation and usage tips to the readme file and / or the descriptions?
  21. Hi Soma, found a little syntax error MarkupSocialShareButtons.js $(function(){ $('[name=theme]').on("change", function(){ }); } I think there are two missing characters? ); Fixed file $(function(){ $('[name=theme]').on("change", function(){ }); });
  22. Hi Adrian, the first method call is inside a normal template After pass it to the module as function param $refPage should be a Page object. So that shouldn't the Problem I think.
  23. I found that problem because $page->editable() or $page->editable("field") doesn't work inside my module... Method call $jedit->jeditable('title', $page) // $page == current page, should be instance of Page...? Inside the module... // public function jeditable($fieldname, Page $refPage) { // doesn't work. GEt an error message that $refPage is NOT an instance of Page...?! public function jeditable($fieldname, $refPage) { if (!$refPage->editable($fieldname)) return null; $fieldname = $this->fields->get($fieldname)->name; $pageId = $refPage->id; return "data-jeditable=1 data-pid={$pageId} data-field={$fieldname}"; } 1) $refPage (= $page) isn't instance of Page... Why? 2) editable() check doesn't work Error: Call to a member function editable() on a non-object
  24. Hi, I play with jeditable as a frontend inline edit module and handle changes with a process module. All works fine as admin, but if I call the process module as guest the process module returns the login form instead an error message. I know the redirect at the backend after a logout, but how could I prevent the process module to return the login form? See returned code here (login form). <form id="ProcessLoginForm" class="InputfieldForm" method="post" action="./" data-colspacing="0"><ul class="Inputfields"> <li class="Inputfield InputfieldText Inputfield_login_name" id="wrap_login_name"> <label class="InputfieldHeader" for="login_name">Username<i class="toggle-icon fa fa-angle-down" data-to="fa-angle-down fa-angle-right"></i></label> <div class="InputfieldContent"><input id="login_name" class="ProcessLoginName InputfieldMaxWidth" name="login_name" type="text" maxlength="2048"> </div> </li> <li class="Inputfield InputfieldText Inputfield_login_pass" id="wrap_login_pass"> <label class="InputfieldHeader" for="login_pass">Password<i class="toggle-icon fa fa-angle-down" data-to="fa-angle-down fa-angle-right"></i></label> <div class="InputfieldContent"><input id="login_pass" class="ProcessLoginPass InputfieldMaxWidth" name="login_pass" type="password" maxlength="2048"> </div> </li> <li class="Inputfield InputfieldSubmit Inputfield_login_submit" id="wrap_Inputfield_login_submit"> <label class="InputfieldHeader InputfieldHeaderHidden"><span>login_submit<i class="toggle-icon fa fa-angle-down" data-to="fa-angle-down fa-angle-right"></i></span></label> <div class="InputfieldContent"><button id="Inputfield_login_submit" class="ui-button ui-widget ui-state-default ui-corner-all" name="login_submit" value="Login" type="submit"><span class="ui-button-text">Login</span></button> </div> </li></ul><input type="hidden" name="TOKEN1422165275X1417982169" value="1EFKXn9SmQE4bfQzGWMCYh3H21X/C.J81" class="_post_token"></form><p></p><div><a href="/pw/"><i class="fa fa-home"></i> Home</a></div><p></p> Here is my process module. <?php /** * Processwire 'JeditableProcess' module * * Needed to handle Jeditable module input at backend * * @author pwFoo * @since 2014-12-07 * * ProcessWire 2.x * Copyright (C) 2011 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com */ class JeditableProcess extends Process { /** * getModuleInfo is a module required by all modules to tell ProcessWire about them * @return array */ public static function getModuleInfo() { return array( 'title' => 'JeditableProcess', 'summary' => 'Needed to handle Jeditable module input at backend', 'version' => '0.0.1', 'permission' => 'page-edit', ); } /** * Get the input, update and save the page. * Each AJAX call to this method will update a single field */ public function ___execute() { //print_r($this->input->post); //Is AJAX request? if(!$this->config->ajax) { throw new WireException("Request must be via AJAX"); } $pid = intval($this->sanitizer->selectorValue($this->input->post->pid)); $field = $this->sanitizer->fieldName($this->input->post->field); $val = $this->sanitizer->text($this->input->post->content); //echo "PID={$pid}|FIELD={$fieldname}|CONTENT={$val}"; $refPage = $this->pages->get($pid); if(!$refPage->editable($field)) { echo "Permission denied!"; } else { $refPage->of(false); $refPage->set($field, $val); $refPage->save($field); echo $refPage->$field; } } } As admin all works fine. Field gets changed and saved.
  25. I would do it like Nico wrote above... Requests should restricted to source ip address for security reasons. You have to write some code. Also your way won't work without custom code. So write a simple API and send needed params via GET sounds good.
×
×
  • Create New...