/**
* Check whether the main category and the extra categories are valid
* in a Blog's context and try to fix errors.
*
* @author Tilman BLUMENBACH / Tblue
*
* @param integer The main category to check (by reference).
* @param object The Blog to which the category is supposed to belong to (by reference).
* @param array Extra categories for the post (by reference).
*
* @return boolean False on error (use xmlrpcs_resperror() to return it), true on success.
*/
function xmlrpcs_check_cats(&$maincat, &$Blog, &$extracats)
{
global $xmlrpcs_errcode, $xmlrpcs_errmsg, $xmlrpcerruser;
// Trim $maincat and $extracats (qtm sends whitespace before the cat IDs):
$maincat = trim($maincat);
$extracats = array_map('trim', $extracats);
$ChapterCache =& get_ChapterCache();
// ---- CHECK MAIN CATEGORY ----
if ($ChapterCache->get_by_ID($maincat, false) === false) {
// Category does not exist!
// Remove old category from extra cats:
if (($key = array_search($maincat, $extracats)) !== false) {
unset($extracats[$key]);
}
// Set new category (blog default):
$maincat = $Blog->get_default_cat_ID();
logIO('Invalid main cat ID - new ID: ' . $maincat);
} else {
if (get_allow_cross_posting() < 2 && get_catblog($maincat) != $Blog->ID) {
// We cannot use a maincat of another blog than the current one:
$xmlrpcs_errcode = $xmlrpcerruser + 11;
$xmlrpcs_errmsg = 'Current crossposting setting does not allow moving posts to a different blog.';
return false;
}
}
// ---- CHECK EXTRA CATEGORIES ----
foreach ($extracats as $ecat) {
if ($ecat == $maincat) {
// We already checked the maincat above (or reset it):
continue;
}
logIO('Checking extra cat: ' . $ecat);
if ($ChapterCache->get_by_ID($ecat, false) === false) {
// Extra cat does not exist:
$xmlrpcs_errcode = $xmlrpcerruser + 11;
$xmlrpcs_errmsg = 'Extra category ' . (int) $ecat . ' not found in requested blog.';
return false;
}
}
if (!in_array($maincat, $extracats)) {
logIO('$maincat was not found in $extracats array - adding.');
$extracats[] = $maincat;
}
return true;
}
//.........这里部分代码省略.........
// auto requires jQuery
// fp> if we add this here, we have to exetnd the inner if()
// init_ratings_js( 'blog' );
// Get list of active filters:
$active_filters = $MainList->get_active_filters();
if (!empty($active_filters)) {
// The current page is being filtered...
if (array_diff($active_filters, array('page')) == array()) {
// This is just a follow "paged" page
$disp_detail = 'posts-next';
$seo_page_type = 'Next page';
if ($Blog->get_setting('paged_noindex')) {
// We prefer robots not to index category pages:
$robots_index = false;
}
} elseif (array_diff($active_filters, array('cat_array', 'cat_modifier', 'cat_focus', 'posts', 'page')) == array()) {
// This is a category page
$disp_detail = 'posts-cat';
$seo_page_type = 'Category page';
if ($Blog->get_setting('chapter_noindex')) {
// We prefer robots not to index category pages:
$robots_index = false;
}
global $cat, $catsel;
if (empty($catsel) && preg_match('~^[0-9]+$~', $cat)) {
// We are on a single cat page:
// NOTE: we must have selected EXACTLY ONE CATEGORY through the cat parameter
// BUT: - this can resolve to including children
// - selecting exactly one cat through catsel[] is NOT OK since not equivalent (will exclude children)
// echo 'SINGLE CAT PAGE';
if ($Blog->get_setting('canonical_cat_urls') && $redir == 'yes' || $Blog->get_setting('relcanonical_cat_urls')) {
// Check if the URL was canonical:
if (!isset($Chapter)) {
$ChapterCache =& get_ChapterCache();
/**
* @var Chapter
*/
$Chapter =& $ChapterCache->get_by_ID($MainList->filters['cat_array'][0], false);
}
if ($Chapter) {
if ($Chapter->parent_ID) {
// This is a sub-category page (i-e: not a level 1 category)
$disp_detail = 'posts-subcat';
}
$canonical_url = $Chapter->get_permanent_url(NULL, NULL, $MainList->get_active_filter('page'), NULL, '&');
if (!is_same_url($ReqURL, $canonical_url)) {
// fp> TODO: we're going to lose the additional params, it would be better to keep them...
// fp> what additional params actually?
if ($Blog->get_setting('canonical_cat_urls') && $redir == 'yes') {
// REDIRECT TO THE CANONICAL URL:
header_redirect($canonical_url, true);
} else {
// Use rel="canonical":
add_headline('<link rel="canonical" href="' . $canonical_url . '" />');
}
}
} else {
// If the requested chapter was not found display 404 page
$Messages->add(T_('The requested chapter was not found'));
global $disp;
$disp = '404';
break;
}
}
if ($post_navigation == 'same_category') {
// Category is set and post navigation should go through the same category, set navigation target param
/**
* Load items by the given categories or collection ID
* After the Items are loaded create a map of loaded items by categories
*
* @param array of category ids
* @param integer collection ID
* @return boolean true if load items was required and it was loaded successfully, false otherwise
*/
function load_by_categories($cat_array, $coll_ID)
{
global $DB, $posttypes_specialtypes;
if (empty($cat_array) && empty($coll_ID)) {
// Nothing to load
return false;
}
// In case of an empty cat_array param, use categoriesfrom the given collection
if (empty($cat_array)) {
// Get all categories from the given subset
$ChapterCache =& get_ChapterCache();
$subset_chapters = $ChapterCache->get_chapters_by_subset($coll_ID);
$cat_array = array();
foreach ($subset_chapters as $Chapter) {
$cat_array[] = $Chapter->ID;
}
}
// Check which category is not loaded
$not_loaded_cat_ids = array();
foreach ($cat_array as $cat_ID) {
if (!isset($this->items_by_cat_map[$cat_ID])) {
// This category is not loaded
$not_loaded_cat_ids[] = $cat_ID;
// Initialize items_by_cat_map for this cat_ID
$this->items_by_cat_map[$cat_ID] = array('items' => array(), 'sorted' => false);
}
}
if (empty($not_loaded_cat_ids)) {
// Requested categories items are all loaded
return false;
}
// Query to load all Items from the given categories
$sql = 'SELECT postcat_cat_ID as cat_ID, postcat_post_ID as post_ID FROM T_postcats
WHERE postcat_cat_ID IN ( ' . implode(', ', $not_loaded_cat_ids) . ' )
ORDER BY postcat_post_ID';
$cat_posts = $DB->get_results($sql, ARRAY_A, 'Get all category post ids pair by category');
// Initialize $Blog from coll_ID
$BlogCache =& get_BlogCache();
$Blog = $BlogCache->get_by_ID($coll_ID);
$visibility_statuses = is_admin_page() ? get_visibility_statuses('keys', array('trash')) : get_inskin_statuses($coll_ID, 'post');
// Create ItemQuery for loading visible items
$ItemQuery = new ItemQuery($this->dbtablename, $this->dbprefix, $this->dbIDname);
// Set filters what to select
$ItemQuery->SELECT($this->dbtablename . '.*');
$ItemQuery->where_chapter2($Blog, $not_loaded_cat_ids, "");
$ItemQuery->where_visibility($visibility_statuses);
$ItemQuery->where_datestart(NULL, NULL, NULL, NULL, $Blog->get_timestamp_min(), $Blog->get_timestamp_max());
$ItemQuery->where_types('-' . implode(',', $posttypes_specialtypes));
// Clear previous items from the cache and load by the defined SQL
$this->clear(true);
$this->load_by_sql($ItemQuery);
foreach ($cat_posts as $row) {
// Iterate through the post - cat pairs and fill the map
if (empty($this->cache[$row['post_ID']])) {
// The Item was not loaded because it does not correspond to the defined filters
continue;
}
// Add to the map
$this->items_by_cat_map[$row['cat_ID']]['items'][] = $this->get_by_ID($row['post_ID']);
}
}
/**
* Display button to create a new post
*
* @param integer Chapter ID
*/
function display_post_button($chapter_ID, $Item = NULL)
{
global $Blog;
$post_button = '';
$chapter_is_locked = false;
$write_new_post_url = $Blog->get_write_item_url($chapter_ID);
if ($write_new_post_url != '') {
// Display button to write a new post
$post_button = '<a href="' . $write_new_post_url . '"><span class="ficon newTopic" title="' . T_('Post new topic') . '"></span></a>';
} else {
// If a creating of new post is unavailable
$ChapterCache =& get_ChapterCache();
$current_Chapter = $ChapterCache->get_by_ID($chapter_ID, false, false);
if ($current_Chapter && $current_Chapter->lock) {
// Display icon to inform that this forum is locked
$post_button = '<span class="ficon locked" title="' . T_('This forum is locked: you cannot post, reply to, or edit topics.') . '"></span>';
$chapter_is_locked = true;
}
}
if (!empty($Item)) {
if ($Item->comment_status == 'closed' || $Item->comment_status == 'disabled' || $Item->is_locked()) {
// Display icon to inform that this topic is locked for comments
if (!$chapter_is_locked) {
// Display this button only when chapter is not locked, to avoid a duplicate button
$post_button .= ' <span class="ficon locked" title="' . T_('This topic is locked: you cannot edit posts or make replies.') . '"></span>';
}
} else {
// Display button to post a reply
$post_button .= ' <a href="' . $Item->get_feedback_url() . '#form_p' . $Item->ID . '"><span class="ficon postReply" title="' . T_('Reply to topic') . '"></span></a>';
}
}
if (!empty($post_button)) {
// Display button
echo '<div class="post_button">';
echo $post_button;
echo '</div>';
}
}
/**
* Get chapters
*
* @param integer Chapter parent ID
*/
function get_chapters($parent_ID = 0)
{
global $Blog, $skin_chapters_cache;
if (isset($skin_chapters_cache)) {
// Get chapters from cache
return $skin_chapters_cache;
}
$skin_chapters_cache = array();
if ($parent_ID > 0) {
// Get children of selected chapter
global $DB, $Settings;
$skin_chapters_cache = array();
$SQL = new SQL();
$SQL->SELECT('cat_ID');
$SQL->FROM('T_categories');
$SQL->WHERE('cat_parent_ID = ' . $DB->quote($parent_ID));
if ($Settings->get('chapter_ordering') == 'manual') {
// Manual order
$SQL->ORDER_BY('cat_meta, cat_order');
} else {
// Alphabetic order
$SQL->ORDER_BY('cat_meta, cat_name');
}
$ChapterCache =& get_ChapterCache();
$categories = $DB->get_results($SQL->get());
foreach ($categories as $c => $category) {
$skin_chapters_cache[$c] = $ChapterCache->get_by_ID($category->cat_ID);
// Get children
$SQL->WHERE('cat_parent_ID = ' . $DB->quote($category->cat_ID));
$children = $DB->get_results($SQL->get());
foreach ($children as $child) {
$skin_chapters_cache[$c]->children[] = $ChapterCache->get_by_ID($child->cat_ID);
}
}
} else {
// Get the all chapters for current blog
$ChapterCache =& get_ChapterCache();
$ChapterCache->load_subset($Blog->ID);
if (isset($ChapterCache->subset_cache[$Blog->ID])) {
$skin_chapters_cache = $ChapterCache->subset_cache[$Blog->ID];
foreach ($skin_chapters_cache as $c => $Chapter) {
// Init children
foreach ($skin_chapters_cache as $child) {
// Again go through all chapters to find a children for current chapter
if ($Chapter->ID == $child->get('parent_ID')) {
// Add to array of children
$skin_chapters_cache[$c]->children[] = $child;
}
}
}
foreach ($skin_chapters_cache as $c => $Chapter) {
// Unset the child chapters
if ($Chapter->get('parent_ID')) {
unset($skin_chapters_cache[$c]);
}
}
}
}
return $skin_chapters_cache;
}
/**
* Callback: Generate category line when it has children
*
* @param object Chapter we want to display
* @param integer Level of the category in the recursive tree
* @return string HTML
*/
function cat_line($Chapter, $level)
{
global $cat_array;
if (!isset($cat_array)) {
$cat_array = array();
}
$exclude_cats = sanitize_id_list($this->disp_params['exclude_cats'], true);
if (in_array($Chapter->ID, $exclude_cats)) {
// Cat ID is excluded, skip it
return;
}
// ID of the current selected category
$first_selected_cat_ID = isset($cat_array[0]) ? $cat_array[0] : 0;
if (!isset($this->disp_params['current_parents'])) {
// Try to find the parent categories in order to select it because of widget setting is enabled
$this->disp_params['current_all_cats'] = array();
// All children of the root parent of the selcted category
$this->disp_params['current_parents'] = array();
// All parents of the selected category
$this->disp_params['current_selected_level'] = 0;
// Level of the selected category
if ($first_selected_cat_ID > 0) {
$this->disp_params['current_selected_level'] = $this->disp_params['current_selected_level'] + 1;
$ChapterCache =& get_ChapterCache();
$parent_Chapter =& $ChapterCache->get_by_ID($first_selected_cat_ID, false, false);
while ($parent_Chapter !== NULL) {
// Go up to the first/root category
$root_parent_ID = $parent_Chapter->ID;
if ($parent_Chapter =& $parent_Chapter->get_parent_Chapter()) {
$this->disp_params['current_parents'][] = $parent_Chapter->ID;
$this->disp_params['current_all_cats'][] = $parent_Chapter->ID;
$this->disp_params['current_selected_level'] = $this->disp_params['current_selected_level'] + 1;
}
}
// Load all categories of the current selected path (these categories should be visible on page)
$this->disp_params['current_all_cats'] = $cat_array;
$this->load_category_children($root_parent_ID, $this->disp_params['current_all_cats'], $this->disp_params['current_parents']);
}
}
$parent_cat_is_visible = isset($this->disp_params['parent_cat_is_visible']) ? $this->disp_params['parent_cat_is_visible'] : false;
$start_level = intval($this->disp_params['start_level']);
if ($start_level > 1 && ($start_level > $level + 1 || !in_array($Chapter->ID, $this->disp_params['current_all_cats']) && !$this->disp_params['parent_cat_is_visible'] || $this->disp_params['current_selected_level'] < $level && !$this->disp_params['parent_cat_is_visible'])) {
// Don't show this item because of level restriction
$this->disp_params['parent_cat_is_visible'] = false;
//return '<span style="font-size:10px">hidden: ('.$level.'|'.$this->disp_params['current_selected_level'].')</span>';
return '';
} elseif (!isset($this->disp_params['current_cat_level'])) {
// Save level of the current selected category
$this->disp_params['current_cat_level'] = $level;
$this->disp_params['parent_cat_is_visible'] = true;
}
if ($this->disp_params['mark_first_selected'] && $Chapter->ID == $first_selected_cat_ID || $this->disp_params['mark_children'] && $Chapter->ID != $first_selected_cat_ID && in_array($Chapter->ID, $cat_array) || $this->disp_params['mark_parents'] && $Chapter->ID != $first_selected_cat_ID && in_array($Chapter->ID, $this->disp_params['current_parents'])) {
// This category should be selected
$start_tag = $this->disp_params['item_selected_start'];
} else {
if (empty($Chapter->children)) {
// This category has no children
$start_tag = $this->disp_params['item_last_start'];
} else {
$start_tag = $this->disp_params['item_start'];
}
}
if ($Chapter->meta) {
// Add class name "meta" for meta categories
$start_tag = $this->add_cat_class_attr($start_tag, 'meta');
}
$r = $start_tag;
if ($this->disp_params['use_form'] || $this->disp_params['display_checkboxes']) {
// We want to add form fields:
$cat_checkbox_params = '';
if ($Chapter->meta) {
// Disable the checkbox of meta category ( and hide it by css )
$cat_checkbox_params = ' disabled="disabled"';
}
$r .= '<label><input type="checkbox" name="catsel[]" value="' . $Chapter->ID . '" class="checkbox middle"';
if (in_array($Chapter->ID, $cat_array)) {
// This category is in the current selection
$r .= ' checked="checked"';
}
$r .= $cat_checkbox_params . ' /> ';
}
$cat_name = $Chapter->dget('name');
if ($Chapter->lock && isset($this->disp_params['show_locked']) && $this->disp_params['show_locked']) {
$cat_name .= '<span style="padding:0 5px;" >' . get_icon('file_not_allowed', 'imgtag', array('title' => T_('Locked'))) . '</span>';
}
// Make a link from category name
$r .= '<a href="';
if ($this->disp_params['link_type'] == 'context') {
// We want to preserve current browsing context:
$r .= regenerate_url('cats,catsel', 'cat=' . $Chapter->ID);
} else {
$r .= $Chapter->get_permanent_url();
}
//.........这里部分代码省略.........
/**
* Get name for a given cat ID.
*
* @return string Cat name in case of success, false on failure.
*/
function get_catname($cat_ID)
{
$ChapterCache =& get_ChapterCache();
$Chapter =& $ChapterCache->get_by_ID($cat_ID);
return $Chapter->name;
}
/**
* Get ready for displaying the skin.
*
* This may register some CSS or JS...
*/
function display_init()
{
global $Messages, $disp, $debug;
// Request some common features that the parent function (Skin::display_init()) knows how to provide:
parent::display_init(array('jquery', 'font_awesome', 'bootstrap', 'bootstrap_evo_css', 'bootstrap_messages', 'style_css', 'colorbox', 'bootstrap_init_tooltips', 'disp_auto'));
// Skin specific initializations:
// Limit images by max height:
$max_image_height = intval($this->get_setting('max_image_height'));
if ($max_image_height > 0) {
add_css_headline('.evo_image_block img { max-height: ' . $max_image_height . 'px; width: auto; }');
}
// Initialize a template depending on current page
switch ($disp) {
case 'front':
// Init star rating for intro posts:
init_ratings_js('blog', true);
break;
case 'posts':
global $cat, $bootstrap_manual_posts_text;
// Init star rating for intro posts:
init_ratings_js('blog', true);
$bootstrap_manual_posts_text = T_('Posts');
if (!empty($cat)) {
// Init the <title> for categories page:
$ChapterCache =& get_ChapterCache();
if ($Chapter =& $ChapterCache->get_by_ID($cat, false)) {
$bootstrap_manual_posts_text = $Chapter->get('name');
}
}
break;
}
if ($this->is_left_navigation_visible()) {
// Include JS code for left navigation panel only when it is displayed:
require_js($this->get_url() . 'left_navigation.js');
}
}
请发表评论