![](http://processwire-forums.s3.us-west-2.amazonaws.com/set_resources_6/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
Jo J
Members-
Posts
39 -
Joined
-
Days Won
1
Everything posted by Jo J
-
I moved the pages out of under the Admin level & to the normal Pages level. and this worked: public function init() { parent::init(); $this->addHookAfter('Pages::saved', $this, 'redirectAfterSave'); } public function redirectAfterSave(HookEvent $event) { $page = $event->arguments[0]; if($page->template->name === self::module_template) { $app_url = $this->config->urls->admin . 'myapp/'; $this->wire('session')->redirect($app_url); } } I need to do more reading on the Admin mechanics.
-
I've created a process module that saves pages under the Home > Admin > MyPages level in the admin. The module has a list of those pages created with links to allow further editing via PW's normal Page Edit. Upon clicking it, the form opens for editing. To stay away from the Admin territory (hidden by default), I'd like to redirect back to the module's home after saving my edits but am not successful so far. I've been trying a bunch of ways I see here in the forum & the docs. Among some that do not appear to trigger (from my ProcessMyApp.module.php) are: 1) Derived from my understanding of API doc init() { parent::init(); //$this->wire()->processPageEdit->setRedirectPath('/myapp/'); $this->wire()->processPageEdit->setRedirectUrl($this->config->urls->admin . '/myapp/'); } 2) Derived from Ryan's /site/modules/RedirectPageEdit.module here init() { parent::init(); $this->wire()->session->addHookBefore('redirect', $this, 'redirectAfterSave'); } 3) Also derived from my understanding of API doc init() { parent::init(); $this->wire()->addHookAfter('ProcessPageEdit::processSaveRedirect' , $this, 'redirectAfterSave'); } The redirectAfterSave: public function redirectAfterSave(HookEvent $event) { $process = $event->object; $page = $process->getPage(); bd($event,'Tracy no see'); if($page->template->name === self::module_template) { $event->arguments = array($this->config->urls->admin . 'myapp/'); } } What could I be overlooking? Tried in Processwire 3.0.243 & 3.0.244
-
@Dave NicholsI too am not clear, but if you want to remove anchor tags from a body I would do something like this: in ready.php wire()->addHookBefore('Pages::saveReady', function(HookEvent $event) { $page = $event->arguments(0); if ($page->name == 'parent-name') { $body = $page->body; // Use regex to remove anchor tags but keep the inner text $bodyWithoutAnchors = preg_replace_callback( '/<a[^>]*>(.*?)<\/a>/is', // Match <a> tags with content function ($matches) { return $matches[1]; // Return the inner text }, $body ); // Update the page body if ($body !== $bodyWithoutAnchors) { $page->body = $bodyWithoutAnchors; } } }); Backup your database & test with care as the above pattern will unlink ALL "<a>" tags. you may want to adjust the pattern to the children accordingly.
-
Can anyone advise / assist with a site recovery?...
Jo J replied to creativeguy's topic in General Support
If you have access to a front-end template or a script that can execute PHP within your ProcessWire environment...add this code temporarily. echo wire('config')->urls->admin; This will output the admin URL, e.g., websiteurl.com/processwire/. -
@bernhardIn this test, I didn't want to install benchmark tools, so I just used PHP (code below) with the following results: test 1) Elapsed Processwire Boot time Apache/2.4.62: 0.1405s Page load time: 6.53 ms Database query time: 0.5 ms Memory used: 325.21 KB Elapsed Processwire Boot time nginx/1.26.1: 0.1175s Page load time: 4.68 ms Database query time: 0.65 ms Memory used: 256.13 KB test 2) Elapsed Processwire Boot time Apache/2.4.62: 0.2145s Page load time: 6.42 ms Database query time: 0.45 ms Memory used: 325.21 KB Elapsed Processwire Boot time nginx/1.26.1: 0.1512s Page load time: 4.86 ms Database query time: 0.64 ms Memory used: 256.13 KB test 3) Elapsed Processwire Boot time Apache/2.4.62: 0.1809s Page load time: 48.97 ms Database query time: 0.7 ms Memory used: 325.21 KB Elapsed Processwire Boot time nginx/1.26.1: 0.0909s Page load time: 4.65 ms Database query time: 0.64 ms Memory used: 256.13 KB <?php $home = $pages->get('/'); /** @var HomePage $home */ $start_time = microtime(true); $start_memory = memory_get_usage(); $start_query_time = microtime(true); $pages = $pages->find("template=basic-page"); $query_time = microtime(true) - $start_query_time; ?> ?><!DOCTYPE html> <!-- STANDARD >main.php body--> <?php $end_time = microtime(true); $page_load_time = $end_time - $start_time; $end_memory = memory_get_usage(); $memory_used = $end_memory - $start_memory; $elapsed = Debug::stopTimer($timer, 's'); // Debug::startTimer in index.php ?> <div> <p>Elapsed Processwire Boot time <?php echo $_SERVER['SERVER_SOFTWARE'] . ': ' . $elapsed ?><br> Page load time: <?php echo round($page_load_time * 1000, 2); ?> ms<br> Database query time: <?php echo round($query_time * 1000, 2); ?> ms<br> Memory used: <?php echo round($memory_used / 1024, 2); ?> KB</p> </div> </body> </html> Breakdown of results: Elapsed ProcessWire Boot Time: NGINX consistently shows lower boot times, indicating it may handle PHP requests more efficiently than Apache in this test case. Page Load Time: The page load time in the third test for Apache (48.97 ms) is an anomaly I can't explain. Caching? Network latency? Database Query Time: Apache and NGINX have similar query times Memory Used: Memory usage is relatively low, and the difference between the two servers is not substantial.
-
Just wondering, if access to PHP files other than index.php in the site root is blocked (e.g., via the PW default .htaccess in the root), wouldn't this suggest that any .htaccess rules in a module subdirectory (like abc.om/site/modules/Module-name/.htaccess) would not have any effect on the overall operation of your ProcessWire site in Apache?
-
Wow good point. From here on, it might be wise to check if a module has its own htaccess file. I haven't come across one yet.
-
Undefined array key "SCRIPT_NAME" in wire/core/ProcessWire.php on line 1175
Jo J replied to kylxbn's topic in General Support
I vaguely recall this happening to me too. But that was a while back for me to know how it got fixed. Have you tried checking your httpHosts in config is complete? $config->httpHosts = array('localhost','yourdomain.com') or ensure you have the correct index.php & .htaccess that goes with ProcessWire 3.0.229? -
Using named pipes in Windows - Install.php changes
Jo J replied to Greenhorn's topic in General Support
I use unix sockets in my dev environment too and am surprised to find just one of you here. I opened an issue to see if it gets in. -
I used to do this. Sometime before version 3.0.184. I symlinked just the wire folder inside multiple installations...until I started getting duplicate module errors. I don't remember if it was due to class loading issues or minor differences in file path/directory structure between installations but there was definitely conflicting issues. It could have been cache related too. It didn't work for me.
-
JSYK, this issue has been fixed by Ryan. His preferred fix also addresses when the #login_start gets stale via cache which is important. Issue #1839 corrects ProcessLogin refresh issue when client and server have different times for UTC/GMT. The fix has been pushed to the current dev branch as of today for continued testing.
-
I also experienced this issue. Following on netcarver's advice above, it turns out that my device clock is ahead by over 5 minutes. I adjusted my device time & it worked but thought a broader solution might be better. This fixed my issue. var startTime = parseInt($('#login_start').val()); // GMT/UTC // var maxSeconds = 300; // max age for login form before refreshing it (300=5min) var clientStartTime = Math.floor(new Date().getTime() / 1000); var clockDifference = clientStartTime - startTime; var maxSeconds = 300 + clockDifference; But I prefer it be done in the core, so I opened an issue in github.
-
Double quotes getting added in page Title via API save
Jo J replied to Jo J's topic in General Support
I ought to have known better. It's not a title issue, rather it's the name--that I should be validating for existence. (And the sanitizer->selectorValue doesn't help either. So, here's what worked: --same-- $title = $row['title']; $name = wire('sanitizer')->name($title,true,128,'-'); $p = wire('pages')->get("name={$name}"); // check if name already exists if(0 < $p->id) { continue; } --same-- Is there a better answer? -
Double quotes getting added in page Title via API save
Jo J replied to Jo J's topic in General Support
I thought I solved it with addslashes($title). But it didn't work either. -
fixed site by enabling debug, install tracy, and then removing both ?!
Jo J replied to joe_g's topic in General Support
I seem to remember this happen to me too. I came across @horst's comment to avoid it: with old wire version, make a db dump, but for all caches use drop table, create table, without inserts. Or, if you are able, remove the inserts in the live db. remove all files within the cache disc subdirectories switch wire folder, load the admin for 2 or 3 times -
Using the ff snippet I derived from one kind member here (sorry, I can't remember & I also cleared my browser cache), I cannot figure out how to avoid double quote enclosures on titles with commas that are being added in the admin: while($row = $files->getCSV('importwines.csv',['separator' => '|'])) { $title = wire('sanitizer')->selectorValue($row['title']); $title = wire("sanitizer")->text($title, array("maxLength"=>128)); // fetch and sanitize the title $p = wire('pages')->get("title={$title}"); // check if it already exists if(0 < $p->id) continue; // move on to the next record if it exists $p = new Page(); $p->template = "wine-item"; $p->parent = "wine-list"; $p->title = $title; // use the sanitized title $p->vintage = wire("sanitizer")->int($row['vintage']); $p->price = wire("sanitizer")->float($row['price']); $p->category = wire("sanitizer")->int($row['category']); $p->location = wire("sanitizer")->text($row['location'], array("maxLength"=>128)); $p->of(false); $p->save(); } These are the escape characters i've tried: "vintage"|"title"|"price"|"location"|"category" 2020|"Cross Barn Chardonnay\\, Sonoma Coast"|105.00|"United States"|1324 2020|Truchard Chardonnay, Carneros|115.00|"United States"|1324 2018|"""Grgich Chardonnay, Napa Valley"""|170.00|"United States"|1324 Undesired results as page titles in the admin includes the double quotes: "Cross Barn Chardonnay , Sonoma Coast" "Truchard Chardonnay, Carneros" "Grgich Chardonnay, Napa Valley" These 3 are also being excluded by a broad $page->find($selector) selector filter unless I manually delete the double quotes in the admin. I think the $sanitizer->selectorValue() above also calls the new selectorValueV1() & selectorValueV2() because I am using PW3.0.210. Is there another sanitizer I should be using for the title?
-
Glad you solved it somehow!
- 4 replies
-
- formbuilder
- success
-
(and 3 more)
Tagged with:
-
I have no access to the module to test it myself but.. have you tried enclosing it with html tags? html:<h1>Thank you!<br>We will contact you soon.</h1>
- 4 replies
-
- formbuilder
- success
-
(and 3 more)
Tagged with:
-
LoginRegister - Display Registration Form even when already logged it?
Jo J replied to strandoo's topic in General Support
I also see your point in wanting to put it all in the same flow. It might take more time, but I would explore the module in depth coz after quick inspection the necessary methods for registration are hookable. -
LoginRegister - Display Registration Form even when already logged it?
Jo J replied to strandoo's topic in General Support
...you'd have to add $loginRegister = modules()->get('LoginRegister'); $content = $loginRegister->execute(); echo $content; -
LoginRegister - Display Registration Form even when already logged it?
Jo J replied to strandoo's topic in General Support
Yes you can. I have something similar for a blogging site. Copy/edit/improve here what makes sense to your case... wire()->addHookBefore('LoginRegister::renderList', function($event) { $links = array(); $defaults = $event->arguments(0); if(user()->isLoggedin()) { if (user()->hasRole('member')) { $links['member-list'] = "<a href='" . $this->wire('pages')->get('/directory/')->url . "'>" . $this->_('Member Directory') . "</a>"; } if (user()->hasRole('author')) { $links['blog-admin'] = "<a href='" . $this->wire('pages')->get('/utilities/blog-admin/')->url . "'>" . $this->_('Blog Admin') . "</a>"; } if (user()->hasRole('admin')) { $links['back-admin'] = "<a href='" . $this->wire('pages')->get('template=admin')->url . "'>" . $this->_('Page Admin') . "</a>"; } } else { if($event->object->allowFeature('register')) { $defaults['register'] = "<p>Don't have an account yet? Members can <a href='./?register=1' class='inline'>" . $this->_("register for an account") . "</a></p>"; } } $links = array_merge($links, $defaults); $event->arguments('items', $links); }); -
Was curious too. I searched and, yes, it was brought up before. Here. TLDR. As mentioned there, it becomes more important when multiple programmers are (or will be--next guy after you) involved. Also mentioned, was the additional benefit of self-documentation when you follow a naming convention. To answer your question, being all implementors of the PW architecture (and PHP), it probably makes sense for us to be consistent with it. (Compared to other frameworks PW made it easy for us.) Still, I did another round of refactoring recently and felt happier after. None of my direct templates have echos. Reduced them to about 10. Since they mostly describe a type of page (model), it's a 1 word all-lowercase filename. I have a couple of controller classes that I camelCased with an .inc extension so the admin wont see it...and added an underscore so its listed on top. I guess we all have different reasons.
-
I'm not really sure if this will lead you to something or nothing, but have you tried using a compatible jquery version in the FE? The PW BE uses jquery 1.11.1 with a migrate version 1.2.1 but in my testing jquery ver 2.2.4 worked too. It works for me using something like the following: echo "<div edit='",$input->get->id,".images' >","<a>dbl-click to edit</a></div>"; $scripts = "<script type='text/javascript'>" . "$(document).on('pw-modal-closed', '.pw-edit-modal', function() {" . "var saveButton = document.getElementById('button_save');" . "saveButton.click();" . "});" . "</script>"; $jquery_version = "2.2.4"; Then in my main template I add that jquery variable because for regular FE pages, I use another jquery version. <script>window.jQuery || document.write('<script src="<?php echo $config->urls->skin, "js/jquery-{$jquery_version}.min.js"; ?>"><\/script>')</script>
-
I just checked my values in a Ubuntu 18 distro and sure enough I get 0, 1000, 1440 for those 3 settings. Thank you much for this. I will be testing and applying your findings for sure.
-
For a front-end search form? One strategy I often use is concatenating the selector one input field at a time. Just make sure your add your validation. Something like this: $selector = ''; if($place = sanitizer()->selectorValue($input->post->place)) { $input->whitelist('place', $place); $selector .= ", place%=$place"; } if($input->post->doctor) { $input->whitelist('doctor', $input->post->doctor); if($input->post->doctor == '1') { $selector .= ", name=jim"; } elseif($input->post->doctor == '2') { $selector .= ", name=jon"; } elseif($input->post->doctor == '3') { $selector .= ", name=jake"; } } $limit = 12; $template = doctor; $parent = doctors; $selector .= ", sort=sort, limit=$limit"; $selector = "template=$template, parent=$parent" . $selector; $results = pages()->find->($selector);
- 1 reply
-
- 3
-