| 8 | | // Try to open the directory |
| 9 | | if($dir = opendir($directory)) { |
| 10 | | // Create an array for all files found |
| 11 | | $tmp = Array(); |
| 12 | | |
| 13 | | // Add the files |
| 14 | | while($file = readdir($dir)) { |
| 15 | | // Make sure the file exists |
| 16 | | if($file != "." && $file != ".." && $file[0] != '.') { |
| 17 | | // If it's a directiry, list all files within it |
| 18 | | if(is_dir($directory . "/" . $file)) { |
| 19 | | $tmp2 = get_files($directory . "/" . $file); |
| 20 | | if(is_array($tmp2)) { |
| 21 | | $tmp = array_merge($tmp, $tmp2); |
| 22 | | } |
| 23 | | } else if (is_readable($directory . "/" . $file)) { |
| 24 | | $filename = basename(stripslashes($file)); |
| 25 | | $pi = pathinfo($file); |
| 26 | | if (is_allowed_extension($pi["extension"])) { |
| 27 | | array_push($tmp, $directory . "/" . $file); |
| 28 | | } |
| 29 | | } |
| 30 | | } |
| 31 | | } |
| 32 | | // Finish off the function |
| 33 | | closedir($dir); |
| 34 | | return $tmp; |
| | 8 | // Try to open the directory |
| | 9 | if($dir = opendir($directory)) { |
| | 10 | // Create an array for all files found |
| | 11 | $tmp = Array(); |
| | 12 | // Add the files |
| | 13 | while($file = readdir($dir)) { |
| | 14 | // Make sure the file exists |
| | 15 | if($file != "." && $file != ".." && $file[0] != '.') { |
| | 16 | // If it's a directiry, list all files within it |
| | 17 | if(is_dir($directory . "/" . $file)) { |
| | 18 | $tmp2 = get_files($directory . "/" . $file); |
| | 19 | if(is_array($tmp2)) { |
| | 20 | $tmp = array_merge($tmp, $tmp2); |
| | 21 | } |
| | 22 | } else if (is_readable($directory . "/" . $file)) { |
| | 23 | $filename = basename(stripslashes($file)); |
| | 24 | $pi = pathinfo($file); |
| | 25 | if (is_allowed_extension($pi["extension"])) { |
| | 26 | array_push($tmp, $directory . "/" . $file); |
| | 27 | } |
| | 28 | } |
| | 29 | } |
| | 30 | } |
| | 31 | // Finish off the function |
| | 32 | closedir($dir); |
| | 33 | return $tmp; |
| 39 | | global $TABLE_PREFIX; |
| 40 | | global $config; |
| 41 | | |
| 42 | | |
| 43 | | $filename_parts = explode(".",strrev($filename),2); |
| 44 | | $filename_base = strrev($filename_parts[1]); |
| 45 | | $filename_ext = strrev($filename_parts[0]); |
| 46 | | |
| 47 | | $result = array( |
| 48 | | 'output' => '', |
| 49 | | 'picture_id' => false, |
| 50 | | ); |
| 51 | | |
| 52 | | $i = 0; |
| 53 | | |
| 54 | | $unique_filename_base = strtolower(sanitize_filename($filename_base)); |
| 55 | | |
| 56 | | // now get the name of the collection |
| 57 | | |
| 58 | | $sql = "SELECT c.path AS collection_path, c.id AS collection_id, |
| 59 | | a.path AS album_path, a.id AS album_id |
| 60 | | FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c |
| 61 | | WHERE c.id = a.parent_id AND a.id = '$album_id'"; |
| 62 | | |
| 63 | | $sql_result = run_query($sql); |
| 64 | | $albumdata = mysql_fetch_assoc($sql_result); |
| 65 | | |
| 66 | | // this shouldn't happen in normal cases |
| 67 | | if (empty($albumdata)) { |
| 68 | | $result['errors'] .= 'No such album!'; |
| 69 | | return $result; |
| 70 | | } |
| 71 | | |
| 72 | | $dest_album_name = SmartStripSlashes($albumdata["album_path"]); |
| 73 | | $dest_collection_name = SmartStripSlashes($albumdata["collection_path"]); |
| 74 | | |
| 75 | | $create_path = $dest_collection_name."/".$dest_album_name; |
| 76 | | |
| 77 | | while (is_file('images/'.$create_path."/".$unique_filename_base . "." . $filename_ext)){ |
| 78 | | $unique_filename_base = $filename_base . " (" . ++$i .")"; |
| 79 | | } |
| 80 | | |
| 81 | | $final_filename = $unique_filename_base . "." . $filename_ext; |
| 82 | | |
| 83 | | // final fully qualified file name |
| 84 | | $final_fqfn = $config["basedir"].'images/'.$create_path.'/'.$final_filename; |
| 85 | | |
| 86 | | if (!makeDirs($config['basedir'].'images/'.$create_path, 0777)) { |
| 87 | | $result['errors'] .= 'Could not create directory '.$create_path.'!'; |
| 88 | | return $result; |
| 89 | | }; |
| 90 | | |
| 91 | | // cannot use move_uploaded_file here, because plog-import uses the same function and |
| 92 | | // and doesn't deal with uploaded files |
| 93 | | //if (!move_uploaded_file($tmpname,$final_fqfn)) { |
| 94 | | |
| 95 | | if (is_uploaded_file($tmpname)) { |
| 96 | | if (!move_uploaded_file($tmpname,$final_fqfn)) { |
| 97 | | $result['errors'] .= 'Could not move uploaded file! ' . $tmpname .' to '.$final_fqfn; |
| 98 | | return $result; |
| 99 | | } |
| 100 | | } |
| 101 | | else |
| 102 | | if (!rename($tmpname,$final_fqfn)) { |
| 103 | | $result['errors'] .= 'Could not move file! ' . $tmpname .' to '.$final_fqfn; |
| 104 | | return $result; |
| 105 | | }; |
| 106 | | |
| 107 | | @unlink($tmpname); |
| 108 | | $res = chmod($final_fqfn, 0755); |
| 109 | | |
| 110 | | // Get the EXIF data. |
| 111 | | $exif_raw = read_exif_data_raw($final_fqfn); |
| 112 | | $exif = array(); |
| 113 | | |
| 114 | | $exif["date_taken"] = (isset($exif_raw["IFD0"]["DateTime"])) ? trim($exif_raw["IFD0"]["DateTime"]) : ''; |
| 115 | | $exif["camera"] = (isset($exif_raw["IFD0"]["Make"]) && isset($exif_raw["IFD0"]["Model"])) ? trim($exif_raw["IFD0"]["Make"]) . " " . trim($exif_raw["IFD0"]["Model"]) : ''; |
| 116 | | $exif["shutter_speed"] = (isset($exif_raw["SubIFD"]["ExposureTime"])) ? $exif_raw["SubIFD"]["ExposureTime"] : ''; |
| 117 | | $exif["focal_length"] = (isset($exif_raw["SubIFD"]["FocalLength"])) ? $exif_raw["SubIFD"]["FocalLength"] : ''; |
| 118 | | $exif["flash"] = (isset($exif_raw["SubIFD"]["Flash"])) ? $exif_raw["SubIFD"]["Flash"] : ''; |
| 119 | | $exif["aperture"] = (isset($exif_raw["SubIFD"]["FNumber"])) ? $exif_raw["SubIFD"]["FNumber"] : ''; |
| 120 | | |
| 121 | | $picture_path = $create_path . "/" . $final_filename; |
| 122 | | |
| 123 | | $query = "INSERT INTO `".$TABLE_PREFIX."pictures` |
| 124 | | (`parent_collection`, |
| 125 | | `parent_album`, |
| 126 | | `path`, |
| 127 | | `date_modified`, |
| 128 | | `date_submitted`, |
| 129 | | `allow_comments`, |
| 130 | | `EXIF_date_taken`, |
| 131 | | `EXIF_camera`, |
| 132 | | `EXIF_shutterspeed`, |
| 133 | | `EXIF_focallength`, |
| 134 | | `EXIF_flash`, |
| 135 | | `EXIF_aperture`, |
| 136 | | `caption`, |
| 137 | | `description`) |
| 138 | | VALUES |
| 139 | | ('".$albumdata['collection_id']."', |
| 140 | | '".$albumdata['album_id']."','".mysql_escape_string($picture_path)."', |
| | 38 | global $TABLE_PREFIX; |
| | 39 | global $config; |
| | 40 | |
| | 41 | $filename_parts = explode(".",strrev($filename),2); |
| | 42 | $filename_base = strrev($filename_parts[1]); |
| | 43 | $filename_ext = strrev($filename_parts[0]); |
| | 44 | |
| | 45 | $result = array( |
| | 46 | 'output' => '', |
| | 47 | 'picture_id' => false, |
| | 48 | ); |
| | 49 | |
| | 50 | $i = 0; |
| | 51 | |
| | 52 | $unique_filename_base = strtolower(sanitize_filename($filename_base)); |
| | 53 | |
| | 54 | // now get the name of the collection |
| | 55 | |
| | 56 | $sql = "SELECT c.path AS collection_path, c.id AS collection_id, |
| | 57 | a.path AS album_path, a.id AS album_id |
| | 58 | FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c |
| | 59 | WHERE c.id = a.parent_id AND a.id = '$album_id'"; |
| | 60 | |
| | 61 | $sql_result = run_query($sql); |
| | 62 | $albumdata = mysql_fetch_assoc($sql_result); |
| | 63 | |
| | 64 | // this shouldn't happen in normal cases |
| | 65 | if (empty($albumdata)) { |
| | 66 | $result['errors'] .= 'No such album!'; |
| | 67 | return $result; |
| | 68 | } |
| | 69 | |
| | 70 | $dest_album_name = SmartStripSlashes($albumdata["album_path"]); |
| | 71 | $dest_collection_name = SmartStripSlashes($albumdata["collection_path"]); |
| | 72 | |
| | 73 | $create_path = $dest_collection_name."/".$dest_album_name; |
| | 74 | |
| | 75 | while (is_file('images/'.$create_path."/".$unique_filename_base . "." . $filename_ext)){ |
| | 76 | $unique_filename_base = $filename_base . " (" . ++$i .")"; |
| | 77 | } |
| | 78 | |
| | 79 | $final_filename = $unique_filename_base . "." . $filename_ext; |
| | 80 | |
| | 81 | // final fully qualified file name |
| | 82 | $final_fqfn = $config["basedir"].'images/'.$create_path.'/'.$final_filename; |
| | 83 | |
| | 84 | if (!makeDirs($config['basedir'].'images/'.$create_path, 0777)) { |
| | 85 | $result['errors'] .= 'Could not create directory '.$create_path.'!'; |
| | 86 | return $result; |
| | 87 | }; |
| | 88 | |
| | 89 | // cannot use move_uploaded_file here, because plog-import uses the same function and |
| | 90 | // and doesn't deal with uploaded files |
| | 91 | //if (!move_uploaded_file($tmpname,$final_fqfn)) { |
| | 92 | |
| | 93 | if (is_uploaded_file($tmpname)) { |
| | 94 | if (!move_uploaded_file($tmpname,$final_fqfn)) { |
| | 95 | $result['errors'] .= 'Could not move uploaded file! ' . $tmpname .' to '.$final_fqfn; |
| | 96 | return $result; |
| | 97 | } |
| | 98 | } |
| | 99 | else |
| | 100 | if (!rename($tmpname,$final_fqfn)) { |
| | 101 | $result['errors'] .= 'Could not move file! ' . $tmpname .' to '.$final_fqfn; |
| | 102 | return $result; |
| | 103 | }; |
| | 104 | |
| | 105 | @unlink($tmpname); |
| | 106 | $res = chmod($final_fqfn, 0755); |
| | 107 | |
| | 108 | // Get the EXIF data. |
| | 109 | $exif_raw = read_exif_data_raw($final_fqfn,false); |
| | 110 | $exif = array(); |
| | 111 | |
| | 112 | $exif["date_taken"] = (isset($exif_raw["IFD0"]["DateTime"])) ? trim($exif_raw["IFD0"]["DateTime"]) : ''; |
| | 113 | $exif["camera"] = (isset($exif_raw["IFD0"]["Make"]) && isset($exif_raw["IFD0"]["Model"])) ? trim($exif_raw["IFD0"]["Make"]) . " " . trim($exif_raw["IFD0"]["Model"]) : ''; |
| | 114 | $exif["shutter_speed"] = (isset($exif_raw["SubIFD"]["ExposureTime"])) ? $exif_raw["SubIFD"]["ExposureTime"] : ''; |
| | 115 | $exif["focal_length"] = (isset($exif_raw["SubIFD"]["FocalLength"])) ? $exif_raw["SubIFD"]["FocalLength"] : ''; |
| | 116 | $exif["flash"] = (isset($exif_raw["SubIFD"]["Flash"])) ? $exif_raw["SubIFD"]["Flash"] : ''; |
| | 117 | $exif["aperture"] = (isset($exif_raw["SubIFD"]["FNumber"])) ? $exif_raw["SubIFD"]["FNumber"] : ''; |
| | 118 | |
| | 119 | $picture_path = $create_path . "/" . $final_filename; |
| | 120 | |
| | 121 | $result = insert_picture($albumdata['collection_id'],$albumdata['album_id'],$picture_path,$exif,$caption,$desc,$filename); |
| | 122 | |
| | 123 | // let's generate the thumbnail and the large thumbnail right away. |
| | 124 | // this way, the user won't see any latency from the thumbnail generation |
| | 125 | // when viewing the gallery for the first time |
| | 126 | // this also helps with the image pre-loading problem introduced |
| | 127 | // by a javascript slideshow. |
| | 128 | |
| | 129 | $thumbpath = generate_thumb($picture_path, $result['picture_id'],THUMB_SMALL); |
| | 130 | #$thumbpath = generate_thumb($picture_path, $result['picture_id'],THUMB_LARGE); |
| | 131 | |
| | 132 | return $result; |
| | 133 | }; |
| | 134 | |
| | 135 | function insert_picture($collection_id,$album_id,$picture_path,$exif,$caption,$desc,$filename) { |
| | 136 | global $TABLE_PREFIX; |
| | 137 | |
| | 138 | $query = "INSERT INTO `".$TABLE_PREFIX."pictures` |
| | 139 | (`parent_collection`, |
| | 140 | `parent_album`, |
| | 141 | `path`, |
| | 142 | `date_modified`, |
| | 143 | `date_submitted`, |
| | 144 | `allow_comments`, |
| | 145 | `EXIF_date_taken`, |
| | 146 | `EXIF_camera`, |
| | 147 | `EXIF_shutterspeed`, |
| | 148 | `EXIF_focallength`, |
| | 149 | `EXIF_flash`, |
| | 150 | `EXIF_aperture`, |
| | 151 | `caption`, |
| | 152 | `description`) |
| | 153 | VALUES |
| | 154 | ('".$collection_id."', |
| | 155 | '".$album_id."','".mysql_escape_string($picture_path)."', |
| 152 | | |
| 153 | | $sql_result = run_query($query); |
| 154 | | |
| 155 | | $result['output'] .= 'Your photo ('.$filename.') was uploaded successfully.'; |
| 156 | | $result['picture_id'] = mysql_insert_id(); |
| 157 | | |
| 158 | | // let's generate the thumbnail and the large thumbnail right away. |
| 159 | | // this way, the user won't see any latency from the thumbnail generation |
| 160 | | // when viewing the gallery for the first time |
| 161 | | // this also helps with the image pre-loading problem introduced |
| 162 | | // by a javascript slideshow. |
| 163 | | |
| 164 | | $thumbpath = generate_thumb($picture_path, $result['picture_id'],THUMB_SMALL); |
| 165 | | #$thumbpath = generate_thumb($picture_path, $result['picture_id'],THUMB_LARGE); |
| 166 | | |
| 167 | | return $result; |
| | 167 | |
| | 168 | $sql_result = run_query($query); |
| | 169 | |
| | 170 | $result['output'] .= 'Your photo ('.$filename.') was uploaded successfully.'; |
| | 171 | $result['picture_id'] = mysql_insert_id(); |
| | 172 | return $result; |
| | 173 | } |
| | 174 | |
| | 175 | function update_picture($id,$caption,$allow_comments,$description) { |
| | 176 | global $TABLE_PREFIX; |
| | 177 | $id = intval($id); |
| | 178 | $caption = mysql_real_escape_string($caption); |
| | 179 | $description = mysql_real_escape_string($description); |
| | 180 | $allow_comments = intval($allow_comments); |
| | 181 | $query = "UPDATE ".$TABLE_PREFIX."pictures SET |
| | 182 | caption = '$caption', |
| | 183 | description = '$description', |
| | 184 | allow_comments = '$allow_comments' |
| | 185 | WHERE id='$id'"; |
| | 186 | $result = mysql_query($query); |
| | 187 | if ($result) |
| | 188 | return array('output' => 'You have successfully modified the selected picture.'); |
| | 189 | else |
| | 190 | return array('errors' => mysql_error()); |
| | 191 | } |
| | 192 | |
| | 193 | function move_picture($pic_id,$to_album) { |
| | 194 | global $TABLE_PREFIX; |
| | 195 | global $config; |
| | 196 | // we need the parent_id from the album we're changing to |
| | 197 | $to_album = intval($to_album); |
| | 198 | $pic_id = intval($pic_id); |
| | 199 | |
| | 200 | $query = "SELECT * FROM ".$TABLE_PREFIX."albums WHERE `id` = '$to_album'"; |
| | 201 | $result = run_query($query); |
| | 202 | $row = mysql_fetch_assoc($result); |
| | 203 | |
| | 204 | if (!is_array($row)) { |
| | 205 | return array('errors' => 'There is no album with id ' . $to_album); |
| | 206 | }; |
| | 207 | |
| | 208 | $new_collection = $row['parent_id']; |
| | 209 | |
| | 210 | // move picture to new location |
| | 211 | // we need to query to get collection names and album names to find new directory path |
| | 212 | |
| | 213 | $picture = get_picture_by_id($pic_id); |
| | 214 | $album = get_album_by_id($to_album); |
| | 215 | |
| | 216 | $filename = SmartStripSlashes(basename($picture['path'])); |
| | 217 | $directory = SmartStripSlashes($album['collection_path'])."/".SmartStripSlashes($album['album_path'])."/"; |
| | 218 | $new_path = $directory.$filename; |
| | 219 | |
| | 220 | if (!rename($config['basedir']."images/".SmartStripSlashes($picture['path']), $config['basedir']."images/".$new_path)) { |
| | 221 | return array('errors' => "Error moving file! ($picture[path] to $new_path)"); |
| | 222 | }; |
| | 223 | |
| | 224 | $new_path = mysql_real_escape_string($new_path); |
| | 225 | |
| | 226 | // update database |
| | 227 | $sql = "UPDATE ".$TABLE_PREFIX."pictures SET |
| | 228 | path = '$new_path', |
| | 229 | parent_album = '$to_album', |
| | 230 | parent_collection = '$new_collection' |
| | 231 | WHERE id = '$pic_id'"; |
| | 232 | if (!mysql_query($sql)) { |
| | 233 | return array('errors' => mysql_error()); |
| | 234 | }; |
| | 235 | return array('output' => 'Success'); |
| | 236 | } |
| | 237 | |
| | 238 | function delete_picture($del_id) { |
| | 239 | global $TABLE_PREFIX; |
| | 240 | global $config; |
| | 241 | $del_id = intval($del_id); |
| | 242 | global $thumbnail_config; |
| | 243 | $picture = get_picture_by_id($del_id); |
| | 244 | if ($picture) { |
| | 245 | $query = "DELETE FROM ".$TABLE_PREFIX."pictures WHERE `id`= '" . $picture['id'] . "'"; |
| | 246 | run_query($query); |
| | 247 | |
| | 248 | // delete all comments for the picture |
| | 249 | $query = "DELETE FROM ".$TABLE_PREFIX."comments WHERE `parent_id`= '" . $picture['id'] . "'"; |
| | 250 | run_query($query); |
| | 251 | |
| | 252 | // make sure that the file is actually located inside our images directory |
| | 253 | $full_path = realpath($config['basedir'] . 'images/' . $picture['path']); |
| | 254 | // also check whether this image is in the correct folder |
| | 255 | $relative_path = substr($full_path,0,strlen($config['basedir'])); |
| | 256 | $basename = basename($picture['path']); |
| | 257 | if ($relative_path == $config['basedir']) { |
| | 258 | foreach($thumbnail_config as $tkey => $tval) { |
| | 259 | $thumbpath = $config['basedir'].'thumbs/'.$tval['filename_prefix'].$picture['id'].'-'.$basename; |
| | 260 | if (file_exists($thumbpath) && is_writable($thumbpath)) { |
| | 261 | //print "deleting $thumbpath<br/>"; |
| | 262 | @chmod($thumbpath, 0777); |
| | 263 | unlink($thumbpath); |
| | 264 | }; |
| | 265 | }; |
| | 266 | if (is_file($full_path)) { |
| | 267 | // print "deleting $full_path<br/>"; |
| | 268 | @chmod($full_path, 0777); |
| | 269 | |
| | 270 | if (!unlink($full_path)) |
| | 271 | return array('errors' => 'Could not physically delete file from disk!'); |
| | 272 | }; |
| | 273 | } else { |
| | 274 | return array('errors' => 'Picture has invalid path, ignoring delete request'); |
| | 275 | }; |
| | 276 | } else { |
| | 277 | return array('errors' => 'There is no picture with id ' . $del_id); |
| | 278 | }; |
| 170 | | function update_picture($id,$caption,$allow_comments,$description) { |
| 171 | | global $TABLE_PREFIX; |
| 172 | | $id = intval($id); |
| 173 | | $caption = mysql_real_escape_string($caption); |
| 174 | | $description = mysql_real_escape_string($description); |
| 175 | | $allow_comments = intval($allow_comments); |
| 176 | | $query = "UPDATE ".$TABLE_PREFIX."pictures SET |
| 177 | | caption = '$caption', |
| 178 | | description = '$description', |
| 179 | | allow_comments = '$allow_comments' |
| 180 | | WHERE id='$id'"; |
| 181 | | $result = mysql_query($query); |
| 182 | | if ($result) |
| 183 | | return array('output' => 'You have successfully modified the selected picture.'); |
| 184 | | else |
| 185 | | return array('errors' => mysql_error()); |
| 186 | | } |
| 187 | | |
| 188 | | function move_picture($pic_id,$to_album) { |
| 189 | | global $TABLE_PREFIX; |
| 190 | | global $config; |
| 191 | | // we need the parent_id from the album we're changing to |
| 192 | | $to_album = intval($to_album); |
| 193 | | $pic_id = intval($pic_id); |
| 194 | | |
| 195 | | $query = "SELECT * FROM ".$TABLE_PREFIX."albums WHERE `id` = '$to_album'"; |
| 196 | | $result = run_query($query); |
| 197 | | $row = mysql_fetch_assoc($result); |
| 198 | | |
| 199 | | if (!is_array($row)) { |
| 200 | | return array('errors' => 'There is no album with id ' . $to_album); |
| 201 | | }; |
| 202 | | |
| 203 | | $new_collection = $row['parent_id']; |
| 204 | | |
| 205 | | |
| 206 | | // move picture to new location |
| 207 | | // we need to query to get collection names and album names to find new directory path |
| 208 | | |
| 209 | | $picture = get_picture_by_id($pic_id); |
| 210 | | $album = get_album_by_id($to_album); |
| 211 | | |
| 212 | | $filename = SmartStripSlashes(basename($picture['path'])); |
| 213 | | $directory = SmartStripSlashes($album['collection_path'])."/".SmartStripSlashes($album['album_path'])."/"; |
| 214 | | $new_path = $directory.$filename; |
| 215 | | |
| 216 | | if (!rename($config['basedir']."images/".SmartStripSlashes($picture['path']), $config['basedir']."images/".$new_path)) { |
| 217 | | return array('errors' => "Error moving file! ($picture[path] to $new_path)"); |
| 218 | | }; |
| 219 | | |
| 220 | | $new_path = mysql_real_escape_string($new_path); |
| 221 | | |
| 222 | | // update database |
| 223 | | $sql = "UPDATE ".$TABLE_PREFIX."pictures SET |
| 224 | | path = '$new_path', |
| 225 | | parent_album = '$to_album', |
| 226 | | parent_collection = '$new_collection' |
| 227 | | WHERE id = '$pic_id'"; |
| 228 | | if (!mysql_query($sql)) { |
| 229 | | return array('errors' => mysql_error()); |
| 230 | | }; |
| 231 | | return array('output' => 'Success'); |
| 232 | | } |
| 233 | | |
| 234 | | function delete_picture($del_id) { |
| 235 | | global $TABLE_PREFIX; |
| 236 | | global $config; |
| 237 | | $del_id = intval($del_id); |
| 238 | | global $thumbnail_config; |
| 239 | | $picture = get_picture_by_id($del_id); |
| 240 | | if ($picture) { |
| 241 | | |
| 242 | | $query = "DELETE FROM ".$TABLE_PREFIX."pictures WHERE `id`= '" . $picture['id'] . "'"; |
| 243 | | run_query($query); |
| 244 | | |
| 245 | | // delete all comments for the picture |
| 246 | | $query = "DELETE FROM ".$TABLE_PREFIX."comments WHERE `parent_id`= '" . $picture['id'] . "'"; |
| 247 | | run_query($query); |
| 248 | | |
| 249 | | // make sure that the file is actually located inside our images directory |
| 250 | | $full_path = realpath($config['basedir'] . 'images/' . $picture['path']); |
| 251 | | // also check whether this image is in the correct folder |
| 252 | | $relative_path = substr($full_path,0,strlen($config['basedir'])); |
| 253 | | $basename = basename($picture['path']); |
| 254 | | if ($relative_path == $config['basedir']) { |
| 255 | | foreach($thumbnail_config as $tkey => $tval) { |
| 256 | | $thumbpath = $config['basedir'].'thumbs/'.$tval['filename_prefix'].$picture['id'].'-'.$basename; |
| 257 | | if (file_exists($thumbpath) && is_writable($thumbpath)) { |
| 258 | | //print "deleting $thumbpath<br/>"; |
| 259 | | @chmod($thumbpath, 0777); |
| 260 | | unlink($thumbpath); |
| 261 | | }; |
| 262 | | }; |
| 263 | | if (is_file($full_path)) { |
| 264 | | // print "deleting $full_path<br/>"; |
| 265 | | @chmod($full_path, 0777); |
| 266 | | |
| 267 | | if (!unlink($full_path)) |
| 268 | | return array('errors' => 'Could not physically delete file from disk!'); |
| 269 | | }; |
| 270 | | } else { |
| 271 | | return array('errors' => 'Picture has invalid path, ignoring delete request'); |
| 272 | | }; |
| 273 | | } else { |
| 274 | | return array('errors' => 'There is no picture with id ' . $del_id); |
| 275 | | }; |
| 276 | | }; |
| 277 | | |
| 279 | | global $config; |
| 280 | | global $TABLE_PREFIX; |
| 281 | | $output = $errors = ""; |
| 282 | | $id = 0; |
| 283 | | $collection_name = trim(SmartStripSlashes($collection_name)); |
| 284 | | if (empty($collection_name)) { |
| 285 | | return array("errors" => "Please enter a valid name for the collection"); |
| 286 | | }; |
| 287 | | |
| 288 | | // do not allow collections with duplicate names, otherwise mod_rewritten links will start |
| 289 | | // to behave weird. |
| 290 | | $collection_exists = get_collection_by_name($collection_name); |
| 291 | | if ($collection_exists) { |
| 292 | | return array("errors" => 'New collection could not be created, because there already is one named `'.$collection_exists['name'].'`!'); |
| 293 | | } |
| 294 | | |
| 295 | | $collection_folder = strtolower(sanitize_filename($collection_name)); |
| 296 | | // first try to create the directory, and only if that succeeds, then insert |
| 297 | | // a new row into collections table, otherwise the collection will not be usable |
| 298 | | // anyway |
| 299 | | $create_path = $config["basedir"] . "/images/".$collection_folder; |
| 300 | | |
| 301 | | // create directory |
| 302 | | if (!makeDirs($create_path, 0777)) { |
| 303 | | $errors .= "Could not create directory $create_path!</p>"; |
| 304 | | } else { |
| 305 | | $sql_name = mysql_real_escape_string($collection_name); |
| 306 | | $description = mysql_real_escape_string($description); |
| 307 | | $collection_folder = mysql_real_escape_string($collection_folder); |
| 308 | | $query = "INSERT INTO ".$TABLE_PREFIX."collections (`name`,`description`,`path`) VALUES ('$sql_name', '$description', '$collection_folder')"; |
| 309 | | $result = run_query($query); |
| 310 | | $id = mysql_insert_id(); |
| 311 | | |
| 312 | | $output .= 'You have successfully created the collection <strong>'.$collection_name.'.</strong>'; |
| 313 | | }; |
| 314 | | |
| 315 | | // caller can check the value of id, if it is zero, then collection creation failed |
| 316 | | // errors and output are separate, because this way the caller can format the return value |
| 317 | | // as it needs |
| 318 | | $result = array( |
| 319 | | "output" => $output, |
| 320 | | "errors" => $errors, |
| 321 | | "id" => $id, |
| 322 | | ); |
| 323 | | return $result; |
| | 282 | global $config; |
| | 283 | global $TABLE_PREFIX; |
| | 284 | $output = $errors = ""; |
| | 285 | $id = 0; |
| | 286 | $collection_name = trim(SmartStripSlashes($collection_name)); |
| | 287 | if (empty($collection_name)) { |
| | 288 | return array("errors" => "Please enter a valid name for the collection"); |
| | 289 | }; |
| | 290 | |
| | 291 | // do not allow collections with duplicate names, otherwise mod_rewritten links will start |
| | 292 | // to behave weird. |
| | 293 | $collection_exists = get_collection_by_name($collection_name); |
| | 294 | if ($collection_exists) { |
| | 295 | return array("errors" => 'New collection could not be created, because there already is one named `'.$collection_exists['name'].'`!'); |
| | 296 | } |
| | 297 | |
| | 298 | $collection_folder = strtolower(sanitize_filename($collection_name)); |
| | 299 | // first try to create the directory, and only if that succeeds, then insert |
| | 300 | // a new row into collections table, otherwise the collection will not be usable |
| | 301 | // anyway |
| | 302 | $create_path = $config["basedir"] . "/images/".$collection_folder; |
| | 303 | |
| | 304 | // create directory |
| | 305 | if (!makeDirs($create_path, 0777)) { |
| | 306 | $errors .= "Could not create directory $create_path!</p>"; |
| | 307 | } else { |
| | 308 | $sql_name = mysql_real_escape_string($collection_name); |
| | 309 | $description = mysql_real_escape_string($description); |
| | 310 | $collection_folder = mysql_real_escape_string($collection_folder); |
| | 311 | $query = "INSERT INTO ".$TABLE_PREFIX."collections (`name`,`description`,`path`) VALUES ('$sql_name', '$description', '$collection_folder')"; |
| | 312 | $result = run_query($query); |
| | 313 | $id = mysql_insert_id(); |
| | 314 | |
| | 315 | $output .= 'You have successfully created the collection <strong>'.$collection_name.'.</strong>'; |
| | 316 | }; |
| | 317 | |
| | 318 | // caller can check the value of id, if it is zero, then collection creation failed |
| | 319 | // errors and output are separate, because this way the caller can format the return value |
| | 320 | // as it needs |
| | 321 | $result = array( |
| | 322 | "output" => $output, |
| | 323 | "errors" => $errors, |
| | 324 | "id" => $id, |
| | 325 | ); |
| | 326 | return $result; |