Example #1
0
/**
 * wp.getPageList
 *
 * @see http://codex.wordpress.org/XML-RPC_wp#wp.getPageList
 *
 * @param xmlrpcmsg XML-RPC Message
 *					0 blogid (int): Unique identifier of the blog.
 *					1 username (string): User login.
 *					2 password (string): Password for said username.
 */
function wp_getpagelist($m)
{
    // CHECK LOGIN:
    /**
     * @var User
     */
    if (!($current_User =& xmlrpcs_login($m, 1, 2))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    // GET BLOG:
    /**
     * @var Blog
     */
    if (!($Blog =& xmlrpcs_get_Blog($m, 0))) {
        // Login failed, return (last) error:
        return xmlrpcs_resperror();
    }
    // Get the pages to display:
    load_class('items/model/_itemlistlight.class.php', 'ItemListLight');
    $MainList = new ItemListLight($Blog, NULL, NULL, 0);
    // Protected and private get checked by statuses_where_clause().
    $statuses = array('published', 'redirected', 'protected', 'private');
    if ($current_User->check_perm('blog_ismember', 'view', false, $Blog->ID)) {
        // These statuses require member status:
        $statuses = array_merge($statuses, array('draft', 'deprecated'));
    }
    logIO('Statuses: ' . implode(', ', $statuses));
    $MainList->set_filters(array('visibility_array' => $statuses, 'order' => 'DESC', 'unit' => 'posts', 'types' => '1000'));
    // Run the query:
    $MainList->query();
    logIO('Items:' . $MainList->result_num_rows);
    $data = array();
    while ($Item =& $MainList->get_item()) {
        logIO('Item:' . $Item->title . ' - Issued: ' . $Item->issue_date . ' - Modified: ' . $Item->datemodified);
        $data[] = new xmlrpcval(array('page_id' => new xmlrpcval($Item->ID, 'int'), 'page_title' => new xmlrpcval($Item->title), 'page_parent_id' => new xmlrpcval(isset($Item->parent_ID) ? $Item->parent_ID : 0, 'int'), 'dateCreated' => new xmlrpcval(datetime_to_iso8601($Item->issue_date), 'dateTime.iso8601'), 'date_created_gmt' => new xmlrpcval(datetime_to_iso8601($Item->issue_date, true), 'dateTime.iso8601')), 'struct');
    }
    logIO('OK.');
    return new xmlrpcresp(new xmlrpcval($data, 'array'));
}
 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     /**
      * @var ItemList2
      */
     global $MainList;
     global $BlogCache, $Blog;
     global $Item, $Settings;
     $this->init_display($params);
     $blog_ID = intval($this->disp_params['blog_ID']);
     $listBlog = $blog_ID ? $BlogCache->get_by_ID($blog_ID, false) : $Blog;
     if (empty($listBlog)) {
         echo $this->disp_params['block_start'];
         echo $this->disp_params['block_body_start'];
         echo T_('The requested Blog doesn\'t exist any more!');
         echo $this->disp_params['block_body_end'];
         echo $this->disp_params['block_end'];
         return;
     }
     // Define default template params that can be rewritten by skin
     $this->disp_params = array_merge(array('item_first_image_before' => '<div class="item_first_image">', 'item_first_image_after' => '</div>', 'item_first_image_placeholder' => '<div class="item_first_image_placeholder"><a href="$item_permaurl$"></a></div>', 'item_title_before' => '<div class="item_title">', 'item_title_after' => '</div>', 'item_title_single_before' => '', 'item_title_single_after' => '', 'item_excerpt_before' => '<div class="item_excerpt">', 'item_excerpt_after' => '</div>', 'item_content_before' => '<div class="item_content">', 'item_content_after' => '</div>', 'item_images_before' => '<div class="item_images">', 'item_images_after' => '</div>'), $this->disp_params);
     // Create ItemList
     // Note: we pass a widget specific prefix in order to make sure to never interfere with the mainlist
     $limit = intval($this->disp_params['limit']);
     if ($this->disp_params['disp_teaser']) {
         // We want to show some of the post content, we need to load more info: use ItemList2
         $ItemList = new ItemList2($listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCache', $this->code . '_');
     } else {
         // no excerpts, use ItemListLight
         load_class('items/model/_itemlistlight.class.php', 'ItemListLight');
         $ItemList = new ItemListLight($listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCacheLight', $this->code . '_');
     }
     $cat_array = sanitize_id_list($this->disp_params['cat_IDs'], true);
     // Filter list:
     $filters = array('cat_array' => $cat_array, 'orderby' => $this->disp_params['order_by'], 'order' => $this->disp_params['order_dir'], 'unit' => 'posts', 'coll_IDs' => $this->disp_params['blog_ID']);
     if ($this->disp_params['item_visibility'] == 'public') {
         // Get only the public items
         $filters['visibility_array'] = array('published');
     }
     if (isset($this->disp_params['page'])) {
         $filters['page'] = $this->disp_params['page'];
     }
     if ($this->disp_params['item_type'] != '#') {
         // Not "default", restrict to a specific type (or '' for all)
         $filters['types'] = $this->disp_params['item_type'];
     }
     if ($this->disp_params['follow_mainlist'] == 'tags') {
         // Restrict to Item tagged with some tag used in the Mainlist:
         if (!isset($MainList)) {
             // Nothing to follow, don't display anything
             return false;
         }
         $all_tags = $MainList->get_all_tags();
         if (empty($all_tags)) {
             // Nothing to follow, don't display anything
             return false;
         }
         $filters['tags'] = implode(',', $all_tags);
         if (!empty($Item)) {
             // Exclude current Item
             $filters['post_ID'] = '-' . $Item->ID;
         }
         // fp> TODO: in addition to just filtering, offer ordering in a way where the posts with the most matching tags come first
     }
     $chapter_mode = false;
     if ($this->disp_params['item_group_by'] == 'chapter') {
         // Group by chapter:
         $chapter_mode = true;
         # This is the list of categories to restrict the linkblog to (cats will be displayed recursively)
         # Example: $linkblog_cat = '4,6,7';
         $linkblog_cat = '';
         # This is the array if categories to restrict the linkblog to (non recursive)
         # Example: $linkblog_catsel = array( 4, 6, 7 );
         $linkblog_catsel = array();
         // $cat_array;
         // Compile cat array stuff:
         $linkblog_cat_array = array();
         $linkblog_cat_modifier = '';
         compile_cat_array($linkblog_cat, $linkblog_catsel, $linkblog_cat_array, $linkblog_cat_modifier, $listBlog->ID);
         $filters['cat_array'] = $linkblog_cat_array;
         $filters['cat_modifier'] = $linkblog_cat_modifier;
     }
     $ItemList->set_filters($filters, false);
     // we don't want to memorize these params
     // Run the query:
     $ItemList->query();
     if (!$ItemList->result_num_rows) {
         // Nothing to display:
         return;
     }
     // Check if the widget displays only single title
     $this->disp_params['disp_only_title'] = !($this->disp_params['attached_pics'] != 'none' || $this->disp_params['disp_excerpt'] || $this->disp_params['disp_teaser']);
     // Start to capture display content here in order to solve the issue to don't display empty widget
     ob_start();
     // This variable used to display widget. Will be set to true when content is displayed
     $content_is_displayed = false;
     // Get extra classes depending on widget settings:
     $block_css_class = $this->get_widget_extra_class();
     if (empty($block_css_class)) {
         // No extra class, Display default wrapper:
         echo $this->disp_params['block_start'];
     } else {
         // Append extra classes for widget block:
         echo preg_replace('/ class="([^"]+)"/', ' class="$1' . $block_css_class . '"', $this->disp_params['block_start']);
     }
     $title = sprintf($this->disp_params['title_link'] ? '<a href="' . $listBlog->gen_blogurl() . '" rel="nofollow">%s</a>' : '%s', $this->disp_params['title']);
     $this->disp_title($title);
     echo $this->disp_params['block_body_start'];
     if ($chapter_mode) {
         // List grouped by chapter/category:
         $items_map_by_chapter = array();
         $chapters_of_loaded_items = array();
         $group_by_blogs = false;
         $prev_chapter_blog_ID = NULL;
         while ($iterator_Item =& $ItemList->get_item()) {
             // Display contents of the Item depending on widget params:
             $Chapter =& $iterator_Item->get_main_Chapter();
             if (!isset($items_map_by_chapter[$Chapter->ID])) {
                 $items_map_by_chapter[$Chapter->ID] = array();
                 $chapters_of_loaded_items[] = $Chapter;
             }
             $items_map_by_chapter[$Chapter->ID][] = $iterator_Item;
             // Group by blogs if there are chapters from multiple blogs
             if (!$group_by_blogs && $Chapter->blog_ID != $prev_chapter_blog_ID) {
                 // group by blogs is not decided yet
                 $group_by_blogs = $prev_chapter_blog_ID != NULL;
                 $prev_chapter_blog_ID = $Chapter->blog_ID;
             }
         }
         usort($chapters_of_loaded_items, 'Chapter::compare_chapters');
         $displayed_blog_ID = NULL;
         if ($group_by_blogs && isset($this->disp_params['collist_start'])) {
             // Start list of blogs
             echo $this->disp_params['collist_start'];
         } else {
             // Display list start, all chapters are in the same group ( not grouped by blogs )
             echo $this->disp_params['list_start'];
         }
         foreach ($chapters_of_loaded_items as $Chapter) {
             if ($group_by_blogs && $displayed_blog_ID != $Chapter->blog_ID) {
                 $Chapter->get_Blog();
                 if ($displayed_blog_ID != NULL) {
                     // Display the end of the previous blog's chapter list
                     echo $this->disp_params['list_end'];
                 }
                 echo $this->disp_params['coll_start'] . $Chapter->Blog->get('shortname') . $this->disp_params['coll_end'];
                 // Display start of blog's chapter list
                 echo $this->disp_params['list_start'];
                 $displayed_blog_ID = $Chapter->blog_ID;
             }
             $content_is_displayed = $this->disp_chapter($Chapter, $items_map_by_chapter) || $content_is_displayed;
         }
         if ($content_is_displayed) {
             // End of a chapter list - if some content was displayed this is always required
             echo $this->disp_params['list_end'];
         }
         if ($group_by_blogs && isset($this->disp_params['collist_end'])) {
             // End of blog list
             echo $this->disp_params['collist_end'];
         }
     } else {
         // Plain list:
         echo $this->disp_params['list_start'];
         /**
          * @var ItemLight (or Item)
          */
         while ($Item =& $ItemList->get_item()) {
             // Display contents of the Item depending on widget params:
             $content_is_displayed = $this->disp_contents($Item) || $content_is_displayed;
         }
         if (isset($this->disp_params['page'])) {
             if (empty($this->disp_params['pagination'])) {
                 $this->disp_params['pagination'] = array();
             }
             $ItemList->page_links($this->disp_params['pagination']);
         }
         echo $this->disp_params['list_end'];
     }
     echo $this->disp_params['block_body_end'];
     echo $this->disp_params['block_end'];
     if ($content_is_displayed) {
         // Some content is displayed, Print out widget
         ob_end_flush();
     } else {
         // No content, Don't display widget
         ob_end_clean();
     }
 }
Example #3
0
 /**
  * If the list is sorted by category...
  *
  * This is basically just a stub for backward compatibility
  */
 function &get_item()
 {
     if ($this->group_by_cat == 1) {
         // This is the first call to get_item() after get_category_group()
         $this->group_by_cat = 2;
         // Return the object we already got in get_category_group():
         return $this->current_Obj;
     }
     $Item =& parent::get_next();
     if (!empty($Item) && $this->group_by_cat == 2 && $Item->main_cat_ID != $this->main_cat_ID) {
         // We have just hit a new category!
         $this->group_by_cat == 0;
         // For info only.
         $r = false;
         return $r;
     }
     //pre_dump( $Item );
     return $Item;
 }
Example #4
0
 *
 * For a quick explanation of b2evo 2.0 skins, please start here:
 * {@link http://b2evolution.net/man/skin-structure}
 *
 * @package evoskins
 * @subpackage rss
 *
 * @version $Id: index.main.php 3157 2013-03-06 04:34:44Z fplanque $
 */
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
$Timer->resume('prepare list');
load_class('/items/model/_itemlistlight.class.php', 'ItemListLight');
// Use a LIGHT Item List:  (Sitemap = 50000 entries max)
$MainList = new ItemListLight($Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), 50000);
// By default we only want items that have the MAIN cat in this blog,
// i-e with its canonical URL in this blog (cross posted stuff will be listed in its main blog)
// However this may be overriden in a stub (or param)
param('cat_focus', 'string', 'main');
// Filter list:
$MainList->set_filters(array('visibility_array' => array('published'), 'types' => '-' . implode(',', $posttypes_nopermanentURL), 'unit' => 'all', 'cat_focus' => $cat_focus));
// pre_dump( $cat_focus, $MainList->filters );
// Run the query:
$MainList->query();
// Old style globals for category.funcs:
// TODO: dh> check if still required.
$postIDlist = $MainList->get_page_ID_list();
$postIDarray = $MainList->get_page_ID_array();
$Timer->stop('prepare list');
$Timer->resume('display list');
 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     /**
      * @var ItemList2
      */
     global $MainList;
     global $BlogCache, $Blog;
     global $Item;
     $this->init_display($params);
     if ($this->disp_params['order_by'] == 'RAND' && isset($this->BlockCache)) {
         // Do NOT cache if display order is random
         $this->BlockCache->abort_collect();
     }
     $listBlog = $this->disp_params['blog_ID'] ? $BlogCache->get_by_ID($this->disp_params['blog_ID'], false) : $Blog;
     if (empty($listBlog)) {
         echo $this->disp_params['block_start'];
         echo T_('The requested Blog doesn\'t exist any more!');
         echo $this->disp_params['block_end'];
         return;
     }
     // Create ItemList
     // Note: we pass a widget specific prefix in order to make sure to never interfere with the mainlist
     $limit = $this->disp_params['limit'];
     if ($this->disp_params['disp_teaser']) {
         // We want to show some of the post content, we need to load more info: use ItemList2
         $ItemList = new ItemList2($listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCache', $this->code . '_');
     } else {
         // no excerpts, use ItemListLight
         load_class('items/model/_itemlistlight.class.php', 'ItemListLight');
         $ItemList = new ItemListLight($listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCacheLight', $this->code . '_');
     }
     //$cat_array = sanitize_id_list($this->disp_params['cat_IDs'], true);
     // Filter list:
     $filters = array('orderby' => $this->disp_params['order_by'], 'order' => $this->disp_params['order_dir'], 'unit' => 'posts');
     if (isset($this->disp_params['page'])) {
         $filters['page'] = $this->disp_params['page'];
     }
     if ($this->disp_params['item_type'] != '#') {
         // Not "default", restrict to a specific type (or '' for all)
         $filters['types'] = $this->disp_params['item_type'];
     }
     if ($this->disp_params['follow_mainlist'] == 'tags') {
         // Restrict to Item tagged with some tag used in the Mainlist:
         if (!isset($MainList)) {
             // Nothing to follow, don't display anything
             return false;
         }
         $all_tags = $MainList->get_all_tags();
         if (empty($all_tags)) {
             // Nothing to follow, don't display anything
             return false;
         }
         $filters['tags'] = implode(',', $all_tags);
         if (!empty($Item)) {
             // Exclude current Item
             $filters['post_ID'] = '-' . $Item->ID;
         }
         // fp> TODO: in addition to just filtering, offer ordering in a way where the posts with the most matching tags come first
     }
     $chapter_mode = false;
     if ($this->disp_params['item_group_by'] == 'chapter') {
         // Group by chapter:
         $chapter_mode = true;
         # This is the list of categories to restrict the linkblog to (cats will be displayed recursively)
         # Example: $linkblog_cat = '4,6,7';
         $linkblog_cat = '';
         # This is the array if categories to restrict the linkblog to (non recursive)
         # Example: $linkblog_catsel = array( 4, 6, 7 );
         $linkblog_catsel = array();
         // $cat_array;
         // Compile cat array stuff:
         $linkblog_cat_array = array();
         $linkblog_cat_modifier = '';
         compile_cat_array($linkblog_cat, $linkblog_catsel, $linkblog_cat_array, $linkblog_cat_modifier, $listBlog->ID);
         $filters['cat_array'] = $linkblog_cat_array;
         $filters['cat_modifier'] = $linkblog_cat_modifier;
         $filters['orderby'] = 'main_cat_ID ' . $filters['orderby'];
     }
     $ItemList->set_filters($filters, false);
     // we don't want to memorize these params
     // Run the query:
     $ItemList->query();
     if (!$ItemList->result_num_rows) {
         // Nothing to display:
         return;
     }
     // Start to capture display content here in order to solve the issue to don't display empty widget
     ob_start();
     // This variable used to display widget. Will be set to true when content is displayed
     $content_is_displayed = false;
     if (!$this->disp_params['disp_title'] && in_array($this->disp_params['attached_pics'], array('first', 'all'))) {
         // Don't display bullets when we show only the pictures
         $block_css_class = 'nobullets';
     }
     if (empty($block_css_class)) {
         echo $this->disp_params['block_start'];
     } else {
         // Additional class for widget block
         echo preg_replace('/ class="([^"]+)"/', ' class="$1 ' . $block_css_class . '"', $this->disp_params['block_start']);
     }
     $title = sprintf($this->disp_params['title_link'] ? '<a href="' . $listBlog->gen_blogurl() . '" rel="nofollow">%s</a>' : '%s', $this->disp_params['title']);
     $this->disp_title($title);
     echo $this->disp_params['list_start'];
     if ($chapter_mode) {
         // List grouped by chapter/category:
         /**
          * @var ItemLight (or Item)
          */
         while ($Item =& $ItemList->get_category_group()) {
             // Open new cat:
             $Chapter =& $Item->get_main_Chapter();
             echo $this->disp_params['item_start'];
             echo '<a href="' . $Chapter->get_permanent_url() . '">' . $Chapter->get('name') . '</a>';
             echo $this->disp_params['group_start'];
             while ($Item =& $ItemList->get_item()) {
                 // Display contents of the Item depending on widget params:
                 $content_is_displayed = $this->disp_contents($Item) || $content_is_displayed;
             }
             // Close cat
             echo $this->disp_params['group_end'];
             echo $this->disp_params['item_end'];
         }
     } else {
         // Plain list:
         /**
          * @var ItemLight (or Item)
          */
         while ($Item =& $ItemList->get_item()) {
             // Display contents of the Item depending on widget params:
             $content_is_displayed = $this->disp_contents($Item) || $content_is_displayed;
         }
     }
     if (isset($this->disp_params['page'])) {
         $ItemList->page_links();
     }
     echo $this->disp_params['list_end'];
     echo $this->disp_params['block_end'];
     if ($content_is_displayed) {
         // Some content is displayed, Print out widget
         ob_end_flush();
     } else {
         // No content, Don't display widget
         ob_end_clean();
     }
 }
Example #6
0
    /**
     * Constructor
     *
     * Note: Weekly archives use MySQL's week numbering and MySQL default if applicable.
     * In MySQL < 4.0.14, WEEK() always uses mode 0: Week starts on Sunday;
     * Value range is 0 to 53; week 1 is the first week that starts in this year.
     *
     * @link http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
     *
     * @todo categories combined with 'ALL' are not supported (will output too many archives,
     * some of which will resolve to no results). We need subqueries to support this efficiently.
     *
     * @param string
     * @param integer
     * @param boolean
     */
    function ArchiveList($archive_mode = 'monthly', $limit = 100, $sort_order = 'date', $preserve_context = false, $dbtable = 'T_items__item', $dbprefix = 'post_', $dbIDname = 'ID')
    {
        global $DB;
        global $blog, $cat, $catsel;
        global $Blog;
        global $show_statuses;
        global $author, $assgn, $status, $types;
        global $s, $sentence, $exact;
        global $posttypes_specialtypes;
        $this->dbtable = $dbtable;
        $this->dbprefix = $dbprefix;
        $this->dbIDname = $dbIDname;
        $this->archive_mode = $archive_mode;
        /*
         * WE ARE GOING TO CONSTRUCT THE WHERE CLOSE...
         */
        $this->ItemQuery = new ItemQuery($this->dbtable, $this->dbprefix, $this->dbIDname);
        // TEMPORARY OBJ
        // - - Select a specific Item:
        // $this->ItemQuery->where_ID( $p, $title );
        if (is_admin_page()) {
            // Don't restrict by date in the Back-office
            $timestamp_min = NULL;
            $timestamp_max = NULL;
        } else {
            // Restrict posts by date started
            $timestamp_min = $Blog->get_timestamp_min();
            $timestamp_max = $Blog->get_timestamp_max();
        }
        if ($preserve_context) {
            // We want to preserve the current context:
            // * - - Restrict to selected blog/categories:
            $this->ItemQuery->where_chapter($blog, $cat, $catsel);
            // * Restrict to the statuses we want to show:
            $this->ItemQuery->where_visibility($show_statuses);
            // Restrict to selected authors:
            $this->ItemQuery->where_author($author);
            // Restrict to selected assignees:
            $this->ItemQuery->where_assignees($assgn);
            // Restrict to selected satuses:
            $this->ItemQuery->where_statuses($status);
            // - - - + * * timestamp restrictions:
            $this->ItemQuery->where_datestart('', '', '', '', $timestamp_min, $timestamp_max);
            // Keyword search stuff:
            $this->ItemQuery->where_keywords($s, $sentence, $exact);
            $this->ItemQuery->where_types($types);
        } else {
            // We want to preserve only the minimal context:
            // * - - Restrict to selected blog/categories:
            $this->ItemQuery->where_chapter($blog, '', array());
            // * Restrict to the statuses we want to show:
            $this->ItemQuery->where_visibility($show_statuses);
            // - - - + * * timestamp restrictions:
            $this->ItemQuery->where_datestart('', '', '', '', $timestamp_min, $timestamp_max);
            // Include all types except pages, intros and sidebar links:
            $this->ItemQuery->where_types('-' . implode(',', $posttypes_specialtypes));
        }
        $this->from = $this->ItemQuery->get_from();
        $this->where = $this->ItemQuery->get_where();
        $this->group_by = $this->ItemQuery->get_group_by();
        switch ($this->archive_mode) {
            case 'monthly':
                // ------------------------------ MONTHLY ARCHIVES ------------------------------------
                $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) AS month,
																	COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . '
													GROUP BY year, month
													ORDER BY year DESC, month DESC';
                break;
            case 'daily':
                // ------------------------------- DAILY ARCHIVES -------------------------------------
                $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, MONTH(' . $this->dbprefix . 'datestart) AS month,
																	DAYOFMONTH(' . $this->dbprefix . 'datestart) AS day,
																	COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . '
													GROUP BY year, month, day
													ORDER BY year DESC, month DESC, day DESC';
                break;
            case 'weekly':
                // ------------------------------- WEEKLY ARCHIVES -------------------------------------
                $sql = 'SELECT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) AS year, ' . $DB->week($this->dbprefix . 'datestart', locale_startofweek()) . ' AS week,
															COUNT(DISTINCT postcat_post_ID) AS count ' . $this->from . $this->where . '
													GROUP BY year, week
													ORDER BY year DESC, week DESC';
                break;
            case 'postbypost':
            default:
                // ----------------------------- POSY BY POST ARCHIVES --------------------------------
                $this->count_total_rows();
                $archives_list = new ItemListLight($Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), $this->total_rows);
                $archives_list->set_filters(array('visibility_array' => array('published'), 'types' => '-' . implode(',', $posttypes_specialtypes)));
                if ($sort_order == 'title') {
                    $archives_list->set_filters(array('orderby' => 'title', 'order' => 'ASC'));
                }
                $archives_list->query();
                $this->rows = array();
                while ($Item = $archives_list->get_item()) {
                    $this->rows[] = $Item;
                }
                $this->result_num_rows = $archives_list->result_num_rows;
                $this->current_idx = 0;
                $this->arc_w_last = '';
                return;
        }
        // dh> Temp fix for MySQL bug - apparently in/around 4.1.21/5.0.24.
        // See http://forums.b2evolution.net/viewtopic.php?p=42529#42529
        if (in_array($this->archive_mode, array('monthly', 'daily', 'weekly'))) {
            $sql_version = $DB->get_version();
            if (version_compare($sql_version, '4', '>')) {
                $sql = 'SELECT SQL_CALC_FOUND_ROWS ' . substr($sql, 7);
                // "SQL_CALC_FOUND_ROWS" available since MySQL 4
            }
        }
        parent::Results($sql, 'archivelist_', '', $limit);
        $this->restart();
    }
Example #7
0
/**
 * Generate fake hit statistics
 *
 * @param integer the number of days to generate statistics
 * @param integer min interval between hits in seconds
 * @param integer max interval between hits in seconds
 * @param boolean TRUE to display the process dots during generating of the hits
 * @return integer count of inserted hits
 */
function generate_hit_stat($days, $min_interval, $max_interval, $display_process = false)
{
    global $baseurlroot, $admin_url, $user_agents, $DB;
    load_class('items/model/_itemlistlight.class.php', 'ItemListLight');
    load_class('sessions/model/_hit.class.php', 'Hit');
    $links = array();
    $BlogCache =& get_BlogCache();
    $blogs_id = $BlogCache->load_public();
    foreach ($blogs_id as $blog_id) {
        // handle all public blogs
        $listBlog =& $BlogCache->get_by_ID($blog_id);
        if (empty($listBlog)) {
            continue;
        }
        $ItemList = new ItemListLight($listBlog);
        $filters = array();
        # This is the list of categories to restrict the linkblog to (cats will be displayed recursively)
        # Example: $linkblog_cat = '4,6,7';
        $linkblog_cat = '';
        # This is the array if categories to restrict the linkblog to (non recursive)
        # Example: $linkblog_catsel = array( 4, 6, 7 );
        $linkblog_catsel = array();
        // $cat_array;
        // Compile cat array stuff:
        $linkblog_cat_array = array();
        $linkblog_cat_modifier = '';
        compile_cat_array($linkblog_cat, $linkblog_catsel, $linkblog_cat_array, $linkblog_cat_modifier, $listBlog->ID);
        $filters['cat_array'] = $linkblog_cat_array;
        $filters['cat_modifier'] = $linkblog_cat_modifier;
        $ItemList->set_default_filters($filters);
        // Get the items list of current blog
        $ItemList->query();
        if (!$ItemList->result_num_rows) {
            // Nothing to display:
            continue;
        }
        while ($Item =& $ItemList->get_category_group()) {
            // Open new cat:
            $Chapter =& $Item->get_main_Chapter();
            while ($Item =& $ItemList->get_item()) {
                $links[] = array('link' => '/' . $listBlog->siteurl . '/' . $Chapter->get_url_path() . $Item->urltitle, 'blog_id' => $blog_id);
            }
        }
        // add search links for all blogs
        $links[] = array('link' => url_add_param('/' . $listBlog->siteurl, 's=$keywords$&disp=search&submit=Search', '&'), 'blog_id' => $blog_id);
        $links[] = array('link' => url_add_param('/' . $listBlog->siteurl, 'disp=users', '&'), 'blog_id' => $blog_id, 'disp' => 'users');
        $links[] = array('link' => url_add_param('/' . $listBlog->siteurl, 'disp=user&user_ID=1', '&'), 'blog_id' => $blog_id, 'disp' => 'users');
        $links[] = array('link' => url_add_param('/' . $listBlog->siteurl, 'disp=threads', '&'), 'blog_id' => $blog_id, 'disp' => 'threads');
        $links[] = array('link' => url_add_param('/' . $listBlog->siteurl, 'disp=profile', '&'), 'blog_id' => $blog_id, 'disp' => 'profile');
    }
    $referes = array('http://www.fake-referer1.com', 'http://www.fake-referer2.com', 'http://www.fake-referer3.com', 'http://www.fake-referer4.com', 'http://www.fake-referer5.com', 'http://www.fake-referer6.com', 'http://www.fake-referer7.com', 'http://www.fake-referer8.com', 'http://www.fake-referer9.com', 'http://www.mail.google.com/fake/referer', 'http://www.webmail.aol.com/fake/referer', 'http://www.mail.yahoo.com/fake/referer', 'http://bloglines.com/fake/referer', 'http://www.fake-refer-online-casino1.com', 'http://www.fake-refer-online-casino2.com', 'http://www.fake-refer-online-casino3.com', 'http://www.google.com/url?sa=t&rct=j&q=$keywords$&source=web&cd=4', 'http://www.bing.com/search?q=$keywords$&src=IE-SearchBox&FORM=IE8SRC');
    $devices = array('iphone', 'ipad', 'andrtab', 'android', 'berrytab', 'blkberry', 'winphone', 'wince', 'palm', 'gendvice');
    $robots = array();
    foreach ($user_agents as $lUserAgent) {
        if ($lUserAgent[0] == 'robot') {
            $robots[] = $lUserAgent[1];
        }
    }
    $robots_count = count($robots) - 1;
    $ref_count = count($referes) - 1;
    $admin_link = array('link' => $admin_url, 'blog_id' => NULL);
    $links_count = count($links);
    if (empty($links_count)) {
        $Messages->add('Do not have blog links to generate statistics');
        break;
    }
    // generate users id array
    $users_array = $DB->get_results('
					SELECT user_ID
					  FROM T_users
					  WHERE user_status = "activated" OR user_status= "autoactivated"
					  LIMIT 10', 'ARRAY_A');
    $users_count = count($users_array);
    $devices_count = count($devices);
    if (empty($users_count)) {
        $Messages->add('Do not have valid users to generate statistics');
        break;
    }
    // Calculate the period of testing
    $cur_time = time();
    $past_time = mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $days, date("Y"));
    $insert_data = '';
    $insert_data_count = 0;
    // create session array for testing
    $sessions = array();
    mt_srand(crc32(microtime()));
    for ($i = 0; $i <= $users_count - 1; $i++) {
        $sessions[] = array('sess_ID' => -1, 'sess_key' => generate_random_key(32), 'sess_start_ts' => 0, 'sess_lastseen_ts' => 0, 'sess_ipaddress' => generate_random_ip(), 'sess_user_ID' => $users_array[$i]['user_ID'], 'sess_device' => $devices[mt_rand(0, $devices_count - 1)], 'pervios_link' => '', 'robot' => '');
    }
    // main cycle of generation
    //mt_srand(crc32(microtime()));
    for ($time_shift = $past_time; $cur_time > $time_shift; $time_shift += mt_rand($min_interval, $max_interval)) {
        //mt_srand(crc32(microtime()));
        $insert_data_count = $insert_data_count + 1;
        $rand_i = mt_rand(0, $users_count - 1);
        $rand_link = mt_rand(0, $links_count - 1);
        $cur_seesion = $sessions[$rand_i];
        if (strstr($links[$rand_link]['link'], '$keywords$')) {
            // check if the current search link is selected randomly.
            // If yes, generate search link and add it to DB
            //mt_srand(crc32(microtime()+ $time_shift));
            $keywords = 'fake search ' . mt_rand(0, 9);
            $links[$rand_link]['link'] = str_replace('$keywords$', urlencode($keywords), $links[$rand_link]['link']);
            if (strstr($links[$rand_link]['link'], 's=')) {
                $links[$rand_link]['s'] = $keywords;
            }
        }
        if ($cur_seesion['sess_ID'] == -1) {
            // This session needs initialization:
            $cur_seesion['sess_start_ts'] = $time_shift - 1;
            $cur_seesion['sess_lastseen_ts'] = $time_shift;
            $DB->query("\n\t\t\t\t\tINSERT INTO T_sessions ( sess_key, sess_start_ts, sess_lastseen_ts, sess_ipaddress, sess_user_ID, sess_device )\n\t\t\t\t\tVALUES (\n\t\t\t\t\t\t'" . $cur_seesion['sess_key'] . "',\n\t\t\t\t\t\t'" . date('Y-m-d H:i:s', $cur_seesion['sess_start_ts']) . "',\n\t\t\t\t\t\t'" . date('Y-m-d H:i:s', $cur_seesion['sess_lastseen_ts']) . "',\n\t\t\t\t\t\t" . $DB->quote($cur_seesion['sess_ipaddress']) . ",\n\t\t\t\t\t\t" . $cur_seesion['sess_user_ID'] . ",\n\t\t\t\t\t\t" . $DB->quote($cur_seesion['sess_device']) . "\n\t\t\t\t\t)");
            $cur_seesion['sess_ID'] = $DB->insert_id;
            $sessions[$rand_i] = $cur_seesion;
            $Test_hit = new Hit('', $cur_seesion['sess_ipaddress'], $cur_seesion['sess_ID'], $cur_seesion['sess_lastseen_ts'], 1, $links[$rand_link]);
            $Test_hit->log();
        } else {
            if ($time_shift - $cur_seesion['sess_lastseen_ts'] > 3000 || !empty($cur_seesion['robot'])) {
                // This session last updated more than 3000 sec ago. Instead of this session create a new session.
                $cur_seesion = array('sess_ID' => -1, 'sess_key' => generate_random_key(32), 'sess_start_ts' => 0, 'sess_lastseen_ts' => 0, 'sess_ipaddress' => generate_random_ip(), 'sess_user_ID' => $users_array[mt_rand(0, $users_count - 1)]['user_ID'], 'sess_device' => $devices[mt_rand(0, $devices_count - 1)], 'pervios_link' => '', 'robot' => '');
                $cur_seesion['sess_start_ts'] = $time_shift - 1;
                $cur_seesion['sess_lastseen_ts'] = $time_shift;
                $r_num = mt_rand(0, 100);
                if ($r_num > 40) {
                    // Create anonymous user and make double insert into hits.
                    $cur_seesion['sess_user_ID'] = -1;
                    $DB->query("\n\t\t\t\t\t\t\tINSERT INTO T_sessions ( sess_key, sess_start_ts, sess_lastseen_ts, sess_ipaddress, sess_device )\n\t\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t'" . $cur_seesion['sess_key'] . "',\n\t\t\t\t\t\t\t\t'" . date('Y-m-d H:i:s', $cur_seesion['sess_start_ts']) . "',\n\t\t\t\t\t\t\t\t'" . date('Y-m-d H:i:s', $cur_seesion['sess_lastseen_ts']) . "',\n\t\t\t\t\t\t\t\t" . $DB->quote($cur_seesion['sess_ipaddress']) . ",\n\t\t\t\t\t\t\t\t" . $DB->quote($cur_seesion['sess_device']) . "\n\t\t\t\t\t\t\t)");
                    if ($r_num >= 80) {
                        // Create robot hit
                        $cur_seesion['robot'] = $robots[mt_rand(0, $robots_count)];
                    }
                } else {
                    $DB->query("\n\t\t\t\t\t\t\tINSERT INTO T_sessions( sess_key, sess_start_ts, sess_lastseen_ts, sess_ipaddress, sess_user_ID, sess_device )\n\t\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t'" . $cur_seesion['sess_key'] . "',\n\t\t\t\t\t\t\t\t'" . date('Y-m-d H:i:s', $cur_seesion['sess_start_ts']) . "',\n\t\t\t\t\t\t\t\t'" . date('Y-m-d H:i:s', $cur_seesion['sess_lastseen_ts']) . "',\n\t\t\t\t\t\t\t\t" . $DB->quote($cur_seesion['sess_ipaddress']) . ",\n\t\t\t\t\t\t\t\t" . $cur_seesion['sess_user_ID'] . ",\n\t\t\t\t\t\t\t\t" . $DB->quote($cur_seesion['sess_device']) . "\n\t\t\t\t\t\t\t)");
                }
                $cur_seesion['sess_ID'] = $DB->insert_id;
                if (mt_rand(0, 100) > 20) {
                    //$ref_count
                    $ref_link = $referes[mt_rand(0, $ref_count)];
                    if (strstr($ref_link, '$keywords$')) {
                        // check if the current search link is selected randomly.
                        $keywords = 'fake search ' . mt_rand(0, 9);
                        $ref_link = str_replace('$keywords$', urlencode($keywords), $ref_link);
                    }
                } else {
                    $ref_link = '';
                }
                if ($cur_seesion['sess_user_ID'] == -1) {
                    if (empty($cur_seesion['robot'])) {
                        $link = array('link' => '/htsrv/login.php', 'blog_id' => 1);
                        $Test_hit = new Hit($ref_link, $cur_seesion['sess_ipaddress'], $cur_seesion['sess_ID'], $cur_seesion['sess_lastseen_ts'], 1, $link);
                        $Test_hit->log();
                        $link = array('link' => '/htsrv/login.php?redirect_to=fake_stat', 'blog_id' => 1);
                        $Test_hit = new Hit($baseurlroot, $cur_seesion['sess_ipaddress'], $cur_seesion['sess_ID'], $cur_seesion['sess_lastseen_ts'] + 3, 1, $link);
                        $Test_hit->log();
                        $cur_seesion['pervios_link'] = $baseurlroot . $link['link'];
                    } else {
                        if (mt_rand(0, 100) < 50) {
                            // robot hit
                            $Test_hit = new Hit('', $cur_seesion['sess_ipaddress'], $cur_seesion['sess_ID'], $cur_seesion['sess_lastseen_ts'], 1, $links[$rand_link], $cur_seesion['robot']);
                        } else {
                            // rss/atom hit
                            $Test_hit = new Hit('', $cur_seesion['sess_ipaddress'], $cur_seesion['sess_ID'], $cur_seesion['sess_lastseen_ts'], 1, $links[$rand_link], NULL, NULL, 1);
                        }
                        $Test_hit->log();
                    }
                } else {
                    if (mt_rand(0, 100) < 10) {
                        // Test hit to admin page
                        $Test_hit = new Hit('', $cur_seesion['sess_ipaddress'], $cur_seesion['sess_ID'], $cur_seesion['sess_lastseen_ts'], 1, $admin_link, NULL, 1);
                        $Test_hit->log();
                        $cur_seesion['pervios_link'] = $admin_url;
                    } else {
                        $Test_hit = new Hit($ref_link, $cur_seesion['sess_ipaddress'], $cur_seesion['sess_ID'], $cur_seesion['sess_lastseen_ts'], 1, $links[$rand_link]);
                        $Test_hit->log();
                        $cur_seesion['pervios_link'] = $baseurlroot . $links[$rand_link]['link'];
                    }
                }
            } else {
                // Update session
                $cur_seesion['sess_lastseen_ts'] = $time_shift;
                $Test_hit = new Hit($cur_seesion['pervios_link'], $cur_seesion['sess_ipaddress'], $cur_seesion['sess_ID'], $cur_seesion['sess_lastseen_ts'], 1, $links[$rand_link]);
                $Test_hit->log();
                $sql = "UPDATE T_sessions SET\n\t\t\t\t\t\t\t\tsess_lastseen_ts = '" . date('Y-m-d H:i:s', $cur_seesion['sess_lastseen_ts']) . "'\n\t\t\t\t\t\t\t\tWHERE sess_ID = {$cur_seesion['sess_ID']}";
                $DB->query($sql, 'Update session');
                $cur_seesion['pervios_link'] = $baseurlroot . $links[$rand_link]['link'];
                $sessions[$rand_i] = $cur_seesion;
            }
        }
        $sessions[$rand_i] = $cur_seesion;
        if ($display_process) {
            if ($insert_data_count % 100 == 0) {
                // Display a process of creating by one dot for 100 hits
                echo ' .';
                flush();
            }
        }
    }
    return $insert_data_count;
}