| 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; |
| | 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; |
| 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. |
| | 39 | global $TABLE_PREFIX; |
| | 40 | global $config; |
| | 41 | |
| | 42 | $filename_parts = explode(".",strrev($filename),2); |
| | 43 | $filename_base = strrev($filename_parts[1]); |
| | 44 | $filename_ext = strrev($filename_parts[0]); |
| | 45 | |
| | 46 | $result = array( |
| | 47 | 'output' => '', |
| | 48 | 'picture_id' => false, |
| | 49 | ); |
| | 50 | |
| | 51 | $i = 0; |
| | 52 | |
| | 53 | $unique_filename_base = strtolower(sanitize_filename($filename_base)); |
| | 54 | |
| | 55 | // now get the name of the collection |
| | 56 | |
| | 57 | $sql = "SELECT c.path AS collection_path, c.id AS collection_id, |
| | 58 | a.path AS album_path, a.id AS album_id |
| | 59 | FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c |
| | 60 | WHERE c.id = a.parent_id AND a.id = '$album_id'"; |
| | 61 | |
| | 62 | $sql_result = run_query($sql); |
| | 63 | $albumdata = mysql_fetch_assoc($sql_result); |
| | 64 | |
| | 65 | // this shouldn't happen in normal cases |
| | 66 | if (empty($albumdata)) { |
| | 67 | $result['errors'] .= 'No such album!'; |
| | 68 | return $result; |
| | 69 | } |
| | 70 | |
| | 71 | $dest_album_name = SmartStripSlashes($albumdata["album_path"]); |
| | 72 | $dest_collection_name = SmartStripSlashes($albumdata["collection_path"]); |
| | 73 | |
| | 74 | $create_path = $dest_collection_name."/".$dest_album_name; |
| | 75 | |
| | 76 | while (is_file('images/'.$create_path."/".$unique_filename_base . "." . $filename_ext)){ |
| | 77 | $unique_filename_base = $filename_base . " (" . ++$i .")"; |
| | 78 | } |
| | 79 | |
| | 80 | $final_filename = $unique_filename_base . "." . $filename_ext; |
| | 81 | |
| | 82 | // final fully qualified file name |
| | 83 | $final_fqfn = $config["basedir"].'images/'.$create_path.'/'.$final_filename; |
| | 84 | |
| | 85 | if (!makeDirs($config['basedir'].'images/'.$create_path, 0777)) { |
| | 86 | $result['errors'] .= 'Could not create directory '.$create_path.'!'; |
| | 87 | return $result; |
| | 88 | }; |
| | 89 | |
| | 90 | // cannot use move_uploaded_file here, because plog-import uses the same function and |
| | 91 | // and doesn't deal with uploaded files |
| | 92 | //if (!move_uploaded_file($tmpname,$final_fqfn)) { |
| | 93 | |
| | 94 | if (is_uploaded_file($tmpname)) { |
| | 95 | if (!move_uploaded_file($tmpname,$final_fqfn)) { |
| | 96 | $result['errors'] .= 'Could not move uploaded file! ' . $tmpname .' to '.$final_fqfn; |
| | 97 | return $result; |
| | 98 | } |
| | 99 | } |
| | 100 | else |
| | 101 | if (!rename($tmpname,$final_fqfn)) { |
| | 102 | $result['errors'] .= 'Could not move file! ' . $tmpname .' to '.$final_fqfn; |
| | 103 | return $result; |
| | 104 | }; |
| | 105 | |
| | 106 | @unlink($tmpname); |
| | 107 | $res = chmod($final_fqfn, 0755); |
| | 108 | |
| | 109 | // Get the EXIF data. |
| 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; |
| | 111 | $exif = array(); |
| | 112 | |
| | 113 | $exif["date_taken"] = (isset($exif_raw["IFD0"]["DateTime"])) ? trim($exif_raw["IFD0"]["DateTime"]) : ''; |
| | 114 | $exif["camera"] = (isset($exif_raw["IFD0"]["Make"]) && isset($exif_raw["IFD0"]["Model"])) ? trim($exif_raw["IFD0"]["Make"]) . " " . trim($exif_raw["IFD0"]["Model"]) : ''; |
| | 115 | $exif["shutter_speed"] = (isset($exif_raw["SubIFD"]["ExposureTime"])) ? $exif_raw["SubIFD"]["ExposureTime"] : ''; |
| | 116 | $exif["focal_length"] = (isset($exif_raw["SubIFD"]["FocalLength"])) ? $exif_raw["SubIFD"]["FocalLength"] : ''; |
| | 117 | $exif["flash"] = (isset($exif_raw["SubIFD"]["Flash"])) ? $exif_raw["SubIFD"]["Flash"] : ''; |
| | 118 | $exif["aperture"] = (isset($exif_raw["SubIFD"]["FNumber"])) ? $exif_raw["SubIFD"]["FNumber"] : ''; |
| | 119 | |
| | 120 | $picture_path = $create_path . "/" . $final_filename; |
| 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 | | } |
| | 168 | |
| | 169 | $sql_result = run_query($query); |
| | 170 | |
| | 171 | $result['output'] .= 'Your photo ('.$filename.') was uploaded successfully.'; |
| | 172 | $result['picture_id'] = mysql_insert_id(); |
| | 173 | |
| | 174 | // let's generate the thumbnail and the large thumbnail right away. |
| | 175 | // this way, the user won't see any latency from the thumbnail generation |
| | 176 | // when viewing the gallery for the first time |
| | 177 | // this also helps with the image pre-loading problem introduced |
| | 178 | // by a javascript slideshow. |
| | 179 | |
| | 180 | $thumbpath = generate_thumb($picture_path, $result['picture_id'],THUMB_SMALL); |
| | 181 | #$thumbpath = generate_thumb($picture_path, $result['picture_id'],THUMB_LARGE); |
| | 182 | |
| | 183 | return $result; |
| | 184 | }; |
| 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()); |
| | 187 | global $TABLE_PREFIX; |
| | 188 | $id = intval($id); |
| | 189 | $caption = mysql_real_escape_string($caption); |
| | 190 | $description = mysql_real_escape_string($description); |
| | 191 | $allow_comments = intval($allow_comments); |
| | 192 | $query = "UPDATE ".$TABLE_PREFIX."pictures SET |
| | 193 | caption = '$caption', |
| | 194 | description = '$description', |
| | 195 | allow_comments = '$allow_comments' |
| | 196 | WHERE id='$id'"; |
| | 197 | $result = mysql_query($query); |
| | 198 | if ($result) |
| | 199 | return array('output' => 'You have successfully modified the selected picture.'); |
| | 200 | else |
| | 201 | return array('errors' => mysql_error()); |
| | 202 | } |
| | 203 | |
| | 204 | function update_picture_description($id, $description) { |
| | 205 | global $TABLE_PREFIX; |
| | 206 | $id = intval($id); |
| | 207 | $description = mysql_real_escape_string($description); |
| | 208 | |
| | 209 | $query = "UPDATE ".$TABLE_PREFIX."pictures SET |
| | 210 | description = '$description' |
| | 211 | WHERE id='$id'"; |
| | 212 | $result = mysql_query($query); |
| | 213 | if ($result) |
| | 214 | return array('output' => 'You have successfully modified the selected picture.'); |
| | 215 | else |
| | 216 | return array('errors' => mysql_error()); |
| | 217 | } |
| | 218 | |
| | 219 | function update_picture_caption($id, $caption) { |
| | 220 | global $TABLE_PREFIX; |
| | 221 | $id = intval($id); |
| | 222 | $caption = mysql_real_escape_string($caption); |
| | 223 | |
| | 224 | $query = "UPDATE ".$TABLE_PREFIX."pictures SET |
| | 225 | caption = '$caption' |
| | 226 | WHERE id='$id'"; |
| | 227 | $result = mysql_query($query); |
| | 228 | if ($result) |
| | 229 | return array('output' => 'You have successfully modified the selected picture.'); |
| | 230 | else |
| | 231 | return array('errors' => mysql_error()); |
| 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 | | |
| | 235 | global $TABLE_PREFIX; |
| | 236 | global $config; |
| | 237 | // we need the parent_id from the album we're changing to |
| | 238 | $to_album = intval($to_album); |
| | 239 | $pic_id = intval($pic_id); |
| | 240 | |
| | 241 | $query = "SELECT * FROM ".$TABLE_PREFIX."albums WHERE `id` = '$to_album'"; |
| | 242 | $result = run_query($query); |
| | 243 | $row = mysql_fetch_assoc($result); |
| | 244 | |
| | 245 | if (!is_array($row)) { |
| | 246 | return array('errors' => 'There is no album with id ' . $to_album); |
| | 247 | }; |
| | 248 | |
| | 249 | $new_collection = $row['parent_id']; |
| | 250 | |
| | 251 | // move picture to new location |
| | 252 | // we need to query to get collection names and album names to find new directory path |
| | 253 | |
| | 254 | $picture = get_picture_by_id($pic_id); |
| | 255 | $album = get_album_by_id($to_album); |
| | 256 | |
| | 257 | $filename = SmartStripSlashes(basename($picture['path'])); |
| | 258 | $directory = SmartStripSlashes($album['collection_path'])."/".SmartStripSlashes($album['album_path'])."/"; |
| | 259 | $new_path = $directory.$filename; |
| | 260 | |
| | 261 | if (!rename($config['basedir']."images/".SmartStripSlashes($picture['path']), $config['basedir']."images/".$new_path)) { |
| | 262 | return array('errors' => "Error moving file! ($picture[path] to $new_path)"); |
| | 263 | }; |
| | 264 | |
| | 265 | $new_path = mysql_real_escape_string($new_path); |
| | 266 | |
| | 267 | // update database |
| | 268 | $sql = "UPDATE ".$TABLE_PREFIX."pictures SET |
| | 269 | path = '$new_path', |
| | 270 | parent_album = '$to_album', |
| | 271 | parent_collection = '$new_collection' |
| | 272 | WHERE id = '$pic_id'"; |
| | 273 | if (!mysql_query($sql)) { |
| | 274 | return array('errors' => mysql_error()); |
| | 275 | }; |
| | 276 | return array('output' => 'Success'); |
| | 277 | } |
| | 278 | |
| 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 | | }; |
| | 280 | global $TABLE_PREFIX; |
| | 281 | global $config; |
| | 282 | $del_id = intval($del_id); |
| | 283 | global $thumbnail_config; |
| | 284 | $picture = get_picture_by_id($del_id); |
| | 285 | if ($picture) { |
| | 286 | |
| | 287 | $query = "DELETE FROM ".$TABLE_PREFIX."pictures WHERE `id`= '" . $picture['id'] . "'"; |
| | 288 | run_query($query); |
| | 289 | |
| | 290 | // delete all comments for the picture |
| | 291 | $query = "DELETE FROM ".$TABLE_PREFIX."comments WHERE `parent_id`= '" . $picture['id'] . "'"; |
| | 292 | run_query($query); |
| | 293 | |
| | 294 | // make sure that the file is actually located inside our images directory |
| | 295 | $full_path = realpath($config['basedir'] . 'images/' . $picture['path']); |
| | 296 | // also check whether this image is in the correct folder |
| | 297 | $relative_path = substr($full_path,0,strlen($config['basedir'])); |
| | 298 | $basename = basename($picture['path']); |
| | 299 | if ($relative_path == $config['basedir']) { |
| | 300 | foreach($thumbnail_config as $tkey => $tval) { |
| | 301 | $thumbpath = $config['basedir'].'thumbs/'.$tval['filename_prefix'].$picture['id'].'-'.$basename; |
| | 302 | if (file_exists($thumbpath) && is_writable($thumbpath)) { |
| | 303 | //print "deleting $thumbpath<br/>"; |
| | 304 | @chmod($thumbpath, 0777); |
| | 305 | unlink($thumbpath); |
| | 306 | }; |
| | 307 | }; |
| | 308 | if (is_file($full_path)) { |
| | 309 | // print "deleting $full_path<br/>"; |
| | 310 | @chmod($full_path, 0777); |
| | 311 | |
| | 312 | if (!unlink($full_path)) |
| | 313 | return array('errors' => 'Could not physically delete file from disk!'); |
| | 314 | }; |
| | 315 | } else { |
| | 316 | return array('errors' => 'Picture has invalid path, ignoring delete request'); |
| | 317 | }; |
| | 318 | } else { |
| | 319 | return array('errors' => 'There is no picture with id ' . $del_id); |
| | 320 | }; |
| 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; |
| | 324 | global $config; |
| | 325 | global $TABLE_PREFIX; |
| | 326 | $output = $errors = ""; |