Ejemplo n.º 1
0
Archivo: anchor.php Proyecto: rair/yacs
 /**
  * check that the surfer is an editor of an anchor
  *
  * This function is used to control the authority delegation from the anchor.
  * For example, if some editor is assigned to a complete section of the
  * web site, he/she should be able to edit all articles in this section.
  * you can use following code to check that:
  * [php]
  * $anchor = Anchors::get($article['anchor']);
  * if($anchor->is_assigned() {
  *	 ...
  * }
  * [/php]
  *
  * A logged member is always considered as an editor if he has created the target item.
  *
  * An anonymous surfer is considered as an editor if he has provided the secret handle.
  *
  * To be overloaded into derived class if field has a different name
  *
  * @param int optional reference to some user profile
  * @param boolean TRUE to climb the list of containers up to the top
  * @return TRUE or FALSE
  */
 function is_assigned($user_id = NULL, $cascade = TRUE)
 {
     global $context;
     // we need some data to proceed
     if (!isset($this->item['id'])) {
         return FALSE;
     }
     // id of requesting user
     if (!$user_id) {
         $user_id = Surfer::get_id();
     }
     // anonymous is allowed
     if (!$user_id) {
         $user_id = 0;
     }
     // create the cache
     if (!isset($this->is_assigned_cache)) {
         $this->is_assigned_cache = array();
     }
     // cache the answer
     if (isset($this->is_assigned_cache[$user_id])) {
         return $this->is_assigned_cache[$user_id];
     }
     // surfer has provided the secret handle
     if (isset($this->item['handle']) && Surfer::may_handle($this->item['handle'])) {
         return $this->is_assigned_cache[$user_id] = TRUE;
     }
     // surfer owns this item
     if ($user_id && isset($this->item['owner_id']) && $user_id == $this->item['owner_id']) {
         return $this->is_assigned_cache[$user_id] = TRUE;
     }
     // anchor has been assigned to this surfer
     if ($user_id && Members::check('user:'******'active'] == 'Y' && $this->has_option('anonymous_edit')) {
         return $this->is_assigned_cache[$user_id] = TRUE;
     }
     // members edition is allowed
     if ($this->item['active'] == 'Y' && Surfer::is_empowered('M') && $this->has_option('members_edit')) {
         return $this->is_assigned_cache[$user_id] = TRUE;
     }
     // check parent container
     if ($cascade && isset($this->item['anchor'])) {
         // save requests
         if (!isset($this->anchor) || !$this->anchor) {
             $this->anchor = Anchors::get($this->item['anchor']);
         }
         // check for ownership
         if (is_object($this->anchor)) {
             return $this->is_assigned_cache[$user_id] = $this->anchor->is_assigned($user_id);
         }
     }
     // sorry
     return $this->is_assigned_cache[$user_id] = FALSE;
 }
Ejemplo n.º 2
0
 /**
  * check if a section can be modified
  *
  * This function returns TRUE if the section can be modified,
  * and FALSE otherwise.
  *
  * @param array a set of item attributes, aka, the target section
  * @param object an instance of the Anchor interface
  * @return TRUE or FALSE
  */
 public static function allow_modification($item, $anchor = NULL)
 {
     global $context;
     // sanity check
     if (!isset($item['id']) && !$anchor) {
         return FALSE;
     }
     // surfer is an associate
     if (Surfer::is_associate()) {
         return TRUE;
     }
     // submissions have been disallowed
     if (isset($context['users_without_submission']) && $context['users_without_submission'] == 'Y') {
         return FALSE;
     }
     // surfer owns the container or the section
     if (Sections::is_owned($item, $anchor, TRUE)) {
         return TRUE;
     }
     // allow editor of parent section, if not subscriber, to manage content, except on private sections
     if (Surfer::is_member() && is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned()) {
         return TRUE;
     }
     // section has been locked
     if (isset($item['locked']) && $item['locked'] == 'Y') {
         return FALSE;
     }
     // maybe this anonymous surfer is allowed to handle this item
     if (isset($item['handle']) && Surfer::may_handle($item['handle'])) {
         return TRUE;
     }
     // community wiki
     if (Surfer::is_logged() && Sections::has_option('members_edit', $anchor, $item)) {
         return TRUE;
     }
     // public wiki
     if (Sections::has_option('anonymous_edit', $anchor, $item)) {
         return TRUE;
     }
     // default case
     return FALSE;
 }
Ejemplo n.º 3
0
 /**
  * check if an article can be modified
  *
  * This function returns TRUE if the page can be modified,
  * and FALSE otherwise.
  *
  * @param array a set of item attributes, aka, the target article
  * @param object an instance of the Anchor interface
  * @return TRUE or FALSE
  */
 public static function allow_modification($item, $anchor)
 {
     global $context;
     // sanity check
     if (!isset($item['id']) && !$anchor) {
         return FALSE;
     }
     // surfer is an associate
     if (Surfer::is_associate()) {
         return TRUE;
     }
     // ensure access rights
     if (!Articles::allow_access($item, $anchor)) {
         return FALSE;
     }
     // submissions have been disallowed
     if (isset($context['users_without_submission']) && $context['users_without_submission'] == 'Y') {
         return FALSE;
     }
     // surfer owns the container or the article
     if (Articles::is_owned($item, $anchor)) {
         return TRUE;
     }
     // allow section editors to manage content, except on private sections
     if (Surfer::is_member() && is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned()) {
         return TRUE;
     }
     // allow page editors to manage content, except on private page
     if (Surfer::is_member() && $item['active'] != 'N' && Articles::is_assigned($item['id'])) {
         return TRUE;
     }
     // article has been locked
     if (isset($item['locked']) && $item['locked'] == 'Y') {
         return FALSE;
     }
     // maybe this anonymous surfer is allowed to handle this item
     if (isset($item['handle']) && Surfer::may_handle($item['handle'])) {
         return TRUE;
     }
     // community wiki
     if (Surfer::is_logged() && Articles::has_option('members_edit', $anchor, $item)) {
         return TRUE;
     }
     // public wiki
     if (Articles::has_option('anonymous_edit', $anchor, $item)) {
         return TRUE;
     }
     // default case
     return FALSE;
 }
Ejemplo n.º 4
0
Archivo: files.php Proyecto: rair/yacs
 /**
  * check if a file can be accessed
  *
  * This function returns TRUE if the item can be transferred to surfer,
  * and FALSE otherwise.
  *
  * @param array a set of item attributes, aka, the target file
  * @param object an instance of the Anchor interface, if any
  * @return boolean TRUE or FALSE
  */
 public static function allow_access($item, $anchor)
 {
     global $context;
     // surfer is an associate
     if (Surfer::is_associate()) {
         return TRUE;
     }
     // surfer has uploaded this file
     if (isset($item['create_id']) && Surfer::is($item['create_id'])) {
         return TRUE;
     }
     // the file is anchored to the profile of this member
     if (Surfer::is_member() && !strcmp($item['anchor'], 'user:'******'allows')) && $anchor->allows('fetch', 'file')) {
         return TRUE;
     }
     // anonymous surfer has provided the secret handle
     if (isset($item['handle']) && Surfer::may_handle($item['handle'])) {
         return TRUE;
     }
     // surfer is an editor
     if (is_object($anchor) && $anchor->is_assigned()) {
         return TRUE;
     }
     // surfer is a trusted host
     if (Surfer::is_trusted()) {
         return TRUE;
     }
     // container is hidden
     if (isset($item['active']) && $item['active'] == 'N') {
         return FALSE;
     }
     if (is_object($anchor) && $anchor->is_hidden()) {
         return FALSE;
     }
     // surfer is logged
     if (Surfer::is_logged()) {
         return TRUE;
     }
     // container is restricted
     if (isset($item['active']) && $item['active'] == 'R') {
         return FALSE;
     }
     if (is_object($anchor) && !$anchor->is_public()) {
         return FALSE;
     }
     // public page
     return TRUE;
 }
Ejemplo n.º 5
0
    $anchor = Anchors::get($item['anchor']);
}
// editors can do what they want on items anchored here
if (Surfer::is_member() && is_object($anchor) && $anchor->is_assigned()) {
    Surfer::empower();
} elseif (isset($item['id']) && Articles::is_assigned($item['id']) && Surfer::is_member()) {
    Surfer::empower();
} elseif (Surfer::is_logged() && is_object($anchor) && $anchor->is_assigned()) {
    Surfer::empower('S');
} elseif (isset($item['id']) && Articles::is_assigned($item['id']) && Surfer::is_logged()) {
    Surfer::empower('S');
} elseif (isset($item['options']) && $item['options'] && preg_match('/\\banonymous_edit\\b/i', $item['options'])) {
    Surfer::empower();
} elseif (Surfer::is_member() && isset($item['options']) && $item['options'] && preg_match('/\\bmembers_edit\\b/i', $item['options'])) {
    Surfer::empower();
} elseif (isset($item['handle']) && Surfer::may_handle($item['handle'])) {
    Surfer::empower();
}
//
// is this surfer allowed to browse the page?
//
// associates, editors and readers can read this page
if (Surfer::is_empowered('S')) {
    $permitted = TRUE;
} elseif (isset($item['create_id']) && Surfer::is($item['create_id'])) {
    $permitted = TRUE;
} elseif (is_object($anchor) && !$anchor->is_viewable()) {
    $permitted = FALSE;
} elseif (isset($item['active']) && $item['active'] == 'R' && Surfer::is_logged()) {
    $permitted = TRUE;
} elseif (isset($item['active']) && $item['active'] == 'Y') {