Jump to content

Robin S

Members
  • Posts

    4,928
  • Joined

  • Days Won

    321

Everything posted by Robin S

  1. Currently you cannot. There is a @todo note in the code: // @todo make this format customizable via wireDate() https://github.com/processwire/processwire/blob/57b297fd1d828961b20ef29782012f75957d6886/wire/modules/Process/ProcessPageLister/ProcessPageLister.module#L1264-L1267 Edit: you cannot set the date format individually for the 'created', 'modified' and 'published' columns, but if you don't mind using the same format for all you can use this hook in /site/ready.php: $wire->addHookBefore('ProcessPageLister::execute', function(HookEvent $event) { $lister = $event->object; $lister->nativeDateFormat = 'Y-m-d'; // see https://processwire.com/api/ref/datetime/date/ for format options });
  2. What @Alxndre' is suggesting is something like the below... First you get your category pages, then you loop over the categories, for each category finding pages that have that category selected in the Page Reference field. If there are some matching pages, output the category heading and the list of posts. $categories = $pages->find("template=category"); foreach($categories as $category) { $posts = $pages->find("template=article-post, category=$category"); if(count($posts)) { echo "<h3>$category->title</h3>"; foreach($posts as $post) { // whatever markup you want for the post echo "<p>$post->title</p>"; } } } This is fine for a lot of circumstances, but note that you do a database query to get the categories and then for each category you do a database query. If you have a lot of categories this would mean a lot of database queries. There is another approach that is more efficient: get all the posts sorted by category (as you are already), then for each post check if the category is different from the previous post's category. If it is different then output a heading. $posts = $pages->find("template=article-post, sort=category"); $category_title = ''; foreach($posts as $post) { if($post->category->title !== $category_title) { $category_title = $post->category->title; echo "<h3>$category_title</h3>"; } // whatever markup you want for the post echo "<p>$post->title</p>"; }
  3. I don't think these classes are related to anything you may or may not have defined in mystyles.js. The mystyles.js file is for populating the Styles dropdown in the CKEditor toolbar. The classes defined in the Page Edit Image module config relate only to the three alignment buttons in the module modal:
  4. @szabesz, I think this is covered by $input->url() and $input->httpUrl() now, which were introduced since I wrote my post above. There's a blog post about it somewhere but I can't find it at the moment.
  5. The class names are defined in the config for the Page Edit Image module (ProcessPageEditImageSelect).
  6. Turns out it's not difficult to do this using the core ImageSizer. Here's a function showing the basics - could be turned into a module, enhanced with some error checking, etc. /** * Resize Pageimage using custom name/path * * @param Pageimage $pageimage * @param int $width * @param int $height * @param array $options * * @return string * */ function resizeImage($pageimage, $width = 0, $height = 0, $options = array()) { $filename = $pageimage->filename(); $basename = $pageimage->basename(); $path = rtrim($filename, $basename); $dirname = $width . 'x' . $height; $variation_name = $path . $dirname . '/' . $basename; $variation_url = rtrim($pageimage->url(), $basename) . $dirname . '/' . $basename; $force_new = isset($options['forceNew']) ? $options['forceNew'] : false; if(!file_exists($variation_name) || $force_new) { wire('files')->mkdir($path . $dirname . '/'); copy($filename, $variation_name); $sizer = new ImageSizer($variation_name); $sizer->setOptions($options); $sizer->resize($width, $height); wire('files')->chmod($variation_name); } return $variation_url; } // example $image = $page->images->first(); $src = resizeImage($image, 500, 300); echo "<img src='$src'>";
  7. The built-in image sizing methods are convenient but they're not the only way to resize an image. You could use a third-party PHP library such as WideImage and save your images with any naming or directory structure you need.
  8. A Page Reference field will work great for your "Homepage Listung" field. It's no problem to set a Page Reference field using data from a CSV import. You don't say how you are importing the CSV data, but let's say you are using the ImportPagesCSV module. The module readme says... Probably the easiest way in your case is to use the title of the page. So a basic outline of what's involved... The template for the pages in your Page Reference field should contain the "Title" field and a "Label" text field. Create the pages for the Page Reference field - one for each option that might occur in your CSV data. For the page Title use the value that appears in the CSV data. For the page Label use the label that belongs to that value. Example... Title: "NE2", Label: "n. Endkundenrelevant" Create the Page Reference field and add it to the template used for the pages you will be importing. Specify the pages you just created as the "Selectable pages". For the "Label field" setting, choose "label". Import your CSV data using the ImportPagesCSV module. Done.
  9. Hi @Martijn Geerts, Thanks for this module. I'm wanting to explore using it with a custom module that extends ProcessPageLister but the way the module checks if the page ID supplied to the url() method has the correct process is a stumbling block. In the module there is this test... if (strpos('ProcessPageListerPro', $listerPage->process) !== false) return $listerPage; ...which seems like a weird way to check that the process is okay. For instance, a process named 'age' would pass this test. And any process that has a different name yet may still be an instance of ProcessPageLister fails the test. How about a different test? $process_module = $this->modules->get($listerPage->process); if($process_module instanceof ProcessPageLister) return $listerPage;
  10. I'm having a bit of trouble understanding, but you can automate pretty much anything in PW - nothing has be done manually. Suppose you go with a Page Reference field for your options (which is usually the most flexible approach) - you can create new options (i.e. pages) on-the-fly as you import your data if you need to. But from what you say in the first post, it sounds like you already know the the options ahead of time and that is how you are able to set up the Table field with those options on the Home page. Instead of the Table field, create one page per option under some special branch of the page tree that is dedicated to that purpose. Set up a "Homepage Listung" Page Reference field that uses those pages as options. When you import the data you don't have to know the ID of the option (page) - you can find the option by title (e.g. "Bestätigt") or value (e.g. "JA1") and then set that option (page) for the "Homepage Listung" field.
  11. $index is the key of the array item, which in the case of a PageArray like this is the zero-based index of the item in the array. So it starts at 0 and goes up with each subsequent item. The "</div><div class='col-6'>" portion is where we end the first column and start the second column. There was an error in my code which I have corrected now - we only want this inserted once, when $index matches half the number of items in $testimonials rounded up to the nearest whole number.
  12. Hi @HarryPhone, If I understand right, what you are doing looks more complicated than it needs to be. If you just need values/titles in a select inputfield and your site editors don't need to edit these options then you can define the values/titles in an Options field: https://processwire.com/api/modules/select-options-fieldtype/#separate-option-values If your site editors do need to edit or add new options then you can use a Page Reference field. In the template for the pages you would use the Title field for the option title and add a text field for the option value.
  13. Nice tutorial, thanks! You could simplify the methods a little by making sure you always get the Images field as a Pageimages array, e.g. $wire->addHookMethod('Page::siteFeaturedImage', function($event) { $page = $event->object; if ($page->template != "article") { throw new WireException("Page::siteFeaturedImage() only works on 'Pages of article template', Page ID=$page is not such!"); } $article_featured = $page->getUnformatted('article_featured'); // always a Pageimages array if (count($article_featured)) { $img_url = $article_featured->first()->url; } else { $img_url = urls()->templates . "assets/img/missing-article_image.jpg"; //we show this when image is not available } $event->return = $img_url; });
  14. Nice one. Just another way to skin the cat... <?php $testimonials = $page->testimonials; $testimonials->shuffle(); $firstTestimonial = $testimonials->shift(); ?> <div class="jumbotron jumbotron-fluid bg-color"> <div class="container"> <h2><?= $firstTestimonial->title; ?></h2> <p><?= $firstTestimonial->testimonialBody; ?> - <i><?= $firstTestimonial->testimonialReviewee; ?></i></p> </div> </div> <div class='container'> <div class='row'> <div class='col-6'> <?php foreach($testimonials as $index => $testimonial): ?> <?php if($index == ceil(count($testimonials) / 2)): ?> </div> <div class='col-6'> <?php endif; ?> <h2 class='py-3'><?= $testimonial->title; ?></h2> <p><?= $testimonial->testimonialBody; ?></p> <p class="font-weight-bold text-muted">- <i><?= $testimonial->testimonialReviewee; ?></i></p> <?php endforeach; ?> </div> </div> </div>
  15. I forked this module and made it PW3 compatible. See the readme and the commit for details of what was changed. https://github.com/Toutouwai/ProcessBatcher If folks want to test it and report back I can make a pull request for @Wanze. @tpr, I hid the AdminOnSteroids datatables filterbox and the title case-change button because the layout was a bit messed up. Maybe you could take a look at that when you have time?
  16. @robinc, check out this module code in a Gist by @adrian: https://gist.github.com/adrianbj/2b3b6b40f64a816d397f
  17. Hi @joshuag - any update on this issue? Are you able to reproduce the issue at your end?
  18. Not saying it's a good idea because I have no idea how stable it would be, but if you wanted to share all the modules between the sites you could do something like this in each /site/config.php: $config->paths->siteModules = $config->paths->root . 'shared/modules/'; $config->urls->siteModules = $config->urls->root . 'shared/modules/';
  19. There is this: If you are looking at doing more specific searches with FieldtypeComments::find() be aware of this issue.
  20. Looks normal, so must something particular about the GitHub URL or the way that it is accessed that causes it to be blocked. It may be something that only your host can advise you on. You could try and set up a basic case to serve as a demonstration for them. ProcessWireUpgradeCheck.module basically does what I showed in a post above. If you take a look into WireHttp.php here and here you should be able to extract some of that code to create a basic test case in a PHP file that demonstrates the problem. For reference, here is what you should see when executing the code I posted above: [{"name":"dev","commit":{"sha":"651e8bd20c1f7bf13c08a2098f862adf82700a28","url":"https://api.github.com/repos/processwire/processwire/commits/651e8bd20c1f7bf13c08a2098f862adf82700a28"}},{"name":"master","commit":{"sha":"57b297fd1d828961b20ef29782012f75957d6886","url":"https://api.github.com/repos/processwire/processwire/commits/57b297fd1d828961b20ef29782012f75957d6886"}}]
  21. I think your result means that the problem isn't with GitHub - the request is not being sent successfully. Perhaps a firewall or some other security restriction on your server is blocking it. Are you able to use fopen() on any remote files? If you put this in your template... $handle = fopen('https://www.google.com/', 'r'); bd($handle, 'handle'); ...Tracy should show a stream resource in the dump.
  22. @DaveP, the GitHub API can respond with a 403 in a number of different situations, as described here: https://developer.github.com/v3/ But there should be some explanation in the "message" value of the returned JSON. You could put this in a template and see what you get back: $http = new WireHttp(); $http->setHeader('User-Agent', 'ProcessWireUpgrade'); $json = $http->get('https://api.github.com/repos/processwire/processwire/branches'); print_r($json);
×
×
  • Create New...