/** * 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(); } }
/** * 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; }