hellomoto
Members-
Posts
386 -
Joined
hellomoto's Achievements
-
module Cacheable Placeholders - Dynamic replacements for cached content
hellomoto replied to MoritzLost's topic in Modules/Plugins
I'm trying to use this with a form using InputfieldForm. I have a hook that replaces its CSRF after InputfieldForm::render... but since it generates a CSRF input automatically I assume I can't just overwrite it post-render, because it's expecting what it put out? Maybe I should just add a placeholder for the form itself? (ajax) // ready.php $this->addHookAfter('CachePlaceholders::getTokens', null, 'cachePlaceholders'); function cachePlaceholders(HookEvent $e) { $tokens = $e->return; // defaults $e->return = $tokens; }; // don't cache CSRF in forms on frontend: $this->addHookAfter('InputfieldForm::render', null, 'frontendFormsCSRF'); function frontendFormsCSRF(HookEvent $e) { if ($e->wire()->page->rootParent->id == 2) return; $pattern = '/<input ([^<>]*) class=\'_post_token\' \/>/'; $replace = '{{{csrf::contact}}}'; // bd($e->return); $replaced = preg_replace($pattern, $replace, $e->return); $CP = $e->wire()->modules->get('CachePlaceholders'); $return = $CP->replaceTokens($replaced); // bd($return); $e->replace = true; $e->return = $return; } Then to process the form I put // inquire.php if ($input->post->message) { $sessionCSRF->hasValidToken('contact'); $form->processInput($input->post); // ... } but it isn't submitting because of CSRF issue. -
@FireWire Actually MarkupSitemapXML seems fitting for multisite because it does cache the XML anyway, one can simply change the cache time in the module code or add a config option to do so.
-
Released: Street Address Fieldtype + Inputfield
hellomoto replied to netcarver's topic in Modules/Plugins
Why does the locality & admin_area output in all caps? in the formatted output? Never mind, I found it, formats.php, thanks -
...or would that also be inefficient?
-
Sorry that seems like a very dumb question, as I read that sitemaps are not recommended for smaller websites which makes plenty of sense, and thanks for responding. In a multisite installation, I thought it would be better if possible to generate the sitemap within the respective site directory, rather than in the PW root, because each sitemap could have a different name but then they could all be accessible from each site without additional configuration? So if the sitemap is generated in the site directory (maybe add an option to the module so it detects the path and can just leave the filename input as sitemap.xml), it should be loaded from the root directory, bypassing the site directory inclusion in the URL? $wire->addHook('/sitemap.xml', null, 'returnSitemap'); function returnSitemap($event) { $path = wire('config')->paths->site.'sitemap.xml'; $file = file_get_contents($path); header("Content-Type: text/xml", true, 200); echo $file; exit; } $wire->addHook($config->urls->site.'sitemap.xml', null, 'redirectSitemap'); function redirectSitemap($event) { wire('session')->redirect('/sitemap.xml'); } // doesn't work If hookGenerateSitemap was hookable in your module, it looks like $sitemapPath just needs to be prepended with the site directory to make this automatic, in case of migration or something, to relieve users of the responsibility of changing the sitemap path in your module settings... but I'm referring to the native multisite with multiple databases and I'm thinking about how many copies of each module are present throughout the installation then (not that this add-on module would be large). But that is better than ALSO multiple copies of the core.
-
Is there a reason for rendering the sitemap XML as a file rather than rendering via a hook, as done in this module:? https://github.com/Notanotherdotcom/MarkupSitemapXML
-
Putting the line after xhttp.open does seem to make more sense. Sorry, I failed to reasonably troubleshoot that there. Thank you. It works but not as reliably as jQuery?
-
It didn't for me, thanks though
-
https://github.com/processwire/processwire/blob/44fcf13ea2d7f14a04eed54c29afcc79eb46ec45/wire/core/Config.php#L24 Searching the file for "ajax" only shows the 2 instances in the 1st comment (same line); $config->ajax is doing nothing when I try using it? I make a call to a page and it loads in the element, but $config->ajax is false in the ajax-loaded page. It works with jQuery; I was trying without it function loadlist(segment='') { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("main").innerHTML = this.responseText; } }; xhttp.open("GET", "<?=$page->url?>"+segment, true); xhttp.send(); }
-
I thought I could make an accessory module to conditionally load the core-module-extension site-module, or do so in init.php, but I can't determine whether the core module has been loaded. I tried: $modulesLoader->getAutoloadOrders() in ready.php and it says call to member function on null. class_exists('ProcessPageEditImageSelect', false) says false This works without 'noInit', but then the same problem message when inapplicable, so still need the condition check: $this->wire()->addHook('ProcessPageEditImageSelect::execute', $this->wire()->modules->getModule('ProcessPageEditImageSelect_Pickpage', ['noInit' => true]), 'hook___execute');
-
Aside from not skipping this line if(!$this->page) throw new WireException("No page specified"); within the core module's init() method, this works (it just displays that error message on every other page due to autoloading when inapplicable): public function __construct() { foreach ($this->defaultDataAddl as $k => $v) { if (!array_key_exists($k, $this->data)) $this->data[$k] = $v; } $this->addHook('ProcessPageEditImageSelect::execute', $this, 'hook___execute'); } Replace last line in hook___execute method with this: $event->replace = true; $event->return = "<div id='ProcessPageEditImageSelect'>" . $out . "\n</div>";
-
I guess the class needs to be called instead of the native one to implement its execute method. I added this in its construct: foreach ($this->defaultDataAddl as $k => $v) { if (!array_key_exists($k, $this->data)) $this->data[$k] = $v; } $this->addHook('ProcessPageEditImageSelect::execute', $this, '___execute'); and it has the data from the config, and the $this->page assignment changing, but it's not being called during instantiation in context, so it doesn't call any other of the object's methods needed to execute?