-
Posts
5,008 -
Joined
-
Days Won
333
Everything posted by Robin S
-
@ryan, would you consider making the top-level item in the AdminThemeUikit user nav configurable and/or hookable? I'd like to have the option to make this top-level link a "View site" link rather than an edit profile link, as per the default admin theme. It's much more common for me to want to quickly launch a front-end tab than to edit my profile.
-
It's working for me (with Markdown/Parsedown Extra textformatter - didn't try the other). Do you have any other textformatters enabled for the field besides the markdown textformatter? Anything unusual about how you are getting the field value in your template (something that might cause output formatting to be off)? Edit... ...that sounds like a CSS issue actually. Maybe you have list-style:none and no margin/padding on your ol element?
-
Page Add Process -> template sort sequence by title
Robin S replied to ro-bo's topic in General Support
Try this in /site/ready.php $wire->addHookAfter('ProcessPageAdd::getAllowedTemplates', function(HookEvent $event) { // Get keys (IDs) of returned templates array $template_ids = array_keys($event->return); // Implode for use in a selector string $template_ids_str = implode('|', $template_ids); // Get TemplatesArray of those templates, sorted by label $templates = $this->templates->find("id=$template_ids_str, sort=label"); // Convert to plain array and return $event->return = $templates->getArray(); }); -
v0.0.4 released - adds support for the new password field option that requires the old password to be entered.
-
If you and your site editors have fixed IP addresses you could use mod_rewrite to redirect away from the Admin page based on IP address. In .htaccess, after RewriteEngine On # Define allowed IP addresses RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111 RewriteCond %{REMOTE_ADDR} !^222\.222\.222\.222 # Adjust to suit the name of your Admin page RewriteCond %{REQUEST_URI} ^/processwire/ # Redirect to home page. Use 302 redirect until finished testing. RewriteRule ^ / [L,R=301]
-
I think this Gist by @Soma may be of some help. My point about pagination was really that if you have a large number of authors you cannot apply a limit and must load all results into memory and loop over them to apply the sort. The options for "pseudo-pagination" don't get around this problem unfortunately. The thing with that approach is that you would have to use a hook and loop over all author pages every time a new author is added or an author's name is edited. Sounds like that wouldn't be a big deal in your situation, but would be a problem if there were thousands of authors. Thinking about a solution for large numbers of pages, I had an idea about generating a value for a hidden sort field based on the first letter of the author's name. It would go something like this... In /site/config.php // Prefixes for sort field $config->sortChars = [ 'č' => 'czzzz', // sort after 'c' 'đ' => 'daaaa', // sort before 'd' // etc ]; In /site/ready.php $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->template != 'author') return; // Assuming author's last name is in Title field $initial = mb_strtolower(mb_substr($page->title, 0, 1)); if(isset($this->config->sortChars[$initial])) { // If the initial letter matches a key in the sortChars array // add the prefix to the title and set to the sort field $page->sort_field = $this->config->sortChars[$initial] . $page->title; } else { // Otherwise use the title for the sort field $page->sort_field = $page->title; } }); Then use sort=sort_field in the $pages->find() selector, and limiting/pagination is also possible.
-
Sounds interesting, looking forward to that.
-
Cool to have a dedicated option for these, but 3 and maybe 4 have been possible for a while now via the "No Debug Bar in Selected Templates" feature (the Form Builder iframe was what prompted my request for that feature ).
-
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.