Beispiel #1
0
 /**
  * list childs of this anchor, with or without type filters
  * 
  * @param string set of desired childs (articles, sections...) separted by comma, or "all" keyword
  * @param int offset to start listing
  * @param int the maximum of items returned per type
  * @param mixed string or object the layout to use
  * @return an array of array with raw items sorted by type
  */
 function get_childs($filter = 'all', $offset = 0, $max = 50, $layout = 'raw')
 {
     // we return a array
     $childs = array();
     // files
     if ($filter == 'all' || preg_match('/\\bfiles?\\b/i', $filter)) {
         $childs['file'] = Files::list_by_title_for_anchor($this->get_reference(), $offset, $max, $layout);
     }
     return $childs;
 }
Beispiel #2
0
     $items_per_page = FILES_PER_PAGE;
 }
 // the first file to list
 $offset = ($page - 1) * $items_per_page;
 if (is_object($layout) && method_exists($layout, 'set_offset')) {
     $layout->set_offset($offset);
 }
 // a navigation bar for these files
 if ($count = Files::count_for_anchor($anchor->get_reference())) {
     $context['page_menu'] += array('_count' => sprintf(i18n::ns('%d file', '%d files', $count), $count));
     // navigation commands for files
     $prefix = Files::get_url($anchor->get_reference(), 'navigate');
     $context['page_menu'] += Skin::navigate($anchor->get_url('files'), $prefix, $count, $items_per_page, $page, FALSE);
     // list files by date or by title
     if ($anchor->has_option('files_by') == 'title') {
         $items = Files::list_by_title_for_anchor($anchor->get_reference(), $offset, $items_per_page, $anchor->get_reference());
     } else {
         $items = Files::list_by_date_for_anchor($anchor->get_reference(), $offset, $items_per_page, $anchor->get_reference());
     }
     // actually render the html
     if (is_array($items)) {
         $context['text'] .= Skin::build_list($items, 'decorated');
     } elseif (is_string($items)) {
         $context['text'] .= $items;
     }
 }
 // insert anchor suffix
 if (is_object($anchor)) {
     $context['text'] .= $anchor->get_suffix();
 }
 // page menu
Beispiel #3
0
     $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 section
 if ($count = Files::count_for_anchor('section:' . $item['id'], FALSE, $embedded)) {
     $attachments_count += $count;
     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 (preg_match('/\\bfiles_by_title\\b/i', $item['options'])) {
         $items = Files::list_by_title_for_anchor('section:' . $item['id'], $offset, FILES_PER_PAGE, 'section:' . $item['id'], $embedded);
     } else {
         $items = Files::list_by_date_for_anchor('section:' . $item['id'], $offset, FILES_PER_PAGE, 'section:' . $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;
     }
     // navigation commands for files
     $home = Sections::get_permalink($item);
     $prefix = Sections::get_url($item['id'], 'navigate', 'files');
     $box['bar'] = array_merge($box['bar'], Skin::navigate($home, $prefix, $count, FILES_PER_PAGE, $zoom_index));
 }
 // the command to post a new file -- check 'with_files' option
Beispiel #4
0
     $attachments_count += $count;
     if ($count > 20) {
         $box['bar'] += array('_count' => sprintf(i18n::ns('%d file', '%d files', $count), $count));
     }
     // compact list of files
     if ($compact = Articles::has_option('files_as_compact', $anchor, $item)) {
         $layout = Layouts::new_('compact', 'file');
         $layout->set_focus('article:' . $item['id']);
         // standard list of files
     } else {
         $layout = 'article:' . $item['id'];
     }
     // list files by date (default) or by title (option files_by_title)
     $offset = ($zoom_index - 1) * FILES_PER_PAGE;
     if ($cur_article->has_option('files_by') == 'title') {
         $items = Files::list_by_title_for_anchor('article:' . $item['id'], 0, 300, $layout, $embedded);
     } else {
         $items = Files::list_by_date_for_anchor('article:' . $item['id'], 0, 300, $layout, $embedded);
     }
     // actually render the html
     if (is_array($items)) {
         $box['text'] .= Skin::build_list($items, $compact ? 'compact' : 'decorated');
     } elseif (is_string($items)) {
         $box['text'] .= $items;
     }
     // the command to post a new file
     if (!$compact && $cur_article->allows('creation', 'file')) {
         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'));
     }
 }
Beispiel #5
0
 /**
  * build a notification related to a section
  *
  * 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 section
  * - a button linked to the section
  * - a link to the containing section, if any
  *
  * Note: this function returns legacy HTML, not modern XHTML, because this is what most
  * e-mail client software can afford.
  *
  * @param string either 'apply', 'create' 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, $item, $overlay = NULL)
 {
     global $context;
     // get the main anchor
     $anchor = Anchors::get($item['anchor']);
     // compute page title
     if (is_object($overlay)) {
         $title = Codes::beautify_title($overlay->get_text('title', $item));
     } else {
         $title = Codes::beautify_title($item['title']);
     }
     // headline template
     switch ($action) {
         case 'apply':
             $template = i18n::c('%s is requesting access to %s');
             break;
         case 'create':
             $template = i18n::c('%s has created section %s');
             break;
         case 'update':
             $template = i18n::c('%s has updated section %s');
             break;
     }
     // headline
     $headline = sprintf($template, Surfer::get_link(), '<a href="' . Sections::get_permalink($item) . '">' . $title . '</a>');
     // panel content
     $content = '';
     // signal restricted and private articles
     if ($item['active'] == 'N') {
         $title = PRIVATE_FLAG . $title;
     } elseif ($item['active'] == 'R') {
         $title = RESTRICTED_FLAG . $title;
     }
     // insert page title
     $content .= '<h3><span>' . $title . '</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('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'))) {
             $content .= Skin::build_block($label, 'title');
         }
         // beautify the target page
         $content .= Skin::build_block($description, 'description', '', $item['options']);
     }
     // attachment details
     $details = array();
     // info on related sections
     if ($count = Sections::count_for_anchor('section:' . $item['id'])) {
         $details[] = sprintf(i18n::nc('%d section', '%d sections', $count), $count);
     }
     // info on related articles
     if ($count = Articles::count_for_anchor('section:' . $item['id'])) {
         $details[] = sprintf(i18n::nc('%d page', '%d pages', $count), $count);
     }
     // info on related files
     if ($count = Files::count_for_anchor('section:' . $item['id'], TRUE)) {
         // the actual list of files attached to this section
         if (preg_match('/\\bfiles_by_title\\b/i', $item['options'])) {
             $items = Files::list_by_title_for_anchor('section:' . $item['id'], 0, 300, 'compact');
         } else {
             $items = Files::list_by_date_for_anchor('section:' . $item['id'], 0, 300, 'compact');
         }
         // wrap it with some header
         if (is_array($items)) {
             $items = Skin::build_list($items);
         }
         if ($items) {
             $content .= '<h3><span>' . i18n::s('Files') . '</span></h3>' . $items;
         }
         // details to be displayed at page bottom
         $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('section:' . $item['id'], TRUE)) {
         $details[] = sprintf(i18n::nc('%d link', '%d links', $count), $count);
     }
     // comments
     include_once $context['path_to_root'] . 'comments/comments.php';
     if ($count = Comments::count_for_anchor('section:' . $item['id'], TRUE)) {
         $details[] = sprintf(i18n::nc('%d comment', '%d comments', $count), $count);
     }
     // describe attachments
     if (count($details)) {
         $content .= '<hr align="left" size=1" width="150">' . '<p style="margin: 3px 0;">' . sprintf(i18n::c('This section 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'] . Sections::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 = Sections::get_permalink($item);
         if (!is_object($overlay) || !($label = $overlay->get_label('permalink_command', 'sections', FALSE))) {
             $label = i18n::c('View the section');
         }
         $menu[] = Skin::build_mail_button($link, $label, TRUE);
         // link to the container
         if (is_object($anchor)) {
             $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;
 }
Beispiel #6
0
 //
 // files attached to this category
 //
 // the list of related files if not at another follow-up page
 if (!$zoom_type || $zoom_type == 'files') {
     // build a complete box
     $box = array('bar' => array(), 'text' => '');
     // count the number of files in this category
     if ($count = Files::count_for_anchor('category:' . $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')
         $offset = ($zoom_index - 1) * FILES_PER_PAGE;
         if (isset($item['options']) && preg_match('/\\bfiles_by_title\\b/i', $item['options'])) {
             $items = Files::list_by_title_for_anchor('category:' . $item['id'], $offset, FILES_PER_PAGE, 'category:' . $item['id']);
         } else {
             $items = Files::list_by_date_for_anchor('category:' . $item['id'], $offset, FILES_PER_PAGE, 'category:' . $item['id']);
         }
         if (is_array($items)) {
             $box['text'] .= Skin::build_list($items, 'decorated');
         } else {
             $box['text'] .= $items;
         }
         // navigation commands for files
         $home = Categories::get_permalink($item);
         $prefix = Categories::get_url($item['id'], 'navigate', 'files');
         $box['bar'] = array_merge($box['bar'], Skin::navigate($home, $prefix, $count, FILES_PER_PAGE, $zoom_index));
     }
     // the command to post a new file
     $url = 'files/edit.php?anchor=' . urlencode('category:' . $item['id']);
 /**
  * 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;
 }
Beispiel #8
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;
 }
Beispiel #9
0
 if (isset($item['description']) && $item['description']) {
     $description = utf8::to_unicode(Codes::beautify($item['description'], $item['options']));
     // use adequate label
     if (is_object($overlay) && ($label = $overlay->get_label('description'))) {
         $context['text'] .= Skin::build_block($label, 'title') . '<div>' . $description . "</div>\n";
     } else {
         $context['text'] .= $description . "\n";
     }
 }
 //
 // attached files
 //
 // 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));
Beispiel #10
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;
 }
 /**
  * list articles as a daily weblog 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)) {
         if (Surfer::is_associate()) {
             $text .= '<p>' . sprintf(i18n::s('Use the %s to populate this server.'), Skin::build_link('help/populate.php', i18n::s('Content Assistant'), 'shortcut')) . '</p>';
         }
         return $text;
     }
     // 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)) {
         // three components per box
         $box = array();
         $box['date'] = '';
         $box['title'] = '';
         $box['content'] = '';
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // permalink
         $url = Articles::get_permalink($item);
         // make a live title
         if (is_object($overlay)) {
             $box['title'] .= Codes::beautify_title($overlay->get_text('title', $item));
         } else {
             $box['title'] .= Codes::beautify_title($item['title']);
         }
         // make a clickable title
         $box['title'] = Skin::build_link($url, $box['title'], 'basic');
         // signal restricted and private articles
         if ($item['active'] == 'N') {
             $box['title'] = PRIVATE_FLAG . $box['title'];
         } elseif ($item['active'] == 'R') {
             $box['title'] = RESTRICTED_FLAG . $box['title'];
         }
         // flag articles updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $box['title'] .= EXPIRED_FLAG;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $box['title'] .= NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $box['title'] .= UPDATED_FLAG;
         }
         // what's the date of publication?
         if (isset($item['publish_date']) && $item['publish_date'] > NULL_DATE) {
             $box['date'] .= Skin::build_date($item['publish_date'], 'publishing');
         }
         // the icon to put aside - never use anchor images
         if ($item['icon_url']) {
             $box['content'] .= '<a href="' . $context['url_to_root'] . $url . '"><img src="' . $item['icon_url'] . '" class="left_image" alt="" /></a>';
         }
         // details
         $details = array();
         // 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');
         }
         // show details
         if (count($details)) {
             $box['content'] .= '<p class="details">' . implode(' ~ ', $details) . '</p>' . "\n";
         }
         // list categories by title, if any
         if ($items = Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) {
             $tags = array();
             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>';
                 }
                 $tags[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic');
             }
             $box['content'] .= '<p class="tags">' . implode(' ', $tags) . '</p>';
         }
         // the introduction text, if any
         if (is_object($overlay)) {
             $box['content'] .= Skin::build_block($overlay->get_text('introduction', $item), 'introduction');
         } else {
             $box['content'] .= Skin::build_block($item['introduction'], 'introduction');
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $box['content'] .= $overlay->get_text('list', $item);
         }
         // the description
         $box['content'] .= Skin::build_block($item['description'], 'description', '', $item['options']);
         // a compact list of attached files
         if ($count = Files::count_for_anchor('article:' . $item['id'])) {
             // 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, 'compact');
             } else {
                 $items = Files::list_by_date_for_anchor('article:' . $item['id'], 0, FILES_PER_PAGE, 'compact');
             }
             if (is_array($items)) {
                 $items = Skin::build_list($items, 'compact');
             }
             if ($items) {
                 $box['content'] .= Skin::build_box(i18n::s('Files'), $items, 'header2');
             }
         }
         // build a menu
         $menu = array();
         // read the article
         $menu[] = Skin::build_link($url, i18n::s('Permalink'), 'span');
         // info on related files
         if ($count) {
             $menu[] = Skin::build_link($url . '#_attachments', sprintf(i18n::ns('%d file', '%d files', $count), $count), 'span');
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'])) {
             $menu[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'list'), sprintf(i18n::ns('%d comment', '%d comments', $count), $count), 'span');
         }
         // comment
         if (Comments::allow_creation($item, $anchor)) {
             $menu[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'comment'), i18n::s('Discuss'), 'span');
         }
         // info on related links
         if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
             $menu[] = Skin::build_link($url . '#_attachments', sprintf(i18n::ns('%d link', '%d links', $count), $count), 'span');
         }
         // trackback
         if (Links::allow_trackback()) {
             $menu[] = Skin::build_link('links/trackback.php?anchor=' . urlencode('article:' . $item['id']), i18n::s('Reference this page'), 'span');
         }
         // a menu bar
         if (count($menu)) {
             $box['content'] .= '<div class="menu_bar" style="clear: left;">' . MENU_PREFIX . implode(MENU_SEPARATOR, $menu) . MENU_SUFFIX . "</div>\n";
         }
         // build a simple box for this post
         $text .= '<div class="post">' . '<div class="date">' . $box['date'] . '</div>' . '<h2><span>' . $box['title'] . '</span></h2>' . '<div class="content">' . $box['content'] . '</div>' . '</div>';
     }
     // end of processing
     SQL::free($result);
     return $text;
 }
Beispiel #12
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 #13
0
     // actually render the html for the section
     if (is_array($items)) {
         $box['text'] .= Skin::build_list($items, 'decorated');
     } elseif (is_string($items)) {
         $box['text'] .= $items;
     }
     if ($box['text']) {
         $context['text'] .= Skin::build_box(i18n::s('What is new?'), $box['text']);
     }
 }
 //
 // attached files
 //
 // list files by date (default) or by title (option :files_by_title:)
 if (preg_match('/\\bfiles_by_title\\b/i', $item['options'])) {
     $items = Files::list_by_title_for_anchor('section:' . $item['id'], 0, 300, 'section:' . $item['id']);
 } else {
     $items = Files::list_by_date_for_anchor('section:' . $item['id'], 0, 300, 'section:' . $item['id']);
 }
 // actually render the html for the section
 if ($items) {
     $context['text'] .= Skin::build_box(i18n::s('Files'), Skin::build_list($items, 'decorated'));
 }
 //
 // 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();
Beispiel #14
0
}
// page title
$context['page_title'] = i18n::s('Files');
// stop crawlers
if (Surfer::is_crawler()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // an anchor is mandatory
} elseif (!is_object($anchor)) {
    Safe::header('Status: 404 Not Found', TRUE, 404);
    Logger::error(i18n::s('No anchor has been found.'));
    // provide updated information for this anchor
} else {
    // list files by date (default) or by title (option files_by_title)
    if ($anchor->has_option('files_by') == 'title') {
        $output = Files::list_by_title_for_anchor($anchor->get_reference(), 0, 20, 'compact');
    } else {
        $output = Files::list_by_date_for_anchor($anchor->get_reference(), 0, 20, 'compact');
    }
    // ensure we are producing some text
    if (is_array($output)) {
        // the command to list all files
        if (count($output)) {
            $output = array_merge($output, array(Files::get_url($anchor->get_reference(), 'list') => i18n::s('All files')));
        }
        $output =& Skin::build_list($output, 'compact');
    }
    // actual transmission except on a HEAD request
    if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
        echo $output;
    }
Beispiel #15
0
 /**
  * list childs of this anchor, with or without type filters
  * 
  * @param string set of desired childs (articles, sections...) separted by comma, or "all" keyword
  * @param int offset to start listing
  * @param int the maximum of items returned per type
  * @param mixed string or object the layout to use
  * @return an array of array with raw items sorted by type
  */
 function get_childs($filter = 'all', $offset = 0, $max = 50, $layout = 'raw')
 {
     // we return a array
     $childs = array();
     // sub-categories
     if ($filter == 'all' || preg_match('/\\bcategor(y|ies)\\b/i', $filter)) {
         $childs['category'] = Categories::list_by_title_for_anchor($this, $offset, $max, $layout);
     }
     // related articles
     if ($filter == 'all' || preg_match('/\\barticles?\\b/i', $filter)) {
         $childs['article'] = Members::list_articles_by_title_for_anchor($this->get_reference(), $offset, $max, $layout);
     }
     // related sections
     if ($filter == 'all' || preg_match('/\\bsections?\\b/i', $filter)) {
         $childs['section'] = Members::list_sections_by_title_for_anchor($this->get_reference(), $offset, $max, $layout);
     }
     // related users
     if ($filter == 'all' || preg_match('/\\busers?\\b/i', $filter)) {
         $childs['user'] = Members::list_users_by_name_for_anchor($this->get_reference(), $offset, $max, $layout);
     }
     // files
     if ($filter == 'all' || preg_match('/\\bfiles?\\b/i', $filter)) {
         $childs['file'] = Files::list_by_title_for_anchor($this->get_reference(), $offset, $max, $layout);
     }
     return $childs;
 }
 /**
  * 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;
 }
Beispiel #17
0
     $items =& Members::list_articles_by_title_for_anchor('category:' . $item['id'], 0, 50);
 } else {
     $items =& Members::list_articles_by_date_for_anchor('category:' . $item['id'], 0, 50);
 }
 // actually render the html for the section
 if ($items) {
     $context['text'] .= $section . Skin::build_list($items, 'decorated');
 }
 //
 // the files section
 //
 // title
 $section = Skin::build_block(i18n::s('Files'), 'title');
 // list files by date (default) or by title (option :files_by_title:)
 if (preg_match('/\\bfiles_by_title\\b/i', $item['options'])) {
     $items = Files::list_by_title_for_anchor('category:' . $item['id'], 0, 300, 'category:' . $item['id']);
 } else {
     $items = Files::list_by_date_for_anchor('category:' . $item['id'], 0, 300, 'category:' . $item['id']);
 }
 // actually render the html for the section
 if ($items) {
     $context['text'] .= $section . Skin::build_list($items, 'decorated');
 }
 //
 // the links section
 //
 // title
 $section = Skin::build_block(i18n::s('See also'), 'title');
 // list links by date (default) or by title (option :links_by_title:)
 if (preg_match('/\\blinks_by_title\\b/i', $item['options'])) {
     $items = Links::list_by_title_for_anchor('category:' . $item['id'], 0, 50);
Beispiel #18
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;
 }