Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by kixe

  1. @wbmnfktr The reason is the invalid token: https://github.com/processwire/processwire/blob/bdaf8810cbb71944820c45e0b297d0b75f1e60be/wire/core/SessionCSRF.php#L176-L191 Make sure that the session cookie is set and valid and that the current valid token is sent with the form.
  2. All forms in the backend of processwire are secured against CSRF attacks by assigning them a one-time token. This will ensure that the page and the current session that generates the form is the same as the one that receives the form. E. g. The error message appears when a backend page (also Login) is open and the session has expired, or the session cookie has been deleted from the browser or could not be set in the browser.
  3. Try this hook in hook $this->addHookBefore('PageRender::renderPage', function($e) { $event = $e->arguments[0]; $page = $event->object; $user = $this->wire('user'); // QUICK EXIT if ($user->isSuperuser()) return; // superuser if (!empty($page->template) && $page->template->id == 2) return; // backend if ($user->language->isDefault()) return; // default language $language = $user->language; $currentLanguageStatus = $page->get("status$language"); if ($currentLanguageStatus == 0) { $otherPage = $this->wire('pages')->get(1234); // get page to be rendered instead $event = new HookEvent(array('object' => $otherPage)); $e->arguments(0, $event); } });
  4. 1. Use the right sanitizer $email = $sanitizer->email($email); $pagename = $sanitizer->pageName($pagename); // OR $pagename = $sanitizer->pageNameUTF8($pagename); 2. Set adjustName to true in the save options array to make your page name unique $np = new Page() // ... $np->save(array('adjustName' => true));
  5. The banner is always displayed at the bottom of the page. You can limit the appearance to certain pages via module settings. e. g. Do you use iframes for your forms? If yes, each iframe has its own body tag. The banner is prepended to each closing body tag. Disable the banner by module settings (using selectors) for the framed pages.
  6. Does this help? $this->addHookBefore('ProcessPageEdit::processInput', function($e) { if (wire('input')->post('submit_save')) { $e->message("This page has been saved by pressing the 'Save' button."); } });
  7. Yes $field = 'pass'; // field to check $template = 'user'; // context template $myField = $fields->get($field); $contextTemplate = $templates->get($template)->fieldgroup; $myFieldInContext = $contextTemplate->getFieldContext($myField); $case = $myField->viewable()? '' : ' not'; // optional arguments: 1 = page, 2 = user $message = "Field $field is$case viewable."; if (!$contextTemplate->has($myField)) $message .= " Field $field is not part of template $template."; else { $case = $myFieldInContext->viewable()? '' : ' not'; // optional arguments: 1 = page, 2 = user $message .= " Field $field is$case viewable in context with template $template."; } var_dump($message);
  8. If you use an external DB to generate the select field the DB is queried to generate the field and also if you access the value via Api. Depending on your setup (single/ mutliple) the returned value is either an object of class SelectExtOption or a WireArray of SelectExtOption items. This module does not 'import' anything. The value reference is of type integer and stored in the PW Database.
  9. Some time ago, I started to develop a module that provides a predefined (field settings) list of colors as a supplement to the FieldtypeColor module. Quite expensive and therefore unfortunately remained.
  10. Fixed issue #3 https://github.com/kixe/FieldtypeColor/issues/3 @flydev Thanks
  11. @adrian I know Jumplinks. I use it, I like it and I recommend it. Somebody else using my Process404Logger module had problems interacting with ProcessRedirects. To test and fix this I needed to fix the bugs of ProcessRedirects first.
  12. The module doesn't seem to be supported any more (no commits since 4 years, unfixed issues). I forked the module and switched from mysqli to PDO. I also fixed 2 uninstall bugs. https://github.com/kixe/ProcessRedirects/tree/kixe
  13. I don't know if this is enough for you. But it slimifies the db table a bit. Place the following class and hook in your ready.php to remove orphaned sessions and to disallow the usage of multiple devices of the same user. /** * Class to limit sessions of a user to the current session, disallow multiple devices * */ class SessionHandlerDBRestricted extends SessionHandlerDB { /** * destroy orphaned sessions * @return bool true on success, false on failure * * public function cleanup() { $table = parent::dbTableName; $database = $this->database; $sessionID = $_COOKIE[session_name()]; $userID = $this->wire('user')->id; $query = $database->prepare("DELETE FROM `$table` WHERE user_id=:user_id AND id NOT IN (:id)"); $query->execute(array(":id" => $sessionID,":user_id" => $userID)); return true; } } /** * hook * */ if ($modules->isInstalled('SessionHandlerDB')) { $wire->addHookAfter('Session::loginSuccess', function ($e) { $shdbr = new SessionHandlerDBRestricted(); $shdbr->cleanup(); }); }
  14. @MarcoPLY Where did you set the vars $hreflang and $language? Maybe in the last turn of the foreach loop? If so, not a good idea. The function _x() provides the option to translate a given string in a specific context. This is useful for hardcoded text strings in modules or templates. If you put $leng in quotes and translate this string again under SETUP > LANGUAGES > ANYLANGUAGE > Button: Find Files to translate it maybe will work but it is useless. You don't need _x() here. Your variable $leng is already translated in the database. The following code is enough and should work if you have properly implemented a language switcher which changes the language of the current user. <? $lang = $pages->get(1)->getLanguageValue($user->language, 'name'); ?> <html lang="<?php echo $lang ?>">
  15. In a project I had to add the attribute 'disable' to some options of a select field (page reference) to show them but make them unselectable. Since I could not find an integrated solution, I wrote a tiny module and a hook. This could also be a POC to similar needs. Install module Add the Module to InputfieldPage in the module settings to make it selectable as Inputfield for page reference fields Create a hook in ready.php to manipulate attributes of the <option> tag for specified items Module <?php namespace ProcessWire; /** * POC Inputfield Select Hook Add Option -- Replacement for InputfieldSelect * * Selection of a single value from a select pulldown. Same like InputfieldSelect * except this version provides hookable addOption() function which allows to modify * attributes of the <option> tag (i. e. 'disabled' to show items but disallow to select them * * @author Christoph Thelen aka @kixe * */ class InputfieldSelectHookAddOption extends InputfieldSelect { /** * Return information about this module * */ public static function getModuleInfo() { return array( 'title' => __('Select Hookable Add Option', __FILE__), // Module Title 'summary' => __('Selection of a single value from a select pulldown. Same like InputfieldSelect. except this version provides hookable addOption() function which allows to modify attributes of the <option> tag (e.g. \'disabled\' to show items in dropdown but disallow to select', __FILE__), // Module Summary 'version' => 100, ); } /** * Hook in here to modify attributes */ public function ___addOptionAttributes($value, $label) { return array(); } /** * @see InputfieldSelect::addOption() * */ public function addOption($value, $label = null, array $attributes = null) { if (!is_array($attributes)) $attributes = array(); $attributes = array_merge($attributes, $this->addOptionAttributes($value, $label)); return parent::addOption($value, $label, $attributes); } } Hook /** * This example hook modifies the attributes of the selectable options of a Pagereference field named 'test'. * The selectable pages have the template 'test' assigned which includes a checkbox 'disallow'. * The attribute 'disabled' will be added to the selectable page if the user does not have the role 'user-extended' and 'disallow' is set. * */ $wire->addHookAfter('InputfieldSelectHookAddOption::addOptionAttributes', function($e) { // quick exit if ($e->object->name != 'test') return; if ($this->wire('user')->isSuperuser()|| $this->wire('user')->hasRole('user-extended')) return; // disable items (pages) in select $restrictedPageIDs = $this->wire('pages')->find('template=test,disallow=1')->each('id'); if (in_array($e->arguments[0], $restrictedPageIDs)) $e->return = array('disabled' => 'disabled'); });
  16. Put this in your ready.php (I'm not sure if this hook affects errors and exceptions too) wire()->addHookBefore('WireLog::save', function($e) { if ($this->wire('user')->hasRole('superuser')) { $e->replace = true; $e->return = false; } });
  17. @strandoo I pushed an update to github which should feed your needs. Please checkout.
  18. You don't need to set GET parameters or URL segments. (which is not exactly the same b.t.w.) Install LanguageSupportPageNames module and configure it for your needs. go to home page and set names for the home page. Use 'it' for default language and 'en' for english. Don't use 'home'. Don't leave empty. Access language code from $pages->get(1)->name for current user language and $pages->get(1)->getLanguageValue($language, 'name') for specified language. Get the URLs with $pages->get(1)->localUrl($language)
  19. http://modules.processwire.com/modules/admin-page-field-edit-links/
  20. // inside a class e.g. modules $this->addHookAfter('Pages::trash', $this, 'myHookMethodName'); $this->addHookAfter('Pages::delete', $this, 'myHookMethodName'); public function myHookFunction($event) { // ... } // outside a class e.g. inside ready.php or templates wire()->addHookAfter('Pages::trash', null, 'myHookFunctionName'); wire()->addHookAfter('Pages::delete', null, 'myHookFunctionName'); function myHookFunction($event) { // ... }
  21. I ended up with the following simple template since I was just looking for a csv export/ download option. It works without any errors for any kind of field (repeaters included) <?php // template provides file download of some children data in csv format // export as CSV if $_GET['csv_export‘] == 1 is in url if(isset($input->get->csv_export) && $input->get->csv_export == 1) { // create data array $data = $page->children->explode(function($item){ return array( 'ID'=> $item->id, // page property 'Author' => $item->author->first()->name, // page field 'Length' => $item->timeslots? $item->timeslots * 30 : 0, // integer field 'Info' => $item->info // runtime markup field ); }); // set header header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=file.csv"); header("Pragma: no-cache"); header("Expires: 0"); $output = fopen("php://output", "wb"); foreach ($data as $fields) fputcsv($output, $fields); fclose($output); exit; } // display content of template with link to same page with appended csv_export=1 else { $page->_content = "<a href='./?csv_export=1'>Export Child Pages as CSV</a>"; //link to initiate export }
  22. @Robin S The function is marked as #pw-internal and therefore not meant to be displayed in the docs. Why? No idea! Ask Ryan. The Api Docs have become much better in the last 2 years. Nevertheless, I mainly use the code itself as documentation. btw: Did you look here? https://processwire.com/apigen/class-WireArray.html
  23. $key = $wireArray->getItemKey($item);
  24. First is fixed. Thanks. While playing around getting still some notices: Notice: Trying to get property of non-object in .../site/assets/cache/FileCompiler/site/modules/BatchChildEditor/ProcessChildrenCsvExport.module on line 230 https://github.com/adrianbj/BatchChildEditor/blob/2e079d342ea56ac7be58ae2de4d6cdc1317eec0e/ProcessChildrenCsvExport.module#L230 check wire('fields')->$fieldName first Notice: Trying to get property of non-object in .../site/assets/cache/FileCompiler/site/modules/BatchChildEditor/ProcessChildrenCsvExport.module on line 161 https://github.com/adrianbj/BatchChildEditor/blob/master/ProcessChildrenCsvExport.module#L161 field label expected but field label is not required. Needs fallback to name.
  25. Hi @activestate Welcome to the forum! $singleItem = $pages->get("insight_repeater.h1_tag~=Lor"); $allItems = $pages->find("insight_repeater.h1_tag~=Lor"); Have a look here https://processwire.com/api/fieldtypes/repeaters/
  • Create New...