Jump to content

fbg13

Members
  • Posts

    344
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by fbg13

  1. I forgot to add an expiration time. I updated the code so that the cache never expires.
  2. I'm using this in a module public function init() { $this->addHookBefore("Pages::saveReady", $this, "cacheContent"); } protected function cacheContent($e) { $page = $e->arguments[0]; if($page->template->name == "templateYouWantToCache") { $cache = $this->cache; // delete the old cache $cache->delete("cacheName:" . $page->id); $cache->get("cacheName:" . $page->id, $cache::expireNever, function() use($page){ // code you want to cache $content = $page->title . "<br>"; $content .= $page->body; return $content; }); } } And in the template // since the cache already exists this will just get the cache // but in case no cache is found it generates it $cache->get("cacheName:".$page->id, $cache::expireNever, function() use($page){ // code should be the same as the one that preloads the cache $content = $page->title . "<br>"; $content .= $page->body; return $content; });
  3. Thanks @adrian Will update with some code after i do some more tests.
  4. @oma you process the loop in php if($this->config->ajax && $this->input->post->action == "filterPages") { $letter = $sanitizer->selectorValue($this->input->post->letter); $pages_ = $pages->find("template=templateName, name^={$letter}"); $out = ""; foreach($pages_ as $p) { $out .= "<div>"; $out .= "<h3>{$p->title}</h3>"; $out .= "<img src='{$p->image->first()->url}'>"; $out .= "</div>"; } return json_encode(["html" => $out]); }
  5. Maybe you can't access php files directly, not sure. I have an ajax template and a page, using the template, that i use as the ajax url.
  6. I'm caching a big loop (~1000 pages in a pagetable field) and i want to delete it when a new page is added and after that i want to recreate it with php to avoid users waiting for 10 seconds. I figured out the deletion part $path = $config->paths->assets."cache/MarkupCache/cache_name/"; if(file_exists($path)){ CacheFile::removeAll($path, true); } How can i rebuild the cache with php?
  7. @oma It's sanitizer, i forgot the r, updated the code too.
  8. @oma Yes If you use the current page you can access the page fields by using $page->fieldname. If you use a separate page you have to send the page id with the request if you need it.
  9. <div class="onClick" data-letter="a">A</div> <div class="onClick" data-letter="b">B</div> <div class="content">Contains default data that will get replaced by ajax data</div> $('.onClick').on('click', function(){ var letter = $(this).data('letter'); // gets the value of data-letter from the clicked element $.ajax({ url: ajaxUrl, type: 'POST', dataType: 'json', data: { // post variables 'action': 'filterPages', 'letter': letter }, }).done(function(data){ $('.content').html(data.html); // or // $('.content').append(data.html); // or // $('.content').preppend(data.html); }) }) if($this->config->ajax && $this->input->post->action == "filterPages") { $letter = $sanitizer->selectorValue($this->input->post->letter); $p = $pages->get("template=templateName, name^={$letter}"); $out = "<div>{$p->title}</div>"; return json_encode(["html" => $out]); }
  10. <div style="text-overflow: ellipsis; overflow: hidden; white-space: nowrap;"><?php echo $child->title; ?></div>
  11. You could use masonry or make sure the titles don't take more than a row. You can do the later with css .title-container { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } As for google you can have longer titles, they will just not be displayed fully in search results. You can look at other sites and see how they handle it.
  12. It's because the cisco block has a smaller height than the software one, so the hardware block floats all the way to the left, followed by the networking block. In the second case the software block in higher than the hardware and it prevents the networking block from floating all the way to the left and it gets stuck there leaving no space for the cisco block.
  13. @ryan your function $depth = -1; foreach($page->repeater_items as $item) { if($item->depth > $depth) { echo "<ul>"; } else if($item->depth < $depth) { echo "</ul>"; } echo "<li>$item->title"; $depth = $item->depth; } while($depth--) echo "</ul>"; doesn't account for jumping more than 1 depth, when going from depth 3 to 0 it will output only one </ul> breaking the nesting. Maybe while($depth--) echo "</ul>"; was supposed to take care of that? For me it didn't actually change anything, that i could actually see. Here is how i "fixed" it: $depth = -1; foreach($page->repeater_items as $item) { if($item->depth > $depth) { echo "<ul>"; } else if($item->depth < $depth) { // changed from echo "</ul>"; echo str_repeat("</ul>", $depth - $item->depth); } echo "<li>$item->title"; $depth = $item->depth; } while($depth--) echo "</ul>";
  14. @cyberderf I mean look at the available options and use the one that fits, if none fits then explain in more detail what and when you want to happen.
  15. @Tom. is because of the namespace, adding a backslash (\) before WireDT should fix it. http://stackoverflow.com/questions/8610729/cannot-find-class-with-php-namespace
  16. @cyberderf Check a field's visibility options under the input tab.
  17. If comments are sorted newest to oldest than the nested ones are also sorted like that. To have the nested comments sorted oldest to newest add if( $parentID !== 0 ){ $comments = $comments->sort("created"); } at the top of the function.
  18. It's totally fine, but you can also use count() on all WireArray objects and get the same result. https://processwire.com/api/ref/wire-array/count/ $child->children->count; // or $child->children->count();
  19. count('$child->children') remove the quotes.
  20. You have to implement it to benefit from it, otherwise that tutorial would be pretty meaningless.
  21. I think it refers to the the fact that it's set to true in wire/config.php /** * Protect CSRF? * * Enables CSRF (cross site request forgery) protection on all PW forms, recommended for improved security. * * @var bool * */ $config->protectCSRF = true;
  22. I mean you have an extra checkbox field in your template and when you give someone the unlimited minutes plan you check the checkbox. This adds another step in your code though, as you have to verify if the checkbox is checked for every plan. // isUnlimited is the checkbox fields name // numberOfMinutes is the field that holds the number of minutes if($page->isUnlimited == 1) { $plan = "unlimited"; } else { $plan = $page->numberOfMinutes; } // so if the checkbox is checked the plan becomes unlimited regardless of what the value of numberOfMinutes is Might be possible with a custom sort function, but what you could also do is have one variable for -1 and one for the rest $plans = ""; foreach($page->numberOfMinutes as $minutes) { if($minutes == -1) { $plan = "unlimited"; continue; } $plans .= "{$minutes} <br>"; } echo $plans . $plan; // or echo $plan . $plans; Or you could simply add a huge number for the unlimited plan like 999999 (that's about 694 days in minutes).
  23. -1 or have a checkbox that ignores the number of minutes when checked.
  24. Instead of hooking the url method i added a new method to the Pagefile object public function init() { parent::init(); $this->addHook('Pagefile::s3url', $this, 's3url'); } protected function s3url($event) { $ssl = ($this->useSSL) ? 'https' : 'http'; $domain = $this->domain(); $event->return = "{$ssl}://{$domain}/" . $event->object->page . "/" . $event->object->name; }
  25. FieldtypeFileS3 https://github.com/f-b-g-m/FieldtypeFileS3 The module extends the default FieldtypeFile and InputfieldFile modules and adds few extra methods. For the most part it behaves just like the default files modules, the biggest difference is how you get the file's url. Instead of using $page->fieldname->eq(0)->url you use $page->fieldname->eq(0)->s3url(). Files are not stored locally, they are deleted when the page is saved, if page saving is ommited the file remains on the local server until the page is saved. Another difference is the file size, the default module get the file size directly from the local file, while here it's stored in the database. There is an option to store the files locally, its intented in case one wants to stop using S3 and change back to local storage. What it does is it changes the s3url() method to serve files from local server instead of S3, disables uploading to S3 and disables local file deletion on page save. It does not tranfer files from S3 to local server, that can be done with the aws-cli's through the sync function. Files stored on S3 have the same structure as they would have on the local server. -------------------------------------------------------- -------------------------------------------------------- Been struggling with this for quite a while, but i think i finally managed to make it work/behave the way i wanted. All feedback is welcome!
×
×
  • Create New...