Changeset 1899 in ExiteCMS for trunk/albums.php


Ignore:
Timestamp:
10/22/08 17:49:46 (4 years ago)
Author:
hverton
Message:

fixed not checking write rights properly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/albums.php

    r1853 r1899  
    1717 
    1818// 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; 
     19function has_photo_access($id=0, $type="", $photo_id=0, $mode='read') { 
     20    global $collection, $settings, $userdata, $db_prefix; 
    2121 
    2222    // validate the parameters 
    2323    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    } 
    2431 
    2532    // check if the requested id and type are part of the collection 
     
    2734    foreach($collection as $item) { 
    2835        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            } 
    3055            break; 
    3156        } 
     
    4570        } 
    4671    } 
     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 
    4780    return $match; 
    4881} 
     
    184217if (isset($_POST['SWFSESSIONID'])) { 
    185218    // 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")) { 
    187220        echo "error|".$locale['402']; 
    188221        exit(0); 
     
    250283 
    251284    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")) { 
    253286            $result = dbquery("UPDATE ".$db_prefix."album_photos SET  
    254287                album_photo_title = '".mysql_escape_string(stripinput($_POST['album_photo_title']))."', 
     
    259292            $action = "view"; 
    260293        } 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")) { 
    262295                $result = dbquery("UPDATE ".$db_prefix."gallery_photos SET  
    263296                    gallery_photo_title = '".mysql_escape_string(stripinput($_POST['gallery_photo_title']))."', 
     
    290323                $variables['photo']['parsed_description'] = parsemessage(array(), is_null($variables['photo']['album_photo_description'])?"":$variables['photo']['album_photo_description'], true, true); 
    291324                // 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"); 
    293326                // find the previous and next photo 
    294327                $result = dbquery("SELECT photo_id FROM ".$db_prefix."album_photos 
     
    345378                $variables['photo']['parsed_description'] = parsemessage(array(), is_null($variables['photo']['gallery_photo_description'])?"":$variables['photo']['gallery_photo_description'], true, true); 
    346379                // 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"); 
    348381                // find the previous and next photo 
    349382                $result = dbquery("SELECT photo_id FROM ".$db_prefix."gallery_photos 
     
    397430    if ($action == "highlight") { 
    398431        // 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")) { 
    400433            // set the photo as highlight 
    401434            $result = dbquery("UPDATE ".$db_prefix."albums SET album_highlight = $photo_id WHERE album_id = $album_id"); 
     
    403436            // return to album view 
    404437            $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")) { 
    406439            // set the photo as highlight 
    407440            $result = dbquery("UPDATE ".$db_prefix."galleries SET gallery_highlight = $photo_id WHERE gallery_id = $gallery_id"); 
     
    423456    if ($action == "delete" && isset($_POST['delete'])) { 
    424457        // 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")) { 
    426459            delete_photo($album_id, $photo_id); 
    427460            $variables['errormessages'][] = $locale['411']; 
    428461            // return to the album 
    429462            $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")) { 
    431464            // delete the gallery_photo record 
    432465            $result = dbquery("DELETE FROM ".$db_prefix."gallery_photos WHERE gallery_id = $gallery_id AND photo_id = $photo_id"); 
     
    464497            $variables['errormessages'][] = $locale['414']; 
    465498        } 
    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")) { 
    467500            $variables['errormessages'][] = $locale['415']; 
    468501        } 
     
    499532        $gallery_id = isset($_POST['gallery_id']) && isNum($_POST['gallery_id']) ? $_POST['gallery_id'] : 0; 
    500533        $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")) { 
    502535            $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()."')"); 
    503536        } 
     
    509542 
    510543    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")) { 
    512545            $variables['errormessages'][] = $locale['420']; 
    513546            $type = ""; $action = ""; 
     
    546579            break; 
    547580        case "delete": 
    548             if (!has_photo_access($album_id, "album", 0)) { 
     581            if (!has_photo_access($album_id, "album", 0, "write")) { 
    549582                $variables['errormessages'][] = $locale['420']; 
    550583                $type = ""; $action = ""; 
     
    572605            break; 
    573606        case "edit": 
    574             if (!has_photo_access($album_id, "album", 0)) { 
     607            if (!has_photo_access($album_id, "album", 0, "write")) { 
    575608                $variables['errormessages'][] = $locale['415']; 
    576609                $type = ""; $action = ""; 
     
    628661                    // check if there are galleries present 
    629662                    $variables['album']['galleries'] = 0; 
     663                    $variables['album']['collection'] = array(); 
    630664                    foreach($collection as $item) { 
    631                         if ($item['type'] == "gallery") { 
     665                        if ($item['type'] == "gallery" && has_photo_access($item['id'], $item['type'], 0, "write")) { 
    632666                            $variables['album']['galleries'] = 1; 
    633667                            // add the collection to the variables if any galleries found 
    634                             $variables['album']['collection'] = $collection; 
     668                            $variables['album']['collection'][] = $item; 
    635669                            break; 
    636670                        } 
     
    675709                        $variables['photos'] = array(); 
    676710                        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"); 
    678712                            // update the thumb counter 
    679713                            $result2 = dbquery("UPDATE ".$db_prefix."photos SET photo_thumb_count = photo_thumb_count + 1 WHERE photo_id = ".$data['photo_id']); 
     
    690724            break; 
    691725        case "upload": 
    692             if (!has_photo_access($album_id, "album", 0)) { 
     726            if (!has_photo_access($album_id, "album", 0, "write")) { 
    693727                $variables['errormessages'][] = $locale['402']; 
    694728                $type = ""; $action = ""; 
     
    775809            $variables['errormessages'][] = $locale['427']; 
    776810        } 
    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")) { 
    778812            $variables['errormessages'][] = $locale['428']; 
    779813        } 
     
    811845 
    812846    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")) { 
    814848            $variables['errormessages'][] = $locale['433']; 
    815849            $type = ""; $action = ""; 
     
    848882            break; 
    849883        case "delete": 
    850             if (!has_photo_access($gallery_id, "gallery", 0)) { 
     884            if (!has_photo_access($gallery_id, "gallery", 0, "write")) { 
    851885                $variables['errormessages'][] = $locale['433']; 
    852886                $type = ""; $action = ""; 
     
    874908            break; 
    875909        case "edit": 
    876             if (!has_photo_access($gallery_id, "gallery", 0)) { 
     910            if (!has_photo_access($gallery_id, "gallery", 0, "write")) { 
    877911                $variables['errormessages'][] = $locale['428']; 
    878912                $type = ""; $action = ""; 
     
    9671001                        $variables['photos'] = array(); 
    9681002                        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"); 
    9701004                            // update the thumb counter 
    9711005                            $result2 = dbquery("UPDATE ".$db_prefix."photos SET photo_thumb_count = photo_thumb_count + 1 WHERE photo_id = ".$data['photo_id']); 
     
    10591093                } 
    10601094                // 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"); 
    10621096                break; 
    10631097            case "gallery": 
     
    10821116                    $data['slideshow'] = $slideshow; 
    10831117                // 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"); 
    10851119                } 
    10861120                break; 
Note: See TracChangeset for help on using the changeset viewer.