/**
  * Method that creates the images list file in a gallery directory.<br />
  * If there is already one, it is replaced.
  * @param str $name Name of the gallery.
  * @return array An array containing the images list.
  */
 protected function buildListFile($name)
 {
     $this->debug(__METHOD__, 2, __LINE__);
     $folder = $this->galleryFolder . sh_browser::modifyName($name);
     // We remove the old list file
     $file = $folder . '/' . self::LIST_FILENAME;
     if (file_exists($file)) {
         unlink($file);
     }
     list($width, $height) = explode('x', file_get_contents($folder . '/.images_dimensions'));
     $elements = scandir($folder);
     foreach ($elements as $element) {
         if (substr($element, 0, 1) != '.') {
             // The file is neither ".", nor "..", nor any hidden file or folder
             $ext = array_pop(explode('.', $element));
             if (in_array(strtolower($ext), $this->acceptedTypes)) {
                 // We don't take resized images neither
                 if (!preg_match('`.*\\.resized\\.[0-9]+\\.[0-9]+\\.png`', $element)) {
                     $imagePath = $this->linker->path->changeToShortFolder($folder) . '/' . $element;
                     $values['images'][]['src'] = $imagePath . '.resized.' . $width . '.' . $height . '.png';
                 }
             }
         }
     }
     $this->helper->writeArrayInFile($file, 'values', $values);
     return $values;
 }
 /**
  * Method called by the sh_render class to render the tag RENDER_DIAPORAMA.
  * @param array $attributes An associative array containing all the tag's attributes.
  * @return str The rendered html for the diaporama.
  */
 public function render_diaporama($attributes = array())
 {
     $name = $attributes['name'];
     $folder = $this->diapoFolder . sh_browser::modifyName($name);
     if (!is_dir($folder)) {
         return false;
     }
     if (isset($attributes['id'])) {
         $id = $attributes['id'];
         unset($attributes['id']);
     } else {
         $id = 'd_' . substr(md5(microtime()), 0, 10);
     }
     if (isset($attributes['first'])) {
         $first = $attributes['first'];
     } else {
         $first = 1;
     }
     $file = $folder . '/' . self::LIST_FILENAME;
     if (!file_exists($file)) {
         $this->buildListFile($name);
     }
     include $file;
     if (isset($attributes['manual'])) {
         $values['diapo']['manual'] = true;
         $attributes['commands'] = true;
     }
     if (isset($attributes['commands'])) {
         if (strtolower($attributes['commands']) == 'commands') {
             $values['diapo']['commands'] = true;
         }
     } elseif (file_exists($folder . '/.commands')) {
         $values['diapo']['commands'] = true;
     }
     if (isset($attributes['shuffle']) && is_array($values['images'])) {
         // 2 shuffles to really shuffle the array
         shuffle($values['images']);
         shuffle($values['images']);
     }
     $values['diapo']['id'] = $id;
     if (!empty($attributes['class'])) {
         $values['diapo']['class'] = $attributes['class'];
     } elseif (file_exists($folder . '/.classes')) {
         $values['diapo']['class'] = file_get_contents($folder . '/.classes');
     }
     if (isset($values['images'][$first]['src'])) {
         $values['defaultImage']['src'] = $values['images'][$first]['src'];
     } else {
         $values['defaultImage']['src'] = $values['images'][0]['src'];
     }
     $values['js']['dir'] = $this->getSinglePath(false);
     $values['diapo']['style'] = '';
     if (isset($attributes['width'])) {
         $values['diapo']['style'] .= 'width:' . $attributes['width'] . 'px;';
     }
     if (isset($attributes['height'])) {
         $values['diapo']['style'] .= 'height:' . $attributes['height'] . 'px;';
     }
     if (isset($attributes['float']) && $attributes['float'] != 'none') {
         $values['diapo']['style'] .= 'float:' . $attributes['float'] . ';';
     }
     if ($this->jsAdded) {
         $values['js']['added'] = true;
     } elseif (sh_html::$willRender) {
         $values['js']['added'] = true;
         $this->linker->javascript->get(sh_javascript::SCRIPTACULOUS);
         $this->linker->html->addScript($this->getSinglePath() . 'fastinit.js');
         $this->linker->html->addScript($this->getSinglePath() . 'crossfade.js');
         $this->linker->html->addScript($this->getSinglePath() . 'actions.js');
         $this->jsAdded = true;
     } else {
         $this->jsAdded = true;
     }
     return $this->render('diaporama', $values, false, false);
 }