We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 353
    • 8 Posts
    Hello Everyone -

    It has been a long time since I have worked on a web site and I am, admittedly, very beginner/intermediate. I am integrating a site into ModX and everything has gone very smoothly. I have used ModX years ago and absolutely love its current status.

    The problem I am having is running scripts within ModX. Nothing seems to work properly. I have fiddled around with it a bit, but it is beyond my ability to figure it out now and it seems like a straightforward FaceBox script from the previous site. I have the ModX version in a stager folder on the webserver. Could someone check this out and see what I am doing wrong? It is the FaceBox Image Box on the right of the screen:

    Stager (broken) - http://www.nhpets.com/modx_test/services.html
    Live (working) - http://www.nhpets.com/services.html

    Thank you for any and all help. This is going to be a great tool for my job, and it has been a great learning experience for me!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I would say that you have a problem with your ajax imagefunctions.php file not being able to retrieve its images.
        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
        • 353
        • 8 Posts
        I’m sorry, I left out most of the pertinent information:

        MODx version : 1.0.2
        Version codename: rev 6066
        PHP Version 5.2.12
        Apache Version Apache/2.0.52 (Red Hat)
        MySQL Client API version 5.0.83

        Javascript is located in ’assets/templates/nhpets/js/’
        CSS Stylesheets are located in ’assets/templates/nhpets/styles/’
        Imagefunctions is located in ’assets/templates/nhpets/ajax/’

        Here is the code for my imagefuntions.php:
        <?php
        /*******************************************************************************
        	Filename				: imagefunctions.php
        
        	Called by				: 
        
        	Created					: 30 March 2004 (16:59:40)
        	Created by				: Rick Holmes/NinthVector LLC
        
        	QueryString Collection	: 
        	Form Collection			: 
        	Session Variables		: 
        	Database Tables			: 
        	Stored Procedures		: 
        	Include Files			: 
        
        
        	Comments				: provides AJAX 'back end' for image gallery for NHpets.com
        *******************************************************************************/	
        
        class DirectoryItems {
        	public $filearray = array();
        	private $directory;
        	private $imagetypes = array('jpg', 'jpeg', 'gif', 'png');
        	
        	function __construct($directory) {
        		$this->directory = $directory;
        		$this->getDirectoryItems();
        	}
        
        	private function getDirectoryItems() {
        		if (is_dir($this->directory)) {
        			$d = opendir($this->directory) or die("Failed to open $this->directory");
        			while (false !== ($f = readdir($d))) {
        				if (is_file($this->directory . $f)) {
        					$ext = substr($f, strpos($f, ".") + 1);
        					if (in_array($ext, $this->imagetypes)) {
        						array_push($this->filearray, $f);
        					}	
        				}
        			}
        		}
        	}
        
        	public function encodeJSON() {
        		return json_encode($this->filearray);
        	}
        }
        
        
        // get directory name from Ajax request
        if (isset($_GET['page'])) {
        	
        	$page = $_GET['page'];
        	$directory = "../photos/$page/";
        	
        	$files = new DirectoryItems($directory);
        	echo $files->encodeJSON();
        
        }
        
        // check directory for image files
        
        
        // return JSON string of image names
        
        
        ?>
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Try an absolute path for that line
          	$directory = "../photos/$page/";
            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
            • 353
            • 8 Posts
            I changed it to an absolute path and it still doesn’t work.

            	$directory = "assets/templates/nhpets/photos/$page/";


            It flips through the correct number of images that should be showing, but it is just not displaying the images properly.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              That’s not an absolute path.
              	$directory = "/home/domain/www/assets/templates/nhpets/photos/$page/";

              is an absolute path.
                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
                • 353
                • 8 Posts
                I tried both "/httpdocs/modx_test/assets/templates/nhpets/photos/$page/" and even "http://nhpets.com/modx_test/assets/templates/nhpets/photos/$page/" and neither are displaying the images.

                Using Firebug in firefox just now, I see that the source, regardless of the changes I make, is always
                src="photos/services/DSCN0045.jpg"

                Within Firebug, I manually changed that to
                src="assets/templates/nhpets/photos/services/DSCN0045.jpg"

                and the image renders correctly. I can’t find exactly where in the code the paths are being screwed up because I am not familiar enough with the language.
                  • 353
                  • 8 Posts
                  Here is the Image Call function from the file "assets/templates/nhpets/js/main.js" in case this helps:
                  // does Ajax call to load proper images into array of preloaded images
                  		getImages: function() {
                  			// first get page name from body id
                  			var page = document.body.id;
                  			if (page == 'directions') return;
                  			// php url
                  			var url = '../ajax/imagefunctions.php?page=' + page;
                  			
                  			$.getJSON(url,
                  				function(data) {
                  					jQuery.each(data, function(i, val) {
                  						var id = val.substr(0, val.lastIndexOf('.'));
                  						path = 'photos/' + page + '/' + val;
                  						imageArray[i] = $('<img>').attr('src', path).attr('id', id).attr('class', 'galleryphoto');
                  						});
                  					$('.galleryphoto').replaceWith(imageArray[0]);
                  					$('#image_minus').css('display', 'none')
                  				});			
                  		},
                  		
                  		changeImage: function(direction) {
                  			var count = imageArray.length;
                  			if (direction == 'plus') {
                  				if (imageIndex < count - 1) {
                  					imageIndex = imageIndex + 1;
                  					if ($('.galleryphoto')) {
                  						$('.galleryphoto').replaceWith(imageArray[imageIndex]);
                  					}
                  					$('#image_minus').css('display', 'block');
                  				} else {
                  					$('#image_plus').css('display', 'none');
                  				}
                  			} else if (direction == 'minus') {
                  				if (imageIndex > 0) {
                  					imageIndex = imageIndex - 1;
                  					if ($('.galleryphoto')) {
                  						$('.galleryphoto').replaceWith(imageArray[imageIndex]);
                  					}
                  					$('#image_plus').css('display', 'block')	
                  				} else {
                  					$('#image_minus').css('display', 'none')
                  				}
                  			}
                  		}
                  		
                  	}
                  }();
                  
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    path = 'photos/' + page + '/' + val;
                      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
                      • 353
                      • 8 Posts
                      @sottwell
                      Thank you so much!!! That was the line. It did the trick. Thank you for your prompt advice.

                      For years I have been following the progress of ModX and checking out different site design that people have been using to inspire me. One constant thing I have seen, through the years, is great feedback and help from @sottwell. For your advice today and for all that help you’ve provided through the years, I want to say thank you so much!