Changeset 558
- Timestamp:
- 07/15/08 13:36:59 (5 months ago)
- Location:
- trunk/plog-admin
- Files:
-
- 4 modified
-
plog-admin-functions.php (modified) (24 diffs)
-
plog-import.php (modified) (4 diffs)
-
plog-manage.php (modified) (4 diffs)
-
plog-upload.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plog-admin/plog-admin-functions.php
r557 r558 42 42 $result = array( 43 43 'output' => '', 44 'errors' => '', 44 45 'picture_id' => false, 45 46 ); … … 198 199 } else { 199 200 return array('errors' => plog_tr('Could not modify selected picture')); 200 } ;201 } 201 202 202 203 } … … 208 209 $pic_id = intval($pic_id); 209 210 210 $query = "SELECT * FROM ".TABLE_PREFIX."albums WHERE `id` = ' $to_album'";211 $query = "SELECT * FROM ".TABLE_PREFIX."albums WHERE `id` = '".$to_album."'"; 211 212 $result = run_query($query); 212 213 $row = mysql_fetch_assoc($result); … … 214 215 if (!is_array($row)) { 215 216 return array('errors' => sprintf(plog_tr('There is no album with id %d'),$to_album)); 216 } ;217 } 217 218 218 219 $new_collection = $row['parent_id']; 219 220 220 221 221 // move picture to new location … … 226 226 227 227 $filename = SmartStripSlashes(basename($picture['path'])); 228 $directory = SmartStripSlashes($album['collection_path'])."/".SmartStripSlashes($album['album_path'])."/"; 229 $new_path = $directory.$filename; 230 231 if (!rename($config['basedir']."plog-content/images/".SmartStripSlashes($picture['path']), $config['basedir']."plog-content/images/".$new_path)) { 232 return array('errors' => sprintf(plog_tr("Could not move file! %s to %s"),$picture["path"],$new_path)); 233 }; 234 235 $new_path = mysql_real_escape_string($new_path); 228 $target_path = SmartStripSlashes($album['collection_path'])."/".SmartStripSlashes($album['album_path']); 229 230 $filename_parts = explode(".",strrev($filename),2); 231 $filename_base = strrev($filename_parts[1]); 232 $filename_ext = strrev($filename_parts[0]); 233 $unique_filename_base = strtolower(SmartStripSlashes($filename_base)); 234 235 $i = 0; 236 while ($to_album != $picture['parent_album'] && is_file($config['basedir'].'plog-content/images/'.$target_path."/".$unique_filename_base.".".$filename_ext)){ 237 $unique_filename_base = $filename_base." (" . ++$i . ")"; 238 } 239 240 // final fully qualified file name 241 $picture_path = $target_path.'/'.$unique_filename_base.".".$filename_ext; 242 $final_fqfn = $config['basedir'].'plog-content/images/'.$picture_path; 243 244 if (!rename($config['basedir']."plog-content/images/".SmartStripSlashes($picture['path']), $final_fqfn)) { 245 return array('errors' => sprintf(plog_tr("Could not move file! %s to %s"),$picture['path'],$final_fqfn)); 246 } 236 247 237 248 // update database 238 249 $sql = "UPDATE ".TABLE_PREFIX."pictures SET 239 path = ' $new_path',240 parent_album = ' $to_album',241 parent_collection = ' $new_collection'242 WHERE id = ' $pic_id'";250 path = '".mysql_real_escape_string($picture_path)."', 251 parent_album = '".$to_album."', 252 parent_collection = '".$new_collection."' 253 WHERE id = '".$pic_id."'"; 243 254 if (!mysql_query($sql)) { 244 255 return array('errors' => mysql_error()); 245 } ;256 } 246 257 return array('output' => plog_tr('Success')); 247 258 } … … 297 308 if (empty($collection_name)) { 298 309 return array("errors" => plog_tr("Please enter a valid name for the collection")); 299 };300 301 // do not allow collections with duplicate names, otherwise mod_rewritten links will start302 // to behave weird.303 $collection_exists = get_collection_by_name($collection_name);304 if ($collection_exists) {305 return array("errors" => sprintf(plog_tr('New collection could not be created, because there already is one named `%s`!'),$collection_exists));306 310 } 307 311 … … 311 315 // anyway 312 316 $create_path = $config["basedir"] . "plog-content/images/".$collection_folder; 317 318 // do not allow collections with duplicate names, otherwise mod_rewritten links will start 319 // to behave weird. 320 if (is_dir($create_path)) { 321 // if there is already a directory, check to see if it's in the database 322 $collection_data = get_collection_by_name($collection_name); 323 if ($collection_data){ 324 // it's in the database, so throw duplicate collection error 325 return array("errors" => sprintf(plog_tr('New collection could not be created, because there already is one named `%s`!'),$collection_name)); 326 } else{ 327 // it's not in the database so attempt to delete the directory 328 if (!@rmdir($target_path)){ 329 // could not delete the directory, so prompt the user to delete it manually 330 return array("errors" => sprintf(plog_tr('Collection directory `%s` exists, but no collection exists in the database. Attempt to delete automatically failed. Please delete folder via FTP manually and try again.'), $target_path)); 331 } 332 } 333 } 313 334 314 335 // create directory … … 324 345 325 346 $output .= sprintf(plog_tr('You have successfully created the collection <strong>%s</strong>'),$collection_name); 326 } ;347 } 327 348 328 349 // caller can check the value of id, if it is zero, then collection creation failed … … 346 367 if (empty($name)) { 347 368 return array("errors" => plog_tr("Please enter a valid name for the collection")); 348 } ;369 } 349 370 350 371 $target_name = strtolower(sanitize_filename($name)); … … 367 388 $row = mysql_fetch_assoc($result); 368 389 369 // do not allow collections with duplicate names, otherwise mod_rewritten links will start370 // to behave weird.371 $collection_exists = get_collection_by_name($name);372 if ($row["name"] != $name && $collection_exists) {373 return array("errors" => sprintf(plog_tr('Collection `%s could not be renamed to `%s, because there is another collection with that name'),$row['name'],$name));374 }375 376 390 $source_collection_name = SmartStripSlashes($row["collection_path"]); 377 391 $source_path = $config["basedir"] . "plog-content/images/".$source_collection_name; 378 392 $target_path = $config["basedir"] . "plog-content/images/".$target_name; 379 393 394 // do not allow collections with duplicate names, otherwise mod_rewritten links will start 395 // to behave weird. 396 if ($row["name"] != $name && is_dir($target_path)) { 397 // if there is already a directory, check to see if it's in the database 398 $collection_data = get_collection_by_name($name); 399 if ($collection_data){ 400 // it's in the database, so throw duplicate collection error 401 return array("errors" => sprintf(plog_tr('Collection `%s` could not be renamed to `%s`, because there is another collection with that name'),$row['name'],$name)); 402 } else{ 403 // it's not in the database so attempt to delete the directory 404 if (!@rmdir($target_path)){ 405 // could not delete the directory, so prompt the user to delete it manually 406 return array("errors" => sprintf(plog_tr('Collection directory `%s` exists, but no collection exists in the database. Attempt to delete automatically failed. Please delete folder via FTP manually and try again.'), $target_path)); 407 } 408 } 409 } 410 380 411 // perform the rename on the directory 381 412 if (!rename($source_path, $target_path)) { 382 413 return array("errors" => sprintf(plog_tr("Error renaming directory! (%s to %s)"),$source_path,$target_path)); 383 } ;414 } 384 415 385 416 $target_name = mysql_real_escape_string($target_name); … … 389 420 if (!$result) { 390 421 return array("errors" => mysql_error()); 391 } ;422 } 392 423 393 424 $output = plog_tr('You have successfully modified the selected collection.'); … … 494 525 if (empty($album_name)) { 495 526 return array("errors" => plog_tr("Please enter a valid name for the album")); 496 } ;527 } 497 528 // get the parent collection name 498 529 $query = "SELECT c.path as collection_path FROM ". TABLE_PREFIX."collections c WHERE id = '$pid'"; … … 504 535 if (empty($row)) { 505 536 return array("errors" => plog_tr("No such collection")); 506 } ;537 } 507 538 508 539 $album_folder = strtolower(sanitize_filename($album_name)); … … 511 542 // will be unusable anyway 512 543 $create_path = $config["basedir"] . "plog-content/images/".SmartStripSlashes($row["collection_path"])."/".$album_folder; 544 545 // check path so we are not creating duplicate albums within the same collection 546 if (is_dir($create_path)){ 547 // if there is already a directory, check to see if it's in the database 548 $album_data = get_album_by_name($album_name, $pid); 549 if ($album_data) { 550 // it's in the database, so throw duplicate album error 551 return array("output" => "existing", "id" => $album_data['id'], "errors" => sprintf(plog_tr('New album could not be created, because there already is one named `%s` in the collection `%s`!'), $album_folder, SmartStripSlashes($row['collection_path']))); 552 } else { 553 // it's not in the database so attempt to delete the directory 554 if (!@rmdir($create_path)){ 555 // could not delete the directory, so prompt the user to delete it manually 556 return array("errors" => sprintf(plog_tr('Album directory `%s` exists, but no album exists in the database. Attempt to delete automatically failed. Please delete folder via FTP manually and try again.'), $create_path)); 557 } 558 } 559 } 513 560 514 561 if (!makeDirs($create_path, 0777)) { … … 523 570 524 571 $output .= sprintf(plog_tr('You have successfully created the album <strong>%s</strong>'),$album_name); 525 } ;572 } 526 573 // caller can check the value of id, if it is zero, then album creation failed 527 574 // errors and output are separate, because this way the caller can format the return value … … 561 608 $target_path = $config['basedir'] . "plog-content/images/".$source_collection_name."/".$target_name; 562 609 610 // check path so we are not creating duplicate albums within the same collection 611 if (is_dir($target_path)){ 612 // if there is already a directory, check to see if it's in the database 613 $album_data = get_album_by_name($album_name, $to_collection); 614 if ($album_data) { 615 // it's in the database, so throw duplicate album error 616 return array("errors" => sprintf(plog_tr('New album could not be created, because there already is one named `%s` in the collection `%s`!'), $target_name, $source_collection_name)); 617 } else { 618 // it's not in the database so attempt to delete the directory 619 if (!@rmdir($target_path)){ 620 // could not delete the directory, so prompt the user to delete it manually 621 return array("errors" => sprintf(plog_tr('Album directory `%s` exists, but no album exists in the database. Attempt to delete automatically failed. Please delete folder via FTP manually and try again.'), $target_path)); 622 } 623 } 624 } 625 563 626 // perform the rename on the directory 564 627 if (!rename($source_path, $target_path)) … … 566 629 return array( 567 630 "errors" => sprintf(plog_tr("Error renaming directory! (%s to %s)"),$source_path,$target_path)); 568 } ;631 } 569 632 570 633 $target_name = mysql_real_escape_string($target_name); … … 581 644 if (!$result) { 582 645 return array("errors" => mysql_error()); 583 } ;646 } 584 647 585 648 $output .= plog_tr('You have successfully modified the selected album.'); … … 632 695 } 633 696 634 function move_album($album_id, $to_collection) {697 function move_album($album_id, $to_collection) { 635 698 global $config; 636 699 … … 665 728 $target_path = $config['basedir']."plog-content/images/".$target_collection_name."/".$source_album_name; 666 729 730 // check path so we are not creating duplicate albums within the same collection 731 if (is_dir($target_path)){ 732 // if there is already a directory, check to see if it's in the database 733 $album_data = get_album_by_name($source_album_name, $to_collection); 734 if ($album_data) { 735 // it's in the database, so throw duplicate album error 736 return array("errors" => sprintf(plog_tr('New album could not be created, because there already is one named `%s` in the collection `%s`!'), $source_album_name, $target_collection_name)); 737 } else { 738 // it's not in the database so attempt to delete the directory 739 if (!@rmdir($target_path)){ 740 // could not delete the directory, so prompt the user to delete it manually 741 return array("errors" => sprintf(plog_tr('Album directory `%s` exists, but no album exists in the database. Attempt to delete automatically failed. Please delete folder via FTP manually and try again.'), $target_path)); 742 } 743 } 744 } 745 667 746 // attempt to make new album directory in target collection 668 @mkdir($target_path, 0775); 747 if (!makeDirs($target_path, 0777)) { 748 return array("errors" => sprintf(plog_tr('Could not create directory `%s`!'),$target_path)); 749 } 669 750 670 751 //if (!rename($source_path, $target_path)) … … 685 766 686 767 if (!rename($old_path, $new_path)) 687 $res['errors'] .= sprintf(plog_tr("Could not move file! %s to %s"),$old_path,$new_path);768 $res['errors'] .= sprintf(plog_tr("Could not move file! `%s` to `%s`"),$old_path,$new_path); 688 769 689 770 $path_insert = mysql_real_escape_string($target_collection_name."/".$source_album_name."/".$filename); … … 699 780 $query = "UPDATE ".TABLE_PREFIX."albums SET `parent_id` = '$to_collection' WHERE `id`='$album_id'"; 700 781 $result = run_query($query); 782 783 // attempt to delete the old folder if there were no errors moving the files 784 if ($res['errors'] == ''){ 785 @chmod($source_path,0777); 786 if (!rmdir($source_path)) { 787 return array("errors" => sprintf(plog_tr('Could not remove album from collection `%s`. Album still contains files after all pictures have been moved.'), $source_collection_name)); 788 } 789 } 701 790 702 791 return $res; … … 1068 1157 $parent_collection = intval($parent_collection); 1069 1158 $output = "\n\t\t" . '<input type="button" class="submit" id="show-album" onclick="toggle(\'create-album\'); toggle(\'show-album\')" value="' . plog_tr('Create an Album') . '" />'; 1070 $output .= "\n\t\t" . '<form action="'.$_SERVER[" PHP_SELF"].'" method="post">1159 $output .= "\n\t\t" . '<form action="'.$_SERVER["REQUEST_URI"].'" method="post"> 1071 1160 <div id="create-album" class="cssbox-green" style="width: 385px !important; display: none;"> 1072 1161 <div class="cssbox_head-green"><h2>' . plog_tr('Create an Album') . '</h2></div> … … 1089 1178 $output = ''; 1090 1179 $collection_id = intval($collection_id); 1091 $output .= "\n\t\t" . '<form class="edit" action="'.$_SERVER[" PHP_SELF"].'" method="post">';1180 $output .= "\n\t\t" . '<form class="edit" action="'.$_SERVER["REQUEST_URI"].'" method="post">'; 1092 1181 $collection = get_collection_by_id($collection_id); 1093 1182 -
trunk/plog-admin/plog-import.php
r555 r558 47 47 //print_r($_POST); 48 48 49 if (isset($_POST['upload'])) {49 if (isset($_POST['upload'])) { 50 50 51 51 $destinations = isset($_POST['destinations']) ? $_POST['destinations'] : ''; … … 59 59 $files = get_files($config['basedir'] . 'plog-content/uploads'); 60 60 61 if ($_POST['destination_radio'] == "new" && $_POST["new_album_name"] == "") {61 if ($_POST['destination_radio'] == "new" && $_POST["new_album_name"] == "") { 62 62 $output .= "\n\t" . '<p class="errors">' . plog_tr('New album name not specified!') . '</p>' . "\n"; 63 } 64 else { 63 } else { 65 64 66 65 if ($_POST["destination_radio"] == "new"){ 67 66 // Create the new album 68 $result = add_album($_POST["new_album_name"], NULL, $_POST["collections_menu"]); 69 $album_id = $result["id"]; 70 } 71 else 72 { 67 $result = add_album($_POST['new_album_name'], NULL, $_POST['collections_menu']); 68 if (!$result['errors']) { 69 // no errors, add images to new album 70 $album_id = $result['id']; 71 } else { 72 // errors exist, let's find out what they are 73 if (isset($result['output']) && $result['output'] == "existing" && isset($result['id'])) { 74 // album already exists so try insert images into the existing album 75 // and alert the user that their "new" album is already existing 76 $album_id = $result['id']; 77 // get the collection name for display 78 $sql = "SELECT `name` FROM ".TABLE_PREFIX."collections WHERE id = ".intval($_REQUEST['collections_menu']); 79 $result = run_query($sql); 80 $row = mysql_fetch_assoc($result); 81 $output .= "\n\t" . '<p class="actions">'.sprintf(plog_tr('Album already exists. Uploading file to existing album `%s` in collection `%s`'), $_REQUEST['new_album_name'], $row['name']).'</p>' . "\n"; 82 } else { 83 // error has nothing to do with an existing album, show the returned error 84 $album_id = ''; 85 $output .= "\n\t" . '<p class="errors">' . $result['errors'] . '</p>' . "\n"; 86 } 87 } 88 } else { 89 // use an existing album 73 90 $album_id = $_POST["destination"]; 74 91 } … … 93 110 // delete thumbnail file if it exists 94 111 $thumbpath = $config['basedir'] . 'plog-content/thumbs/import-'.substr($file_key,0,2).'-'.basename($file_name); 95 if (is_file($thumbpath) && is_readable($thumbpath)) 96 { 112 if (is_file($thumbpath) && is_readable($thumbpath)) { 97 113 unlink($thumbpath); 98 } ;99 } ;114 } 115 } 100 116 } 101 117 102 118 $counter++; 103 } ;119 } 104 120 105 121 } … … 108 124 $sql = "SELECT name FROM ".TABLE_PREFIX."albums WHERE id = $album_id"; 109 125 $result = run_query($sql); 110 111 126 $row = mysql_fetch_assoc($result); 112 127 113 128 $output .= "\n\t" . '<p class="actions">'.sprintf(plog_tr('%d picture(s) were successfully imported to album <strong>%s</strong>'),$imported,$row['name']). '</p>' . "\n"; 114 129 115 if ($imported == 0) 116 $output .= "\n\t" . '<p class="errors">' . plog_tr('Make sure to CHMOD 777 your newly created folders within the \'plog-content/uploads/\' directory or else Plogger cannot access them. Plogger cannot CHMOD the directory for you while PHP is in safe mode.') . '</p>' . "\n"; 117 } 118 else 119 $output .= "\n\t" . '<p class="errors">'.$result['output'].'</p>' . "\n"; 120 130 if ($imported == 0) { 131 $output .= "\n\t" . '<p class="errors">' . plog_tr('Make sure to CHMOD 777 your newly created folders within the \'plog-content/uploads/\' directory or else Plogger cannot access them. Plogger cannot CHMOD the directory for you while PHP is in safe mode.') . '</p>' . "\n"; 132 } 133 /* what is this for? 134 else { 135 $output .= "\n\t" . '<p class="errors">'.$result['output'].'</p>' . "\n"; 136 }*/ 137 } 121 138 } 122 139 -
trunk/plog-admin/plog-manage.php
r555 r558 132 132 if (empty($_REQUEST['level'])) { 133 133 $_REQUEST['level'] = ''; 134 } ;134 } 135 135 136 136 // here we will determine if we need to perform a move or delete action. … … 186 186 187 187 if (isset($_REQUEST["selected"])) { 188 foreach ($_REQUEST["selected"] as $mov_id) {188 foreach ($_REQUEST["selected"] as $mov_id) { 189 189 190 190 // if we are using pictures we need to update the parent_collection as well … … 196 196 } else { 197 197 $output .= "\n\t" . '<p class="errors">' . $result['errors'] . '</p>' . "\n"; 198 }; 199 } 200 else if ($level == "albums") { 198 } 199 } else if ($level == "albums") { 201 200 // if we are moving entire albums then we need to rename the folder 202 201 // $pid is our target collection id, $mov_id is our source album … … 207 206 } else { 208 207 $output .= "\n\t" . '<p class="errors">' . $result['errors'] . '</p>' . "\n"; 209 } ;208 } 210 209 } 211 210 -
trunk/plog-admin/plog-upload.php
r557 r558 108 108 if ($_REQUEST["destination_radio"] == "new"){ 109 109 // Create the new album 110 $result = add_album(mysql_real_escape_string($_REQUEST["new_album_name"]), NULL, $_REQUEST["collections_menu"]); 111 $album_id = $result["id"]; 110 $result = add_album(mysql_real_escape_string($_REQUEST['new_album_name']), NULL, $_REQUEST['collections_menu']); 111 if (!$result['errors']) { 112 // no errors, add uploaded image to new album 113 $album_id = $result['id']; 114 } else { 115 // errors exist, let's find out what they are 116 if (isset($result['output']) && $result['output'] == "existing" && isset($result['id'])) { 117 // album already exists so try insert images into the existing album 118 // and alert the user that their "new" album is already existing 119 $album_id = $result['id']; 120 // get the collection name for display 121 $sql = "SELECT `name` FROM ".TABLE_PREFIX."collections WHERE id = ".intval($_REQUEST['collections_menu']); 122 $result = run_query($sql); 123 $row = mysql_fetch_assoc($result); 124 $output .= "\n\t" . '<p class="actions">'.sprintf(plog_tr('Album already exists. Uploading file to existing album `%s` in collection `%s`'), $_REQUEST['new_album_name'], $row['name']).'</p>' . "\n"; 125 } else { 126 // error has nothing to do with an existing album, show the returned error 127 $album_id = ''; 128 $output .= "\n\t" . '<p class="errors">' . $result['errors'] . '</p>' . "\n"; 129 } 130 } 112 131 } else { 132 // use an existing album 113 133 $album_id = $_REQUEST["albums_menu"]; 114 134 } 115 135 116 $result = add_picture($album_id,$_FILES["userfile"]["tmp_name"],$_FILES["userfile"]["name"],$_REQUEST["caption"], $_REQUEST["description"]); 117 $output .= "\n\t" . '<p class="actions">'.$result["output"].'</p>' . "\n"; 136 if ($album_id){ 137 $result = add_picture($album_id,$_FILES["userfile"]["tmp_name"],$_FILES["userfile"]["name"],$_REQUEST["caption"], $_REQUEST["description"]); 138 if (!$result['errors']) { 139 // added uploaded image successfully 140 $output .= "\n\t" . '<p class="actions">'.$result['output'].'</p>' . "\n"; 141 } else { 142 // errors adding the image, show the returned error 143 $output .= "\n\t" . '<p class="errors">' . $result['errors'] . '</p>' . "\n"; 144 } 145 } 118 146 119 147 }
