示例#1
0
文件: anchor.php 项目: 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;
 }
示例#2
0
文件: sections.php 项目: rair/yacs
 /**
  * is the surfer watching this section?
  *
  * @param int the id of the target section
  * @param int optional id to impersonate
  * @return TRUE or FALSE
  */
 public static function is_watched($id, $surfer_id = NULL)
 {
     global $context;
     // no impersonation
     if (!$surfer_id) {
         // a managed section requires an authenticated user
         if (!Surfer::is_logged()) {
             return FALSE;
         }
         // use surfer profile
         $surfer_id = Surfer::get_id();
     }
     // ensure this section has been linked to this user
     return Members::check('section:' . $id, 'user:' . $surfer_id);
 }
示例#3
0
 // build a complete box
 $box = array('bar' => array(), 'text' => '');
 // list participants
 $rows = array();
 Skin::define_img('CHECKED_IMG', 'ajax/accept.png', '*');
 $offset = ($zoom_index - 1) * USERS_LIST_SIZE;
 // list editors of this section, and of parent sections
 if ($items = Sections::list_editors_by_name($item, 0, 1000, 'watch')) {
     foreach ($items as $user_id => $user_label) {
         $owner_state = '';
         if ($user_id == $item['owner_id']) {
             $owner_state = CHECKED_IMG;
         }
         $editor_state = CHECKED_IMG;
         $watcher_state = '';
         if (Members::check($anchors, 'user:'******'watch')) {
     foreach ($items as $user_id => $user_label) {
         // this is a true participant to the item
         $users_count += 1;
         // add the checkmark to existing row
         if (isset($rows[$user_id])) {
             $rows[$user_id][1] = CHECKED_IMG;
         } else {
             $owner = '';
示例#4
0
文件: view.php 项目: rair/yacs
    $permitted = TRUE;
} else {
    $permitted = FALSE;
}
// owners can do what they want
if ($cur_article->allows('modification')) {
    Surfer::empower();
} elseif (Surfer::is_logged() && is_object($anchor) && $anchor->is_assigned()) {
    Surfer::empower('S');
} elseif (isset($item['id']) && $cur_article->is_assigned() && Surfer::is_logged()) {
    Surfer::empower('S');
}
// is the article on user watch list?
$in_watch_list = FALSE;
if (isset($item['id']) && Surfer::get_id()) {
    $in_watch_list = Members::check('article:' . $item['id'], 'user:'******'id']) && !$zoom_type && Surfer::is_empowered() && Versions::count_for_anchor('article:' . $item['id'])) {
    $has_versions = TRUE;
}
// load the skin, maybe with a variant
load_skin('article', $anchor, isset($item['options']) ? $item['options'] : '');
// clear the tab we are in
if (is_object($anchor)) {
    $context['current_focus'] = $anchor->get_focus();
}
// current item
if (isset($item['id'])) {
    $context['current_item'] = 'article:' . $item['id'];
示例#5
0
文件: track.php 项目: rair/yacs
    Logger::error($error);
    // post-processing tasks
} else {
    // successful operation reflected into page title
    if (!strncmp($track, 'user:'******'page_title'] = i18n::s('The list of persons that you follow has been updated');
    } else {
        $context['page_title'] = i18n::s('Your watch list has been updated');
    }
    // follow-up commands
    $menu = array();
    if (is_object($anchor) && $anchor->is_viewable()) {
        $menu[] = Skin::build_link($anchor->get_url(), i18n::s('Done'), 'button');
    }
    // the page now appears in the watch list
    if (Members::check($track, 'user:'******'user:'******'user:'******'', $track))) && isset($user['email']) && $user['email'] && $user['without_alerts'] != 'Y') {
                // contact target user by e-mail
                $subject = sprintf(i18n::c('%s is following you'), strip_tags(Surfer::get_name()));
                // headline
                $headline = sprintf(i18n::c('%s is following you'), Surfer::get_link());
                // information
                $message = '<p>' . sprintf(i18n::c('%s will receive notifications when you will update your followers at %s'), Surfer::get_name(), $context['site_name']) . '</p>';
                // assemble main content of this message
                $message = Skin::build_mail_content($headline, $message);
                // a set of links
                $menu = array();
                // call for action
示例#6
0
 /**
  * list articles
  *
  * Accept following variants:
  * - 'hits', compact plus the number of hits
  * - 'no_author', for articles in the user page
  * - 'category:xxx', if the list is displayed at categories/view.php
  * - 'section:xxx', if the list is displayed at sections/view.php
  *
  * @param resource the SQL result
  * @return array of resulting items, or NULL
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return an array of ($url => $attributes)
     $items = array();
     // empty list
     if (!SQL::count($result)) {
         return $items;
     }
     // sanity check
     if (!isset($this->layout_variant)) {
         $this->layout_variant = 'decorated';
     }
     // process all items in the list
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     while ($item = SQL::fetch($result)) {
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Articles::get_permalink($item);
         // use the title to label the link
         if (is_object($overlay)) {
             $title = Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $title = Codes::beautify_title($item['title']);
         }
         // initialize variables
         $prefix = $suffix = $icon = '';
         // flag sticky pages
         if ($item['rank'] < 10000) {
             $prefix .= STICKY_FLAG;
         }
         // signal locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $suffix .= ' ' . LOCKED_FLAG;
         }
         // flag articles that are dead, or created or updated very recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $prefix .= EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix .= ' ' . NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= ' ' . UPDATED_FLAG;
         }
         // signal articles to be published
         if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) {
             $prefix .= DRAFT_FLAG;
         }
         // signal restricted and private articles
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // the compact version
         if ($this->layout_variant == 'compact') {
             $items[$url] = array($prefix, Skin::strip($title, 30), $suffix, 'basic', NULL);
             continue;
         }
         // with hits
         if ($this->layout_variant == 'hits') {
             if ($item['hits'] > 1) {
                 $suffix = ' <span class="details">- ' . Skin::build_number($item['hits'], i18n::s('hits')) . '</span>';
             }
             $items[$url] = array($prefix, Skin::strip($title, 30), $suffix, 'basic', NULL);
             continue;
         }
         // introduction
         $introduction = '';
         if (is_object($overlay)) {
             $introduction = $overlay->get_text('introduction', $item);
         } else {
             $introduction = $item['introduction'];
         }
         // the introductory text
         if ($introduction) {
             $suffix .= ' -&nbsp;' . Codes::beautify_introduction($introduction);
             // link to description, if any
             if ($item['description']) {
                 $suffix .= ' ' . Skin::build_link($url, MORE_IMG, 'more', i18n::s('View the page')) . ' ';
             }
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $suffix .= $overlay->get_text('list', $item);
         }
         // next line, except if we already are at the beginning of a line
         if ($suffix && !preg_match('/<br\\s*\\/>$/', rtrim($suffix))) {
             $suffix .= BR;
         }
         // append details to the suffix
         $suffix .= '<span class="details">';
         // details
         $details = array();
         // display details only at the main index page, and also at anchor pages
         if (isset($this->focus) && $item['anchor'] != $this->focus) {
             // the author
             if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
                 if ($item['create_name'] != $item['edit_name']) {
                     $details[] = sprintf(i18n::s('by %s, %s'), $item['create_name'], $item['edit_name']);
                 } else {
                     $details[] = sprintf(i18n::s('by %s'), $item['create_name']);
                 }
             }
             // the last action
             $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']);
             // the number of hits
             if (Surfer::is_logged() && $item['hits'] > 1) {
                 $details[] = Skin::build_number($item['hits'], i18n::s('hits'));
             }
             // info on related files
             if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) {
                 $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
             }
             // info on related links
             if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
                 $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
             }
             // info on related comments
             if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
                 $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
             }
             // rating
             if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) {
                 $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic');
             }
             // unusual ranks are signaled to associates and owners
             if ($item['rank'] != 10000 && Articles::is_owned($item, $anchor)) {
                 $details[] = '{' . $item['rank'] . '}';
             }
         }
         // at the user page
         if ($this->layout_variant == 'no_author' && Surfer::get_id()) {
             if (Members::check('article:' . $item['id'], 'user:'******'Stop notifications');
             } else {
                 $label = i18n::s('Watch this page');
             }
             $menu = array('users/track.php?anchor=' . urlencode('article:' . $item['id']) => $label);
             $details[] = Skin::build_list($menu, 'menu');
         }
         // the main anchor link
         if (is_object($anchor) && (!isset($this->focus) || $item['anchor'] != $this->focus)) {
             $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'section'));
         }
         // combine in-line details
         if (count($details)) {
             $suffix .= ucfirst(trim(implode(', ', $details)));
         }
         // end of details
         $suffix .= '</span>';
         // display all tags
         if ($item['tags']) {
             $suffix .= ' <span class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</span>';
         }
         // strip empty details
         $suffix = str_replace(BR . '<span class="details"></span>', '', $suffix);
         $suffix = str_replace('<span class="details"></span>', '', $suffix);
         // insert a suffix separator
         if (trim($suffix)) {
             $suffix = ' ' . $suffix;
         }
         // the icon to put in the left column
         if ($item['thumbnail_url']) {
             $icon = $item['thumbnail_url'];
         } elseif (is_callable(array($anchor, 'get_bullet_url'))) {
             $icon = $anchor->get_bullet_url();
         }
         // list all components for this item
         $items[$url] = array($prefix, $title, $suffix, 'article', $icon);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
示例#7
0
文件: element.php 项目: rair/yacs
 // the list of followers
 $followers = '';
 if ($items = Members::list_watchers_by_name_for_anchor('user:'******'id'], 0, 1000, 'compact')) {
     if (is_array($items)) {
         $items = Skin::build_list($items, 'compact');
     }
     if (Surfer::get_id() == $item['id']) {
         $followers .= '<p>' . i18n::s('Persons who follow you:') . '</p>' . $items;
     } else {
         $followers .= '<p>' . sprintf(i18n::s('Persons who follow %s:'), $item['full_name']) . '</p>' . $items;
     }
 }
 // connect to people
 if (Surfer::get_id() && Surfer::get_id() != $item['id']) {
     // suggest a new connection
     if (!Members::check('user:'******'id'], 'user:'******'USERS_WATCH_IMG', 'users/watch.gif');
         $link = Users::get_url('user:'******'id'], 'track');
         $followers .= '<p style="margin: 1em 0;">' . Skin::build_link($link, USERS_WATCH_IMG . sprintf(i18n::s('Follow %s'), $item['full_name']), 'basic', i18n::s('Be notified of additions from this person')) . '</p>';
     }
 }
 // put followers in a sidebar
 if ($followers) {
     $output .= Skin::layout_horizontally($watched, Skin::build_block($followers, 'sidecolumn'));
 } else {
     $output .= $watched;
 }
 // actual transmission except on a HEAD request
 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
     echo $output;
 }
示例#8
0
文件: view.php 项目: rair/yacs
// insert page family, if any
if (isset($item['family']) && $item['family']) {
    $context['page_title'] = FAMILY_PREFIX . '<span id="family">' . $item['family'] . '</span> ' . FAMILY_SUFFIX . $context['page_title'] . "\n";
}
// page language, if any
if (isset($item['language']) && $item['language'] && $item['language'] != 'none') {
    $context['page_language'] = $item['language'];
}
// page canonical link
$context['page_link'] = Sections::get_permalink($item);
// is the page on user watch list?
$in_watch_list = 'N';
if (Surfer::is_logged() && isset($item['id'])) {
    if (Members::check('section:' . $item['id'], 'user:'******'Y';
    } elseif (Members::check($context['current_focus'], 'user:'******'P';
    }
}
// has this page some versions?
$has_versions = FALSE;
if (isset($item['id']) && !$zoom_type && Surfer::is_empowered() && Surfer::is_logged() && Versions::count_for_anchor('section:' . $item['id'])) {
    $has_versions = TRUE;
}
// has this page some content to manage?
if (!isset($item['id'])) {
    $has_content = FALSE;
} elseif (Articles::count_for_anchor('section:' . $item['id'])) {
    $has_content = TRUE;
} elseif (Sections::count_for_anchor('section:' . $item['id'])) {
    $has_content = TRUE;