Exemplo n.º 1
0
$params = array_merge(array('post_navigation' => 'same_category'), $params);
global $Item, $cat;
/**
 * @var array Save all statuses that used on this page in order to show them in the footer legend
 */
global $legend_statuses, $legend_icons;
if (!is_array($legend_statuses)) {
    // Init this array only first time
    $legend_statuses = array();
}
if (!is_array($legend_icons)) {
    // Init this array only first time
    $legend_icons = array();
}
// Calculate what comments has the Item:
$comments_number = generic_ctp_number($Item->ID, 'comments', get_inskin_statuses($Item->get_blog_ID(), 'comment'));
$status_icon = 'fa-comments';
$status_title = '';
$status_alt = T_('Discussion topic');
$legend_icons['topic_default'] = 1;
if ($Item->is_featured() || $Item->is_intro()) {
    // Special icon for featured & intro posts
    $status_icon = 'fa-bullhorn';
    $status_alt = T_('Sticky topic / Announcement');
    $status_title = '<strong>' . T_('Sticky') . ':</strong> ';
    $legend_icons['topic_sticky'] = 1;
} elseif ($Item->comment_status == 'closed' || $Item->comment_status == 'disabled' || $Item->is_locked()) {
    // The post is closed for comments
    $status_icon = 'fa-lock';
    $status_alt = T_('This topic is locked: you cannot edit posts or make replies.');
    $legend_icons['topic_locked'] = 1;
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * @todo  add param for saved session filter set
  *
  * @param Blog
  * @param mixed Default filter set: Do not show posts before this timestamp, can be 'now'
  * @param mixed Default filter set: Do not show posts after this timestamp, can be 'now'
  * @param integer|NULL Limit
  * @param string name of cache to be used (for table prefix info)
  * @param string prefix to differentiate page/order params when multiple Results appear one same page
  * @param array restrictions for itemlist (position, contact, firm, ...) key: restriction name, value: ID of the restriction
  */
 function ItemListLight(&$Blog, $timestamp_min = NULL, $timestamp_max = NULL, $limit = 20, $cache_name = 'ItemCacheLight', $param_prefix = '', $filterset_name = '')
 {
     global $Settings, $posttypes_specialtypes;
     // Call parent constructor:
     parent::DataObjectList2(get_Cache($cache_name), $limit, $param_prefix, NULL);
     // asimo> The ItemQuery init was moved into the query_init() method
     // The SQL Query object:
     // $this->ItemQuery = new ItemQuery( $this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname );
     $this->Blog =& $Blog;
     if (!empty($filterset_name)) {
         // Set the filterset_name with the filterset_name param
         $this->filterset_name = 'ItemList_filters_' . $filterset_name;
     } else {
         // Set a generic filterset_name
         $this->filterset_name = 'ItemList_filters_coll' . (!is_null($this->Blog) ? $this->Blog->ID : '0');
     }
     $this->page_param = $param_prefix . 'paged';
     // Initialize the default filter set:
     $this->set_default_filters(array('filter_preset' => NULL, 'ts_min' => $timestamp_min, 'ts_max' => $timestamp_max, 'ts_created_max' => NULL, 'coll_IDs' => NULL, 'cat_array' => array(), 'cat_modifier' => NULL, 'cat_focus' => 'wide', 'tags' => NULL, 'authors' => NULL, 'authors_login' => NULL, 'assignees' => NULL, 'assignees_login' => NULL, 'author_assignee' => NULL, 'lc' => 'all', 'keywords' => NULL, 'keyword_scope' => 'title,content', 'phrase' => 'AND', 'exact' => 0, 'post_ID' => NULL, 'post_ID_list' => NULL, 'post_title' => NULL, 'ymdhms' => NULL, 'week' => NULL, 'ymdhms_min' => NULL, 'ymdhms_max' => NULL, 'statuses' => NULL, 'types' => '-' . implode(',', $posttypes_specialtypes), 'visibility_array' => get_inskin_statuses(is_null($this->Blog) ? NULL : $this->Blog->ID, 'post'), 'orderby' => !is_null($this->Blog) ? $this->Blog->get_setting('orderby') : 'datestart', 'order' => !is_null($this->Blog) ? $this->Blog->get_setting('orderdir') : 'DESC', 'unit' => !is_null($this->Blog) ? $this->Blog->get_setting('what_to_show') : 'posts', 'posts' => $this->limit, 'page' => 1, 'featured' => NULL));
 }
Exemplo n.º 3
0
 /**
  * Returns a permalink link to the Comment
  *
  * Note: If you only want the permalink URL, use Comment::get_permanent_url()
  *
  * @param string link text or special value: '#', '#icon#', '#text#'
  * @param string link title
  * @param string class name
  * @param boolean TRUE - to use attr rel="nofollow"
  * @param boolean Restrict by inskin statuses
  * @return string Link
  */
 function get_permanent_link($text = '#', $title = '#', $class = '', $nofollow = false, $restrict_status = true)
 {
     if ($restrict_status && !in_array($this->status, get_inskin_statuses())) {
         return '';
     }
     global $current_User, $baseurl;
     switch ($text) {
         case '#':
             $text = get_icon('permalink') . T_('Permalink');
             break;
         case '#icon#':
             $text = get_icon('permalink');
             break;
         case '#text#':
             $text = T_('Permalink');
             break;
         case '#item#':
             $comment_Item =& $this->get_Item();
             $text = $comment_Item->get_title(array('link_type' => 'none'));
             break;
     }
     if ($title == '#') {
         $title = T_('Permanent link to this comment');
     }
     $url = $this->get_permanent_url();
     // Display as link
     $r = '<a href="' . $url . '" title="' . $title . '"';
     if (!empty($class)) {
         $r .= ' class="' . $class . '"';
     }
     if (!empty($nofollow)) {
         $r .= ' rel="nofollow"';
     }
     $r .= '>' . $text . '</a>';
     return $r;
 }
Exemplo n.º 4
0
 * It is meant to be called by an include in the main.page.php template.
 * To display a feedback, you should call a stub AND pass the right parameters
 * For example: /blogs/index.php?disp=comments
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/gnu-gpl-license}
 * @copyright (c)2003-2015 by Francois Planque - {@link http://fplanque.com/}
 *
 * @package evoskins
 */
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
$CommentList = new CommentList2($Blog);
// Filter list:
$CommentList->set_filters(array('types' => array('comment', 'trackback', 'pingback'), 'statuses' => get_inskin_statuses($Blog->ID, 'comment'), 'order' => 'DESC', 'comments' => $Blog->get_setting('latest_comments_num')));
// Get ready for display (runs the query):
$CommentList->display_init();
$CommentList->display_if_empty(array('msg_empty' => T_('No replies yet...')));
if ($CommentList->result_num_rows > 0) {
    ?>
<table class="bForums fixed_layout evo_content_block" width="100%" cellspacing="1" cellpadding="2" border="0">
	<tr>
		<th class="col1"><?php 
    echo T_('Author');
    ?>
</th>
		<th><?php 
    echo T_('Message');
    ?>
</th>
Exemplo n.º 5
0
    /**
     * 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']);
        }
    }
Exemplo n.º 6
0
/**
 * Construct the where clause to limit retrieved posts/comment on their status
 *
 * TODO: asimo> would be good to move this function to an items and comments common file
 *
 * @param Array statuses of posts/comments we want to get
 * @param string post/comment table db prefix
 * @param integer blog ID
 * @param string permission prefix: 'blog_post!' or 'blog_comment!'
 * @param boolean filter statuses by the current user perm and current page, by default is true. It should be false only e.g. when we have to count comments awaiting moderation.
 * @return string statuses where condition
 */
function statuses_where_clause($show_statuses = NULL, $dbprefix = 'post_', $req_blog = NULL, $perm_prefix = 'blog_post!', $filter_by_perm = true, $author_filter = NULL)
{
    global $current_User, $blog, $DB;
    if (is_null($req_blog)) {
        // try to init request blog if it was not set
        global $blog;
        $req_blog = $blog;
    }
    if (empty($show_statuses)) {
        // use in-skin statuses if show_statuses is empty
        $show_statuses = get_inskin_statuses();
    }
    // init where clauses array
    $where = array();
    // Check modules item statuses where condition but only in case of the items, and don't need to check in case of comments
    if ($req_blog && $perm_prefix == 'blog_post!') {
        // If requested blog is set, then set additional "where" clauses from modules method, before we would manipulate the $show_statuses array
        $modules_condition = modules_call_method('get_item_statuses_where_clause', array('blog_ID' => $req_blog, 'statuses' => $show_statuses));
        if (!empty($modules_condition)) {
            foreach ($modules_condition as $condition) {
                if (!empty($condition)) {
                    // condition is not empty
                    $where[] = $condition;
                }
            }
        }
    }
    if (is_logged_in(false)) {
        // User is logged in and the account was activated
        if ($current_User->check_perm('blogs', 'editall', false)) {
            // User has permission to all blogs posts and comments, we don't have to check blog specific permissions.
            $allowed_statuses_cond = get_allowed_statuses_condition($show_statuses, $dbprefix, NULL, $perm_prefix);
            if (!empty($allowed_statuses_cond)) {
                // condition is not empty
                $where[] = $allowed_statuses_cond;
            }
            $filter_by_perm = false;
            $show_statuses = NULL;
        } elseif (!empty($author_filter) && $author_filter != $current_User->ID) {
            // Author filter is set, but current_User is not the filtered user, then these statuses are not visible for sure
            $show_statuses = array_diff($show_statuses, array('private', 'draft'));
        }
    }
    if ($req_blog == 0 && $filter_by_perm) {
        // This is a very special case when we must check visibility statuses from each blog separately
        // Note: This case should not be called frequently, it may be really slow!!
        $where_condition = '';
        $condition = '';
        if (in_array('published', $show_statuses)) {
            // 'published' status is always allowed in case of all blogs, handle this condition separately
            $where_condition = '( ' . $dbprefix . 'status = "published" )';
            $condition = ' OR ';
        }
        if (!is_logged_in(false)) {
            // When user is not logged in only the 'published' status is allowed, don't check more
            return $where_condition;
        }
        if (in_array('community', $show_statuses)) {
            // 'community' status is always allowed in case of all blogs when a user is logged in, handle this condition separately
            $where_condition .= $condition . '( ' . $dbprefix . 'status = "community" )';
            $condition = ' OR ';
        }
        // Remove 'published' and 'community' statuses because those were already handled
        $show_statuses = array_diff($show_statuses, array('published', 'community'));
        if (empty($show_statuses)) {
            // return if there are no other status
            return $where_condition;
        }
        // Select each blog
        $blog_ids = $DB->get_col('SELECT blog_ID FROM T_blogs');
        $sub_condition = '';
        foreach ($blog_ids as $blog_id) {
            // create statuses where clause condition for each blog separately
            $status_perm = statuses_where_clause($show_statuses, $dbprefix, $blog_id, $perm_prefix, $filter_by_perm, $author_filter);
            if ($status_perm) {
                // User has permission to view some statuses on this blog
                $sub_condition .= '( ( cat_blog_ID = ' . $blog_id . ' ) AND' . $status_perm . ' ) OR ';
            }
        }
        if ($dbprefix == 'post_') {
            // Item query condition
            $from_table = 'FROM T_items__item';
            $reference_column = 'post_ID';
        } else {
            // Comment query condition
            $from_table = 'FROM T_comments';
            $reference_column = 'comment_post_ID';
        }
        // Select each object ID which corresponds to the statuses condition.
        // Note: This is a very slow query when there is many post/comments. This case should not be used frequently.
        $sub_query = 'SELECT ' . $dbprefix . 'ID ' . $from_table . '
						INNER JOIN T_postcats ON ' . $reference_column . ' = postcat_post_ID
						INNER JOIN T_categories ON postcat_cat_ID = cat_ID
						WHERE (' . substr($sub_condition, 0, strlen($sub_condition) - 3) . ')';
        $object_ids = implode(',', $DB->get_col($sub_query));
        if ($object_ids) {
            // If thre is at least one post or comment
            $where_condition .= $condition . '( ' . $dbprefix . 'ID IN (' . $object_ids . ') )';
        }
        return $where_condition;
    }
    if ($filter_by_perm) {
        // filter allowed statuses by the current User perms and by the current page ( front or back office )
        $allowed_statuses_cond = get_allowed_statuses_condition($show_statuses, $dbprefix, $req_blog, $perm_prefix);
        if (!empty($allowed_statuses_cond)) {
            // condition is not empty
            $where[] = $allowed_statuses_cond;
        }
    } elseif (count($show_statuses)) {
        // we are not filtering so all status are allowed, add allowed statuses condition
        $where[] = $dbprefix . 'status IN ( \'' . implode('\',\'', $show_statuses) . '\' )';
    }
    $where = count($where) > 0 ? ' ( ' . implode(' OR ', $where) . ' ) ' : '';
    // echo $where;
    return $where;
}
Exemplo n.º 7
0
    /**
     * Initialize sql query
     *
     * @todo count?
     *
     * @param boolean
     */
    function query_init($force_init = false)
    {
        global $DB;
        if (!$force_init && !empty($this->query_is_initialized)) {
            // Don't initialize query because it was already done
            return;
        }
        // Save to know the query init was done
        $this->query_is_initialized = true;
        if (empty($this->filters)) {
            // Filters have not been set before, we'll use the default filterset:
            // If there is a preset filter, we need to activate its specific defaults:
            $this->filters['filter_preset'] = param($this->param_prefix . 'filter_preset', 'string', $this->default_filters['filter_preset'], true);
            $this->activate_preset_filters();
            // Use the default filters:
            $this->set_filters($this->default_filters);
        }
        // GENERATE THE QUERY:
        /*
         * Resrict to selected blog
         */
        // If we dont have specific comment or post ids, we have to restric to blog
        if (!is_null($this->Blog) && ($this->filters['post_ID'] == NULL || !empty($this->filters['post_ID']) && substr($this->filters['post_ID'], 0, 1) == '-') && ($this->filters['comment_ID'] == NULL || !empty($this->filters['comment_ID']) && substr($this->filters['comment_ID'], 0, 1) == '-') && ($this->filters['comment_ID_list'] == NULL || !empty($this->filters['comment_ID_list']) && substr($this->filters['comment_ID_list'], 0, 1) == '-')) {
            // restriction for blog
            $this->ItemQuery->where_chapter($this->Blog->ID);
        }
        /*
         * filtering stuff:
         */
        $this->CommentQuery->where_author($this->filters['author_IDs']);
        $this->CommentQuery->where_author_email($this->filters['author_email']);
        $this->CommentQuery->where_author_url($this->filters['author_url'], $this->filters['url_match'], $this->filters['include_emptyurl']);
        $this->CommentQuery->where_author_IP($this->filters['author_IP']);
        $this->ItemQuery->where_ID($this->filters['post_ID']);
        $this->CommentQuery->where_ID($this->filters['comment_ID'], $this->filters['author']);
        $this->CommentQuery->where_ID_list($this->filters['comment_ID_list']);
        $this->CommentQuery->where_rating($this->filters['rating_toshow'], $this->filters['rating_turn'], $this->filters['rating_limit']);
        $this->CommentQuery->where_keywords($this->filters['keywords'], $this->filters['phrase'], $this->filters['exact']);
        $this->CommentQuery->where_statuses($this->filters['statuses']);
        $this->CommentQuery->where_types($this->filters['types']);
        $this->ItemQuery->where_datestart('', '', '', '', $this->filters['timestamp_min'], $this->filters['timestamp_max']);
        if (!is_null($this->Blog) && isset($this->filters['user_perm'])) {
            // If Blog and required user permission is set, add the corresponding restriction
            $this->CommentQuery->user_perm_restrict($this->filters['user_perm'], $this->Blog->ID);
        }
        /*
         * ORDER BY stuff:
         */
        $available_sort_options = array('date', 'type', 'author', 'author_url', 'author_email', 'author_IP', 'spam_karma', 'status', 'item_ID');
        $order_by = gen_order_clause($this->filters['orderby'], $this->filters['order'], $this->Cache->dbprefix, $this->Cache->dbIDname, $available_sort_options);
        if ($this->filters['threaded_comments']) {
            // In mode "Threaded comments" we should get all replies in the begining of the list
            $order_by = $this->Cache->dbprefix . 'in_reply_to_cmt_ID DESC, ' . $order_by;
        }
        $this->CommentQuery->order_by($order_by);
        // GET Item IDs, this way we don't have to JOIN two times the items and the categories table into the comment query
        if (isset($this->filters['post_statuses'])) {
            // Set post statuses by filters
            $post_show_statuses = $this->filters['post_statuses'];
        } elseif (is_admin_page()) {
            // Allow all kind of post status ( This statuses will be filtered later by user perms )
            $post_show_statuses = get_visibility_statuses('keys');
        } else {
            // Allow only inskin statuses for posts
            $post_show_statuses = get_inskin_statuses(isset($this->Blog) ? $this->Blog->ID : NULL, 'post');
        }
        // Restrict post filters to available statuses. When blog = 0 we will check visibility statuses for each blog separately ( on the same query ).
        $this->ItemQuery->where_visibility($post_show_statuses);
        $sql_item_IDs = 'SELECT DISTINCT post_ID' . $this->ItemQuery->get_from();
        if (strpos($this->ItemQuery->get_from(), 'T_categories') === false && strpos($this->ItemQuery->get_where(), 'cat_blog_ID') !== false) {
            // Join categories table because it is required here for the field "cat_blog_ID"
            $sql_item_IDs .= ' INNER JOIN T_categories ON post_main_cat_ID = cat_ID ';
        }
        $sql_item_IDs .= $this->ItemQuery->get_where();
        $item_IDs = $DB->get_col($sql_item_IDs, 0, 'Get CommentQuery Item IDs');
        if (empty($item_IDs)) {
            // There is no item which belongs to the given blog and user may view it, so there are no comments either
            parent::count_total_rows(0);
            $this->CommentQuery->WHERE_and('FALSE');
            return;
        }
        $this->CommentQuery->where_post_ID(implode(',', $item_IDs));
        /*
         * Restrict to active comments by default, show expired comments only if it was requested
         * Note: This condition makes the CommentQuery a lot slower!
         */
        $this->CommentQuery->expiry_restrict($this->filters['expiry_statuses']);
        /*
         * GET TOTAL ROW COUNT:
         */
        $sql_count = '
				SELECT COUNT( ' . $this->Cache->dbIDname . ') ' . $this->CommentQuery->get_from() . $this->CommentQuery->get_where();
        parent::count_total_rows($sql_count);
        /*
         * Page set up:
         */
        if ($this->page > 1) {
            // We have requested a specific page number
            if ($this->limit > 0) {
                $pgstrt = '';
                $pgstrt = (intval($this->page) - 1) * $this->limit . ', ';
                $this->CommentQuery->LIMIT($pgstrt . $this->limit);
            }
        } else {
            $this->CommentQuery->LIMIT($this->limit);
        }
    }
Exemplo n.º 8
0
/**
 * Generic comments/trackbacks/pingbacks counting
 *
 * @todo check this in a multiblog page...
 * @todo This should support visibility: at least in the default front office (_feedback.php), there should only the number of visible comments/trackbacks get used ({@link Item::feedback_link()}).
 *
 * @param integer
 * @param string what to count
 * @param mixed string or array to count comments with this/these status(es)
 * @param boolean set true to count expired comments, leave on false otherwise
 */
function generic_ctp_number($post_id, $mode = 'comments', $status = 'published', $count_expired = false, $filter_by_perm = true)
{
    global $DB, $debug, $postdata, $cache_ctp_number, $preview, $servertimenow, $blog;
    if ($preview) {
        // we are in preview mode, no comments yet!
        return 0;
    }
    $show_statuses = is_admin_page() ? get_visibility_statuses('keys', array('trash', 'redirected')) : get_inskin_statuses();
    $filter_index = $filter_by_perm ? 0 : 1;
    if (!isset($cache_ctp_number) || !isset($cache_ctp_number[$filter_index][$post_id])) {
        // we need a query to count comments
        $count_SQL = new SQL();
        $count_SQL->SELECT('comment_post_ID, comment_type, comment_status, COUNT(*) AS type_count');
        $count_SQL->FROM('T_comments');
        $count_SQL->GROUP_BY('comment_post_ID, comment_type, comment_status');
        if (!empty($blog)) {
            $count_SQL->WHERE(statuses_where_clause($show_statuses, 'comment_', $blog, 'blog_comment!', $filter_by_perm));
        }
        if (!$count_expired) {
            $count_SQL->FROM_add('LEFT JOIN T_items__item_settings as expiry_setting ON comment_post_ID = iset_item_ID AND iset_name = "post_expiry_delay"');
            $count_SQL->WHERE_and('expiry_setting.iset_value IS NULL OR expiry_setting.iset_value = "" OR TIMESTAMPDIFF(SECOND, comment_date, ' . $DB->quote(date2mysql($servertimenow)) . ') < expiry_setting.iset_value');
        }
    }
    // init statuses count array
    $statuses_array = array('published' => 0, 'community' => 0, 'protected' => 0, 'private' => 0, 'review' => 0, 'draft' => 0, 'deprecated' => 0, 'trash' => 0, 'total' => 0);
    /*
     * Make sure cache is loaded for current display list:
     */
    if (!isset($cache_ctp_number) || !isset($cache_ctp_number[$filter_index])) {
        global $postIDlist, $postIDarray;
        // if( $debug ) echo "LOADING generic_ctp_number CACHE for posts: $postIDlist<br />";
        if (!empty($postIDlist)) {
            foreach ($postIDarray as $tmp_post_id) {
                // Initializes each post to nocount!
                $cache_ctp_number[$filter_index][$tmp_post_id] = array('comments' => $statuses_array, 'trackbacks' => $statuses_array, 'pingbacks' => $statuses_array, 'feedbacks' => $statuses_array);
            }
            $countall_SQL = $count_SQL;
            $countall_SQL->WHERE_and('comment_post_ID IN (' . $postIDlist . ')');
            foreach ($DB->get_results($countall_SQL->get()) as $row) {
                // detail by status, tyep and post:
                $cache_ctp_number[$filter_index][$row->comment_post_ID][$row->comment_type . 's'][$row->comment_status] = $row->type_count;
                // Total for type on post:
                $cache_ctp_number[$filter_index][$row->comment_post_ID][$row->comment_type . 's']['total'] += $row->type_count;
                // Total for status on post:
                $cache_ctp_number[$filter_index][$row->comment_post_ID]['feedbacks'][$row->comment_status] += $row->type_count;
                // Total for post:
                $cache_ctp_number[$filter_index][$row->comment_post_ID]['feedbacks']['total'] += $row->type_count;
            }
        }
    }
    /*	else
    	{
    		echo "cache set";
    	}*/
    if (!isset($cache_ctp_number[$filter_index][$post_id])) {
        // this should be extremely rare...
        // echo "CACHE not set for $post_id";
        // Initializes post to nocount!
        $cache_ctp_number[$filter_index][intval($post_id)] = array('comments' => $statuses_array, 'trackbacks' => $statuses_array, 'pingbacks' => $statuses_array, 'feedbacks' => $statuses_array);
        $count_SQL->WHERE_and('comment_post_ID = ' . intval($post_id));
        foreach ($DB->get_results($count_SQL->get()) as $row) {
            // detail by status, type and post:
            $cache_ctp_number[$filter_index][$row->comment_post_ID][$row->comment_type . 's'][$row->comment_status] = $row->type_count;
            // Total for type on post:
            $cache_ctp_number[$filter_index][$row->comment_post_ID][$row->comment_type . 's']['total'] += $row->type_count;
            // Total for status on post:
            $cache_ctp_number[$filter_index][$row->comment_post_ID]['feedbacks'][$row->comment_status] += $row->type_count;
            // Total for post:
            $cache_ctp_number[$filter_index][$row->comment_post_ID]['feedbacks']['total'] += $row->type_count;
        }
    }
    if ($mode != 'comments' && $mode != 'trackbacks' && $mode != 'pingbacks') {
        $mode = 'feedbacks';
    }
    if (is_array($status)) {
        // $status is an array and probably contains more then one visibility status
        $result = 0;
        foreach ($status as $one_status) {
            if (isset($cache_ctp_number[$filter_index][$post_id][$mode][$one_status])) {
                $result = $result + $cache_ctp_number[$filter_index][$post_id][$mode][$one_status];
            }
        }
    } elseif (isset($cache_ctp_number[$filter_index][$post_id][$mode][$status])) {
        // $status is a string with one visibility status
        $result = $cache_ctp_number[$filter_index][$post_id][$mode][$status];
    } else {
        // $status is not recognized return total feedback number
        $result = $cache_ctp_number[$filter_index][$post_id][$mode]['total'];
    }
    // pre_dump( $cache_ctp_number[$filter_index][$post_id] );
    return $result;
}
Exemplo n.º 9
0
/**
 * Get # of comments for each category in a blog
 *
 * @param integer Category ID
 * @param integer Blog ID
 */
function get_commentcount_in_category($cat_ID, $blog_ID = NULL)
{
    if (is_null($blog_ID)) {
        global $blog;
        $blog_ID = $blog;
    }
    global $DB, $number_of_comments_in_cat;
    if (!isset($number_of_comments_in_cat[(string) $blog_ID])) {
        global $posttypes_specialtypes;
        $SQL = new SQL();
        $SQL->SELECT('cat_ID, COUNT( comment_ID ) c');
        $SQL->FROM('T_comments');
        $SQL->FROM_add('LEFT JOIN T_postcats ON comment_item_ID = postcat_post_ID');
        $SQL->FROM_add('LEFT JOIN T_categories ON postcat_cat_ID = cat_id');
        $SQL->FROM_add('LEFT JOIN T_items__item ON comment_item_ID = post_id');
        $SQL->WHERE('cat_blog_ID = ' . $DB->quote($blog_ID));
        $SQL->WHERE_and('comment_type IN ( "comment", "trackback", "pingback" )');
        $SQL->WHERE_and(statuses_where_clause(get_inskin_statuses($blog_ID, 'comment'), 'comment_', $blog_ID, 'blog_comment!', true));
        // add where condition to show only those posts commetns which are visible for the current User
        $SQL->WHERE_and(statuses_where_clause(get_inskin_statuses($blog_ID, 'post'), 'post_', $blog_ID, 'blog_post!', true));
        if (!empty($posttypes_specialtypes)) {
            // Get content post types, Exclide pages, intros, sidebar links and ads
            $SQL->WHERE_and('post_ityp_ID NOT IN( ' . $DB->quote($posttypes_specialtypes) . ' )');
        }
        $SQL->GROUP_BY('cat_ID');
        $number_of_comments_in_cat[(string) $blog_ID] = $DB->get_assoc($SQL->get());
    }
    return isset($number_of_comments_in_cat[(string) $blog_ID][$cat_ID]) ? (int) $number_of_comments_in_cat[(string) $blog_ID][$cat_ID] : 0;
}
Exemplo n.º 10
0
 * It is meant to be called by an include in the main.page.php template.
 * To display a feedback, you should call a stub AND pass the right parameters
 * For example: /blogs/index.php?disp=comments
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/gnu-gpl-license}
 * @copyright (c)2003-2015 by Francois Planque - {@link http://fplanque.com/}
 *
 * @package evoskins
 */
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
$CommentList = new CommentList2($Blog);
// Filter list:
$CommentList->set_filters(array('types' => array('comment', 'trackback', 'pingback'), 'statuses' => get_inskin_statuses($Blog->ID, 'comment'), 'order' => 'DESC', 'comments' => 50));
// Get ready for display (runs the query):
$CommentList->display_init();
$CommentList->display_if_empty(array('msg_empty' => T_('No replies yet...')));
if ($CommentList->result_num_rows > 0) {
    ?>
<table id="styled_content_block" class="bForums fixed_layout evo_content_block" width="100%" cellspacing="1" cellpadding="2" border="0">
	<tr>
		<th class="col1"><?php 
    echo T_('Author');
    ?>
</th>
		<th><?php 
    echo T_('Message');
    ?>
</th>
Exemplo n.º 11
0
if ($disp_comments || $disp_trackbacks || $disp_pingbacks) {
    if ($disp_comments) {
    }
    ?>

<!-- Title for comments, tbs, pbs... -->
<h4><?php 
    echo implode(", ", $disp_title);
    ?>
:</h4>

<?php 
    $comments_per_page = !$Blog->get_setting('threaded_comments') ? $Blog->get_setting('comments_per_page') : 1000;
    $CommentList = new CommentList2($Blog, $comments_per_page);
    // Filter list:
    $CommentList->set_filters(array('types' => $type_list, 'statuses' => get_inskin_statuses($Blog->ID, 'comment'), 'post_ID' => $Item->ID, 'order' => $Blog->get_setting('comments_orderdir'), 'threaded_comments' => $Blog->get_setting('threaded_comments')));
    // Get ready for display (runs the query):
    $CommentList->display_init();
    $CommentList->display_if_empty(array('msg_empty' => sprintf(T_('No %s for this post yet...'), implode("/", $disp_title))));
    if ($Blog->get_setting('threaded_comments')) {
        // Array to store the comment replies
        global $CommentReplies;
        $CommentReplies = array();
    }
    while ($Comment =& $CommentList->get_next()) {
        // Loop through comments:
        if ($Blog->get_setting('threaded_comments') && $Comment->in_reply_to_cmt_ID > 0) {
            // Store the replies in a special array
            if (!isset($CommentReplies[$Comment->in_reply_to_cmt_ID])) {
                $CommentReplies[$Comment->in_reply_to_cmt_ID] = array();
            }
Exemplo n.º 12
0
/**
 * Recreate posts autogenerated excerpts
 * Only those posts excerpt will be recreated which are visible in the front office
 *
 * Note: This process can be very very slow if there are many items in the database
 *
 * @param string the url to call if the process needs to be paused becuase of the max execution time
 * @param boolean set true to start from the beginning, false otherwise
 * @param boolean set to true to display recreated/all information or leave it on false to display only dots
 */
function recreate_autogenerated_excerpts($continue_url, $remove_all = true, $detailed_progress_log = false)
{
    global $DB, $localtimenow;
    $start_time = time();
    $max_exec_time = ini_get('max_execution_time');
    $load_limit = 50;
    $progress_log_id = 'progress_log';
    // The timestamp when the process was started
    $process_start_ts = param('start_ts', 'string', $localtimenow);
    // Update only those posts which may be visible in the front office
    $where_condition = '( post_excerpt_autogenerated = 1 OR post_excerpt_autogenerated IS NULL ) AND post_status IN ( \'' . implode('\',\' ', get_inskin_statuses(NULL, 'post')) . '\' )';
    // Update only those posts which were already created when the recreate process was started
    $where_condition .= ' AND post_datecreated < ' . $DB->quote(date2mysql($process_start_ts));
    if ($remove_all) {
        // We are in the beginning of the process and first we set all autogenerated excerpts values to NULL
        if ($detailed_progress_log) {
            // Display detailed progess information
            echo '<span id="' . $progress_log_id . '">' . T_('Clearing autogenerated excerpt values') . '</span>';
            evo_flush();
        }
        // Set all autogenerated excerpt values to NULL
        $query = 'UPDATE T_items__item SET post_excerpt = NULL WHERE ' . $where_condition;
        $DB->query($query, 'Remove all autogenerated excerpts');
        // Count all autogenerated excerpt which value is NULL ( Note: Maybe some of them was already NULL before we have started this process )
        $all_excerpt = $DB->get_var('SELECT count(*) FROM T_items__item WHERE post_excerpt IS NULL AND ' . $where_condition);
        $recreated_excerpts = 0;
    } else {
        // Init params with a previously started process status
        echo '<span id="progress_log"></span>';
        $all_excerpt = param('all_excerpt', 'integer', 0);
        $recreated_excerpts = param('recreated_excerpts', 'integer', 0);
    }
    // Display the current state of the process or a '.' character to indicate the ongoing process
    if ($detailed_progress_log) {
        echo_progress_log_update($progress_log_id, $recreated_excerpts, $all_excerpt);
    } else {
        echo ' .';
    }
    evo_flush();
    $load_SQL = new SQL();
    $load_SQL->SELECT('*');
    $load_SQL->FROM('T_items__item');
    $load_SQL->WHERE($where_condition . ' AND post_excerpt IS NULL');
    $load_SQL->LIMIT($load_limit);
    $ItemCache =& get_ItemCache();
    while (count($ItemCache->load_by_sql($load_SQL)) > 0) {
        // New portion of items was loaded
        $processed_items = 0;
        while (($iterator_Item =& $ItemCache->get_next()) != NULL) {
            // Create new autogenerated excerpt and save it in the database
            $excerpt = $iterator_Item->get_autogenerated_excerpt();
            // Update excerpt without Item->dbupdate() call to make it faster
            $DB->query('UPDATE T_items__item SET post_excerpt = ' . $DB->quote($excerpt) . ' WHERE post_ID = ' . $DB->quote($iterator_Item->ID));
            $processed_items++;
            if ($detailed_progress_log && $processed_items % 3 == 0) {
                // Update progress info after every 3 recreated excerpt when detailed progress log was requested
                echo_progress_log_update($progress_log_id, $recreated_excerpts + $processed_items, $all_excerpt);
                evo_flush();
            }
        }
        // Increase the number recreated excerpts
        $recreated_excerpts += $processed_items;
        // Clear already process items from the cache
        $ItemCache->clear();
        // Display progress log
        if ($detailed_progress_log) {
            echo_progress_log_update($progress_log_id, $recreated_excerpts, $all_excerpt);
        } else {
            echo ' .';
        }
        evo_flush();
        if ($max_exec_time != 0 && $recreated_excerpts < $all_excerpt) {
            // a max execution time limit is set and there are more excerpts to create
            $elapsed_time = time() - $start_time;
            if ($elapsed_time > $max_exec_time - 10) {
                // Increase the time limit in case if less than 10 seconds remained
                $max_exec_time = $max_exec_time + 100;
                if (!set_max_execution_time($max_exec_time)) {
                    $continue_url = url_add_param($continue_url, 'all_excerpt=' . $all_excerpt . '&amp;recreated_excerpts=' . $recreated_excerpts . '&amp;start_ts=' . $process_start_ts, '&amp;');
                    echo '<br />' . 'We are reaching the time limit for this script. Please click <a href="' . $continue_url . '">continue</a>...';
                    evo_flush();
                    exit(0);
                }
            }
        }
    }
    // Check if the recreated exceprts number match with the total number of autogenerated excerpts
    if ($detailed_progress_log && $recreated_excerpts < $all_excerpt) {
        // This means that we are in the end of the process but some post excerpt was updated outside of this process
        // Here we increase the recreated excerpts value because all excerpts were recreated, however some of them not during this process
        echo_progress_log_update($progress_log_id, $all_excerpt, $all_excerpt);
        if ($all_excerpt == $recreated_excerpts + 1) {
            echo '<br />' . T_('Note: One excerpt was re-created in another simultaneous process!');
        } else {
            echo '<br />' . sprintf(T_('Note: %d excerpts were re-created in another simultaneous process!'), $all_excerpt - $recreated_excerpts);
        }
    }
}
Exemplo n.º 13
0
 $edited_Item->dbupdate();
 // post post-publishing operations:
 param('trackback_url', 'string');
 if (!empty($trackback_url)) {
     if ($edited_Item->status != 'published') {
         $Messages->add(T_('Post not publicly published: skipping trackback...'), 'note');
     } else {
         // trackback now:
         load_funcs('comments/_trackback.funcs.php');
         trackbacks($trackback_url, $edited_Item);
     }
 }
 // Execute or schedule notifications & pings:
 $edited_Item->handle_post_processing(false, $exit_after_save);
 $Messages->add(T_('Post has been updated.'), 'success');
 $inskin_statuses = get_inskin_statuses();
 if (!in_array($post_status, $inskin_statuses)) {
     // If post is not published we show it in the Back-office
     $edited_Item->load_Blog();
     if ($post_status == 'redirected') {
         // If a post is in "Redirected" status - redirect to homepage of the blog
         $redirect_to = $edited_Item->Blog->gen_baseurl();
     } else {
         // Redirect to view post in the Back-office
         $redirect_to = url_add_param($admin_url, 'ctrl=items&blog=' . $edited_Item->Blog->ID . '&p=' . $edited_Item->ID, '&');
     }
 } else {
     // User can see this post in the Front-office
     if ($edited_Item->ptyp_ID == 1520) {
         // If post is category intro we should redirect to page of that category
         $main_Chapter =& $edited_Item->get_main_Chapter();
Exemplo n.º 14
0
 $edited_Item->dbupdate();
 // post post-publishing operations:
 param('trackback_url', 'string');
 if (!empty($trackback_url)) {
     if ($edited_Item->status != 'published') {
         $Messages->add(T_('Post not publicly published: skipping trackback...'), 'note');
     } else {
         // trackback now:
         load_funcs('comments/_trackback.funcs.php');
         trackbacks($trackback_url, $edited_Item);
     }
 }
 // Execute or schedule notifications & pings:
 $edited_Item->handle_post_processing(false, $exit_after_save);
 $Messages->add(T_('Post has been updated.'), 'success');
 $inskin_statuses = get_inskin_statuses($edited_Item->get_blog_ID(), 'post');
 if (!in_array($post_status, $inskin_statuses)) {
     // If post is not published we show it in the Back-office
     $edited_Item->load_Blog();
     if ($post_status == 'redirected') {
         // If a post is in "Redirected" status - redirect to homepage of the blog
         $redirect_to = $edited_Item->Blog->gen_baseurl();
     } else {
         // Redirect to view post in the Back-office
         $redirect_to = url_add_param($admin_url, 'ctrl=items&blog=' . $edited_Item->Blog->ID . '&p=' . $edited_Item->ID, '&');
     }
 } else {
     // User can see this post in the Front-office
     if ($edited_Item->ityp_ID == 1520) {
         // If post is category intro we should redirect to page of that category
         $main_Chapter =& $edited_Item->get_main_Chapter();
Exemplo n.º 15
0
/**
 * Get # of comments for each category in a blog
 *
 * @param integer Category ID
 * @param integer Blog ID
 */
function get_commentcount_in_category($cat_ID, $blog_ID = NULL)
{
    if (is_null($blog_ID)) {
        global $blog;
        $blog_ID = $blog;
    }
    global $DB, $number_of_comments_in_cat;
    if (!isset($number_of_comments_in_cat[(string) $blog_ID])) {
        $SQL = new SQL();
        $SQL->SELECT('cat_ID, COUNT( comment_ID ) c');
        $SQL->FROM('T_comments');
        $SQL->FROM_add('LEFT JOIN T_postcats ON comment_post_ID = postcat_post_ID');
        $SQL->FROM_add('LEFT JOIN T_categories ON postcat_cat_ID = cat_id');
        $SQL->FROM_add('LEFT JOIN T_items__item ON comment_post_ID = post_id');
        $SQL->WHERE('cat_blog_ID = ' . $DB->quote($blog_ID));
        $SQL->WHERE_and(statuses_where_clause(get_inskin_statuses(), 'comment_', $blog_ID, 'blog_comment!', true));
        // add where condition to show only those posts commetns which are visible for the current User
        $SQL->WHERE_and(statuses_where_clause(get_inskin_statuses(), 'post_', $blog_ID, 'blog_post!', true));
        $SQL->GROUP_BY('cat_ID');
        $number_of_comments_in_cat[(string) $blog_ID] = $DB->get_assoc($SQL->get());
    }
    return isset($number_of_comments_in_cat[(string) $blog_ID][$cat_ID]) ? (int) $number_of_comments_in_cat[(string) $blog_ID][$cat_ID] : 0;
}
Exemplo n.º 16
0
 */
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
// Default params:
$params = array_merge(array('display_column_forum' => false, 'post_navigation' => 'same_category'), $params);
global $Item;
/**
 * @var array Save all statuses that used on this page in order to show them in the footer legend
 */
global $legend_statuses;
if (!is_array($legend_statuses)) {
    // Init this array only first time
    $legend_statuses = array();
}
$comments_number = generic_ctp_number($Item->ID, 'comments', get_inskin_statuses());
$status_icon = 'topic';
$status_title = '';
$status_alt = T_('No new posts');
if ($Item->is_featured() || $Item->is_intro()) {
    // Special icon for featured & intro posts
    $status_icon = 'topicSticky';
    $status_title = '<strong>' . T_('Sticky') . ':</strong> ';
} elseif ($Item->comment_status == 'closed' || $Item->comment_status == 'disabled' || $Item->is_locked()) {
    // The post is closed for comments
    $status_icon = 'topicLocked';
    $status_alt = T_('This topic is locked: you cannot edit posts or make replies.');
} elseif ($comments_number > 25) {
    // Popular topic
    $status_icon = 'folder_hot.gif';
}