Jump to content

kixe

Members
  • Posts

    790
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by kixe

  1. Added some useful functions to FieldtypeColor class: /** * Find the "naive" difference between two colors. * @param int[] $color_a Three-element array with R,G,B color values 0-255. * @param int[] $color_b Three-element array with R,G,B color values 0-255. * @return int */ public function getColorDistance(array $color_a, array $color_b) /** * Find the difference between two colors' luminance values. * @param int[] $color_a Three-element array with R,G,B color values 0-255. * @param int[] $color_b Three-element array with R,G,B color values 0-255. * @return int */ public function getLuminanceDistance(array $color_a, array $color_b) /** * Find the closest named color * @param hexcolor 6 or 8 digits, with or without leading '#' * @return string */ public function getClosestColorName(string $color) Usage example: $fc = $modules->get('FieldtypeColor'); $colorname = $fc->getClosestColorName('#01fb99'); var_dump($colorname); // string(17) "MediumSpringGreen" I needed this for the COLOR property in .ics file type. According to the specifications, the value must be a valid CSS3 color name. https://icalendar.org/New-Properties-for-iCalendar-RFC-7986/5-9-color-property.html
  2. https://github.com/kixe/FieldtypePageContextData/issues
  3. @MrSnoozles Edit 1: Thanks for feedback. I fixed it in the recommended way. Edit 2: It's good that you found a solution to your needs.
  4. I've pushed a fix. The separator must be translated into a real line break (expected by the Inputfield). I changed the translation to "\r\n" instead of "\n" only, which should work cross platform. Continue to use the string '\n' in the field settings. Please update to version 1.0.1. Could you please give feedback if it works? The pipe '|' you mentioned is already reserved to separate an option 'value' from the option 'title' (@see SelectableOptionManager). I prefer to handle the setup according (very close) to the expectations of the inputfield. ProcessUser and possibly some other processes for editing system pages are not supported. In the special case of ProcessUser, the GET-Parameters forfield and forpage are removed from the url of the modal window for whatever reason. Any idea? The module is still in an alpha stadium. Thanks for testing and feedback.
  5. Make child pages of page beeing edited selectable in a page field named: nameOfTheField $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'nameOfTheField') { $event->return = $event->pages->find('parent=' . wire('input')->get->id); } });
  6. Field that stores one or more references to ProcessWire pages with additional data in field context. Values are editable via page edit modal of the referenced page provided from the field if module AdminPageFieldEditLinks is installed and "Enable link to create new pages?" is checked in field settings. Requirements: AdminPageFieldEditLinks >= 3.1.4 https://github.com/kixe/FieldtypePageContextData https://processwire.com/modules/fieldtype-page-context-data/ Use case example: The planning of the Tonmeistertagung in the CCD (Congress Center Düsseldorf) from November 3rd, 2021 to November 6th, 2021 is in the finalization phase. The conference consists of a conference part and an exhibition. The planning is done via a separate frontendless PW instance. There, all companies (pages) that are active at various events are kept in a pool. Changes (address, logo) can always be done there. For the exhibition of the current conference in November, the exhibitor-companies (pages) are selected via a page reference field. A stand number must now be assigned to each selected company (page). We had originally solved this using the Profield FieldtypeTable. However, this had the disadvantage that each entry again made all companies available for selection and did not recognize which were already selected in a previous table row. The new field type now allows the value (company's stand number) to be assigned to a Company (page) in context to a specific Pagefield living in a specific page. https://tonmeistertagung.com/en/exhibitors/exhibition/
  7. I don't know how well you know the PW API but it's easy to hook in Pages::delete() and Pages::save() In your sattelite instances you just need a name for each user, nothing else. Manage the users in your main instance only and update users via PW API in the others. What is your special usecase? Why do you have multiple PW Installs for the same users?
  8. If a user is succesfully loggedin in another instance you can force login in the current (only if the user name matches) – no password required. Checkout the code I posted: and add this: $xy->users->setCurrentUser($_user); // search for this wire('session')->forceLogin($_user->name); // add this I would assign profile-edit permission only in the main instance. All this needs a bit coding experience. Be careful and don't create security holes!
  9. I can provide a module for this usecase: https://github.com/kixe/AdminHidePageTreeByRole ... or try one of them: https://processwire.com/modules/admin-restrict-page-tree/ https://processwire.com/modules/admin-restrict-branch/
  10. You can use multiple instances of processwire and include one in another. $pwComments = new ProcessWire($config->paths->root . 'site-comments'); $home = $pages->get(1); $homeOfComments = $pwComments->pages->get(1); https://processwire.com/docs/more/multi-site-support/ use Option #1 https://processwire.com/blog/posts/multi-instance-pw3/#using-multi-instance-in-pw3 This is also possible under a single domain if you do not need a frontend at one of the two installations and use different names for your /admin/ pages and session cookies. Under special circumstances you can also access the current user of one instance within the other. Look here: https://github.com/processwire/processwire-issues/issues/1294#issuecomment-759351593
  11. It's not exactly what you're asking for, but it could be helpful or a first approach to solve your problem: In a ProcessWire multi-instance environment, I needed to get the logged-in user of the central PW instance in all the others and found the following solution. Requires to use different session cookie names in each installation and SessionHandlerDB installed. $config->sessionName = wire0; $config->sessionName = wire1; https://github.com/processwire/processwire-issues/issues/1294#issuecomment-759351593
  12. /** * allowed flag constants (bitmask) for context * @see core/field.php * */ Field::flagAccess // 32 Field::flagAccessAPI // 64 Field::flagAccessEditor // 128 /** * set context via fieldgroup * @see core/fieldgroup.php * */ $fieldGroup->setFieldContextArray($field_title->id, ['flagsAdd' => 192, 'flagsDel' => 32]); $fieldGroup->saveContext(); /** * set context via fields * @see core/fields.php * */ $field_title = wire('fields')->get('title'); $field_title->addFlag(128); // runtime wire('fields')->saveFieldgroupContext($field_title, $fieldGroup); not tested, but should work
  13. Possible solution to set $user using a setup with multiple sites (multiple databases Option #1), module SessionHandlerDB and different session names for each instance. Put this code in your ready.php $xy = new ProcessWire($config->paths->root . 'site-xy/'); /** * if a session AND a challenge cookie is present we check if the user is still loggedin in xy * if yes we set the @var wire('user') to the xy instance * */ if ($xy->session->hasCookie() && $xy->session->hasCookie(true)) { // get xy session ID if ($xy>config->https && $xy->config->sessionCookieSecure) { $cn = $xy->config->sessionNameSecure; if (!$cn) $cn = $xy->config->sessionName . 's'; } else { $cn = $xy->config->sessionName; } $SID = $input->cookie->$cn; // set the wire('user') if loggedin if ($SID) { $SHDB = $xy->modules->getModule('SessionHandlerDB', array('noPermissionCheck' => true))->getSessionData($SID); if ($SHDB['user_id'] != 40) { // get fingerprint and session timestamp $fp = isset($SHDB['data']['Session']['_user']['fingerprint'])? $SHDB['data']['Session']['_user']['fingerprint'] : false; $ts = isset($SHDB['data']['Session']['_user']['ts'])? (int) $SHDB['data']['Session']['_user']['ts'] : 0; // validate fingerprint if ($xy->session->getFingerprint() !== $fp) { $this->session->error(__('Unable to assign XY user. XY-Session fingerprint does not match.'), Notice::debug | Notice::log); } // check if session timed out else if ($xy->config->sessionExpireSeconds && $ts < (time() - $xy->config->sessionExpireSeconds)) { $this->session->error(__('Unable to assign XY user. XY-Session timed out.'), Notice::debug | Notice::log); } else { $_user = $xy->users->get($SHDB['user_id']); if ($_user->id) { // session valid, assign user & user_id will be set correctly in DB via SessionHandlerDB::write() $xy->users->setCurrentUser($_user); } } } } }
  14. or simply ... $s = $modules->get('SessionHandlerDB')->getSessions(); // seconds = 300, limit = 100 $online_user_ids = array_filter(array_column($s,'user_id'), function($id) {return $id != 40;}); // with all arguments $seconds = 86400; // one day $limit = 200; $s = $modules->get('SessionHandlerDB')->getSessions($seconds, $limit); $online_user_ids = array_filter(array_column($s,'user_id'), function($id) {return $id != 40;}); Unfortunately this doesn't work if ProcessWire is bootstrapped https://github.com/processwire/processwire-issues/issues/1294#issuecomment-748057420 I have to correct myself. It works also if ProcessWire instance is bootstrapped $otherPwInstance = new ProcessWire($config->paths->root . 'site/'); $s = $otherPwInstance->modules->getModule('SessionHandlerDB', array('noPermissionCheck' => true))->getSessions(); $online_user_ids = array_filter(array_column($s,'user_id'), function($id) {return $id != 40;});
  15. // 'include=all' includes access restricted pages, check access via function viewable() before using render() foreach ($page->children('include=all') as $p) { if ($p->viewable()) $p->render(); } // without argument (selector) access restricted pages are excluded by default foreach ($page->children() as $p) { $p->render(); } Why do you want to render multiple pages?
  16. I have 2 ProcessWire instances running under the same domain, each with own session name and cookie. $config->sessionName = 'wire0'; $config->sessionName = 'wire1'; The assignment of the correct instance via url is done in index.config.php. One of the 2 instances is without frontend and accessible only under the related admin url. In this instance (wire0) the user with ID=14179 is logged in. If I check if the session of the related user in this instance is valid I get false. The user var returns unexpected results as well. $xy = new ProcessWire($config->paths->root . 'site-xy/'); var_dump($xy->session->isValidSession(14179)); // false, should be true var_dump($xy->user->isLoggedin()); // false, should be true If I use the $pages, the $users, $config or any other API of the $xy instance I get what I expect. $userIDs = $xy->users->findIDs('check_access=0'); var_dump(count($userIDs)); // correct number of users in related instance var_dump($xy->config->sessionName); // wire0 var_dump($config->sessionName); // wire1 How can I get the $user or $session vars of another PW instance?
  17. I think you don't need a workaround with a hidden field if you do the hook after and change the PageArray instead of the selector. $wire->addHookAfter('ProcessPageList::find', function($e) { $pages = $e->return; if ($pages->first()->parent->id != 111111) return; // quick exit if parent doesn't match $zeroDatePages = $pages->find("date=''"); // empty date pages $result = $pages->filter('date>0,sort=-date'); // pages with date, sort descending $result->prepend($zeroDatePages); // prepend empty date pages $e->return = $result; });
  18. try // ... $results->setStart(6); // index = 7 - 1 $pagination = $pager->render($results);
  19. I use a hook for something similar /** CUSTOM PAGE SORT * related for InputfieldPageListSelect, ProcessPageList (Page tree) * */ $wire->addHookBefore('ProcessPageList::find', function($e) { $parent = $e->arguments(1); $selectorString = $e->arguments(0); // modify $selectorString, remove, modify, add ',sort= ...' $e->arguments(0, $selectorString); });
  20. Do not overwrite the field object (loop item) with the field value. Try: foreach ($page->fields as $field) { $fieldValue = ''; foreach($languageFallback as $languageID) { $fieldValue = $page->getLanguageValue($languageID, $field); if ($fieldValue) break; } $page->$field = $fieldValue; }
  21. Example with 'body' field. Define a language fallback order in ready.php and render first match in template. (not tested ... ) // in ready.php $languageFallback = [1046,1042,1033]; // array of Language-IDs in fallback order $body = ''; $pageActiveLanguageIds = $page->getLanguages()->each('id'); $languageFallback = array_intersect($languageFallback, $pageActiveLanguageIds); foreach($languageFallback as $languageID) { $body = $page->getLanguageValue($languageID, 'body'); if ($body) break; } $page->body = $body; // in your template file echo $page->body; // render field body
  22. @LostKobrakai If the thread doesn't reveal any ListerPro secrets and provide interesting informations about FieldtypeSelector/ InputfieldSelector, it could be moved and made available to everybody, since FieldtypeSelector is not Pro. 🤔
  23. https://processwire.com/talk/topic/13116-or-selecters-for-different-fields/ Unfortunately the thread is not accessible for everybody. Why? ... which could be found here: https://github.com/processwire/processwire-requests/issues/317 For everyone who is interested in this function. Please vote or add a comment.
×
×
  • Create New...