• Content count

  • Joined

  • Last visited

  • Days Won


kixe last won the day on February 12

kixe had the most liked content!

Community Reputation

897 Excellent

About kixe

  • Rank
    Hero Member

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    Cologne, Germany
  1. 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.
  2. 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.
  3. Fixed issue #3 @flydev Thanks
  4. @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.
  5. 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.
  6. 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(); }); }
  7. @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 ?>">
  8. 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'); });
  9. 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; } });
  10. @strandoo I pushed an update to github which should feed your needs. Please checkout.
  11. 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)
  13. // 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) { // ... }
  14. 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 }
  15. @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?