/** * render a compact list of voted pages * * @param string the anchor (e.g. 'section:123') * @param string layout to use * @return string the rendered text **/ public static function render_voted($anchor = '', $layout = 'simple') { global $context; // we return some text; $text = ''; // number of items to display $count = COMPACT_LIST_SIZE; if (($position = strpos($anchor, ',')) !== FALSE) { $count = (int) trim(substr($anchor, $position + 1)); if (!$count) { $count = COMPACT_LIST_SIZE; } $anchor = trim(substr($anchor, 0, $position)); } // scope is limited to current surfer if ($anchor == 'self' && Surfer::get_id()) { $anchor = 'user:'******'section:') === 0) { // look at this branch of the content tree $anchors = Sections::get_branch_at_anchor($anchor); // query the database and layout that stuff $text =& Articles::list_for_anchor_by('rating', $anchors, 0, $count, $layout); // scope is limited to pages of one surfer } elseif (strpos($anchor, 'user:'******'rating', substr($anchor, 5), 0, $count, $layout); } else { $text =& Articles::list_by('rating', 0, $count, $layout); } // we have an array to format if (is_array($text)) { $text =& Skin::build_list($text, $layout); } // job done return $text; }
// the submit button $context['text'] .= '<p>' . Skin::build_submit_button(i18n::s('Send'), i18n::s('Press [s] to submit data'), 's') . '</p>' . "\n"; // end of the form $context['text'] .= '</div></form>'; // the script used for form handling at the browser page::insert_script(' func' . 'tion validateDocumentPost(container) {' . "\n" . ' if(!container.letter_title.value) {' . "\n" . ' alert("' . i18n::s('No title has been provided.') . '");' . "\n" . ' Yacs.stopWorking();' . "\n" . ' return false;' . "\n" . ' }' . "\n" . ' return true;' . "\n" . ' }' . "\n" . 'document.main_form.letter_title.focus();' . "\n"); // prepare a digest } elseif (isset($action) && $action == 'digest') { // the letter prefix if ($context['letter_prefix']) { $context['letter_body'] .= '<div>' . $context['letter_prefix'] . '</div>'; } // get the date of previous newsletter $digest_stamp = Values::get('letters.digest.stamp', NULL_DATE); // build the content of the letter automatically if ($items =& Articles::list_by('publication', 0, 100, 'digest', $digest_stamp)) { // one slot per section $slots = array(); // scan each article foreach ($items as $url => $label) { // text for this article $text = "\n"; // split $label as array($time, $label, $author, $section, $icon, $introduction) $time = $author = $section = $icon = $introduction = NULL; $sublevel = FALSE; if (is_array($label)) { $time = $label[0]; $author = $label[2]; $section = $label[3]; $icon = $label[4]; $introduction = $label[5];
// query the database and layout that stuff if (!($text = Comments::list_threads_by_date($offset, THREADS_PER_PAGE, $layout))) { $context['text'] .= '<p>' . i18n::s('No comment has been transmitted.') . '</p>'; } // we have an array to format if (is_array($text)) { $text =& Skin::build_list($text, 'rows'); } // cache, whatever changes, for 1 minute Cache::put($cache_id, $text, 'stable', 60); } $context['text'] .= $text; } // page tools if (Surfer::is_associate()) { $context['page_tools'][] = Skin::build_link('comments/check.php', i18n::s('Maintenance'), 'basic'); } // page extra information $cache_id = 'comments/index.php#extra'; if (!($text = Cache::get($cache_id))) { // side bar with the list of most recent pages if ($items =& Articles::list_by('publication', 0, COMPACT_LIST_SIZE, 'compact')) { $text =& Skin::build_box(i18n::s('Recent pages'), Skin::build_list($items, 'compact'), 'boxes'); } Cache::put($cache_id, $text, 'articles'); } $context['components']['boxes'] = $text; // referrals, if any $context['components']['referrals'] = Skin::build_referrals('comments/index.php'); // render the skin render_skin();
} // list future articles if (Surfer::is_associate() && ($rows =& Articles::list_by('future', 0, 5))) { if (is_array($rows)) { $rows = Skin::build_list($rows, 'decorated'); } $context['text'] .= Skin::build_box(i18n::s('Future articles'), $rows, 'header1', 'future'); } // list dead articles if (Surfer::is_associate() && ($rows =& Articles::list_by('expiry', 0, 10, 'hits'))) { if (is_array($rows)) { $rows = Skin::build_list($rows, 'decorated'); } $context['text'] .= Skin::build_box(i18n::s('Dead articles'), $rows, 'header1', 'expired'); } // list the oldest published articles, that have to be validated again if (Surfer::is_associate() && ($rows =& Articles::list_by('review', 0, 10, 'review'))) { if (is_array($rows)) { $rows = Skin::build_list($rows, 'decorated'); } $context['text'] .= Skin::build_box(i18n::s('Oldest articles'), $rows, 'header1', 'oldest'); } // list articles with very few hits if (Surfer::is_associate() && ($rows =& Articles::list_by('unread', 0, 10, 'hits'))) { if (is_array($rows)) { $rows = Skin::build_list($rows, 'decorated'); } $context['text'] .= Skin::build_box(i18n::s('Less read articles'), $rows, 'header1', 'unread'); } // render the skin render_skin();
if (Surfer::is_associate()) { $context['page_tools'][] = Skin::build_link('articles/review.php', i18n::s('Review queue'), 'basic'); $context['page_tools'][] = Skin::build_link('help/populate.php', i18n::s('Content Assistant')); $context['page_tools'][] = Skin::build_link('articles/import.php', i18n::s('Import articles'), 'basic'); $context['page_tools'][] = Skin::build_link('articles/check.php', i18n::s('Maintenance'), 'basic'); } // side bar with a rss feed, if this server is well populated if ($stats['count'] > $items_per_page) { $context['components']['channels'] = Skin::build_box(i18n::s('Information channels'), Skin::build_link(Feeds::get_url('rss'), i18n::s('Recent pages'), 'xml') . BR . Skin::build_link(Feeds::get_url('articles'), i18n::s('Full content'), 'xml'), 'channels'); } // page extra information $cache_id = 'articles/index.php#extra'; if (!($text = Cache::get($cache_id))) { // side bar with the list of most popular articles, if this server is well populated if ($stats['count'] > $items_per_page) { if ($items =& Articles::list_by('hits', 0, COMPACT_LIST_SIZE, 'compact')) { $text .= Skin::build_box(i18n::s('Popular'), Skin::build_list($items, 'compact'), 'boxes'); } } // side boxes for related categories, if any if ($categories = Categories::list_by_date_for_display('article:index', 0, 7, 'raw')) { foreach ($categories as $id => $attributes) { // link to the category page from the box title $label =& Skin::build_box_title(Skin::strip($attributes['title']), Categories::get_permalink($attributes), i18n::s('View the category')); // box content if ($items =& Members::list_articles_by_date_for_anchor('category:' . $id, 0, COMPACT_LIST_SIZE, 'compact')) { $text .= Skin::build_box($label, Skin::build_list($items, 'compact'), 'boxes') . "\n"; } } } // cache it, whatever change, for 1 minute
/** * list most recent articles * * Items order is provided by the layout. * * @param int the offset from the start of the list; usually, 0 or 1 * @param int the number of items to display * @param mixed the list variant, if any * @param string stamp of the minimum publication date to be considered * @return NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon) */ public static function &list_($offset = 0, $count = 10, $layout = 'decorated', $since = NULL) { global $context; // define items order if (is_callable(array($layout, 'items_order'))) { $order = $layout->items_order(); } if (!isset($order) || !$order) { $order = 'publication'; } // ask for ordered articles $output =& Articles::list_by($order, $offset, $count, $layout, $since); return $output; }
/** * render a compact list of recent modifications * * The provided anchor can reference: * - a section 'section:123' * - a category 'category:456' * - a user 'user:789' * - 'self' * - nothing * * @param string the anchor (e.g. 'section:123') * @param string layout to use * @return string the rendered text **/ public static function render_updated($layout = 'simple', $anchor = '') { global $context; // we return some text; $text = ''; // number of items to display $count = COMPACT_LIST_SIZE; if (($position = strpos($anchor, ',')) !== FALSE) { $count = (int) trim(substr($anchor, $position + 1)); if (!$count) { $count = COMPACT_LIST_SIZE; } $anchor = trim(substr($anchor, 0, $position)); } // scope is limited to current surfer if ($anchor == 'self' && Surfer::get_id()) { $anchor = 'user:'******'section:') === 0) { // look at this branch of the content tree $anchors = Sections::get_branch_at_anchor($anchor); // query the database and layout that stuff $text = Articles::list_for_anchor_by('edition', $anchors, 0, $count, $layout); // scope is limited to one category } elseif (strpos($anchor, 'category:') === 0) { // first level of depth $anchors = array(); // get sections linked to this category if ($topics = Members::list_sections_by_title_for_anchor($anchor, 0, 50, 'raw')) { foreach ($topics as $id => $not_used) { $anchors = array_merge($anchors, array('section:' . $id)); } } // second level of depth if (count($topics) && count($anchors) < 2000) { $topics = Sections::get_children_of_anchor($anchors); $anchors = array_merge($anchors, $topics); } // third level of depth if (count($topics) && count($anchors) < 2000) { $topics = Sections::get_children_of_anchor($anchors); $anchors = array_merge($anchors, $topics); } // fourth level of depth if (count($topics) && count($anchors) < 2000) { $topics = Sections::get_children_of_anchor($anchors); $anchors = array_merge($anchors, $topics); } // fifth level of depth if (count($topics) && count($anchors) < 2000) { $topics = Sections::get_children_of_anchor($anchors); $anchors = array_merge($anchors, $topics); } // the category itself is an anchor $anchors[] = $anchor; // ensure anchors are referenced only once $anchors = array_unique($anchors); // query the database and layout that stuff $text = Members::list_articles_by_date_for_anchor($anchors, 0, $count, $layout); // scope is limited to pages of one surfer } elseif (strpos($anchor, 'user:'******'edition', substr($anchor, 5), 0, $count, $layout); } else { $text = Articles::list_by('edition', 0, $count, $layout); } // we have an array to format if (is_array($text)) { $text = Skin::build_list($text, $layout); } // job done return $text; }
/** * get current news from this server * * Actually, this function lists most recent published articles. * * @param int the number of items to list * @param 'feed' to get a regular feed, or 'contents' to get everything * @return an array of array($time, $title, $author, $section, $image, $description) */ public static function get_local_news($count = 20, $variant = 'feed') { global $context; // list the newest published articles return Articles::list_by('publication', 0, $count, $variant); }