See file /var/www/vhosts/web48.essex.concept69.eu/httpdocs/protected/controller/MainController.php


+ Error on line 349

        return $imageFolders[$randomPosition];

<?php
/**
 * MainController for the Martin Michael Krone website at krone-art.de
 *
 * @author Patrick Rodacker <patrick.rodacker@the-reflection.de>
 */
class MainController extends DooController
{

    
// stores the data for the view
    
public $data;

    
// path to the folder where content is placed in html files
    
private $contentRootFolder;

    
// path to the root images folder for display as content
    
private $imageRootFolder;

    
// url to the root images folder
    
private $imageUrl;

    
/**
     * set some default values in the contructor
     */
    
public function __construct()
    {
        
// empty sidebar content as default
        
$this->data['baseUrl'] = Doo::conf()->APP_URL;
        
$this->data['sidebar'] = '&nbsp;';
        
$this->data['classes'] = array('home' => '''image' => '''printed' => '''computer' => '''painting' => '''vita' => '''contact' => '''imprint' => '');
        
$this->contentRootFolder Doo::conf()->SITE_PATH Doo::conf()->PROTECTED_FOLDER 'view/content/';
        
$this->imageRootFolder Doo::conf()->SITE_PATH 'images/';
        
$this->imageUrl Doo::conf()->APP_URL 'images/';
    }


    
/* --------------- public action methods ------------------ */



    /**
     * index action
     */
    
public function index()
    {
        if (
$this->extension != '.html' && $_SERVER['REQUEST_URI'] != '/') {

            
//return 404;
        
}

        
$image $this->getRandomImage('Home');
        
$imageSource $this->imageUrl 'Home' DIRECTORY_SEPARATOR $image['fileName'];
        
$this->data['content'] = '<div class="home_image"><a class="fancybox" href="' $imageSource '"><img width="550" src="' $imageSource '" title="this is the title"/></a></div>';
        
$this->data['title'] = 'Startseite';
        
$this->data['classes']['home'] = 'act';
        
$this->render('index'$this->data);
    }

    
/**
     * image action shows images from folder 'Fotografie'
     */
    
public function image()
    {
        if (!
$this->params['folder'])
        {
            return array(
$this->getRedirectRouteToRandomSubfolder('Fotografie'), 'internal');
        } else {
            
$this->renderImageContent('Fotografie''image');
        }
    }

    public function 
printed()
    {
        if (!
$this->params['folder'])
        {
            return array(
$this->getRedirectRouteToRandomSubfolder('Druckgrafik'), 'internal');
        } else {
            
$this->renderImageContent('Druckgrafik''printed');
        }
    }

    public function 
computer()
    {
        if (!
$this->params['folder'])
        {
            return array(
$this->getRedirectRouteToRandomSubfolder('PC-Grafik'), 'internal');
        } else {
            
$this->renderImageContent('PC-Grafik''computer');
        }
    }

    public function 
painting()
    {
        if (!
$this->params['folder'])
        {
            return array(
$this->getRedirectRouteToRandomSubfolder('Malerei'), 'internal');
        } else {
            
$this->renderImageContent('Malerei''painting');
        }
    }

    public function 
vita()
    {
        
$this->renderTextContent('vita''Vita');
    }

    public function 
imprint()
    {
        
$this->renderTextContent('imprint''Impressum');
    }

    public function 
contact()
    {
        
$this->renderTextContent('contact''Kontakt');
    }


    
/* --------------- private render methods ------------------ */


    
private function renderTextContent($internalName$navigationName)
    {
        
$this->data['content'] = $this->loadContentFromFile($internalName);
        
$this->data['classes'][$internalName] = 'act';
        
$this->data['title'] = $navigationName;
        
$this->render('index'$this->data);
    }

    private function 
renderImageContent($folderName$internalName)
    {
        
$this->data['title'] = $folderName;
        
$this->data['sidebar'] = $this->getSubNavigation($folderName);
        
$this->data['classes'][$internalName] = 'act';

        
// subfolder is clicked
        
if ($folderParam $this->params['folder']) {

            
// find the folder from the folderUri
            
$folder $this->getFolderName($folderName$folderParam);
            
$imageFolderPath $folderName DIRECTORY_SEPARATOR $folder;

            if (
$imageGallery $this->getImageGallery($imageFolderPath))
            {
                
$this->data['content'] = $imageGallery;
                
$this->render('index'$this->data);
            }
        }
    }

    
/**
     * load the content from an html file
     * @param $filename string of the filename without the ending, .html will be appended automatically
     * @return string the content of the html file
     */
    
private function loadContentFromFile($filename)
    {
        
$content '';
        
$file $this->contentRootFolder $filename '.html';
        if (
file_exists($file)) {
            
$content file_get_contents($file);
        }
        return 
$content;
    }

    
/**
     * return the subfolders from the passed folder name under the root image folder 'images/
     * and set the position, set the name and title and uri
     * @param string $folder
     * @return array
     */
    
private function getImageFolders($folder)
    {
        
$imageFolders = new DirectoryIterator($this->imageRootFolder $folder);
        
$folders = array();
        
$counter 1;
        foreach (
$imageFolders as $imageFolder) {
            if (
$imageFolder->isDir() && !$imageFolder->isDot()) {

                
$pathName $imageFolder->getPathName();
                
$fileName $imageFolder->getFileName();
                
$folderDetails = array('path' => $pathName'class' => '');

                
// split to get position
                
if (substr_count($fileName'_')) {
                    list(
$position$folderName) = explode('_'$fileName);
                } else {
                    
$position $counter;
                    
$folderName $imageFolder->getFileName();
                }

                
// get last uri part
                
$baseUrlLevel substr_count(Doo::conf()->APP_URL'/');
                
$subLevel $baseUrlLevel 2;
                
$uriParts explode('/'$_SERVER['REQUEST_URI']);
                list(
$uriName$ending) = explode('.'$uriParts[sizeof($uriParts) - 1]);

                
// sub folder
                
if ((sizeof($uriParts) - $subLevel) == 2) {
                    
$url Doo::conf()->APP_URL $uriParts[sizeof($uriParts)-2] . DIRECTORY_SEPARATOR strtolower($folderName) . '.html';
                } else {
                    
$url Doo::conf()->APP_URL $uriName DIRECTORY_SEPARATOR strtolower($folderName) . '.html';
                }

                
// @todo remove debug output
                // print_r(array($url, Doo::conf()->APP_URL , $uriParts, sizeof($uriParts), $baseUrlLevel, $uriName));

                
$folderDetails['url'] = $url;
                
$folderDetails['folderParam'] = strtolower($folderName) . '.html';

                
// search for an navigation.txt file in the folder
                // and extract navigation name and title
                
$navigationFile $pathName DIRECTORY_SEPARATOR 'navigation.txt';
                if (
file_exists($navigationFile)) {
                    
$lines explode("\n"file_get_contents($navigationFile));

                    foreach (
$lines as $line) {
                        list(
$keyword$value) = explode(':'$line);
                        
$folderDetails[$keyword] = $value;
                    }
                }

                
// if no alternative name is found, set to foldername
                
if (!array_key_exists('name'$folderDetails)) {
                    
$folderDetails['name'] = $folderName;
                }

                
// if no title is found, set to default title
                
if (!array_key_exists('title'$folderDetails)) {
                    
$folderDetails['title'] = 'Bilder im Bereich ' $folderName ' anzeigen';
                }

                
// set active class
                
if ($uriName == strtolower($folderName)) {
                    
$folderDetails['class'] = 'act';
                }

                
// add entry to images folder array
                
$folders[intval($position)] = $folderDetails;
                
$counter++;
            }
        }
        
// sort the array 
        
ksort($folders);
        return 
$folders;
    }

    
/**
     * build a navigation as unordered html list from the image subfolder of the
     * submitted root folder
     *
     * uses the function getImageFolders()
     *
     * @param $folder
     * @return string
     * @see getImageFolders()
     */
    
private function getSubNavigation($folder)
    {
        
$navigation '<ul>';
        foreach (
$entries $this->getImageFolders($folder) as $entry) {
            
$navigation .= '<li><a class="' $entry['class'] . '" href="' $entry['url'] . '" title="' $entry['title'] . '">' $entry['name'] . '</a></li>';
        }
        
$navigation .= '</ul>';
        return 
$navigation;
    }

    
/**
     * return a random image from the images in the folder submitted as parameter
     * the image folder must be located under the root image folder configured via $this->imageFolder
     * @param $folder
     * @return mixed
     * @see getImagesFromFolder
     */
    
private function getRandomImage($folder)
    {
        
// get images
        
$images $this->getImagesFromFolder($folder);

        
$sortedImages = array();
        foreach(
$images as $image) {
            
$sortedImages[] = $image;    
        }        

        
// return random entry
        
return $sortedImages[rand(0sizeof($images) - 1)];
    }

    
/**
     * get the images from a folder under the imageRootFolder and return them as an array
     * @param string $folder
     * @return array $images
     */
    
private function getImagesFromFolder($folder)
    {
        
$path $this->imageRootFolder $folder;
        
$images = array();

        if (
is_dir($path)) {
            
$files = new DirectoryIterator($path);
            
// ksort($files);
            
foreach ($files as $file) {
                if (
$file->isFile()) {
                    
$imageExtensionsAllowed = array('jpg''jpeg''png''gif''bmp');
                    
$fileParts explode('.'strtolower($file->getPathName()));
                    
$fileExtension $fileParts[sizeof($fileParts)-1];
                    if (
in_array($fileExtension$imageExtensionsAllowed)) {
                        
$images[$file->getFileName()] = array('pathName' => $file->getPathName(), 'fileName' => $file->getFileName());
                    }
                }
            }
        }
        
ksort($images);        
        return 
$images;
    }

    
/**
     * create the html markup for the image gallery using the jquery fancybox
     * only the last image will be shown, the other images are hidden via css
     * @param string $folder
     * @return string $content
     */
    
private function getImageGallery($folder)
    {
        
$images $this->getImagesFromFolder($folder);
        if (
sizeof($images) > 0)
        {
            
$firstImage array_shift($images);
            
$imageUrl $this->imageUrl $folder DIRECTORY_SEPARATOR;

            
// first image is visible
            
$content '<a class="fancybox-gallery" rel="gallery1" href="' $imageUrl $firstImage['fileName'] . '" title="Bitte Bild anklicken um alle Bilder der Galerie anzusehen"><img src="' $imageUrl $firstImage['fileName'] . '" width="550" /></a>';

            foreach (
$images as $image) {
                
$content .= '<a class="fancybox-gallery hide" rel="gallery1" href="' $imageUrl $image['fileName'] . '" title="a title"><img src="' $imageUrl $image['fileName'] . '" width="550" /></a>';
            }

            return 
$content;
        }
        else
        {
            return 
false;
        }
    }

    private function 
getRandomSubfolder($folderName) {
        
// redirect to a random page
        
$imageFolders $this->getImageFolders($folderName);
        
$randomPosition rand(1,sizeof($imageFolders));        
        return $imageFolders[$randomPosition];

    }

    private function 
getRedirectRouteToRandomSubfolder($folderName) {
        
$randomFolder $this->getRandomSubfolder($folderName);
        
$redirectUri '/' strtolower($folderName) .'/' $randomFolder['folderParam'];
        return 
$redirectUri;
    }
    
/**
     * search in the subfolders of the imageRootFolder for a matching entry to the requested uri and return the correct folder name
     * @param $categoryFolder
     * @param $folderParam
     * @return string
     */
    
private function getFolderName($categoryFolder$folderParam)
    {
        
$imageFolders $this->getImageFolders($categoryFolder);
        foreach (
$imageFolders as $imageFolder) {
            if (
$imageFolder['folderParam'] == $folderParam) {
                
$folderPathParts explode(DIRECTORY_SEPARATOR$imageFolder['path']);
                return 
$folderPathParts[sizeof($folderPathParts) - 1];
            }
        }
        return 
'';
    }
}

?>


* Stack Trace...

  1. /var/www/vhosts/web48.essex.concept69.eu/httpdocs/index.php(29) calling run()
  2. /var/www/vhosts/web48.essex.concept69.eu/httpdocs/dooframework/app/DooWebApp.php(34) calling routeTo()
  3. /var/www/vhosts/web48.essex.concept69.eu/httpdocs/dooframework/app/DooWebApp.php(114) calling image()
  4. /var/www/vhosts/web48.essex.concept69.eu/httpdocs/protected/controller/MainController.php(66) calling getRedirectRouteToRandomSubfolder()
  5. /var/www/vhosts/web48.essex.concept69.eu/httpdocs/protected/controller/MainController.php(353) calling getRandomSubfolder()


* Variables...  Conf .  GET  .  POST  .  Session  .  Cookie 


object(DooConfig)#1 (22) {
  
["AUTOLOAD"] => NULL
  
["SITE_PATH"] => string(50"/var/www/vhosts/web48.essex.concept69.eu/httpdocs/"
  
["PROTECTED_FOLDER"] => string(10"protected/"
  
["BASE_PATH"] => string(63"/var/www/vhosts/web48.essex.concept69.eu/httpdocs/dooframework/"
  
["LOG_PATH"] => NULL
  
["APP_URL"] => string(20"http://krone-art.de/"
  
["SUBFOLDER"] => string(1"/"
  
["APP_MODE"] => string(3"dev"
  
["AUTOROUTE"] => bool(false)
  [
"DEBUG_ENABLED"] => bool(true)
  [
"ERROR_404_DOCUMENT"] => NULL
  
["ERROR_404_ROUTE"] => string(6"/error"
  
["CACHE_PATH"] => NULL
  
["AUTO_VIEW_RENDER_PATH"] => string(16"/fotografie.html"
  
["MEMCACHE"] => NULL
  
["TEMPLATE_ENGINE"] => string(7"DooView"
  
["TEMPLATE_SHOW_COMMENT"] => NULL
  
["TEMPLATE_ALLOW_PHP"] => NULL
  
["TEMPLATE_COMPILE_ALWAYS"] => NULL
  
["TEMPLATE_GLOBAL_TAGS"] => NULL
  
["MODULES"] => NULL
  
["APP_NAMESPACE_ID"] => NULL
}
$_COOKIE Variables array(0) {
}

BACK TO TOP