Jump to content
horst

Page Image Manipulator 1

Recommended Posts

That wasn't my intention at all :) We have all fallen victim to this one - several times!

I don't ever remember to do it, but it is why it is recommended to do:

f("Y"==$on){

With it reversed like that, if you forget the second equals sign, it will throw an error, rather than assigning the value!

No, I definitely needed to have my nose rubbed in it if I couldn't see my mistake from Soma's comment. ;)

Good tip on reversing the comparison, I will try to make that my habit going forward!

Now as for Page Image Manipulator, I still see it recreating the images if I don't check for the image and skip it manually. :huh: 

(Latest code is in my edited previous post)

Share this post


Link to post
Share on other sites

There's a weird thing going on or I must do something silly. (dev 2.5.18)

/**
 * Options need to be set, if not I see the below error:
 * Error: Exception: Error when trying to save the MemoryImage: we have no Targetfilename! ...
 * (weird I guess)
 *
 */

$options = array('outputFormat' => 'jpg');
 
// Call PIM
$pim = $image->pimLoad("bright", true)->setOptions($options)->contrast(100)->brightness(100)->pimSave();
 
/**
 * There's no prefix in the filename of the image (should be 'bright' I guess), 
 * Now the original image is overwritten every time, after 3 or 4 page loads the image will be blank.  
 *
 */
 
/**
 * Setting setTargetFilename() in the PIM call and PIM works as expected.
 *
 */

$watermark = $page->rootParent->png;
$assets = str_replace($image->ext, '', $image->filename) . "video.150x112.jpg";
$pim = $image->size(150, 112)->pimLoad("video", true)->setTargetFilename($assets)->watermarkLogo($watermark, 'center', 0)->pimSave();
$image = "<img src='$pim->url' />";
---

I've spend a few hours to debug, but can't find any clue.

Edited by Martijn Geerts
  • Like 1

Share this post


Link to post
Share on other sites

@Martijn: I have tested it with PW 2.5.19 from this afternoon (14:00). I cannot replicate all of what you have reported.

WHen I take a basename.png and use your code example from above I get the right output:

// original   =>  variation
basename.png  =>  pim_bright_basename.jpg  

// URL  
/site/assets/files/1/pim_bright_basename.jpg

BUT it recreates it everytime new, also if I set the second param to false:

$options = array('outputFormat' => 'jpg');
 
// Call PIM
$pim = $image->pimLoad("bright", FALSE)->setOptions($options)->contrast(100)->brightness(100)->pimSave();

This is a bug or inconveniance by design, but If you call it this way it works as expected, without recreating it everytime:

$options = array('outputFormat' => 'jpg');
 
// Call PIM
$pim = $image->pimLoad("bright", FALSE, $options)->contrast(100)->brightness(100)->pimSave();

Share this post


Link to post
Share on other sites

I found out that the modue is not set to singular in the module header:

    static public function getModuleInfo() {
        return array(
            'title'      => 'Page Image Manipulator',
            'version'    => 14,
            'summary'    => 'This module provide basic Imagemanipulations for Pageimages and Imagefiles',
            'author'     => 'horst',
            'href'       => 'http://mods.pw/5E',
            'singular'   => false,
            'autoload'   => true
        );
    }

But because of this init gets called again and again:

    public function init() {
        $this->addHook('Pageimage::pimLoad', $this, 'getPageImageManipulator');
        $this->addHook('Pageimage::isVariation', $this, 'HookIsVariationPim');
    }

Funny enough it gets called with every call to a "pimLoad" initiated by a hook. Thus the hooks mulitply causing the module to crash (timeout exceeded) after 7 to 10 images beeing processed in a row within a single page.

I set the module to singular and everything seems to work fine.

  • Like 3

Share this post


Link to post
Share on other sites

:-[ , many thanks! This is fixed now in the Github repo.

  • Like 2

Share this post


Link to post
Share on other sites

:-[ , many thanks! This is fixed now in the Github repo.

Ok great. I was not 100% sure if setting it to "single" would be the perfect solution as I'm still not too familiar with the module architecture.

But it seems reasonable to me, and if it also seems reasonable to you then its fine. At least it works fine for me even when scaling 50 images in a row for a automatically generated slideshow.

Thanks for the plugin, it produces way better results than the standard image plugin in terms of quality.

BTW: I needed centred scaled down images that are not cropped and keep their proportions. Thus I had to add the following code:

function galleryimage($image) {
   if(($image->width / $image->height) > (600 / 400))
       return $image->pimLoad("gallery")->width(600)->canvas(600,400)->pimSave();
   else
       $img = $image->pimLoad("gallery")->height(400)->canvas(600,400)->pimSave();
}

Maybe you could add an option to scale that allows to keep proportions that way as this is something others might need too.

Actually this task was the reason for me to choose pim as this is not done correctly by the standard scaling algorithm, it seems to produce images that are not centred when you add an image that has the correct width but not the correct height. So when calling this with an image of e.g. 600x300 i would get a reulting image where all the added vertical canvas is on the bottom or if i remeber correctly it just returned the orignal image even though it was of the wrong size.

return $image->size(600, 400, array( 'upscaling' => true, 'cropping' => false, 'quality' => 97 ));

But thats something for the core module developers maybe.

  • Like 2

Share this post


Link to post
Share on other sites

Thanks for the plugin, it produces way better results than the standard image plugin in terms of quality.

.

Hhm, hard to believe. It uses the same functions and params as you can use with the core ImageSizer.

.

.

.

BTW: I needed centred scaled down images that are not cropped and keep their proportions. Thus I had to add the following code:

function galleryimage($image) {
   if(($image->width / $image->height) > (600 / 400))
       return $image->pimLoad("gallery")->width(600)->canvas(600,400)->pimSave();
   else
       $img = $image->pimLoad("gallery")->height(400)->canvas(600,400)->pimSave();
}
Maybe you could add an option to scale that allows to keep proportions that way as this is something others might need too.

.

The PiM is a bit outdated. The function you suggested is missing, I know. But I have no time at the moment to work on this.

.

.

.

Actually this task was the reason for me to choose pim as this is not done correctly by the standard scaling algorithm, it seems to produce images that are not centred when you add an image that has the correct width but not the correct height. So when calling this with an image of e.g. 600x300 i would get a reulting image where all the added vertical canvas is on the bottom or if i remeber correctly it just returned the orignal image even though it was of the wrong size.

return $image->size(600, 400, array( 'upscaling' => true, 'cropping' => false, 'quality' => 97 ));
But thats something for the core module developers maybe.

.

The core ImageSizer does not support canvas. But there is one other API-level ImageTool available: Pia. With it you can use $image->contain(), what reduces both sizes (width and height) to fit into given boundaries.

.

:)

Share this post


Link to post
Share on other sites

Hi Horst

I just went to update this via the updater on a site and got this error:

Error: Cannot redeclare PageEditFieldPermissionConfig() (previously declared in /home/justright/public_html/site/modules/PageEditFieldPermission/PageEditFieldPermissionConfig.php:8) (line 8 of /home/justright/public_html/site/modules/PageEditFieldPermission/PageEditFieldPermissionConfig.php) 

Which produced an server internal error for the entire site.

I have removed the page edit field permissions module (removed the folder) and that solved it. But why does updating your module break this other one?

On another PW site I tried uninstalling yours instead and the same thing happened. Removing the PIM folder didn't solve it.

Share this post


Link to post
Share on other sites

Hey Joss - I think the issue is more about refreshing the modules cache in general which probably happens when you update another module. That error with PageEditFieldPermissionConfig is actually a bit painful - if you upgraded PW to latest dev before upgrading the module it becomes quite difficult to get rid of that error because you can't actually upgrade the module to the latest version that fixes it. You might need to manually uninstall it, then reinstall - at least that was my experience.

  • Like 1

Share this post


Link to post
Share on other sites

I am very new to PW and PHP so please bear with me: I am probably making fundamental errors...

I have pages generated by a  template called postcard: each contain a jpg image which I am trying to watermark.  I am using PW Intermediate profile.

I have PageImageManipulator installed, I've created an imagefield called 'watermarkfield' and created a template called 'tools' with only Title and watermarkfield. I have then created a child page of Home called 'tools' using the tools template and have included in it a transparent png file called watermark.png in the watermarkfield.  I have saved the tools page as 'hidden'.

The content of the template postcard.php is:

<?php

// postcard.php template file
// See README.txt for more information

// Primary content is the page's body copy
$content = $page->body;

$png = $pages->get('/tools/')->watermarkfield;
foreach($images as $image) {
    $watermarked_image = $image->pimLoad('tw', true)->width(500)->watermarkLogo($png, 'southwest', 0)->pimSave();
    echo "<img src='{$watermarked_image->url}' />";
}

I am getting the following error on the produced pages:

Notice: Undefined variable: images in /var/www/vhosts/the-limes.com/httpdocs/site/templates/postcard.php on line 10
Warning: Invalid argument supplied for foreach() in /var/www/vhosts/the-limes.com/httpdocs/site/templates/postcard.php on line 10

Please can someone put me right?

Share this post


Link to post
Share on other sites

Hi @grumpy,

It looks to me that you have done nearly everything right. The only thing you left out is to populate $images in your code. I think you simply forgot

$images = $page->images;

, assumed that your current $page has an images field that is called "images".

But you also can ommit this extra line and change your code in line 10 to be:

foreach($page->images as $image) {

Share this post


Link to post
Share on other sites

Thank you horst.  I did option 2 (see above) and it went wrong big time!

Fatal error: Exception: Cannot read the pngAlphaImageFile! (in /var/www/vhosts/the-limes.com/httpdocs/site/modules/PageImageManipulator/ImageManipulator.class.php line 1652) #0 /var/www/vhosts/the-limes.com/httpdocs/site/templates/postcard.php(11): ImageManipulator->watermarkLogo(Object(Pageimages), 'southwest', 0) #1 /var/www/vhosts/the-limes.com/httpdocs/wire/core/TemplateFile.php(169): require('/var/www/vhosts...') #2 [internal function]: TemplateFile->___render() #3 /var/www/vhosts/the-limes.com/httpdocs/wire/core/Wire.php(366): call_user_func_array(Array, Array) #4 /var/www/vhosts/the-limes.com/httpdocs/wire/core/Wire.php(321): Wire->runHooks('render', Array) #5 /var/www/vhosts/the-limes.com/httpdocs/wire/modules/PageRender.module(356): Wire->__call('render', Array) #6 /var/www/vhosts/the-limes.com/httpdocs/wire/modules/PageRender.module(356): TemplateFile->render() #7 [internal function]: PageRender->___renderPage(Object(HookEvent)) #8 /var/www/vhosts/the-limes.com/httpdocs/wire/core/Wire.php(366): call_user_func_a in /var/www/vhosts/the-limes.com/httpdocs/index.php on line 252
Error: Exception: Cannot read the pngAlphaImageFile! (in /var/www/vhosts/the-limes.com/httpdocs/site/modules/PageImageManipulator/ImageManipulator.class.php line 1652)

#0 /var/www/vhosts/the-limes.com/httpdocs/site/templates/postcard.php(11): ImageManipulator->watermarkLogo(Object(Pageimages), 'southwest', 0)
#1 /var/www/vhosts/the-limes.com/httpdocs/wire/core/TemplateFile.php(169): require('/var/www/vhosts...')
#2 [internal function]: TemplateFile->___render()
#3 /var/www/vhosts/the-limes.com/httpdocs/wire/core/Wire.php(366): call_user_func_array(Array, Array)
#4 /var/www/vhosts/the-limes.com/httpdocs/wire/core/Wire.php(321): Wire->runHooks('render', Array)
#5 /var/www/vhosts/the-limes.com/httpdocs/wire/modules/PageRender.module(356): Wire->__call('render', Array)
#6 /var/www/vhosts/the-limes.com/httpdocs/wire/modules/PageRender.module(356): TemplateFile->render()
#7 [internal function]: PageRender->___renderPage(Object(HookEvent))
#8 /var/www/vhosts/the-limes.com/httpdocs/wire/core/Wire.php(366): call_user_func_a

Share this post


Link to post
Share on other sites

In case it helps, to give the fatal error etc. (see above) my amended postcard template read (I've since reverted it to the original error):

<?php

// postcard.php template file
// See README.txt for more information

// Primary content is the page's body copy
$content = $page->body;

$png = $pages->get('/tools/')->watermarkfield;
foreach($page->images as $image) {
    $watermarked_image = $image->pimLoad('tw', true)->width(500)->watermarkLogo($png, 'southwest', 0)->pimSave();
    echo "<img src='{$watermarked_image->url}' />";
}

Share this post


Link to post
Share on other sites

This error says that there is something wrong with your PNG file.

Please check on the tools template if the watermarkfield is set for a single image or for multiple images. If it is setup for multiple images, please correct it.

You can also check in your template if you got an imageobject:

$png = $pages->get('/tools/')->watermarkfield;

if (empty($png)) {
    // uhm, something went wrong!
    ... stop with further execution
}
Edited by horst

Share this post


Link to post
Share on other sites

You were absolutely right about that.  I did it and finally I have an image with a watermark.  Thank you very much for your help.  That's the good news... BUT.....

please look at:

http://www.the-limes.com/postcards/chalfont-st-peter/chalfont-st-peter-001/

We have made new images at the head of  the document (including watermarking the green png button which didn't want watermarking) and the image which did need to be watermarked does not have one.

If I store the postcard images (without watermark) in a protected directory on my website is PIM able to watermark them as they are called for by the postcard template?

Share this post


Link to post
Share on other sites

You need to apply the watermarking to the right image(field).

If you don't want oversized, watermarked images in your header menu, simply do not apply it there.

Look through your template code and find the right position, not where you have the header menu but where you output the postcard image.

Also be aware that currently, when trying out things, you may get displayed cached images also when altering the code. To force new creation of Pim images put as a second argument to pimLoad() a boolean true, BUT don't forget to remove it, once you have finished your code!

Share this post


Link to post
Share on other sites

Thank you, Horst, I'll try and muddle through that one.  I'll get there in the end - I don't give up!

  • Like 1

Share this post


Link to post
Share on other sites

Hi,

I would like add white text on image. Is there easy way to do that using this module? I know i can add watermark text but it has his own style. I need just white text with no style.

Share this post


Link to post
Share on other sites

Thank you for this Great Module !

I stuck with variations. Without resize image by using ProcessWire api variations not working. If i use ProcessWire sizing api with pim2Load function there are many files (no need them).

What i want to do :

1- Make a duplicate from original and keep original

2- Apply watermark to duplicated image

3- If result is fine for resize size, use this image for resizing (OR) resize from original and apply watermark, but don't make duplicates (for better watermark result)

4- See variations on admin panel, if i delete all images or specified image, delete all variations. (Deletion not working with below codes, if i delete image on filesystem i can see all watermarked images)

// Also i tried with pim2Load('wmi')->stepResize(image->width)->watermarkLogo($wmPath, 'c', '2')->pimSave();
$duplicateAndWatermarkOriginal = $image->pim2Load('wmi')->watermarkLogo($wmPath, 'c', '2')->pimSave();
// Create a small sized 1130x500px
// Also i tried with pim2Load('wmi')->stepResize(1130, 500)->watermarkLogo($wmPath, 'c', '2')->pimSave();
$smallFromDuplicated = $duplicateAndWatermarkOriginal->size(1130, 500);

Watermarked images is working and not regenerating them. Also i added a log message to your class. For check whats happened.

            if('page'==$this->entryItem) {
                $this->message("pageImage setFilename, setOriginal, targetFilename :: {$targetFilename}", Notice::log);
                $pageimage = clone $this->pageimage;
                $pageimage->setFilename($targetFilename);
                $pageimage->setOriginal($this->pageimage);
                return $pageimage;
            }

And i can have logs messages. Sometimes i can see variations count going up (from 2 variations to 4 variations) on list view of images but when i click variations its going down (from 4 variations to 2 variation) and on the list created images not appear.

Now i am running script like this and variations are working :

// Duplicated from original (same size), and apply watermark (here we have 2 original size without watermark and 1 with watermark)
$dImage = $image->size($image->width)->pim2Load('wmi')->watermarkLogo($wmPath, 'c', '2')->pimSave();
// Create small size from $dImage already watermarked (not have a duplicate  )
$sSizeImage = $dImage->size(1130, 500);
// If i want to create from original again (we have one more duplicate)
$sSizeFromOriginal = $image->size(1130, 500)->pim2Load('wmismall')->watermarkLogo($wmPath, 'c', '2')->pimSave();

Share this post


Link to post
Share on other sites

Hi @ukyo,

maybe there are optimization possibilities in your workflow. If you don't mind, I write down some thoughts ?

1) if you don't want send your original (master) image through the browser, (what I highly recommend), upload it with the max quality setting you can. (Speaking on JPEG only here in this regard).

2) try to reduce the image processing steps to a minimum. In your example you first call size with original width. This triggers a complete image manipulation including creation of a diskfile with the exact dimensions of the original image. But with a lower quality (depending of your default settings, maybe: 90). This lesser quality version is then loaded into pim2 and gets watermarked, and again saved with default value for quality. This is repeated once again for the $sSizeImage.

Better would be to A) use quality 100 for all intermediate steps and only save the last one with your desired endquality. I would create one fullsize variation with the watermark logo.

// creates a copy of the original, but with watermark and suffix "wmi"
$wmiImage = $image->pim2Load('wmi')->watermarkLogo($wmPath, 'c', '2')->setQuality(100)->setSharpening('none')->pimSave();

 Now use this wmi image (variation) for your resized versions:

// create an image 1130x500
$sSizeImage1 = $wmiImage->size(1130, 500);

// create an image max width 300 
$sSizeImage2 = $wmiImage->width(300);

// and so on, ...

This way you have the original image plus one fullsize with watermark and one variation for every output image.

Share this post


Link to post
Share on other sites

You are right but I can't see variations on admin panel. This is why i am resizing original image again with same width.

Share this post


Link to post
Share on other sites

On my side, i tested some methods for add resized or watermarked images to variations for admin panel :
 
If i change your suffix and if i use variation name like ProcessWire (width x height) :
 

// From
$suffix = "-pim2-{$suffix}";

// To
$suffix = ".pim2.{$suffix}";

// And making watermarking by use variation like ProcessWire
// Watermark from original
$dImage = $image->pim2Load("{$image->width}x{$image->height}")->watermarkLogo($wmPath, 'c', '2')->pimSave();

// Create medium size from original with watermark
$mImg = $image->pim2Load("1130x500")->resize(1130, 500)->watermarkLogo($wmPath, 'c', '2')->pimSave();

// Use medium size for resize (will be watermarked making only resize)
$mImg = $mImg->size(750, 300);

Created files on disk :

rh4c5k.jpg

Here created variations :

r88me0.jpg

Original Size Watermarked

2uiu6bc.jpg

Medium Size Watermarked

ndvimt.jpg

I am not displaying original image. Displaying watermarked and sized images. Like this if i delete images from admin panel delete image and variations, clean work. Now the problem is file sizes as you see on my screen shot.

2h6dnxx.jpg

Order : Original Image - Watermarked from Original image - Resized from watermarked original image 

Edited: File sizes screenshot added.

  • Like 1

Share this post


Link to post
Share on other sites

@ukyo: you were right, there was a bug with the naming of variations. With using them from API in templates, it wasn't a big problem, but with trying to use them with the CKeditor it was, because the created name of the variation prevents PW from identifying them as variations, as you said.

I found out that there simply was missing a single dot in front of the suffix string: -pim2-suffix has to be .-pim2-suffix in cases where only the pim works on original images, whereas when pim worked on a variation, everything worked alright.

This is fixed now with version 0.2.7 of pim2.

Share this post


Link to post
Share on other sites

Hi Folks,

I hope somebody can help me out with following problem:

After a fresh Install of PW 2.7 i installed the wunderful Module of Horst "PAGE IMAGE MANIPULATOR" .

But I am not able to call the module functions. I Always get the following errormessage. It seems to me
that PW don't know anything of the installed module. But it is installed correctly. 

Horst mentioned , it could be something with accessrights of my file/image - field. But I tried out nearly 
everything to fix the problem. maybe some of you had a same problem.

ErrorMessage:

Error:     Exception: Method Pagefile::pim2Load does not exist or is not
callable in this context (in [...]/⁠html/⁠wire/⁠core/⁠Wire.php line 358)

#0 [internal function]: Wire-⁠>___callUnknown('pim2Load', Array)
#1 [...]/⁠html/⁠wire/⁠core/⁠Wire.php(398): call_user_func_array(Array, Array)
#2 [...]/⁠html/⁠wire/⁠core/⁠Wire.php(333): Wire-⁠>runHooks('callUnknown', Array)
#3 [...]/⁠html/⁠wire/⁠core/⁠Wire.php(337): Wire-⁠>__call('callUnknown', Array)
#4 [...]/⁠html/⁠wire/⁠core/⁠Wire.php(337): Pagefile-⁠>callUnknown('pim2Load',
Array)
#5 [...]/⁠html/⁠site/⁠templates/⁠basic-⁠page.php(18):
Wire-⁠>__call('pim2Load', Array)
#6 [...]/⁠html/⁠site/⁠templates/⁠basic-⁠page.php(18): Pagefile-⁠>pim2Load('test')
#7 [...]/⁠html/⁠site/⁠templates/⁠ho

This error message was shown because you are logged in as a Superuser.
Error has been logged.

The Problem also come up on a local windowsinstall with WAMPP and a Live- Webserver install on linux. 

:-(((

Thanks a lot

Michael

Share this post


Link to post
Share on other sites

@ukyo: you were right, there was a bug with the naming of variations. With using them from API in templates, it wasn't a big problem, but with trying to use them with the CKeditor it was, because the created name of the variation prevents PW from identifying them as variations, as you said.

I found out that there simply was missing a single dot in front of the suffix string: -pim2-suffix has to be .-pim2-suffix in cases where only the pim works on original images, whereas when pim worked on a variation, everything worked alright.

This is fixed now with version 0.2.7 of pim2.

I wrote my own module. Because, I have a project need to finish it quickly.

On my side file sizes are important. With your module. if you apply watermark file sizes going up (this is normal but x2 size up, not normal) On the screenshots you can see the results.

If you want have a look to my module here is a link : https://processwire.com/talk/topic/11318-avbimage/

And on attachment you can see my module result  :

post-2064-0-48512500-1447810184_thumb.pn

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-07-03 -- SnipWire 0.8.7 (beta) released! Fixes some small bugs and adds an indicator for TEST mode 2020-04-06 -- SnipWire 0.8.6 (beta) released! Adds support for Snipcart subscriptions and also fixes some problems 2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  

       
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By Sten
      Hello
      Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.
      So I'd like to create a module to include theses files added according to the url /fr/en/...
      Have you some observations to do before I begin about the direction to take ?
      Thank you
    • By ukyo
      Mystique Module for ProcessWire CMS/CMF
      Github repo : https://github.com/trk/Mystique
      Mystique module allow you to create dynamic fields and store dynamic fields data on database by using a config file.
      Requirements
      ProcessWire 3.0 or newer PHP 7.0 or newer FieldtypeMystique InputfieldMystique Installation
      Install the module from the modules directory:
      Via Composer:
      composer require trk/mystique Via git clone:
      cd your-processwire-project-folder/ cd site/modules/ git clone https://github.com/trk/Mystique.git Module in live reaction with your Mystique config file
      This mean if you remove a field from your config file, field will be removed from edit screen. As you see on youtube video.
      Using Mystique with your module or use different configs path, autoload need to be true for modules
      Default configs path is site/templates/configs/, and your config file name need to start with Mystique. and need to end with .php extension.
      Adding custom path not supporting anymore !
      // Add your custom path inside your module class`init` function, didn't tested outside public function init() { $path = __DIR__ . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; Mystique::add($path); } Mystique module will search site/modules/**/configs/Mystique.*.php and site/templates/Mystique.*.php paths for Mystique config files.
      All config files need to return a PHP ARRAY like examples.
      Usage almost same with ProcessWire Inputfield Api, only difference is set and showIf usage like on example.
      <?php namespace ProcessWire; /** * Resource : testing-mystique */ return [ 'title' => __('Testing Mystique'), 'fields' => [ 'text_field' => [ 'label' => __('You can use short named types'), 'description' => __('In file showIf working like example'), 'notes' => __('Also you can use $input->set() method'), 'type' => 'text', 'showIf' => [ 'another_text' => "=''" ], 'set' => [ 'showCount' => InputfieldText::showCountChars, 'maxlength' => 255 ], 'attr' => [ 'attr-foo' => 'bar', 'attr-bar' => 'foo' ] ], 'another_text' => [ 'label' => __('Another text field (default type is text)') ] ] ]; Example:
      site/templates/configs/Mystique.seo-fields.php <?php namespace ProcessWire; /** * Resource : seo-fields */ return [ 'title' => __('Seo fields'), 'fields' => [ 'window_title' => [ 'label' => __('Window title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'attr' => [ 'placeholder' => __('Enter a window title') ] ], 'navigation_title' => [ 'label' => __('Navigation title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'showIf' => [ 'window_title' => "!=''" ], 'attr' => [ 'placeholder' => __('Enter a navigation title') ] ], 'description' => [ 'label' => __('Description for search engines'), 'type' => Mystique::TEXTAREA, 'useLanguages' => true ], 'page_tpye' => [ 'label' => __('Type'), 'type' => Mystique::SELECT, 'options' => [ 'basic' => __('Basic page'), 'gallery' => __('Gallery'), 'blog' => __('Blog') ] ], 'show_on_nav' => [ 'label' => __('Display this page on navigation'), 'type' => Mystique::CHECKBOX ] ] ]; Searching data on Mystique field is limited. Because, Mystique saving data to database in json format. When you make search for Mystique field, operator not important. Operator will be changed with %= operator.
      Search example
      $navigationPages = pages()->find('my_mystique_field.show_on_nav=1'); $navigationPages = pages()->find('my_mystique_field.page_tpye=gallery');
    • By Robin S
      This is a module I made as an experiment a while ago and never got around to releasing publicly. At the time it was prompted by discussions around using Repeater fields for "page builder" purposes, where the depth feature could possibly be used for elements that would be nested inside other elements. I thought it would be useful to enforce some depth rules and translate the depth data into a multi-dimensional array structure.
      I'm not using this module anywhere myself but maybe it's useful to somebody.
      Repeater Depth Helper
      This module does two things relating to Repeater fields that have the "Item depth" option enabled:
      It enforces some depth rules for Repeater fields on save. Those rules are:
      The first item must have a depth of zero. Each item depth must not be more than one greater than previous item depth. It provides a RepeaterPageArray::getDepthStructure helper method that returns a nested depth structure for a Repeater field value.
      Helper method
      The module adds a RepeaterPageArray::getDepthStructure method that returns a multi-dimensional array where the key is the page ID and the value is an array of nested "child" items, or null if there are no nested children.
      Example

      The module doesn't make any assumptions about how you might want to use the depth structure array, but here is a way you might use it to output a nested unordered list.
      // Output a nested unordered list from a depth structure array function outputNestedList($depth_structure, $repeater_items) { $out = "<ul>"; foreach($depth_structure as $page_id => $nested_children) { $out .= "<li>" . $repeater_items->get("id=$page_id")->title; // Go recursive if there are nested children if(is_array($nested_children)) $out .= outputNestedList($nested_children, $repeater_items); $out .= "</li>"; } $out .= "</ul>"; return $out; } $repeater_items = $page->my_repeater; $depth_structure = $repeater_items->getDepthStructure(); echo outputNestedList($depth_structure, $repeater_items);
       
      https://github.com/Toutouwai/RepeaterDepthHelper
      https://modules.processwire.com/modules/repeater-depth-helper/
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
×
×
  • Create New...