comparison mgtool.php @ 16:3491ab93630e

Add sub-gallery thumbnails to gallery cache data.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 14 Sep 2015 10:57:10 +0300
parents 805f93962cf9
children c698618e6f67
comparison
equal deleted inserted replaced
15:805f93962cf9 16:3491ab93630e
32 32
33 define("GCLEAN_CACHES" , 0x01); 33 define("GCLEAN_CACHES" , 0x01);
34 define("GCLEAN_THUMBNAILS", 0x02); 34 define("GCLEAN_THUMBNAILS", 0x02);
35 define("GCLEAN_ALL" , 0x0f); 35 define("GCLEAN_ALL" , 0x0f);
36 36
37
38 define("GUPD_MED_IMAGE" , 0x01); 37 define("GUPD_MED_IMAGE" , 0x01);
39 define("GUPD_TN_IMAGE" , 0x02); 38 define("GUPD_TN_IMAGE" , 0x02);
40 define("GUPD_IMAGES" , 0x0f); 39 define("GUPD_IMAGES" , 0x0f);
41 define("GUPD_EXIF_INFO" , 0x10); 40 define("GUPD_EXIF_INFO" , 0x10);
42 define("GUPD_CAPTION" , 0x20); 41 define("GUPD_CAPTION" , 0x20);
325 324
326 return ($entry[$field] < $cvalue); 325 return ($entry[$field] < $cvalue);
327 } 326 }
328 327
329 328
330 function mgWriteGalleryCache($cacheFilename, &$gallery, &$entries) 329 function mgWriteGalleryCache($cacheFilename, &$gallery, &$entries, &$parentEntry)
331 { 330 {
332 // Store gallery cache for this directory 331 // Store gallery cache for this directory
333 $images = array(); 332 $images = array();
334 $albums = array(); 333 $albums = array();
335 foreach ($entries as $ename => &$edata) 334 foreach ($entries as $ename => &$edata)
343 else 342 else
344 $albums[$ename] = &$edata; 343 $albums[$ename] = &$edata;
345 } 344 }
346 ksort($images); 345 ksort($images);
347 ksort($albums); 346 ksort($albums);
347
348 // Choose gallery album image
349 if (count($images) > 0)
350 {
351 end($images);
352 $parentEntry["image"] = key($images);
353 }
348 354
349 $str = 355 $str =
350 "<?\n". 356 "<?\n".
351 "\$galData = ".var_export($gallery, TRUE).";\n". 357 "\$galData = ".var_export($gallery, TRUE).";\n".
352 "\$galAlbumsIndex = ".var_export(array_keys($albums), TRUE).";\n". 358 "\$galAlbumsIndex = ".var_export(array_keys($albums), TRUE).";\n".
358 return mgError("Error writing '".$cacheFilename."'\n"); 364 return mgError("Error writing '".$cacheFilename."'\n");
359 365
360 return TRUE; 366 return TRUE;
361 } 367 }
362 368
363 function mgHandleDirectory($mode, $basepath, $path, $parentData, $parentEntry, $writeMode, $startAt) 369
370 function mgHandleDirectory($mode, $basepath, $path, &$parentData, &$parentEntry, $writeMode, $startAt)
364 { 371 {
365 global $galExifConversions, $galTNPath, $galCleanFlags; 372 global $galExifConversions, $galTNPath, $galCleanFlags;
366 373
367 // Get cache file path 374 // Get cache file path
368 if (($cacheFilename = mgGetPath($path, "cache_file")) === FALSE) 375 if (($cacheFilename = mgGetPath($path, "cache_file")) === FALSE)
421 // Read caption data 428 // Read caption data
422 $captions = mgReadCaptionsFile($basepath, $path); 429 $captions = mgReadCaptionsFile($basepath, $path);
423 $gallery = mgGetAlbumData($basepath, $path); 430 $gallery = mgGetAlbumData($basepath, $path);
424 if ($parentData !== NULL && $parentEntry !== NULL) 431 if ($parentData !== NULL && $parentEntry !== NULL)
425 { 432 {
426 $gallery["parent"] = $parentData; 433 $gallery["parent"] = &$parentData;
427 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption"); 434 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption");
428 } 435 }
429 436
430 // Start actual processing 437 // Start actual processing
431 $nentries = count($entries); 438 $nentries = count($entries);
538 } 545 }
539 546
540 echo "\r".$path." ..... DONE\n"; 547 echo "\r".$path." ..... DONE\n";
541 548
542 mgCheckQuit(TRUE); 549 mgCheckQuit(TRUE);
543
544 // Store gallery cache for this directory
545 if ($writeMode && !mgWriteGalleryCache($cacheFilename, $gallery, $entries))
546 return FALSE;
547 {
548 {
549 }
550 }
551 } 550 }
552 else 551 else
553 mgFatal("Invalid work mode '".$mode."'.\n"); 552 mgFatal("Invalid work mode '".$mode."'.\n");
554 553
555 mgCheckQuit(TRUE); 554 mgCheckQuit(TRUE);
560 { 559 {
561 $epath = $path."/".$ename."/"; 560 $epath = $path."/".$ename."/";
562 $newWriteMode = ($writeMode === FALSE && $epath == $startAt) || $writeMode; 561 $newWriteMode = ($writeMode === FALSE && $epath == $startAt) || $writeMode;
563 562
564 if (!mgHandleDirectory($mode, $basepath, $epath, $gallery, $edata, $newWriteMode, $startAt)) 563 if (!mgHandleDirectory($mode, $basepath, $epath, $gallery, $edata, $newWriteMode, $startAt))
564 return FALSE;
565 }
566
567 // Finish update modes
568 if ($mode == GCMD_UPDATE || $mode == GCMD_RESCAN)
569 {
570 // Store gallery cache for this directory
571 if ($writeMode && !mgWriteGalleryCache($cacheFilename, $gallery, $entries, $parentEntry))
565 return FALSE; 572 return FALSE;
566 } 573 }
567 574
568 mgCheckQuit(TRUE); 575 mgCheckQuit(TRUE);
569 576