Changeset 1899 in ExiteCMS for trunk/albums.php
- Timestamp:
- 10/22/08 17:49:46 (4 years ago)
- File:
-
- 1 edited
-
trunk/albums.php (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/albums.php
r1853 r1899 17 17 18 18 // local function to check for album, gallery and/or photo access 19 function has_photo_access($id=0, $type="", $photo_id=0 ) {20 global $collection ;19 function has_photo_access($id=0, $type="", $photo_id=0, $mode='read') { 20 global $collection, $settings, $userdata, $db_prefix; 21 21 22 22 // validate the parameters 23 23 if (empty($id) || empty($type)) return false; 24 if ($mode != 'read' && $mode != 'write') $mode = 'read'; 25 26 // result cache 27 static $resultcache; 28 if (isset($resultcache[$type][$id][$mode])) { 29 return $resultcache[$type][$id][$mode]; 30 } 24 31 25 32 // check if the requested id and type are part of the collection … … 27 34 foreach($collection as $item) { 28 35 if ($item['type'] == $type && $item['id'] == $id) { 29 $match = true; 36 // match found. 37 if ($mode == 'write') { 38 // Does the user have write access? 39 switch ($type) { 40 case "album": 41 $album = dbarray(dbquery("SELECT * FROM ".$db_prefix."albums WHERE album_id = $id")); 42 $match = $album && ((iMEMBER && $album['album_write'] == -1 && $album['album_owner'] == $userdata['user_id']) || checkgroup($album['album_write'])); 43 break; 44 case "gallery": 45 $gallery = dbarray(dbquery("SELECT * FROM ".$db_prefix."galleries WHERE gallery_id = $id")); 46 $match = $gallery && ((iMEMBER && $gallery['gallery_write'] == -1 && $gallery['gallery_owner'] == $userdata['user_id']) || checkgroup($gallery['gallery_write'])); 47 break; 48 default: 49 $match = false; 50 break; 51 } 52 } else { 53 $match = true; 54 } 30 55 break; 31 56 } … … 45 70 } 46 71 } 72 73 // add the result to the resultcache 74 if (!isset($resultcache)) $resultcache = array(); 75 if (!isset($resultcache[$type])) $resultcache[$type] = array(); 76 if (!isset($resultcache[$type][$id])) $resultcache[$type][$id] = array(); 77 $resultcache[$type][$id][$mode] = $match; 78 79 // return the result 47 80 return $match; 48 81 } … … 184 217 if (isset($_POST['SWFSESSIONID'])) { 185 218 // check if the user has upload rights to this album 186 if (empty($_POST['album_id']) || !isNum($_POST['album_id']) || !has_photo_access($_POST['album_id'], "album", 0 )) {219 if (empty($_POST['album_id']) || !isNum($_POST['album_id']) || !has_photo_access($_POST['album_id'], "album", 0, "write")) { 187 220 echo "error|".$locale['402']; 188 221 exit(0); … … 250 283 251 284 if ($action == "edit" && isset($_POST['save'])) { 252 if (!empty($album_id) && has_photo_access($album_id, "album", $photo_id )) {285 if (!empty($album_id) && has_photo_access($album_id, "album", $photo_id, "write")) { 253 286 $result = dbquery("UPDATE ".$db_prefix."album_photos SET 254 287 album_photo_title = '".mysql_escape_string(stripinput($_POST['album_photo_title']))."', … … 259 292 $action = "view"; 260 293 } else { 261 if (!empty($gallery_id) && has_photo_access($gallery_id, "gallery", $photo_id )) {294 if (!empty($gallery_id) && has_photo_access($gallery_id, "gallery", $photo_id, "write")) { 262 295 $result = dbquery("UPDATE ".$db_prefix."gallery_photos SET 263 296 gallery_photo_title = '".mysql_escape_string(stripinput($_POST['gallery_photo_title']))."', … … 290 323 $variables['photo']['parsed_description'] = parsemessage(array(), is_null($variables['photo']['album_photo_description'])?"":$variables['photo']['album_photo_description'], true, true); 291 324 // check if the user may edit the photo properties 292 $variables['can_edit'] = ($variables['is_moderator'] || (iMEMBER && $userdata['user_id'] == $variables['photo']['album_owner'])) ? 1 : 0;325 $variables['can_edit'] = has_photo_access($album_id, "album", $photo_id, "write"); 293 326 // find the previous and next photo 294 327 $result = dbquery("SELECT photo_id FROM ".$db_prefix."album_photos … … 345 378 $variables['photo']['parsed_description'] = parsemessage(array(), is_null($variables['photo']['gallery_photo_description'])?"":$variables['photo']['gallery_photo_description'], true, true); 346 379 // check if the user may edit the photo properties 347 $variables['can_edit'] = ($variables['is_moderator'] || (iMEMBER && $userdata['user_id'] == $variables['photo']['gallery_owner'])) ? 1 : 0;380 $variables['can_edit'] = has_photo_access($gallery_id, "gallery", $photo_id, "write"); 348 381 // find the previous and next photo 349 382 $result = dbquery("SELECT photo_id FROM ".$db_prefix."gallery_photos … … 397 430 if ($action == "highlight") { 398 431 // check if the user has access to this album 399 if (!empty($album_id) && has_photo_access($album_id, "album", $photo_id )) {432 if (!empty($album_id) && has_photo_access($album_id, "album", $photo_id, "write")) { 400 433 // set the photo as highlight 401 434 $result = dbquery("UPDATE ".$db_prefix."albums SET album_highlight = $photo_id WHERE album_id = $album_id"); … … 403 436 // return to album view 404 437 $type = "album"; $action = "view"; 405 } elseif (!empty($gallery_id) && has_photo_access($gallery_id, "gallery", $photo_id )) {438 } elseif (!empty($gallery_id) && has_photo_access($gallery_id, "gallery", $photo_id, "write")) { 406 439 // set the photo as highlight 407 440 $result = dbquery("UPDATE ".$db_prefix."galleries SET gallery_highlight = $photo_id WHERE gallery_id = $gallery_id"); … … 423 456 if ($action == "delete" && isset($_POST['delete'])) { 424 457 // check if the user has access to this album and this photo 425 if (!empty($album_id) && has_photo_access($album_id, "album", $photo_id )) {458 if (!empty($album_id) && has_photo_access($album_id, "album", $photo_id, "write")) { 426 459 delete_photo($album_id, $photo_id); 427 460 $variables['errormessages'][] = $locale['411']; 428 461 // return to the album 429 462 $type = "album"; $action = "view"; 430 } elseif (!empty($gallery_id) && has_photo_access($gallery_id, "gallery", $photo_id )) {463 } elseif (!empty($gallery_id) && has_photo_access($gallery_id, "gallery", $photo_id, "write")) { 431 464 // delete the gallery_photo record 432 465 $result = dbquery("DELETE FROM ".$db_prefix."gallery_photos WHERE gallery_id = $gallery_id AND photo_id = $photo_id"); … … 464 497 $variables['errormessages'][] = $locale['414']; 465 498 } 466 if ($action == "edit" && !has_photo_access($variables['album']['album_id'], "album", 0 )) {499 if ($action == "edit" && !has_photo_access($variables['album']['album_id'], "album", 0, "write")) { 467 500 $variables['errormessages'][] = $locale['415']; 468 501 } … … 499 532 $gallery_id = isset($_POST['gallery_id']) && isNum($_POST['gallery_id']) ? $_POST['gallery_id'] : 0; 500 533 $photo_title = stripinput($_POST['photo_title']); 501 if ($photo_id && has_photo_access($album_id, "album", $photo_id) && has_photo_access($gallery_id, "gallery", 0 )) {534 if ($photo_id && has_photo_access($album_id, "album", $photo_id) && has_photo_access($gallery_id, "gallery", 0, "write")) { 502 535 $result = dbquery("INSERT IGNORE INTO ".$db_prefix."gallery_photos (gallery_id, photo_id, gallery_photo_title, gallery_photo_datestamp) VALUES ($gallery_id, $photo_id, '".mysql_escape_string($photo_title)."', '".time()."')"); 503 536 } … … 509 542 510 543 if ($action == "delete" && isset($_POST['delete'])) { 511 if (!has_photo_access($album_id, "album", 0 )) {544 if (!has_photo_access($album_id, "album", 0, "write")) { 512 545 $variables['errormessages'][] = $locale['420']; 513 546 $type = ""; $action = ""; … … 546 579 break; 547 580 case "delete": 548 if (!has_photo_access($album_id, "album", 0 )) {581 if (!has_photo_access($album_id, "album", 0, "write")) { 549 582 $variables['errormessages'][] = $locale['420']; 550 583 $type = ""; $action = ""; … … 572 605 break; 573 606 case "edit": 574 if (!has_photo_access($album_id, "album", 0 )) {607 if (!has_photo_access($album_id, "album", 0, "write")) { 575 608 $variables['errormessages'][] = $locale['415']; 576 609 $type = ""; $action = ""; … … 628 661 // check if there are galleries present 629 662 $variables['album']['galleries'] = 0; 663 $variables['album']['collection'] = array(); 630 664 foreach($collection as $item) { 631 if ($item['type'] == "gallery" ) {665 if ($item['type'] == "gallery" && has_photo_access($item['id'], $item['type'], 0, "write")) { 632 666 $variables['album']['galleries'] = 1; 633 667 // add the collection to the variables if any galleries found 634 $variables['album']['collection'] = $collection;668 $variables['album']['collection'][] = $item; 635 669 break; 636 670 } … … 675 709 $variables['photos'] = array(); 676 710 while ($data = dbarray($result)) { 677 $data['can_edit'] = ($variables['is_moderator'] || (iMEMBER && $userdata['user_id'] == $variables['album']['album_owner'])) ? 1 : 0;711 $data['can_edit'] = has_photo_access($album_id, "album", 0, "write"); 678 712 // update the thumb counter 679 713 $result2 = dbquery("UPDATE ".$db_prefix."photos SET photo_thumb_count = photo_thumb_count + 1 WHERE photo_id = ".$data['photo_id']); … … 690 724 break; 691 725 case "upload": 692 if (!has_photo_access($album_id, "album", 0 )) {726 if (!has_photo_access($album_id, "album", 0, "write")) { 693 727 $variables['errormessages'][] = $locale['402']; 694 728 $type = ""; $action = ""; … … 775 809 $variables['errormessages'][] = $locale['427']; 776 810 } 777 if ($action == "edit" && !has_photo_access($variables['gallery']['gallery_id'], "gallery", 0 )) {811 if ($action == "edit" && !has_photo_access($variables['gallery']['gallery_id'], "gallery", 0, "write")) { 778 812 $variables['errormessages'][] = $locale['428']; 779 813 } … … 811 845 812 846 if ($action == "delete" && isset($_POST['delete'])) { 813 if (!has_photo_access($gallery_id, "gallery", 0 )) {847 if (!has_photo_access($gallery_id, "gallery", 0, "write")) { 814 848 $variables['errormessages'][] = $locale['433']; 815 849 $type = ""; $action = ""; … … 848 882 break; 849 883 case "delete": 850 if (!has_photo_access($gallery_id, "gallery", 0 )) {884 if (!has_photo_access($gallery_id, "gallery", 0, "write")) { 851 885 $variables['errormessages'][] = $locale['433']; 852 886 $type = ""; $action = ""; … … 874 908 break; 875 909 case "edit": 876 if (!has_photo_access($gallery_id, "gallery", 0 )) {910 if (!has_photo_access($gallery_id, "gallery", 0, "write")) { 877 911 $variables['errormessages'][] = $locale['428']; 878 912 $type = ""; $action = ""; … … 967 1001 $variables['photos'] = array(); 968 1002 while ($data = dbarray($result)) { 969 $data['can_edit'] = ($variables['is_moderator'] || (iMEMBER && $userdata['user_id'] == $variables['gallery']['gallery_owner'])) ? 1 : 0;1003 $data['can_edit'] = has_photo_access($gallery_id, "gallery", 0, "write"); 970 1004 // update the thumb counter 971 1005 $result2 = dbquery("UPDATE ".$db_prefix."photos SET photo_thumb_count = photo_thumb_count + 1 WHERE photo_id = ".$data['photo_id']); … … 1059 1093 } 1060 1094 // check if this album is editable 1061 $data['can_edit'] = ($variables['is_moderator'] || checkgroup($data['album_write']) || (iMEMBER && $userdata['user_id'] == $data['owner'])) ? 1 : 0;1095 $data['can_edit'] = has_photo_access($value['id'], "album", 0, "write"); 1062 1096 break; 1063 1097 case "gallery": … … 1082 1116 $data['slideshow'] = $slideshow; 1083 1117 // check if this album is editable 1084 $data['can_edit'] = ($variables['is_moderator'] || checkgroup($data['gallery_write']) || (iMEMBER && $userdata['user_id'] == $data['owner'])) ? 1 : 0;1118 $data['can_edit'] = has_photo_access($value['id'], "gallery", 0, "write"); 1085 1119 } 1086 1120 break;
Note: See TracChangeset
for help on using the changeset viewer.
