コード例 #1
0
ファイル: layout_servers.php プロジェクト: rair/yacs
 /**
  * list servers
  *
  * @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
     while ($item = SQL::fetch($result)) {
         // initialize variables
         $prefix = $suffix = $icon = '';
         // the url to view this item
         $url = Servers::get_url($item['id']);
         // use the title as a label
         $label = Skin::strip($item['title'], 10);
         // flag files uploaded recently
         if ($item['edit_date'] >= $context['fresh']) {
             $prefix = NEW_FLAG . $prefix;
         }
         // description
         if ($item['description']) {
             $suffix .= ' ' . ucfirst(trim($item['description']));
         }
         // the menu bar for associates and poster
         if (Surfer::is_empowered() || Surfer::is($item['edit_id'])) {
             $menu = array(Servers::get_url($item['id'], 'edit') => i18n::s('Edit'), Servers::get_url($item['id'], 'delete') => i18n::s('Delete'));
             $suffix .= ' ' . Skin::build_list($menu, 'menu');
         }
         // add a separator
         if ($suffix) {
             $suffix = ' - ' . $suffix;
         }
         // append details to the suffix
         $suffix .= BR . '<span class="details">';
         // 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']));
         }
         // the edition date
         $details[] = Skin::build_date($item['edit_date']);
         // all details
         if (count($details)) {
             $suffix .= ucfirst(implode(', ', $details)) . "\n";
         }
         // end of details
         $suffix .= '</span>';
         // list all components for this item
         $items[$url] = array($prefix, $label, $suffix, 'server', $icon);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
コード例 #2
0
ファイル: members.php プロジェクト: rair/yacs
 /**
  * list alphabetically the sections related to any anchor
  *
  * Actually list sections by rank, then by title, then by date.
  * If you select to not use the ranking system, sections will be ordered by title only.
  * Else sections with a low ranking mark will appear first,
  * and sections with a high ranking mark will be put at the end of the list.
  *
  * Only sections matching following criteria are returned:
  * - section is visible (active='Y')
  * - section is restricted (active='R'), but surfer is a logged user
  * - section is restricted (active='N'), but surfer is an associate
  * - an expiry date has not been defined, or is not yet passed
  *
  * @param the target anchor
  * @param int the offset from the start of the list; usually, 0 or 1
  * @param int the number of items to display
  * @param string the list variant, if any
  * @return NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
  *
  * @see sections/select.php
  */
 public static function &list_sections_by_title_for_anchor($anchor, $offset = 0, $count = 10, $variant = 'compact')
 {
     global $context;
     // display active and restricted items
     $where = "sections.active='Y'";
     if (Surfer::is_logged()) {
         $where .= " OR sections.active='R'";
     }
     if (Surfer::is_empowered('S')) {
         $where .= " OR sections.active='N'";
     }
     $where = '(' . $where . ')';
     // only consider live sections
     $where .= " AND ((sections.expiry_date is NULL)" . "OR (sections.expiry_date <= '" . NULL_DATE . "') OR (sections.expiry_date > '" . $context['now'] . "'))";
     // the list of sections
     $query = "SELECT sections.*" . "\tFROM (" . SQL::table_name('members') . " AS members" . ", " . SQL::table_name('sections') . " AS sections)" . " WHERE (members.anchor LIKE '" . SQL::escape($anchor) . "')" . "\tAND (members.member_type = 'section')" . "\tAND (members.member_id = sections.id)" . "\tAND (" . $where . ")" . " ORDER BY sections.title, sections.edit_date DESC LIMIT " . $offset . ',' . $count;
     // use existing listing facility
     $output =& Sections::list_selected(SQL::query($query), $variant);
     return $output;
 }
コード例 #3
0
ファイル: layout_links.php プロジェクト: rair/yacs
 /**
  * list links
  *
  * Recognize following variants:
  * - 'no_anchor' to list items attached to one particular anchor
  * - 'no_author' to list items attached to one user prolink
  *
  * @param resource the SQL result
  * @return array of resulting items, or NULL
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return an array of ($url => $attributes)
     $items = array();
     // empty list
     if (!SQL::count($result)) {
         return $items;
     }
     // sanity check
     if (!isset($this->layout_variant)) {
         $this->layout_variant = 'no_anchor';
     }
     // process all items in the list
     while ($item = SQL::fetch($result)) {
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // initialize variables
         $prefix = $suffix = $icon = '';
         // make a label
         $label = Links::clean($item['title'], $item['link_url']);
         // flag links uploaded recently
         if ($item['edit_date'] >= $context['fresh']) {
             $prefix = NEW_FLAG . $prefix;
         }
         // the number of clicks
         if ($item['hits'] > 1) {
             $suffix .= ' (' . Skin::build_number($item['hits'], i18n::s('clicks')) . ') ';
         }
         // add a separator
         if ($suffix) {
             $suffix = ' - ' . $suffix;
         }
         // details
         $details = array();
         // item poster
         if ($item['edit_name'] && $this->layout_variant != 'no_author') {
             if (Surfer::is_member() || (!isset($context['content_without_details']) || $context['content_without_details'] != 'Y') || is_object($anchor) && $anchor->has_option('with_details')) {
                 $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']));
             }
         }
         // show an anchor link
         if ($this->layout_variant != 'no_anchor' && $this->layout_variant != 'no_author' && $item['anchor'] && ($anchor = Anchors::get($item['anchor']))) {
             $anchor_url = $anchor->get_url();
             $anchor_label = ucfirst($anchor->get_title());
             $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor_url, $anchor_label, 'article'));
         }
         // the menu bar for associates and poster
         if (Surfer::is_empowered() || Surfer::is($item['edit_id'])) {
             $details[] = Skin::build_link('links/edit.php?id=' . $item['id'], i18n::s('edit'), 'span');
             $details[] = Skin::build_link('links/delete.php?id=' . $item['id'], i18n::s('delete'), 'span');
         }
         // append details to the suffix
         if (count($details)) {
             $suffix .= BR . Skin::finalize_list($details, 'menu');
         }
         // description
         if ($item['description']) {
             $suffix .= BR . Codes::beautify($item['description']);
         }
         // build the actual link to check it
         if ($this->layout_variant == 'review') {
             $icon = $item['link_url'];
         }
         // url is the link itself -- hack for xhtml compliance
         $url = str_replace('&', '&amp;', $item['link_url']);
         // let the rendering engine guess the type of link
         $link_type = NULL;
         // except if we want to stay within this window
         if (isset($item['link_target']) && $item['link_target'] != 'I') {
             $link_type = 'external';
         }
         // hovering title
         $link_title = NULL;
         if (isset($item['link_title']) && $item['link_title']) {
             $link_title = $item['link_title'];
         }
         // pack everything
         $items[$url] = array($prefix, $label, $suffix, $link_type, $icon, $link_title);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
コード例 #4
0
ファイル: anchor.php プロジェクト: rair/yacs
 /**
  * check that the surfer is an editor of an anchor
  *
  * This function is used to control the authority delegation from the anchor.
  * For example, if some editor is assigned to a complete section of the
  * web site, he/she should be able to edit all articles in this section.
  * you can use following code to check that:
  * [php]
  * $anchor = Anchors::get($article['anchor']);
  * if($anchor->is_assigned() {
  *	 ...
  * }
  * [/php]
  *
  * A logged member is always considered as an editor if he has created the target item.
  *
  * An anonymous surfer is considered as an editor if he has provided the secret handle.
  *
  * To be overloaded into derived class if field has a different name
  *
  * @param int optional reference to some user profile
  * @param boolean TRUE to climb the list of containers up to the top
  * @return TRUE or FALSE
  */
 function is_assigned($user_id = NULL, $cascade = TRUE)
 {
     global $context;
     // we need some data to proceed
     if (!isset($this->item['id'])) {
         return FALSE;
     }
     // id of requesting user
     if (!$user_id) {
         $user_id = Surfer::get_id();
     }
     // anonymous is allowed
     if (!$user_id) {
         $user_id = 0;
     }
     // create the cache
     if (!isset($this->is_assigned_cache)) {
         $this->is_assigned_cache = array();
     }
     // cache the answer
     if (isset($this->is_assigned_cache[$user_id])) {
         return $this->is_assigned_cache[$user_id];
     }
     // surfer has provided the secret handle
     if (isset($this->item['handle']) && Surfer::may_handle($this->item['handle'])) {
         return $this->is_assigned_cache[$user_id] = TRUE;
     }
     // surfer owns this item
     if ($user_id && isset($this->item['owner_id']) && $user_id == $this->item['owner_id']) {
         return $this->is_assigned_cache[$user_id] = TRUE;
     }
     // anchor has been assigned to this surfer
     if ($user_id && Members::check('user:'******'active'] == 'Y' && $this->has_option('anonymous_edit')) {
         return $this->is_assigned_cache[$user_id] = TRUE;
     }
     // members edition is allowed
     if ($this->item['active'] == 'Y' && Surfer::is_empowered('M') && $this->has_option('members_edit')) {
         return $this->is_assigned_cache[$user_id] = TRUE;
     }
     // check parent container
     if ($cascade && isset($this->item['anchor'])) {
         // save requests
         if (!isset($this->anchor) || !$this->anchor) {
             $this->anchor = Anchors::get($this->item['anchor']);
         }
         // check for ownership
         if (is_object($this->anchor)) {
             return $this->is_assigned_cache[$user_id] = $this->anchor->is_assigned($user_id);
         }
     }
     // sorry
     return $this->is_assigned_cache[$user_id] = FALSE;
 }
コード例 #5
0
ファイル: view.php プロジェクト: rair/yacs
// owners can do what they want
if ($cur_article->allows('modification')) {
    Surfer::empower();
} elseif (Surfer::is_logged() && is_object($anchor) && $anchor->is_assigned()) {
    Surfer::empower('S');
} elseif (isset($item['id']) && $cur_article->is_assigned() && Surfer::is_logged()) {
    Surfer::empower('S');
}
// is the article on user watch list?
$in_watch_list = FALSE;
if (isset($item['id']) && Surfer::get_id()) {
    $in_watch_list = Members::check('article:' . $item['id'], 'user:'******'id']) && !$zoom_type && Surfer::is_empowered() && Versions::count_for_anchor('article:' . $item['id'])) {
    $has_versions = TRUE;
}
// load the skin, maybe with a variant
load_skin('article', $anchor, isset($item['options']) ? $item['options'] : '');
// clear the tab we are in
if (is_object($anchor)) {
    $context['current_focus'] = $anchor->get_focus();
}
// current item
if (isset($item['id'])) {
    $context['current_item'] = 'article:' . $item['id'];
}
// path to this page
if ($whole_rendering) {
    $context['path_bar'] = Surfer::get_path_bar($anchor);
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
ファイル: layout_locations.php プロジェクト: rair/yacs
 /**
  * list locations
  *
  * Recognize following variants:
  * - 'no_anchor' to list items attached to one particular anchor
  * - 'no_author' to list items attached to one user prolocation
  *
  * @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
     while ($item = SQL::fetch($result)) {
         // initialize variables
         $prefix = $suffix = $icon = '';
         // the url to view this item
         $url = Locations::get_url($item['id']);
         // build a valid label
         if ($item['geo_place_name']) {
             $label = Skin::strip($item['geo_place_name'], 10);
         } else {
             $label = $item['latitude'] . ', ' . $item['longitude'];
         }
         // description
         if ($item['description']) {
             $suffix .= ' ' . ucfirst(trim($item['description']));
         }
         // the menu bar for associates and poster
         if (Surfer::is_empowered() || Surfer::is($item['edit_id'])) {
             $menu = array(Locations::get_url($item['id'], 'edit') => i18n::s('Edit'), Locations::get_url($item['id'], 'delete') => i18n::s('Delete'));
             $suffix .= ' ' . Skin::build_list($menu, 'menu');
         }
         // add a separator
         if ($suffix) {
             $suffix = ' - ' . $suffix;
         }
         // append details to the suffix
         $suffix .= BR . '<span class="details">';
         // details
         $details = array();
         // item poster
         if (isset($this->layout_variant) && $this->layout_variant != 'no_author') {
             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']));
             }
         } else {
             $details[] = Anchors::get_action_label($item['edit_action']);
         }
         // show an anchor location
         if (isset($this->layout_variant) && $this->layout_variant != 'no_anchor' && $item['anchor'] && ($anchor = Anchors::get($item['anchor']))) {
             $anchor_url = $anchor->get_url();
             $anchor_label = ucfirst($anchor->get_title());
             $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor_url, $anchor_label, 'article'));
         }
         // all details
         if (count($details)) {
             $suffix .= ucfirst(implode(', ', $details)) . "\n";
         }
         // end of details
         $suffix .= '</span>';
         // list all components for this item
         $items[$url] = array($prefix, $label, $suffix, 'location', $icon);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
コード例 #8
0
ファイル: view.php プロジェクト: rair/yacs
 // assemble tabs
 //
 if (!$zoom_type) {
     $panels[] = array('followers', i18n::s('Followers'), 'followers_panel', NULL, Users::get_url($item['id'], 'element', 'watch'));
 }
 // let YACS do the hard job
 $context['text'] .= Skin::build_tabs($panels);
 //
 // populate the extra panel
 //
 // page tools
 //
 // tools to maintain my page
 if (Surfer::is_empowered()) {
     // change avatar
     if (Surfer::is_empowered() && isset($item['avatar_url']) && $item['avatar_url']) {
         Skin::define_img('IMAGES_ADD_IMG', 'images/add.gif');
         $label = i18n::s('Change picture');
         $context['page_tools'][] = Skin::build_link(Users::get_url($item['id'], 'select_avatar'), IMAGES_ADD_IMG . $label, 'basic');
     }
     // modify this page
     Skin::define_img('USERS_EDIT_IMG', 'users/edit.gif');
     $context['page_tools'][] = Skin::build_link(Users::get_url($item['id'], 'edit'), USERS_EDIT_IMG . i18n::s('Edit this profile'), 'basic', i18n::s('Press [e] to edit'), FALSE, 'e');
     // change password
     if (!isset($context['users_authenticator']) || !$context['users_authenticator']) {
         Skin::define_img('USERS_PASSWORD_IMG', 'users/password.gif');
         $context['page_tools'][] = Skin::build_link(Users::get_url($item['id'], 'password'), USERS_PASSWORD_IMG . i18n::s('Change password'), 'basic');
     }
     // only associates can delete user profiles; self-deletion may also be allowed
     if (isset($item['id']) && !$zoom_type && $permitted && (Surfer::is_associate() || Surfer::is($item['id']) && (!isset($context['users_without_self_deletion']) || $context['users_without_self_deletion'] != 'Y'))) {
         Skin::define_img('USERS_DELETE_IMG', 'users/delete.gif');
コード例 #9
0
ファイル: dates.php プロジェクト: rair/yacs
 /**
  * get some statistics for one anchor
  *
  * @param the selected anchor (e.g., 'article:12')
  * @return the resulting ($count, $min_date, $max_date) array
  */
 public static function stat_past_for_anchor($anchor)
 {
     global $context;
     // restrict the query to addressable content
     $where = Articles::get_sql_where();
     // put only published pages in boxes
     if (isset($variant) && $variant == 'boxes') {
         $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
         // provide published pages to anonymous surfers
     } elseif (!Surfer::is_logged()) {
         $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
         // logged surfers that are non-associates are restricted to their own articles, plus published articles
     } elseif (!Surfer::is_empowered()) {
         $where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))";
     }
     // now
     $match = gmstrftime('%Y-%m-%d %H:%M:%S');
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(articles.edit_date) as oldest_date, MAX(articles.edit_date) as newest_date " . " FROM " . SQL::table_name('dates') . " as dates " . ", " . SQL::table_name('articles') . " AS articles" . " WHERE ((dates.anchor_type LIKE 'article') AND (dates.anchor_id = articles.id))" . "\tAND (dates.date_stamp < '" . SQL::escape($match) . "') AND\t(articles.anchor = '" . SQL::escape($anchor) . "') AND " . $where;
     $output = SQL::query_first($query);
     return $output;
 }
コード例 #10
0
ファイル: feed.php プロジェクト: rair/yacs
$id = NULL;
if (isset($_REQUEST['id'])) {
    $id = $_REQUEST['id'];
} elseif (isset($context['arguments'][0])) {
    $id = $context['arguments'][0];
}
$id = strip_tags($id);
// get the item from the database
$item = Sections::get($id);
// get the related anchor, if any
$anchor = NULL;
if (isset($item['anchor']) && $item['anchor']) {
    $anchor = Anchors::get($item['anchor']);
}
// editors have associate-like capabilities
if (Surfer::is_empowered('M') && (isset($item['id']) && isset($user['id']) && Sections::is_assigned($item['id'], $user['id'])) || is_object($anchor) && $anchor->is_assigned()) {
    Surfer::empower('A');
}
// load a skin, maybe with a variant
load_skin('sections', $anchor, isset($item['options']) ? $item['options'] : '');
// path to this page
$context['path_bar'] = array('sections/' => i18n::s('Site map'));
// page title
$context['page_title'] = i18n::s('RSS feed');
// not found
if (!isset($item['id']) || !$item['id']) {
    include '../error.php';
    // access denied
} elseif (!Sections::allow_access($item, $anchor)) {
    // give anonymous surfers a chance for HTTP authentication
    if (!Surfer::is_logged()) {
コード例 #11
0
ファイル: print.php プロジェクト: rair/yacs
 // restricted to logged members
 if ($item['active'] == 'R') {
     $details[] = RESTRICTED_FLAG . i18n::s('Community - Access is granted to any identified surfer');
 } elseif ($item['active'] == 'N') {
     $details[] = PRIVATE_FLAG . i18n::s('Private - Access is restricted to selected persons');
 }
 // rank for this section
 if (intval($item['rank']) != 10000 && Surfer::is_associate()) {
     $details[] = sprintf(i18n::s('Rank: %s'), $item['rank']);
 }
 // signal sections to be activated
 if (Surfer::is_empowered() && $item['activation_date'] > $context['now']) {
     $details[] = DRAFT_FLAG . ' ' . sprintf(i18n::s('Section will be activated %s'), Skin::build_date($item['activation_date']));
 }
 // expired section
 if (Surfer::is_empowered() && $item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
     $details[] = EXPIRED_FLAG . ' ' . sprintf(i18n::s('Section has expired %s'), Skin::build_date($item['expiry_date']));
 }
 // display details, if any
 if (count($details)) {
     $context['text'] .= '<p>' . ucfirst(implode(BR . "\n", $details)) . "</p>\n";
 }
 // insert anchor prefix
 if (is_object($anchor)) {
     $context['text'] .= $anchor->get_prefix();
 }
 // the introduction text, if any
 $context['text'] .= Skin::build_block($item['introduction'], 'introduction');
 // the description, which is the actual page body
 $context['text'] .= Skin::build_block($item['description'], 'description', '', $item['options']);
 //
コード例 #12
0
 /**
  * format just one item
  *
  * This is used within this script, but also to shape sections assigned
  * to the surfer in the web form for new articles.
  *
  * @param array attributes of one item
  * @return array of ($url => array($prefix, $label, $suffix, ...))
  *
  * @see articles/edit.php
  **/
 function one(&$item)
 {
     global $context;
     // this function is invoked directly from articles/edit.php
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     // sanity check
     if (!isset($this->layout_variant)) {
         $this->layout_variant = 'articles/edit.php?anchor=section:';
     }
     // 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;
     } elseif ($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;
     }
     // details
     $details = array();
     // info on related articles
     if ($count = Members::count_articles_for_anchor('section:' . $item['id'])) {
         $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
     }
     // info on related files
     if ($count = Files::count_for_anchor('section:' . $item['id'], TRUE)) {
         $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
     }
     // info on related links
     if ($count = Links::count_for_anchor('section:' . $item['id'], TRUE)) {
         $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
     }
     // info on related comments
     if ($count = Comments::count_for_anchor('section:' . $item['id'], TRUE)) {
         $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
     }
     // append details to the suffix
     if (count($details)) {
         $suffix .= "\n" . '<span class="details">(' . implode(', ', $details) . ')</span>';
     }
     // introduction
     if ($item['introduction']) {
         $suffix .= ' ' . Codes::beautify_introduction(trim($item['introduction']));
     }
     // add a head list of related links
     $subs = array();
     // add sub-sections on index pages
     if ($related =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, 2 * YAHOO_LIST_SIZE, 'raw')) {
         foreach ($related as $id => $attributes) {
             // look for sub-sub-sections
             $leaves = array();
             if ($children =& Sections::list_by_title_for_anchor('section:' . $id, 0, 50, 'raw')) {
                 foreach ($children as $child_id => $child_attributes) {
                     $child_url = $this->layout_variant . $child_id;
                     $leaves[$child_url] = $child_attributes['title'];
                 }
             }
             // link for this sub-section
             $url = $this->layout_variant . $id;
             // expose sub-sub-sections as well
             if (count($leaves) > YAHOO_LIST_SIZE) {
                 $subs[$url] = array('', $attributes['title'], Skin::build_box(i18n::s('More spaces'), Skin::build_list($leaves, 'compact'), 'folded'));
             } elseif (count($leaves)) {
                 $subs[$url] = array('', $attributes['title'], Skin::build_list($leaves, 'compact'));
             } else {
                 $subs[$url] = $attributes['title'];
             }
         }
     }
     // one sub-section per line
     if (count($subs)) {
         $suffix .= Skin::build_list($subs, 'compact');
     }
     // put the actual icon in the left column
     if (isset($item['thumbnail_url'])) {
         $icon = $item['thumbnail_url'];
     }
     // only associates and editors can post to a locked section
     if (isset($item['locked']) && $item['locked'] == 'Y' && !Surfer::is_empowered()) {
         $url = '_' . $item['id'];
     } else {
         $url = $this->layout_variant . $item['id'];
     }
     // use the title to label the link
     $label = Skin::strip($item['title'], 50);
     // list all components for this item
     $output = array($url => array($prefix, $label, $suffix, 'section', $icon));
     return $output;
 }
コード例 #13
0
ファイル: layout_links_as_daily.php プロジェクト: rair/yacs
 /**
  * list blogmarks
  *
  * @param resource the SQL result
  * @return string resulting text
  **/
 function layout($result)
 {
     global $context;
     // we return a string
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // start in north
     $in_north = TRUE;
     // define allowed HTML tags for the cover page
     define('ALLOWED_HTML_TAGS', '<a><b><br><h1><h2><h3><i><img><li><ol><p><ul>');
     // build a list of articles
     $box = array();
     $box['content'] = '';
     $previous_date = NULL;
     while ($item = SQL::fetch($result)) {
         // not the same date
         $current_date = substr($item['edit_date'], 0, 10);
         if ($previous_date != $current_date) {
             // insert a complete box for the previous date
             if ($box['content']) {
                 if ($in_north) {
                     $text .= '<div class="newest">' . "\n";
                 }
                 $text .= Skin::build_box($box['title'], $box['content']);
                 if ($in_north) {
                     $text .= '</div>' . "\n";
                 }
                 $in_north = FALSE;
             }
             // prepare a box for a new date
             $previous_date = $current_date;
             $box['title'] = Skin::build_date($item['edit_date'], 'no_hour');
             $box['content'] = '';
         }
         $box['content'] .= '<br clear="both" />';
         // time
         $box['content'] .= '<span class="details">' . substr($item['edit_date'], 11, 5) . '</span> ';
         // make a label
         $label = Links::clean($item['title'], $item['link_url']);
         $box['content'] .= Skin::build_link($item['link_url'], $label);
         // flag links updated recently
         if ($item['edit_date'] >= $context['fresh']) {
             $box['content'] .= ' ' . NEW_FLAG;
         }
         // the description
         if (trim($item['description'])) {
             $box['content'] .= "\n<br/>" . Skin::cap(Codes::beautify($item['description']), 500) . "\n";
         }
         // the menu bar for associates and poster
         if (Surfer::is_empowered() || Surfer::is($item['edit_id'])) {
             $menu = array('links/edit.php?id=' . $item['id'] => i18n::s('Edit'), 'links/delete.php?id=' . $item['id'] => i18n::s('Delete'));
             $box['content'] .= ' ' . Skin::build_list($menu, 'menu');
         }
         // append details to the suffix
         $box['content'] .= BR . '<span class="details">';
         // details
         $details = array();
         // item poster
         if (Surfer::is_member()) {
             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']));
             }
         } else {
             $details[] = Anchors::get_action_label($item['edit_action']);
         }
         // show an anchor link
         if ($item['anchor'] && ($anchor = Anchors::get($item['anchor']))) {
             $anchor_url = $anchor->get_url();
             $anchor_label = ucfirst($anchor->get_title());
             $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor_url, $anchor_label));
         }
         // all details
         $box['content'] .= ucfirst(trim(implode(' ', $details))) . "\n";
         // end of details
         $box['content'] .= '</span><br/><br/>';
     }
     // close the on-going box
     if ($in_north) {
         $text .= '<div class="newest">' . "\n";
     }
     $text .= Skin::build_box($box['title'], $box['content']);
     if ($in_north) {
         $text .= '</div>' . "\n";
     }
     // end of processing
     SQL::free($result);
     return $text;
 }
コード例 #14
0
ファイル: fetch_as_csv.php プロジェクト: rair/yacs
} elseif (Surfer::is_logged() && is_object($anchor) && $anchor->is_assigned()) {
    Surfer::empower('S');
} elseif (isset($item['id']) && Articles::is_assigned($item['id']) && Surfer::is_logged()) {
    Surfer::empower('S');
} elseif (isset($item['options']) && $item['options'] && preg_match('/\\banonymous_edit\\b/i', $item['options'])) {
    Surfer::empower();
} elseif (Surfer::is_member() && isset($item['options']) && $item['options'] && preg_match('/\\bmembers_edit\\b/i', $item['options'])) {
    Surfer::empower();
} elseif (isset($item['handle']) && Surfer::may_handle($item['handle'])) {
    Surfer::empower();
}
//
// is this surfer allowed to browse the page?
//
// associates, editors and readers can read this page
if (Surfer::is_empowered('S')) {
    $permitted = TRUE;
} elseif (isset($item['create_id']) && Surfer::is($item['create_id'])) {
    $permitted = TRUE;
} elseif (is_object($anchor) && !$anchor->is_viewable()) {
    $permitted = FALSE;
} elseif (isset($item['active']) && $item['active'] == 'R' && Surfer::is_logged()) {
    $permitted = TRUE;
} elseif (isset($item['active']) && $item['active'] == 'Y') {
    $permitted = TRUE;
} else {
    $permitted = FALSE;
}
// load localized strings
i18n::bind('overlays');
// load the skin, maybe with a variant
コード例 #15
0
ファイル: comments.php プロジェクト: rair/yacs
 /**
  * thread newest comments
  *
  * Result of this query should be processed with a layout adapted to articles
  *
  * @param int the offset from the start of the list; usually, 0 or 1
  * @param int the number of items to display
  * @param string the list variant, if any
  * @return NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
  *
  * @see comments/index.php
  */
 public static function &list_threads_by_date_for_anchor($anchor, $offset = 0, $count = 10, $variant = 'date')
 {
     global $context;
     // restrict the query to addressable content
     $where = Articles::get_sql_where();
     // provide published pages to anonymous surfers
     if (!Surfer::is_logged()) {
         $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
         // logged surfers that are non-associates are restricted to their own articles, plus published articles
     } elseif (!Surfer::is_empowered()) {
         $where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))";
     }
     // only consider live articles for non-associates
     if (!Surfer::is_empowered()) {
         $where .= " AND ((articles.expiry_date is NULL) " . "OR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . $context['now'] . "'))";
     }
     // if not associate, restrict to comments at public published not expired pages
     if (!Surfer::is_associate()) {
         $where = " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND ((articles.expiry_date is NULL)" . "\tOR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'))";
     }
     // avoid blank records on join
     $where .= ' AND (articles.id > 0)';
     // several anchors
     if (is_array($anchor)) {
         $items = array();
         foreach ($anchor as $token) {
             $items[] = "articles.anchor LIKE '" . SQL::escape($token) . "'";
         }
         $where_anchor = join(' OR ', $items);
     } else {
         $where_anchor = "articles.anchor LIKE '" . SQL::escape($anchor) . "'";
     }
     // the list of comments
     $query = "SELECT articles.* FROM " . SQL::table_name('comments') . " AS comments" . ", " . SQL::table_name('articles') . " AS articles" . " WHERE ((comments.anchor_type LIKE 'article') AND (comments.anchor_id = articles.id))" . "\tAND (" . $where_anchor . ") AND " . $where . " GROUP BY articles.id" . " ORDER BY articles.edit_date DESC LIMIT " . $offset . ',' . $count;
     // return a list of articles
     $output =& Articles::list_selected(SQL::query($query), $variant);
     return $output;
 }
コード例 #16
0
ファイル: edit.php プロジェクト: rair/yacs
 //
 $menu = array();
 if ($whole_rendering) {
     // the submit button
     $menu[] = Skin::build_submit_button(i18n::s('Submit'), i18n::s('Press [s] to submit data'), 's');
     // cancel button
     if (isset($item['id'])) {
         $menu[] = Skin::build_link(Categories::get_permalink($item), i18n::s('Cancel'), 'span');
     }
     // insert the menu in the page
     $context['text'] .= Skin::finalize_list($menu, 'assistant_bar');
 }
 // several options to check
 $input = array();
 // do not stamp edition date -- complex command
 if (Surfer::is_empowered() && isset($item['id']) && Surfer::has_all()) {
     $input[] = '<input type="checkbox" name="silent" value="Y" /> ' . i18n::s('Do not change modification date.');
 }
 // validate page content
 $input[] = '<input type="checkbox" name="option_validate" value="Y" checked="checked" /> ' . i18n::s('Ensure this post is valid XHTML.');
 // append post-processing options
 if ($input) {
     $context['text'] .= '<p>' . implode(BR, $input) . '</p>';
 }
 // transmit the id as a hidden field
 if (isset($item['id']) && $item['id']) {
     $context['text'] .= '<input type="hidden" name="id" value="' . $item['id'] . '" />';
 }
 // end of the form
 $context['text'] .= '</div></form>';
 // append the script used for data checking on the browser
コード例 #17
0
 /**
  * list sections
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // empty list
     if (!SQL::count($result)) {
         return $text;
     }
     // maximum number of items
     if (isset($this->layout_variant) && $this->layout_variant > 3) {
         $maximum_items = $this->layout_variant;
     } elseif (defined('YAHOO_LIST_SIZE')) {
         $maximum_items = YAHOO_LIST_SIZE;
     } else {
         $maximum_items = 7;
     }
     // clear flows
     $text .= '<br style="clear: left" />';
     // process all items in the list
     $family = '';
     while ($item = SQL::fetch($result)) {
         // change the family
         if ($item['family'] != $family) {
             $family = $item['family'];
             $text .= '<h2><span>' . $family . '&nbsp;</span></h2>' . "\n";
         }
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // the url to view this item
         $url = Sections::get_permalink($item);
         // initialize variables
         $prefix = $label = $suffix = $icon = $hover = '';
         // signal restricted and private sections
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // 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;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix .= NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= UPDATED_FLAG;
         }
         // display introduction field on hovering
         if ($item['introduction']) {
             $hover .= strip_tags(Codes::beautify_introduction($item['introduction']));
         }
         // details and content
         $details = array();
         $content = array();
         // count related sub-elements
         $related_count = 0;
         // info on related articles
         if ($count = Articles::count_for_anchor('section:' . $item['id'])) {
             if ($count > $maximum_items) {
                 $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
             } elseif (Surfer::is_empowered()) {
                 $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
             }
             $related_count += $count;
             // get the overlay for content of this section, if any
             $content_overlay = NULL;
             if (isset($item['content_overlay'])) {
                 $content_overlay = Overlay::bind($item['content_overlay']);
             }
             // no room to list articles
             if (count($content) >= $maximum_items) {
             } elseif (is_object($content_overlay) && is_callable(array($content_overlay, 'render_list_for_anchor'))) {
                 if ($related = $content_overlay->render_list_for_anchor('section:' . $item['id'], $maximum_items - count($content))) {
                     foreach ($related as $sub_url => $label) {
                         $sub_prefix = $sub_suffix = $sub_hover = '';
                         if (is_array($label)) {
                             $sub_prefix = $label[0];
                             $sub_suffix = $label[2];
                             if (@$label[5]) {
                                 $sub_hover = $label[5];
                             }
                             $label = $label[1];
                         }
                         $content[] = $sub_prefix . $label . $sub_suffix;
                     }
                 }
                 // regular rendering of related articles
             } else {
                 if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) {
                     $order = $matches[1];
                 } else {
                     $order = 'edition';
                 }
                 if ($related =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, $maximum_items - count($content), 'compact')) {
                     foreach ($related as $sub_url => $label) {
                         $sub_prefix = $sub_suffix = $sub_hover = '';
                         if (is_array($label)) {
                             $sub_prefix = $label[0];
                             $sub_suffix = $label[2];
                             if (@$label[5]) {
                                 $sub_hover = $label[5];
                             }
                             $label = $label[1];
                         }
                         $content[] = $sub_prefix . $label . $sub_suffix;
                     }
                 }
             }
         }
         // info on related files
         if ($count = Files::count_for_anchor('section:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
             $related_count += $count;
             // add related files if necessary
             if (count($content) < $maximum_items && ($related = Files::list_by_date_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), 'compact'))) {
                 foreach ($related as $sub_url => $label) {
                     $sub_prefix = $sub_suffix = $sub_hover = '';
                     if (is_array($label)) {
                         $sub_prefix = $label[0];
                         $sub_suffix = $label[2];
                         if (@$label[5]) {
                             $sub_hover = $label[5];
                         }
                         $label = $label[1];
                     }
                     $content[] = $sub_prefix . $label . $sub_suffix;
                 }
             }
         }
         // info on related links
         if ($count = Links::count_for_anchor('section:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
             $related_count += $count;
             // add related links if necessary
             if (count($content) < $maximum_items && ($related = Links::list_by_date_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), 'compact'))) {
                 foreach ($related as $sub_url => $label) {
                     $sub_prefix = $sub_suffix = $sub_hover = '';
                     if (is_array($label)) {
                         $sub_prefix = $label[0];
                         $sub_suffix = $label[2];
                         if (@$label[5]) {
                             $sub_hover = $label[5];
                         }
                         $label = $label[1];
                     }
                     $content[] = $sub_prefix . $label . $sub_suffix;
                 }
             }
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('section:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
             $related_count += $count;
         }
         // info on related sections
         if ($count = Sections::count_for_anchor('section:' . $item['id'])) {
             if ($count > $maximum_items) {
                 $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count);
             } elseif (Surfer::is_empowered()) {
                 $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count);
             }
             $related_count += $count;
             // add sub-sections
             if ($related =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), 'compact')) {
                 foreach ($related as $sub_url => $label) {
                     $sub_prefix = $sub_suffix = $sub_hover = '';
                     if (is_array($label)) {
                         $sub_prefix = $label[0];
                         $sub_suffix = $label[2];
                         if (@$label[5]) {
                             $sub_hover = $label[5];
                         }
                         $label = $label[1];
                     }
                     $content[] = $sub_prefix . $label . $sub_suffix;
                 }
             }
         }
         // give me more
         if (count($content) && $related_count > $maximum_items) {
             $content[] = '...' . MORE_IMG;
         }
         // layout details
         if (count($content)) {
             $hover .= '<ul><li>' . implode('</li><li>', $content) . '</li></ul>';
         }
         // add a link to the main page
         if (!$hover) {
             $hover = i18n::s('View the section');
         }
         // use the title to label the link
         $title = Skin::strip($item['title'], 50);
         // new or updated flag
         if ($suffix) {
             $details[] = $suffix;
         }
         // append details
         if (count($details)) {
             $title .= BR . '<span class="details">' . implode(', ', $details) . '</span>';
         }
         // look for an image
         $icon = '';
         if (isset($item['thumbnail_url']) && $item['thumbnail_url']) {
             $icon = $item['thumbnail_url'];
         } elseif (is_callable(array($anchor, 'get_bullet_url'))) {
             $icon = $anchor->get_bullet_url();
         }
         // use the thumbnail for this section
         if ($icon) {
             // fix relative path
             if (!preg_match('/^(\\/|http:|https:|ftp:)/', $icon)) {
                 $icon = $context['url_to_root'] . $icon;
             }
             // use parameter of the control panel for this one
             $options = '';
             if (isset($context['classes_for_thumbnail_images'])) {
                 $options = 'class="' . $context['classes_for_thumbnail_images'] . '" ';
             }
             // build the complete HTML element
             $icon = '<img src="' . $icon . '" alt="" title="" ' . $options . ' />';
             // use default icon if nothing to display
         } else {
             $icon = MAP_IMG;
         }
         // use tipsy on hover
         $content = '<a href="' . $url . '" id="titles_' . $item['id'] . '">' . $icon . BR . $prefix . $title . '</a>';
         Page::insert_script('$(function() {' . "\n" . '	$("a#titles_' . $item['id'] . '").each(function() {' . "\n" . '		$(this).tipsy({fallback: \'<div style="text-align: left;">' . str_replace(array("'", "\n"), array('"', '<br />'), $hover) . '</div>\',' . "\n" . '		 html: true,' . "\n" . '		 gravity: $.fn.tipsy.autoWE,' . "\n" . '		 fade: true,' . "\n" . '		 offset: 8,' . "\n" . '		 opacity: 1.0});' . "\n" . '	});' . "\n" . '});' . "\n");
         // add a floating box
         $text .= Skin::build_box(NULL, $content, 'floating');
     }
     // clear flows
     $text .= '<br style="clear: left" />';
     // end of processing
     SQL::free($result);
     return $text;
 }
コード例 #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;
     }
     // we return some text
     $text = '';
     // maximum number of items
     if (isset($this->layout_variant) && $this->layout_variant > 3) {
         $maximum_items = $this->layout_variant;
     } elseif (defined('YAHOO_LIST_SIZE')) {
         $maximum_items = YAHOO_LIST_SIZE;
     } else {
         $maximum_items = 7;
     }
     // stack of items
     $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';
     $family = '';
     while ($item = SQL::fetch($result)) {
         // change the family
         if ($item['family'] != $family) {
             // flush current stack, if any
             if (count($items)) {
                 $text .= Skin::build_list($items, '2-columns');
             }
             $items = array();
             // show the family
             $family = $item['family'];
             $text .= '<h2><span>' . $family . '&nbsp;</span></h2>' . "\n";
         }
         // the url to view this item
         $url = Sections::get_permalink($item);
         // initialize variables
         $prefix = $label = $suffix = $icon = '';
         // signal restricted and private sections
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // 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;
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix .= NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= UPDATED_FLAG;
         }
         // details and content
         $details = array();
         $content = array();
         // count related sub-elements
         $related_count = 0;
         // info on related articles
         if ($count = Articles::count_for_anchor('section:' . $item['id'])) {
             if ($count > $maximum_items) {
                 $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
             } elseif (Surfer::is_empowered()) {
                 $details[] = sprintf(i18n::ns('%d page', '%d pages', $count), $count);
             }
             $related_count += $count;
             // get the overlay for content of this section, if any
             $content_overlay = NULL;
             if (isset($item['content_overlay'])) {
                 $content_overlay = Overlay::bind($item['content_overlay']);
             }
             // no room to list articles
             if (count($content) >= $maximum_items) {
             } elseif (is_object($content_overlay) && is_callable(array($content_overlay, 'render_list_for_anchor'))) {
                 if ($related = $content_overlay->render_list_for_anchor('section:' . $item['id'], $maximum_items - count($content))) {
                     foreach ($related as $sub_url => $label) {
                         $sub_prefix = $sub_suffix = $sub_hover = '';
                         if (is_array($label)) {
                             $sub_prefix = $label[0];
                             $sub_suffix = $label[2];
                             if (@$label[5]) {
                                 $sub_hover = $label[5];
                             }
                             $label = $label[1];
                         }
                         $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'basic', $sub_hover) . $sub_suffix;
                     }
                 }
                 // regular rendering of related articles
             } else {
                 if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) {
                     $order = $matches[1];
                 } else {
                     $order = 'edition';
                 }
                 if ($related =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, $maximum_items - count($content), 'compact')) {
                     foreach ($related as $sub_url => $label) {
                         $sub_prefix = $sub_suffix = $sub_hover = '';
                         if (is_array($label)) {
                             $sub_prefix = $label[0];
                             $sub_suffix = $label[2];
                             if (@$label[5]) {
                                 $sub_hover = $label[5];
                             }
                             $label = $label[1];
                         }
                         $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'article', $sub_hover) . $sub_suffix;
                     }
                 }
             }
         }
         // info on related files
         if ($count = Files::count_for_anchor('section:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count);
             $related_count += $count;
             // add related files if necessary
             if (count($content) < $maximum_items && ($related = Files::list_by_date_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), 'compact'))) {
                 foreach ($related as $sub_url => $label) {
                     $sub_prefix = $sub_suffix = $sub_hover = '';
                     if (is_array($label)) {
                         $sub_prefix = $label[0];
                         $sub_suffix = $label[2];
                         if (@$label[5]) {
                             $sub_hover = $label[5];
                         }
                         $label = $label[1];
                     }
                     $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'file', $sub_hover) . $sub_suffix;
                 }
             }
         }
         // info on related links
         if ($count = Links::count_for_anchor('section:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count);
             $related_count += $count;
             // add related links if necessary
             if (count($content) < $maximum_items && ($related = Links::list_by_date_for_anchor('section:' . $item['id'], 0, $maximum_items - count($content), 'compact'))) {
                 foreach ($related as $sub_url => $label) {
                     $sub_prefix = $sub_suffix = $sub_hover = '';
                     if (is_array($label)) {
                         $sub_prefix = $label[0];
                         $sub_suffix = $label[2];
                         if (@$label[5]) {
                             $sub_hover = $label[5];
                         }
                         $label = $label[1];
                     }
                     $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'link', $sub_hover) . $sub_suffix;
                 }
             }
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('section:' . $item['id'], TRUE)) {
             $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count);
             $related_count += $count;
         }
         // info on related sections
         if ($count = Sections::count_for_anchor('section:' . $item['id'])) {
             if ($count > $maximum_items) {
                 $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count);
             } elseif (Surfer::is_empowered()) {
                 $details[] = sprintf(i18n::ns('%d section', '%d sections', $count), $count);
             }
             $related_count += $count;
             // add sub-sections
             if ($related =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, $maximum_items, 'compact')) {
                 foreach ($related as $sub_url => $label) {
                     $sub_prefix = $sub_suffix = $sub_hover = '';
                     if (is_array($label)) {
                         $sub_prefix = $label[0];
                         $sub_suffix = $label[2];
                         if (@$label[5]) {
                             $sub_hover = $label[5];
                         }
                         $label = $label[1];
                     }
                     $content[] = $sub_prefix . Skin::build_link($sub_url, $label, 'section', $sub_hover) . $sub_suffix;
                 }
             }
         }
         // introduction
         if ($item['introduction']) {
             $suffix .= ' ' . Codes::beautify_introduction($item['introduction']);
         }
         // append details to the suffix
         if (count($details)) {
             $suffix .= ' <span class="details">(' . implode(', ', $details) . ')</span>';
         }
         // give me more
         if (count($content) && $related_count > $maximum_items) {
             $content[] = Skin::build_link(Sections::get_permalink($item), i18n::s('More') . MORE_IMG, 'more', i18n::s('View the section'));
         }
         // layout details
         if (count($content)) {
             foreach ($content as $line) {
                 $suffix .= '<div>' . YAHOO_ITEM_PREFIX . $line . YAHOO_ITEM_SUFFIX . '</div>';
             }
         }
         // use the title to label the link
         $label = Skin::strip($item['title'], 50);
         // put the actual icon in the left column
         if (isset($item['thumbnail_url'])) {
             $icon = $item['thumbnail_url'];
         }
         // some hovering title for this section
         $hover = i18n::s('View the section');
         // list all components for this item --use basic link style to avoid prefix or suffix images, if any
         $items[$url] = array($prefix, $label, $suffix, 'basic', $icon, $hover);
     }
     // flush the stack
     if (count($items)) {
         $text .= Skin::build_list($items, '2-columns');
     }
     // end of processing
     SQL::free($result);
     return $text;
 }
コード例 #19
0
ファイル: edit.php プロジェクト: rair/yacs
    // anonymous users are invited to log in or to register
    if (!Surfer::is_logged()) {
        if (isset($item['id'])) {
            $link = Tables::get_url($item['id'], 'edit');
        } elseif (isset($_REQUEST['anchor'])) {
            $link = 'tables/edit.php?anchor=' . urlencode($_REQUEST['anchor']);
        } else {
            $link = 'tables/edit.php';
        }
        Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode($link));
    }
    // permission denied to authenticated user
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // maybe posts are not allowed here
} elseif (!isset($item['id']) && $anchor->has_option('locked') && !Surfer::is_empowered()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('This page has been locked.'));
    // an error occured
} elseif (count($context['error'])) {
    $item = $_REQUEST;
    $with_form = TRUE;
    // process uploaded data
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    // the follow-up page
    $next = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url();
    // display the form on error
    if (!($_REQUEST['id'] = Tables::post($_REQUEST))) {
        $item = $_REQUEST;
        $with_form = TRUE;
        // post-processing
コード例 #20
0
ファイル: layout_tables.php プロジェクト: rair/yacs
 /**
  * list tables
  *
  * Recognize following variants:
  * - 'no_anchor' to list items attached to one particular anchor
  *
  * @param resource the SQL result
  * @return array one item per image
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return an array of ($url => $attributes)
     $items = array();
     // empty list
     if (!SQL::count($result)) {
         return $items;
     }
     if (!isset($this->layout_variant)) {
         $this->layout_variant = 'no_anchor';
     }
     // process all items in the list
     while ($item = SQL::fetch($result)) {
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // initialize variables
         $prefix = $suffix = $icon = '';
         // the url to view this item
         $url = Tables::get_url($item['id']);
         // codes to embed this image
         if ($anchor && $this->focus == $anchor->get_reference()) {
             // codes
             $codes = array();
             $codes[] = '[table=' . $item['id'] . ']';
             $codes[] = '[table.filter=' . $item['id'] . ']';
             $codes[] = '[table.chart=' . $item['id'] . ']';
             $codes[] = '[table.bars=' . $item['id'] . ']';
             $codes[] = '[table.line=' . $item['id'] . ']';
             // integrate codes
             if (!isset($_SESSION['surfer_editor']) || $_SESSION['surfer_editor'] == 'yacs') {
                 foreach ($codes as $code) {
                     $suffix .= '<a onclick="edit_insert(\'\', \' ' . $code . '\');return false;" title="insert" tabindex="2000">' . $code . '</a> ';
                 }
             } else {
                 $suffix .= join(' ', $codes);
             }
             $suffix .= BR;
         }
         // we are listing tables attached to an chor
         if ($anchor && $this->focus == $anchor->get_reference()) {
             $label = '_';
             // the title
             if ($item['title']) {
                 $suffix .= Skin::strip($item['title'], 10);
             }
             // an index of tables
         } else {
             // the title
             if ($item['title']) {
                 $label = Skin::strip($item['title'], 10);
             }
         }
         // flag tables created or updated very recently
         if (isset($item['create_date']) && $item['create_date'] >= $context['fresh']) {
             $suffix .= NEW_FLAG;
         } elseif (isset($item['edit_date']) && $item['edit_date'] >= $context['fresh']) {
             $suffix .= UPDATED_FLAG;
         }
         // details
         $details = array();
         if (Surfer::is_associate() && $item['nick_name']) {
             $details[] = '"' . $item['nick_name'] . '"';
         }
         if (Surfer::is_logged() && $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']));
         }
         // the menu bar for associates and poster
         if (Surfer::is_empowered()) {
             $details[] = Skin::build_link(Tables::get_url($item['id'], 'view'), i18n::s('details'), 'basic');
             $details[] = Skin::build_link(Tables::get_url($item['id'], 'edit'), i18n::s('edit'), 'basic');
             $details[] = Skin::build_link(Tables::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic');
         }
         // append details
         if (count($details)) {
             $suffix .= BR . Skin::finalize_list($details, 'menu');
         }
         // list all components for this item
         $items[$url] = array($prefix, $label, $suffix, 'table', $icon);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
コード例 #21
0
 /**
  * list files
  *
  * @param resource the SQL result
  * @return array of resulting items, or NULL
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // we return an array of ($url => $attributes)
     $items = array();
     // empty list
     if (!SQL::count($result)) {
         return $items;
     }
     // sanity check
     if (!isset($this->layout_variant)) {
         $this->layout_variant = '';
     }
     // process all items in the list
     while ($item = SQL::fetch($result)) {
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // initialize variables
         $prefix = $suffix = $icon = '';
         // more details
         $url = Files::get_permalink($item);
         // codes
         $codes = array();
         // files that can be embedded
         if (preg_match('/\\.(3gp|flv|gan|m4v|mm|mov|mp4|swf)$/i', $item['file_name'])) {
             $codes[] = '[embed=' . $item['id'] . ']';
         }
         // link for direct download
         $codes[] = '[file=' . $item['id'] . ']';
         $codes[] = '[download=' . $item['id'] . ']';
         // integrate codes
         if (!isset($_SESSION['surfer_editor']) || $_SESSION['surfer_editor'] == 'yacs') {
             foreach ($codes as $code) {
                 $suffix .= '<a onclick="edit_insert(\'\', \' ' . $code . '\');return false;" title="insert" tabindex="2000">' . $code . '</a> ';
             }
         } else {
             $suffix .= join(' ', $codes);
         }
         $suffix .= BR . '<span class="details">';
         // signal restricted and private files
         if ($item['active'] == 'N') {
             $suffix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $suffix .= RESTRICTED_FLAG;
         }
         // file title or file name
         $label = Codes::beautify_title($item['title']);
         if (!$label) {
             $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name']));
         }
         $suffix .= $label;
         // flag files uploaded recently
         if ($item['create_date'] >= $context['fresh']) {
             $suffix .= NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= UPDATED_FLAG;
         }
         $suffix .= '</span>';
         // details
         $details = array();
         if (Surfer::is_logged() && $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']));
         }
         // the menu bar for associates and poster
         if (Surfer::is_empowered()) {
             $details[] = Skin::build_link($url, i18n::s('details'), 'basic');
             $details[] = Skin::build_link(Files::get_url($item['id'], 'edit'), i18n::s('edit'), 'basic');
             $details[] = Skin::build_link(Files::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic');
         }
         // append details
         if (count($details)) {
             $suffix .= BR . Skin::finalize_list($details, 'menu');
         }
         // explicit icon
         if ($item['thumbnail_url']) {
             $icon = $item['thumbnail_url'];
         } else {
             $icon = $context['url_to_root'] . Files::get_icon_url($item['file_name']);
         }
         // list all components for this item
         $items[$url] = array($prefix, '_', $suffix, 'file', $icon);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
コード例 #22
0
ファイル: articles.php プロジェクト: rair/yacs
 /**
  * get some statistics for one anchor
  *
  * Only articles matching following criteria are returned:
  * - article is visible (active='Y')
  * - article is restricted (active='R'), but the surfer is an authenticated member,
  * or YACS is allowed to show restricted teasers
  * - article is protected (active='N'), but surfer is an associate, and we are not feeding someone
  * - surfer is anonymous or the variant is 'boxes', and article has been officially published
  * - logged surfers are restricted to their own articles, plus published articles
  * - an expiry date has not been defined, or is not yet passed
  *
  * @param the selected anchor (e.g., 'section:12')
  * @param boolean FALSE to include sticky pages, TRUE otherwise
  * @return the resulting ($count, $min_date, $max_date) array
  *
  * @see sections/view.php
  */
 public static function stat_for_anchor($anchor, $without_sticky = FALSE)
 {
     global $context;
     // sanity check
     if (!$anchor) {
         return NULL;
     }
     // restrict the query to addressable content
     $where = Articles::get_sql_where();
     // avoid sticky articles
     if ($without_sticky) {
         $where .= " AND (articles.rank >= 10000)";
     }
     // anonymous surfers and subscribers will see only published articles
     if (!Surfer::is_member()) {
         $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
         // logged surfers that are non-associates are restricted to their own articles, plus published articles
     } elseif (!Surfer::is_empowered()) {
         $where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))";
     }
     // only consider live articles
     $where .= " AND ((articles.expiry_date is NULL) " . "OR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . $context['now'] . "'))";
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . " FROM " . SQL::table_name('articles') . " AS articles" . " WHERE (articles.anchor LIKE '" . SQL::escape($anchor) . "') AND (" . $where . ")";
     $output = SQL::query_first($query);
     return $output;
 }
コード例 #23
0
ファイル: sections.php プロジェクト: rair/yacs
 /**
  * get some statistics for some sections
  *
  * Only sections matching following criteria are returned:
  * - section is visible (active='Y')
  * - section is restricted (active='R'), but surfer is a logged user
  * - section is hidden (active='N'), but surfer is an associate
  *
  * Non-activated and expired sections are counted as well.
  *
  * @param string the selected anchor (e.g., 'section:12')
  * @return array the resulting ($count, $min_date, $max_date) array
  *
  * @see sections/delete.php
  * @see sections/index.php
  * @see sections/layout_sections.php
  * @see sections/layout_sections_as_yahoo.php
  * @see sections/view.php
  */
 public static function stat_for_anchor($anchor = '')
 {
     global $context;
     // limit the query to one level
     if ($anchor) {
         $where = "(sections.anchor LIKE '" . SQL::escape($anchor) . "')";
     } else {
         $where = "(sections.anchor='' OR sections.anchor is NULL)";
     }
     // show everything if we are about to suppress a section
     if (!preg_match('/delete\\.php/', $context['script_url'])) {
         // display active and restricted items
         $where .= "AND (sections.active='Y'";
         // list restricted sections to authenticated surfers
         if (Surfer::is_logged()) {
             $where .= " OR sections.active='R'";
         }
         // list hidden sections to associates, editors and readers
         if (Surfer::is_empowered('S')) {
             $where .= " OR sections.active='N'";
         }
         $where .= ")";
         // hide sections removed from index maps
         $where .= " AND (sections.index_map = 'Y')";
         // non-associates will have only live sections
         if ($anchor && !Surfer::is_empowered()) {
             $where .= " AND ((sections.activation_date is NULL)" . "\tOR (sections.activation_date <= '" . $context['now'] . "'))" . " AND ((sections.expiry_date is NULL)" . "\tOR (sections.expiry_date <= '" . NULL_DATE . "') OR (sections.expiry_date > '" . $context['now'] . "'))";
         }
     }
     // list sections
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . " FROM " . SQL::table_name('sections') . " AS sections" . " WHERE " . $where;
     $output = SQL::query_first($query);
     return $output;
 }
コード例 #24
0
ファイル: skin_skeleton.php プロジェクト: rair/yacs
 /**
  * build a user profile
  *
  * @param array one user profile
  * @param string a profiling option, including 'prefix', 'suffix', and 'extra'
  * @param string more information
  * @return a string to be returned to the browser
  *
  * @see sections/section.php
  */
 public static function build_profile(&$user, $variant = 'prefix', $more = '')
 {
     global $context;
     // we return some text
     $text = '';
     // label
     $label = isset($user['full_name']) && $user['full_name'] ? $user['full_name'] : $user['nick_name'];
     // link to the user profile
     $url = Users::get_permalink($user);
     // configured styles
     $more_styles = '';
     if (isset($context['classes_for_avatar_images']) && $context['classes_for_avatar_images']) {
         $more_styles = ' ' . encode_field($context['classes_for_avatar_images']);
     }
     // depending of what we want to do
     switch ($variant) {
         // at the beginning of the page
         case 'prefix':
         default:
             // avatar
             $avatar = '';
             if (isset($user['avatar_url']) && $user['avatar_url']) {
                 $thumb = '';
                 if ($position = strrpos($user['avatar_url'], '/')) {
                     $thumb = substr($user['avatar_url'], 0, $position) . '/thumbs' . substr($user['avatar_url'], $position);
                 }
                 if (is_readable($context['path_to_root'] . str_replace($context['url_to_root'], '', $thumb))) {
                     $avatar =& Skin::build_link($url, '<img src="' . $thumb . '" alt="" title="avatar" class="avatar left_image" />', 'basic');
                 } else {
                     $avatar =& Skin::build_link($url, '<img src="' . $user['avatar_url'] . '" alt="" title="avatar" class="avatar left_image' . $more_styles . '" />', 'basic');
                 }
             }
             // several items
             $details = array();
             // date of post
             if ($more) {
                 $details[] = $more;
             }
             // from where
             if (isset($user['from_where']) && $user['from_where']) {
                 $details[] = sprintf(i18n::s('from %s'), Codes::beautify($user['from_where']));
             }
             // display details
             if (count($details)) {
                 $text .= '<span class="details">' . implode(', ', $details) . '</span>' . BR;
             }
             // use the introduction field, if any
             if (isset($user['introduction']) && $user['introduction']) {
                 $text .= Codes::beautify($user['introduction']);
             }
             // suffix after the full name
             if ($text) {
                 $text = ' -- ' . $text;
             }
             $text = '<div class="top">' . $avatar . Skin::build_link($url, $label, 'user') . $text . '</div><br style="clear: left;" />';
             break;
             // at the end of the page
         // at the end of the page
         case 'suffix':
             // avatar
             $avatar = '';
             if (isset($user['avatar_url']) && $user['avatar_url']) {
                 $thumb = '';
                 if ($position = strrpos($user['avatar_url'], '/')) {
                     $thumb = substr($user['avatar_url'], 0, $position) . '/thumbs' . substr($user['avatar_url'], $position);
                 }
                 if (is_readable($context['path_to_root'] . str_replace($context['url_to_root'], '', $thumb))) {
                     $avatar =& Skin::build_link($url, '<img src="' . $thumb . '" alt="" title="avatar" class="avatar left_image" />', 'basic');
                 } else {
                     $avatar =& Skin::build_link($url, '<img src="' . $user['avatar_url'] . '" alt="" title="avatar" class="avatar left_image' . $more_styles . '" />', 'basic');
                 }
             }
             // date of post
             if ($more) {
                 $text .= $more . ' ';
             }
             // from where
             if (isset($user['from_where']) && $user['from_where']) {
                 $text .= sprintf(i18n::s('from %s'), Codes::beautify($user['from_where']));
             }
             // display details
             if ($text) {
                 $text = '<span class="details">' . $text . '</span>' . BR;
             }
             // use the introduction field, if any
             if (isset($user['introduction']) && $user['introduction']) {
                 $text .= Codes::beautify($user['introduction']);
             }
             // suffix after the full name
             if ($text) {
                 $text = ' -- ' . $text;
             }
             $text = '<address>' . $avatar . Skin::build_link($url, $label, 'user') . $text . '</address><br style="clear: left;" />';
             break;
             // in a sidebox
         // in a sidebox
         case 'extra':
             // details attributes
             $details = array();
             // avatar
             if (isset($user['avatar_url']) && $user['avatar_url']) {
                 $details[] =& Skin::build_link($url, '<img src="' . $user['avatar_url'] . '" alt="" title="avatar" class="avatar' . $more_styles . '" />', 'basic');
             } else {
                 if (Surfer::is_empowered()) {
                     Skin::define_img('IMAGES_ADD_IMG', 'images/add.gif');
                     $details[] =& Skin::build_link(Users::get_url($user['id'], 'select_avatar'), IMAGES_ADD_IMG . i18n::s('Add picture'), 'basic');
                 }
             }
             // date of post
             if ($more) {
                 $details[] = $more;
             }
             // from where
             if (isset($user['from_where']) && $user['from_where']) {
                 $details[] = sprintf(i18n::s('from %s'), Codes::beautify($user['from_where']));
             }
             // details first
             if (count($details)) {
                 $text .= '<p class="details">' . join(BR, $details) . '</p>';
             }
             // do not use description because of codes such as location, etc
             if (isset($user['introduction']) && $user['introduction']) {
                 $text .= Codes::beautify($user['introduction']);
             }
             // show contact information
             if (Surfer::may_contact()) {
                 $contacts = Users::build_presence($user);
                 if ($contacts) {
                     $text .= BR . $contacts;
                 }
             }
             // everything in an extra box
             $text = Skin::build_box($label, $text, 'profile');
             break;
     }
     // return by reference
     return $text;
 }
コード例 #25
0
ファイル: view_as_tabs.php プロジェクト: rair/yacs
             $home = Sections::get_permalink($item);
             $prefix = Sections::get_url($item['id'], 'navigate', 'sections');
             $box['bottom_bar'] += Skin::navigate($home, $prefix, $count, $items_per_page, $zoom_index);
         }
         // bottom menu
         if ($box['bottom_bar']) {
             $box['text'] .= Skin::build_list($box['bottom_bar'], 'menu_bar');
         }
         // there is some box content
         if ($box['text']) {
             $text .= $box['text'];
         }
     }
 }
 // associates may list special sections as well
 if (!$zoom_type && Surfer::is_empowered()) {
     // inactive sections, if any
     $items = Sections::list_inactive_by_title_for_anchor('section:' . $item['id'], 0, 50, 'compact');
     // we have an array to format
     if (count($items)) {
         $items =& Skin::build_list($items, 'compact');
     }
     // displayed as another box
     if ($items) {
         $context['page_menu'] += array('_other_sections' => Skin::build_sliding_box(i18n::s('Other sections'), $items, NULL, TRUE, TRUE));
     }
 }
 // trailer information
 //
 // add trailer information from the overlay, if any
 if (is_object($overlay)) {
コード例 #26
0
ファイル: move.php プロジェクト: rair/yacs
    // a destination anchor is mandatory
} elseif (!is_object($destination)) {
    Safe::header('Status: 404 Not Found', TRUE, 404);
    Logger::error(i18n::s('No anchor has been found.'));
    // permission denied
} elseif (!Articles::is_owned($item, $anchor)) {
    // anonymous users are invited to log in or to register
    if (!Surfer::is_logged()) {
        $link = Articles::get_url($item['id'], 'move', $destination->get_reference());
        Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode($link));
    }
    // permission denied to authenticated user
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // maybe this article cannot be modified anymore
} elseif (isset($item['locked']) && $item['locked'] == 'Y' && !Surfer::is_empowered()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('This page has been locked.'));
    // do the job
} else {
    // attributes to change
    $fields = array();
    $fields['id'] = $item['id'];
    $fields['anchor'] = $destination->get_reference();
    // do the change
    if (Articles::put_attributes($fields)) {
        // only when comments are allowed
        if (!Articles::has_option('no_comments', $anchor, $item)) {
            // add a comment to make the move explicit
            include_once $context['path_to_root'] . 'comments/comments.php';
            $fields = array();
コード例 #27
0
ファイル: edit_as_thread.php プロジェクト: rair/yacs
 }
 $input .= '/> ' . i18n::s('Contributions are accepted') . ' ' . BR . '<input type="radio" name="locked" value="Y"';
 if (isset($item['locked']) && $item['locked'] == 'Y') {
     $input .= ' checked="checked"';
 }
 if (isset($item['active']) && $item['active'] == 'N') {
     $input .= '/> ' . i18n::s('Only owners and associates can add content');
 } else {
     $input .= '/> ' . i18n::s('Only assigned persons, owners and associates can add content');
 }
 $fields[] = array($label, $input);
 // append fields
 $text .= Skin::build_form($fields);
 $fields = array();
 // the thumbnail url may be set after the page has been created
 if (isset($item['id']) && Surfer::is_empowered() && Surfer::is_member()) {
     $label = i18n::s('Thumbnail');
     $input = '';
     $hint = '';
     // show the current thumbnail
     if (isset($item['thumbnail_url']) && $item['thumbnail_url']) {
         $input .= '<img src="' . $item['thumbnail_url'] . '" alt="" />' . BR;
         $command = i18n::s('Change');
     } else {
         $hint .= i18n::s('Upload a small image to illustrate this page when it is listed into parent page.');
         $command = i18n::s('Add an image');
     }
     $input .= '<input type="text" name="thumbnail_url" size="55" value="' . encode_field(isset($item['thumbnail_url']) ? $item['thumbnail_url'] : '') . '" maxlength="255" />';
     if (Surfer::may_upload()) {
         $input .= ' <span class="details">' . Skin::build_link('images/edit.php?anchor=' . urlencode('article:' . $item['id']) . '&amp;action=thumbnail', $command, 'button') . '</span>';
     }
コード例 #28
0
ファイル: files.php プロジェクト: rair/yacs
 /**
  * restrict the scope of SQL query
  *
  * @return string to be inserted into a SQL statement
  */
 private static function get_sql_where()
 {
     // display active items
     $where = "files.active='Y'";
     // add restricted items to members and for trusted hosts, or if teasers are allowed
     if (Surfer::is_logged() || Surfer::is_trusted() || Surfer::is_teased()) {
         $where .= " OR files.active='R'";
     }
     // include hidden items for associates and for trusted hosts, or if teasers are allowed
     if (Surfer::is_empowered('S') || Surfer::is_trusted() || Surfer::is_teased()) {
         $where .= " OR files.active='N'";
     }
     // end of active filter
     $where = '(' . $where . ')';
     // job done
     return $where;
 }
コード例 #29
0
ファイル: layout_sections_as_jive.php プロジェクト: rair/yacs
 /**
  * list sections as topics in a forum
  *
  * @param resource the SQL result
  * @return string the rendered text
  **/
 function layout($result)
 {
     global $context;
     // empty list
     if (!SQL::count($result)) {
         $output = array();
         return $output;
     }
     // layout in a table
     $text = Skin::table_prefix('wide');
     // 'even' is used for title rows, 'odd' for detail rows
     $class_title = 'odd';
     $class_detail = 'even';
     // build a list of sections
     $family = '';
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     while ($item = SQL::fetch($result)) {
         // change the family
         if ($item['family'] != $family) {
             $family = $item['family'];
             // show the family
             $text .= Skin::table_suffix() . '<h2><span>' . $family . '&nbsp;</span></h2>' . "\n" . Skin::table_prefix('wide');
         }
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'section:' . $item['id']);
         // get the main anchor
         $anchor = Anchors::get($item['anchor']);
         // reset everything
         $prefix = $label = $suffix = $icon = '';
         // signal restricted and private sections
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // indicate the id in the hovering popup
         $hover = i18n::s('View the section');
         if (Surfer::is_member()) {
             $hover .= ' [section=' . $item['id'] . ']';
         }
         // 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']);
         }
         // use the title as a link to the page
         $title =& Skin::build_link($url, $title, 'basic', $hover);
         // flag sections updated recently
         if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) {
             $suffix = EXPIRED_FLAG . ' ';
         } elseif ($item['create_date'] >= $context['fresh']) {
             $suffix = NEW_FLAG . ' ';
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix = UPDATED_FLAG . ' ';
         }
         // this is another row of the output
         $text .= '<tr class="' . $class_title . '"><th>' . $prefix . $title . $suffix . '</th><th>' . i18n::s('Poster') . '</th><th>' . i18n::s('Messages') . '</th><th>' . i18n::s('Last active') . '</th></tr>' . "\n";
         $count = 1;
         // get last posts for this board --avoid sticky pages
         if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) {
             $order = $matches[1];
         } else {
             $order = 'edition';
         }
         if ($articles =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, 5, 'raw', TRUE)) {
             foreach ($articles as $id => $article) {
                 // get the related overlay, if any
                 $article_overlay = Overlay::load($article, 'article:' . $id);
                 // flag articles updated recently
                 if ($article['expiry_date'] > NULL_DATE && $article['expiry_date'] <= $context['now']) {
                     $flag = EXPIRED_FLAG . ' ';
                 } elseif ($article['create_date'] >= $context['fresh']) {
                     $flag = NEW_FLAG . ' ';
                 } elseif ($article['edit_date'] >= $context['fresh']) {
                     $flag = UPDATED_FLAG . ' ';
                 } else {
                     $flag = '';
                 }
                 // use the title to label the link
                 if (is_object($article_overlay)) {
                     $title = Codes::beautify_title($article_overlay->get_text('title', $article));
                 } else {
                     $title = Codes::beautify_title($article['title']);
                 }
                 // title
                 $title = Skin::build_link(Articles::get_permalink($article), $title, 'article');
                 // poster
                 $poster = Users::get_link($article['create_name'], $article['create_address'], $article['create_id']);
                 // comments
                 $comments = Comments::count_for_anchor('article:' . $article['id']);
                 // last editor
                 $action = '';
                 if ($article['edit_date']) {
                     // label the action
                     if (isset($article['edit_action'])) {
                         $action = Anchors::get_action_label($article['edit_action']);
                     } else {
                         $action = i18n::s('edited');
                     }
                     $action = '<span class="details">' . $action . ' ' . Skin::build_date($article['edit_date']) . '</span>';
                 }
                 // this is another row of the output
                 $text .= '<tr class="' . $class_detail . '"><td>' . $title . $flag . '</td><td>' . $poster . '</td><td style="text-align: center;">' . $comments . '</td><td>' . $action . '</td></tr>' . "\n";
             }
         }
         // more details
         $details = array();
         // board introduction
         if ($item['introduction']) {
             $details[] = Codes::beautify_introduction($item['introduction']);
         }
         // indicate the total number of threads here
         if (($count = Articles::count_for_anchor('section:' . $item['id'])) && $count >= 5) {
             $details[] = sprintf(i18n::s('%d threads'), $count) . '&nbsp;&raquo;';
         }
         // link to the section index page
         if ($details) {
             $details = Skin::build_link(Sections::get_permalink($item), join(' -&nbsp;', $details), 'basic');
         } else {
             $details = '';
         }
         // add a command for new post
         $poster = '';
         if (Surfer::is_empowered()) {
             $poster = Skin::build_link('articles/edit.php?anchor=' . urlencode('section:' . $item['id']), i18n::s('Add a page') . '&nbsp;&raquo;', 'basic');
         }
         // insert details in a separate row
         if ($details || $poster) {
             $text .= '<tr class="' . $class_detail . '"><td colspan="3">' . $details . '</td><td>' . $poster . '</td></tr>' . "\n";
         }
         // more details
         $more = array();
         // board moderators
         if ($moderators = Sections::list_editors_by_name($item, 0, 7, 'comma5')) {
             $more[] = sprintf(i18n::ns('Moderator: %s', 'Moderators: %s', count($moderators)), $moderators);
         }
         // children boards
         if ($children =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, COMPACT_LIST_SIZE, 'compact')) {
             $more[] = sprintf(i18n::ns('Child board: %s', 'Child boards: %s', count($children)), Skin::build_list($children, 'comma'));
         }
         // as a compact list
         if (count($more)) {
             $content = '<ul class="compact">';
             foreach ($more as $list_item) {
                 $content .= '<li>' . $list_item . '</li>' . "\n";
             }
             $content .= '</ul>' . "\n";
             // insert details in a separate row
             $text .= '<tr class="' . $class_detail . '"><td colspan="4">' . $content . '</td></tr>' . "\n";
         }
     }
     // end of processing
     SQL::free($result);
     $text .= Skin::table_suffix();
     return $text;
 }
コード例 #30
0
ファイル: element.php プロジェクト: rair/yacs
} elseif (isset($context['arguments'][1])) {
    $action = $context['arguments'][1];
}
$action = strip_tags($action);
// maybe this anonymous surfer is allowed to handle this item
if (isset($item['handle']) && Surfer::may_handle($item['handle'])) {
    Surfer::empower();
} elseif (isset($item['id']) && Articles::is_assigned($item['id']) || is_object($anchor) && $anchor->is_assigned()) {
    Surfer::empower();
} elseif (Articles::has_option('anonymous_edit', $anchor, $item)) {
    Surfer::empower();
} elseif (Surfer::is_member() && Articles::has_option('members_edit', $anchor, $item)) {
    Surfer::empower();
}
// associates and editors can do what they want
if (Surfer::is_empowered()) {
    $permitted = TRUE;
} else {
    $permitted = FALSE;
}
// no not kill script validation
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') {
    return;
}
// not found -- help web crawlers
if (!isset($item['id'])) {
    Safe::header('Status: 404 Not Found', TRUE, 404);
    die(i18n::s('No item has the provided id.'));
    // permission denied
} elseif (!$permitted) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);