[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 | |
---|
[15970] | 40 | $query_model = 'SELECT * |
---|
[13652] | 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'], |
---|
[18124] | 106 | 'show_thumbnail_caption' => !empty($_POST['show_thumbnail_caption']), |
---|
[12678] | 107 | ); |
---|
| 108 | |
---|
| 109 | if (!is_numeric($params['height'])) |
---|
| 110 | { |
---|
| 111 | array_push($page['errors'], 'Thumbnails max height must be an integer.'); |
---|
| 112 | } |
---|
| 113 | if (!is_numeric($params['margin'])) |
---|
| 114 | { |
---|
| 115 | array_push($page['errors'], 'Margin between thumbnails must be an integer.'); |
---|
| 116 | } |
---|
| 117 | if (!is_numeric($params['nb_image_page'])) |
---|
| 118 | { |
---|
| 119 | array_push($page['errors'], 'Number of photos per page must be an integer.'); |
---|
| 120 | } |
---|
| 121 | |
---|
[12758] | 122 | if ($params['height'] != $conf['GThumb']['height']) |
---|
| 123 | { |
---|
[13652] | 124 | delete_gthumb_cache($conf['GThumb']['height']); |
---|
[12758] | 125 | } |
---|
| 126 | elseif ($params['margin'] != $conf['GThumb']['margin']) |
---|
| 127 | { |
---|
[13652] | 128 | delete_gthumb_cache($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']); |
---|
[12758] | 129 | } |
---|
| 130 | |
---|
[12678] | 131 | if (empty($page['errors'])) |
---|
| 132 | { |
---|
| 133 | $query = ' |
---|
| 134 | UPDATE ' . CONFIG_TABLE . ' |
---|
| 135 | SET value="' . addslashes(serialize($params)) . '" |
---|
| 136 | WHERE param="GThumb" |
---|
| 137 | LIMIT 1'; |
---|
| 138 | pwg_query($query); |
---|
| 139 | |
---|
| 140 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | // Configuration du template |
---|
| 145 | $template->assign( |
---|
| 146 | array( |
---|
| 147 | 'HEIGHT' => $params['height'], |
---|
| 148 | 'MARGIN' => $params['margin'], |
---|
| 149 | 'NB_IMAGE_PAGE' => $params['nb_image_page'], |
---|
| 150 | 'BIG_THUMB' => $params['big_thumb'], |
---|
| 151 | 'CACHE_BIG_THUMB' => $params['cache_big_thumb'], |
---|
| 152 | 'METHOD' => $params['method'], |
---|
[18124] | 153 | 'SHOW_THUMBNAIL_CAPTION' => $params['show_thumbnail_caption'], |
---|
[13652] | 154 | 'PWG_TOKEN' => get_pwg_token(), |
---|
[12678] | 155 | ) |
---|
| 156 | ); |
---|
| 157 | |
---|
| 158 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl')); |
---|
| 159 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 160 | |
---|
| 161 | ?> |
---|