Hello world macro

I try to understand Zenphotos macros.

Following this page
https://www.zenphoto.org/news/content-macros/
I wrote a php macro file, enabled it in the extensions admin page.

I get a blank page because of line
'owner'=>'mymacro.php';

and with
'owner'=>'mymacro.php',
My Hello World is not displayed (using [ HELLOWORLD My ] )
End of page is not displayed too.

Using [ HELLOWORLD ] displays in red 1 parameter is missing, but page is fully displayed.

[ HELLOWORLD 'My' ] does not work too.
So, I am a bit lost.

Comments

  • acrylian Administrator, Developer

    Without the full code it will be hard to tell. What does the debuglog say? (that is the first you have to look!).

    If you have the spaces before/after the brackets it is probably just that. Those are only there in the doc - as noted - to make sure ZP does not exectute them. So [HELLOWORLD My].

    I referenced it on the other topic but this is a quite simple macro plugin you also can use as a guide:
    https://github.com/acrylian/zp_mapembed

  • ctdlg Member
    edited June 16

    My php file is a copy of code found here :
    https://www.zenphoto.org/news/content-macros/ :

    <?php
    /** Macro de test
     *
     * <br>
     * Fichier php  dans le répertoire plugins, et activé.
     *  */
    $plugin_author = "Me";
    $plugin_version = '0.1';
    $plugin_is_filter = 5|THEME_PLUGIN|ADMIN_PLUGIN;
    zp_register_filter('content_macro','mymacro');
    function mymacro($macros) {
            $macros['HELLOWORLD'] = array(
                    'class'=>'expression',
                    'params'=>array('string'),
                    'value'=>'getHelloWorld($1);',
                    'owner'=>'basic',
                    'desc'=>gettext('%1 = Text before')
            );
            return $macros;
    }
    function getHelloWorld() {
             return $beforetext.'Hello World';
    }
    ?>
    


    And error log :

     {885:Sun, 16 Jun 2024 18:14:18 GMT} Zenphoto v1.6.3
    AVERTISSEMENT : Undefined variable $_zp_db dans /DonneesMsi/Sites/clatique/multimedia/zp-core/functions/functions.php à la ligne 2727
    applyMacros called from getCodeblock (template-functions.php [4365])
    from printCodeblock (template-functions.php [4379])
    from include (pages-aide.php [33])
    from include (index.php [128])
    from index.php [56]
    {885:Sun, 16 Jun 2024 18:14:18 GMT}
    ERREUR : Call to a member function quote() on null dans /DonneesMsi/Sites/clatique/multimedia/zp-core/functions/functions.php à la ligne 2727 
    

    Your macros are ok :

    [ZENPHOTO_VERSION] 
    [CODEBLOCK 2]
    


    work as expected

  • acrylian Administrator, Developer

    The code looks actually correct, althouth the macro class probably should be "function" instead of "expression".

    Thanks you just found an error. There was a globla declaration missing. Should be fixed in the 1.6.4 support build. 1.6.4 will probably be release later today.

Sign In or Register to comment.