I'd like to access Zenphoto's template functions within a MODx snippet as per the Zenphoto as a 'plugin' user guide article. But I'm running into some trouble with [b]MODx Revolution 2.0.7-pl[/b] and [b]Zenphoto 1.4.0.2[/b] (installed in the /zenphoto/ directory)
I've attempted adding the suggested [i]constant definitions[/i] and a [i]require_once[/i] statement for the Zenphoto template-functions.php file to a [i]chunk[/i] which is then included in the [i]template[/i].
The chunk:
define('WEBPATH', 'zenphoto'); define('ZENFOLDER', 'zp-core'); require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");
The snippet:
$randomImage = getRandomImages(); echo '[img]'. $randomImage->getSizedImage(getOption('image_size')) . '[/img]getTitle() . '" />';
This attempt returns the following (anonymised) error:
Fatal error: Call to a member function getSizedImage() on a non-object in /home/username/domain.ca/core/cache/elements/modsnippet/46.include.cache.php on line 9
The same code in a standalone PHP file returns a random image successfully.
Someone found a solution for Evo back in 2008 by adding the constant definitions and require statement in the MODx index.php file. I understand this isn't a great solution but I attempted it anyway with expectedly no success.
Does anyone have any suggestions on how to get this working?
Errors like this are most likely caused by the zenphoto "include" being done from within a function. This has the effect of making Zenphoto global variables become
"local" to the function.
If you can figure out which varialbles this is happening to you can declare them global in your code snippit.
Implementing this is not an easy task because we do not know specifically what variables are impacted. I would make a guess that in this particular case it is the $_zp_supported_images variable, but that is just a guess.
The best thing would be to figure out how to launch Zenphoto from not within a function call. (This is how Zenphoto does launch its plugins so that they do not suffer this issue.)