[12678] | 1 | <?php |
---|
| 2 | |
---|
| 3 | function ws_images_getGThumbPlusThumbnail($params, &$service) |
---|
| 4 | { |
---|
| 5 | global $conf; |
---|
| 6 | |
---|
| 7 | if (empty($params['image_id'])) |
---|
| 8 | { |
---|
| 9 | return new PwgError(403, "image_id is required"); |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); |
---|
| 13 | |
---|
| 14 | $forbidden = get_sql_condition_FandF( |
---|
| 15 | array( |
---|
| 16 | 'forbidden_categories' => 'ic.category_id', |
---|
| 17 | 'visible_categories' => 'ic.category_id', |
---|
| 18 | 'visible_images' => 'i.id' |
---|
| 19 | ), |
---|
| 20 | 'AND' |
---|
| 21 | ); |
---|
| 22 | |
---|
| 23 | $query = 'SELECT i.* |
---|
| 24 | FROM '.IMAGES_TABLE.' AS i |
---|
| 25 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
| 26 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
| 27 | WHERE i.id = '.$params['image_id'].' |
---|
| 28 | '.$forbidden.' |
---|
| 29 | ;'; |
---|
| 30 | |
---|
| 31 | $picture = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 32 | |
---|
| 33 | if (empty($picture)) |
---|
| 34 | { |
---|
| 35 | return new PwgError(404, "image not found"); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | $data = get_gthumb_data($picture, $params['size']); |
---|
| 39 | $result = array(); |
---|
| 40 | |
---|
| 41 | if (empty($data['src'])) |
---|
| 42 | { |
---|
| 43 | $cache_dir = GTHUMB_CACHE_DIR.'/'; |
---|
| 44 | if ($params['size'] == 'small' or $conf['GThumb']['cache_big_thumb']) |
---|
| 45 | { |
---|
| 46 | $cache_dir = $data['cache_path']; |
---|
| 47 | } |
---|
| 48 | $file = $cache_dir.'/'.md5($picture['path']).'.'.$picture['tn_ext']; |
---|
| 49 | |
---|
| 50 | if (!is_dir($cache_dir)) |
---|
| 51 | { |
---|
| 52 | mkgetdir($cache_dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR); |
---|
| 53 | if (!is_writable($cache_dir)) |
---|
| 54 | { |
---|
| 55 | die("Give write access (chmod 777) to $cache_dir directory at the root of your Piwigo installation"); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | $filepath = $picture['path']; |
---|
| 60 | if ($data['use_high']) |
---|
| 61 | { |
---|
| 62 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
---|
| 63 | $filepath = file_path_for_type($filepath, 'high'); |
---|
| 64 | } |
---|
| 65 | $img = new pwg_image($filepath); |
---|
| 66 | $result = $img->pwg_resize($file, $data['width'], $data['height'], $conf['upload_form_thumb_quality'], false, true, ($params['size'] == 'big'), false); |
---|
| 67 | $img->destroy(); |
---|
| 68 | } |
---|
| 69 | else |
---|
| 70 | { |
---|
| 71 | $file = $data['src']; |
---|
| 72 | $result['width'] = $data['width']; |
---|
| 73 | $result['height'] = $data['height']; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | if ($params['return']) |
---|
| 77 | { |
---|
| 78 | switch (get_extension($file)) |
---|
| 79 | { |
---|
| 80 | case 'jpg': |
---|
| 81 | case 'jpeg': |
---|
| 82 | header('Content-type: image/jpeg'); break; |
---|
| 83 | case 'gif': |
---|
| 84 | header('Content-type: image/gif'); break; |
---|
| 85 | case 'png': |
---|
| 86 | header('Content-type: image/png'); break; |
---|
| 87 | default: |
---|
| 88 | header('Content-type: unknow'); break; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | header('Last-Modified: '.date('r', filemtime($file))); |
---|
| 92 | readfile($file); |
---|
| 93 | if (!$conf['GThumb']['cache_big_thumb']) |
---|
| 94 | { |
---|
| 95 | @unlink($file); |
---|
| 96 | } |
---|
| 97 | exit(); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | return array( |
---|
| 101 | 'id' => $picture['id'], |
---|
| 102 | 'src' => $file, |
---|
| 103 | 'width' => $result['width'], |
---|
| 104 | 'height' => $result['height'], |
---|
| 105 | ); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | function gtdeltree($path) |
---|
| 109 | { |
---|
| 110 | if (is_dir($path)) |
---|
| 111 | { |
---|
| 112 | $fh = opendir($path); |
---|
| 113 | while ($file = readdir($fh)) |
---|
| 114 | { |
---|
| 115 | if ($file != '.' and $file != '..') |
---|
| 116 | { |
---|
| 117 | $pathfile = $path . '/' . $file; |
---|
| 118 | if (is_dir($pathfile)) |
---|
| 119 | { |
---|
| 120 | gtdeltree($pathfile); |
---|
| 121 | } |
---|
| 122 | else |
---|
| 123 | { |
---|
| 124 | @unlink($pathfile); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | closedir($fh); |
---|
| 129 | return @rmdir($path); |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
[12691] | 133 | function gtdirsize($path, &$size=0, &$nb_files=0) |
---|
| 134 | { |
---|
| 135 | if (is_dir($path)) |
---|
| 136 | { |
---|
| 137 | $fh = opendir($path); |
---|
| 138 | while ($file = readdir($fh)) |
---|
| 139 | { |
---|
| 140 | if ($file != '.' and $file != '..' and $file != 'index.htm') |
---|
| 141 | { |
---|
| 142 | $pathfile = $path . '/' . $file; |
---|
| 143 | if (is_dir($pathfile)) |
---|
| 144 | { |
---|
| 145 | $data = gtdirsize($pathfile, $size, $nb_files); |
---|
| 146 | } |
---|
| 147 | else |
---|
| 148 | { |
---|
| 149 | $size += filesize($pathfile); |
---|
| 150 | $nb_files++; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | closedir($fh); |
---|
| 155 | } |
---|
| 156 | return array( |
---|
| 157 | 'size' => $size, |
---|
| 158 | 'nb_files' => $nb_files, |
---|
| 159 | ); |
---|
| 160 | } |
---|
| 161 | |
---|
[12678] | 162 | ?> |
---|