Beispiel #1
0
 /**
  * build a navigation bar to neighbours
  *
  * This function is useful to help surfers browse sets of images attached to some page.
  * In this case it is invoked from [script]images/view.php[/script], and the anchoring page
  * is supposed to provide URLs to previous and next neighbours ([code]$anchor->get_neighbours()[/code])
  *
  * @param an array of (previous_url, previous_label, next_url, next_label, option_url, option_label)
  * @param string describing the intended layout (ie, 'sidebar', 'manual', 'slideshow')
  * @result some text to be inserted in the page
  *
  * @see articles/view.php
  * @see comments/view.php
  * @see files/view.php
  * @see images/view.php
  * @see locations/view.php
  * @see shared/anchor.php
  */
 public static function &neighbours(&$data, $layout = 'sidebar')
 {
     global $context;
     // return by reference
     $output = NULL;
     // sanity check
     if (!is_array($data)) {
         return $output;
     }
     // extract navigation information from parameters
     $previous_url = '';
     if (isset($data[0]) && $data[0]) {
         $previous_url = $data[0];
     }
     if (!isset($data[1])) {
         $previous_label = $previous_hover = '';
     } elseif ($data[1] && $layout != 'manual') {
         $previous_label = Codes::strip($data[1]);
         $previous_hover = i18n::s('Previous');
     } else {
         $previous_label = i18n::s('Previous');
         $previous_hover = Codes::strip($data[1]);
     }
     $next_url = '';
     if (isset($data[2]) && $data[2]) {
         $next_url = $data[2];
     }
     if (!isset($data[3])) {
         $next_label = $next_hover = '';
     } elseif ($data[3] && $layout != 'manual') {
         $next_label = Codes::strip($data[3]);
         $next_hover = i18n::s('Next');
     } else {
         $next_label = i18n::s('Next');
         $next_hover = Codes::strip($data[3]);
     }
     $option_url = '';
     if (isset($data[4]) && $data[4]) {
         $option_url = $data[4];
     }
     $option_label = '';
     if (isset($data[5]) && $data[5]) {
         $option_label = Codes::strip($data[5]);
     }
     // nothing to do
     if (!$previous_url && !$next_url) {
         return $output;
     }
     // select a layout
     if (!$layout) {
         $layout = 'compact';
         if (preg_match('/\\bimg\\b/', $previous_label . ' ' . $next_label)) {
             $layout = 'table';
         }
     }
     // format labels
     switch ($layout) {
         case 'manual':
             // articles/view.php
             break;
         case 'sidebar':
         default:
             $previous_label = '« ' . $previous_label;
             $next_label = $next_label . ' »';
             break;
         case 'slideshow':
             // images/view.php
             Skin::define_img('PREVIOUS_PREFIX', 'tools/previous.gif', '« ');
             $previous_label = PREVIOUS_PREFIX . $previous_label;
             Skin::define_img('NEXT_SUFFIX', 'tools/next.gif', ' »');
             $next_label = $next_label . NEXT_SUFFIX;
             break;
     }
     // a link to go backwards
     $previous = '';
     if ($previous_url) {
         $previous =& Skin::build_link($previous_url, $previous_label, 'pager-previous', $previous_hover);
     }
     // a link to go forward
     $next = '';
     if ($next_url) {
         $next =& Skin::build_link($next_url, $next_label, 'pager-next', $next_hover);
     }
     // an option, if any
     $option = '';
     if ($option_url) {
         $option =& Skin::build_link($option_url, $option_label, 'basic');
     } elseif ($option_label) {
         $option = $option_label;
     }
     // layout everything
     $text = '';
     switch ($layout) {
         case 'manual':
             $items = array();
             if ($previous) {
                 $items[] = $previous;
             }
             if ($next) {
                 $items[] = $next;
             }
             if ($option) {
                 $items[] = $option;
             }
             $text .= '<p class="tiny" style="text-align: right; margin: 1em auto">' . implode(MENU_SEPARATOR, $items) . '</p>' . "\n";
             break;
         case 'sidebar':
         default:
             $text .= '<ul>';
             if ($previous) {
                 $text .= '<li class="previous">' . $previous . '</li>';
             }
             if ($next) {
                 $text .= '<li class="next">' . $next . '</li>';
             }
             $text .= '</ul>';
             break;
         case 'slideshow':
             $text .= '<table class="neighbours"><tr>' . '<td class="previous">' . ($previous ? $previous : '&nbsp;') . '</td>' . '<td class="option">' . ($option ? $option : '&nbsp;') . '</td>' . '<td class="next">' . ($next ? $next : '&nbsp;') . '</td>' . '</tr></table>' . "\n";
             break;
     }
     return $text;
 }
Beispiel #2
0
include_once '../feeds.php';
if (!($items = Feeds::get_local_news(20, 'compact'))) {
    return;
}
// keep only titles and ISO8859-1 labels
$titles = array();
$links = array();
$count = 0;
foreach ($items as $url => $label) {
    // we are not interested into all attributes
    if (is_array($label)) {
        $label = $label[1];
    }
    // strip codes
    include_once '../../codes/codes.php';
    $label = Codes::strip($label);
    // remove every html tag
    $label = strip_tags(Safe::html_entity_decode($label));
    // remember this
    $titles[$count] = $label;
    $links[$count] = $url;
    $count++;
}
// cache handling --except on scripts/validate.php
if (!headers_sent() && (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET')) {
    // this is a schockwave object
    Safe::header('Content-Type: application/x-shockwave-flash');
    // enable 30-minute caching (30*60 = 1800), even through https, to help IE6 on download
    http::expire(1800);
    // the original content
    $page = '';
Beispiel #3
0
 /**
  * list dates
  *
  * Recognize following variants:
  * - 'no_anchor' to list items attached to one particular anchor
  * - 'no_author' to list items attached to one user prodate
  *
  * @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 an array of ($url => $attributes)
     $items = array();
     // 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)) {
         // initialize variables
         $prefix = $suffix = $icon = '';
         // the url to view this item
         $url = Articles::get_permalink($item);
         // build a valid label
         $label = Codes::beautify_title($item['title']);
         // the introductory text
         if ($item['introduction']) {
             $suffix .= ' -&nbsp;' . Codes::strip($item['introduction']);
             // link to description, if any
             if ($item['description']) {
                 $suffix .= ' ' . Skin::build_link($url, MORE_IMG, 'more', i18n::s('View the page')) . ' ';
             }
         }
         // details
         $details = array();
         // item poster
         if ($item['edit_name']) {
             $details[] = sprintf(i18n::s('edited by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date']));
         }
         // 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']) {
             $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic');
         }
         // all details
         if (count($details)) {
             $suffix .= BR . '<span class="details">' . ucfirst(implode(', ', $details)) . '</span>';
         }
         // the icon to put in the left column
         if ($item['thumbnail_url']) {
             $icon = $item['thumbnail_url'];
         }
         // list all components for this item
         $items[$url] = array($prefix, $label, $suffix, 'date', $icon, $item['date_stamp']);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
Beispiel #4
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;
 }
Beispiel #5
0
 /**
  * format a title
  *
  * New lines and images are the only things accepted in titles.
  * The goal is to provide a faster service than beautify()
  *
  * @param string raw title
  * @return string finalized title
  */
 public static function beautify_title($text)
 {
     // suppress pairing codes
     $output = Codes::strip($text, FALSE);
     // the only code transformed in titles
     $output = str_replace(array('[nl]', '[NL]'), '<br />', $output);
     // remove everything, except links, breaks and images, and selected tags
     $output = strip_tags($output, '<a><abbr><acronym><b><big><br><code><del><div><dfn><em><i><img><ins><p><q><small><span><strong><sub><sup><tt><u>');
     // return by reference
     return $output;
 }