Jump to content

kixe

Members
  • Posts

    806
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by kixe

  1. 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); } });
  2. 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));
  3. 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.
  4. 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."); } });
  5. 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);
  6. 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.
  7. 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.
  8. Fixed issue #3 https://github.com/kixe/FieldtypeColor/issues/3 @flydev Thanks
  9. @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.
  10. 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
  11. 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(); }); }
  12. @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 ?>">
  13. 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'); });
  14. 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; } });
  15. @strandoo I pushed an update to github which should feed your needs. Please checkout.
  16. 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)
  17. http://modules.processwire.com/modules/admin-page-field-edit-links/
  18. // 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) { // ... }
  19. 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 }
  20. @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
  21. $key = $wireArray->getItemKey($item);
  22. 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.
  23. 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/
  24. @adrian Cool ... ... but you will get unexpected results if the page has no title and uses the name instead or whatever. I would replace $p->title with $this->wire('processHeadline') to get it more stable. $this->addHookAfter('Page::render', function($event) { if($this->process != 'ProcessPageEdit') return; $p = $this->process->getPage(); $headline = "My ID is $p->id"; $event->return = str_replace($this->wire('processHeadline').'</h1>', '<strong><em>'.$headline.'</em></strong></h1>', $event->return); }); @flydev $this->getUpdateStatus() // ? what's that? return?
  25. Quick check debug mode on? any warnings, notices, errors? does $mostRecentlyCreatedPageByUser->id return something > 0? is $mostRecentlyCreatedPageByUser->city and $mostRecentlyCreatedPageByUser->miles populated? You should check the latter 2 in your template before echo.
×
×
  • Create New...