Jump to content

horst

PW-Moderators
  • Posts

    4,077
  • Joined

  • Last visited

  • Days Won

    87

Everything posted by horst

  1. Hey @kathep, glad you have solved it. But I wonder if it couldn't be done shorter, and also if not one of my examples also should work. Do you also have tried my second example? I think this one should work, regardless if I have understand the hirarchycal order of your data or not. If you like, please try out and compare the following examples: if($design_technique instanceof PageArray) { # first run my example 1) but put the $alreadyFoundCategories = array one level up !!! // create array for collecting output $outItems = array(); // array collecting categories $alreadyFoundCategories = array(); // this is moved from **) to this line foreach($design_technique as $test_skill) { // **) here was the "$alreadyFoundCategories = array();" before foreach($test_skill->design_skill_category as $example) { // is already processed, so skip this one if(isset($alreadyFoundCategories["{$example->title}"])) continue; // add it to the list $alreadyFoundCategories[$example->title] = $example->title; // collect for output $outItems[] = $example->title; } } // collect for comparision $outItems1 = $outItems; # second run is my example 2) // create array for collecting output $outItems = array(); foreach($design_technique as $test_skill) { foreach($test_skill->design_skill_category as $example) { $outItems[$example->title] = $example->title; // $outItems will be created as associative array, $key => value // we use the value (your title) also for the key // therefore each following item with a identical value will overwrite the previous one // and each items stays unique, as this is the nature of arrays: they cannot have keys with the same name or index !!! // therefore there is no need for array_unique ! But let us see } } // save it and create unique arrays for comparision: $outItems2 = $outItems; // we pass $outItems1 and $outItems2 through array_unique(), what will remove any duplicate value if there is any ! $outItems1u = array_unique($outItems1); $outItems2u = array_unique($outItems2); // now we put some debug message out $outMsg = "<pre>\n"; $outMsg .= "Method 1 collected " . count($outItems1) . " items\n"; $outMsg .= "Method 2 collected " . count($outItems2) . " items\n\n"; $outMsg .= "UniqueArray1 has " . count($outItems1u) . " items\n"; $outMsg .= "UniqueArray2 has " . count($outItems2u) . " items\n\n"; $outMsg .= "Method 1 seems to work " . (count($outItems1) == count($outItems1u) ? 'correct!' : 'wrong! Sorry.') . "\n"; $outMsg .= "Method 2 seems to work " . (count($outItems2) == count($outItems2u) ? 'correct!' : 'wrong! Sorry.') . "\n"; echo $outMsg . "\n\n</pre>"; }
  2. here is one more solution, created / based on Somas module
  3. It would be god if you can provide some more details about the hooks you are using for those modules, (a few lines of code for each of both modules) And if you create pages via API you also have to save them, so what is the difference between saving them the fisrt time (via API after creation) and the second one? A few lines of code you use to create save them would be helpful too.
  4. New addition: retinafy! this was created on request from @jjozsi here in this post. . * retinafy // create a pageimage with any method you like $image = $page->images->first()->size(400, 300); // call retinafy on it echo $image->retinafy(); // it outputs a markup string like this, where width and height is populated with half the sizes of the pageimage <img src="/site/assets/files/1234/basename.400x300.jpg" width="200" height="150" alt="description" /> . . The default markup template has the default replacements URL, WIDTH, HEIGHT and DESCRIPTION. <img src="[URL]" width="[WIDTH]" height="[HEIGHT]" alt="[DESCRIPTION]" /> You can change that to any markup you like in the modules Configpage! . . If you have additional properties populated with pageimages in your system, you can provide an array with those property names: // if you need custom properties in your markup, define the template in the modules config page with those placeholders, // please only use UPPERCASE and wrapp these [ ] around them <img src="[URL]" width="[WIDTH]" height="[HEIGHT]" data-custom1="[CUSTOM1]" data-custom2="[CUSTOM2]" /> // call retinafy with custom property names $customPropertyNames = array("custom1", "custom2"); echo $image->retinafy($customPropertyNames); // it outputs a markup string like this, where width and height is populated with half the sizes of the pageimage <img src="/site/assets/files/1234/basename.400x300.jpg" width="200" height="150" data-custom1="custom-value-1" data-custom2="custom-value-2" /> . . Regarding to the technique described in the article @jjozsi linked to in his post it would make much sense to use a low quality setting sitewide by defining it in the ImageSizerOptions, also available on the Pia Configpage. Otherwise, if this is not possible, you need to call your images for that you want the retinafy markup with the quality option set: // create a pageimage with any method you like echo $page->images->first()->size(400, 300, array("quality"=>35))->retinafy();
  5. I have updated Pia with this retinafy: https://github.com/horst-n/PageimageAssistant/commit/d31d743533133b130131d8c5b042bd510bf68bb2
  6. @jjozs: If you think you can go with Pia, I can implement this feature, but I wanted to clarify how it should be best done. With my above suggestion Pia will not create any image, you create the images with what ever method you like before Pia comes into play. Normally with images there is not returned any HTML output from PW. Only the images get rendered and the returned pageimage object holds the necessary properties (url, width, height, etc). But with a module we can also achieve to create and return some html output. So Pia will only inspect and return what is given by the pageimage on wich you call ->retinafy. If it has the right dimensions in regards of upscaling or not isn't noticed by Pia. How I understand it, you want to create and serve one image for all devices including retinas. You create the images in doublesizes as normally but with less quality == high compression. To achieve this you can set the sitewide default options for the imagesizer right in Pias config page. And if you have concernes that the images do not match a minimum length, there is are settings in images fields for minWidth and minHeight. If you provide values there, no image that do not match these criterias can be uploaded!
  7. If no other users are allowed to the Admin, one could use Diogos module I think: http://modules.processwire.com/modules/process-admin-custom-pages/ Edit: that was the wrong module, here is the right one: https://github.com/ocorreiododiogo/ProcessHomeAdmin
  8. Have you the latest cropimage module? There were updates lately regarding repeater fields: https://github.com/apeisa/Thumbnails/commits/master
  9. @jjozsi welcome to the forums. @jjozsi & @all I think this is a perfect task for Pia. I would suggest to implement it this way: // create a pageimage with any known method or module (width, height, size, crop, contain, cover, ...) $image = $images->first()->size(400,400,$options); // return output for retina displays $image->retina(); Pia will inspect the given pageimage for width and height and outputs a html img tag according to your settings in ModuleConfig but fills in the half value for width and height. Available placeholders should be each available Pageimage property from your system as uppercase wrapped into [], so the default ones are: - - [WIDTH] - [HEIGHT] - [DESCRIPTION] So, if you have this configsetting: <img src="" width="[WIDTH]" height="[HEIGHT]" alt="[DESCRIPTION]" /> and your $image->width is 400 and your $image->height is 300, the output of $image->retina() will be something like: <img src="/site/assets/files/1234/basename.400x300.jpg" width="200" height="150" alt="the image description" /> What do you think? Or is it odd to calculate the double size for the initial images by yourself? The advantage of this implementation is that you can use it with any core- or module-method (even future ones) that return a pageimage!
  10. -------------------------------------------------------------------------------------------------------------------------------- for PW 3.0+ please follow this link! -------------------------------------------------------------------------------------------------------------------------------- Croppable Image Module for PW >= 2.5.11 and PW <= 2.7.3 Version 0.8.3 alpha Hey, today I can announce an early (alpha) release of CroppableImage, what was forked from Anttis Thumbnails module. Until now there was a lot of work done by owzim, Martijn Geerts and me. We have solved the issues regarding the list from here: The modules are bundled together so that you only can and have to use FieldtypeCroppableImage for install, uninstall & configure. It uses new naming scheme that was introduced with PW 2.5.0 that supports suffixes. The complete image rendering is delegated to the core ImageSizer, or to any optional hooked in rendering engine. Template-settings are now fully supported, including removing variations when settings have changed. It fully respects settings for upscaling. If upscaling is set to false, you cannot select rectangles smaller than the crop setting. We implemented these enhancements: The GridView now is very nice and compact, and also benefits from the lately introduced setting for $config->adminThumbOptions. Permanent storage of the crop coordinates, quality and sharpening settings are now implemented native. No need to use PiM for this anymore. The usage/display of the Quality and Sharpening DropDown-Selects can be globally disabled/allowed in the modules Configpage. (additionally to that a setting on a 'per field base' is planned.) And the most wanted feature by the community: It gives back a pageimage and not the URL-string. This way you can use it like this: // get the first image instance of crop setting 'portrait' $image = $page->images->first()->getCrop('portrait'); You can further use every pageimage property like 'url', 'description', 'width' & 'height' with it: // get the first image instance of crop setting 'portrait' $image = $page->images->first()->getCrop('portrait'); echo "<img src='{$image->url}' alt='{$image->description}' />"; And you can proceed further image rendering with it: // get the first image instance of crop setting 'portrait' and proceed a resize with imagesizer $image = $page->images->first()->getCrop('portrait'); $thumb = $image->width(200); // or like this: $thumb = $page->images->first()->getCrop('portrait')->width(200); // and if you have installed Pia, you can use it here too: $thumb = $page->images->first()->getCrop('portrait')->crop("square=120"); The only downside with this is that when you (as the site developer) have enabled the usage of DropDown-Selects in the images editor, you do not know the values the editors have chosen for the images. As a workaround for this you can use the getCrop() method with a second param. This is a PW selector string. It can contain as many of the known pageimage options like 'quality', 'sharpening', 'cropping', etc, as you need, but none of them is required. But required is at least one setting for 'width' or 'height': $image = $page->images->first()->getCrop('portrait', "width=200"); $image = $page->images->first()->getCrop('portrait', "width=200, height=200, quality=80"); $image = $page->images->first()->getCrop('portrait', "height=400, sharpening=medium, quality=75"); . . You can get the module from GitHub: https://github.com/horst-n/CroppableImage (Better Docs are coming soon) Screenshots Related Infos A good setting in site/config.php for the AdminThumbs are: (height=>200 and scale=>0.5 !) $config->adminThumbOptions = array( 'width' => 0, 'height' => 200, 'scale' => 0.5, 'imageSizer' => array( 'upscaling' => false, 'cropping' => true, 'autoRotation' => true, 'sharpening' => 'soft', 'quality' => 90, 'suffix' => array(), ) );
  11. Wow! You have brought it a step further! Very well done to use the same naming scheme and provide the same methods. Edit: At the GitRepo I have seen that the gregwar lib supports IMagick? I saw a GD.php and a Imagick.php. How can I force to use the Imagick.php?
  12. It could be something like that: if($design_technique instanceof PageArray) { // create array for collecting output $outItems = array(); foreach($design_technique as $test_skill) { // array collecting categories $alreadyFoundCategories = array(); foreach($test_skill->design_skill_category as $example) { // is already processed, so skip this one if(isset($alreadyFoundCategories["{$example->title}"])) continue; // add it to the list $alreadyFoundCategories["{$example->title}"] = $example->title; // collect for output $outItems[] = $example->title; } } // create the output $import_skill .= " > " . implode(" / ", $outItems); } You can shorten this by using an associative array for $outItems and drop collecting items in $alreadyFoundCategories. Also I'm not really sure on wich level the items reside you want avoid to be collected twice. So you have to experiment with this snippet. if($design_technique instanceof PageArray) { // create array for collecting output $outItems = array(); foreach($design_technique as $test_skill) { foreach($test_skill->design_skill_category as $example) { // collect for output $outItems["{$example->title}"] = $example->title; } } // create the output $import_skill .= " > " . implode(" / ", $outItems); }
  13. Hey Ivan, a happy new year 2015! Actually here in Aachen Germany it is looking gray without snow at around +4°C
  14. If you have only a few or one function in a template, you may wrap a if function_exists() around it. If you have custom functions in other template files too, best way is to use a separate functions file. Depending on your setup you can include_once() your functions file in the site/config.php or a _init.php. This way you don't need to include it repeatedly in every single template file.
  15. @kathep: I like working with a editor / IDE that supports remote file editing (it is done via FTP behind the scenes). For me this is the most comfortable way, I really like it. Maybe your editor of choice has this too? Or can be extended somehow? Or another way could be to use a system software / protocol that lets you "hang in" remote directories into your filesystem. This way you can open any remote file with any software, also if the software doesn't support opening remote files by it self.
  16. I find PW and PHP addictive. And here is what others say: google-4-addictive EDIT: corrected broken google link
  17. ... and not to forget that your PHP skills will raise too. BTW, how have you found PW?
  18. Hey @kathep, it is simply missing a dot here, that concatenate your multiple results: $reading_w_heading .= "<p><a href='$read->url'>" .... $reading_w_heading .= "concatenate me"; (more here)
  19. horst

    Merry Christmas!

    Yes that was Stollen. And, ähm, this was you? I thought it was the angel.
  20. horst

    Merry Christmas!

    Frohe Weihnacht!
  21. @BernhardB: oh thanks! No problem to correct me if I do such nonsense. Ähm, maybe I need a syntax checking here in the forums editor,
  22. Hey, this is a parse error that says there is a sign missing or there is one to much somewhere in your code between line 1 and line 167 in course.php. So, nothing one can say without seeing the code. With wich Editor do you write your code? I would recommend an editor with syntaxHighlighting and syntaxChecking (!!) for PHP. If you don't have any, you can ask here what other users can recommend on free software for your system (Mac?). I have worked many years with Active State Komodo Edit, what is available for Win, Mac and Linux for free.
  23. Thanks for giving those insights. I have made a note to the additional param for wider aspect ratios, what wouldn't be much work to implement, but will wait if other users request support for weighten with those wider aspect ratios. Thanks for your help with this.
×
×
  • Create New...