示例#1
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;
 }
示例#2
0
文件: files.php 项目: rair/yacs
 /**
  * check if new files can be added
  *
  * This function returns TRUE if files can be added to some place,
  * and FALSE otherwise.
  *
  * @param array a set of item attributes, if any
  * @param object an instance of the Anchor interface, if any
  * @param string the type of item, e.g., 'article' or 'section'
  * @return boolean TRUE or FALSE
  */
 public static function allow_creation($item = NULL, $anchor = NULL, $variant = NULL)
 {
     global $context;
     // guess the variant
     if (!$variant) {
         // most frequent case
         if (isset($item['id'])) {
             $variant = 'article';
         } elseif (is_object($anchor)) {
             $variant = $anchor->get_type();
         } else {
             return FALSE;
         }
     }
     // attach a file to an article
     if ($variant == 'article') {
         // 'no initial upload' option
         if (!isset($item['id']) && Articles::has_option('no_initial_upload', $anchor, $item)) {
             return FALSE;
         }
         // 'no files' option
         if (Articles::has_option('no_files', $anchor, $item)) {
             return FALSE;
         }
         // attach a file to a user profile
     } elseif ($variant == 'user') {
         // associates can always proceed
         if (Surfer::is_associate()) {
         } elseif (!is_object($anchor) || !Surfer::get_id()) {
             return FALSE;
         } elseif ($anchor->get_reference() != 'user:'******'options']) && is_string($item['options']) && preg_match('/\\bwith_files\\b/i', $item['options'])) {
         } elseif (!isset($item['id']) && is_object($anchor) && $anchor->has_option('with_files', FALSE)) {
         } else {
             return FALSE;
         }
     }
     // surfer is not allowed to upload a file
     if (!Surfer::may_upload()) {
         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;
     }
     // only in articles
     if ($variant == 'article') {
         // surfer owns this item, or the anchor
         if (Articles::is_owned($item, $anchor)) {
             return TRUE;
         }
         // surfer is an editor, and the page is not private
         if (isset($item['active']) && $item['active'] != 'N' && Articles::is_assigned($item['id'])) {
             return TRUE;
         }
         // only in sections
     } elseif ($variant == 'section') {
         // surfer owns this item, or the anchor
         if (Sections::is_owned($item, $anchor, TRUE)) {
             return TRUE;
         }
         // surfer is an editor, and the section is not private
         if (isset($item['active']) && $item['active'] != 'N' && Sections::is_assigned($item['id'])) {
             return TRUE;
         }
     }
     // surfer is an editor, and container is not private
     if (isset($item['active']) && $item['active'] != 'N' && is_object($anchor) && $anchor->is_assigned()) {
         return TRUE;
     }
     if (!isset($item['id']) && is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned()) {
         return TRUE;
     }
     // item has been locked
     if (isset($item['locked']) && $item['locked'] == 'Y') {
         return FALSE;
     }
     // anchor has been locked --only used when there is no item provided
     if (!isset($item['id']) && is_object($anchor) && $anchor->has_option('locked')) {
         return FALSE;
     }
     // surfer is an editor (and item has not been locked)
     if ($variant == 'article' && isset($item['id']) && Articles::is_assigned($item['id'])) {
         return TRUE;
     }
     if ($variant == 'section' && isset($item['id']) && Sections::is_assigned($item['id'])) {
         return TRUE;
     }
     if (is_object($anchor) && $anchor->is_assigned()) {
         return TRUE;
     }
     // container is hidden
     if (isset($item['active']) && $item['active'] == 'N') {
         return FALSE;
     }
     if (is_object($anchor) && $anchor->is_hidden()) {
         return FALSE;
     }
     // authenticated members and subscribers are allowed to add files
     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;
     }
     // anonymous contributions are allowed for articles and for sections
     if ($variant == 'article' || $variant == 'section') {
         if (isset($item['options']) && preg_match('/\\banonymous_edit\\b/i', $item['options'])) {
             return TRUE;
         }
         if (is_object($anchor) && $anchor->has_option('anonymous_edit')) {
             return TRUE;
         }
     }
     // the default is to not allow for new files
     return FALSE;
 }
 /**
  * layout the newest articles
  *
  * caution: this function also updates page title directly, and this makes its call non-cacheable
  *
  * @param array the article
  * @return string the rendered text
  **/
 function layout_newest($item)
 {
     global $context;
     // get the related overlay, if any
     $overlay = Overlay::load($item, 'article:' . $item['id']);
     // get the anchor
     $anchor = Anchors::get($item['anchor']);
     // the url to view this item
     $url = Articles::get_permalink($item);
     // reset the rendering engine between items
     Codes::initialize($url);
     // build a title
     if (is_object($overlay)) {
         $title = Codes::beautify_title($overlay->get_text('title', $item));
     } else {
         $title = Codes::beautify_title($item['title']);
     }
     // title prefix & suffix
     $text = $prefix = $suffix = '';
     // flag articles updated recently
     if ($context['site_revisit_after'] < 1) {
         $context['site_revisit_after'] = 2;
     }
     $context['fresh'] = gmstrftime('%Y-%m-%d %H:%M:%S', mktime(0, 0, 0, date("m"), date("d") - $context['site_revisit_after'], date("Y")));
     // link to permalink
     if (Surfer::is_empowered()) {
         $title = Skin::build_box_title($title, $url, i18n::s('Permalink'));
     }
     // signal articles to be published
     if ($item['publish_date'] <= NULL_DATE) {
         $prefix .= DRAFT_FLAG;
     } else {
         if ($item['publish_date'] > NULL_DATE && $item['publish_date'] > $context['now']) {
             $prefix .= DRAFT_FLAG;
         }
     }
     // signal restricted and private articles
     if ($item['active'] == 'N') {
         $prefix .= PRIVATE_FLAG . ' ';
     } elseif ($item['active'] == 'R') {
         $prefix .= RESTRICTED_FLAG . ' ';
     }
     // signal locked articles
     if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
         $suffix .= LOCKED_FLAG;
     }
     // flag expired article
     if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
         $suffix .= EXPIRED_FLAG;
     }
     // update page title directly
     $text .= Skin::build_block($prefix . $title . $suffix, 'title');
     // if this article has a specific icon, use it
     if ($item['icon_url']) {
         $icon = $item['icon_url'];
     } elseif ($item['anchor'] && ($anchor = Anchors::get($item['anchor']))) {
         $icon = $anchor->get_icon_url();
     }
     // if we have a valid image
     if (preg_match('/(.gif|.jpg|.jpeg|.png)$/i', $icon)) {
         // fix relative path
         if (!preg_match('/^(\\/|http:|https:|ftp:)/', $icon)) {
             $icon = $context['url_to_root'] . $icon;
         }
         // flush the image on the right
         $text .= '<img src="' . $icon . '" class="right_image" alt="" />';
     }
     // article rating, if the anchor allows for it
     if (!is_object($anchor) || !$anchor->has_option('without_rating')) {
         // report on current rating
         $label = '';
         if ($item['rating_count']) {
             $label = Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])) . ' ';
         }
         $label .= i18n::s('Rate this page');
         // allow for rating
         $text .= Skin::build_link(Articles::get_url($item['id'], 'like'), $label, 'basic');
     }
     // the introduction text, if any
     if (is_object($overlay)) {
         $text .= Skin::build_block($overlay->get_text('introduction', $item), 'introduction');
     } else {
         $text .= Skin::build_block($item['introduction'], 'introduction');
     }
     // insert overlay data, if any
     if (is_object($overlay)) {
         $text .= $overlay->get_text('view', $item);
     }
     // the beautified description, which is the actual page body
     if ($item['description']) {
         // use adequate label
         if (is_object($overlay) && ($label = $overlay->get_label('description'))) {
             $text .= Skin::build_block($label, 'title');
         }
         $text .= Skin::build_block($item['description'], 'description', '', $item['options']);
     }
     //
     // list related files
     //
     // if this surfer is an editor of this article, show hidden files as well
     if (Articles::is_assigned($item['id']) || is_object($anchor) && $anchor->is_assigned()) {
         Surfer::empower();
     }
     // build a complete box
     $box['bar'] = array();
     $box['text'] = '';
     // count the number of files in this article
     if ($count = Files::count_for_anchor('article:' . $item['id'])) {
         if ($count > 20) {
             $box['bar'] += array('_count' => sprintf(i18n::ns('%d file', '%d files', $count), $count));
         }
         // list files by date (default) or by title (option files_by_title)
         if (Articles::has_option('files_by', $anchor, $item) == 'title') {
             $items = Files::list_by_title_for_anchor('article:' . $item['id'], 0, FILES_PER_PAGE, 'article:' . $item['id']);
         } else {
             $items = Files::list_by_date_for_anchor('article:' . $item['id'], 0, FILES_PER_PAGE, 'article:' . $item['id']);
         }
         if (is_array($items)) {
             $box['text'] .= Skin::build_list($items, 'decorated');
         }
         // navigation commands for files
         $prefix = Articles::get_url($item['id'], 'navigate', 'files');
         $box['bar'] += Skin::navigate($url, $prefix, $count, FILES_PER_PAGE, 0);
         // the command to post a new file, if allowed
         if (Files::allow_creation($item, $anchor, 'article')) {
             $link = 'files/edit.php?anchor=' . urlencode('article:' . $item['id']);
             $box['bar'] += array($link => i18n::s('Add a file'));
         }
         if (is_array($box['bar'])) {
             $box['text'] .= Skin::build_list($box['bar'], 'menu_bar');
         }
     }
     // actually render the html for this box
     if ($box['text']) {
         $text .= Skin::build_box(i18n::s('Files'), $box['text'], 'header1', 'files');
     }
     //
     // bottom page menu
     //
     // discuss this page, if the index page can be commented, and comments are accepted at the article level
     if (Comments::allow_creation($item, $anchor)) {
         $this->menu[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'comment'), i18n::s('Post a comment'), 'span');
     }
     // info on related comments
     if ($count = Comments::count_for_anchor('article:' . $item['id'])) {
         $this->menu[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'list'), sprintf(i18n::ns('%d comment', '%d comments', $count), $count), 'span');
     }
     // new links are accepted at the index page and at the article level
     if (Links::allow_trackback()) {
         $this->menu[] = Skin::build_link('links/trackback.php?anchor=' . urlencode('article:' . $item['id']), i18n::s('Reference this page'), 'span');
     }
     // info on related links
     if ($count = Links::count_for_anchor('article:' . $item['id'])) {
         $this->menu[] = Skin::build_link($url . '#_attachments', sprintf(i18n::ns('%d link', '%d links', $count), $count), 'span');
     }
     // new files are accepted at the index page and at the article level
     if (is_object($anchor) && $anchor->has_option('with_files') && !($anchor->has_option('no_files') || preg_match('/\\bno_files\\b/i', $item['options']))) {
         // add a file
         if (Files::allow_creation($item, $anchor, 'article')) {
             if ($context['with_friendly_urls'] == 'Y') {
                 $link = 'files/edit.php/article/' . $item['id'];
             } else {
                 $link = 'files/edit.php?anchor=' . urlencode('article:' . $item['id']);
             }
             $this->menu[] = Skin::build_link($link, i18n::s('Add a file'), 'span');
         }
     }
     // modify this page
     if (Surfer::is_empowered()) {
         $this->menu[] = Skin::build_link(Articles::get_url($item['id'], 'edit'), i18n::s('Edit'), 'span');
     }
     // view permalink
     if (Surfer::is_empowered()) {
         $this->menu[] = Skin::build_link($url, i18n::s('Permalink'), 'span');
     }
     // insert overlay data, if any
     if (is_object($overlay)) {
         $text .= $overlay->get_text('trailer', $item);
     }
     // add trailer information from this item, if any
     if (isset($item['trailer']) && trim($item['trailer'])) {
         $text .= Codes::beautify($item['trailer']);
     }
     // returned the formatted content
     return $text;
 }
示例#4
0
 /**
  * list articles for search requests
  *
  * @param resource the SQL result
  * @return array of resulting items ($score, $summary), or NULL
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return an array of array($score, $summary)
     $items = array();
     // empty list
     if (!SQL::count($result)) {
         return $items;
     }
     // 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)) {
         // one box at a time
         $box = '';
         // 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;
         }
         // 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);
         }
         // details
         $details = array();
         // the author
         if ($item['create_name'] != $item['edit_name']) {
             $details[] = sprintf(i18n::s('by %s, %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id']), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']));
         } else {
             $details[] = sprintf(i18n::s('by %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id']));
         }
         // 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'])) {
             $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'])) {
             $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');
         }
         // the main anchor link
         if (is_object($anchor)) {
             $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'section'));
         }
         // display all tags
         if ($item['tags']) {
             $details[] = '<span class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</span>';
         }
         // combine in-line details
         if (count($details)) {
             $suffix .= '<p class="details">' . Skin::finalize_list($details, 'menu') . '</p>';
         }
         // insert a suffix separator
         if (trim($suffix)) {
             $suffix = ' ' . $suffix;
         }
         // item summary
         $box .= $prefix . Skin::build_link($url, $title, 'article') . $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();
         }
         // build the complete HTML element
         if ($icon) {
             $icon = '<img src="' . $icon . '" alt="" title="' . encode_field(strip_tags($title)) . '" />';
             // make it a clickable link
             $icon = Skin::build_link($url, $icon, 'basic');
             // default icon
         } else {
             $icon = DECORATED_IMG;
         }
         // layout this item
         $list = array(array($box, $icon));
         $items[] = array($item['score'], Skin::finalize_list($list, 'decorated'));
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
示例#5
0
// review command provided to container owners
if (is_object($anchor) && $anchor->is_owned()) {
    Skin::define_img('ARTICLES_STAMP_IMG', 'articles/stamp.gif');
    $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'stamp'), ARTICLES_STAMP_IMG . i18n::s('Stamp'));
}
// lock command provided to associates and authenticated editors
if (Articles::is_owned($item, $anchor)) {
    if (!isset($item['locked']) || $item['locked'] == 'N') {
        Skin::define_img('ARTICLES_LOCK_IMG', 'articles/lock.gif');
        $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'lock'), ARTICLES_LOCK_IMG . i18n::s('Lock'));
    } else {
        Skin::define_img('ARTICLES_UNLOCK_IMG', 'articles/unlock.gif');
        $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'lock'), ARTICLES_UNLOCK_IMG . i18n::s('Unlock'));
    }
}
// delete command
if (Articles::allow_deletion($item, $anchor)) {
    Skin::define_img('ARTICLES_DELETE_IMG', 'articles/delete.gif');
    $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'delete'), ARTICLES_DELETE_IMG . i18n::s('Delete this page'));
}
// duplicate command provided to container owners
if (Articles::is_owned(NULL, $anchor)) {
    Skin::define_img('ARTICLES_DUPLICATE_IMG', 'articles/duplicate.gif');
    $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'duplicate'), ARTICLES_DUPLICATE_IMG . i18n::s('Duplicate this page'));
}
// use date of last modification into etag computation
if (isset($item['edit_date'])) {
    $context['page_date'] = $item['edit_date'];
}
// render the skin
render_skin();
示例#6
0
文件: view.php 项目: rair/yacs
}
// page title
if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > $context['now']) {
    $context['page_title'] .= DRAFT_FLAG;
}
if (isset($item['active']) && $item['active'] == 'R') {
    $context['page_title'] .= RESTRICTED_FLAG;
} elseif (isset($item['active']) && $item['active'] == 'N') {
    $context['page_title'] .= PRIVATE_FLAG;
}
if (is_object($overlay)) {
    $context['page_title'] .= $overlay->get_text('title', $item);
} elseif (isset($item['title'])) {
    $context['page_title'] .= $item['title'];
}
if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
    $context['page_title'] .= ' ' . LOCKED_FLAG;
}
// page language, if any
if (isset($item['language']) && $item['language'] && $item['language'] != 'none') {
    $context['page_language'] = $item['language'];
}
// page canonical link
$context['page_link'] = Articles::get_permalink($item);
// not found -- help web crawlers
if (!isset($item['id'])) {
    include '../error.php';
    // permission denied
} elseif (!$permitted) {
    // make it clear to crawlers
    if (Surfer::is_crawler()) {
示例#7
0
 /**
  * list articles as topics in a forum
  *
  * @param resource the SQL result
  * @return string the rendered text
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // start a table
     $text .= Skin::table_prefix('jive');
     // headers
     $text .= Skin::table_row(array(i18n::s('Topic'), i18n::s('Content')), 'header');
     // build a list of articles
     $odd = FALSE;
     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 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']);
         }
         // one row per article
         $text .= '<tr class="' . ($odd ? 'odd' : 'even') . '"><td>';
         $odd = !$odd;
         // signal articles to be published
         if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) {
             $text .= DRAFT_FLAG;
         }
         // signal restricted and private articles
         if ($item['active'] == 'N') {
             $text .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $text .= RESTRICTED_FLAG;
         }
         // use the title as a link to the page
         $text .= Skin::build_link($url, '<strong>' . $title . '</strong>', 'basic');
         // signal locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $text .= ' ' . LOCKED_FLAG;
         }
         // flag articles updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $text .= ' ' . EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $text .= ' ' . NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $text .= ' ' . UPDATED_FLAG;
         }
         // add details, if any
         $details = array();
         // poster name
         if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
             if ($item['create_name']) {
                 $details[] = sprintf(i18n::s('posted by %s %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id']), Skin::build_date($item['create_date']));
             }
         }
         // last update
         $details[] = sprintf(i18n::s('Updated %s'), Skin::build_date($item['edit_date']));
         // add details to the title
         if (count($details)) {
             $text .= '<p class="details" style="margin: 3px 0">' . join(', ', $details) . '</p>';
         }
         // display all tags
         if ($item['tags']) {
             $text .= '<p class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</p>';
         }
         // next cell for the content
         $text .= '</td><td width="70%">';
         // the content to be displayed
         $content = '';
         // rating
         if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) {
             $content .= Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic');
         }
         // the introductory text
         if (is_object($overlay)) {
             $content .= Codes::beautify_introduction($overlay->get_text('introduction', $item));
         } else {
             $content .= Codes::beautify_introduction($item['introduction']);
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $content .= $overlay->get_text('list', $item);
         }
         // the description
         $content .= Skin::build_block($item['description'], 'description', '', $item['options']);
         // attachment details
         $details = array();
         // info on related files
         if ($count = Files::count_for_anchor('article:' . $item['id'])) {
             Skin::define_img('FILES_LIST_IMG', 'files/list.gif');
             $details[] = Skin::build_link($url . '#_attachments', FILES_LIST_IMG . sprintf(i18n::ns('%d file', '%d files', $count), $count), 'span');
         }
         // info on related links
         if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
             Skin::define_img('LINKS_LIST_IMG', 'links/list.gif');
             $details[] = LINKS_LIST_IMG . sprintf(i18n::ns('%d link', '%d links', $count), $count);
         }
         // count replies
         if ($count = Comments::count_for_anchor('article:' . $item['id'])) {
             $details[] = Skin::build_link($url . '#_discussion', sprintf(i18n::ns('%d comment', '%d comments', $count), $count), 'span');
         }
         // the command to reply
         if (Comments::allow_creation($item, $anchor)) {
             Skin::define_img('COMMENTS_ADD_IMG', 'comments/add.gif');
             $details[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'comment'), COMMENTS_ADD_IMG . i18n::s('Post a comment'), 'span');
         }
         // describe attachments
         $content .= Skin::finalize_list($details, 'menu_bar');
         // end the row
         $text .= $content . '</td></tr>';
     }
     // end of processing
     SQL::free($result);
     // return the table
     $text .= Skin::table_suffix();
     return $text;
 }
示例#8
0
 /**
  * list articles as rows in a table
  *
  * @param resource the SQL result
  * @return string the rendered text
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // build a list of articles
     $rows = array();
     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
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Articles::get_permalink($item);
         // reset everything
         $id = $summary = $owner = $type = $status = $update = $progress = '';
         // link to the page
         $id = Skin::build_link($url, $item['id'], 'basic');
         // signal articles to be published
         if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) {
             $summary .= DRAFT_FLAG;
         }
         // signal restricted and private articles
         if ($item['active'] == 'N') {
             $summary .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $summary .= RESTRICTED_FLAG;
         }
         // indicate the id in the hovering popup
         $hover = i18n::s('View the page');
         if (Surfer::is_member()) {
             $hover .= ' [article=' . $item['id'] . ']';
         }
         // use the title to label the link
         if (is_object($overlay)) {
             $label = Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $label = Codes::beautify_title($item['title']);
         }
         // use the title as a link to the page
         $summary .= Skin::build_link($url, $label, 'basic', $hover);
         // signal locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $summary .= ' ' . LOCKED_FLAG;
         }
         // flag articles updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $summary .= ' ' . EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $summary .= ' ' . NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $summary .= ' ' . UPDATED_FLAG;
         }
         // attachment details
         $details = array();
         // info on related files
         if ($count = Files::count_for_anchor('article:' . $item['id'])) {
             Skin::define_img('FILES_LIST_IMG', 'files/list.gif');
             $details[] = FILES_LIST_IMG . sprintf(i18n::ns('%d file', '%d files', $count), $count);
         }
         // info on related links
         if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
             Skin::define_img('LINKS_LIST_IMG', 'links/list.gif');
             $details[] = LINKS_LIST_IMG . sprintf(i18n::ns('%d link', '%d links', $count), $count);
         }
         // comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
             Skin::define_img('COMMENTS_LIST_IMG', 'comments/list.gif');
             $details[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'list'), COMMENTS_LIST_IMG . sprintf(i18n::ns('%d comment', '%d comments', $count), $count));
         }
         // combine in-line details
         if (count($details)) {
             $summary .= ' <span class="details">' . trim(implode(' ', $details)) . '</span>';
         }
         // dates
         $summary .= BR . '<span class="details">' . join(BR, Articles::build_dates($anchor, $item)) . '</span>';
         // display all tags
         if ($item['tags']) {
             $summary .= BR . '<span class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</span>';
         }
         // page owner
         if (isset($item['owner_id']) && ($owner = Users::get($item['owner_id']))) {
             $owner = Users::get_link($owner['full_name'], $owner['email'], $owner['id']);
         }
         // type is provided by the overlay
         if (is_object($overlay)) {
             $type = $overlay->get_value('type', '');
         }
         // status value
         if (is_object($overlay)) {
             $status = $overlay->get_value('status', '');
         }
         // progress value
         if (is_object($overlay)) {
             $progress = $overlay->get_value('progress', '');
         }
         // this is another row of the output
         $cells = array($id, $summary, $owner, $type, $status, $progress);
         // append this row
         $rows[] = $cells;
     }
     // end of processing
     SQL::free($result);
     // headers
     $headers = array(i18n::s('Number'), i18n::s('Information'), i18n::s('Owner'), i18n::s('Type'), i18n::s('Status'), i18n::s('Progress'));
     // return a sortable table
     $text .= Skin::table($headers, $rows, 'grid');
     return $text;
 }
示例#9
0
文件: list.php 项目: rair/yacs
if ($id) {
    $anchor = Anchors::get($id);
}
// which page should be displayed
if (isset($_REQUEST['page'])) {
    $page = $_REQUEST['page'];
} elseif (isset($context['arguments'][2])) {
    $page = $context['arguments'][2];
} else {
    $page = 1;
}
$page = max(1, intval($page));
// only anchor owners can proceed
if (is_object($anchor) && $anchor->is_owned()) {
    $permitted = TRUE;
} elseif (is_object($anchor) && $anchor->get_type() == 'article' && Articles::is_owned(NULL, $anchor)) {
    $permitted = TRUE;
} elseif (is_object($anchor) && $anchor->get_type() == 'section' && Sections::is_owned(NULL, $anchor)) {
    $permitted = TRUE;
} else {
    $permitted = FALSE;
}
// load the skin, maybe with a variant
load_skin('versions', $anchor);
if (!defined('VERSIONS_PER_PAGE')) {
    define('VERSIONS_PER_PAGE', 25);
}
// clear the tab we are in, if any
if (is_object($anchor)) {
    $context['current_focus'] = $anchor->get_focus();
}
示例#10
0
 /**
  * list articles for manual review
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @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;
     }
     // 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 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 = '';
         // 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;
         }
         // details
         $details = array();
         // the author(s)
         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);
         }
         // append details to the suffix
         $suffix .= ' -&nbsp;<span class="details">' . ucfirst(trim(implode(', ', $details))) . '</span>';
         // commands to review the article
         $menu = array();
         // read the page
         $menu = array_merge($menu, array($url => i18n::s('Read')));
         // validate the page
         $menu = array_merge($menu, array('articles/stamp.php?id=' . $item['id'] . '&amp;confirm=review' => i18n::s('Validate')));
         // add a menu
         $suffix .= ' ' . Skin::build_list($menu, 'menu');
         // list all components for this item
         $items[$url] = array($prefix, $title, $suffix, 'basic', NULL);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
示例#11
0
文件: edit.php 项目: rair/yacs
 //
 $text = '';
 // provide information to section owner
 if (isset($item['id'])) {
     // owner
     $label = i18n::s('Owner');
     $input = '';
     if (isset($item['owner_id'])) {
         if ($owner = Users::get($item['owner_id'])) {
             $input = Users::get_link($owner['full_name'], $owner['email'], $owner['id']);
         } else {
             $input = i18n::s('No owner has been found.');
         }
     }
     // change the owner
     if (Articles::is_owned($item, $anchor) || Surfer::is_associate()) {
         $input .= ' <span class="details">' . Skin::build_link(Articles::get_url($item['id'], 'own'), i18n::s('Change'), 'button') . '</span>';
     }
     $fields[] = array($label, $input);
 }
 // the active flag: Yes/public, Restricted/logged, No/associates --we don't care about inheritance, to enable security changes afterwards
 if (!isset($item['id']) || $cur_article->is_owned() || Surfer::is_associate()) {
     $label = i18n::s('Access');
     $input = Skin::build_active_set_input($item);
     $hint = Skin::build_active_set_hint($anchor);
     $fields[] = array($label, $input, $hint);
 }
 // locked: Yes / No
 $label = i18n::s('Locker');
 $input = '<input type="radio" name="locked" value="N"';
 if (!isset($item['locked']) || $item['locked'] != 'Y') {
示例#12
0
 /**
  * list articles
  *
  * @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;
     }
     // 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 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;
         }
         // 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;
         }
         // rating
         if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) {
             $suffix .= Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count']));
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
             $suffix .= ' (' . $count . ')';
         }
         // details
         $details = array();
         // 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);
         }
         // flag popular pages
         if ($item['hits'] > 300) {
             $details[] = POPULAR_FLAG;
         }
         // 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 .= ' - <span class="details">' . trim(implode(', ', $details)) . '</span>';
         }
         // list all components for this item
         $items[$url] = array($prefix, $title, $suffix, 'article', $icon);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
示例#13
0
 /**
  * list articles as rows in a table
  *
  * @param resource the SQL result
  * @return string the rendered text
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // we list pages for one surfer
     // sanity check
     if (!isset($this->focus)) {
         $this->focus = Surfer::get_id();
     }
     // build a list of articles
     Skin::define_img('CHECKED_IMG', 'ajax/accept.png', '*');
     $rows = array();
     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
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Articles::get_permalink($item);
         // reset everything
         $summary = $update = $owner = $editor = $watcher = '';
         // signal articles to be published
         if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) {
             $summary .= DRAFT_FLAG;
         }
         // signal restricted and private articles
         if ($item['active'] == 'N') {
             $summary .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $summary .= RESTRICTED_FLAG;
         }
         // indicate the id in the hovering popup
         $hover = i18n::s('View the page');
         if (Surfer::is_member()) {
             $hover .= ' [article=' . $item['id'] . ']';
         }
         // use the title to label the link
         if (is_object($overlay)) {
             $label = Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $label = Codes::beautify_title($item['title']);
         }
         // use the title as a link to the page
         $summary .= Skin::build_link($url, $label, 'basic', $hover);
         // signal locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $summary .= ' ' . LOCKED_FLAG;
         }
         // flag articles updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $summary .= ' ' . EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $summary .= ' ' . NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $summary .= ' ' . UPDATED_FLAG;
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $summary .= $overlay->get_text('list', $item);
         }
         // attachment details
         $details = array();
         // 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);
         }
         // comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
         }
         // 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()), 'basic'));
         }
         // combine in-line details
         if (count($details)) {
             $summary .= BR . '<span class="details">' . trim(implode(' &middot; ', $details)) . '</span>';
         }
         // display all tags
         if ($item['tags']) {
             $summary .= BR . '<span class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</span>';
         }
         // dates
         //			$update = '<span class="details">'.join(BR, Articles::build_dates($anchor, $item)).'</span>';
         // watcher
         if (Articles::is_watched($item['id'], $this->focus)) {
             $watcher = CHECKED_IMG;
         }
         // editor
         if (Articles::is_assigned($item['id'], $this->focus)) {
             $editor = CHECKED_IMG;
         }
         // owner
         if (isset($item['owner_id']) && $item['owner_id'] == $this->focus) {
             $owner = CHECKED_IMG;
         }
         // this is another row of the output
         //			$cells = array($summary, $update, $watcher, $editor, $owner);
         $cells = array($summary, $watcher, $editor, $owner);
         // append this row
         $rows[] = $cells;
     }
     // end of processing
     SQL::free($result);
     // headers
     //		$headers = array(i18n::s('Page'), i18n::s('Dates'), i18n::s('Watcher'), i18n::s('Editor'), i18n::s('Owner'));
     $headers = array(i18n::s('Page'), i18n::s('Watcher'), i18n::s('Editor'), i18n::s('Owner'));
     // return a sortable table
     $text .= Skin::table($headers, $rows, 'grid');
     return $text;
 }
示例#14
0
 /**
  * list articles
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // build a list of articles
     $item_count = 0;
     $items = array();
     include_once $context['path_to_root'] . 'articles/article.php';
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     while ($item = SQL::fetch($result)) {
         // next item
         $item_count += 1;
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Articles::get_permalink($item);
         // one box per article
         $prefix = $suffix = $icon = '';
         // build a box around two first articles
         if ($item_count == 1) {
             $text .= '<div class="recent">' . "\n";
         } elseif ($item_count == 3) {
             $text .= '</div><br style="clear: left;" />' . "\n";
         }
         // layout newest articles
         if ($item_count < 3) {
             // style to apply
             switch ($item_count) {
                 case 1:
                     $text .= '<div class="left">';
                     break;
                 case 2:
                     $text .= '<div class="right">';
                     break;
             }
             // the icon to put aside
             if ($item['thumbnail_url']) {
                 $icon = $item['thumbnail_url'];
             } elseif (is_object($anchor)) {
                 $icon = $anchor->get_thumbnail_url();
             }
             if ($icon) {
                 $text .= '<a href="' . $context['url_to_root'] . $url . '" title="' . i18n::s('View the page') . '"><img src="' . $icon . '" class="left_image" alt="" /></a>';
             }
             $text .= $this->layout_newest($item, $anchor) . '</div>' . "\n";
             // layout recent articles
         } else {
             // 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']);
             }
             // 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 introductory text
             $introduction = '';
             if (is_object($overlay)) {
                 $introduction .= Codes::beautify_introduction($overlay->get_text('introduction', $item));
             } elseif ($item['introduction']) {
                 $introduction .= Codes::beautify_introduction($item['introduction']);
             } else {
                 $introduction .= Skin::cap(Codes::beautify($item['description'], $item['options']), 70);
             }
             if ($introduction) {
                 $suffix .= ' -&nbsp;' . $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();
             // 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');
             }
             // combine in-line details
             if (count($details)) {
                 $suffix .= ucfirst(trim(implode(', ', $details)));
             }
             // unusual ranks are signaled to associates
             if ($item['rank'] != 10000 && Articles::is_owned($item, $anchor)) {
                 $suffix .= ' {' . $item['rank'] . '} ';
             }
             // list categories by title, if any
             $anchors = array();
             if ($members =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 5, 'raw')) {
                 foreach ($members as $id => $attributes) {
                     // add background color to distinguish this category against others
                     if (isset($attributes['background_color']) && $attributes['background_color']) {
                         $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>';
                     }
                     if ($this->focus != 'category:' . $id) {
                         $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic');
                     }
                 }
             }
             // list section and categories in the suffix
             if (@count($anchors)) {
                 $suffix .= BR . sprintf(i18n::s('In %s'), implode(', ', $anchors));
             }
             // end of details
             $suffix .= '</span>';
             // strip empty details
             $suffix = str_replace(BR . '<span class="details"></span>', '', $suffix);
             $suffix = str_replace('<span class="details"></span>', '', $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);
         }
     }
     // extend the #home_south in case of floats
     if ($item_count > 1 && $item_count < 3) {
         $text .= '<p style="clear: left;">&nbsp;</p></div>' . "\n";
     }
     // turn the list to a string
     if (count($items)) {
         $text .= Skin::build_list($items, 'decorated');
     }
     // end of processing
     SQL::free($result);
     return $text;
 }
示例#15
0
 /**
  * list articles as topics in a forum
  *
  * @param resource the SQL result
  * @return string the rendered text
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // allow for complete styling
     $text = '<div class="last_articles">';
     // build a list of articles
     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
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Articles::get_permalink($item);
         // build a title
         if (is_object($overlay)) {
             $title = Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $title = Codes::beautify_title($item['title']);
         }
         // reset everything
         $prefix = $label = $suffix = $icon = '';
         // signal articles to be published
         if (!isset($item['publish_date']) || $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;
         }
         // flag expired articles
         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 locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $suffix .= ' ' . LOCKED_FLAG;
         }
         // rating
         if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) {
             $suffix .= ' ' . Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic');
         }
         // indicate the id in the hovering popup
         $hover = i18n::s('View the page');
         if (Surfer::is_member()) {
             $hover .= ' [article=' . $item['id'] . ']';
         }
         // one box per update
         $text .= '<div class="last_article" >';
         // use the title as a link to the page
         $text .= Skin::build_block($prefix . ucfirst($title) . $suffix, 'header1');
         // some details about this page
         $details = array();
         // page starter and date
         if ($item['create_name']) {
             $details[] = sprintf(i18n::s('Started by %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id'])) . ' ' . Skin::build_date($item['create_date']);
         }
         // page last modification
         if ($item['edit_date'] && $item['edit_action'] == 'article:update' && $item['edit_name']) {
             $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . sprintf(i18n::s('by %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id'])) . ' ' . Skin::build_date($item['edit_date']);
         }
         // friends
         if ($friends =& Members::list_users_by_posts_for_anchor('article:' . $item['id'], 0, USERS_LIST_SIZE, 'comma5', $item['create_id'])) {
             $details[] = sprintf(i18n::s('with %s'), $friends);
         }
         // people details
         if ($details) {
             $text .= '<p class="details">' . join(', ', $details) . "</p>\n";
         }
         // the introductory text
         $introduction = '';
         if (is_object($overlay)) {
             $introduction = $overlay->get_text('introduction', $item);
         } elseif ($item['introduction']) {
             $introduction = $item['introduction'];
         }
         if ($introduction) {
             $text .= '<div style="margin: 1em 0;">' . Codes::beautify_introduction($introduction) . '</div>';
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $text .= $overlay->get_text('list', $item);
         }
         // info on related comments
         if (($count = Comments::count_for_anchor('article:' . $item['id'])) > 1) {
             $text .= '<div style="margin-top: 1em;"><p class="details">' . sprintf(i18n::s('%d contributions, including:'), $count) . '</p></div>';
         }
         // avoid first file if mentioned in last contribution
         $file_offset = 0;
         // get last contribution for this page
         if ($comment = Comments::get_newest_for_anchor('article:' . $item['id'])) {
             if (preg_match('/\\[(download|file)=/', $comment['description'])) {
                 $file_offset++;
             }
             // bars around the last contribution
             $bottom_menu = array();
             // last contributor
             $contributor = Users::get_link($comment['create_name'], $comment['create_address'], $comment['create_id']);
             $flag = '';
             if ($comment['create_date'] >= $context['fresh']) {
                 $flag = NEW_FLAG;
             } elseif ($comment['edit_date'] >= $context['fresh']) {
                 $flag = UPDATED_FLAG;
             }
             $bottom_menu[] = sprintf(i18n::s('By %s'), $contributor) . ' ' . Skin::build_date($comment['create_date']) . $flag;
             // offer to reply
             if (Comments::allow_creation($item, $anchor)) {
                 $link = Comments::get_url($comment['id'], 'reply');
                 $bottom_menu[] = Skin::build_link($link, i18n::s('Reply'), 'basic');
             }
             // gather pieces
             $pieces = array();
             // last contribution, and user signature
             $pieces[] = ucfirst(trim($comment['description'])) . Users::get_signature($comment['create_id']);
             // bottom
             if ($bottom_menu) {
                 $pieces[] = '<div style="margin-top: 1em;">' . ucfirst(trim(Skin::finalize_list($bottom_menu, 'menu'))) . '</div>';
             }
             // put all pieces together
             $text .= '<div class="last_comment">' . "\n" . join("\n", $pieces) . '</div>' . "\n";
         }
         // list more recent files
         if ($items = Files::list_by_date_for_anchor('article:' . $item['id'], $file_offset, 3, 'dates')) {
             // more files than listed
             $more = '';
             if (($count = Files::count_for_anchor('article:' . $item['id'])) > 3) {
                 $more = '<span class="details">' . sprintf(i18n::s('%d files, including:'), $count) . '</span>';
             }
             if (is_array($items)) {
                 $items = Skin::build_list($items, 'compact');
             }
             $text .= '<div style="margin: 1em 0;">' . $more . $items . '</div>';
         }
         // display all tags
         if ($item['tags']) {
             $text .= ' <p class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</p>';
         }
         // navigation links
         $menu = array();
         // permalink
         $menu[] = Skin::build_link($url, i18n::s('View the page'), 'span');
         // info on related links
         if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
             $menu[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
         }
         // the main anchor link
         if (is_object($anchor) && (!isset($this->focus) || $item['anchor'] != $this->focus)) {
             $menu[] = Skin::build_link($anchor->get_url(), sprintf(i18n::s('in %s'), ucfirst($anchor->get_title())), 'span', i18n::s('View the section'));
         }
         // actually insert details
         $text .= Skin::finalize_list($menu, 'menu_bar');
         // bottom of the box
         $text .= '</div>';
     }
     // close the list of articles
     $text .= '</div>';
     // beautify everything at once
     $text = Codes::beautify($text);
     // end of processing
     SQL::free($result);
     // done
     return $text;
 }
示例#16
0
 /**
  * list articles as slashdot do
  *
  * @param resource the SQL result
  * @return string the rendered text
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // build a list of articles
     include_once $context['path_to_root'] . 'articles/article.php';
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     $class = 'even';
     while ($item = SQL::fetch($result)) {
         // get the related overlay
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the 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']);
         }
         // reset everything
         $content = $prefix = $label = $suffix = $icon = '';
         // the icon to put aside
         if ($item['thumbnail_url']) {
             $icon = $item['thumbnail_url'];
         }
         if ($icon) {
             $icon = '<a href="' . $context['url_to_root'] . $url . '"><img src="' . $icon . '" class="right_image" alt="" title="' . encode_field(i18n::s('More')) . '" /></a>';
         }
         // flag sticky pages
         if ($item['rank'] < 10000) {
             $prefix .= STICKY_FLAG;
         }
         // signal articles to be published
         if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > $context['now']) {
             $prefix .= DRAFT_FLAG;
         }
         // signal restricted and private articles
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // signal locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $suffix .= ' ' . LOCKED_FLAG;
         }
         // flag articles updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $suffix .= ' ' . EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix .= ' ' . NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= ' ' . UPDATED_FLAG;
         }
         // rating
         if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) {
             $suffix .= Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic');
         }
         // the full introductory text
         if ($item['introduction']) {
             $content .= Codes::beautify_introduction($item['introduction']);
         } elseif (!is_object($overlay)) {
             $article = new Article();
             $article->load_by_content($item);
             $content .= $article->get_teaser('teaser');
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $content .= $overlay->get_text('list', $item);
         }
         // add details
         $details = array();
         // the author
         if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
             if ($item['edit_name'] == $item['create_name']) {
                 $details[] = sprintf(i18n::s('by %s'), ucfirst($item['create_name']));
             } else {
                 $details[] = sprintf(i18n::s('by %s, %s'), ucfirst($item['create_name']), ucfirst($item['edit_name']));
             }
         }
         // the modification date
         if ($item['edit_date'] > NULL_DATE) {
             $details[] = Skin::build_date($item['edit_date']);
         }
         // read the article
         $details[] = Skin::build_link($url, i18n::s('More'), 'basic');
         // info on related files
         if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) {
             $details[] = Skin::build_link($url . '#_attachments', sprintf(i18n::ns('%d file', '%d files', $count), $count), 'basic');
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
             $link = Comments::get_url('article:' . $item['id'], 'list');
             $details[] = Skin::build_link($link, sprintf(i18n::ns('%d comment', '%d comments', $count), $count), 'basic');
         }
         // discuss
         if (Comments::allow_creation($item, $anchor)) {
             $details[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'comment'), i18n::s('Discuss'), 'basic');
         }
         // info on related links
         if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
             $details[] = Skin::build_link($url . '#_attachments', sprintf(i18n::ns('%d link', '%d links', $count), $count), 'basic');
         }
         // list categories by title, if any
         if ($items =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) {
             foreach ($items as $id => $attributes) {
                 // add background color to distinguish this category against others
                 if (isset($attributes['background_color']) && $attributes['background_color']) {
                     $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>';
                 }
                 $details[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic');
             }
         }
         // details
         if (count($details)) {
             $content .= '<div><span class="details">' . ucfirst(implode(' - ', $details)) . '</span></div>';
         }
         // insert a complete box
         $text .= Skin::build_box(Skin::build_link($url, $prefix . $title . $suffix, 'basic', i18n::s('View the page')), $icon . $content, 'header1 ' . $class, 'article_' . $item['id']);
         // stack boxes
         if ($class == 'even') {
             $class = 'odd';
         } else {
             $class = 'even';
         }
     }
     // end of processing
     SQL::free($result);
     return $text;
 }
示例#17
0
文件: duplicate.php 项目: rair/yacs
    $context['current_focus'] = $anchor->get_focus();
}
// path to this page
$context['path_bar'] = Surfer::get_path_bar($anchor);
if (isset($item['id'])) {
    $context['path_bar'] = array_merge($context['path_bar'], array(Articles::get_permalink($item) => $item['title']));
}
// page title
if (isset($item['id'])) {
    $context['page_title'] = sprintf(i18n::s('%s: %s'), i18n::s('Duplicate'), $item['title']);
}
// not found
if (!isset($item['id'])) {
    include '../error.php';
    // permission denied
} elseif (!Articles::is_owned($item, $anchor)) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // action is confirmed
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'duplicate') {
    // to duplicate related items
    $original_anchor = 'article:' . $item['id'];
    // we will get a new id and a new handle
    unset($item['id']);
    unset($item['handle']);
    // the duplicator becomes the author
    unset($item['create_address']);
    unset($item['create_date']);
    unset($item['create_id']);
    unset($item['create_name']);
    unset($item['edit_address']);
示例#18
0
 /**
  * list articles as topics in a forum
  *
  * @param resource the SQL result
  * @return string the rendered text
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // page size for comments
     include_once $context['path_to_root'] . 'comments/layout_comments_as_updates.php';
     $layout = new Layout_comments_as_updates();
     // build a list of articles
     $rows = array();
     include_once $context['path_to_root'] . 'comments/comments.php';
     while ($item = SQL::fetch($result)) {
         // get the related overlay
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Articles::get_permalink($item);
         // build a title
         if (is_object($overlay)) {
             $title = Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $title = Codes::beautify_title($item['title']);
         }
         // reset everything
         $text = $prefix = $label = $suffix = $icon = '';
         // signal articles to be published
         if (!isset($item['publish_date']) || $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;
         }
         // flag expired articles, and articles updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $suffix = EXPIRED_FLAG . ' ';
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix = NEW_FLAG . ' ';
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix = UPDATED_FLAG . ' ';
         }
         // rating
         if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) {
             $suffix .= ' ' . Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic');
         }
         // select an icon for this thread
         $item['comments_count'] = Comments::count_for_anchor('article:' . $item['id']);
         if (is_object($overlay) && $overlay->attributes['overlay_type'] == 'poll') {
             Skin::define_img('POLL_IMG', 'articles/poll.gif');
             $icon = POLL_IMG;
         } elseif ($item['rank'] < 10000) {
             Skin::define_img('STICKY_THREAD_IMG', 'articles/sticky_thread.gif');
             $icon = STICKY_THREAD_IMG;
         } elseif (isset($item['comments_count']) && $item['comments_count'] >= 20) {
             Skin::define_img('VERY_HOT_THREAD_IMG', 'articles/very_hot_thread.gif');
             $icon = VERY_HOT_THREAD_IMG;
         } elseif (isset($item['comments_count']) && $item['comments_count'] >= 10) {
             $icon = HOT_THREAD_IMG;
         } else {
             $icon = THREAD_IMG;
         }
         // indicate the id in the hovering popup
         $hover = i18n::s('View the page');
         if (Surfer::is_member()) {
             $hover .= ' [article=' . $item['id'] . ']';
         }
         // use the title as a link to the page
         $title = $prefix . Skin::build_link($url, ucfirst($title), 'basic', $hover) . $suffix;
         $suffix = '';
         // the introductory text
         $introduction = '';
         if (is_object($overlay)) {
             $introduction = $overlay->get_text('introduction', $item);
         } elseif ($item['introduction']) {
             $introduction = $item['introduction'];
         }
         if ($introduction) {
             $suffix .= BR . Codes::beautify_introduction($introduction);
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $suffix .= $overlay->get_text('list', $item);
         }
         // shortcuts to comments pages
         if (isset($item['comments_count']) && ($pages = (int) ceil($item['comments_count'] / $layout->items_per_page())) && $pages > 1) {
             $suffix .= '<p class="details">Pages ';
             for ($index = 1; $index <= $pages; $index++) {
                 $suffix .= Skin::build_link('comments/list.php?id=article:' . $item['id'] . '&amp;page=' . $index, $index, 'basic', i18n::s('One page of comments')) . ' ';
             }
             $suffix .= Skin::build_link('comments/list.php?id=article:' . $item['id'] . '&amp;page=' . $pages, MORE_IMG, 'basic', i18n::s('Most recent comments')) . '</p>';
         }
         // links to sections and categories
         $anchors = array();
         // the main anchor link
         if (is_object($anchor) && (!isset($this->focus) || $item['anchor'] != $this->focus)) {
             $anchors[] = Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'basic', i18n::s('In this section'));
         }
         // list categories by title, if any
         if ($members =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) {
             foreach ($members as $category_id => $attributes) {
                 // add background color to distinguish this category against others
                 if (isset($attributes['background_color']) && $attributes['background_color']) {
                     $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>';
                 }
                 if (!isset($this->focus) || $this->focus != 'category:' . $category_id) {
                     $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic', i18n::s('Related topics'));
                 }
             }
         }
         // list section and categories in the suffix
         if (@count($anchors)) {
             $suffix .= '<p class="tags">' . implode(' ', $anchors) . '</p>';
         }
         // the creator of this article
         $starter = '';
         if ($item['create_name']) {
             $starter = '<span class="details">' . Users::get_link($item['create_name'], $item['create_address'], $item['create_id']) . '</span>';
         }
         // the last editor
         $details = '';
         if ($item['edit_date']) {
             // find a name, if any
             $user = '';
             if ($item['edit_name']) {
                 // label the action
                 if (isset($item['edit_action'])) {
                     $user .= Anchors::get_action_label($item['edit_action']) . ' ';
                 }
                 // name of last editor
                 $user .= sprintf(i18n::s('by %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']));
             }
             $details .= $user . ' ' . Skin::build_date($item['edit_date']);
         }
         // signal locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $details .= ', ' . LOCKED_FLAG;
         }
         // poster details
         if ($details) {
             $details = '<p class="details">' . $details . "</p>\n";
         }
         if (!isset($item['comments_count'])) {
             $item['comments_count'] = 0;
         }
         // this is another row of the output
         $cells = array($title . $suffix, 'center=' . $starter, 'center=' . $item['comments_count'], 'center=' . Skin::build_number($item['hits']), $details);
         if (THREAD_IMG) {
             $cells = array_merge(array($icon), $cells);
         }
         $rows[] = $cells;
     }
     // end of processing
     SQL::free($result);
     // headers
     $headers = array(i18n::s('Topic'), 'center=' . i18n::s('Poster'), 'center=' . i18n::s('Replies'), 'center=' . i18n::s('Views'), i18n::s('Last post'));
     if (THREAD_IMG) {
         $headers = array_merge(array(''), $headers);
     }
     // make a sortable table
     $output = Skin::table($headers, $rows, 'yabb');
     return $output;
 }
示例#19
0
 /**
  * list articles as rows in a table
  *
  * @param resource the SQL result
  * @return string the rendered text
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // build a list of articles
     $rows = array();
     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
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Articles::get_permalink($item);
         // reset everything
         $title = $abstract = $author = '';
         // signal articles to be published
         if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) {
             $title .= DRAFT_FLAG;
         }
         // signal restricted and private articles
         if ($item['active'] == 'N') {
             $title .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $title .= RESTRICTED_FLAG;
         }
         // indicate the id in the hovering popup
         $hover = i18n::s('View the page');
         if (Surfer::is_member()) {
             $hover .= ' [article=' . $item['id'] . ']';
         }
         // use the title to label the link
         if (is_object($overlay)) {
             $label = Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $label = Codes::beautify_title($item['title']);
         }
         // use the title as a link to the page
         $title .= Skin::build_link($url, $label, 'basic', $hover);
         // signal locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $title .= ' ' . LOCKED_FLAG;
         }
         // flag articles updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $title .= ' ' . EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $title .= ' ' . NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $title .= ' ' . UPDATED_FLAG;
         }
         // the icon
         if ($item['thumbnail_url']) {
             $abstract .= '<a href="' . $context['url_to_root'] . $url . '"><img src="' . $item['thumbnail_url'] . '" class="right_image" alt="" /></a>';
         }
         // the introductory text
         if (is_object($overlay)) {
             $abstract .= Codes::beautify_introduction($overlay->get_text('introduction', $item));
         } elseif ($item['introduction']) {
             $abstract .= Codes::beautify_introduction($item['introduction']);
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $abstract .= $overlay->get_text('list', $item);
         }
         // make some abstract out of main text
         if (!$item['introduction'] && $context['skins_with_details'] == 'Y') {
             $abstract .= Skin::cap(Codes::beautify($item['description'], $item['options']), 50);
         }
         // attachment details
         $details = array();
         // info on related files
         if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) {
             Skin::define_img('FILES_LIST_IMG', 'files/list.gif');
             $details[] = FILES_LIST_IMG . sprintf(i18n::ns('%d file', '%d files', $count), $count);
         }
         // info on related links
         if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
             Skin::define_img('LINKS_LIST_IMG', 'links/list.gif');
             $details[] = LINKS_LIST_IMG . sprintf(i18n::ns('%d link', '%d links', $count), $count);
         }
         // comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
             Skin::define_img('COMMENTS_LIST_IMG', 'comments/list.gif');
             $details[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'list'), COMMENTS_LIST_IMG . sprintf(i18n::ns('%d comment', '%d comments', $count), $count));
         }
         // describe attachments
         if (count($details)) {
             $abstract .= '<p style="margin: 3px 0;">' . join(', ', $details) . '</p>';
         }
         // anchors
         $anchors = array();
         if ($members =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) {
             foreach ($members as $category_id => $attributes) {
                 // add background color to distinguish this category against others
                 if (isset($attributes['background_color']) && $attributes['background_color']) {
                     $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>';
                 }
                 $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic');
             }
         }
         if (@count($anchors)) {
             $abstract .= '<p class="tags" style="margin: 3px 0">' . implode(' ', $anchors) . '</p>';
         }
         // poster name
         if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
             if ($item['create_name']) {
                 $author = Users::get_link($item['create_name'], $item['create_address'], $item['create_id']);
             } else {
                 $author = Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']);
             }
         }
         // more details
         $details =& Articles::build_dates($anchor, $item);
         // 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');
         }
         // page details
         if (count($details)) {
             $details = '<p class="details">' . join(', ', $details) . '</p>';
         }
         // this is another row of the output -- title, abstract, (author,) details
         if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
             $cells = array($title, $abstract, $author, $details);
         } else {
             $cells = array($title, $abstract, $details);
         }
         // append this row
         $rows[] = $cells;
     }
     // end of processing
     SQL::free($result);
     // headers
     if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
         $headers = array(i18n::s('Topic'), i18n::s('Abstract'), i18n::s('Poster'), i18n::s('Details'));
     } else {
         $headers = array(i18n::s('Topic'), i18n::s('Abstract'), i18n::s('Details'));
     }
     // return a sortable table
     $text .= Skin::table($headers, $rows, 'grid');
     return $text;
 }
示例#20
0
    $context['page_tools'][] = Skin::build_link(Versions::get_url('article:' . $item['id'], 'list'), ARTICLES_VERSIONS_IMG . i18n::s('Versions'), 'basic', i18n::s('Restore a previous version if necessary'));
}
// publish this page
if (Articles::allow_publication($item, $anchor)) {
    if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE) {
        Skin::define_img('ARTICLES_PUBLISH_IMG', 'articles/publish.gif');
        $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'publish'), ARTICLES_PUBLISH_IMG . i18n::s('Publish'));
    }
}
// review command provided to container owners
if (is_object($anchor) && $anchor->is_owned()) {
    Skin::define_img('ARTICLES_STAMP_IMG', 'articles/stamp.gif');
    $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'stamp'), ARTICLES_STAMP_IMG . i18n::s('Stamp'));
}
// lock command provided to associates and authenticated editors
if (Articles::is_owned($item, $anchor)) {
    if (!isset($item['locked']) || $item['locked'] == 'N') {
        Skin::define_img('ARTICLES_LOCK_IMG', 'articles/lock.gif');
        $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'lock'), ARTICLES_LOCK_IMG . i18n::s('Lock'));
    } else {
        Skin::define_img('ARTICLES_UNLOCK_IMG', 'articles/unlock.gif');
        $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'lock'), ARTICLES_UNLOCK_IMG . i18n::s('Unlock'));
    }
}
// delete command
if (Articles::allow_deletion($item, $anchor)) {
    Skin::define_img('ARTICLES_DELETE_IMG', 'articles/delete.gif');
    $context['page_tools'][] = Skin::build_link(Articles::get_url($item['id'], 'delete'), ARTICLES_DELETE_IMG . i18n::s('Delete this page'));
}
// several extra boxes in a row
//
示例#21
0
 } else {
     Skin::define_img('ARTICLES_UNPUBLISH_IMG', 'articles/unpublish.gif');
     $input = ARTICLES_UNPUBLISH_IMG . i18n::s('not published');
 }
 $fields[] = array($label, $input);
 // the expiry date
 $label = i18n::s('Expiry date');
 if (isset($item['expiry_date']) && $item['expiry_date'] > NULL_DATE) {
     $input = Surfer::from_GMT($item['expiry_date']);
 } else {
     $input = i18n::s('never');
 }
 $fields[] = array($label, $input);
 // the parent section
 if (is_object($anchor)) {
     if (isset($item['id']) && Articles::is_owned($item, $anchor)) {
         $label = i18n::s('Section');
         $input =& Skin::build_box(i18n::s('Select parent container'), Sections::get_radio_buttons($anchor->get_reference()), 'folded');
         $fields[] = array($label, $input);
     } else {
         $text .= '<input type="hidden" name="anchor" value="' . $anchor->get_reference() . '" />';
     }
 }
 // append fields
 if (is_object($anchor)) {
     $label = sprintf(i18n::s('Contribution to "%s"'), $anchor->get_title());
 } else {
     $label = i18n::s('Contribution to parent container');
 }
 $text .= Skin::build_box($label, Skin::build_form($fields), 'folded');
 $fields = array();
示例#22
0
文件: articles.php 项目: rair/yacs
 /**
  * build a notification related to an article
  *
  * The action can be one of the following:
  * - 'apply' - surfer would like to get access to the page
  * - 'publish' - either a published page has been posted, or a draft page has been published
  * - 'submit' - a draft page has been posted
  * - 'update' - a page (draft or published) has been modified
  *
  * This function builds a mail message that displays:
  * - an image of the contributor (if possible)
  * - a headline mentioning the contribution
  * - the full content of the new comment
  * - a button linked to the reply page
  * - a link to the containing page
  *
  * Note: this function returns legacy HTML, not modern XHTML, because this is what most
  * e-mail client software can afford.
  *
  * @param string either 'apply', 'publish', 'submit' or 'update'
  * @param array attributes of the item
  * @param object overlay of the item, if any
  * @return string text to be send by e-mail
  */
 public static function build_notification($action = 'publish', $item, $overlay = NULL)
 {
     global $context;
     // sanity check
     if (!isset($item['anchor']) || !($anchor = Anchors::get($item['anchor']))) {
         throw new Exception('no anchor for this article');
     }
     // compute page title
     if (is_object($overlay)) {
         $title = Codes::beautify_title($overlay->get_text('title', $item));
     } else {
         $title = Codes::beautify_title($item['title']);
     }
     // headline link to section
     $headline_link = '<a href="' . $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url() . '">' . $anchor->get_title() . '</a>';
     // headline template
     switch ($action) {
         case 'apply':
             $template = i18n::c('%s is requesting access to %s');
             $headline_link = '<a href="' . Articles::get_permalink($item) . '">' . $title . '</a>';
             break;
         case 'publish':
             $template = i18n::c('%s has posted a page in %s');
             break;
         case 'submit':
             $template = i18n::c('%s has submitted a page in %s');
             break;
         case 'update':
             $template = i18n::c('%s has updated a page in %s');
             break;
     }
     // headline
     $headline = sprintf($template, Surfer::get_link(), $headline_link);
     // panel content
     $content = '';
     // more insight on this page
     $prefix = $suffix = '';
     // signal articles to be published
     if (!isset($item['publish_date']) || $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;
     }
     // flag expired articles
     if (isset($item['expiry_date']) && $item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
         $prefix .= EXPIRED_FLAG . ' ';
     }
     // signal locked articles
     if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
         $suffix .= ' ' . LOCKED_FLAG;
     }
     // insert page title
     $content .= '<h3><span>' . $prefix . $title . $suffix . '</span></h3>';
     // insert anchor prefix
     if (is_object($anchor)) {
         $content .= $anchor->get_prefix();
     }
     // the introduction text, if any
     if (is_object($overlay)) {
         $content .= Skin::build_block($overlay->get_text('introduction', $item), 'introduction');
     } elseif (isset($item['introduction']) && trim($item['introduction'])) {
         $content .= Skin::build_block($item['introduction'], 'introduction');
     }
     // get text related to the overlay, if any
     if (is_object($overlay)) {
         $content .= $overlay->get_text('diff', $item);
     }
     // filter description, if necessary
     if (is_object($overlay)) {
         $description = $overlay->get_text('description', $item);
     } else {
         $description = $item['description'];
     }
     // the beautified description, which is the actual page body
     if ($description) {
         // use adequate label
         if (is_object($overlay) && ($label = $overlay->get_label('description'))) {
             $content .= Skin::build_block($label, 'title');
         }
         // beautify the target page
         $content .= Skin::build_block($description, 'description', '', $item['options']);
     }
     // attachment details
     $details = array();
     // avoid first file in list if mentioned in last comment
     $file_offset = 0;
     // comments
     include_once $context['path_to_root'] . 'comments/comments.php';
     if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
         // get last contribution for this page
         if ($comment = Comments::get_newest_for_anchor('article:' . $item['id'])) {
             if (preg_match('/\\[(download|file)=/', $comment['description'])) {
                 $file_offset++;
             }
             // bars around the last contribution
             $bottom_menu = array();
             // last contributor
             $contributor = Users::get_link($comment['create_name'], $comment['create_address'], $comment['create_id']);
             $flag = '';
             if ($comment['create_date'] >= $context['fresh']) {
                 $flag = NEW_FLAG;
             } elseif ($comment['edit_date'] >= $context['fresh']) {
                 $flag = UPDATED_FLAG;
             }
             $bottom_menu[] = sprintf(i18n::s('By %s'), $contributor) . ' ' . Skin::build_date($comment['create_date']) . $flag;
             // gather pieces
             $pieces = array();
             // last contribution, and user signature
             $pieces[] = ucfirst(trim($comment['description'])) . Users::get_signature($comment['create_id']);
             // bottom
             if ($bottom_menu) {
                 $pieces[] = '<div>' . ucfirst(trim(Skin::finalize_list($bottom_menu, 'menu'))) . '</div>';
             }
             // put all pieces together
             $content .= '<div>' . "\n" . join("\n", $pieces) . '</div>' . "\n";
         }
         // count comments
         $details[] = sprintf(i18n::nc('%d comment', '%d comments', $count), $count);
     }
     // info on related files
     if ($count = Files::count_for_anchor('article:' . $item['id'])) {
         // most recent files attached to this page
         if ($items = Files::list_by_date_for_anchor('article:' . $item['id'], $file_offset, 3, 'dates')) {
             // more files than listed
             $more = '';
             if ($count > 3) {
                 $more = '<span class="details">' . sprintf(i18n::s('%d files, including:'), $count) . '</span>';
             }
             if (is_array($items)) {
                 $items = Skin::build_list($items, 'compact');
             }
             $items = '<div>' . $more . $items . '</div>';
         }
         // wrap it with some header
         if ($items) {
             $content .= '<h3><span>' . i18n::c('Files') . '</span></h3>' . $items;
         }
         // count files
         $details[] = sprintf(i18n::nc('%d file', '%d files', $count), $count);
     }
     // info on related links
     include_once $context['path_to_root'] . 'links/links.php';
     if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
         $details[] = sprintf(i18n::nc('%d link', '%d links', $count), $count);
     }
     // describe attachments
     if (count($details)) {
         $content .= '<hr align="left" size=1" width="150">' . '<p>' . sprintf(i18n::c('This page has %s'), join(', ', $details)) . '</p>';
     }
     // assemble main content of this message
     $text = Skin::build_mail_content($headline, $content);
     // a set of links
     $menu = array();
     // request access to the item
     if ($action == 'apply') {
         // call for action
         $link = $context['url_to_home'] . $context['url_to_root'] . Articles::get_url($item['id'], 'invite', Surfer::get_id());
         $label = sprintf(i18n::c('Invite %s to participate'), Surfer::get_name());
         $menu[] = Skin::build_mail_button($link, $label, TRUE);
         // link to user profile
         $link = Surfer::get_permalink();
         $label = sprintf(i18n::c('View the profile of %s'), Surfer::get_name());
         $menu[] = Skin::build_mail_button($link, $label, FALSE);
         // invite to visit the item
     } else {
         // call for action
         $link = Articles::get_permalink($item);
         if (!is_object($overlay) || !($label = $overlay->get_label('permalink_command', 'articles', FALSE))) {
             $label = i18n::c('View the page');
         }
         $menu[] = Skin::build_mail_button($link, $label, TRUE);
         // link to the container
         $link = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url();
         $menu[] = Skin::build_mail_button($link, $anchor->get_title(), FALSE);
     }
     // finalize links
     $text .= Skin::build_mail_menu($menu);
     // the full message
     return $text;
 }
示例#23
0
文件: links.php 项目: rair/yacs
 /**
  * check if new links can be added
  *
  * This function returns TRUE if links can be added to some place,
  * and FALSE otherwise.
  *
  * @param object an instance of the Anchor interface, if any
  * @param array a set of item attributes, if any
  * @param string the type of item, e.g., 'section'
  * @return boolean TRUE or FALSE
  */
 public static function allow_creation($item = NULL, $anchor = NULL, $variant = NULL)
 {
     global $context;
     // backward compatibility, reverse parameters :
     // $anchor is always a object and $item a array
     if (is_object($item) || is_array($anchor)) {
         $permute = $anchor;
         $anchor = $item;
         $item = $permute;
     }
     // guess the variant
     if (!$variant) {
         // most frequent case
         if (isset($item['id'])) {
             $variant = 'article';
         } elseif (is_object($anchor)) {
             $variant = $anchor->get_type();
         } else {
             return FALSE;
         }
     }
     // only in articles
     if ($variant == 'article') {
         // 'no_links' option
         if (Articles::has_option('no_links', $anchor, $item)) {
             return FALSE;
         }
         // other containers
     } else {
         // links have to be activated
         if (isset($item['options']) && is_string($item['options']) && preg_match('/\\bwith_links\\b/i', $item['options'])) {
         } elseif (!isset($item['id']) && is_object($anchor) && $anchor->has_option('with_links', FALSE)) {
         } else {
             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;
     }
     // only in articles
     if ($variant == 'article') {
         // surfer owns this item, or the anchor
         if (Articles::is_owned($item, $anchor)) {
             return TRUE;
         }
         // surfer is an editor, and the page is not private
         if (isset($item['active']) && $item['active'] != 'N' && Articles::is_assigned($item['id'])) {
             return TRUE;
         }
         // only in sections
     } elseif ($variant == 'section') {
         // surfer owns this item, or the anchor
         if (Sections::is_owned($item, $anchor, TRUE)) {
             return TRUE;
         }
         // surfer is an editor, and the section is not private
         if (isset($item['active']) && $item['active'] != 'N' && Sections::is_assigned($item['id'])) {
             return TRUE;
         }
     }
     // surfer is an editor, and container is not private
     if (isset($item['active']) && $item['active'] != 'N' && is_object($anchor) && $anchor->is_assigned()) {
         return TRUE;
     }
     if (!isset($item['id']) && is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned()) {
         return TRUE;
     }
     // item has been locked
     if (isset($item['locked']) && $item['locked'] == 'Y') {
         return FALSE;
     }
     // anchor has been locked --only used when there is no item provided
     if (!isset($item['id']) && is_object($anchor) && $anchor->has_option('locked')) {
         return FALSE;
     }
     // surfer is an editor (and item has not been locked)
     if ($variant == 'article' && isset($item['id']) && Articles::is_assigned($item['id'])) {
         return TRUE;
     }
     if ($variant == 'section' && isset($item['id']) && Sections::is_assigned($item['id'])) {
         return TRUE;
     }
     if (is_object($anchor) && $anchor->is_assigned()) {
         return TRUE;
     }
     // container is hidden
     if (isset($item['active']) && $item['active'] == 'N') {
         return FALSE;
     }
     if (is_object($anchor) && $anchor->is_hidden()) {
         return FALSE;
     }
     // authenticated members and subscribers are allowed to add links
     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;
     }
     // anonymous contributions are allowed for articles
     if ($variant == 'article') {
         if (isset($item['options']) && preg_match('/\\banonymous_edit\\b/i', $item['options'])) {
             return TRUE;
         }
         if (is_object($anchor) && $anchor->has_option('anonymous_edit')) {
             return TRUE;
         }
     }
     // the default is to not allow for new links
     return FALSE;
 }
示例#24
0
 /**
  * list articles as digg do
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // build a list of articles
     $text = '';
     $item_count = 0;
     include_once $context['path_to_root'] . 'articles/article.php';
     include_once $context['path_to_root'] . 'comments/comments.php';
     while ($item = SQL::fetch($result)) {
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Articles::get_permalink($item);
         // make a live title
         if (is_object($overlay)) {
             $title = Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $title = Codes::beautify_title($item['title']);
         }
         // next item
         $item_count += 1;
         // section opening
         if ($item_count == 1) {
             $text .= '<div class="newest">' . "\n";
         }
         // reset everything
         $content = $prefix = $label = $suffix = $icon = '';
         // the icon to put aside
         if ($item['thumbnail_url']) {
             $icon = $item['thumbnail_url'];
         } elseif (is_callable(array($anchor, 'get_bullet_url'))) {
             $icon = $anchor->get_bullet_url();
         }
         if ($icon) {
             $icon = '<a href="' . $context['url_to_root'] . $url . '"><img src="' . $icon . '" class="right_image" alt="" title="' . encode_field(i18n::s('View the page')) . '" /></a>';
         }
         // rating
         if ($item['rating_count']) {
             $rating_label = sprintf(i18n::ns('%s vote', '%s votes', $item['rating_count']), '<span class="big">' . $item['rating_count'] . '</span>' . BR);
         } else {
             $rating_label = i18n::s('No vote');
         }
         // present results
         $digg = '<div class="digg"><div class="votes">' . $rating_label . '</div>';
         // a rating has already been registered
         if (isset($_COOKIE['rating_' . $item['id']])) {
             Cache::poison();
         } else {
             $digg .= '<div class="rate">' . Skin::build_link(Articles::get_url($item['id'], 'like'), i18n::s('Rate it'), 'basic') . '</div>';
         }
         // close digg-like area
         $digg .= '</div>';
         // 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;
         }
         // signal locked articles
         if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) {
             $suffix .= ' ' . LOCKED_FLAG;
         }
         // flag articles updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $suffix .= ' ' . EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix .= ' ' . NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= ' ' . UPDATED_FLAG;
         }
         // the full introductory text
         if (is_object($overlay)) {
             $content .= Codes::beautify_introduction($overlay->get_text('introduction', $item));
         }
         if ($item['introduction']) {
             $content .= Codes::beautify_introduction($item['introduction']);
         } else {
             $article = new Article();
             $article->load_by_content($item);
             $content .= $article->get_teaser('teaser');
         }
         // add details
         $details = array();
         // the author
         if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
             if ($item['edit_name'] == $item['create_name']) {
                 $details[] = sprintf(i18n::s('by %s'), ucfirst($item['create_name']));
             } else {
                 $details[] = sprintf(i18n::s('by %s, %s'), ucfirst($item['create_name']), ucfirst($item['edit_name']));
             }
         }
         // the publish date
         if (isset($item['publish_date']) && $item['publish_date'] > NULL_DATE) {
             $details[] = Skin::build_date($item['publish_date']);
         }
         // read the article
         $details[] = Skin::build_link($url, i18n::s('View the page'), 'basic');
         // info on related files
         if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) {
             $details[] = Skin::build_link($url . '#_attachments', sprintf(i18n::ns('%d file', '%d files', $count), $count), 'basic');
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
             $link = Comments::get_url('article:' . $item['id'], 'list');
             $details[] = Skin::build_link($link, sprintf(i18n::ns('%d comment', '%d comments', $count), $count), 'basic');
         }
         // discuss
         if (Comments::allow_creation($item, $anchor)) {
             $details[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'comment'), i18n::s('Discuss'), 'basic');
         }
         // info on related links
         if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
             $details[] = Skin::build_link($url . '#_attachments', sprintf(i18n::ns('%d link', '%d links', $count), $count), 'basic');
         }
         // link to the anchor page
         if (is_object($anchor) && (!isset($this->focus) || $item['anchor'] != $this->focus)) {
             $details[] = Skin::build_link($anchor->get_url(), $anchor->get_title(), 'basic');
         }
         // list categories by title, if any
         if ($items =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) {
             foreach ($items as $id => $attributes) {
                 // add background color to distinguish this category against others
                 if (isset($attributes['background_color']) && $attributes['background_color']) {
                     $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>';
                 }
                 $details[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic');
             }
         }
         // details
         if (count($details)) {
             $content .= '<p class="details">' . ucfirst(implode(' - ', $details)) . '</p>';
         }
         // manage layout
         $content = '<div class="digg_content">' . $digg . $content . '</div>';
         // insert a complete box
         $text .= Skin::build_box($prefix . $title . $suffix, $icon . $content, 'header1', 'article_' . $item['id']);
         // section closing
         if ($item_count == 1) {
             $text .= '</div>' . "\n";
         }
     }
     // end of processing
     SQL::free($result);
     return $text;
 }