We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13197
    • 21 Posts
    I am hoping to integrate some Zenphoto galleries and images into a MODx site, but am having some problems. If anyone has any ideas about what could be causing this I would be very grateful for any feedback. I will post this on the MODx and Zenphoto forums.

    The following two bits of php code are intended to:
    1. Allow the use of Zenphoto functions from a non-zenphoto site.
    2. Display a random image from a Zenphoto album on the page.
    They seem to work as expected if placed in a page that is not part of my MODx site.
    If I place the code into MODx snippets and place those snippets in my template I get the error message displayed below.

    MODx and Zenphoto are both sharing the same MySQL database. The Zenphoto tables have a prefix of zp_ to keep them separate from the MODx ones. I did originally have a separate database for Zenphoto but had the same problem.

    MODx is running from within the root of the site /. Zenphoto is in a folder called /zenphoto. I don’t think there is a problem with the paths described as MODx appears to be reading the zenphoto ’template-functions.php’ file OK. The correct user name and password are entered in the zenphoto config file. I thought that it might be a problem accessing the zenphoto config file so I added <code>require_once(’zp-config.php’);</code> but it did not help.

    I am using Zenphoto 1.2 and MODx 0.9.6.1

    I should mention that the display of a random image is not all I wish to achieve by integrating Zenphoto! It just seemed like a good starting point for experimentation.

    Andy
    <!-- gives access to the zen photo template functions -->
    <?php
    define('ZENFOLDER', 'zp-core');
    define('WEBPATH', 'zenphoto');
    require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");
    ?>
    
    <!--  displays a random image from a zen photo gallery -->
    <?php
    $randomImage = getRandomImages();
    $randomImageURL = getURL($randomImage);
    echo "<a href='".$randomImageURL."' title='Random Picture...'>
    <img src='". $randomImage->getSizedImage(getOption('image_size')) . "'
    alt=\"random image\"\n" . $randomImage->getTitle() . '" /></a>';
    ?>
    
    <!-- error displayed when run as a snippet from within MODx. (The real user name is displayed)-->
    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »
     
    PHP error debug
      Error: 	mysql_connect() [function.mysql-connect]: Access denied for user: 'username@localhost' (Using password: NO)	 
      Error type/ Nr.: 	Warning - 2	 
      File: 	/home/itough/www/www/zenphoto/zp-core/functions-db.php	 
      Line: 	33	 
      Line 33 source: 	$mysql_connection = @mysql_connect($_zp_conf_vars['mysql_host'], $_zp_conf_vars['mysql_user'], $_zp_conf_vars['mysql_pass']); 
    
      • 7231
      • 4,205 Posts
      The error that you are getting is because you have not set the correct username/password for the database connection in the zenphoto/zp-core/functions-db.php file.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 13197
        • 21 Posts
        Hi dev_cw. Thanks for the swift response.

        Yes that looks like the case.

        However, I think that the functions-db.php file is supposed to obtain the user name and password from the zp-config.php file.

        When used from ’outside MODx’ it seems to be able to read the user name and password OK. When used from ’within MODx’ it gets the user name but not the password.

        The code from line 32-3 reads:
        $mysql_connection = @mysql_connect($_zp_conf_vars['mysql_host'], $_zp_conf_vars['mysql_user'], $_zp_conf_vars['mysql_pass']);


        So in this file I have not entered a user name or password, yet in the error message it displays the correct user name. This suggests it is getting that from the zp-config.php file. But for some reason it is either unable to read the password from the same file, or is not trying to place a password.

        If you have any further thoughts I would be grateful. Andy
          • 7231
          • 4,205 Posts
          require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");
          This may need to be altered to include the modx base path: $modx->config[’base_path’] in order to get the correct path. What is WEBPATH set to and where is the dir located in the modx directory.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 13197
            • 21 Posts
            MODx is at /home/itough/www/www/
            Zenphoto is at /home/itough/www/www/zenphoto
            My hosting company have things set so that /home/itough/www/www/ is treated as / as far as paths are concerned.

            WEBPATH for Zenphoto is set to zenphoto
            require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");
            results in: /home/itough/www/www/zenphoto/zp-core/functions-db.php

            I am not sure how I should incorporate: $modx->config[’base_path’] into the line: require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");

            I hope I have answered the questions properly!

            Thanks, Andy


              • 13197
              • 21 Posts
              The technical support guys from ICDSoft.com who host my domain have come up with a solution to this problem. Instead of placing the:
              <?php
              define('ZENFOLDER', 'zp-core');
              define('WEBPATH', 'zenphoto');
              require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");
              ?>
              as a snippet in a template it needs to be placed into the MODx index.php file.

              The other code:
              <?php
              $randomImage = getRandomImages();
              $randomImageURL = getURL($randomImage);
              echo "<a href='".$randomImageURL."' title='Random Picture...'>
              <img src='". $randomImage->getSizedImage(getOption('image_size')) . "'
              alt=\"random image\"\n" . $randomImage->getTitle() . '" /></a>';
              ?>
              is used as a snippet inside templates.

              Thanks to dev_cw for you earlier help with this.

              Andy

                • 7231
                • 4,205 Posts
                Glad you got it working. However be careful with editing the index.php file since you may overwrite it during an update.
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 13197
                  • 21 Posts
                  Good point. I’ll make sure I back it up. Thanks. Andy
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    I would try to make that a plugin, rather than add it to the index.php file.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 6726
                      • 7,075 Posts
                      That would be cool since ZenPhoto rocks !

                      In the meantime, thanks for the quick and dirty integration...
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l&#39;outil id