[12678] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 4 | |
---|
[13652] | 5 | function delete_gthumb_cache($height) |
---|
[12691] | 6 | { |
---|
[13652] | 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 | } |
---|
[12691] | 21 | } |
---|
| 22 | |
---|
[13652] | 23 | if (isset($_GET['getMissingDerivative'])) |
---|
[12733] | 24 | { |
---|
[13652] | 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) |
---|
[12733] | 29 | { |
---|
[13652] | 30 | $start_id = $max_id; |
---|
[12733] | 31 | } |
---|
[13652] | 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 |
---|
[12733] | 48 | { |
---|
[13652] | 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)) |
---|
[12733] | 52 | { |
---|
[13652] | 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) |
---|
[12733] | 59 | { |
---|
[13652] | 60 | $urls[] = $derivative->get_url().$uid; |
---|
[12733] | 61 | } |
---|
[13652] | 62 | if (count($urls)>=$max_urls && !$is_last) |
---|
| 63 | break; |
---|
[12733] | 64 | } |
---|
[13652] | 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; |
---|
[12733] | 75 | } |
---|
[13652] | 76 | $ret['urls']=$urls; |
---|
| 77 | echo json_encode($ret); |
---|
| 78 | exit(); |
---|
[12733] | 79 | } |
---|
| 80 | |
---|
[13652] | 81 | global $template, $conf, $page; |
---|
| 82 | |
---|
| 83 | load_language('plugin.lang', GTHUMB_PATH); |
---|
| 84 | include(dirname(__FILE__).'/config_default.inc.php'); |
---|
| 85 | $params = $conf['GThumb']; |
---|
| 86 | |
---|
| 87 | // Delete cache |
---|
| 88 | if (isset($_POST['cachedelete'])) |
---|
| 89 | { |
---|
| 90 | check_pwg_token(); |
---|
| 91 | delete_gthumb_cache($conf['GThumb']['height']); |
---|
| 92 | delete_gthumb_cache($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']); |
---|
| 93 | redirect('admin.php?page=plugin-GThumb'); |
---|
| 94 | } |
---|
| 95 | |
---|
[12678] | 96 | // Save configuration |
---|
| 97 | if (isset($_POST['submit'])) |
---|
| 98 | { |
---|
| 99 | $params = array( |
---|
| 100 | 'height' => $_POST['height'], |
---|
| 101 | 'margin' => $_POST['margin'], |
---|
| 102 | 'nb_image_page' => $_POST['nb_image_page'], |
---|
| 103 | 'big_thumb' => !empty($_POST['big_thumb']), |
---|
| 104 | 'cache_big_thumb' => !empty($_POST['cache_big_thumb']), |
---|
| 105 | 'method' => $_POST['method'], |
---|
| 106 | ); |
---|
| 107 | |
---|
| 108 | if (!is_numeric($params['height'])) |
---|
| 109 | { |
---|
| 110 | array_push($page['errors'], 'Thumbnails max height must be an integer.'); |
---|
| 111 | } |
---|
| 112 | if (!is_numeric($params['margin'])) |
---|
| 113 | { |
---|
| 114 | array_push($page['errors'], 'Margin between thumbnails must be an integer.'); |
---|
| 115 | } |
---|
| 116 | if (!is_numeric($params['nb_image_page'])) |
---|
| 117 | { |
---|
| 118 | array_push($page['errors'], 'Number of photos per page must be an integer.'); |
---|
| 119 | } |
---|
| 120 | |
---|
[12758] | 121 | if ($params['height'] != $conf['GThumb']['height']) |
---|
| 122 | { |
---|
[13652] | 123 | delete_gthumb_cache($conf['GThumb']['height']); |
---|
[12758] | 124 | } |
---|
| 125 | elseif ($params['margin'] != $conf['GThumb']['margin']) |
---|
| 126 | { |
---|
[13652] | 127 | delete_gthumb_cache($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']); |
---|
[12758] | 128 | } |
---|
| 129 | |
---|
[12678] | 130 | if (empty($page['errors'])) |
---|
| 131 | { |
---|
| 132 | $query = ' |
---|
| 133 | UPDATE ' . CONFIG_TABLE . ' |
---|
| 134 | SET value="' . addslashes(serialize($params)) . '" |
---|
| 135 | WHERE param="GThumb" |
---|
| 136 | LIMIT 1'; |
---|
| 137 | pwg_query($query); |
---|
| 138 | |
---|
| 139 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | // Configuration du template |
---|
| 144 | $template->assign( |
---|
| 145 | array( |
---|
| 146 | 'HEIGHT' => $params['height'], |
---|
| 147 | 'MARGIN' => $params['margin'], |
---|
| 148 | 'NB_IMAGE_PAGE' => $params['nb_image_page'], |
---|
| 149 | 'BIG_THUMB' => $params['big_thumb'], |
---|
| 150 | 'CACHE_BIG_THUMB' => $params['cache_big_thumb'], |
---|
| 151 | 'METHOD' => $params['method'], |
---|
[13652] | 152 | 'PWG_TOKEN' => get_pwg_token(), |
---|
[12678] | 153 | ) |
---|
| 154 | ); |
---|
| 155 | |
---|
| 156 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl')); |
---|
| 157 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 158 | |
---|
| 159 | ?> |
---|