-
Posts
25 -
Joined
-
Last visited
Posts posted by iipa
-
-
Hello forum!
I have a site, where I want to remember two settings defined by user:
1) Theme (light or dark)
2) Language (Finnish or English)Because user makes changes to these settings on client side, I am a bit lost with how can I save them in ProcessWire $session variable? I would like to use $session for more reliable saving, and since it is only two variables I will use, I doubt it will become too resource-needy.
I have tried using jQuery's post() -method referring to a file in Templates folder (theme.php), but I get 403 Forbidden Error. I don't like the idea of trying to post to same file user currently is in, which is why I thought having a separate file would be good in this.
Contents of theme.php:
<?php namespace ProcessWire; header('Access-Control-Allow-Origin: https://domain.com'); $theme = $input->post['theme']; if(!empty($theme)) $session->theme = $theme; ?>
Long story short: Does anybody have any pro tips I could use with setting and getting $session variables?
-
On 9/24/2019 at 7:38 PM, horst said:
Ah ok. There is no build in solution for this. You have to build something yourself. For example, if there is currently no use of tags, (or an expandable usage of tags), with this imagefield, you may setup tags with predefined values, so that the user can select one if he like to. If this is not possible due to restricted other usage of tags, it may become very uncomfortable, as there are currently no other fields bundled together with an image (besides description and tags). I'm not sure if the imageextra module from justb3a is uptodate with the current devstate (?), If so, and if tags are no option, this would be the way to go.
Actually I came to a pretty handy solution with my co-dev! Images have information about their modification time saved within them, so using that I came up with following code:
$img = $page->image; // check if image exists if($img) { // fetch cropped images' modification timestamps $tsNormal = filemtime($img->getCrop('normaali')->filename); $tsHigh = filemtime($img->getCrop('korkeampi')->filename); $tsLow = filemtime($img->getCrop('matalampi')->filename); // check if they have the same modification time => user hasn't cropped the image, so use the original if(!($tsNormal == $tsHigh && $tsNormal == $tsLow)) { // stamps are not equal => check which is highest aka last modified switch(max($tsNormal, $tsHigh, $tsLow)) { case $tsNormal: $img = $img->getCrop('normaali'); break; case $tsHigh: $img = $img->getCrop('korkeampi'); break; case $tsLow: $img = $img->getCrop('matalampi'); break; } } }
Seems to work quite nicely for my purpose ?Thought it would be nice to share, if anybody else wants to achieve similar effect!
- 4
- 1
-
10 hours ago, horst said:
I don't understand what's the question means ?? When you upload an image to a field with 3 defined crop settings, there will be created 3 default crops. So there ever is a crop present, but not a manually user defined one. ??
Yes, there will always be default crops. Problem is that I don't need to use all of them, just one.
I'll try to explain better:
1. User uploads an image.
2. If user thinks the image is good as it is, render the uncropped version.
3. If user wants to crop the image, user selects which crop setting they want to use, and then render that crop version.Problem is how can I detect which version should I use? I can't check if a version exists, since they always do.
-
Couple of other questions though:
1. If I have multiple cropping options (normal, higher, lower height), how can I easily control which crop setting should be used? Since it does all crops when uploading the image, I can't simply check if a crop version exists. Also what if I want to use the original image instead of crop versions, how can I select that?
2. Translation file lacks a few fields from the modal: "ESC" and cropped image parameters (imgUrl, suffix, width x height, quality, sharpening). Also cropped image modal title "Save" can't be translated.
Otherwise great module! ?
- 1
-
On 9/18/2019 at 9:52 PM, horst said:
Hi @iipa, after (re)naming the cropsettings lowercase [a-z0-9], the issue is gone, or not?
Yes, issue is gone now ?
- 1
-
Hi!
I have an issue when I upload an image into the field. This is one of the log messages ("matalampi" is the crop setting?
/../site/assets/files/1328/testiimagenodashes-1.-matalampi.0x48.jpg - Unable to copy /../site/assets/files/1328/testiimagenodashes-1.-matalampi.jpg => /../site/assets/cache/WireTempDir/.PFM0.06231100T1568804893RIbnRkmpEmZApFan/0/testiimagenodashes-1.-matalampi.0x48.jpg
Same error comes from all variations.
Apparently the field tries to create file variations from the image immediately after upload, but for some reason it doesn't work and a corrupted file is created. This becomes a problem when I try to check if there exists a cropped version of the image: It thinks that there is one, but since it's corrupted, image doesn't show in site.
Is there a way to prevent variations being created before user actually crops the image?
var_dump of image, if it helps anything ("matalampi", "korkeampi" and "normaali" are crop settings?
object(ProcessWire\Pageimage)#370 (13) { ["url"]=> string(71) "/../site/assets/files/1448/img.-normaali.jpg" ["filename"]=> string(100) "/../site/assets/files/1448/img.-normaali.jpg" ["filesize"]=> bool(false) ["description"]=> string(0) "" ["tags"]=> string(0) "" ["created"]=> string(18) "17.9.2019 14:09:57" ["modified"]=> string(18) "17.9.2019 14:09:57" ["filemtime"]=> string(17) "1.1.1970 02:00:00" ["width"]=> int(0) ["height"]=> int(0) ["suffix"]=> string(0) "" ["original"]=> string(34) "img.jpg" ["variations"]=> array(5) { [0]=> string(40) "img.0x260.jpg" [1]=> string(50) "img.-matalampi.0x48.jpg" [2]=> string(50) "img.-korkeampi.0x48.jpg" [3]=> string(50) "img.-normaali.670x0.jpg" [4]=> string(49) "img.-normaali.0x48.jpg" } }
"filemtime" looks kinda fishy: Does it affect anything?
Edit: Aaand as soon as I decided to ask this, it seems that the issue was that my crop setting names had capital letters! So heads up for that to others as well ?
- 2
-
Hi fellow developers!
I have a basic image field on my page. I would like to force a specific aspect ratio when user wants to crop the image. Module apparently uses crop.js for cropping features, and I found some settings related to it in ProcessPageEditImageSelect.js:
var cropSettings = { autoCrop: true, autoCropArea: 0.35, zoomable: false, rotatable: false, // etc ... };
I would like to change these settings, but obviously I don't want to do so straight in module code (especially because it is in wire).
Question is: How can I refer to these settings somewhere safer? (For example I have admin.js where I already do some other stuff in admin pages located in site/templates/scripts)
-
On 8/17/2019 at 3:16 PM, eydun said:
Oon some browser+OS combos that button does not work, unfortunately.
6 hours ago, ryan said:@iipa Pasting stuff from Word should be no problem ... I think most of our clients likely do this. So you definitely shouldn't get an internal server error from PW at least. Though you might try setting $config->debug=true; in your /site/config.php file (temporarily) and trying again, just in case — that will make it produce a verbose error message. But it's more likely that it is coming from mod_security or some other Apache or PHP module on the server that is monitoring input and halting the request when it comes across something it doesn't like. I don't blame it, as MS word can produce some pretty sketchy looking markup. But between CKEditor and htmlpurifier, PW should be able to clean it up just fine once the server lets it through. But if it's an Apache/PHP module doing this (which seems likely) then nothing you adjust in PW can fix it since the module examines the request before PW even boots, so you'd instead have to disable or configure the Apache module (mod_security, suhosin, or whatever it might be).
I actually have debug on, since we haven't launched yet, but I'm also starting to lean into problem being in server side configurations.
On 8/17/2019 at 7:39 PM, horst said:I use the hook from Ryan since a few weeks and it works really good
Maybe one can this adapt to match more than inline styles. (?)
I managed to accomplish this in CKEditor's config.js by adding
config.disallowedContent = '*{*}';
which does it automatically when pasting. It was also enough to keep server happy aswell!
- 1
-
7 minutes ago, dragan said:
You probably have to update PW. It was introduced with 3.0.127:
Well that's propably why, since I have 3.0.123! Thanks @dragan, sometimes the simplest things to check just don't come to mind ?
- 1
-
I have a CKEditor Textarea in a page template. Some users like to add text in them by pasting from Word document. This leads to internal server error when saving page. When using paste without formatting (cmd + shift + V), page is saved normally, so I assume error has something to do with Word's hidden characters that cause issues in many other programs as well. (I don't have Word myself, so I debugged this with video chat with user. I forgot to ask to check code view, so I'm not sure if they are visible there.)
Is there a way in ProcessWire/PHP to sanitize Textarea input from these hidden characters, or can I prevent this by changing editor settings (listed below, if it helps)? I don't like leaving error handling rely to user action - somebody always forgets to do things specific way and it weakens user experience.
Textarea formatting: none (htmlspecialchars off) field type: CKEditor content type: markup/html experimental markup/html settings: all on acf: on html purifier: on additional purify settings: all on extra allowed content: none add-ons: pwimage, pwlink, sourcedialog sourcedialog settings: none disabled add-ons: image, magicline
-
On 8/10/2019 at 2:20 PM, Robin S said:
Check if saved page has errors:
$wire->addHookAfter('Pages::saveReady', function(HookEvent $event) { /* @var Page $page */ $page = $event->arguments(0); // Find out if the page being saved has any errors $has_errors = $page->hasStatus(Page::statusFlagged); // Do something accordingly... });
Hi @Robin S! I'm a bit confused with your solution. I tried to use your code, it threw me "Uncaught Error: Undefined class constant 'statusFlagged'".
I looked at wire/Page.php, and it doesn't seem to have statusFlagged:
static protected $statuses = array( 'locked' => self::statusLocked, 'systemID' => self::statusSystemID, 'system' => self::statusSystem, 'draft' => self::statusDraft, 'versions' => self::statusVersions, 'temp' => self::statusTemp, 'hidden' => self::statusHidden, 'unpublished' => self::statusUnpublished, 'trash' => self::statusTrash, 'deleted' => self::statusDeleted, 'systemOverride' => self::statusSystemOverride, 'corrupted' => self::statusCorrupted, );
Am I looking at the wrong place, or has it been renamed?
-
-
9 minutes ago, dragan said:
Just get it from Github: https://github.com/PHPOffice/PhpSpreadsheet
What do you mean with "just get it from Github"? How do I refer to it from ProcessWire?
-
Hi fellow developers!
I want to implement following action:
- Admin-priviledged user uploads a spreadsheet file (with many sheets)
- When page is saved, back end generates repeater items from the sheets
- We can render spreadsheet data from the repeater field. Profit!
Currently I'm trying to find a way to read the uploaded spreadsheet file. ProcessWire doesn't seem to have modules suitable for my needs, but external PHP Library PhpSpreadsheet sounds like it could do the job. However, I can't even try it, because I simply don't understand how I can refer to an external library!
Folder structure:
-
templates
- _func.php > where I want to refer to the library
-
libraries
-
PhpSpreadsheet
- bunch of *.php > what I want to refer to
-
PhpSpreadsheet
I have tried different things varying from their documentation to forum posts and PW API with no luck. I would prefer not to use Composer, since it seems kind of overkill for one library.
Thanks in advance and have a great day!
-
Hi louis, Gideon and szabesz - long time no see! ?
My syntax is same as yours, but somehow it still doesn't load it. I'm thinking it might be because I didn't load favicon through ProcessWire, I just put the image in server through SFTP. Testing still continues, since I've been busy with other things.
Suggestions of cause are still welcome, and I will post if I find the solution myself!
-
On 3/13/2019 at 3:05 PM, dragan said:
Did you check your browser console? Do you see anything suspicious there?
Hi @dragan, I'm fairly new to ProcessWire forums, so a bit over two months later I finally see your response ?
Console didn't show anything suspicious, and neither did ProcessWire error logs. However, some time after scratching my head around this issue I noticed that it solved itself - no idea when, how or why, but every icon is shown correctly now. Hopefully I won't come around this issue again!
- 1
-
I had some issues with server provider and subdomain SSL certificate (I want all my sites use forced https), but after those were resolved, @dragan's solution works perfectly! So thanks again, now I'm able to use actual data also in testing phase, which helps in UI design.
- 1
-
Thank you @Robin S, that is exactly what I need! Referring to a field through form in hooks is something I haven't come across yet. It's always exciting to find new things to explore!
- 2
-
Hi!
I have two Page Reference fields: Category and Subcategory. Category is parent of Subcategory, and can have 0 to n Subcategories. Fields are selected by dropdown selection.
I'm trying to achieve following logic:
1.
Select Category(obviously works)2.
Change Subcategory options based on selected Category(this works)3. Hide the Subcategory field if Category has no Subcategories (to prevent weird dropdown with nothing to select)
I have tried to investigate two possible alternatives to achieve step 3:
A) Make dynamic condition into Subcategory selection's "Only visible if..." field
B) Make a hook that fires when Category changes, then hides Subcategory field if Category has no children
So far I haven't been successful in either. Conditions I've tried always lead to hidden field, and I haven't been able to find set up a hook that fires on field change.
So here's the question (finally): Is there a way to alter field visibility in API, for example in ready.php or inside a hook? In API I could loop through categories, find the ones that have children and then make a selector based on their IDs.
-
Wow, that sounds nice as well! And fairly easy to implement too. You know what they say, work smart, not hard!
- 1
-
Hmm, that's a good point. There certainly are some risks that come with having the same database that I haven't considered. Thanks for pointing them out!
First solution doesn't work in this case, because client wants to test how things work with adding real content, so they probably wouldn't like the idea of things being wiped with every update.
The second option with migrations sounds cool though - might be just what I need!
- 1
-
Hi everybody!
I have been reading about Multisite, but it kinda bugs me that every topic talks about having both admin and database same for multiple sites.
I have a project where customer tests it by adding content to the site, while I still need to do some changes here and there in code, maybe some in database. If something crashes for a while, customer can't keep testing, which is a bit problematic.
Is there any way that I could have two separate versions of one site ("production" and development) that share the same database, but are otherwise independent? Just the thought of having to migrate database every time I want to show client something new gives me anxiety ?
-
I have added favicon files (.png, .xml, .ico, .svg) into site/templates/images/favicon/ folder. I refer to them in _after.php, <head> tag. Problem is that favicon does not show. When I go to the address of the .png icon, it shows the basic blue icon with question mark = something is wrong. But when I check .svg file, it shows correctly. Browser console and ProcessWire error log don't recognize any issues. All files have chmod 644, and all folders 755. All images added into site through ProcessWire admin are displayed correctly.
What could be the caused of this issue?
-
I have a problem with Font Awesome icons that came with ProcessWire - or some of them. Attached are two images - first one with admin view, other is from the view where you can choose icon for a field. As you can see, some icons are there, but most of them aren't. Neither browser console nor ProcessWire error log show any errors, so I'm kind of lost where I should even start looking into this issue.
Has anybody else had this issue? If you have, how did you solve it? I already tried to re-upload wire-folder, but it didn't help.
Using $session to save UI changes on site
in General Support
Posted
Somehow I didn't consider this option at all! Thanks @dragan, I decided to implement this with cookies ?
And thanks to you too @horst, I'm sure this will come handy at some point!