Changeset 13652 for extensions/GThumb/admin.php
- Timestamp:
- Mar 20, 2012, 11:32:30 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/GThumb/admin.php
r12758 r13652 3 3 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 4 4 5 function delete_gthumb_cache($height) 6 { 7 $pattern = '#.*-cu_s9999x'.$height.'\.[a-zA-Z0-9]{3,4}$#'; 8 if ($contents = @opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR)) 9 { 10 while (($node = readdir($contents)) !== false) 11 { 12 if ($node != '.' 13 and $node != '..' 14 and is_dir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node)) 15 { 16 clear_derivative_cache_rec(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node, $pattern); 17 } 18 } 19 closedir($contents); 20 } 21 } 22 23 if (isset($_GET['getMissingDerivative'])) 24 { 25 list($max_id, $image_count) = pwg_db_fetch_row( pwg_query('SELECT MAX(id)+1, COUNT(*) FROM '.IMAGES_TABLE) ); 26 $start_id = intval($_POST['prev_page']); 27 $max_urls = intval($_POST['max_urls']); 28 if ($start_id<=0) 29 { 30 $start_id = $max_id; 31 } 32 33 $uid = '&b='.time(); 34 global $conf; 35 $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; 36 $conf['derivative_url_style']=2; //script 37 38 $qlimit = min(5000, ceil(max($image_count/500, $max_urls))); 39 40 $query_model = 'SELECT id, path, representative_ext, width, height 41 FROM '.IMAGES_TABLE.' 42 WHERE id < start_id 43 ORDER BY id DESC 44 LIMIT '.$qlimit; 45 46 $urls=array(); 47 do 48 { 49 $result = pwg_query( str_replace('start_id', $start_id, $query_model)); 50 $is_last = pwg_db_num_rows($result) < $qlimit; 51 while ($row=pwg_db_fetch_assoc($result)) 52 { 53 $start_id = $row['id']; 54 $src_image = new SrcImage($row); 55 if ($src_image->is_mimetype()) 56 continue; 57 $derivative = new DerivativeImage(ImageStdParams::get_custom(9999, $conf['GThumb']['height']), $src_image); 58 if (@filemtime($derivative->get_path())===false) 59 { 60 $urls[] = $derivative->get_url().$uid; 61 } 62 if (count($urls)>=$max_urls && !$is_last) 63 break; 64 } 65 if ($is_last) 66 { 67 $start_id = 0; 68 } 69 }while (count($urls)<$max_urls && $start_id); 70 71 $ret = array(); 72 if ($start_id) 73 { 74 $ret['next_page']=$start_id; 75 } 76 $ret['urls']=$urls; 77 echo json_encode($ret); 78 exit(); 79 } 80 5 81 global $template, $conf, $page; 6 82 7 83 load_language('plugin.lang', GTHUMB_PATH); 8 include_once(GTHUMB_PATH.'functions.inc.php');9 84 include(dirname(__FILE__).'/config_default.inc.php'); 10 85 $params = $conf['GThumb']; 11 86 12 87 // Delete cache 13 if (isset($_ GET['deletecache']))88 if (isset($_POST['cachedelete'])) 14 89 { 15 check_pwg_token(); 16 gtdeltree(GTHUMB_CACHE_DIR); 90 check_pwg_token(); 91 delete_gthumb_cache($conf['GThumb']['height']); 92 delete_gthumb_cache($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']); 17 93 redirect('admin.php?page=plugin-GThumb'); 18 }19 20 // Generate cache21 if (isset($_GET['generatecache']))22 {23 if ($_GET['generatecache'] == 'complete')24 {25 array_push($page['infos'], l10n('Cache have been generated'));26 }27 else28 {29 $query = 'SELECT id, path, md5sum, tn_ext FROM '.IMAGES_TABLE.';';30 $result = pwg_query($query);31 $cache_dir = GTHUMB_CACHE_DIR.'/'.$conf['GThumb']['height'].'/';32 $missing = array();33 34 while ($row = pwg_db_fetch_assoc($result))35 {36 if (!is_file($cache_dir.md5($row['path'].(!empty($row['md5sum']) ? $row['md5sum'] : '')).'.'.$row['tn_ext'])37 and in_array(get_extension($row['path']), $conf['picture_ext']))38 {39 array_push($missing, $row['id']);40 }41 }42 echo json_encode($missing);43 exit();44 }45 94 } 46 95 … … 72 121 if ($params['height'] != $conf['GThumb']['height']) 73 122 { 74 gtdeltree(GTHUMB_CACHE_DIR);123 delete_gthumb_cache($conf['GThumb']['height']); 75 124 } 76 125 elseif ($params['margin'] != $conf['GThumb']['margin']) 77 126 { 78 gtdeltree(GTHUMB_CACHE_DIR.'/'.($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']));127 delete_gthumb_cache($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']); 79 128 } 80 129 … … 101 150 'CACHE_BIG_THUMB' => $params['cache_big_thumb'], 102 151 'METHOD' => $params['method'], 103 ) 104 ); 105 106 // Informations 107 $data = gtdirsize(GTHUMB_CACHE_DIR); 108 109 $template->assign( 110 array( 111 'NB_FILES' => $data['nb_files'], 112 'CACHE_SIZE' => $data['size'], 113 'PWG_TOKEN' => get_pwg_token(), 152 'PWG_TOKEN' => get_pwg_token(), 114 153 ) 115 154 );
Note: See TracChangeset
for help on using the changeset viewer.