Jump to content

Robin S

Members
  • Posts

    5,008
  • Joined

  • Days Won

    333

Everything posted by Robin S

  1. This is missing the option for actually setting the sharpening amount. I think it should be: foreach(array('none', 'soft', 'medium', 'strong') as $sharpening) { echo "<img src='" . $child->post_image->first()->size(200, 0, [ 'upscaling' => false, 'quality' => 90, 'sharpening' => $sharpening, 'suffix' => $sharpening ])->url . "' title='{$sharpening}' />"; } The jaggies are a consequence of the sharpening - you can't have it both ways. With sharpening off the edges are smooth.
  2. As @Mike Rockett says, the quick and dirty way is to use CSS: .MarkupPagerNav li { display:none; } .MarkupPagerNav .MarkupPagerNavPrevious, .MarkupPagerNav .MarkupPagerNavNext { display:block; } For a PHP solution, here's what I use for prev/next pagination of news summaries. I think it's based on some code shared here in the forums but I can't remember where. In my case I wanted greyed-out prev/next links when on the first/last page. <?php $limit = 5; $news = $pages->find("template=news_item, post_date<=today, limit=$limit, sort=sort"); $total_pages = ceil($news->getTotal() / $limit); // output news summaries here // pagination if($total_pages > 1): $current_url = $page->url; if($input->urlSegmentsStr) $current_url .= $input->urlSegmentsStr . '/'; ?> <div class="pagination"> <div class="prev-page"> <?php if($input->pageNum > 2): ?> <a rel="prev" href="<?= $current_url . $config->pageNumUrlPrefix . ($input->pageNum - 1) ?>">Prev page</a> <?php elseif($input->pageNum === 2): ?> <a rel="prev" href="<?= $current_url ?>">Prev page</a> <?php else: ?> Prev page <?php endif; ?> </div> <div class="centre-text">Page <?= $input->pageNum ?> of <?= $total_pages ?></div> <div class="next-page"> <?php if($input->pageNum < $total_pages): ?> <a rel="next" href="<?= $current_url . $config->pageNumUrlPrefix . ($input->pageNum + 1) ?>">Next page</a> <?php else: ?> Next page <?php endif; ?> </div> </div> <?php endif; ?>
  3. Are you saying that an images field inside a repeater does not allow drag-and-drop uploading? I'm not aware of any such limitation and with a quick test it seems to be working for me, even inside nested repeaters. I think you should check out the Croppable Image 3 module for managing your different crops. https://github.com/horst-n/CroppableImage3
  4. The %= operator matches part words (which can be desirable) but all the characters in the search string must be in the given order in the searched fields. When I want to match part words I will usually explode() on the space character and then match against each word as a separate clause in the selector. $selector = ''; $search_terms = $sanitizer->selectorValue($input->get->search); if($search_terms) { $search_terms = preg_replace("/\s+/", " ", $search_terms); // replace multiple spaces with single space $terms = explode(" ", $search_terms); foreach($terms as $term) { $selector .= "title|body%=$term, "; } $matches = $pages->find($selector); }
  5. InputfieldPage is available in the hook function as $event->object - so in your hook code copied from InputfieldPage::processInputAddPages you can replace class methods called like $this->someClassMethod() with $event->object->someClassMethod(). But you will need to distinguish between class methods and other PW API variables accessed with $this. E.g. $this->getSetting() vs $this->pages() Edit: actually, that will only work for public methods and properties so it's probably not sufficient. Another alternative is to copy the entire InputfieldPage module to /site/modules/ and make changes there.
  6. As you found, you can't change the $parent_id variable inside the InputfieldPage::processInputAddPages method using this type of hook because $parent_id is neither an argument to the method nor a return value of the method. I think you would have to use a replace hook - copy the whole InputfieldPage::processInputAddPages into your hook function and change as needed. Bear in mind that doing this means that any future core changes in InputfieldPage::processInputAddPages will not take effect while your hook is in place.
  7. Could you use the "Alternative Template Filename" option to assign the home.php file to all templates?
  8. Thanks. I tried all manner of things and just couldn't get it working in one test environment - but there is a lot of stuff going in that environment so probably a conflict of some sort. Tried it in a cleaner environment and it works as expected. I can confirm that properties added by addHookProperty() can be matched by an in-memory selector: $basic_pages = $pages->find("template=basic_page"); $result = $basic_pages->find("lastModifiedStr=2 months ago"); So that could be a compelling reason to prefer addHookProperty() over addHookMethod() depending on the circumstances.
  9. Just wanted to add that you can override an automatically prepended/appended file for a template on the Files tab of Edit Template. If you know you never want those automatically prepended/appended files for the template then this is the way to go. The $use_main approach is more suitable when some of the time you want the appended file and some of the time you don't (for an AJAX-loaded page, for instance).
  10. There's no absolutely right or wrong way - if you asked 10 people you'd probably get 10 different answers. It comes down to what you find most comfortable to read, write and maintain. Personally I like a single auto-appended main.php containing the HTML head, body and any "framework" markup that will appear on all pages. For blocks of content I use variables defined in an auto-prepended init.php and overwritten in template files where needed. I like to use output buffering when populating my "block" variables: <?php ob_start(); // $side_col ?> <div class="side-col"> <p>Something else here.</p> <?php // some PHP here ?> </div> <?php $side_col = ob_get_clean(); ?> Generally my approach would be to use main.php for all templates including the home template - anything unique to the home template would be inside the main "block" variables. But here's another way: I have a $use_main variable defined as true in init.php, and at the top of main.php I have if(!$use_main) return; So if I don't want the contents of main.php appended I can set $use_main to false in a template and then use alternative markup. You could do this in your home template. I think in this case I would create a different template for this ("article_categories"), but it would "extend" the parent articles category so I'm only changing the parts that need to be different. I do this by including the template to be extended at the start of the template file. // template extends... include './articles.php'; Then in article_categories I overwrite the variables I want to change from what is defined in the articles template. Alternatively you could use a single template for both articles and article_categories and use some logic inside it to change the output. if($page->parent->name === 'articles') { // then this is one of the article category pages } This is probably the result of template "Family" settings.
  11. You're absolutely right that neither would work with $pages->find() - I didn't think that through. But I think it should be possible to use the property in an in-memory selector, like: $results = $some_pagearray->find("lastModifiedStr=10 days ago"); Trouble is I can't test this as I can't get the code example in the API reference for addHookProperty() to work. Does it work for you? For me the hook never fires and I just get NULL for $page->lastModifiedStr. The same hook code works fine when in addHook() or addHookMethod() and called with $page->lastModifiedStr().
  12. One difference that just occurred to me is that the property may used in a selector but the method may not. So in the examples from my last post I could do... $results = $pages->find("lastModifiedStr=10 days ago"); ...but not... $results = $pages->find("lastModified=10 minutes ago"); Is that right?
  13. Thanks. I'm sure I'm missing something here, but it seems like addHookMethod() can do everything that addHookProperty() can plus it can optionally take arguments. In the Hooks docs there is this example for addHook(), aka addHookMethod(): public function init() { $this->addHook('Page::lastModified', $this, 'lastModified'); } public function lastModified($event) { $page = $event->object; $event->return = wireRelativeTimeStr($page->modified); } echo $page->lastModified(); // outputs "10 minutes ago" And then in the addHookProperty() API reference there is virtually the same example: // Adding a hook property $wire->addHookProperty('Page::lastModifiedStr', function($event) { $page = $event->object; $event->return = wireDate('relative', $page->modified); }); // Accessing the property (from any instance) echo $page->lastModifiedStr; // outputs: "10 days ago" So the addHook() example could alternatively be added with addHookProperty(). But if addHook()/addHookMethod() can "do more" than addHookProperty() thanks to the ability to pass in arguments, in what circumstances would you want to use addHookProperty()?
  14. I'm hoping someone might explain the difference between addHookProperty() and addHookMethod() and when you would use one over the other. One of the things I find confusing is that the docs for addHookMethod() say that it is an alias for addHook(), yet the example given for addHook() in the Hooks documentation is the same is the example given for addHookProperty() in the new API reference.
  15. v0.0.2 released - a complete overhaul of the module. Custom Inputfield Dependencies now does the same thing but in a completely different way (thanks to a great idea from @adrian) The module no longer requires Hanna Code and inputfield dependencies are now set on the "Input" tab of "Edit Field". See the first post for all the details. If you are using v0.0.1 of the module then this is a breaking change and you will need to redefine your dependencies (sorry ). But the new approach taken in v0.0.2 is so much better that hopefully you'll find the change worthwhile.
  16. I tested this and can confirm the issue - I believe it's a bug and created a GitHub issue for it: https://github.com/processwire/processwire-issues/issues/152 The issue only occurs when both Page fields are 'single' fields.
  17. You could FTP your files to an "uploads" directory and them import them to a field on a page using the API. For example, to add PDF files in /uploads/ to a field named "files" on the Home page... // function for adding files function addFiles($file_extension, $page_id, $files_field_name) { $files = glob( wire('config')->paths->root . "uploads/*.$file_extension" ); $p = wire('pages')->get($page_id); $p->of(false); foreach($files as $file) { $p->$files_field_name->add($file); } $p->save(); } // call the function with arguments to suit addFiles('pdf', 1, 'files'); Remember to delete the files from the uploads directory after each successful import.
  18. You can also find the admin page name (and thereby the URL) by viewing the "pages" table in phpMyAdmin or similar. Look for the row with the id of 2.
  19. I misread your post and thought you meant Select Multiple rather than Page List Select Multiple - the latter is fine for thousands of pages as it is ajax-paginated.
  20. Not very well - that's when you would want to use an inputfield that loads options on demand with AJAX. I think Autocomplete is the only core inputfield that does this. Misread your post and thought you meant Select Multiple. Page List Select Multiple uses the standard ajax-paginated page tree so that is fine for thousands of pages, although slower to use than Autocomplete. Inputfield Selectize is based on selectize.js which does have an AJAX load feature but I'm not sure this is available for pages in the PW module.
  21. Maybe I'm misunderstanding something, but a Page field seems ideal for what you want to do. You leave the Song pages where they are (under Songs in the tree) and then select them in a "Songs" field in your "Playlist" template. Several of the available inputfields for a Page field allow you to sort pages in the field - Autocomplete is a good option for selecting from a large number of pages but you could use AsmSelect or some other inputfield if you prefer. In the screenshot below, imagine these "vegetable" pages are instead songs. This way you don't need any child pages under your Playlist pages. P.S. I think you forgot to add your screenshots.
  22. Rather than making duplicate Song pages as children under the playlist, could your Playlist template have an Autocomplete Page field "Songs" where you select Song pages?
  23. Media Manager might be the slickest option for this. Not 100% sure but I think it allows you to upload new media directly from a page being edited. If you want a no-cost solution you could look at adapting this module from @mr-fan, which is based on code by @adrian https://github.com/mr-fan/AutoImagePages But it doesn't allow for the uploading of new files directly from a page being edited - you must upload from the parent page of the files/images branch.
  24. There are a couple of solutions linked to in this topic in the FB VIP forum.
  25. HTML renders fine for CKEditor fields. For text or textarea fields there are two possibilities: Strip the tags... $this->addHookBefore('Fieldtype::markupValue', function($event) { $field = $event->arguments('field'); $page = $event->arguments('page'); $value = $event->arguments('value'); if($field->name == 'my_field' && $page->template->name == 'my_pagetable_template') { $event->arguments('value', $this->sanitizer->textarea($value)); } }); ..or decode entities (being mindful of potential security risks that this opens up)... $this->addHookAfter('Fieldtype::markupValue', function($event) { $field = $event->arguments('field'); $page = $event->arguments('page'); if($field->name == 'my_field' && $page->template->name == 'my_pagetable_template') { $event->return = html_entity_decode($event->return); } });
×
×
  • Create New...