/** * 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; }
/** * list articles * * @param resource the SQL result * @return string * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // sanity check if (!isset($this->focus)) { $this->focus = NULL; } // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; $odd = TRUE; while ($item = SQL::fetch($result)) { // get the related overlay $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); // build a title if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } // signal articles to be published 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; } // some details $details = array(); // info on related files --optional if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); } // info on related comments --mandatory if ($count = Comments::count_for_anchor('article:' . $item['id'], FALSE)) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); } // info on related links --optional if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); } // details if (count($details)) { $suffix .= ' <span class="details">(' . ucfirst(implode(', ', $details)) . ')</span>'; } // flag popular pages if ($item['hits'] > 300) { $suffix .= POPULAR_FLAG; } // last contribution if ($item['edit_action']) { $action = Anchors::get_action_label($item['edit_action']) . ' '; } else { $action = i18n::s('edited'); } if ($item['edit_name']) { $suffix .= '<br /><span class="details">' . sprintf(i18n::s('%s by %s %s'), $action, Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])) . '</span>'; } else { $suffix .= '<br /><span class="details">' . $action . ' ' . Skin::build_date($item['edit_date']) . '</span>'; } // flag articles updated recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item, $this->focus); } // the hovering title if ($item['introduction'] && $context['skins_with_details'] == 'Y') { $hover = strip_tags(Codes::beautify_introduction($item['introduction'])); } else { $hover = i18n::s('View the page'); } // help members to reference this page if (Surfer::is_member()) { $hover .= ' [article=' . $item['id'] . ']'; } // add an image if available if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } elseif (is_callable(array($anchor, 'get_bullet_url'))) { $icon = $anchor->get_bullet_url(); } // format the image if ($icon) { $icon = Skin::build_link($url, '<img src="' . $icon . '" />', 'basic', $hover); } // list all components for this item if ($odd = !$odd) { $class = ' class="odd"'; } else { $class = ' class="even"'; } // use a table to layout the image properly if ($icon) { $text .= '<div' . $class . '><table class="decorated"><tr><td class="image" style="text-align: center">' . $icon . '</td><td class="content">' . $prefix . Skin::build_link($url, Skin::strip($title, 30), 'basic', $hover) . $suffix . '</td></tr></table></div>'; } else { $text .= '<div' . $class . '>' . $prefix . Skin::build_link($url, Skin::strip($title, 30), 'basic', $hover) . $suffix . '</div>'; } } // end of processing SQL::free($result); return $text; }
$id = $context['arguments'][0]; } $id = strip_tags($id); // get the item from the database $item = Servers::get($id); // get the related anchor, if any $anchor = NULL; if (isset($item['anchor']) && $item['anchor']) { $anchor = Anchors::get($item['anchor']); } // associates can do what they want if (Surfer::is_associate()) { $permitted = TRUE; } elseif (is_object($anchor) && !$anchor->is_viewable()) { $permitted = FALSE; } elseif ($item['active'] == 'R' && Surfer::is_member()) { $permitted = TRUE; } elseif ($item['active'] == 'Y') { $permitted = TRUE; } else { $permitted = FALSE; } // load the skin load_skin('servers'); // current item if (isset($item['id'])) { $context['current_item'] = 'server:' . $item['id']; } // the path to this page $context['path_bar'] = array('servers/' => i18n::s('Servers')); // the title of the page
/** * 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 (!($delta = SQL::count($result))) { return $text; } // process all items in the list $count = 0; $items = array(); while ($item = SQL::fetch($result)) { // the url to view this item $url = Sections::get_permalink($item); // initialize variables $prefix = $label = $suffix = ''; // flag sections that are draft or dead if ($item['activation_date'] >= $context['now']) { $prefix .= DRAFT_FLAG; } elseif ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } // signal restricted and private sections if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // flag items updated recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // // start the label with family, if any // if($item['family']) // $label = ucfirst(Skin::strip($item['family'], 30)).' - '; // use the title to label the link $label .= ucfirst(Skin::strip($item['title'], 30)); // the hovering title if ($item['introduction'] && $context['skins_with_details'] == 'Y') { $hover = strip_tags(Codes::beautify_introduction($item['introduction'])); } else { $hover = i18n::s('View the section'); } // help members to reference this page if (Surfer::is_member()) { $hover .= ' [section=' . $item['id'] . ']'; } // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'basic', NULL, $hover); // limit to one page of results if (++$count >= COMPACT_LIST_SIZE - 1) { break; } } // end of processing SQL::free($result); // turn this to some text $text .= Skin::build_list($items, 'comma'); // some indications on the number of connections if (($delta -= $count) > 0) { $text .= ', ...'; } return $text; }
/** * 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 . ' </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) . ' »'; } // link to the section index page if ($details) { $details = Skin::build_link(Sections::get_permalink($item), join(' - ', $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') . ' »', '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; }
/** * get some statistics * * @return the resulting ($count, $min_date, $max_date) array */ public static function stat() { global $context; // select among active and restricted items $where = "servers.active='Y'"; if (Surfer::is_member()) { $where .= " OR servers.active='R'"; } if (Surfer::is_associate()) { $where .= " OR servers.active='N'"; } // 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('servers') . ' AS servers' . ' WHERE (' . $where . ')'; $output = SQL::query_first($query); return $output; }
// the rank if ($cur_article->is_owned() || Surfer::is_associate()) { // the default value if (!isset($item['rank'])) { $item['rank'] = 10000; } $label = i18n::s('Rank'); $input = '<input type="text" name="rank" id="rank" size="10" value="' . encode_field($item['rank']) . '" maxlength="255" />'; $hint = sprintf(i18n::s('For %s pages; regular pages are ranked at %s.'), '<a href="#" onclick="$(\'#rank\').value=10; return false;">' . i18n::s('sticky') . '</a>', '<a href="#" onclick="$(\'#rank\').value=10000; return false;">' . i18n::s('10000') . '</a>'); $fields[] = array($label, $input, $hint); } // the publication date $label = i18n::s('Publication date'); if (isset($item['publish_date']) && $item['publish_date'] > NULL_DATE) { $input = Surfer::from_GMT($item['publish_date']); } elseif (isset($item['id']) && (Surfer::is_associate() || Surfer::is_member() && is_object($anchor) && $anchor->is_assigned())) { Skin::define_img('ARTICLES_PUBLISH_IMG', 'articles/publish.gif'); $input = Skin::build_link(Articles::get_url($item['id'], 'publish'), ARTICLES_PUBLISH_IMG . i18n::s('Publish'), 'basic'); } else { Skin::define_img('ARTICLES_UNPUBLISH_IMG', 'articles/unpublish.gif'); $input = ARTICLES_UNPUBLISH_IMG . i18n::s('not published'); } $fields[] = array($label, $input); // the expiry date $label = i18n::s('Expiry date'); if (isset($item['expiry_date']) && $item['expiry_date'] > NULL_DATE) { $input = Surfer::from_GMT($item['expiry_date']); } else { $input = i18n::s('never'); } $fields[] = array($label, $input);
if ($text =& Articles::list_by('publication', $offset, $items_per_page)) { // we have an array to format if (is_array($text)) { $text =& Skin::build_list($text, 'decorated'); } } // cache this to speed subsequent queries Cache::put($cache_id, $text, 'articles'); } $context['text'] .= $text; } // // extra content // // add a page if (Surfer::is_associate() || Surfer::is_member() && (!isset($context['users_without_submission']) || $context['users_without_submission'] != 'Y')) { $context['page_tools'][] = Skin::build_link('articles/edit.php', i18n::s('Add a page'), 'basic'); } // other commands if (Surfer::is_associate()) { $context['page_tools'][] = Skin::build_link('articles/review.php', i18n::s('Review queue'), 'basic'); $context['page_tools'][] = Skin::build_link('help/populate.php', i18n::s('Content Assistant')); $context['page_tools'][] = Skin::build_link('articles/import.php', i18n::s('Import articles'), 'basic'); $context['page_tools'][] = Skin::build_link('articles/check.php', i18n::s('Maintenance'), 'basic'); } // side bar with a rss feed, if this server is well populated if ($stats['count'] > $items_per_page) { $context['components']['channels'] = Skin::build_box(i18n::s('Information channels'), Skin::build_link(Feeds::get_url('rss'), i18n::s('Recent pages'), 'xml') . BR . Skin::build_link(Feeds::get_url('articles'), i18n::s('Full content'), 'xml'), 'channels'); } // page extra information $cache_id = 'articles/index.php#extra';
/** * 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 an array of ($url => $attributes) $items = array(); // process all items in the list while ($item = SQL::fetch($result)) { // get the related overlay, if any $overlay = Overlay::load($item, 'section:' . $item['id']); // the url to view this item $url = Sections::get_permalink($item); // initialize variables $prefix = $label = $suffix = ''; // flag sections that are draft or dead if ($item['activation_date'] >= $context['now']) { $prefix .= DRAFT_FLAG; } elseif ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } // signal restricted and private sections if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // flag items updated recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // // start the label with family, if any // if($item['family']) // $label = ucfirst(Skin::strip($item['family'], 30)).' - '; // use the title to label the link if (is_object($overlay)) { $label = ucfirst(Codes::beautify_title($overlay->get_text('title', $item))); } else { $label .= ucfirst(Skin::strip($item['index_title'], 30)); } // the hovering title if ($item['introduction'] && $context['skins_with_details'] == 'Y') { $hover = strip_tags(Codes::beautify_introduction($item['introduction'])); } else { $hover = i18n::s('View the section'); } // help members to reference this page if (Surfer::is_member()) { $hover .= ' [section=' . $item['id'] . ']'; } // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'basic', NULL, $hover); } // end of processing SQL::free($result); return $items; }
/** * can this surfer mail other users? * * @return TRUE if alowed, FALSE otherwise */ public static function may_mail() { global $context; // email has to be activated if (!isset($context['with_email'])) { return FALSE; } if ($context['with_email'] != 'Y') { return FALSE; } // only members can send e-mail if (!Surfer::is_member()) { return FALSE; } return Surfer::may_contact(); }
/** * list articles * * @param resource the SQL result * @return array * * @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; } // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; while ($item = SQL::fetch($result)) { // get the related overlay $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); // build a title if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = ''; // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } // signal articles to be published 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; } // count related comments, if any if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) { $suffix .= ' (' . $count . ')'; } // flag articles updated recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // the hovering title if ($item['introduction'] && $context['skins_with_details'] == 'Y') { $hover = strip_tags(Codes::beautify_introduction($item['introduction'])); } else { $hover = i18n::s('View the page'); } // help members to reference this page if (Surfer::is_member()) { $hover .= ' [article=' . $item['id'] . ']'; } // list all components for this item $items[$url] = array($prefix, Skin::strip($title, 30), $suffix, 'basic', NULL, $hover); } // end of processing SQL::free($result); return $items; }
/** * post a new file or an updated file * * This function populates the error context, where applicable. * * @param array an array of fields * @param string to support editors -- see files/edit.php * @return the id of the new file, or FALSE on error * * @see agents/messages.php * @see files/author.php * @see files/edit.php **/ public static function post(&$fields) { global $context; // no anchor reference if (!isset($fields['anchor']) || !$fields['anchor'] || !($anchor = Anchors::get($fields['anchor']))) { Logger::error(i18n::s('No anchor has been found.')); return FALSE; } // protect from hackers if (isset($fields['icon_url'])) { $fields['icon_url'] = encode_link($fields['icon_url']); } if (isset($fields['thumbnail_url'])) { $fields['thumbnail_url'] = encode_link($fields['thumbnail_url']); } // protect access from anonymous users if (!isset($fields['active_set'])) { $fields['active_set'] = 'Y'; } // cascade anchor access rights $fields['active'] = $anchor->ceil_rights($fields['active_set']); // set default values for this editor Surfer::check_default_editor($fields); // reinforce date formats if (!isset($fields['create_date']) || $fields['create_date'] <= NULL_DATE) { $fields['create_date'] = $fields['edit_date']; } // make the file name searchable on initial post if (!isset($fields['id']) && !isset($fields['keywords']) && isset($fields['file_name']) && $fields['file_name'] != 'none') { $fields['keywords'] = ' ' . str_replace(array('%20', '_', '.', '-'), ' ', $fields['file_name']); } // columns updated $query = array(); // update an existing record if (isset($fields['id'])) { // id cannot be empty if (!isset($fields['id']) || !is_numeric($fields['id'])) { Logger::error(i18n::s('No item has the provided id.')); return FALSE; } // an actual upload has taken place --change modification date and reset detach data if (isset($fields['file_name']) && $fields['file_name'] != 'none') { $query[] = "assign_address=''"; $query[] = "assign_date=''"; $query[] = "assign_id=''"; $query[] = "assign_name=''"; $query[] = "create_address='" . SQL::escape($fields['edit_address']) . "'"; $query[] = "create_date='" . SQL::escape($fields['edit_date']) . "'"; $query[] = "create_id=" . SQL::escape($fields['edit_id']); $query[] = "create_name='" . SQL::escape($fields['edit_name']) . "'"; $query[] = "edit_address='" . SQL::escape($fields['edit_address']) . "'"; $query[] = "edit_action='file:update'"; $query[] = "edit_date='" . SQL::escape($fields['edit_date']) . "'"; $query[] = "edit_id=" . SQL::escape($fields['edit_id']); $query[] = "edit_name='" . SQL::escape($fields['edit_name']) . "'"; $query[] = "file_name='" . SQL::escape($fields['file_name']) . "'"; $query[] = "file_size='" . SQL::escape($fields['file_size']) . "'"; } // fields that are visible only to people allowed to update a file if (Surfer::is_member()) { $query[] = "active='" . SQL::escape($fields['active']) . "'"; $query[] = "active_set='" . SQL::escape($fields['active_set']) . "'"; $query[] = "icon_url='" . SQL::escape(isset($fields['icon_url']) ? $fields['icon_url'] : '') . "'"; $query[] = "thumbnail_url='" . SQL::escape(isset($fields['thumbnail_url']) ? $fields['thumbnail_url'] : '') . "'"; } // regular fields $query[] = "alternate_href='" . SQL::escape(isset($fields['alternate_href']) ? $fields['alternate_href'] : '') . "'"; $query[] = "behaviors='" . SQL::escape(isset($fields['behaviors']) ? $fields['behaviors'] : '') . "'"; if (isset($fields['description'])) { $query[] = "description='" . SQL::escape($fields['description']) . "'"; } $query[] = "overlay='" . SQL::escape(isset($fields['overlay']) ? $fields['overlay'] : '') . "'"; $query[] = "overlay_id='" . SQL::escape(isset($fields['overlay_id']) ? $fields['overlay_id'] : '') . "'"; $query[] = "file_href='" . SQL::escape(isset($fields['file_href']) ? $fields['file_href'] : '') . "'"; $query[] = "keywords='" . SQL::escape(isset($fields['keywords']) ? $fields['keywords'] : '') . "'"; $query[] = "rank='" . SQL::escape(isset($fields['rank']) ? $fields['rank'] : '10000') . "'"; $query[] = "source='" . SQL::escape(isset($fields['source']) ? $fields['source'] : '') . "'"; $query[] = "title='" . SQL::escape(isset($fields['title']) ? $fields['title'] : '') . "'"; // build the full query $query = "UPDATE " . SQL::table_name('files') . " SET " . join(', ', $query) . " WHERE id = " . SQL::escape($fields['id']); // actual insert if (SQL::query($query) === FALSE) { return FALSE; } // insert a new record } elseif (isset($fields['file_name']) && $fields['file_name'] && isset($fields['file_size']) && $fields['file_size']) { $query[] = "active='" . SQL::escape($fields['active']) . "'"; $query[] = "active_set='" . SQL::escape($fields['active_set']) . "'"; $query[] = "alternate_href='" . SQL::escape(isset($fields['alternate_href']) ? $fields['alternate_href'] : '') . "'"; $query[] = "anchor='" . SQL::escape($fields['anchor']) . "'"; $query[] = "anchor_id=SUBSTRING_INDEX('" . SQL::escape($fields['anchor']) . "', ':', -1)"; $query[] = "anchor_type=SUBSTRING_INDEX('" . SQL::escape($fields['anchor']) . "', ':', 1)"; $query[] = "behaviors='" . SQL::escape(isset($fields['behaviors']) ? $fields['behaviors'] : '') . "'"; $query[] = "create_name='" . SQL::escape(isset($fields['create_name']) ? $fields['create_name'] : $fields['edit_name']) . "'"; $query[] = "create_id=" . SQL::escape(isset($fields['create_id']) ? $fields['create_id'] : $fields['edit_id']); $query[] = "create_address='" . SQL::escape(isset($fields['create_address']) ? $fields['create_address'] : $fields['edit_address']) . "'"; $query[] = "create_date='" . SQL::escape($fields['create_date']) . "'"; $query[] = "description='" . SQL::escape(isset($fields['description']) ? $fields['description'] : '') . "'"; $query[] = "edit_name='" . SQL::escape($fields['edit_name']) . "'"; $query[] = "edit_id=" . SQL::escape($fields['edit_id']); $query[] = "edit_address='" . SQL::escape($fields['edit_address']) . "'"; $query[] = "edit_action='file:create'"; $query[] = "edit_date='" . SQL::escape($fields['edit_date']) . "'"; $query[] = "file_name='" . SQL::escape($fields['file_name']) . "'"; $query[] = "file_href='" . SQL::escape(isset($fields['file_href']) ? $fields['file_href'] : '') . "'"; $query[] = "file_size='" . SQL::escape($fields['file_size']) . "'"; $query[] = "hits=0"; $query[] = "icon_url='" . SQL::escape(isset($fields['icon_url']) ? $fields['icon_url'] : '') . "'"; $query[] = "keywords='" . SQL::escape(isset($fields['keywords']) ? $fields['keywords'] : '') . "'"; $query[] = "overlay='" . SQL::escape(isset($fields['overlay']) ? $fields['overlay'] : '') . "'"; $query[] = "overlay_id='" . SQL::escape(isset($fields['overlay_id']) ? $fields['overlay_id'] : '') . "'"; $query[] = "rank='" . SQL::escape(isset($fields['rank']) ? $fields['rank'] : '10000') . "'"; $query[] = "source='" . SQL::escape(isset($fields['source']) ? $fields['source'] : '') . "'"; $query[] = "thumbnail_url='" . SQL::escape(isset($fields['thumbnail_url']) ? $fields['thumbnail_url'] : '') . "'"; $query[] = "title='" . SQL::escape(isset($fields['title']) ? $fields['title'] : '') . "'"; // build the full query $query = "INSERT INTO " . SQL::table_name('files') . " SET " . join(', ', $query); // actual insert if (SQL::query($query) === FALSE) { return FALSE; } // remember the id of the new item $fields['id'] = SQL::get_last_id($context['connection']); // nothing done } else { Logger::error(i18n::s('Nothing has been received. Ensure you are below size limits set for this server.')); return FALSE; } // clear the cache for files Files::clear($fields); // end of job return $fields['id']; }
$anchor = Anchors::get($item['anchor']); } // the anchor has to be viewable by this surfer if (!is_object($anchor) || $anchor->is_viewable()) { $permitted = TRUE; } else { $permitted = FALSE; } // nothing to change if (!isset($item['id'])) { $editable = FALSE; } elseif (Surfer::is_associate() || is_object($anchor) && $anchor->is_assigned()) { $editable = TRUE; } elseif (Surfer::is($item['edit_id'])) { $editable = TRUE; } elseif (Surfer::is_member() && (!isset($context['users_without_file_overloads']) || $context['users_without_file_overloads'] != 'Y')) { $editable = TRUE; } else { $editable = FALSE; } // load the skin, maybe with a variant load_skin('images', $anchor); // clear the tab we are in, if any if (is_object($anchor)) { $context['current_focus'] = $anchor->get_focus(); } // current item if (isset($item['id'])) { $context['current_item'] = 'image:' . $item['id']; } // the path to this page
/** * build linked tags * * @param string the full list of tags * @return string HTML tags to be put in the resulting page */ public static function &build_tags($tags) { global $context; $text = ''; // list existing tags $tags = explode(',', $tags); foreach ($tags as $tag) { if (!($tag = trim($tag))) { continue; } if ($category = Categories::get_by_keyword($tag)) { // get category visibility and check surfer rights $active = $category['active']; if ($active == 'Y' || $active == 'R' && Surfer::is_member() || $active == 'N' && Surfer::is_associate()) { // add background color to distinguish this category against others if (isset($category['background_color']) && $category['background_color']) { $tag = '<span style="background-color: ' . $category['background_color'] . '; padding: 0 3px 0 3px;">' . $tag . '</span>'; } $text .= Skin::build_link(Categories::get_permalink($category), $tag, 'basic') . ' '; } else { // do not show the tag for this category $text .= ''; } } else { $text .= $tag . ' '; } } $text = rtrim($text, ' '); // a link to add a tag return $text; }
} $id = strip_tags($id); // get the item from the database $item = Categories::get($id); // get the related anchor, if any $anchor = NULL; if (isset($item['anchor']) && $item['anchor']) { $anchor = Anchors::get($item['anchor']); } // get the related overlay, if any $overlay = NULL; if (isset($item['overlay'])) { $overlay = Overlay::load($item, 'category:' . $item['id']); } // associates and authenticated editors can do what they want if (Surfer::is_associate() || Surfer::is_member() && is_object($anchor) && $anchor->is_assigned()) { $permitted = TRUE; } else { $permitted = FALSE; } // load the skin load_skin('categories'); // the path to this page if (is_object($anchor) && $anchor->is_viewable()) { $context['path_bar'] = $anchor->get_path_bar(); } else { $context['path_bar'] = array('categories/' => i18n::s('Categories')); } if (isset($item['id'])) { $context['path_bar'] = array_merge($context['path_bar'], array(Categories::get_permalink($item) => $item['title'])); }
/** * list users * * @param resource the SQL result * @return array of resulting items (id => label), or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($url => $attributes) $items = array(); // empty list if (!($delta = SQL::count($result))) { return $items; } // build a list of users while ($item = SQL::fetch($result)) { // reset everything $prefix = $label = $suffix = $icon = ''; // signal restricted and private users 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 profile'); if (Surfer::is_member()) { $hover .= ' [user='******'id'] . ']'; } // the url to view this item $url = Users::get_permalink($item); // use full name, then nick name if (isset($item['full_name']) && $item['full_name']) { $title = $item['full_name']; } elseif (isset($item['nick_name'])) { $title = $item['nick_name']; } // show contact information if (Surfer::may_contact() && ($contacts = Users::build_presence($item))) { $suffix .= ' ' . $contacts; } // flag users updated recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG . ' '; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG . ' '; } // do not use description because of codes such as location, etc if (isset($item['introduction']) && $item['introduction']) { $suffix .= ' - ' . Codes::beautify($item['introduction']); } // display all tags // if($item['tags']) // $suffix .= ' <span class="details tags">'.Skin::build_tags($item['tags'], 'user:'******'id']).'</span>'; // the full label $label = $prefix . Skin::build_link($url, $title, 'basic', $hover) . $suffix; // use the avatar, if any $icon = ''; if (isset($item['avatar_url']) && $item['avatar_url']) { $icon = '<a href="' . $context['url_to_root'] . $url . '"><img src="' . $item['avatar_url'] . '" alt=" " title="' . encode_field($hover) . '" style="float: left; max-width: 25px; max-height: 25px; margin-right: 4px;" /></a>'; } // list all components for this item --use basic link style to avoid prefix or suffix images, if any $items[$item['id']] = $icon . $label; } // end of processing SQL::free($result); // job done return $items; }
/** * list articles as rows in a table * * @param resource the SQL result * @return string the rendered text **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // build a list of articles $rows = array(); include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // get the related overlay $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 everything $title = $abstract = $author = ''; // signal articles to be published if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $title .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $title .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $title .= RESTRICTED_FLAG; } // indicate the id in the hovering popup $hover = i18n::s('View the page'); if (Surfer::is_member()) { $hover .= ' [article=' . $item['id'] . ']'; } // use the title to label the link if (is_object($overlay)) { $label = Codes::beautify_title($overlay->get_text('title', $item)); } else { $label = Codes::beautify_title($item['title']); } // use the title as a link to the page $title .= Skin::build_link($url, $label, 'basic', $hover); // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $title .= ' ' . LOCKED_FLAG; } // flag articles updated recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $title .= ' ' . EXPIRED_FLAG; } elseif ($item['create_date'] >= $context['fresh']) { $title .= ' ' . NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $title .= ' ' . UPDATED_FLAG; } // the icon if ($item['thumbnail_url']) { $abstract .= '<a href="' . $context['url_to_root'] . $url . '"><img src="' . $item['thumbnail_url'] . '" class="right_image" alt="" /></a>'; } // the introductory text if (is_object($overlay)) { $abstract .= Codes::beautify_introduction($overlay->get_text('introduction', $item)); } elseif ($item['introduction']) { $abstract .= Codes::beautify_introduction($item['introduction']); } // insert overlay data, if any if (is_object($overlay)) { $abstract .= $overlay->get_text('list', $item); } // make some abstract out of main text if (!$item['introduction'] && $context['skins_with_details'] == 'Y') { $abstract .= Skin::cap(Codes::beautify($item['description'], $item['options']), 50); } // attachment details $details = array(); // info on related files if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) { Skin::define_img('FILES_LIST_IMG', 'files/list.gif'); $details[] = FILES_LIST_IMG . sprintf(i18n::ns('%d file', '%d files', $count), $count); } // info on related links if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { Skin::define_img('LINKS_LIST_IMG', 'links/list.gif'); $details[] = LINKS_LIST_IMG . sprintf(i18n::ns('%d link', '%d links', $count), $count); } // comments if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) { Skin::define_img('COMMENTS_LIST_IMG', 'comments/list.gif'); $details[] = Skin::build_link(Comments::get_url('article:' . $item['id'], 'list'), COMMENTS_LIST_IMG . sprintf(i18n::ns('%d comment', '%d comments', $count), $count)); } // describe attachments if (count($details)) { $abstract .= '<p style="margin: 3px 0;">' . join(', ', $details) . '</p>'; } // anchors $anchors = array(); if ($members =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) { foreach ($members as $category_id => $attributes) { // add background color to distinguish this category against others if (isset($attributes['background_color']) && $attributes['background_color']) { $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>'; } $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic'); } } if (@count($anchors)) { $abstract .= '<p class="tags" style="margin: 3px 0">' . implode(' ', $anchors) . '</p>'; } // poster name if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') { if ($item['create_name']) { $author = Users::get_link($item['create_name'], $item['create_address'], $item['create_id']); } else { $author = Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']); } } // more details $details =& Articles::build_dates($anchor, $item); // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // page details if (count($details)) { $details = '<p class="details">' . join(', ', $details) . '</p>'; } // this is another row of the output -- title, abstract, (author,) details if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') { $cells = array($title, $abstract, $author, $details); } else { $cells = array($title, $abstract, $details); } // append this row $rows[] = $cells; } // end of processing SQL::free($result); // headers if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') { $headers = array(i18n::s('Topic'), i18n::s('Abstract'), i18n::s('Poster'), i18n::s('Details')); } else { $headers = array(i18n::s('Topic'), i18n::s('Abstract'), i18n::s('Details')); } // return a sortable table $text .= Skin::table($headers, $rows, 'grid'); return $text; }
/** * list articles as topics in a forum * * @param resource the SQL result * @return string the rendered text **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // allow for complete styling $text = '<div class="last_articles">'; // build a list of articles include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // get the related overlay $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); // build a title if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // reset everything $prefix = $label = $suffix = $icon = ''; // signal articles to be published if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // flag expired articles if ($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 locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $suffix .= ' ' . LOCKED_FLAG; } // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $suffix .= ' ' . Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // indicate the id in the hovering popup $hover = i18n::s('View the page'); if (Surfer::is_member()) { $hover .= ' [article=' . $item['id'] . ']'; } // one box per update $text .= '<div class="last_article" >'; // use the title as a link to the page $text .= Skin::build_block($prefix . ucfirst($title) . $suffix, 'header1'); // some details about this page $details = array(); // page starter and date if ($item['create_name']) { $details[] = sprintf(i18n::s('Started by %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id'])) . ' ' . Skin::build_date($item['create_date']); } // page last modification if ($item['edit_date'] && $item['edit_action'] == 'article:update' && $item['edit_name']) { $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . sprintf(i18n::s('by %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id'])) . ' ' . Skin::build_date($item['edit_date']); } // friends if ($friends =& Members::list_users_by_posts_for_anchor('article:' . $item['id'], 0, USERS_LIST_SIZE, 'comma5', $item['create_id'])) { $details[] = sprintf(i18n::s('with %s'), $friends); } // people details if ($details) { $text .= '<p class="details">' . join(', ', $details) . "</p>\n"; } // the introductory text $introduction = ''; if (is_object($overlay)) { $introduction = $overlay->get_text('introduction', $item); } elseif ($item['introduction']) { $introduction = $item['introduction']; } if ($introduction) { $text .= '<div style="margin: 1em 0;">' . Codes::beautify_introduction($introduction) . '</div>'; } // insert overlay data, if any if (is_object($overlay)) { $text .= $overlay->get_text('list', $item); } // info on related comments if (($count = Comments::count_for_anchor('article:' . $item['id'])) > 1) { $text .= '<div style="margin-top: 1em;"><p class="details">' . sprintf(i18n::s('%d contributions, including:'), $count) . '</p></div>'; } // avoid first file if mentioned in last contribution $file_offset = 0; // get last contribution for this page if ($comment = Comments::get_newest_for_anchor('article:' . $item['id'])) { if (preg_match('/\\[(download|file)=/', $comment['description'])) { $file_offset++; } // bars around the last contribution $bottom_menu = array(); // last contributor $contributor = Users::get_link($comment['create_name'], $comment['create_address'], $comment['create_id']); $flag = ''; if ($comment['create_date'] >= $context['fresh']) { $flag = NEW_FLAG; } elseif ($comment['edit_date'] >= $context['fresh']) { $flag = UPDATED_FLAG; } $bottom_menu[] = sprintf(i18n::s('By %s'), $contributor) . ' ' . Skin::build_date($comment['create_date']) . $flag; // offer to reply if (Comments::allow_creation($item, $anchor)) { $link = Comments::get_url($comment['id'], 'reply'); $bottom_menu[] = Skin::build_link($link, i18n::s('Reply'), 'basic'); } // gather pieces $pieces = array(); // last contribution, and user signature $pieces[] = ucfirst(trim($comment['description'])) . Users::get_signature($comment['create_id']); // bottom if ($bottom_menu) { $pieces[] = '<div style="margin-top: 1em;">' . ucfirst(trim(Skin::finalize_list($bottom_menu, 'menu'))) . '</div>'; } // put all pieces together $text .= '<div class="last_comment">' . "\n" . join("\n", $pieces) . '</div>' . "\n"; } // list more recent files if ($items = Files::list_by_date_for_anchor('article:' . $item['id'], $file_offset, 3, 'dates')) { // more files than listed $more = ''; if (($count = Files::count_for_anchor('article:' . $item['id'])) > 3) { $more = '<span class="details">' . sprintf(i18n::s('%d files, including:'), $count) . '</span>'; } if (is_array($items)) { $items = Skin::build_list($items, 'compact'); } $text .= '<div style="margin: 1em 0;">' . $more . $items . '</div>'; } // display all tags if ($item['tags']) { $text .= ' <p class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</p>'; } // navigation links $menu = array(); // permalink $menu[] = Skin::build_link($url, i18n::s('View the page'), 'span'); // info on related links if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $menu[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); } // the main anchor link if (is_object($anchor) && (!isset($this->focus) || $item['anchor'] != $this->focus)) { $menu[] = Skin::build_link($anchor->get_url(), sprintf(i18n::s('in %s'), ucfirst($anchor->get_title())), 'span', i18n::s('View the section')); } // actually insert details $text .= Skin::finalize_list($menu, 'menu_bar'); // bottom of the box $text .= '</div>'; } // close the list of articles $text .= '</div>'; // beautify everything at once $text = Codes::beautify($text); // end of processing SQL::free($result); // done return $text; }
/** * 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; } // output as a string $text = ''; // build a list of sections $family = ''; $first = TRUE; while ($item = SQL::fetch($result)) { // change the family if ($item['family'] != $family) { $family = $item['family']; // close last table only if a section has been already listed if (!$first) { $text .= Skin::table_suffix(); } // show the family $text .= '<h2><span>' . $family . ' </span></h2>' . "\n" . Skin::table_prefix('yabb') . Skin::table_row(array(i18n::s('Board'), 'center=' . i18n::s('Topics'), i18n::s('Last post')), 'header'); } elseif ($first) { $text .= Skin::table_prefix('yabb'); $text .= Skin::table_row(array(i18n::s('Board'), 'center=' . i18n::s('Topics'), i18n::s('Last post')), 'header'); } // done with this case $first = FALSE; // 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 as a link to the page $title =& Skin::build_link($url, Codes::beautify_title($item['title']), 'basic', $hover); // also use a clickable thumbnail, if any if ($item['thumbnail_url']) { $prefix = Skin::build_link($url, '<img src="' . $item['thumbnail_url'] . '" alt="" title="' . encode_field($hover) . '" class="left_image" />', 'basic', $hover) . $prefix; } // 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 . ' '; } // board introduction if ($item['introduction']) { $suffix .= '<br style="clear: none;" />' . Codes::beautify_introduction($item['introduction']); } // more details $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, 'comma')) { $more[] = sprintf(i18n::ns('Child board: %s', 'Child boards: %s', count($children)), Skin::build_list($children, 'comma')); } // as a compact list if (count($more)) { $details .= '<ul class="compact">'; foreach ($more as $list_item) { $details .= '<li>' . $list_item . '</li>' . "\n"; } $details .= '</ul>' . "\n"; } // all details if ($details) { $details = BR . '<span class="details">' . $details . "</span>\n"; } // count posts here, and in children sections $anchors = Sections::get_branch_at_anchor('section:' . $item['id']); if (!($count = Articles::count_for_anchor($anchors))) { $count = 0; } // get last post $last_post = '--'; $article =& Articles::get_newest_for_anchor($anchors, TRUE); if ($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 = ''; } // title $last_post = Skin::build_link(Articles::get_permalink($article), Codes::beautify_title($article['title']), 'article'); // last editor if ($article['edit_date']) { // find a name, if any if ($article['edit_name']) { // label the action if (isset($article['edit_action'])) { $action = Anchors::get_action_label($article['edit_action']); } else { $action = i18n::s('edited'); } // name of last editor $user = sprintf(i18n::s('%s by %s'), $action, Users::get_link($article['edit_name'], $article['edit_address'], $article['edit_id'])); } $last_post .= $flag . BR . '<span class="tiny">' . $user . ' ' . Skin::build_date($article['edit_date']) . '</span>'; } } // this is another row of the output $text .= Skin::table_row(array($prefix . $title . $suffix . $details, 'center=' . $count, $last_post)); } // end of processing SQL::free($result); $text .= Skin::table_suffix(); return $text; }
} else { $details[] = Skin::build_date($item['edit_date']); } // all details $context['page_details'] .= ucfirst(implode(', ', $details)); // reference this item if (Surfer::is_member()) { $context['page_details'] .= BR . sprintf(i18n::s('Use following codes to reference this item: %s'), '[file=' . $item['id'] . '] or [download=' . $item['id'] . ']'); } // end of details $context['page_details'] .= '</p>'; } // file has been assigned if (isset($item['assign_id']) && $item['assign_id']) { // reminder to file owner if (Surfer::is_member() && Surfer::get_id() == $item['assign_id']) { $context['text'] .= Skin::build_block(sprintf(i18n::s('You have reserved this file %s, and you are encouraged to %s as soon as possible, or to %s.'), Skin::build_date($item['assign_date']), Skin::build_link(Files::get_url($item['id'], 'edit'), i18n::s('upload an updated version'), 'basic'), Skin::build_link(Files::get_url($item['id'], 'fetch', 'release'), i18n::s('release reservation'), 'basic')), 'note'); // information to other surfers } else { $context['text'] .= Skin::build_block(sprintf(i18n::s('This file has been assigned to %s %s, and it is likely that an updated version will be made available soon.'), Users::get_link($item['assign_name'], $item['assign_address'], $item['assign_id']), Skin::build_date($item['assign_date'])), 'note'); } } // a table to present file data $rows = array(); // file name $name = str_replace('_', ' ', $item['file_name']); // downloads and file size $other_details = array(); if (isset($item['hits']) && $item['hits'] > 1) { $other_details[] = Skin::build_number($item['hits'], i18n::s('downloads')); }
/** * 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('&', '&', $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; }
/** * check if new locations can be added * * This function returns TRUE if locations can be added to some place, * and FALSE otherwise. * * @param object an instance of the Anchor interface, if any * @param array a set of item attributes, if any * @param string the type of item, e.g., 'section' * @return boolean TRUE or FALSE */ public static function allow_creation($item = NULL, $anchor = NULL, $variant = NULL) { global $context; // backward compatibility, reverse parameters : // $anchor is always a object and $item a array if (is_object($item) || is_array($anchor)) { $permute = $anchor; $anchor = $item; $item = $permute; } // guess the variant if (!$variant) { // most frequent case if (isset($item['id'])) { $variant = 'article'; } elseif (is_object($anchor)) { $variant = $anchor->get_type(); } else { return FALSE; } } // only in articles if ($variant == 'article') { // 'no_links' option if (Articles::has_option('no_locations', $anchor, $item)) { return FALSE; } // other containers } else { // locations have to be activated explicitly if (isset($item['options']) && is_string($item['options']) && preg_match('/\\bwith_locations\\b/i', $item['options'])) { } elseif (is_object($anchor) && $anchor->has_option('with_locations')) { } else { return FALSE; } } // surfer is an associate if (Surfer::is_associate()) { return TRUE; } // submissions have been disallowed if (isset($context['users_without_submission']) && $context['users_without_submission'] == 'Y') { return FALSE; } // only in articles if ($variant == 'article') { // surfer owns this item, or the anchor if (Articles::is_owned($item, $anchor)) { return TRUE; } // surfer is an editor, and the page is not private if (isset($item['active']) && $item['active'] != 'N' && Articles::is_assigned($item['id'])) { return TRUE; } // only in sections } elseif ($variant == 'section') { // surfer owns this item, or the anchor if (Sections::is_owned($item, $anchor, TRUE)) { return TRUE; } } // surfer is an editor, and container is not private if (isset($item['active']) && $item['active'] != 'N' && is_object($anchor) && $anchor->is_assigned()) { return TRUE; } if (!isset($item['id']) && is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned()) { return TRUE; } // item has been locked if (isset($item['locked']) && $item['locked'] == 'Y') { return FALSE; } // anchor has been locked --only used when there is no item provided if (!isset($item['id']) && is_object($anchor) && $anchor->has_option('locked')) { return FALSE; } // surfer is an editor (and item has not been locked) if ($variant == 'article' && isset($item['id']) && Articles::is_assigned($item['id'])) { return TRUE; } if ($variant == 'section' && isset($item['id']) && Sections::is_assigned($item['id'])) { return TRUE; } if (is_object($anchor) && $anchor->is_assigned()) { return TRUE; } // container is hidden if (isset($item['active']) && $item['active'] == 'N') { return FALSE; } if (is_object($anchor) && $anchor->is_hidden()) { return FALSE; } // surfer is a member if (Surfer::is_member()) { return TRUE; } // container is restricted if (isset($item['active']) && $item['active'] == 'R') { return FALSE; } if (is_object($anchor) && !$anchor->is_public()) { return FALSE; } // authenticated members and subscribers are allowed to add locations if (Surfer::is_logged()) { return TRUE; } // anonymous contributions are allowed for articles if ($variant == 'article') { if (isset($item['options']) && preg_match('/\\banonymous_edit\\b/i', $item['options'])) { return TRUE; } if (is_object($anchor) && $anchor->has_option('anonymous_edit')) { return TRUE; } } // the default is to not allow for new locations return FALSE; }
/** * list files * * Recognize following variants: * - 'section:123' to list items attached to one particular anchor * - 'no_author' to list items attached to one user profile * * @param resource the SQL result * @return string HTML text to be displayed, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // sanity check if (!isset($this->focus)) { $this->focus = ''; } // process all items in the list $items = array(); while ($item = SQL::fetch($result)) { // one box at a time $box = ''; // get the main anchor $anchor = Anchors::get($item['anchor']); // we feature only the head of the list, if we are at the origin page if (!count($items) && $anchor && is_string($this->focus) && $this->focus == $anchor->get_reference()) { $box .= Codes::render_object('file', $item['id']); // no side icon $icon = ''; // we are listing various files from various places } else { $prefix = $suffix = ''; // stream the file if (Files::is_stream($item['file_name'])) { $url = Files::get_url($item['id'], 'stream', $item['file_name']); } else { $url = Files::get_url($item['id'], 'fetch', $item['file_name']); } // absolute url $url = $context['url_to_home'] . $context['url_to_root'] . $url; // signal restricted and private files if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // file title or file name $label = Codes::beautify_title($item['title']); if (!$label) { $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name'])); } // show a reference to the file for members $hover = i18n::s('Get the file'); if (Surfer::is_member()) { $hover .= ' [file=' . $item['id'] . ']'; } // flag files uploaded recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // one line of text $box .= $prefix . Skin::build_link($url, $label, 'basic', $hover) . $suffix; // side icon if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } else { $icon = $context['url_to_root'] . Files::get_icon_url($item['file_name']); } // build the complete HTML element $icon = '<img src="' . $icon . '" alt="" title="' . encode_field(strip_tags($label)) . '" />'; // make it a clickable link $icon = Skin::build_link($url, $icon, 'basic'); } // first line of details $details = array(); // file poster and last action if ($this->layout_variant != 'no_author') { $details[] = sprintf(i18n::s('shared by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])); } else { $details[] = Skin::build_date($item['edit_date']); } // downloads if ($item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('downloads')); } // file size if ($item['file_size'] > 1) { $details[] = Skin::build_number($item['file_size'], i18n::s('bytes')); } // anchor link if ($anchor && is_string($this->focus) && $this->focus != $anchor->get_reference()) { $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')); } $box .= '<p class="details">' . Skin::finalize_list($details, 'menu') . '</p>'; // append details $details = array(); // view the file $details[] = Skin::build_link(Files::get_permalink($item), i18n::s('details'), 'basic'); // file has been detached if (isset($item['assign_id']) && $item['assign_id']) { // who has been assigned? if (Surfer::is($item['assign_id'])) { $details[] = DRAFT_FLAG . sprintf(i18n::s('reserved by you %s'), Skin::build_date($item['assign_date'])); } else { $details[] = DRAFT_FLAG . sprintf(i18n::s('reserved by %s %s'), Users::get_link($item['assign_name'], $item['assign_address'], $item['assign_id']), Skin::build_date($item['assign_date'])); } } // detach or edit the file if (Files::allow_modification($item, $anchor)) { if (!isset($item['assign_id']) || !$item['assign_id']) { $details[] = Skin::build_link(Files::get_url($item['id'], 'reserve'), i18n::s('reserve'), 'basic', i18n::s('Prevent other persons from changing this file until you update it')); } // release reservation if (isset($item['assign_id']) && $item['assign_id'] && (Surfer::is($item['assign_id']) || is_object($anchor) && $anchor->is_owned())) { $details[] = Skin::build_link(Files::get_url($item['id'], 'release'), i18n::s('release reservation'), 'basic', i18n::s('Allow other persons to update this file')); } if (!isset($item['assign_id']) || !$item['assign_id'] || Surfer::is($item['assign_id']) || is_object($anchor) && $anchor->is_owned()) { $details[] = Skin::build_link(Files::get_url($item['id'], 'edit'), i18n::s('update'), 'basic', i18n::s('Share a new version of this file, or change details')); } } // delete the file if (Files::allow_deletion($item, $anchor)) { $details[] = Skin::build_link(Files::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic'); } // append details if (count($details)) { $box .= '<p class="details">' . Skin::finalize_list($details, 'menu') . '</p>'; } // insert item icon if ($icon) { $list = array(array($box, $icon)); $items[] = Skin::finalize_list($list, 'decorated'); // put the item in a division } else { $items[] = '<div style="margin: 0 0 1em 0">' . $box . '</div>'; } } // stack all items in a single column $text = Skin::finalize_list($items, 'rows'); // end of processing SQL::free($result); return $text; }
} else { $hint .= i18n::s('Image to be displayed in the panel aside the page.'); $command = i18n::s('Add an image'); } $value = ''; if (isset($item['icon_url']) && $item['icon_url']) { $value = $item['icon_url']; } $input .= '<input type="text" name="icon_url" size="55" value="' . encode_field($value) . '" maxlength="255" />'; if (Surfer::may_upload()) { $input .= ' <span class="details">' . Skin::build_link('images/edit.php?anchor=' . urlencode('file:' . $item['id']) . '&action=icon', $command, 'button') . '</span>'; } $fields[] = array($label, $input, $hint); } // the thumbnail url may be set after the page has been created if (isset($item['id']) && 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('file:' . $item['id']) . '&action=thumbnail', $command, 'button') . '</span>'; }
// the submit button $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . "\n" . Skin::finalize_list($menu, 'menu_bar') . '<input type="hidden" name="id" value="' . $item['id'] . '" />' . "\n" . '<input type="hidden" name="confirm" value="yes" />' . "\n" . '</p></form>' . "\n"; // set the focus Page::insert_script('$("#confirmed").focus();'); // the title of the table if (isset($item['title'])) { $context['text'] .= Skin::build_block($item['title'], 'title'); } // display the full text $context['text'] .= Skin::build_block($item['description'], 'description'); // execute the query string to build the table if (isset($item['query']) && $item['query']) { $context['text'] .= Tables::build($item['id'], 'sortable'); } // display the query string, if any if (isset($item['query']) && $item['query']) { $context['text'] .= BR . '<pre>' . $item['query'] . '</pre>' . BR . "\n"; } // details $details = array(); // information on uploader if (Surfer::is_member() && $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'])); } // all details if ($details) { $context['text'] .= '<p class="details">' . ucfirst(implode(', ', $details)) . '</p>' . "\n"; } } // render the skin render_skin();
$lines[] = Skin::build_link(Articles::get_url($item['id'], 'mail'), ARTICLES_EMAIL_IMG . i18n::s('Notify participants')); } // manage editors if ($cur_article->is_owned() || Surfer::is_associate()) { Skin::define_img('ARTICLES_ASSIGN_IMG', 'articles/assign.gif'); $lines[] = Skin::build_link(Users::get_url('article:' . $item['id'], 'select'), ARTICLES_ASSIGN_IMG . i18n::s('Manage participants')); } // the command to track back if (Links::allow_trackback()) { Skin::define_img('TOOLS_TRACKBACK_IMG', 'tools/trackback.gif'); $lines[] = Skin::build_link('links/trackback.php?anchor=' . urlencode('article:' . $item['id']), TOOLS_TRACKBACK_IMG . i18n::s('Reference this page'), 'basic', i18n::s('Various means to link to this page')); } // more tools if (isset($context['with_export_tools']) && $context['with_export_tools'] == 'Y' || is_object($anchor) && $anchor->has_option('with_export_tools')) { // check tools visibility if (Surfer::is_member() || isset($context['with_anonymous_export_tools']) && $context['with_anonymous_export_tools'] == 'Y') { // get a PDF version Skin::define_img('ARTICLES_PDF_IMG', 'articles/export_pdf.gif'); $lines[] = Skin::build_link(Articles::get_url($item['id'], 'fetch_as_pdf'), ARTICLES_PDF_IMG . i18n::s('Save as PDF'), 'basic', i18n::s('Save as PDF')); // open in Word Skin::define_img('ARTICLES_WORD_IMG', 'articles/export_word.gif'); $lines[] = Skin::build_link(Articles::get_url($item['id'], 'fetch_as_msword'), ARTICLES_WORD_IMG . i18n::s('Copy in MS-Word'), 'basic', i18n::s('Copy in MS-Word')); } } // print this page if (Surfer::is_logged() || isset($context['with_anonymous_export_tools']) && $context['with_anonymous_export_tools'] == 'Y') { Skin::define_img('TOOLS_PRINT_IMG', 'tools/print.gif'); $lines[] = Skin::build_link(Articles::get_url($item['id'], 'print'), TOOLS_PRINT_IMG . i18n::s('Print this page'), 'basic', i18n::s('Get a paper copy of this page.')); } // in a side box if (count($lines)) {
} if (isset($context['arguments'][2])) { $next = $context['arguments'][2]; } $next = strip_tags($next); // // is this surfer allowed to browse the resulting page? // // associates and editors can do what they want if (Surfer::is_associate() || Articles::is_assigned($id) || is_object($anchor) && $anchor->is_assigned()) { $permitted = TRUE; } elseif (Surfer::get_id() && isset($item['create_id']) && $item['create_id'] == Surfer::get_id()) { $permitted = TRUE; } elseif (is_object($anchor) && !$anchor->is_viewable()) { $permitted = FALSE; } elseif (isset($item['active']) && $item['active'] == 'R' && Surfer::is_member()) { $permitted = TRUE; } elseif (isset($item['active']) && $item['active'] == 'Y') { $permitted = TRUE; } else { $permitted = FALSE; } // load the skin, maybe with a variant load_skin('polls', $anchor); // the path to this page $context['path_bar'] = Surfer::get_path_bar($anchor); // the title of the page if (isset($item['title']) && $item['title']) { $context['page_title'] = $item['title']; } else { $context['page_title'] = i18n::s('Vote for a poll');
/** * check if a surfer owns a section * * @param array section attributes * @param object parent anchor, if any * @param boolean FALSE if the surfer can be an editor of parent section * @param int optional reference to some user profile * @return TRUE or FALSE */ public static function is_owned($item = NULL, $anchor = NULL, $strict = FALSE, $user_id = NULL) { global $context; // id of requesting user if (!$user_id) { if (!Surfer::get_id()) { return FALSE; } $user_id = Surfer::get_id(); } // surfer owns this section if (isset($item['owner_id']) && $item['owner_id'] == $user_id) { return TRUE; } // do not look upwards if (!$anchor || !is_object($anchor)) { return FALSE; } // associates can do what they want if (Surfer::is($user_id) && Surfer::is_associate()) { return TRUE; } // we are owning one of the parents if ($anchor->is_owned($user_id)) { return TRUE; } // surfer is a member assigned to one of the parents if (!$strict && Surfer::is_member() && is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned($user_id)) { return TRUE; } // sorry return FALSE; }
// add background color to distinguish this category against others if (isset($attributes['background_color']) && $attributes['background_color']) { $label = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $label . '</span>'; } // build a unlink button for this category if (Surfer::is_associate()) { $suffix .= BR . '<form method="post" action="' . $context['script_url'] . '"><div>' . '<input type="hidden" name="anchor" value="category:' . $category_id . '" />' . '<input type="hidden" name="member" value="' . encode_field($member) . '" />' . Skin::build_submit_button(i18n::s('Unlink')) . '</div></form>'; } // a button to change the thumbnail of the anchored page if ($icon) { $suffix .= ' <form method="post" action="' . $context['url_to_root'] . 'categories/set_as_thumbnail.php"><div>' . '<input type="hidden" name="anchor" value="' . encode_field($member) . '" />' . '<input type="hidden" name="id" value="' . $category_id . '" />' . Skin::build_submit_button(i18n::s('Use this thumbnail as the thumbnail of the page')) . '</div></form>'; } // list sub-categories to be linked, if any // display active and restricted items $where = "categories.active='Y'"; if (Surfer::is_member()) { $where .= " OR categories.active='R'"; } if (Surfer::is_associate()) { $where .= " OR categories.active='N'"; } // only consider live categories $where = '(' . $where . ')' . ' AND ((categories.expiry_date is NULL)' . "\tOR (categories.expiry_date <= '" . NULL_DATE . "') OR (categories.expiry_date > '" . $context['now'] . "'))"; // limit the query to top level only $query = "SELECT categories.id, categories.title " . " FROM " . SQL::table_name('categories') . " AS categories " . " WHERE (" . $where . ") AND (categories.anchor='category:" . $category_id . "')" . " ORDER BY categories.title"; $result = SQL::query($query); $sub_categories = array(); while ($result && ($option = SQL::fetch($result))) { $sub_categories['category:' . $option['id']] = $option['title']; } if (count($sub_categories)) {
$fields['description'] = i18n::c('This category is a specialized glossary of terms, made out of tags added to pages, and out of search requests.'); $fields['rank'] = 29000; $fields['options'] = 'no_links'; if ($fields['id'] = Categories::post($fields)) { Categories::clear($fields); $root_category = 'category:' . $fields['id']; } } // stop crawlers if (Surfer::is_crawler()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // ensure we have a valid category to host keywords } elseif (!$root_category) { Logger::error(i18n::s('No item has been found.')); } elseif (!Surfer::is_member()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // ensure we have a keyword } elseif (!$search) { Logger::error(i18n::s('No keyword to search for.')); } elseif (!($articles = Articles::search($search, 1.0, 50, 'raw'))) { Logger::error(i18n::s('No item has been found.')); // create a category for this keyword if none exists yet } elseif (!($category =& Categories::get_by_keyword($search))) { $fields = array(); $fields['keywords'] = $search; $fields['anchor'] = $root_category; $fields['title'] = ucfirst($search); if ($fields['id'] = Categories::post($fields)) { Categories::clear($fields);