You are here

function _photos_access in Album Photos 7.3

Same name and namespace in other branches
  1. 8.4 photos.module \_photos_access()
  2. 6.2 photos.module \_photos_access()

Photos menu access callback.

Parameters

$value: $node, $user, $file->fid OR $node->nid.

7 calls to _photos_access()
photos_edit_sort_albums_save in inc/photos.edit.inc
Save weight for array of album id's.
photos_edit_sort_save in inc/photos.edit.inc
Save weight for array of image id's.
photos_edit_sort_subalbums_save in inc/photos.edit.inc
Save weight for array of image id's in sub-album.
photos_edit_update in inc/photos.edit.inc
Ajax edit image.
photos_edit_update_load in inc/photos.edit.inc
Ajax edit image load text.

... See full list

1 string reference to '_photos_access'
photos_menu in ./photos.module
Implements hook_menu().

File

./photos.module, line 384
Implementation of photos.module.

Code

function _photos_access($type, $value, $id = 0) {
  global $user;
  switch ($type) {
    case 'viewUser':
      return $value->uid && user_access('create photo', $value) || user_access('access user profiles') && user_access('view photo');
    case 'imageOrig':
      if (!user_access('view original')) {
        return FALSE;
      }
    case 'imageView':

      // Value is fid, check if user can view this photo's album.
      if ($user->uid == 1) {
        return TRUE;
      }
      if (variable_get('photos_access_photos', 0)) {
        $node = _photos_access_pass_type($value, 1);
        if (isset($node['node']->viewid) && $node['node']->viewid != 3) {
          return node_access('view', (object) $node['node']);
        }
        elseif (isset($node['view']->pass)) {
          if (isset($_SESSION[$node['view']->nid . '_' . session_id()]) && $node['view']->pass == $_SESSION[$node['view']->nid . '_' . session_id()] || !photos_access_pass_validate($node)) {
            return TRUE;
          }
        }
        else {
          return user_access('view photo');
        }
      }
      else {
        return user_access('view photo');
      }
      break;
    case 'album':
      return $value->type == 'photos' && node_access('view', $value);
    case 'subAlbum':
      return variable_get('photos_node_' . $value->type, 0) && node_access('view', $value);
    case 'editAlbum':
      if ($value->type == 'photos') {
        return node_access('update', $value);
      }
      else {
        return variable_get('photos_node_' . $value->type, 0) && node_access('update', $value);
      }
    case 'imageEdit':
      if (!is_object($value)) {
        $query = db_select('node', 'n');
        $query
          ->join('photos_image', 'p', 'p.pid = n.nid');
        $query
          ->fields('n', array(
          'nid',
        ))
          ->condition('p.fid', $value);
        $nid = $query
          ->execute()
          ->fetchField();
        $value = node_load($nid);
      }
      return node_access('update', $value) || node_access('delete', $value);
    case 'imageDelete':
      if (!is_object($value)) {
        $query = db_select('node', 'n');
        $query
          ->join('photos_image', 'p', 'p.pid = n.nid');
        $query
          ->fields('n', array(
          'nid',
        ))
          ->condition('p.fid', $value);
        $nid = $query
          ->execute()
          ->fetchField();
        $value = node_load($nid);
      }
      return node_access('delete', $value);
  }
}