Example #1
0
File: feed.php Project: rair/yacs
     if (is_object($anchor)) {
         $values['channel']['title'] = sprintf(i18n::s('Comments for: %s'), $anchor->get_title());
         $values['channel']['link'] = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url();
         $values['channel']['description'] = $anchor->get_teaser('quote');
     } else {
         $values['channel']['title'] = sprintf(i18n::s('Recent comments at %s'), $context['site_name']);
         $values['channel']['link'] = $context['url_to_home'] . $context['url_to_root'];
         $values['channel']['description'] = i18n::s('Each article also has its own newsfeed.');
     }
     // the image for this channel
     if (isset($context['powered_by_image']) && $context['powered_by_image']) {
         $values['channel']['image'] = $context['url_to_home'] . $context['url_to_root'] . $context['powered_by_image'];
     }
     // list comments from the database -- no more than 100 at a time
     if (is_object($anchor)) {
         $values['items'] = Comments::list_by_date_for_anchor($anchor->get_reference(), 0, 100, 'feed');
     } else {
         $values['items'] = Comments::list_by_date(0, 100, 'feed');
     }
     // make a text
     include_once '../services/codec.php';
     include_once '../services/rss_codec.php';
     $result = rss_Codec::encode($values);
     $text = @$result[1];
     // put in cache
     Safe::file_put_contents($cache_id, $text);
 }
 //
 // transfer to the user agent
 //
 // handle the output correctly
 /**
  * list categories
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // empty list
     if (!SQL::count($result)) {
         $output = array();
         return $output;
     }
     // we return plain text
     $text = '';
     // process all items in the list
     while ($item = SQL::fetch($result)) {
         // one box per category
         $box['title'] = '';
         $box['text'] = '';
         // use the title to label the link
         $box['title'] = Skin::strip($item['title'], 50);
         // list related categories, if any
         if ($items = Categories::list_by_date_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE, 'compact')) {
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $label = $label[1];
                 }
                 $box['text'] .= '<li>' . Skin::build_link($url, $label, 'category') . '</li>' . "\n";
             }
         }
         // info on related sections
         $items =& Members::list_sections_by_title_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE);
         if ($items) {
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $label = $label[1];
                 }
                 $box['text'] .= '<li>' . Skin::build_link($url, $label, 'section') . '</li>' . "\n";
             }
         }
         // info on related articles
         if (isset($item['options']) && preg_match('/\\barticles_by_title\\b/i', $item['options'])) {
             $items =& Members::list_articles_by_title_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE);
         } else {
             $items =& Members::list_articles_by_date_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE);
         }
         if ($items) {
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $label = $label[1];
                 }
                 $box['text'] .= '<li>' . Skin::build_link($url, $label, 'article') . '</li>' . "\n";
             }
         }
         // info on related files
         if (isset($item['options']) && preg_match('/\\bfiles_by_title\\b/i', $item['options'])) {
             $items = Files::list_by_title_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE, 'category:' . $item['id']);
         } else {
             $items = Files::list_by_date_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE, 'category:' . $item['id']);
         }
         if ($items) {
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $label = $label[1];
                 }
                 $box['text'] .= '<li>' . Skin::build_link($url, $label, 'file') . '</li>' . "\n";
             }
         }
         // info on related comments
         include_once $context['path_to_root'] . 'comments/comments.php';
         if ($items = Comments::list_by_date_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE, 'compact')) {
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $label = $label[1];
                 }
                 $box['text'] .= '<li>' . Skin::build_link($url, $label, 'comment') . '</li>' . "\n";
             }
         }
         // info on related links
         include_once $context['path_to_root'] . 'links/links.php';
         if (isset($item['options']) && preg_match('/\\blinks_by_title\\b/i', $item['options'])) {
             $items = Links::list_by_title_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE);
         } else {
             $items = Links::list_by_date_for_anchor('category:' . $item['id'], 0, COMPACT_LIST_SIZE);
         }
         if ($items) {
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $label = $label[1];
                 }
                 $box['text'] .= '<li>' . Skin::build_link($url, $label) . '</li>' . "\n";
             }
         }
         // add a direct link to the category
         if (Surfer::is_associate()) {
             $box['title'] .= '&nbsp;' . Skin::build_link(Categories::get_permalink($item), MORE_IMG, 'basic');
         }
         // make a full list
         if ($box['text']) {
             $box['text'] = '<ul>' . $box['text'] . '</ul>' . "\n";
         }
         // always make a box, to let associates visit the category
         $text .= Skin::build_box($box['title'], $box['text']);
     }
     // end of processing
     SQL::free($result);
     return $text;
 }
Example #3
0
 if (is_object($layout) && method_exists($layout, 'set_offset')) {
     $layout->set_offset($offset);
 }
 // build a complete box
 $box = array('bar' => array(), 'text' => '');
 // new comments are allowed
 if (Comments::allow_creation($item, $anchor, 'section')) {
     $box['text'] .= Comments::get_form('section:' . $item['id']);
 }
 // a navigation bar for these comments
 if ($count = Comments::count_for_anchor('section:' . $item['id'])) {
     if ($count > 20) {
         $box['bar'] += array('_count' => sprintf(i18n::s('%d comments'), $count));
     }
     // list comments by date
     $items = Comments::list_by_date_for_anchor('section:' . $item['id'], $offset, $items_per_page, $layout, TRUE);
     // actually render the html
     if (is_array($items)) {
         $box['text'] .= Skin::build_list($items, 'rows');
     } elseif (is_string($items)) {
         $box['text'] .= $items;
     }
     // navigation commands for comments
     $prefix = Comments::get_url('section:' . $item['id'], 'navigate');
     $box['bar'] = array_merge($box['bar'], Skin::navigate(NULL, $prefix, $count, $items_per_page, $zoom_index, FALSE, TRUE));
 }
 // build a box
 if ($box['text']) {
     // show commands
     if (count($box['bar'])) {
         // append the menu bar at the end
Example #4
0
 /**
  * render comment as json format
  * 
  * @param int $id of the comment
  * @param object $anchor of the comment
  */
 public static function render_json($id, $anchor)
 {
     // we'll return json
     $output = '';
     // get layout and render last comment
     $layout = Comments::get_layout($anchor);
     $layout->set_variant('no_wrap');
     $rendering = Comments::list_by_date_for_anchor($anchor, 0, 1, $layout, true);
     $output = json_encode(array('entity' => 'comment', 'id' => $id, 'anchor' => $anchor->get_reference(), 'html' => $rendering));
     // allow for data compression
     render_raw('application/json');
     echo $output;
     // the post-processing hook, then exit
     finalize_page(TRUE);
 }
Example #5
0
 // list files by date (default) or by title (option :files_by_title:)
 $items = array();
 if (Articles::has_option('files_by', $anchor, $item) == 'title') {
     $items = Files::list_by_title_for_anchor('article:' . $item['id'], 0, 300, 'compact');
 } else {
     $items = Files::list_by_date_for_anchor('article:' . $item['id'], 0, 300, 'compact');
 }
 // actually list items
 if (count($items)) {
     $context['text'] .= Skin::build_box(i18n::s('Files'), utf8::to_unicode(Skin::build_list($items, 'compact')));
 }
 //
 // attached comments
 //
 // list immutable comments by date
 $items = Comments::list_by_date_for_anchor('article:' . $item['id'], 0, 500, 'excerpt');
 // actually list items
 if ($items) {
     $context['text'] .= Skin::build_box(i18n::s('Comments'), utf8::to_unicode($items));
 }
 //
 // related links
 //
 // list links by date (default) or by title (option :links_by_title:)
 $items = array();
 if (Articles::has_option('links_by_title', $anchor, $item)) {
     $items = Links::list_by_title_for_anchor('article:' . $item['id'], 0, 50, 'compact');
 } else {
     $items = Links::list_by_date_for_anchor('article:' . $item['id'], 0, 50, 'compact');
 }
 // actually list items
Example #6
0
 /**
  * list sections
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // empty list
     if (!SQL::count($result)) {
         $output = array();
         return $output;
     }
     // the maximum number of items per section
     if (!defined('MAXIMUM_ITEMS_PER_SECTION')) {
         define('MAXIMUM_ITEMS_PER_SECTION', 100);
     }
     // we return plain text
     $text = '';
     // process all items in the list
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     $family = '';
     while ($item = SQL::fetch($result)) {
         // change the family
         if ($item['family'] != $family) {
             $family = $item['family'];
             // show the family
             $text .= '<h2><span>' . $family . '&nbsp;</span></h2>' . "\n";
         }
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'section:' . $item['id']);
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // one box per section
         $box = array('title' => '', 'text' => '');
         // box content
         $elements = array();
         // use the title to label the link
         if (is_object($overlay)) {
             $box['title'] .= Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $box['title'] .= Codes::beautify_title($item['title']);
         }
         $details = array();
         // info on related articles
         if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) {
             $order = $matches[1];
         } else {
             $order = 'edition';
         }
         $items =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact');
         if (@count($items)) {
             // mention the number of items in folded title
             $details[] = sprintf(i18n::ns('%d page', '%d pages', count($items)), count($items));
             // add one link per item
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'article') . $suffix;
             }
         }
         // info on related files
         if (Sections::has_option('files_by', $anchor, $item) == 'title') {
             $items = Files::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact');
         } else {
             $items = Files::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact');
         }
         if ($items) {
             // mention the number of sections in folded title
             $details[] = sprintf(i18n::ns('%d file', '%d files', count($items)), count($items));
             // add one link per item
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'file') . $suffix;
             }
         }
         // info on related comments
         if ($items = Comments::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact', TRUE)) {
             // mention the number of sections in folded title
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', count($items)), count($items));
             // add one link per item
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'comment') . $suffix;
             }
         }
         // info on related links
         if (Sections::has_option('links_by_title', $anchor, $item)) {
             $items = Links::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact');
         } else {
             $items = Links::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact');
         }
         if ($items) {
             // mention the number of sections in folded title
             $details[] = sprintf(i18n::ns('%d link', '%d links', count($items)), count($items));
             // add one link per item
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label) . $suffix;
             }
         }
         // list related sections, if any
         if ($items =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact')) {
             // mention the number of sections in folded title
             $details[] = sprintf(i18n::ns('%d section', '%d sections', count($items)), count($items));
             // add one link per item
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'section') . $suffix;
             }
         }
         // signal continuing sections
         if (count($elements) > MAXIMUM_ITEMS_PER_SECTION) {
             $elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('More pages') . MORE_IMG, 'basic');
         } else {
             $elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'shortcut');
         }
         // complement title
         if (count($details)) {
             $box['title'] .= ' <span class="details">(' . join(', ', $details) . ')</span>';
         }
         // insert introduction, if any
         if ($item['introduction']) {
             $box['text'] .= Codes::beautify_introduction($item['introduction']);
         }
         // make a full list
         if (count($elements)) {
             $box['text'] .= '<ul><li>' . implode('</li>' . "\n" . '<li>', $elements) . '</li></ul>' . "\n";
         }
         // if we have an icon for this section, use it
         if (isset($item['thumbnail_url']) && $item['thumbnail_url']) {
             // adjust the class
             $class = '';
             if (isset($context['classes_for_thumbnail_images'])) {
                 $class = 'class="' . $context['classes_for_thumbnail_images'] . '" ';
             }
             // build the complete HTML element
             $icon = '<img src="' . $item['thumbnail_url'] . '" alt="" title="' . encode_field(Codes::beautify_title($item['title'])) . '" ' . $class . '/>';
             // make it clickable
             $link = Skin::build_link(Sections::get_permalink($item), $icon, 'basic');
             // put this aside
             $box['text'] = '<table class="decorated"><tr>' . '<td class="image">' . $link . '</td>' . '<td class="content">' . $box['text'] . '</td>' . '</tr></table>';
         }
         // always make a box
         $text .= Skin::build_box($box['title'], $box['text'], 'folded');
     }
     // end of processing
     SQL::free($result);
     return $text;
 }
Example #7
0
 /**
  * list articles
  *
  * @param resource the SQL result
  * @return a string to be displayed
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // no hovering label
     $href_title = '';
     // we build an array for the skin::build_tabs() function
     $panels = array();
     // process all items in the list
     while ($item = SQL::fetch($result)) {
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // panel content
         $text = '';
         // insert anchor prefix
         if (is_object($anchor)) {
             $text .= $anchor->get_prefix();
         }
         // the introduction text, if any
         if (is_object($overlay)) {
             $text .= Skin::build_block($overlay->get_text('introduction', $item), 'introduction');
         } elseif (isset($item['introduction']) && trim($item['introduction'])) {
             $text .= Skin::build_block($item['introduction'], 'introduction');
         }
         // get text related to the overlay, if any
         if (is_object($overlay)) {
             $text .= $overlay->get_text('view', $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'))) {
                 $text .= Skin::build_block($label, 'title');
             }
             // beautify the target page
             $text .= Skin::build_block($description, 'description', '', $item['options']);
         }
         // list files only to people able to change the page
         if (Articles::allow_modification($item, $anchor)) {
             $embedded = NULL;
         } else {
             $embedded = Codes::list_embedded($item['description']);
         }
         // build a complete box
         $box = array('bar' => array(), 'text' => '');
         // count the number of files in this article
         if ($count = Files::count_for_anchor('article:' . $item['id'], FALSE, $embedded)) {
             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)
             $offset = ($zoom_index - 1) * FILES_PER_PAGE;
             if (Articles::has_option('files_by', $anchor, $item) == 'title') {
                 $items = Files::list_by_title_for_anchor('article:' . $item['id'], 0, 300, 'article:' . $item['id'], $embedded);
             } else {
                 $items = Files::list_by_date_for_anchor('article:' . $item['id'], 0, 300, 'article:' . $item['id'], $embedded);
             }
             // actually render the html
             if (is_array($items)) {
                 $box['text'] .= Skin::build_list($items, 'decorated');
             } elseif (is_string($items)) {
                 $box['text'] .= $items;
             }
             // the command to post a new file
             if (Files::allow_creation($item, $anchor, 'article')) {
                 Skin::define_img('FILES_UPLOAD_IMG', 'files/upload.gif');
                 $box['bar'] += array('files/edit.php?anchor=' . urlencode('article:' . $item['id']) => FILES_UPLOAD_IMG . i18n::s('Add a file'));
             }
         }
         // some files have been attached to this page
         if ($page == 1 && $count > 1) {
             // the command to download all files
             $link = 'files/fetch_all.php?anchor=' . urlencode('article:' . $item['id']);
             if ($count > 20) {
                 $label = i18n::s('Zip 20 first files');
             } else {
                 $label = i18n::s('Zip all files');
             }
             $box['bar'] += array($link => $label);
         }
         // there is some box content
         if ($box['text']) {
             $text .= Skin::build_content('files', i18n::s('Files'), $box['text'], $box['bar']);
         }
         // list of comments
         $title_label = '';
         if (is_object($anchor)) {
             $title_label = ucfirst($overlay->get_label('list_title', 'comments'));
         }
         if (!$title_label) {
             $title_label = i18n::s('Comments');
         }
         // no layout yet
         $layout = NULL;
         // label to create a comment
         $add_label = '';
         if (is_object($overlay)) {
             $add_label = $overlay->get_label('new_command', 'comments');
         }
         if (!$add_label) {
             $add_label = i18n::s('Post a comment');
         }
         // get a layout from anchor
         $layout =& Comments::get_layout($anchor, $item);
         // provide author information to layout
         if (is_object($layout) && isset($item['create_id']) && $item['create_id']) {
             $layout->set_focus('user:'******'create_id']);
         }
         // the maximum number of comments per page
         if (is_object($layout)) {
             $items_per_page = $layout->items_per_page();
         } else {
             $items_per_page = COMMENTS_PER_PAGE;
         }
         // the first comment to list
         $offset = 0;
         if (is_object($layout) && method_exists($layout, 'set_offset')) {
             $layout->set_offset($offset);
         }
         // build a complete box
         $box = array('bar' => array(), 'prefix_bar' => array(), 'text' => '');
         // feed the wall
         if (Comments::allow_creation($item, $anchor)) {
             $box['text'] .= Comments::get_form('article:' . $item['id']);
         }
         // a navigation bar for these comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'])) {
             if ($count > 20) {
                 $box['bar'] += array('_count' => sprintf(i18n::ns('%d comment', '%d comments', $count), $count));
             }
             // list comments by date
             $items = Comments::list_by_date_for_anchor('article:' . $item['id'], $offset, $items_per_page, $layout, TRUE);
             // actually render the html
             if (is_array($items)) {
                 $box['text'] .= Skin::build_list($items, 'rows');
             } elseif (is_string($items)) {
                 $box['text'] .= $items;
             }
             // navigation commands for comments
             $prefix = Comments::get_url('article:' . $item['id'], 'navigate');
             $box['bar'] = array_merge($box['bar'], Skin::navigate(NULL, $prefix, $count, $items_per_page, $zoom_index));
         }
         // ensure that the surfer can change content
         if (Articles::allow_modification($item, $anchor)) {
             // view or modify this section
             $menu = array();
             $box['bar'] += array(Articles::get_permalink($item) => i18n::s('View the page'));
             if (!is_object($overlay) || !($label = $overlay->get_label('edit_command', 'articles'))) {
                 $label = i18n::s('Edit this page');
             }
             $box['bar'] += array(Articles::get_url($item['id'], 'edit') => $label);
         }
         // show commands
         if (count($box['bar'])) {
             // commands before the box
             $box['text'] = Skin::build_list($box['prefix_bar'], 'menu_bar') . $box['text'];
             // append the menu bar at the end
             $box['text'] .= Skin::build_list($box['bar'], 'menu_bar');
         }
         // build a box
         if ($box['text']) {
             // put a title if there are other titles or if more than 2048 chars
             $title = '';
             if (preg_match('/(<h1|<h2|<h3|<table|\\[title|\\[subtitle)/i', $context['text'] . $text) || strlen($context['text'] . $text) > 2048) {
                 $title = $title_label;
             }
             // insert a full box
             $text .= Skin::build_box($title, $box['text'], 'header1', 'comments');
         }
         // assemble the full panel
         $panels[] = array('att' . $item['id'], ucfirst(Skin::strip($item['title'], 30)), 'atc' . $item['id'], $text);
     }
     // there is some box content
     if (trim($box['text'])) {
         $text .= $box['text'];
     }
     // format tabs
     $text = Skin::build_tabs($panels);
     // end of processing
     SQL::free($result);
     return $text;
 }
Example #8
0
 /**
  * list pages
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // allow for multiple calls
     static $accordion_id;
     if (!isset($accordion_id)) {
         $accordion_id = 1;
     } else {
         $accordion_id++;
     }
     // empty list
     if (!SQL::count($result)) {
         $output = array();
         return $output;
     }
     // the maximum number of items per article
     if (!defined('MAXIMUM_ITEMS_PER_ACCORDION')) {
         define('MAXIMUM_ITEMS_PER_ACCORDION', 100);
     }
     // we return plain text
     $text = '';
     // type of listed object
     $items_type = $this->listed_type;
     // process all items in the list
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     $family = '';
     while ($item = SQL::fetch($result)) {
         // get the object interface, this may load parent and overlay
         $entity = new $items_type($item);
         // change the family (layout of sections)
         if (isset($item['family']) && $item['family'] != $family) {
             $family = $item['family'];
             // show the family
             $text .= '<h2><span>' . $family . '&nbsp;</span></h2>' . "\n";
         }
         // one box per page
         $box = array('title' => '', 'text' => '');
         // signal entity to be published
         if (isset($item['publish_date']) && ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S'))) {
             $box['title'] .= DRAFT_FLAG;
         }
         // signal entity to be activated
         if (isset($item['activation_date']) && $item['activation_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) {
             $box['title'] .= DRAFT_FLAG;
         }
         // signal restricted and private entity
         if ($item['active'] == 'N') {
             $box['title'] .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $box['title'] .= RESTRICTED_FLAG;
         }
         // use the title to label the link
         if (is_object($entity->overlay)) {
             $box['title'] .= Codes::beautify_title($entity->overlay->get_text('title', $item));
         } else {
             $box['title'] .= Codes::beautify_title($item['title']);
         }
         // box content
         $elements = array();
         // complement the title with interesting details
         $details = array();
         // info on related article, only for sections
         if ($items_type == 'section') {
             if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) {
                 $order = $matches[1];
             } else {
                 $order = 'edition';
             }
             $items =& Articles::list_for_anchor_by($order, $entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact');
             if (@count($items)) {
                 // mention the number of items in folded title
                 $details[] = sprintf(i18n::ns('%d page', '%d pages', count($items)), count($items));
                 // add one link per item
                 foreach ($items as $url => $label) {
                     $prefix = $suffix = '';
                     if (is_array($label)) {
                         $prefix = $label[0];
                         $suffix = $label[2];
                         $label = $label[1];
                     }
                     $elements[] = $prefix . Skin::build_link($url, $label, 'article') . $suffix;
                 }
             }
         }
         // info on related files
         if ($entity->has_option('files_by') == 'title') {
             $items = Files::list_by_title_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact');
         } else {
             $items = Files::list_by_date_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact');
         }
         if ($items) {
             // mention the number of items in folded title
             $details[] = sprintf(i18n::ns('%d file', '%d files', count($items)), count($items));
             // add one link per item
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'file') . $suffix;
             }
         }
         // info on related comments
         if ($items = Comments::list_by_date_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact', TRUE)) {
             // mention the number of items in folded title
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', count($items)), count($items));
             // add one link per item
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = rtrim(Codes::strip(' ' . $label[2]), '- ');
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'comment') . $suffix;
             }
         }
         // info on related links
         if ($entity->has_option('links_by_title')) {
             $items = Links::list_by_title_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact');
         } else {
             $items = Links::list_by_date_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact');
         }
         if ($items) {
             // mention the number of items in folded title
             $details[] = sprintf(i18n::ns('%d link', '%d links', count($items)), count($items));
             // add one link per item
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label) . $suffix;
             }
         }
         // list related sub-sections, if any
         if ($items_type == 'section') {
             if ($items =& Sections::list_by_title_for_anchor($entity->get_reference(), 0, MAXIMUM_ITEMS_PER_ACCORDION + 1, 'compact')) {
                 // mention the number of sections in folded title
                 $details[] = sprintf(i18n::ns('%d section', '%d sections', count($items)), count($items));
                 // add one link per item
                 foreach ($items as $url => $label) {
                     $prefix = $suffix = '';
                     if (is_array($label)) {
                         $prefix = $label[0];
                         $suffix = $label[2];
                         $label = $label[1];
                     }
                     $elements[] = $prefix . Skin::build_link($url, $label, 'section') . $suffix;
                 }
             }
         }
         // a link to the page
         $permalink = $entity->get_permalink($item);
         $elements[] = Skin::build_link($permalink, sprintf(i18n::s('View the %s'), $items_type) . MORE_IMG, 'shortcut');
         // complement title
         if (count($details)) {
             $box['title'] .= ' <span class="details">(' . join(', ', $details) . ')</span>';
         }
         // insert introduction, if any
         if (is_object($entity->overlay)) {
             $box['text'] .= Skin::build_block($entity->overlay->get_text('introduction', $item), 'introduction');
         } elseif (trim($item['introduction'])) {
             $box['text'] .= Skin::build_block($item['introduction'], 'introduction');
         } else {
             // insert overlay data, if any
             if (is_object($entity->overlay)) {
                 $box['text'] .= $entity->overlay->get_text('box', $item);
             }
             // the content of this box
             $box['text'] .= Codes::beautify($item['description'], $item['options']);
         }
         // make a full list
         if (count($elements)) {
             $box['text'] .= Skin::finalize_list($elements, 'compact');
         }
         // display all tags
         if ($item['tags']) {
             $box['text'] .= ' <p class="tags" style="margin-bottom: 0">' . Skin::build_tags($item['tags'], $entity->get_reference()) . '</p>';
         }
         // if we have an icon for this page, use it
         if (isset($item['thumbnail_url']) && $item['thumbnail_url']) {
             // adjust the class
             $class = '';
             if (isset($context['classes_for_thumbnail_images'])) {
                 $class = 'class="' . $context['classes_for_thumbnail_images'] . '" ';
             }
             // build the complete HTML element
             $icon = '<img src="' . $item['thumbnail_url'] . '" alt="" title="' . encode_field(Codes::beautify_title($item['title'])) . '" ' . $class . '/>';
             // make it clickable
             $link = Skin::build_link($permalink, $icon, 'basic');
             // put this aside
             $box['text'] = '<table class="decorated"><tr>' . '<td class="image">' . $link . '</td>' . '<td class="content">' . $box['text'] . '</td>' . '</tr></table>';
         }
         // always make a box
         $text .= $this->build_accordion_box($box['title'], $box['text'], 'accordion_' . $accordion_id);
     }
     // we have bounded styles and scripts
     $this->load_scripts_n_styles();
     // end of processing
     SQL::free($result);
     return $text;
 }
Example #9
0
File: list.php Project: rair/yacs
        }
        $context['text'] .= Skin::finalize_list($menu, 'assistant_bar');
    }
    // insert anchor suffix
    if (is_object($anchor)) {
        $context['text'] .= $anchor->get_suffix();
    }
} else {
    ///// json output
    // get comment layout
    $layout = Comments::get_layout($anchor);
    // set variant, if any
    if (isset($_REQUEST['variant'])) {
        $layout->set_variant($_REQUEST['variant']);
    }
    // get offset
    $offset = isset($_REQUEST['start']) && is_numeric($_REQUEST['start']) ? $_REQUEST['start'] : 0;
    $count = isset($_REQUEST['batch']) && is_numeric($_REQUEST['batch']) ? $_REQUEST['batch'] : COMMENTS_PER_PAGE;
    // do the request, get them from the end (reversed)
    $comments = Comments::list_by_date_for_anchor($anchor, $offset, $count, $layout, true);
    // how many left for next batch ?
    $comment_left = Comments::count_for_anchor($anchor) - $offset - $count;
    $output = json_encode(array('comments' => $comments, 'anchor' => $anchor->get_reference(), 'left' => $comment_left));
    // allow for data compression
    render_raw('application/json');
    echo $output;
    // the post-processing hook, then exit
    finalize_page(TRUE);
}
// render the skin
render_skin();
Example #10
0
File: print.php Project: rair/yacs
 //
 // the comments section
 //
 // layout for printed comments
 $layout = 'no_anchor';
 // the maximum number of comments per page
 if (is_object($layout)) {
     $items_per_page = $layout->items_per_page();
 } else {
     $items_per_page = COMMENTS_PER_PAGE;
 }
 // build a complete box
 $box['bar'] = array();
 $box['text'] = '';
 // list comments by date
 $items = Comments::list_by_date_for_anchor('section:' . $item['id'], 0, $items_per_page, $layout);
 // actually render the html
 if (is_array($items)) {
     $box['text'] .= Skin::build_list($items, 'rows');
 } elseif (is_string($items)) {
     $box['text'] .= $items;
 }
 // build a box
 if ($box['text']) {
     $context['text'] .= Skin::build_box('', $box['text']);
 }
 //
 // related link
 //
 // list links by date (default) or by title (option :links_by_title:)
 if (preg_match('/\\blinks_by_title\\b/i', $item['options'])) {
Example #11
0
File: view.php Project: rair/yacs
 if (!$zoom_type || $zoom_type == 'comments') {
     // build a complete box
     $box = array('bar' => array(), 'text' => '');
     // count the number of comments in this category
     if ($zoom_type == 'comments') {
         $url = '_count';
     } else {
         $url = Categories::get_permalink($item) . '#comments';
     }
     if ($count = Comments::count_for_anchor('category:' . $item['id'])) {
         if ($count > 20) {
             $box['bar'] = array('_count' => sprintf(i18n::ns('%d comment', '%d comments', $count), $count));
         }
         // list comments by date
         $offset = ($zoom_index - 1) * COMMENTS_PER_PAGE;
         $items = Comments::list_by_date_for_anchor('category:' . $item['id'], $offset, COMMENTS_PER_PAGE);
         if (is_array($items)) {
             $box['text'] .= Skin::build_list($items, 'rows');
         }
         // navigation commands for comments
         $home = Categories::get_permalink($item);
         $prefix = Categories::get_url($item['id'], 'navigate', 'comments');
         if ($zoom_type == 'comments') {
             $box['bar'] = array_merge($box['bar'], Skin::navigate($home, $prefix, $count, COMMENTS_PER_PAGE, $zoom_index, TRUE));
         }
     }
     // the command to post a new comment
     if (Comments::allow_creation($item, $anchor, 'category')) {
         Skin::define_img('COMMENTS_ADD_IMG', 'comments/add.gif');
         $url = 'comments/edit.php?anchor=' . urlencode('category:' . $item['id']);
         $box['bar'] += array($url => COMMENTS_ADD_IMG . i18n::s('Post a comment'));
Example #12
0
 /**
  * list sections
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // empty list
     if (!SQL::count($result)) {
         $output = array();
         return $output;
     }
     // the maximum number of items per section
     if (!defined('MAXIMUM_ITEMS_PER_SECTION')) {
         define('MAXIMUM_ITEMS_PER_SECTION', 50);
     }
     // we return plain text
     $text = '';
     // process all items in the list
     include_once $context['path_to_root'] . 'comments/comments.php';
     while ($item = SQL::fetch($result)) {
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'section:' . $item['id']);
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Sections::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 sections that are draft, dead, or created or updated very recently
         if ($item['activation_date'] >= $context['now']) {
             $prefix .= DRAFT_FLAG;
         } elseif ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $prefix .= EXPIRED_FLAG;
         }
         if ($item['create_date'] >= $context['fresh']) {
             $suffix .= NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= UPDATED_FLAG;
         }
         // signal restricted and private sections
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // one box per section
         $box = array('title' => '', 'text' => '');
         // add a direct link to the section
         $box['title'] = $prefix . Skin::build_link($url, $title, 'basic') . $suffix;
         // box content
         $elements = array();
         // info on related articles
         if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) {
             $order = $matches[1];
         } else {
             $order = 'edition';
         }
         $items =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact');
         if (@count($items)) {
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'article') . $suffix;
             }
         }
         // info on related files
         if (Sections::has_option('files_by', $anchor, $item) == 'title') {
             $items = Files::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact');
         } else {
             $items = Files::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact');
         }
         if ($items) {
             foreach ($items as $url => $label) {
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'file') . $suffix;
             }
         }
         // info on related comments
         if ($items = Comments::list_by_date_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact', TRUE)) {
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'comment') . $suffix;
             }
         }
         // list related sections, if any
         if ($items =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, MAXIMUM_ITEMS_PER_SECTION + 1, 'compact')) {
             foreach ($items as $url => $label) {
                 $prefix = $suffix = '';
                 if (is_array($label)) {
                     $prefix = $label[0];
                     $suffix = $label[2];
                     $label = $label[1];
                 }
                 $elements[] = $prefix . Skin::build_link($url, $label, 'section') . $suffix;
             }
         }
         // signal continuing sections
         if (count($elements) > MAXIMUM_ITEMS_PER_SECTION) {
             $elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('More pages') . MORE_IMG, 'basic');
         } elseif (!count($elements) && Surfer::is_associate()) {
             $elements[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'shortcut');
         }
         // make a full list
         if (count($elements)) {
             $box['text'] = '<ul><li>' . implode('</li>' . "\n" . '<li>', $elements) . '</li></ul>' . "\n";
         }
         // always make a box
         $text .= Skin::build_box($box['title'], $box['text']);
     }
     // end of processing
     SQL::free($result);
     return $text;
 }