Jump to content

Zeka

Members
  • Posts

    1,065
  • Joined

  • Last visited

  • Days Won

    11

Everything posted by Zeka

  1. @Ivan Gretsky I am not sure that this will help, but for one project I been using these hooks for a similar task. Maybe it will give you some ideas. public function init() { $this->addHookBefore('PageRender::renderPage', $this, 'hookBeforePageRenderTemplater'); $this->addHookAfter('TemplateFile::render', $this, 'hookAfterTemplateRender'); $this->wire('config')->ignoreTemplateFileRegex = "/(\.before\.)|(\.after\.)|(\.{$this->template_files_suffix}\.)|(^_)/"; } public function hookBeforePageRenderTemplater($e) { $event = $e->arguments(0); $page = $event->object; if ($page->template->name == 'admin') return; $options = $event->arguments(0); $template = $page->template; $options['prependFiles'] = [ "{$template}.before.php", "_init.php", ]; $options['appendFiles'] = [ "{$template}.after.php", "_after.php", ]; $event->setArgument(0, $options); } public function hookAfterTemplateRender($event) { if ($this->wire('page') == null) return; if (strpos($event->object->filename, 'TracyDebugger') !== false) return; if (str_replace('site/assets/cache/FileCompiler/', '', $event->object->filename) !== $this->wire('page')->template->filename) return; if (strpos($_SERVER['REQUEST_URI'], $this->wire('config')->urls->admin) === 0 || $this->wire('page')->template->name == 'admin') return; $template = $event->object; $options = $template->options; if (is_array($options) && array_key_exists('pageStack', $options)) { $view = $this->wire($this->api_view_var); $layout = $this->wire($this->api_layout_var); $page = $this->wire('page'); $page_template = $page->template; if ($template->halt) { return; }; if (empty($options['pageStack']) && $page_template->templater_url_segments) $this->wire('session')->redirect($page->url); $template_name = ($page->template->altFilename) ? $page->template->altFilename : $page->template->name; $view_file = $this->getViewFilePath($template_name); if (is_file($view_file)) { $view->setFilename($view_file); } else { throw new WireException("View file for this page template ({$view_file}) does not exist"); } $event->return = $event->return . $layout->render(); } }
  2. @maddmac Sorry, but no. I do not use FormBuilder.
  3. https://processwire.com/docs/start/variables/input/ https://processwire.com/blog/posts/pw-3.0.125/ https://processwire.com/api/ref/wire-input/ $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->name == 'myselect') { $temp = $this->wire('input')->get('temp', 'text', 'fallback-template'); $event->return = $event->pages->find('template=$temp'); } });
  4. @PWaddict Try to use $inputfield->set('maxFiles', 20);
  5. @clemens Try to $wire->addHookAfter(); https://processwire.com/docs/modules/hooks/#do-i-want-my-hook-to-run-before-or-after-the-method-i-am-hooking-or-does-it-matter
  6. @Orkun I think that it is enoght to run it once if you have some issues or after update to PW >= 3.0.156. https://github.com/processwire/processwire/blob/master/wire/core/PagesParents.php#L485 Save method from PagesParents class executes on every page save and if it's necessary it will execute rebuildAll method. https://github.com/processwire/processwire/blob/master/wire/core/PagesParents.php#L502
  7. @franciccio-ITALIANO You can get it from DB in the "pages" table. Row where id = 2.
  8. Hi. After update to 3.0.163 and 3.0.164 selectors like pages('template=tag, title.data1022="", limit=10'); do not work. Could somebody confirm it? Thanks.
  9. Hi. For now I add flag at init.php and remove it in ready.php like // init.php if (strpos(sanitizer()->entities(input()->url()), 'some/page/')) { fields('somefield')->addFlag(Field::flagAutojoin); } // ready.php fields('somefield')->removeFlag(Field::flagAutojoin); But there are pages that not so easy to identify by URL. So far I couldn't find any suitable hook and probably it is the only way to do it, or I missed something? Thank!
  10. @ryan Just to make sure that I understand you correctly when a page with 'tour' or 'bike' template is saved this hook clears cache only /reviews/bike-tours/* and /reviews/boat-[name]/ segments. Cache for review page and all other segments stay untouched. If so, it looks like what I'm looking for. ProCacheStaticClear - is it something new in V4 or tripsite specific? Definitely it steps forward to save resources and more selective cache clearing process. But I would like to propose one more optimization relative to multilanguage setup. We also have two languages: Ukrainian as default and Russian as secondary. Only 40% of news have a translation to the Russian language, but when a page is saved and doesn't have translation (secondary language is not active) ProCache clears the cache for all Russian pages and listings. In our case, every news item page has tags, sections, categories, author reference fields (all these referenced pages also have pagination and language versions), could be listed in sitemaps, RSS feeds etc. So clearing cache for secondary language (probably hundreds (in some case thousand) of pages), when there are actually no changes for it could produce unnecessary load. I have found some example on tripsite.com where this optimization could be handy. https://www.tripsite.com/bike-boat/all/ - 106 Tours https://www.tripsite.com/br/bicicleta-barco/all/ - 65 Tours https://www.tripsite.com/es/bici-barco/all/ - 46 Tours I can assume that not all tours available on every language and when a new relevant page with template 'tour' is saved cache for all these URLs (pages) and URL segments is cleared regardless of Portugues or Espanol languages are active for the saved tour. What do you think?
  11. @ryan Thanks. I have two examples: -------------- I have an RSS page which uses RSS template. This page outputs the main RSS feed, also there are several allowed URL segemtns for this template such: rss/google-news/ rss/yandex-news/ rss/ukrnet/ etc. Each segment outputs platform-specific feed with different markup and pages that are listed in the feed (based on the selection from options field). So when any new post is published or saved cache for RSS page including its URL segments are cleared, but because new post could be listed only for Google News clearing cache for Yandex and Ukrnet segments is unnecessary. -------------- Next example I have sitemap page/template which outputs sitemaps index like: Based on URL segments I generate a sitemap for specific time period or template. The same thing here if new category or post is created I want to clear the cache only for relevant template URL segment or for segment that reprecent current month (there are several thousand posts per month so regenerating cache for each URL segment each time creates unnecessary load on the server).
  12. @ryan Could you (or somebody who have access to the new version) please list names of these methods as I thinking about updating and buying a new licence. In my case, I need to be able to delete only specific cached urlSegment or page without its urlSegmetns independently from publishReady or saveReady hooks
  13. Just happend on PW 3.0.163. Fixed by rebuildAll method available since 3.0.156 $pages->parents()->rebuildAll();
  14. @ryan Thanks for updates. In previous versions of ProCache there is no way to clear cache separately for page and its urlSegments. As all templates loads on every request, I'm trying to keep the number of templates as low as possible, so very often we use urlSegments for that. In such cases, the output of the page and its urlSegments could be not related to each other. It would be great if we could control this behaviour via cache clearing behaviors options or at least have separate functions from API side.
  15. it is worth trying other options before disabling this feature completely * 0 or false: Fingerprint off * 1 or true: Fingerprint on with default/recommended setting (currently 10). * 2: Fingerprint only the remote IP * 4: Fingerprint only the forwarded/client IP (can be spoofed) * 8: Fingerprint only the useragent * 10: Fingerprint the remote IP and useragent (default) * 12: Fingerprint the forwarded/client IP and useragent * 14: Fingerprint the remote IP, forwarded/client IP and useragent (all).
  16. Zeka

    breadcrumbs

    @fruid I'm using this function for /** * Render breadcrumb navigation * */ function renderBreadcrumbs(PageArray $items, Array $options = []) { $page = wire('page'); if (!count($items)) return ''; $index = 1; $defaults = array( 'class' => 'breadcrumbs__list', // class for the <ul> 'a_class' => 'breadcrumbs__link', // class for a item 'a_active_class' => 'breadcrumbs__link--active', // class for a active item 'liclass' => 'breadcrumbs__item', // class for li item 'active' => 'breadcrumbs__item--active', // class for active item ); $options = array_merge($defaults); $out = "<ul class='$options[class]' itemscope itemtype='http://schema.org/BreadcrumbList'>"; foreach ($items as $item) { $class = $item->id == $page->id ? " class='$options[liclass]" . ' ' . "$options[active]'" : " class='$options[liclass]'"; $a_class = $item->id == $page->id ? " class='$options[a_class]" . ' ' . "$options[a_active_class]'" : " class='$options[a_class]'"; $title = $item("bradcrumbs_title|title"); $url = $item->url; $out .= "<li $class itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'><a $a_class href='$url' itemprop='item'><span itemprop='name'>$title</span><meta itemprop='position' content='$index' /></a>"; $out .= "</li>"; $index++; } $out .= "</ul>"; return $out; } Then in template file $breadcrumbs = renderBreadcrumbs(page('parents')->not('template=categories|products')->add(page()));
  17. @MoritzLost Thanks for the answer. You are right, I forgot to set namespace in init.php But it doesn't help, nom I get error Class 'ProcessWire\Products' not found I went through WireClassLoader.php and from findClassInPaths method in looks like the class name should be the same as its filename. So, I changed ProductsPagesType.php to class ProductsPagesType extends PagesType { /// } and then if I call it will work $products = new ProductsPagesType(); wire('products', $products, true); But I want to use "Products" and not "ProductsPages" or "ProductsPagesType" as classname and it look like the only way to do it via classLoader is to load it maually wire('classLoader')->loadClass('ProductsPagesType'); In this case even if classname is not equal to its filename like // ProductsPagesTypes.php class Products extends PagesType { /// } it will load it and I this code will work $products = new Products(); wire('products', $products, true); Am I right or I missed something?
  18. Hi. I have been using a module approach to include my custom Pages Types and other classes that extend Page class. In PW 3.0.152 we got the ability to specify custom Page classes without modules or manual include. So what I'm trying to do is basically load my custom pages types via classLoader. ProductsPagesType.php <?php namespace ProcessWire; class Products extends PagesType { /** * Construct the Products manager for the given parent and template * * @param Template|int|string|array $templates Template object or array of template objects, names or IDs * @param int|Page|array $parents Parent ID or array of parent IDs (may also be Page or array of Page objects) */ public function __construct($templates = array(), $parents = array()) { parent::__construct($templates, $parents); $this->addTemplates("products"); $this->addParents($this->pages->get("/products/")->id); } public function dumbMethod() { return 'test'; } } // init.php wire('classLoader')->addSuffix('PagesType', wire('config')->paths->classes); $products = new Products(); wire('products', $products, true); I get Fatal Error: Uncaught Error: Class 'Products' not found Autoload debug panel output: bd(wire('classLoader')); What I'm doing wrong?
  19. You can hook to pageNotFound // in modules init() $this->addHookBefore('ProcessPageView::pageNotFound', $this, 'redirectToEnglish'); public function redirectToEnglish($event){ // some logic $this->session->redirect($yourpage->url); }
  20. @Confluent Design You can ask your question here https://processwire.com/about/contact/
  21. @celfred Try to use TracyDebugger https://modules.processwire.com/modules/tracy-debugger/ https://adrianbj.github.io/TracyDebugger/#/debug-methods
  22. @ottogal You can change default grid mode to "vertical list"
×
×
  • Create New...