-
Posts
5,039 -
Joined
-
Days Won
340
Everything posted by Robin S
-
I think this is totally justified. The amount of data that is being stolen these days is just crazy, and it has real impacts on real people. One of the worst incidents to date is the Equifax hack: https://en.wikipedia.org/wiki/Equifax#May.E2.80.93July_2017_data_breach John Oliver did a good piece on it: Automatic encryption just has to become the new normal, and I'm confident it won't be that big a deal to implement once the code wizards out there turn their minds to the challenge.
-
[RESOLVED] Images losing saturation when resized by ProcessWire
Robin S replied to mike62's topic in General Support
Are you sure you are comparing apples with apples here? In your screenshot, is the original image being viewed in the context of a browser, or is it viewed in some other application? There are so many things that can come into play when you are dealing with colour management - whether the image has a colour profile embedded, what the colour profile is (sRGB is probably the safest option), the colour management support within the application you are viewing the image in, etc. To verify that the colour loss has anything to do ProcessWire's resizing you should insert the original image next to a resized version of that image in a template file and view them in your browser. <img src="/path/to/original-image.jpg" alt=""> <img src="<?= $page->image->size(854,0)->url ?>" alt=""> -
When I create a new Hanna Code tag I am always creating a PHP tag (I don't think I've ever had a need to create a text or Javascript tag). And I prefer to edit my tag code in my IDE rather than in the code field within the Hanna Code module. Because of this my Hanna codes always consist of... <?php include $config->paths->templates . "hannas/{$hanna->name}.php"; ...which just includes a file named the same as the Hanna tag from a "hannas" folder in /site/templates/ Always on the lookout for efficiencies, I had a go at automating the process of setting up new Hanna tags and come up with the following. Maybe it's useful to someone. In /site/ready.php: // Pre-fill code for new Hanna tags and create file $wire->addHookBefore('ProcessHannaCode::executeEdit', function(HookEvent $event) { $id = (int) $this->input->get('id'); // Include code for later use $file_include_code = '<?php include $config->paths->templates . "hannas/{$hanna->name}.php";'; if(!$id) { // A new Hanna tag is being added // Set type to PHP $this->addHookBefore('InputfieldRadios(name=hc_type)::render', function(HookEvent $event) { $inputfield = $event->object; $inputfield->value = 2; }); // Set code to include file of same name as tag $this->addHookBefore('InputfieldTextarea(name=hc_code)::render', function(HookEvent $event) use ($file_include_code) { $inputfield = $event->object; $inputfield->value = $file_include_code; }); } else { // An existing Hanna tag is being edited (the new tag has been saved) // Get the data for this tag /* @var \PDOStatement $query */ $query = $this->database->prepare("SELECT name, type, code FROM hanna_code WHERE id=:id"); $query->bindValue(':id', $id); $query->execute(); if(!$query->rowCount()) throw new WireException("Unknown ID"); list($name, $type, $code) = $query->fetch(\PDO::FETCH_NUM); // If it's a PHP tag and the tag code matches the include code... if($type == 2 && $code === $file_include_code) { $filename = $this->config->paths->templates . "hannas/{$name}.php"; // Check if there is an existing file and if not... if(!file_exists($filename)) { // Define the contents of the file // Just the namespace and API variables for IDE code-completion // Some of this is PhpStorm-specific so adjust as needed $contents = '<?php namespace ProcessWire; //<editor-fold desc="API variables"> /** * @var Config $config * @var Fieldgroups $fieldgroups * @var Fields $fields * @var Languages $languages * @var Modules $modules * @var Page $page * @var Pages $pages * @var Paths $urls * @var Permissions $permissions * @var ProcessWire $wire * @var Roles $roles * @var Sanitizer $sanitizer * @var Session $session * @var Templates $templates * @var User $user * @var Users $users * @var WireCache $cache * @var WireDatabasePDO $database * @var WireDateTime $datetime * @var WireFileTools $files * @var WireInput $input * @var WireLog $log * @var WireMail $mail * @var \ProCache $procache * @var \FormBuilder $forms * **/ //</editor-fold> '; // Create a file and insert the contents above file_put_contents($filename, $contents); } } } });
- 4 replies
-
- 10
-
-
I think it does make sense to say that the superuser role is a role without any restrictions and that therefore permissions are not something that can be granted or not granted to a superuser. The comment (from Ryan in the GitHub issue) that I don't agree with is: Why should there be the presumption that there is never any scenario where a non-superuser could be trusted to add or edit a field or template? Depending on the user and the project there could be quite valid cases for this. I think it ought to be possible to elevate a role right up to the point where they are virtually a superuser. One way this could perhaps be implemented is by adding a permission for each core Process module.
-
Sorry, it's due to my browser autofilling the download URL with the wrong data when I edit the module in the modules directory. Please try again now and it should work.
-
Do you mean you want to get the current day of the week and use it in the selector? Maybe this is what you want: $day = date('l'); $events = $pages->find("template=weekly-event, day_in_week=$day'");
-
It depends on where in the sort order you want the special characters to go. Without doing anything special PHP would sort special characters after ASCII characters, so for instance that would place "Čavlović" after "Zola". If that is what you want (and I doubt that it is) it seems that you can achieve this kind of sort by using the "useSortsAfter" option for PageFinder: $authors = $pages->find("template=author, sort=title", ['useSortsAfter' => true]); BTW, it's far from clear to me what the "useSortsAfter" option does exactly. But I don't think that is what you want anyway. To get a language-aware sort I think you would have to use something like PHP's Collator class - others may know better but I don't think PW has anything built in for this. So here is something that might work, but it would mean you must get all your authors in one $pages->find() - no pagination in other words: // Find the author pages $authors = $pages->find("template=author"); // Get an array where key is author page ID and value is author page title $titles = $authors->explode('title', ['key' => 'id']); // New Collator instance $collator = new \Collator('hr_HR'); // Croatian locale // Apply language-aware sort $collator->asort($titles); // Apply custom sort property to author pages $i = 1; foreach($titles as $id => $title) { $author = $authors->get("id=$id"); $author->custom_sort = $i; $i++; } // Sort authors by custom sort property $authors->sort('custom_sort'); // Now loop over $authors and output markup
-
Very interesting post. I will listen to music while (graphic) designing and I haven't noticed any ill effects there, but if I am planning or coding I find it has a negative impact. Especially when debugging or trying to think laterally about a challenging task. Even the most ambient of background noise I find distracting in those circumstances - like some of the brain's energy gets unconsciously diverted to listening and you can bring less resources to bear on the issue as a result. Do you have an online portfolio of paintings? Would love to see some of your work.
-
v0.0.6 released: More efficient evaluation of dependencies.
-
Does $p->children()->eq() first return all child pages?
Robin S replied to Matte85's topic in API & Templates
In the selector that you use with the children() method, you can do anything that you can do in a $pages->find() selector. Because behind the scenes... $page->children($selector) ...is essentially... $pages->find("parent=$page, $selector") Like I said, I'm no expert on multi-language, but I think PW has tools that let you handle multi-language smarter than this. Have a read here about multi-language fields and here about language support in general. -
You are right. It seems that when the hook fires for the AJAX reload the process is ProcessPageView and not ProcessPageEdit. So @Juergen's way of getting the page from the id GET variable would be the way to go.
-
getPage() is a method of ProcessPageEdit. It's fine to use it, but you first need to check that the current process is ProcessPageEdit. if($this->process != 'ProcessPageEdit') return; $page = $this->process->getPage(); // ...
-
@Macrura, would you mind testing the attached module update and let me know if it works as expected and improves the page load time? Just want to confirm it does the job before pushing the change to GitHub. CustomInputfieldDependencies.zip
-
Hi @Macrura, looking at the module code I can immediately see a much more efficient way to match the current page than what the module is doing currently. I'll post back here shortly with an update.
-
Does $p->children()->eq() first return all child pages?
Robin S replied to Matte85's topic in API & Templates
Could you explain more about this? I haven't built multi-language sites myself, but I'm not seeing how translations would have an affect on applying the limit within the selector as opposed to getting individual children with $parent->children()->eq($i). If your limit is 5, but there are only 3 children under a particular parent, then of course you will only get 3 children returned. But that is the same with eq() also. Note that if you want to return only pages with some particular template, property, field value, etc then you can specify that in the selector for children(), e.g. // Return children up to $limit where my_field is not empty $items = $parent->children("my_field!='', limit=$limit"); -
Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)
Robin S replied to ryan's topic in Modules/Plugins
The strange thing is though is that you have working embedded YouTube videos on that site here: http://www.burstoncrown.com/events/easy-thursdays/jess-morgan-and-kitty-macfarlane/ Perhaps the host is running mod_security or similar and that is being triggered by particular patterns in some video URLs? -
Excluding a past event from a PageReference field after it's been chosen
Robin S replied to a-ok's topic in General Support
@oma, when you use a date/time as a string in a $pages->find() selector it is internally passed through strtotime(). So if you are doing a separate strtotime() elsewhere that you want to give the same result you must use the same string, i.e. use "today" for both or "now" for both. -
@ryan, this part of the blog post... ...seems to contradict the setting in /wire/config.php, where... $config->defaultAdminTheme = 'AdminThemeDefault'; Shouldn't the default admin theme used for new installations match that defined in /wire/config.php? Also, is it possible to define a setting specifying the previous AdminThemeDefault as the default theme for new installs? Speaking for myself, I'm not ready to shift to AdminThemeUikit just yet and it's likely that aspects of my custom profile that I choose on installation are not compatible with AdminThemeUikit.
-
Does $p->children()->eq() first return all child pages?
Robin S replied to Matte85's topic in API & Templates
It does return all children if you use the children() method without a selector, or use children as a property. You could do that more efficiently as: foreach($parent->children("limit=$limit") as $child) { //... } -
It's working for me. Double-check the hook code, or maybe you have some other module or hook interfering? AdminTheme::getExtraMarkup should never return null - even if it's unused it still returns an array. $wire->addHookAfter('AdminTheme::getExtraMarkup', function(HookEvent $event) { $parts = $event->return; $parts['head'] .= '<link rel="stylesheet" href="/site/templates/custom.css">'; $event->return = $parts; });
-
Excluding a past event from a PageReference field after it's been chosen
Robin S replied to a-ok's topic in General Support
I misunderstood - I thought you wanted to sort by the most distant upcoming date, not the soonest upcoming date. So you'll need a different approach I think, where you loop over your result pages add them to a new array using the next upcoming date as the key, then you sort the array by key. Edit: after thinking some more, this is not an ideal solution because your upcoming date timestamps may not be unique, so they don't make good candidates to use as array keys. A better idea is to add the next upcoming date timestamp as a custom property of each result. So the general principles... 1. Keep the "events_detail_dates_sort_date" field in your template, but instead of populating it with the soonest upcoming date you populate with the most distant upcoming date in the saveReady hook. This field will not be used to sort the pages (so you could consider renaming it if you like) but rather to exclude pages that have no upcoming date in your $pages->find() selector, so that you are not having to process more pages than necessary. 2. Loop over the raw unsorted results of your $pages->find() query, adding the timestamp of the next upcoming date as a custom property. Then sort on that property: // For each of your $pages->find() results... foreach($results as $result) { // Test for the template of the result here // ... // Get the repeater page with the next upcoming date $next_upcoming = $result->events_detail_dates->get("events_detail_dates_start_date>=$today, sort=events_detail_dates_start_date"); // Add the timestamp of the next upcoming date to the result as a custom property $result->next_upcoming = $next_upcoming->getUnformatted('events_detail_dates_start_date'); } // Sort the results by the custom property $results->sort('next_upcoming'); // Now loop over $results to output the markup You'll need to expand on this to deal with the other template ("Our pick") you are including in your results. So you would first test for the template of the result page and use the above if it is "events-detail" and come up with some other numerical value for the "our pick" results to use as "next_upcoming" so they appear where you want them when sorted by the custom property. -
The UIkit theme is looking lovely, but does anyone else think it goes a little too far in terms of padding? On my 27" monitor this interface looks quite large. On something like a 13" laptop you would not get much interface on the screen it would require a lot of scrolling. I love clean whitespace as much as the next person, but there is more than just aesthetics to consider. The admin interface is something that as developers we are going to spend a significant amount of time using. The extra scrolling and mouse movement that a widely-spaced interface requires is something to consider. Definitely not wanting a cramped, crowded interface but I think there is scope to be more efficient here, particularly in the vertical padding. In designing a utilitarian interface like this I would be inclined to follow a process of starting with no padding and then adding padding to elements by eye until it feels right.
-
Excluding a past event from a PageReference field after it's been chosen
Robin S replied to a-ok's topic in General Support
Oh right, that's because you can't use spaces around field/operator/value in selector strings. I was just composing that in the browser. If you change to... if($article->template->name == 'events-detail') { if(count($article->events_detail_dates->find("events_detail_dates_start_date>=$today"))) include './inc/events-item.inc'; } //... ...it should work. Not sure why it would need to auto update apart from when the page is saved. It only needs to update if you are making a change to the page by adding or removing a date. In terms of old dates you exclude those in the $pages->find() selector that gets your results: events_detail_dates_sort_date>=$today -
If you are using Page Reference fields there is some limited support for this. See this post:
-
If you want to add a CSS file so that it is linked at the bottom of the list of admin styles and scripts you can use a hook like this: $wire->addHookAfter('AdminTheme::getExtraMarkup', function(HookEvent $event) { $parts = $event->return; $parts['head'] .= '<link rel="stylesheet" href="/path/to/custom.css">'; $event->return = $parts; });