rash
-
Posts
112 -
Joined
-
Last visited
Posts posted by rash
-
-
@horst: Thanks a lot, that was very helpful. First I lost overview a bit, then I found this older thread with you being involved too, that brought the final kick. Now this is working fine:
$img_url = "https://example.com/index.php?cust=foo&id=1234&filename=d9b88153-89e4.jpg"; $img_query = parse_url($img_url, PHP_URL_QUERY); parse_str($img_query, $params); $filename = $params["filename"]; // result: d9b88153-89e4.jpg $page->of(FALSE); $page->imgs->add($img_url); // add image to multi-image field $imgs $page->save("imgs"); // save added image with unwanted name index.php // w/o trackChange() file seems to get renamed in file system but not in db $page->imgs->trackChange("basename"); // eq(0) is the right image in my case, other selectors are possible $image = $page->imgs->eq(0); $image->removeVariations(); // delete variations (thumbnails etc.) $image->rename($filename); // rename index.php to d9b88153-89e4.jpg $page->save("imgs"); // save changes to $imgs field
I’m pretty glad to have that annoyance solved, so thank you very much once more.
PS: The mess in the dumps above resulted from a typo in deleteAll() before saving the new image, so more than one image was saved.
- 1
-
Okay @horst, you asked for it ?, this is $imgs1:
object(ProcessWire\Pageimages)#359 (6) { ["count"]=>int(2) ["page"]=>string(7) "/probe/" ["field"]=>string(4) "imgs" ["url"]=>string(24) "/site/assets/files/1338/" ["path"]=>string(67) "/www/htdocs/w0097e14/example.de/site/assets/files/1338/" ["items"]=>array(2) { ["index.php"]=>array(14) { ["url"]=>string(33) "/site/assets/files/1338/index.php" ["filename"]=>string(76) "/www/htdocs/w0097e14/example.de/site/assets/files/1338/index.php" ["filesize"]=>int(0) ["description"]=>string(0) "" ["tags"]=>string(0) "" ["created"]=>string(19) "04-04-2021 13:18:54" ["modified"]=>string(19) "04-04-2021 13:18:54" ["created_users_id"]=>int(41) ["modified_users_id"]=>int(41) ["filemtime"]=>string(19) "01-01-1970 01:00:00" ["width"]=>int(0) ["height"]=>int(0) ["suffix"]=>string(0) "" ["variations"]=>array(1) { [0]=> string(15) "index.0x260.php" } } ["kunde_example_datensatz_10497_filename_d9b88153-89e4-4129-aa70-06ab8b137181.jpg"]=>array(13) { ["url"]=>string(115) "/site/assets/files/1338/kunde_example_datensatz_10497_filename_d9b88153-89e4-4129-aa70-06ab8b137181.jpg" ["filename"]=>string(158) "/www/htdocs/w0097e14/example.de/site/assets/files/1338/kunde_example_datensatz_10497_filename_d9b88153-89e4-4129-aa70-06ab8b137181.jpg" ["filesize"]=>int(0) ["description"]=>string(0) "" ["tags"]=>string(0) "" ["created"]=>string(19) "04-04-2021 18:13:05" ["modified"]=>string(19) "04-04-2021 18:13:05" ["created_users_id"]=>int(41) ["modified_users_id"]=>int(41) ["filemtime"]=>string(19) "01-01-1970 01:00:00" ["width"]=>int(0) ["height"]=>int(0) ["suffix"]=>string(0) "" } } }
And this is $imgs2:
object(ProcessWire\Pageimages)#365 (6) { ["count"]=>int(2) ["page"]=>string(7) "/probe/" ["field"]=>string(4) "imgs" ["url"]=>string(24) "/site/assets/files/1338/" ["path"]=>string(67) "/www/htdocs/w0097e14/example.de/site/assets/files/1338/" ["items"]=>array(2) { ["index.php"]=>array(14) { ["url"]=>string(33) "/site/assets/files/1338/index.php" ["filename"]=>string(76) "/www/htdocs/w0097e14/example.de/site/assets/files/1338/index.php" ["filesize"]=>int(0) ["description"]=>string(0) "" ["tags"]=>string(0) "" ["created"]=>string(19) "04-04-2021 13:18:54" ["modified"]=>string(19) "04-04-2021 13:18:54" ["created_users_id"]=>int(41) ["modified_users_id"]=>int(41) ["filemtime"]=>string(19) "01-01-1970 01:00:00" ["width"]=>int(0) ["height"]=>int(0) ["suffix"]=>string(0) "" ["variations"]=>array(1) { [0]=>string(15) "index.0x260.php" } } ["kunde_example_datensatz_10497_filename_d9b88153-89e4-4129-aa70-06ab8b137181.jpg"]=>array(13) { ["url"]=>string(115) "/site/assets/files/1338/kunde_example_datensatz_10497_filename_d9b88153-89e4-4129-aa70-06ab8b137181.jpg" ["filename"]=>string(158) "/www/htdocs/w0097e14/example.de/site/assets/files/1338/kunde_example_datensatz_10497_filename_d9b88153-89e4-4129-aa70-06ab8b137181.jpg" ["filesize"]=>int(0) ["description"]=>string(0) "" ["tags"]=>string(0) "" ["created"]=>string(19) "04-04-2021 18:08:41" ["modified"]=>string(19) "04-04-2021 18:08:41" ["created_users_id"]=>int(41) ["modified_users_id"]=>int(41) ["filemtime"]=>string(19) "01-01-1970 01:00:00" ["width"]=>int(0) ["height"]=>int(0) ["suffix"]=>string(0) "" } } }
Obviously there is something unwanted happening after $page->images->add(), as the whole URL gets transformed to a string with _ dividers and affects as well as filename I can see this is crap but not how to prevent it and why it doesn't work to at least rename filename (renaming url should be not problem after). (Btw: Don’t ask me why this text appears as a link …)
-
Thanks @horst – sadly your suggestion is not working, no matter whether I do $page->save('imgs') once or twice, the filename remains index.php persistently. I’ve also tried to select the image with imgs->eq(n) instead of $imgs->last, but no success.
-
Hi all,
I would like to copy external images to PW image fields via API. Under "normal" circumstances the process is absolutely simple and working without the slightest problem. Now in a current project there are image urls where the filename is just a parameter in a generic URL like so:
$img_url = "https://example.com/index.php?cust=foo&id=1234&filename=d9b88153-89e4.jpg"; $page->of(FALSE); $page->imgs->add($img_url); $page->save(); $page->of(TRUE);
Result: The image gets copied "correctly", means: the file physically reaches it’s target directory, but it’s filename is expectedly "index.php", therefore the data field in the db image table stays empty. Of course I can isolate the filename d9b88153-89e4.jpg of the URL quite easily with parse_url() and parse_str() but don’t find a way to transfer the filename to the image. $page->imgs->data = $filename, $page->imgs->name = $filename and $page->imgs->filename = $filename are not working.
-
Hi all,
I’m building a simple frontend login system for a specific role, using the LoginRegister module. I want users of this role to login with email and password, which is working just fine. I would also like to allow those users to change their password, but not their email address. In the LoginRegister config I obvioulsy can’t get rid of the email and password field, so there is no option to limit the profile fields to password only.
I tried it with the following (quick’n dirty) hook:
wire()->addHookAfter('LoginRegister::buildProfileForm', function(HookEvent $event) { $form = $event->return; $email_field = $form->getChildByName('profile_email'); $form->remove($email_field); $event->return = $form; });
First it seems to do the trick, as there is no email field displayed anymore, but after submitting the form I get Uncaught Error: Call to a member function val() on null in /…/site/modules/LoginRegister/LoginRegister.module:913. I guess an email value is expected, so I tried to submit it separately:
wire()->addHookAfter('LoginRegister::buildProfileForm', function(HookEvent $event) { $form = $event->return; $email_field = $form->getChildByName('profile_email'); $form->remove($email_field); $usermail = $event->wire('user')->email; $email_field->value = $usermail; $event->return = $form; });
No luck, the error stays the same. Is there a more intelligent way to limit the profile edit options to password and nothing else?
-
Okay, thank you – that might be an explanation, as on this particular site 3.0.142 is running. You think it would be possible to just replace ProcessForgotPassword.module? I’m not sure if I should do a complete PW update, as there are quite a few loose ends in this project at the moment and I fear to lose the overview. Worst case would be to postpone the PW reset smoothening until PW will be updated later.
-
On 5/24/2020 at 12:22 PM, Robin S said:
Adding some code to expand on my post above. In /site/ready.php:
// Forgot password: pre-fill verify field from URL parameter $wire->addHookBefore('ProcessForgotPassword::renderForm', function(HookEvent $event) { $form = $event->arguments(0); $form_name = $event->arguments(1); if($form_name !== 'step3') return; $verify_field = $form->getChildByName('verify'); if(!$verify_field) return; $code = $event->wire('input')->get('code'); if(!$code) return; $verify_field->description = 'Please type or paste in the code you received in your email if it is not already shown below.'; $verify_field->value = urldecode($code); });
I just set this up on a site and it seems to be working well.
@Robin S While trying to get a password reset process a bit smoother, I stumbled upon your hook that looks very promising. Maybe I didn’t get it correctly, but it seems that ProcessForgotPassword::renderForm is not working. There is no method ___renderForm in ProcessForgotPassword.module, so nothing at all happens after clicking the (successfully modified) email link. When I try ProcessForgotPassword::execute instead I get at least a reaction, but I don‘t know how to select the field verify to populate. It’s not crucial, as I can live with the unsmoother copy-paste-code as well, but I would prefer to do it the way you suggested.
-
Got it now – a bit embarassing how long it took:
$text = $comment->text; $modules->TextformatterTextileRestricted->formatValue(new Page(), new Field(), $text);
Or, in my case, as I format the comments inside a function:
$text = $comment->text; wire('modules')->TextformatterTextileRestricted->formatValue(new Page(), new Field(), $text);
Suddenly the day showed a brighter coloring.
-
Hi all,
I’m using the Textile module for all of my own and most of my client’s sites and that works just fine. For the first time I have the need to allow a bit basic formatting in a user input textarea delivered by the PW comment system and I don’t know how to "textilize" the comment text. The line in my comments output:
$text = $comment->getFormatted('text');
getFormatted() replaces double line breaks with </p><p> and offers the option to nest the whole thing in opening and closing <p> tags. So I will probably have to get unformatted text instead and format it with Textile Restricted. I guess this will be very easy, but can’t find the right method for it.
-
Is it possible to pass session vars immediately in Hanna Code?
Let’s say, I include two PHP files file_1.php and file_2.php via Hanna Code input in a textarea. When I set $session->foo = "bar" in file_1.php and try to get the value in file_2.php it is not there before page reload. Obviously it has to do with the rendering/formatting order. Is there a more or less dirty trick to intrude the session vars into Hanna Code in the first run?
-
Meanwhile I found a solution. It might be not the most elegant one, but leads straight to the expected result. Just in case someone else is interested:
<?php /** * Render a nested list of comments to a page recursively * @param array $page->comments * @param int $maxDepth comment levels, usually the same as set in comments settings * @param array $doneComments, keeping ids of already processed comments * @return string * */ function renderComments($comments, $maxDepth = 0, $doneComments) { $out = ""; global $doneComments; foreach($comments as $comment) : $id = $comment->id; // comment already processed -> next loop if (in_array($id, $doneComments)) continue; // comment never seen before -> fill in array and go ahead $doneComments[] = $id; $out .= "\n<li>"; // add comment content here if($comment->children() && $maxDepth) { $out .= renderComments($comment->children, $maxDepth-1, $doneComments); } $out .= "</li>"; endforeach; if ($out) $out = "\n<ul class='level-".$maxDepth."'>".$out."</ul>\n"; return $out; } global $doneComments; $doneComments = array(); echo renderComments($page->comments, 3, $doneComments); ?>
Each comment’s id goes into an array that labels it as 'done'. In the next loop we check the array whether the current comment is already 'done' and continue if so.
-
Hi there,
I’m struggling with a threaded comment system based on this function:
<?php function renderComments($comments, $maxDepth = 0) { $out = ""; foreach($comments as $comment) : $out .= "\n<li>"; // add comment content here if($comment->children() && $maxDepth) { $out .= renderComments($comment->children, $maxDepth-1); } $out .= "</li>"; endforeach; if ($out) $out = "\n<ul class='level-".$maxDepth."'>".$out."</ul>\n"; return $out; } ?>
Let’s say, there are 9 comments and 3 levels in this order:
com-1
---- com-2
--------- com-4
--------- com-5
--------- com-7
---- com-3
--------- com-6
--------- com-8
--------- com-9In this example, the function above returns:
com-1
---- com-2
--------- com-4
--------- com-5
--------- com-7
---- com-3
--------- com-6
--------- com-8
--------- com-9
com-2
---- com-4
---- com-5
---- com-7
com-3
---- com-6
---- com-8
---- com-9
com-4
com-5
com-6
com-7
com-8
com-9The problem is obviously caused by some logic issues in the recursion. When I use basically the same function for a page tree, everything works as expected. The comments seem to be structured different, especially their child roles. How can I stop the output after round 1 to get the expected result? Thanks in advance.
-
Update: The issue was obviously fixed by @ryan and is working fine now. Tested with PW 3.0.168. Thanks a lot!
-
Another thanks @dragan , Page::loaded was indeed the wrong method. ProcessPageEdit::buildForm delivers the $page object I was looking for – that's great! I have to play around a little with details to find out whether After or Before work better for my needs. Btw: I didn’t want to conceal the big plan, but I first had to check if I get the edit page object done before I could start to concretize a few foggy approaches for getting some rather weird customer wishes done.
-
Thanks, @dragan, I guessed exactly the same ? Unfortunately that guess didn’t lead me to somewhere useful yet. When I do
$wire->addHookAfter('Page::loaded', function($event) { $page = $event->object; if ($page->whatever) { // do something } });
$page contains all pages, not just the one I’m currently editing. Is there any chance to isolate this particular page in an object?
-
Hi all,
when I’m editing a page in the backend, eg. /processwire/page/edit/?id=1032, is there a way to get the currently edited page (here: id=1032) as a page object, let’s call it $pageInEdit? The big plan behind would lead a bit too far, just a simple example what I would like to achieve:
if ($pageInEdit->field == 'foo') { // send a message or do something else }
Thanks in advance
-
@MoritzLost This is a very elegant approach indeed! I’ve already built it in and it works flawlessly. I also appreciate it’s temporary nature that allows me to keep everything like it is, and just get rid of the helper field and the hook as soon as the select issue might be fixed someday. So another big thanks for that! (Btw: time comsumption was manageable, 5 minutes or so …)
- 1
-
@Robin S Thank you for the information and opening a new issue. The sort option on the mentioned site is not critical, but as I work with Select Options quite often, I’m looking forward to a fix in the hopefully not too distant future. I agree to your (and @MoritzLosts) suggested Page Reference workaround – it’s one of my favourite field types, but sometimes seems a bit oversized for minor settings.
-
Thanks to both of you. I forgot to mention that I tried it with separated values before, unfortunately the same thing happened. In any case the db table field-direction just stores IDs so sort=direction sorts by those numbers. sort=direction.value is leading to the same error as sort_direction.title (1054 Unknown column) and sort=direction->value as well as sort=direction->title do no sort at all. I was hoping it would be just a syntax problem, obviously things are a bit more complicated …
-
Hi,
I would like to sort pages by the title of their Select Options field direction. Its easy to sort them by their option ID but not by their title. The ID’s/titles are:
1=north 2=west 3=south 4=east
I would like them sorted alphabetically: east, north, south, west. What I’ve tried so far:
$tracks = $pages->find("template=basic, sort=direction); // sorts north, west, south, east following the ID’s $tracks = $pages->find("template=basic, sort=direction->title); // sorts nothing at all $tracks = $pages->find("template=basic, sort=direction.title); // error: field not found
If there’s no better way, I could change the select options so that ID’s and titles have the same order. Unfortunately there are quite a few pages that would need to get edited, so I’d like to avoid that.
Thanks in advance
-
Thanks a lot, dragan. You’re right, I should have specified the "where" a bit more – in this case I meant the page itself in edit mode as in your case 2. Anyway, I checked out the runtime markup field and it does exactly what I was looking for with very little effort. Perfect solution!
- 1
-
Hi guys,
I’m dealing with a problem that first didn’t even look as one, before I found out that it might not be that easy. I would like to have a link list of external sources referenced by page X. Something similar to the Page field but for external web pages and with different numbers of references. I tried to do it with a repeater field containing a text input and an URL field. That’s nearly all I want, except that I’d like it to be clickable on the admin page like so:
<li><a href='URL_1'>TEXT_1</a></li>
<li><a href='URL_2'>TEXT_2</a></li>The link list will be used for admin purposes only, as there are several research sources per page, that would be faster accessible than by copying/pasting URLs out of the input fields. So it’s more an admin GUI problem, as it would of course be no big thing to render a link list on the frontend.
Any ideas to get that done?
-
Hi guys,
I was working with the Images Extra module for quite a while, and now I’m trying to migrate a bunch of those fields to the new core solution that came with PW 3.0.142. So far, anything is great except one thing I neither like nor understand. All custom fields corresponding with an image are stored in the filedata column like so:
{"_field_1_id":"value_1", "_field_2_id":"value_2", etc.}
Now some of the values store unicode escapes for diacritical characters like ü, ö, ä, ß (eg. 'K\u00fcche' instead of 'Küche') while other values of the same type are stored unescaped. Unfortunately I cannot detect any system, values from the same fields store identical values sometimes escaped, sometimes unescaped.
Although the output works fine in any case, looking at things like 'K\u00fcche' slightly depresses me, so I would prefer to store all values in proper, readable characters. How could I do that?
-
Thanks a lot, arjen and Robin S. At least my ignorance of the notes in the settings tabs is undoubtedly a bit embarrasing. But good to understand it for now and the future.
- 1
[Solved] Reconstruct PW site when server data is lost?
in Getting Started
Posted
Hi all,
due to pure stupidity I managed to delete the complete root directory of a site without having a backup. [ short break to shake head, rofl etc. ] Luckily the database still exists and so do nearly 100 percent of the site directory. My first thought was to simply make a fresh install and change config.php data to use the existing database. Unfortunately the backend keeps me out and suspects whatever to be 'forged'. I guess it has to do with $config->userAuthSalt and/or $config->tableSalt. So is there any chance to connect a fresh install with an existing database? That would at least save me a few hours.