/**
  * 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();
     }
 }
Esempio n. 2
0
    /**
     * Restrict to specific collection/chapters (blog/categories)
     *
     * @param integer
     * @param string List of cats to restrict to
     * @param array Array of cats to restrict to
     */
    function where_chapter($blog, $cat = '', $catsel = array())
    {
        global $cat_array;
        // this is required for the cat_req() callback in compile_cat_array()
        $blog = intval($blog);
        // Extra security
        // Save for future use (permission checks..)
        $this->blog = $blog;
        $this->FROM_add('INNER JOIN T_postcats ON ' . $this->dbIDname . ' = postcat_post_ID
											INNER JOIN T_categories ON postcat_cat_ID = cat_ID');
        $BlogCache =& get_BlogCache();
        $current_Blog = $BlogCache->get_by_ID($blog);
        $this->WHERE_and($current_Blog->get_sql_where_aggregate_coll_IDs('cat_blog_ID'));
        $cat_array = NULL;
        $cat_modifier = NULL;
        // Compile the real category list to use:
        // TODO: allow to pass the compiled vars directly to this class
        compile_cat_array($cat, $catsel, $cat_array, $cat_modifier, $blog);
        if (!empty($cat_array)) {
            // We want to restict to some cats:
            global $DB;
            if ($cat_modifier == '-') {
                $eq = 'NOT IN';
            } else {
                $eq = 'IN';
            }
            $whichcat = 'postcat_cat_ID ' . $eq . ' (' . $DB->quote($cat_array) . ') ';
            // echo $whichcat;
            $this->WHERE_and($whichcat);
            if ($cat_modifier == '*') {
                // We want the categories combined! (i-e posts must be in ALL requested cats)
                $this->GROUP_BY($this->dbIDname . ' HAVING COUNT(postcat_cat_ID) = ' . count($cat_array));
            }
        }
    }
Esempio n. 3
0
/**
 * Compiles the cat array from $cat (recursive + optional modifiers) and $catsel[] (non recursive)
 * and keeps those values available for future reference (category widget)
 */
function param_compile_cat_array($restrict_to_blog = 0, $cat_default = NULL, $catsel_default = array())
{
    // For now, we'll need those as globals!
    // fp> this is used for the categories widget
    // fp> we want might to use a $set_globals params to compile_cat_array()
    global $cat_array, $cat_modifier;
    $cat = param('cat', '/^[*\\-]?([0-9]+(,[0-9]+)*)?$/', $cat_default, true);
    // List of cats to restrict to
    $catsel = param('catsel', 'array', $catsel_default, true);
    // Array of cats to restrict to
    $cat_array = array();
    $cat_modifier = '';
    compile_cat_array($cat, $catsel, $cat_array, $cat_modifier, $restrict_to_blog);
}
 /**
  * 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();
     }
 }
Esempio n. 5
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;
}
Esempio n. 6
0
 /**
  * List of items by category
  *
  * @param array MUST contain at least the basic display params
  */
 function disp_cat_item_list($link_type = 'linkto_url')
 {
     global $BlogCache, $Blog;
     global $timestamp_min, $timestamp_max;
     $linkblog = $this->disp_params['linkblog_ID'];
     if (!$linkblog) {
         // No linkblog blog requested for this blog
         return;
     }
     // Load the linkblog blog:
     $link_Blog =& $BlogCache->get_by_ID($linkblog, false);
     if (empty($link_Blog)) {
         echo $this->disp_params['block_start'];
         echo T_('The requested Blog doesn\'t exist any more!');
         echo $this->disp_params['block_end'];
         return;
     }
     # 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();
     // Compile cat array stuff:
     $linkblog_cat_array = array();
     $linkblog_cat_modifier = '';
     compile_cat_array($linkblog_cat, $linkblog_catsel, $linkblog_cat_array, $linkblog_cat_modifier, $linkblog);
     $limit = $this->disp_params['linkblog_limit'] ? $this->disp_params['linkblog_limit'] : 1000;
     // Note: 1000 will already kill the display
     $LinkblogList =& new ItemListLight($link_Blog, $timestamp_min, $timestamp_max, $limit);
     $LinkblogList->set_filters(array('cat_array' => $linkblog_cat_array, 'cat_modifier' => $linkblog_cat_modifier, 'orderby' => 'main_cat_ID title', 'order' => 'ASC', 'unit' => 'posts'), false);
     // we don't want to memorise these params
     // Run the query:
     $LinkblogList->query();
     if (!$LinkblogList->get_num_rows()) {
         // empty list:
         return;
     }
     echo $this->disp_params['block_start'];
     $this->disp_title($this->disp_params['title']);
     echo $this->disp_params['list_start'];
     /**
      * @var ItemLight
      */
     while ($Item =& $LinkblogList->get_category_group()) {
         // Open new cat:
         echo $this->disp_params['item_start'];
         $Item->main_category();
         echo $this->disp_params['group_start'];
         while ($Item =& $LinkblogList->get_item()) {
             echo $this->disp_params['item_start'];
             $Item->title(array('link_type' => $link_type));
             /*
             $Item->content_teaser( array(
             		'before'      => '',
             		'after'       => ' ',
             		'disppage'    => 1,
             		'stripteaser' => false,
             	) );
             
             $Item->more_link( array(
             		'before'    => '',
             		'after'     => '',
             		'link_text' => T_('more').' &raquo;',
             	) );
             */
             echo $this->disp_params['item_end'];
         }
         // Close cat
         echo $this->disp_params['group_end'];
         echo $this->disp_params['item_end'];
     }
     // Close the global list
     echo $this->disp_params['list_end'];
     echo $this->disp_params['block_end'];
 }