Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function curent_date($var, $var2)
- {
- date_default_timezone_set("Europe/Dublin");
- return date($var, $var2);
- }
- function w_log($name, $content)
- {
- global $warr;
- $worked_time = round(microtime(true) - $warr['start_time'], 3);
- $ram = memory_get_usage();
- $warr['log'] .= "{$worked_time}:{$name} - {$content} | {$ram}";
- }
- function is_boot()
- {
- if (!preg_match("/bot|crawl|spider|robo/i", $_SERVER['HTTP_USER_AGENT']) && preg_match("/firefox|windows|explor|chrome|opera/i", $_SERVER['HTTP_USER_AGENT'])) {
- return false;
- }
- return true;
- }
- function skim($skim)
- {
- $rn = floor(10000 / $skim);
- if (mt_rand(1, $rn) <= 100 && 0 < $skim) {
- return true;
- }
- return false;
- }
- function title_to_len($title, $limit)
- {
- if ($limit < strlen($title)) {
- $title = substr($title, 0, strrpos(substr($title, 0, $limit), " ")) . "";
- }
- return $title;
- }
- ini_set("expose_php", "off");
- ini_set("display_errors", "off");
- ini_set("display_startup_errors", "off");
- $config = unserialize(file_get_contents("files/config"));
- $flgs = unserialize(file_get_contents("files/flgs"));
- $st = microtime(true);
- $time = time();
- $cache_step = $config['cache_step'];
- if (empty($cache_step)) {
- $cache_step = 1;
- }
- $curent_hour = curent_date("G", time());
- $pstats_id = md5($_SERVER['REQUEST_URI']);
- $host = str_replace("www.", "", getenv("HTTP_HOST"));
- $warr = array();
- $warr['start_time'] = microtime(true);
- $warr['host'] = $host;
- if (preg_match("/n=|t=|f=/i", $_SERVER['REQUEST_URI'])) {
- preg_match("/([\\.\\?\\=0-9a-z\\_\\-\\/]{1,64})/i", $_SERVER['REQUEST_URI'], $matches);
- } else {
- preg_match("/([0-9a-z\\_\\-\\/]{1,64})/i", $_SERVER['REQUEST_URI'], $matches);
- }
- $warr['uri_filtred'] = $matches['1'];
- $warr['query_url'] = str_replace("www.", "", "http://{$_SERVER['HTTP_HOST']}{$warr['uri_filtred']}");
- $warr['log'] = "";
- $warr['format'] = "m";
- $warr['param_str'] = "";
- $warr['query_mode'] = "base_search";
- w_log("warr_query_url", $warr['query_url']);
- if (empty($_SERVER['HTTP_USER_AGENT'])) {
- $_SERVER['HTTP_USER_AGENT'] = "bot";
- }
- $warr['is_boot'] = is_boot();
- $link = mysql_connect($config['host'], $config['user'], $config['pass']);
- if (mysql_select_db($config['dbname'], $link)) {
- w_log("mysql_select_db", "ok");
- } else {
- w_log("mysql_select_db", "error");
- }
- $cache_time = 240 * $cache_step;
- if (15 < $flgs['la']['0']) {
- $cache_time = $cache_time * 10;
- }
- if (isset($_COOKIE['adminlog'])) {
- $cache_time = "0";
- }
- if (!empty($_REQUEST['p'])) {
- preg_match("/[0-9]{0,3}/", $_REQUEST['p'], $matches);
- $warr['p'] = $matches['0'];
- $warr['param_str'] .= $matches['0'];
- }
- if ($_REQUEST['n'] != __FILE__) {
- preg_match("/[a-z0-9_]{1,32}/i", $_REQUEST['n'], $matches);
- $_REQUEST['n'] = $matches['0'];
- $warr['query_niche'] = $matches['0'];
- $warr['param_str'] .= $matches['0'];
- $warr['n'] = $matches['0'];
- if (!empty($_COOKIE['tr_categories']) && $warr['is_boot'] == false) {
- mysql_query("update `niches` set `clicks`=clicks+1 where `name`='{$warr['query_niche']}'");
- }
- }
- if (!empty($_REQUEST['t'])) {
- preg_match("/[a-z0-9]{1,32}/i", $_REQUEST['t'], $matches);
- $_REQUEST['t'] = $matches['0'];
- $warr['param_str'] .= $matches['0'];
- $warr['t'] = $matches['0'];
- }
- if (!empty($warr['t']) || !empty($warr['p'])) {
- $cache_time = 14400 * $cache_step;
- }
- if (!empty($_REQUEST['id'])) {
- preg_match("/v([0-9]{1,8})/", $_REQUEST['id'], $matches);
- @$id = $matches['1'];
- @$warr['id'] = $matches['1'];
- $warr['param_str'] .= $matches['1'];
- }
- if (!empty($_REQUEST['f']) && count($_REQUEST['f']) == "1" && $_REQUEST['f'] == "c") {
- $warr['format'] = "c";
- $warr['param_str'] .= "c";
- $cache_time = $cache_time * 3;
- setcookie("tr_categories", "1", time() + 86400, "/", ".{$host}");
- mysql_query("update `niches` set `hits`=hits+1 where `name`='" . __FILE__ . "'");
- }
- $warr['cache_file'] = md5($warr['param_str']);
- w_log("cache_file", $warr['cache_file']);
- $r_max = 20;
- $rp_max = 10;
- if ($flgs['num_rs'] <= 200) {
- $r_max = 3;
- $rp_max = 2;
- }
- if (200 < $flgs['num_rs'] && $flgs['num_rs'] < 1000) {
- $r_max = 5;
- $rp_max = 8;
- }
- if (mt_rand(1, $r_max) == "1") {
- $rand = true;
- }
- if (empty($_COOKIE['tr_main']) && $warr['is_boot'] == false && $warr['format'] != "c") {
- w_log("mysql_insert_pstats", "start");
- if (mysql_query("UPDATE `pstats` set `i`=`i`+'1' where `id`='{$pstats_id}'")) {
- w_log("mysql_insert_pstats", "ok");
- } else {
- w_log("mysql_insert_pstats", "error");
- }
- if (mysql_query("update `stats_h` set `hits`=hits+1 where `hour`='{$curent_hour}' ")) {
- w_log("mysql_update_hits", "ok");
- } else {
- w_log("mysql_update_hits", "error");
- }
- } else {
- w_log("mysql_update_hits", "noneed");
- }
- if (!empty($id)) {
- w_log("as_id", $id);
- if (!empty($_COOKIE['tr_main']) && $_COOKIE['tr_' . __FILE__] < 21 && empty($_COOKIE['tr_cjclicks']) && !preg_match("/bot|crawl|spider|robo/i", $_SERVER['HTTP_USER_AGENT']) && preg_match("/firefox|windows|explor|chrome|opera/i", $_SERVER['HTTP_USER_AGENT'])) {
- mysql_query("update `w_content` set `l_clicks`=l_clicks+1,`clicks`=clicks+1 where `id` = '{$id}'");
- mysql_query("update `stats_h` set `clicks`=clicks+1 where `hour` = '{$curent_hour}'");
- w_log("as_id_update_stats", "ok");
- }
- if (mt_rand(1, 100) == "1" && empty($_COOKIE['tr_cjclicks']) && !empty($_COOKIE['tr_main'])) {
- $domain = preg_replace("/^www./i", "", getenv("HTTP_HOST"));
- if (!preg_match("/{$domain}/i", getenv("SCRIPT_FILENAME"))) {
- $domain = mt_rand(999, 999999);
- }
- $str_to_key = "E45RtGD1Nb5 & +&7?r/Gt%4w8g5-^f1v#2@1xkjdpenDortmg)grF{$domain}T4G1fd-Qafuy6*D1cu&ld";
- $key = sha1($str_to_key);
- $key = "{$domain}_{$key}";
- if ($config['lic_key'] != $key) {
- header("location:http://www.tuberotator.com/src/in.php?d={$domain}&n={$_REQUEST['n']}&t={$_REQUEST['t']}");
- mysql_close();
- exit();
- } else {
- unset($key);
- unset($str_to_key);
- }
- }
- if ($config['mode'] == "out") {
- $q = mysql_query("select url from `w_content` where `id`='{$id}'");
- $r = mysql_fetch_array($q);
- header("location:{$r['url']}");
- exit();
- } else {
- $cache_time = 3600 * 6 * $cache_step;
- if (isset($_COOKIE['adminlog'])) {
- $cache_time = "0";
- }
- $rel = true;
- }
- }
- if (empty($_COOKIE['tr_main'])) {
- setcookie("tr_" . __FILE__, "1", time() + 86400, "/", ".{$host}");
- w_log("cookie_new_tr_" . __FILE__, "ok");
- } else {
- $c = intval($_COOKIE['tr_' . __FILE__]) + 1;
- setcookie("tr_" . __FILE__, $c, time() + 86400, "/", ".{$host}");
- w_log("cookie_update_tr_" . __FILE__, $c);
- }
- $cache_file = $warr['cache_file'];
- $cache_dir = substr($cache_file, 0, 3);
- $cache_dir = "files/tmp/cache/{$cache_dir}";
- $cache_file = "{$cache_dir}/{$cache_file}";
- w_log("cache_check_local_files", "start");
- if (file_exists("files/tmp/flgs_regen_url")) {
- $flgs_regen_url = file_get_contents("files/tmp/flgs_regen_url");
- } else {
- $flgs_regen_url = false;
- }
- if (file_exists($cache_file) && $warr['query_url'] != $flgs_regen_url && empty($_COOKIE['adminlog'])) {
- w_log("cache_check_local_files", "end");
- if (time() - $cache_time < filemtime($cache_file)) {
- $flgs['cache'] = "on";
- w_log("cache_read_cache_file", "start");
- include($cache_file);
- w_log("cache_read_cache_file", "end");
- w_log("cache_time", $cache_time);
- w_log("cache_get_from_file", $cache_file);
- } else {
- if (file_exists("files/tmp/cache/caches")) {
- $caches = unserialize(file_get_contents("files/tmp/cache/caches"));
- if (!is_array($caches)) {
- $caches = array();
- }
- } else {
- $caches = array();
- }
- if (!in_array($warr['query_url'], $caches)) {
- $caches[] = $warr['query_url'];
- }
- if (file_exists("files/tmp/cache/caches")) {
- unlink("files/tmp/cache/caches");
- }
- file_put_contents("files/tmp/cache/caches", serialize($caches));
- chmod("files/tmp/cache/caches", 438);
- file_put_contents($cache_file, file_get_contents($cache_file));
- include($cache_file);
- }
- } else {
- w_log("content", "gen new start");
- file_put_contents("files/tmp/tmp_gen_page", "");
- $flgs['cache'] = "off";
- $q = mysql_query("SELECT * FROM `templates`");
- while ($r = mysql_fetch_array($q)) {
- $arr['templates'][$r['name']] = $r['template'];
- }
- if (empty($_REQUEST['n']) && empty($_REQUEST['t'])) {
- $_REQUEST['n'] = __FILE__;
- w_log("content", "type " . __FILE__);
- }
- function get_all_ads($ads)
- {
- global $config;
- if (empty($ads) && isset($config['a_block_flg']) && $config['a_block_flg'] == "on") {
- $q = mysql_query("SELECT * FROM `niches` where `name`='" . __FILE__ . "'");
- $r = mysql_fetch_assoc($q);
- $ads = $r['ads'];
- }
- if (preg_match("/STARTADS/", $ads)) {
- preg_match_all("/<--STARTADS([0-9]{1,3})-->(.+)<--END-->/Us", $ads, $matches, PREG_SET_ORDER);
- foreach ($matches as $value) {
- $ads_arr[$value[1]] = $value[2];
- }
- } else {
- $ads_arr['0'] = $ads;
- }
- return $ads_arr;
- }
- if (!empty($_REQUEST['n'])) {
- $q = mysql_query("select * from `niches`");
- while ($r = mysql_fetch_assoc($q)) {
- $warr['all_niches_arr'] = $r;
- $warr['all_niches_keys'][] = $r['name'];
- $warr['all_niches_thumbs'][] = $r['thumb'];
- }
- preg_match_all("/[a-z0-9_]{3,24}*?/i", $_REQUEST['n'], $search_query);
- @$niche = @mysql_real_escape_string($search_query['0']['0']);
- $q = mysql_query("SELECT * FROM `niches` where `name`='{$niche}'");
- $r = mysql_fetch_assoc($q);
- $niche = $r['name'];
- $niche_num = $r['num'];
- $niche_keys = $r['keys'];
- $warr['niche_keys'] = $r['keys'];
- $niche_title = $r['title'];
- $niche_desc = $r['desc'];
- $query = $niche_keys;
- $warr['niche_ads_arr'] = get_all_ads($r['ads']);
- if (preg_match("/[(|)]/", $niche_keys)) {
- preg_match_all("/[a-z0-9()+s*-~]{3,128}*?/i", $niche_keys, $search_query);
- $warr['query_mode'] = "full_search";
- } else {
- preg_match_all("/[a-z0-9]{3,18}*?/i", $niche_keys, $search_query);
- }
- w_log("content", "VARS:niche={$niche};niche_num = {$niche_num};niche_keys={$niche_keys};query={$query}");
- } else if (!empty($_REQUEST['t'])) {
- w_log("content", "type tag");
- $q = mysql_query("SELECT * FROM `niches` where `name`='" . __FILE__ . "'");
- $r = mysql_fetch_assoc($q);
- $warr['niche_ads_arr'] = get_all_ads($r['ads']);
- preg_match_all("/[a-z]{3,18}/i", $_REQUEST['t'], $search_query);
- @$query = $search_query['0']['0'];
- $q = mysql_query("SELECT sum(num) FROM `tags_stats` WHERE `tag` like '{$query}%'");
- $r = mysql_fetch_row($q);
- $niche_num = $r['0'];
- w_log("content", "VARS:query={$query};niche_num={$niche_num}");
- }
- $search_query = array_unique($search_query['0']);
- $search_str = implode(" ", $search_query);
- $num_words = count($search_query);
- if ($warr['format'] == "c") {
- $main_tmpl = $arr['templates']['categories'];
- $warr['query'] = "";
- } else {
- $main_tmpl = $arr['templates'][__FILE__];
- if (!empty($rel)) {
- $main_tmpl = $arr['templates']['embed'];
- }
- }
- preg_match_all("/<--THUMB-->/", $main_tmpl, $matches);
- $limit = count($matches[0]);
- w_log("content_num_thumbs", $limit);
- @$warr['num_pages'] = ceil($niche_num / $limit);
- $limit_start_max = $niche_num - $limit;
- if ($limit_start_max < $limit) {
- $limit_start_max = "0";
- }
- if (100000 < $limit_start_max) {
- $limit_start_max = "100000";
- }
- $limit_start = "0";
- if (!empty($warr['p'])) {
- $limit_start = $warr['p'] * $limit - $limit;
- }
- if ($query != "*" && $warr['query_mode'] != "full_search") {
- w_log("content_mode1_str_start", "ok");
- function dbq($type)
- {
- global $search_query;
- global $num_words;
- global $limit_start;
- global $limit_start_max;
- global $limit;
- global $niche_num;
- global $rel;
- global $config;
- $q_str = "";
- $i = 0;
- foreach ($search_query as $tag) {
- if (!empty($_REQUEST['n'])) {
- if (substr($tag, 0 - 1, 1) == "*") {
- $tag = str_replace("*", "", $tag);
- $q_str .= "`tag` like '{$tag}%'";
- } else {
- $q_str .= "`tag` ='{$tag}'";
- }
- }
- if (!empty($_REQUEST['t'])) {
- if (3 < strlen($tag)) {
- $tag = preg_replace("/^(.+)([m|t|b]{0,1}ings?|ous|ies|ed|s|y)$/isU", "$1", $tag);
- }
- $q_str .= "`tag` like '{$tag}%'";
- }
- ++$i;
- if ($i == $num_words) {
- break;
- }
- $q_str .= " or ";
- }
- $key = implode(" ", $search_query);
- $tq = mysql_query("SELECT tid,num FROM `tags_stats` where {$q_str}");
- $i = 0;
- $force = "use index(`tid`,`ctr`)";
- $q_str = "";
- $niche_num = "";
- if (!empty($tq)) {
- $num_rows = mysql_num_rows($tq);
- while ($tqr = mysql_fetch_array($tq)) {
- $niche_num = $niche_num + $tqr['num'];
- $table_id = substr($tqr['tid'], 0 - 2, 2);
- if (strlen($table_id) < 2) {
- $table_id = "0{$table_id}";
- }
- if ($type == "h") {
- $table_name = "`_tags{$table_id}`";
- } else {
- $table_name = "`tags{$table_id}`";
- }
- $q_str .= "SELECT id,ctr FROM {$table_name} {$force} where `tid` = '{$tqr['tid']}'";
- ++$i;
- if ($i == $num_rows) {
- break;
- }
- $q_str .= " union ";
- }
- }
- $sort_order = "order by `ctr` DESC";
- $limit_start_to_q = $limit_start;
- if (!empty($rand) || !empty($rel) && $config['rotation_mode'] != "max_perfomance") {
- $limit_max_to_q = $limit_start_max;
- if (4000 < $limit_max_to_q && !empty($rand)) {
- $limit_max_to_q = 4000;
- }
- $limit_start_to_q = mt_rand(0, $limit_max_to_q);
- }
- $q_str .= " {$sort_order} LIMIT {$limit_start_to_q},{$limit}";
- return $q_str;
- }
- $q = mysql_query(dbq("h"));
- @$row = @mysql_num_rows($q);
- if (!$q || $row < 1) {
- $q = mysql_query(dbq("m"));
- @$row = @mysql_num_rows($q);
- w_log("content_mode1_get_from", "disk_table");
- } else {
- w_log("content_mode1_get_from", "ram");
- }
- $q_str = "where `id` in (";
- $i = 0;
- while ($r = @mysql_fetch_array($q)) {
- $q_str .= "{$r['id']}";
- ++$i;
- if ($i == $row) {
- break;
- }
- $q_str .= ",";
- }
- $sort_order = "order by `ctr` DESC";
- $q_str .= ") {$sort_order} ";
- w_log("content_mode1_str_end", "str:{$q_str}");
- }
- function duration_time($sec)
- {
- $duration = curent_date("i:s", $sec);
- if (3599 < $sec) {
- $h = floor($sec / 3600);
- $ms = curent_date("i:s", $sec);
- $duration = "{$h}:{$ms}";
- }
- return $duration;
- }
- if ($query == "*" && $warr['query_mode'] != "full_search") {
- w_log("content_mode2_str_start", "ok");
- $sort_order = "order by `ctr` DESC";
- $use_index = "use index(`ctr_2`)";
- $q_str = "{$use_index} where `status`='1' {$sort_order} limit {$limit_start},{$limit}";
- w_log("content_mode2_order", "{$sort_order}");
- if (!empty($rand) || !empty($rel) && $config['rotation_mode'] != "max_perfomance") {
- $limit_start_to_q = mt_rand(0, $limit_start_max);
- $q = mysql_query("select id from ids where i>='{$limit_start_to_q}' limit {$limit}");
- while ($r = mysql_fetch_array($q)) {
- $arr_ids[] = $r['id'];
- }
- @$ids = @implode(",", $arr_ids);
- $variant = "2";
- if ($variant == "2" && !empty($arr_ids)) {
- $q_str = "where ";
- $i = 0;
- foreach ($arr_ids as $iid) {
- $q_str .= "`id`='{$iid}'";
- ++$i;
- if (count($arr_ids) <= $i) {
- break;
- }
- $q_str .= " or ";
- }
- $q_str .= " limit 0,{$limit}";
- } else {
- $q_str = "where `id` in({$ids}) limit 0,{$limit}";
- }
- w_log("content_mode2_order", "rand");
- }
- w_log("content_mode2_str_start", "end");
- }
- if ($warr['query_mode'] == "full_search") {
- w_log("content_mode3_str_start", "ok");
- function multi_search($query)
- {
- global $rel;
- global $limit_start_max;
- global $limit_start;
- global $limit;
- global $config;
- global $warr;
- if (!empty($rel) && $config['rotation_mode'] != "max_perfomance") {
- $limit_start = mt_rand(0, $limit_start_max);
- w_log("content_mode3_sort_order", "rand");
- }
- w_log("content_mode3_sort_order", "desc or other");
- $q_str = "";
- $cache_time = 3600 * 6;
- w_log("content_mode3_query_dump_cache_time", $cache_time);
- $cache_file = md5($warr['niche_keys']);
- $cache_dir = substr($cache_file, 0, 3);
- $cache_dir = "files/tmp/cache_query/{$cache_dir}";
- $cache_file = "{$cache_dir}/{$cache_file}";
- w_log("content_mode3_query_dump_file_path", $cache_file);
- if (time() - $cache_time < @filemtime($cache_file)) {
- $arr = unserialize(file_get_contents($cache_file));
- w_log("content_mode3_query_dump_is_cache?", "yes");
- } else {
- if (preg_match("/([+|(])/", $query, $matches)) {
- if (preg_match("/^(([a-z0-9+]{3,255}))$/isU", $query, $matches)) {
- if (preg_match("/+/", $query)) {
- $query_arr = explode("+", $matches['1']);
- } else {
- $query_arr[] = $matches['1'];
- }
- $query_arr = array_unique($query_arr);
- $c = count($query_arr);
- $i = 0;
- foreach ($query_arr as $key) {
- $q_str .= "`tags` LIKE '%{$key}%'";
- ++$i;
- if ($i < $c) {
- $q_str .= " and ";
- }
- }
- }
- unset($matches['0']);
- $cm = count($matches);
- $im = 0;
- foreach ($matches as $keys) {
- if (preg_match("/[a-z+|s]/i", $keys)) {
- $query_arr = explode("+", $keys);
- $q_str_sep = "and";
- }
- if (preg_match("/|/", $keys)) {
- $query_arr = explode("|", $keys);
- $q_str_sep = "or";
- }
- $c = count($query_arr);
- $i = 0;
- $q_str .= "(";
- foreach ($query_arr as $key) {
- $q_str .= "`tags` LIKE '%{$key}%'";
- ++$i;
- if ($i < $c) {
- $q_str .= " {$q_str_sep} ";
- }
- }
- $q_str .= ")";
- ++$im;
- if ($im < $cm) {
- $q_str .= " and ";
- }
- }
- $q = mysql_query("select id,ctr from tags where {$q_str} order by ctr desc");
- while ($r = mysql_fetch_array($q)) {
- $arr[] = $r;
- }
- if (!file_exists("files/tmp/cache_query")) {
- mkdir("files/tmp/cache_query");
- chmod("files/tmp/cache_query", 511);
- }
- if (!file_exists($cache_dir)) {
- mkdir($cache_dir);
- chmod($cache_dir, 511);
- }
- if (!empty($arr)) {
- if (file_exists($cache_file)) {
- unlink($cache_file);
- }
- file_put_contents($cache_file, serialize($arr));
- $num = count($arr);
- mysql_query("update `niches` set `num`='{$num}' where `name`='{$warr['n']}'");
- }
- }
- w_log("content_mode3_query_dump_is_cache?", "no");
- }
- $content = array();
- $i = $limit_start;
- while ($i < $limit_start + $limit) {
- if (empty($arr[$i])) {
- break;
- }
- $content[] = $arr[$i];
- ++$i;
- }
- $ids = array();
- foreach ($content as $key) {
- $ids[] = $key['id'];
- }
- $ids = implode(",", $ids);
- $sort_order = "order by `ctr` DESC";
- $q_str = "where id in({$ids}) {$sort_order}";
- return $q_str;
- }
- $q_str = multi_search($niche_keys);
- }
- w_log("content_qet", "start");
- w_log("content_qet_query", $q_str);
- $content = mysql_query("SELECT * FROM `w_content` {$q_str} ");
- w_log("content_qet", "end");
- @$content_num_rows = @mysql_num_rows($content);
- if ($content_num_rows < 1 || !$content_num_rows && $warr['query_mode'] != "full_search") {
- w_log("content_qet_status", "notfound");
- $content = mysql_query("SELECT * FROM `w_content` where `status`='1' limit {$limit_start},{$limit}");
- $notfound = true;
- $content_num_rows = mysql_num_rows($content);
- } else {
- w_log("content_qet_status", "found-{$content_num_rows}");
- }
- function tag_title($title, $main_tmpl)
- {
- if (preg_match("/<--TITLE([0-9]{1,3})-->/", $main_tmpl, $matches)) {
- $t = title_to_len($title, $matches['1']);
- $main_tmpl = preg_replace("/<--TITLE([0-9]{1,3})-->/", $t, $main_tmpl);
- }
- $pattern2 = "/<--TITLE([0-9]{1,3})([_|-]{0,1})(format)?-->/";
- if (preg_match($pattern2, $main_tmpl, $matches)) {
- if (isset($matches['3']) && $matches['3'] == "format") {
- $title = preg_replace("/[W|s|_|-]/i", " ", $title);
- preg_match_all("/[a-z]{3,24}/i", $title, $t_matches);
- $title_arr = $t_matches['0'];
- array_unique($title_arr);
- $title = implode(" ", $title_arr);
- if (strlen($title) < 3) {
- $title = "free video";
- }
- }
- $t = title_to_len($title, $matches['1']);
- $t = strtolower(str_replace(" ", $matches['2'], $t));
- $main_tmpl = preg_replace($pattern2, $t, $main_tmpl);
- }
- return $main_tmpl;
- }
- if (!empty($id)) {
- w_log("embed_code_get", "start");
- $qt = mysql_query("select * from `w_content` where `id`='{$id}'");
- $rt = mysql_fetch_assoc($qt);
- w_log("embed_code_get", "end");
- w_log("embed_code_parse_tmpl", "start");
- $embed_source = $rt['embed'];
- $main_tmpl = str_replace("<--EMBED_CODE-->", $embed_source, $main_tmpl);
- $main_tmpl = str_replace("<--DURATION-->", duration_time($rt['duration']), $main_tmpl);
- $main_tmpl = tag_title($rt['title'], $main_tmpl);
- $main_tmpl = str_replace("<--TITLE-->", $rt['title'], $main_tmpl);
- $tags = str_replace("_", "", $rt['tags']);
- $tags = explode(" ", $tags);
- $num_tags = count($tags);
- if (0 < $num_tags) {
- function gen_tags()
- {
- global $main_tmpl;
- global $tags;
- $pattern = "#START_TAGS@(.*)@separator\\=\\'(.*)'\\,max_num\\=\\'([0-9]{0,1})\\'@?END#";
- preg_match_all("/{$pattern}/i", $main_tmpl, $matches);
- $n_of_matches = count($matches['0']);
- $ti = 0;
- while ($ti <= $n_of_matches) {
- preg_match("/{$pattern}/i", $main_tmpl, $matches);
- if (!isset($tags_arr)) {
- $i = 0;
- foreach ($tags as $tag) {
- $qt = mysql_query("select * from `tags_stats` where `tag`='{$tag}'");
- $rt = mysql_fetch_assoc($qt);
- if (!(5 < $rt['num'])) {
- continue;
- }
- $tags_arr[] = $tag;
- if (!(9 <= $i)) {
- continue;
- }
- break;
- break;
- }
- }
- $tags = $tags_arr;
- if ($matches['3'] < count($tags)) {
- $keys = array_map("strlen", array_keys($tags));
- array_multisort($keys, SORT_DESC, $tags);
- $tags = array_slice($tags, 0, $matches['3']);
- }
- sort($tags);
- $i = 0;
- $t_str = "";
- foreach ($tags as $tag) {
- ++$i;
- $t = str_replace("{tag}", "{$tag}", $matches[1]);
- $t = str_replace("{tag_path}", "t/{$tag}", $t);
- $t_str .= "{$t}";
- if (count($tags) <= $i) {
- break;
- }
- $t_str .= "{$matches['2']}";
- }
- $main_tmpl = preg_replace("/{$pattern}/i", $t_str, $main_tmpl, 1);
- ++$ti;
- }
- return $main_tmpl;
- }
- $main_tmpl = @gen_tags();
- }
- w_log("embed_code_parse_tmpl", "end");
- }
- while ($r = mysql_fetch_array($content)) {
- $content_arr[] = $r;
- }
- if (!empty($warr['query_niche']) && empty($rel) && $limit_start == "0") {
- function select_niche_thumb()
- {
- global $content_arr;
- global $warr;
- $ic = mt_rand(1, 3);
- $i = 0;
- foreach ($content_arr as $arr) {
- ++$i;
- if ($i < $ic) {
- continue;
- }
- $thumbs = unserialize($arr['thumbs']);
- $th_id = "10";
- $arr['at'] = "10";
- if (3 < count($thumbs)) {
- $th_id = "13";
- $arr['at'] = "13";
- } else if (1 < count($thumbs)) {
- $th_id = "11";
- $arr['at'] = "11";
- }
- if (9 < $arr['at']) {
- $th_id = substr($r['at'], 0 - 1, 1);
- }
- $th_id = substr($arr['at'], 0 - 1, 1);
- $thumb = $thumbs[$th_id];
- if (in_array($thumb, $warr['all_niches_thumbs'])) {
- continue;
- }
- $warr['all_niches_thumbs'][] = $thumb;
- mysql_query("update `niches` set `thumb`='{$thumb}' where `name`='{$warr['query_niche']}'");
- break;
- break;
- }
- }
- w_log("opt_select_niche_thumb", "start");
- select_niche_thumb();
- w_log("opt_select_niche_thumb", "end");
- }
- if (!empty($rand)) {
- if (mt_rand(1, 3) == "1") {
- shuffle($content_arr);
- }
- } else {
- function cmp($a, $b)
- {
- if ($a['ctr'] == $b) {
- return 0;
- }
- return $b['ctr'] < $a['ctr'] ? 0 - 1 : 1;
- }
- @usort($content_arr, "cmp");
- if (mt_rand(1, $rp_max) == "1" && !empty($content_arr)) {
- shuffle($content_arr);
- }
- if ($config['rotation_mode'] == "max_perfomance" && !empty($rel)) {
- shuffle($content_arr);
- }
- }
- //=========================================== PAYMENT ========================================//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement