-
Posts
4,077 -
Joined
-
Last visited
-
Days Won
87
Community Answers
-
horst's post in How to disable default image variation? was marked as the answer
I assume you are speaking of the default admin thumb? If yes, there is no way I know about to avoid this with image fields. It is a requirement to display each image in the admin.
But if you don't need the thumbnails, just a list with filenames, you can use a file field instead of an image field. The image field is based upon file field, it only has additonal methods and properties related to images.
-
horst's post in Tagging multiple images was marked as the answer
Ok.
// code snippet that belongs into the site/ready.php file: // a hook that reads IPTC keywords on images upload and populates them into the images tags field $wire->addHookBefore("InputfieldFile::fileAdded", function(HookEvent $event) { $inputfield = $event->object; // handle to the image field if(!$inputfield instanceof InputfieldImage) { // we need an images field, not a file field return; // early return } if(version_compare(wire('config')->version, '2.8.0', '<')) { $p = $inputfield->value['page']; // get the page, PW < 2.8 } else { $p = $inputfield->attributes['value']->page; // get the page, PW >= 2.8 | 3.0 (or only from 3.0.17+ ??) } $image = $event->argumentsByName('pagefile'); // get the image // check for IPTC data $additionalInfo = array(); $info = @getimagesize($image->filename, $additionalInfo); // read image markers if($info !== false && is_array($additionalInfo) && isset($additionalInfo['APP13'])) { // APP13 is the IPTC marker $iptc = iptcparse($additionalInfo['APP13']); // IPTC field 025 = keywords collection if(is_array($iptc) && isset($iptc['2#025']) && is_array($iptc['2#025']) && count($iptc['2#025']) > 0) { $tags = array(); foreach($iptc['2#025'] as $k => $v) { if(empty($v)) continue; $tags[] = trim(strtolower($v)); } $p->get($inputfield->name)->trackChange('tags'); // prepare page to keep track for changes $image->tags = implode(' ', $tags); // add the tags list as string $p->save($inputfield->name); // save the page images field } } });
EDIT:
code was modified to detect $page also with PW version >= 2.8 | 3.0
EDIT 2:
Now it is working for all PW versions again. Had have the wrong HookEvent used here (addHokkAfter, but must be: addHookBefore!)
-
horst's post in Foreach loop commented out in HTML page was marked as the answer
The php server environment where you use this code, has short php syntax disabled.
To be save and transportable with your code, you never should use this. Always use <?php to enter into php mode. Better don't use <?
-
horst's post in Echoing AIOM "String" in template was marked as the answer
My personal opinion is: this is uggly code, hard to read, hard to maintain. I would do it more like this:
switch($switchColor) { case "Style3": $cssLink = AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/style3.css')); break; case "Style4": $cssLink = AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/style4.css')); break; default: $cssLink = AIOM::CSS(array('styles/style1.css', 'styles/slider.css', 'styles/style2.css', 'styles/normal.css')); } echo "<link rel='stylesheet' href='{$cssLink}' />";
To be honest, it could be made a bit more readable:
$myStyles = array('styles/style1.css', 'styles/slider.css', 'styles/style2.css'); if('Style3' == $switchColor) { $myStyles[] = 'styles/style3.css'; } else if('Style4' == $switchColor) { $myStyles[] = 'styles/style4.css'; } else { $myStyles[] = 'styles/normal.css'; } $cssLink = AIOM::CSS($myStyles); echo "<link rel='stylesheet' href='{$cssLink}' />"; // ---------------------------------------------------- // or just ? echo "<link rel='stylesheet' href='" . AIOM::CSS($myStyles) . "' />"; // or ? echo '<link rel="stylesheet" href="' . AIOM::CSS($myStyles) . '" />';
-
horst's post in How to organize Fields in Fieldsets with the ModuleConfig->add() method? was marked as the answer
Ah, great. I figured it out myself!
We need to add all fields into a children array:
$this->add( array( array( 'type' => 'Fieldset', 'name' => '_myfieldset', 'label' => 'Fieldset Label', 'collapsed' => Inputfield::collapsedYes, // Inputfield::collapsedNo 'children' => array( array( 'type' => 'select', 'name' => 'kit_type', 'label' => 'Select the Kit you are using', 'options' => array('uikit' => 'uikit'), 'required' => true, 'columnWidth' => 50, ), array( 'type' => 'text', 'name' => 'kit_fullpath', 'label' => 'directory site path to your kits scss sources', 'columnWidth' => 50, ) ), // close children ), // close fieldset //.. add more fields )); -
horst's post in Include and bootstrap with PW 3 was marked as the answer
I think it has to do with namespace.
Have you tried to prefix your file with
<?php namespace ProcessWire; or maybe it also works if you add
<?php use ProcessWire; ----
Or you can call it
$u = new ProcessWire\User(); -
horst's post in Image Resizing was marked as the answer
I can see!
You should read a bit about the images and our ImageSizer in the docs. What you are currently missing is, how to avoid the images caching. Add "forceNew" => true to your options array while developing. Otherwise you always will get the previously created and cached variation.
If you want to compare different options in one go, you also should read a bit about the suffix property.
-
horst's post in getRandom vs php rand() function was marked as the answer
I cannot follow for what you need all those arrays besides the images-array?
In the images-array all informations are accessible, why do you need to populate additional arrays with redundant data?
I clearly haven't checked what you want to do here.
You get you a random image from a multiple images field (what is a wirearray). And now, where is the other data that you need to find, before you populate all those arrays?
I'm also not sure if this is correct:
$rand_nr = rand(0, $h_images->count()); or if it should be
$rand_nr = rand(0, $h_images->count() -1); Images->count is 1-based and numeric array indexes are zero-based.
----
But back to the main question. Is it right that you have an images field and a list with links that is somehow paired one by one, but lives in different objects? What do you use to store the links in?
Wouldn't it be possible to write the links directly into an images field (by default, you have descriptions and tags field, but with a module like images-extra, you can add as many fields to the images as you need).
-
horst's post in Controlling cache globally was marked as the answer
Only thing I know is with ProCache, there you can globally toggle it with a single click.
-
horst's post in PNG file size increased on image upload was marked as the answer
Hi @wsjmdavies, welcome to the forums.
This seems to be not exactly determined what you've explained. But no problem, we can go together step by step to inspect what happens.
Regarding uploaded (original) images and image variations:
If you upload new images to an images field, the original uploaded files never get altered, with one exception. (I come to this later *) So, the original (uploaded) file regularly is unaltered, means has the exact filesize and contents as your local copy. Only the filename will get altered to match the criterias for asset filenames in PW. (all lowercase, 0-9, a-z, _-, no dots, etc) Image variations derives from the original uploaded source and are altered according to your request. (different dimensiones, optionally cropped, etc). A few part is reflected in a suffix that is appended to all image variations filename. (basename.jpg becomes basename.0x100.jpg or that like)
---
How have you determined that the original file gots altered?
What are your settings in the images field? Do you have any setting there in the fields for max-width or max-height? (* this would be the only exception where uploaded files can get altered!)
You have uploaded an image that contains compressed image (bitmap) data. Photoshop is able to apply a (hopefully) lossless compression to the bitmap data before storing it into the image file. ImageRenderingEngines in webenvironments often have not included equal compression algorithm. SO they uncompress the bitmap data, alters it, and stores it uncompressed, or with much lower compression rate into a new file. (What explains why a new (variation) file has higher filesize)
BTW: using compressed images as original sources for variations is a bad idea. It is not much relevant with PNGs, but highly with JPEGs:
mostly you will not serve the originals, (or you shouldn't do), but generate and serve variations. to generate one, you need to open (and uncompress compressed bitmap data) of the original image (more CPU usage each time) with JPEGs, what do not have lossless compression, you multiply building of compression artefacts with each saving / compression of bitmap data Best practice is: upload (original) images with 100% quality, and / or without compression. Do not serve those originals directly! If you need to serve images with the full dimensions, create a variation with 100% width/height, but lesser quality (e.g. 80% - 90%)
$original = $page->images->first(); $options = array('quality' => 80, 'forceNew' => true); // forceNew is recommended for testing purposes only!! $variation = $original->width($original->width, $options); // create an identical variation with lesser quality and filesize -
horst's post in URL formatting was marked as the answer
You are calling $sanitizer in the scope of a custom function. There you need to call it with wire("sanitizer")->pageName(), or, if you need it multiple times in your function: $sanitizer = wire("sanitizer"); and afterwards you can use $sanitizer->pageName().
This behaves the same with all PW template vars, like: $config, $pages, $templates, $sanitizer, $session, ...
-
horst's post in Resize methods in admin was marked as the answer
size() is bound to images, not files
you need to get the page then get the imagesfield then select the desired image (not: file!) do the resize -
horst's post in Update 2.7.3 to 3.0.8 - ProcessWire::getArray does not exist... was marked as the answer
Hah! It's working now with using
$include_fuel ? wire('all')->getArray() : array(), Thanks, @Lostkobrakai! You made me happy!
-
horst's post in Help Removing Repeater was marked as the answer
Repeaters (can) create pages before you need them. This is for convenience. The default value is set to 3.
You also can setup a repeater field to only create pages on demand. If I remember right, this would need one additional save click for every repeater item you add in the edit process.
1) check delete trash
2) set the repeater fields to NOT create temp pages, the default is set to 3 (!)
3) look under Admin -> Pages -> ... for a hidden folder with the repeater children and delete them
-
horst's post in File upload (images, pdfs) from base64 value was marked as the answer
$tmpDir = new WireTempDir('someName'); // add files $fileBasename = 'basename.ext'; $filename = $tmpDir->get() . $fileBasename; file_put_contents($filename, base64_decode($b64Data)); $page->files->add($filename); // repeat for all files ... // optionally, at the end call $tmpDir->removeAll(); EDIT: Ah, you already know / found WireTempdir()
EDIT2: If one use WireTempDir for very timeconsuming tasks, one optionally can define a maxAge for it, different than the default 120 seconds:
$tmpDir = new WireTempDir('someName', array('maxAge' => 300)); -
horst's post in Install to server subdirectory path not working with PW 2.7? was marked as the answer
@nixsofar: Do you speak from the exact same server in regard of the 2.6 and 2.7 installs?
And what's about to install the 2.6, and after checking and seeing it's running, just upload the complete wire folder and subfolders from 2.7 to, e.g. wire-27. After upload is complete, rename wire to wire-26 and wire-27 to wire. Besides the complete wire folder you also have to switch the index.php. That's all. (the htaccess hasn't any changes between this two versions and can stay as is).
Does this work?
-
horst's post in Sorting by Related Page Count was marked as the answer
I think this must work:
$pa = new PageArray(); // use a PageArray to collect all subject pages foreach($pages->find("template=subject") as $subject) { // iterate over all subject pages $subject->set('myCount', $pages->find("template=artworks, subjects=$subject")->count); // add a temporary property to it that holds the total number of linked items $pa->add($subject); // add it to the PageArray } foreach($pa->sort("-myCount") as $item) { // sort the PageArray descending by total number and echo the title and count echo "<li>{$item->title} ({$item->myCount})</li>"; } -
horst's post in Problems with rendered page - double div-Elements was marked as the answer
have you looked into the ckeditor content in one of those pages in editmode? (Sourcecode of the ckeditor field).
Could it be you have copied from your local installation and pasted into the ckeditor field of the online version? This way it would be possible that one of those divs (the inner one) was included with the copy / paste action and now lives in the field content of three pages.
Just a thought, maybe wrong.
PS: welcome to PW
-
horst's post in Update Modules results in caches is marked as crashed and last automatic repair failed was marked as the answer
can you delete all rows from the table caches via phpmyadmin?
or, if not, can you delete the table caches and create a new one:
CREATE TABLE `caches` ( `name` VARCHAR(255) NOT NULL, `data` MEDIUMTEXT NOT NULL, `expires` DATETIME NOT NULL, PRIMARY KEY (`name`), INDEX `expires` (`expires`) ) COLLATE='utf8_general_ci' ENGINE=MyISAM; This should solve it. After hitting refresh, it rows should be populated again.
-
horst's post in displaying PDF file failed although i followed the instructions i found here was marked as the answer
// maybe a link to the PDF is enough
echo "<a href='{$page->showPdf->url}' target='_blank'> download a nice PDF here </a>";
-
horst's post in set custom (temporary) url to page? was marked as the answer
Maybe this is of help for you? Jumplinks
-
horst's post in Multiple templates for one page, like PHP traits, or "granular" templates? was marked as the answer
Is it needed for the Backend Editmode? What's about to simply have one template with some fieldsets, each fieldset contains a few fields (those you mentioned in your subtemplates) and the visibility of the fieldsets are bound through checkboxes and the onlyShowIf settings for templates?
| Select granule Subtemplates: | | | | [ ] use Basic-Car | [ ] use Diesel-Engine | [ ] use Turbo-Engine | [ ] use Four-Wheel-Drive | | | | Select granule Subtemplates: | | | | [x] use Basic-Car | [ ] use Diesel-Engine | [ ] use Turbo-Engine | [ ] use Four-Wheel-Drive | | | |--- Basic car -------------------------------------------------------------------------------| | | | BC_textfield_1 BC_ceckbox_1 ... | | | |---------------------------------------------------------------------------------------------| | Select granule Subtemplates: | | | | [x] use Basic-Car | [ ] use Diesel-Engine | [ ] use Turbo-Engine | [x] use Four-Wheel-Drive | | | |--- Basic car -------------------------------------------------------------------------------| | | | BC_textfield_1 BC_ceckbox_1 ... | | | |---------------------------------------------------------------------------------------------| |--- Four-Wheel-Drive ------------------------------------------------------------------------| | | | FWD_textfield_1 FWD_ceckbox_1 .... | | | |---------------------------------------------------------------------------------------------| -
Pseudocode is like: only show Fieldset_BasicCar if Checkbox_BC is checked
-
horst's post in Page not showing up in search was marked as the answer
DatabaseStopwords.php
and https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/DatabaseStopwords.php#L83
Maybe something like:
DatabaseStopwords::remove("about"); in the config.php or on top of a / the search.php ?
-
horst's post in upscaling false is ignored was marked as the answer
@Tyssen: yes, the pixelated ones are cached versions from before you specified upscaling = false.
If you want to override them you can use one of the following methods:
add a $image->removeVariations() before creating the new ones! Attention: don't forget to remove this once you are ready!
since PW 2.5 you also can add 'forceNew' => true to your options array, this forces recreation of the variations every time a page loads! so please be careful and remove it after wards!!
you may load Pia, Pageimage Assistant module. She has an option in the modules config page for forceNew that works sitewide if you are in debug mode and logged in as superuser. This way you do not need to alter your template codes and also it does not slow down your page for guest visitors if you forget to disable it. -
horst's post in Can't access images array from external page was marked as the answer
If you know the pageid, you only need to get the page:
// get the page for that id $internalpage = $wire->pages->get($pageid); // now check if the page could be found if ($internalpage->id != $pageid) return false; // you can also check for the id not 0 if ($internalpage->id == 0) return false; So, assuming your $pageid is right, you will pass the lines above and you should be able to access your images field as usual:
$images = $internalpage->images; // lets check if there are images available or if the field in this page is empty, e.g. not uploaded any image to it if (count($images)) { foreach($images as $image) { // do stuff with the images ... } } BTW, welcome to the forums.