Changeset 260
- Timestamp:
- 02/11/08 21:14:11 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/trunk-newurl/api/process/luxbumgallery.php
r256 r260 17 17 /**-----------------------------------------------------------------------**/ 18 18 var $dir; 19 19 20 20 var $sortPosition = ''; 21 21 var $private = false; … … 44 44 45 45 $this->addAllFiles($fileType); 46 $this->_completeInfos ();46 $this->_completeInfos(); 47 47 $this->_loadPrivate(); 48 48 } … … 57 57 * @access private 58 58 */ 59 function _completeInfos () {60 if ($fd = dir ($this->dirPath)) {61 while ($current _file = $fd->read()) {62 if (files::isPhotoFile($this->dir, $current _file)) {63 $theFile = luxbum::getFilePath($this->dir, $current _file);64 $this->imageSize += filesize ($theFile);65 $this->imageCount++; 66 } 67 else if (files::isFlvFile($this->dir, $current _file)) {68 $theFile = luxbum::getFilePath($this->dir, $current _file);69 $this->flvSize += filesize ($theFile);70 $this->flvCount++; 59 function _completeInfos() { 60 if ($fd = dir($this->dirPath)) { 61 while ($currentFile = $fd->read()) { 62 if (files::isPhotoFile($this->dir, $currentFile)) { 63 $theFile = luxbum::getFilePath($this->dir, $currentFile); 64 $this->imageSize += filesize($theFile); 65 $this->imageCount++; 66 } 67 else if (files::isFlvFile($this->dir, $currentFile)) { 68 $theFile = luxbum::getFilePath($this->dir, $currentFile); 69 $this->flvSize += filesize($theFile); 70 $this->flvCount++; 71 71 } 72 72 } … … 92 92 93 93 /** 94 * 94 * 95 95 */ 96 96 function setDir($dir) { … … 102 102 * @return String Chemin de la galerie 103 103 */ 104 function getDir () {104 function getDir() { 105 105 return $this->dir; 106 106 } … … 123 123 124 124 /** 125 * 125 * 126 126 */ 127 127 function isUnlocked() { … … 129 129 return $privateManager->isUnlocked($this->dir); 130 130 } 131 131 132 132 function isPrivateAndLocked($current = true) { 133 133 return $this->isPrivate() && !$this->isUnlocked(); … … 140 140 * Lit le fichier des dates/descriptions et retourne un tableau 141 141 * correspondant par rapport au nom de fichier. 142 * 142 * 143 143 * @return array clᅵ: nomPhoto / valeur: date|description 144 144 */ 145 function getDescriptions () {146 $desc = array ();147 148 if (file_exists($this->dirPath.DESCRIPTION_FILE)) { 149 $fd = @fopen ($this->dirPath.DESCRIPTION_FILE, 'r');145 function getDescriptions() { 146 $desc = array(); 147 148 if (file_exists($this->dirPath.DESCRIPTION_FILE)) { 149 $fd = @fopen($this->dirPath.DESCRIPTION_FILE, 'r'); 150 150 if ($fd === false) { 151 151 throw new Pluf_HTTP_FileSystemException(__("Unable to open file: ").$this->dirPath.DESCRIPTION_FILE); 152 152 } 153 153 while ($line = trim(fgets($fd))) { 154 if ( ereg ('^.*\|.*\|.*$', $line)) {155 list ($imgName, $imgDescription) = explode('|', $line, 2);154 if ( ereg('^.*\|.*\|.*$', $line)) { 155 list($imgName, $imgDescription) = explode('|', $line, 2); 156 156 $desc [$imgName] = $imgDescription; 157 157 } 158 158 } 159 fclose ($fd);159 fclose($fd); 160 160 } 161 161 return $desc; 162 162 } 163 163 164 164 /** 165 165 * Crᅵe ou met ᅵ jour le fichier des descriptions des photos 166 * 167 */ 168 function createOrMajDescriptionFile () {169 $desc = array ();166 * 167 */ 168 function createOrMajDescriptionFile() { 169 $desc = array(); 170 170 171 171 // Search images which are in the description file 172 172 if (file_exists($this->dirPath . DESCRIPTION_FILE)) { 173 if (!($fd = @fopen ($this->dirPath . DESCRIPTION_FILE, 'r'))) {173 if (!($fd = @fopen($this->dirPath . DESCRIPTION_FILE, 'r'))) { 174 174 throw new Pluf_HTTP_FileSystemException(__("Unable to read file: ").$this->dirPath.DESCRIPTION_FILE); 175 } 175 } 176 176 else { 177 while ($line = fgets ($fd)) {178 if (ereg ('^.*\|.*\|.*$', $line)) {179 list($desc[]) = explode ('|', $line, 2);177 while ($line = fgets($fd)) { 178 if (ereg('^.*\|.*\|.*$', $line)) { 179 list($desc[]) = explode('|', $line, 2); 180 180 } 181 181 } … … 185 185 186 186 // On ajoute les images non présentes dans le fichier de description 187 if (!($fd = @fopen ($this->dirPath . DESCRIPTION_FILE, 'a+'))) {187 if (!($fd = @fopen($this->dirPath . DESCRIPTION_FILE, 'a+'))) { 188 188 throw new Pluf_HTTP_FileSystemException(__("Unable to write file: ").$this->dirPath.DESCRIPTION_FILE); 189 } 189 } 190 190 else { 191 191 reset($this->arrayList); 192 while (list (,$img) = each($this->arrayList)) {192 while (list(,$img) = each($this->arrayList)) { 193 193 $name = $img->getFile(); 194 if (!in_array ($name, $desc)) {195 fputs ($fd, "$name||\n");196 } 197 } 198 fclose ($fd);194 if (!in_array($name, $desc)) { 195 fputs($fd, "$name||\n"); 196 } 197 } 198 fclose($fd); 199 199 } 200 200 } … … 203 203 * Update the description file 204 204 */ 205 function updateDescriptionFile () {205 function updateDescriptionFile() { 206 206 if (!files::deleteFile($this->dirPath . DESCRIPTION_FILE)) { 207 207 throw new Pluf_HTTP_FileSystemException(__("Unable to delete file: ").$this->dirPath.DESCRIPTION_FILE); 208 208 } 209 209 210 210 if (!($fd = fopen ($this->dirPath . DESCRIPTION_FILE, 'a'))) { 211 211 throw new Pluf_HTTP_FileSystemException(__("Unable to delete file: ").$this->dirPath.DESCRIPTION_FILE); 212 212 } 213 213 else { 214 for ($i = 0 ; $i < $this->getTotalCount () ; $i++) {214 for ($i = 0 ; $i < $this->getTotalCount() ; $i++) { 215 215 $img = $this->list[$i]; 216 $name = $img->getFile ();217 $description = $img->getDescription ();218 $date = $img->getDate ();219 fputs ($fd, "$name|$date|$description\n");216 $name = $img->getFile(); 217 $description = $img->getDescription(); 218 $date = $img->getDate(); 219 fputs($fd, "$name|$date|$description\n"); 220 220 } 221 221 fclose ($fd); 222 222 } 223 223 } 224 224 225 225 /**-----------------------------------------------------------------------**/ 226 226 /** Fonctions des sous galeries */ … … 230 230 * 231 231 */ 232 function isSubGallery ($current_file) {233 if (!is_dir($this->dirPath.$current _file)) {232 function isSubGallery($currentFile) { 233 if (!is_dir($this->dirPath.$currentFile)) { 234 234 return false; 235 235 } 236 if ($current _file[0] == '.') {236 if ($currentFile[0] == '.') { 237 237 return false; 238 238 } 239 if ($current _file == files::removeTailSlash(THUMB_DIR)240 || $current _file == files::removeTailSlash(PREVIEW_DIR)) {239 if ($currentFile == files::removeTailSlash(THUMB_DIR) 240 || $currentFile == files::removeTailSlash(PREVIEW_DIR)) { 241 241 return false; 242 242 } 243 if (files::isPhotoFile($this->dir, $current _file)) {243 if (files::isPhotoFile($this->dir, $currentFile)) { 244 244 return false; 245 245 } … … 253 253 return count($this->listSubGallery) > 0; 254 254 } 255 255 256 256 /** 257 257 * … … 262 262 263 263 // Parcours des photos du dossiers 264 while ($current _file = readdir($dir_fd)) {265 if ($this->isSubGallery($current _file)) {266 $this->listSubGallery[] = $this->dir.$current _file;264 while ($currentFile = readdir($dir_fd)) { 265 if ($this->isSubGallery($currentFile)) { 266 $this->listSubGallery[] = $this->dir.$currentFile; 267 267 } 268 268 } … … 280 280 */ 281 281 private function addAllFiles($fileType) { 282 282 283 283 if ($fileType == '') { 284 284 $fileType = TYPE_IMAGE_FILE | TYPE_FLV_FILE; … … 286 286 287 287 // Ouverture du dossier des photos 288 if ($dir_fd = opendir ($this->dirPath)) {289 288 if ($dir_fd = opendir($this->dirPath)) { 289 290 290 // Fetch all images, their descriptions and their orders 291 $desc = $this->getDescriptions ();291 $desc = $this->getDescriptions(); 292 292 $this->_loadSort(); 293 293 294 294 // Parcours des photos du dossiers 295 while ($current _file = readdir($dir_fd)) {296 295 while ($currentFile = readdir($dir_fd)) { 296 297 297 // Add an image file 298 if (files::isPhotoFile ($this->dir, $current_file) &&($fileType & TYPE_IMAGE_FILE)) {299 $imageTemp = new luxBumImage ($this->dir, $current_file);300 298 if (files::isPhotoFile($this->dir, $currentFile) &&($fileType & TYPE_IMAGE_FILE)) { 299 $imageTemp = new luxBumImage($this->dir, $currentFile); 300 301 301 // On affecte les dates / descriptions 302 if (array_key_exists ($current_file, $desc)) {303 list ($imgDate, $imgDescription) = explode ("|", $desc[$current_file], 2);304 $imageTemp->setAllDescription ($imgDescription, $imgDate);302 if (array_key_exists($currentFile, $desc)) { 303 list($imgDate, $imgDescription) = explode("|", $desc[$currentFile], 2); 304 $imageTemp->setAllDescription($imgDescription, $imgDate); 305 305 } 306 306 307 307 // On affecte l'ordre 308 if (array_key_exists ($current_file, $this->sortList)) {309 $imageTemp->setSortPosition($this->sortList[$current _file]);308 if (array_key_exists($currentFile, $this->sortList)) { 309 $imageTemp->setSortPosition($this->sortList[$currentFile]); 310 310 } 311 311 $this->addToList($imageTemp); 312 312 } 313 313 314 314 // Add a flash video file 315 else if (files::isFlvFile($this->dir, $current _file) &&($fileType & TYPE_FLV_FILE)) {316 $object = new LuxbumFlv($this->dir, $current _file);315 else if (files::isFlvFile($this->dir, $currentFile) &&($fileType & TYPE_FLV_FILE)) { 316 $object = new LuxbumFlv($this->dir, $currentFile); 317 317 $this->addToList($object); 318 318 } 319 319 } 320 closedir ($dir_fd);321 } 322 323 if (count ($this->arrayList) > 0) {320 closedir($dir_fd); 321 } 322 323 if (count($this->arrayList) > 0) { 324 324 $this->arrayList = $this->sortRecordset($this->arrayList, $this->sortType, $this->sortOrder); 325 325 } 326 326 } 327 328 327 328 329 329 /**-----------------------------------------------------------------------**/ 330 330 /** Fonctions de tri */ … … 378 378 * @access private 379 379 */ 380 function _completeDefaultImage () { 381 $default = ''; 382 383 // On est dans une sous galerie sans images 380 protected function _completeDefaultImage() { 381 382 // The gallery has no image 384 383 if ($this->getTotalCount() == 0) { 385 384 $this->preview = ''; 386 } 387 385 return; 386 } 387 388 388 if ($this->getImageCount() == 0 && $this->getFlvCount() > 0) { 389 389 390 390 } 391 391 … … 394 394 $fd = fopen(luxbum::getFilePath($this->dir, DEFAULT_INDEX_FILE), 'r'); 395 395 $line = fgets($fd); 396 396 397 397 if (files::isFile($this->dir, $line)) { 398 $default = $line; 398 $this->preview = $line; 399 fclose($fd); 400 return; 399 401 } 400 402 fclose($fd); … … 402 404 403 405 // Search the first image of the gallery 404 if ($default == '') { 405 $trouve = false; 406 $apercu_fd = opendir ($this->dirPath); 407 408 while (!$trouve && $current_file = readdir ($apercu_fd)) { 409 if ($current_file[0] != '.' 410 && !is_dir (luxbum::getImage ($this->dir, $current_file)) 411 && eregi ('^.*(' . ALLOWED_FORMAT . ')$', $current_file)) { 412 $default = $current_file; 413 $trouve = true; 414 } 415 } 416 closedir($apercu_fd); 417 } 418 419 $this->preview = $default; 406 $fd = opendir($this->dirPath); 407 408 while ($currentFile = readdir($fd)) { 409 if ($currentFile[0] != '.' 410 && !is_dir(luxbum::getImage($this->dir, $currentFile)) 411 && eregi('^.*(' . ALLOWED_FORMAT . ')$', $currentFile)) { 412 $this->preview = $currentFile; 413 closedir($fd); 414 return; 415 } 416 } 417 closedir($fd); 420 418 } 421 419 … … 423 421 * Set an user defined image 424 422 * @param String $filename Filename of the user defined image 425 * @return boolean 426 */ 427 function setNewDefaultImage ($filename) {423 * @return boolean 424 */ 425 function setNewDefaultImage($filename) { 428 426 $theFile = $this->dirPath . $filename; 429 if (!is_file ($theFile)) {427 if (!is_file($theFile)) { 430 428 return false; 431 429 } 432 files::writeFile ($this->dirPath . DEFAULT_INDEX_FILE, $filename);430 files::writeFile($this->dirPath . DEFAULT_INDEX_FILE, $filename); 433 431 return true; 434 432 } 435 436 433 434 437 435 /**-----------------------------------------------------------------------**/ 438 436 /** Rename / delete functions */ … … 443 441 * @return boolean Rename success (true) or failed (false) 444 442 */ 445 function rename ($newName) {446 if (files::renameDir ($this->dirPath, luxbum::getFsPath($newName))) {447 commentaire::renameGalerie ($this->dir, $newName);443 function rename($newName) { 444 if (files::renameDir($this->dirPath, luxbum::getFsPath($newName))) { 445 commentaire::renameGalerie($this->dir, $newName); 448 446 $this->setName($newName); 449 447 return true; … … 451 449 return false; 452 450 } 453 454 /** 455 * Delete a gallery 456 * @static 451 452 /** 453 * Delete a gallery 454 * @static 457 455 * @param String $galleryName Gallery name to delete 458 456 */ 459 function delete ($galleryName) {460 files::deltree (luxbum::getFsPath($galleryName));461 commentaire::deleteGalerie ($galleryName);462 } 463 457 function delete($galleryName) { 458 files::deltree(luxbum::getFsPath($galleryName)); 459 commentaire::deleteGalerie($galleryName); 460 } 461 464 462 /** 465 463 * Delete the gallery cache. 466 464 */ 467 function clearCache () {465 function clearCache() { 468 466 $this->reset(); 469 while (list (,$img) = each ($this->arrayList)) { 470 $img->clearCache (); 471 } 472 } 473 474 475 // /** 476 // * @return string the link url to select all images in the current gallery 477 // */ 478 // public function getLinkSelectAll() { 479 // return link::selectall($this->dir); 480 // } 481 482 // /** 483 // * @return string the link url to select all images in the current gallery 484 // */ 485 // public function getLinkUnselectAll() { 486 // return link::unselectall($this->dir); 487 // } 488 467 while (list(,$img) = each($this->arrayList)) { 468 $img->clearCache(); 469 } 470 } 471 472 /** 473 * Empty implementation of the __toString() method 474 */ 489 475 function __toString() { 490 476 echo "luxbumgallery::__toString();";
