expired()) {
echo $cache->get();
exit();
}
}
if ($nishe == 'drawn') {
$cond[] = "nsh_alias IN ($drawn)";
} else if ($nishe == 'nodrawn') {
$cond[] = "nsh_alias NOT IN ($drawn)";
} else {
$nList = preg_split("/[^a-z0-9-]+/i", $nishe, -1, PREG_SPLIT_NO_EMPTY);
$nList = "'" . implode("', '", $nList) . "'";
$cond[] = "nsh_alias IN ($nList)";
}
if (!empty($except)) {
$nList = preg_split("/[^a-z0-9-]+/i", $except, -1, PREG_SPLIT_NO_EMPTY);
$nList = "'" . implode("', '", $nList) . "'";
$cond[] = "nsh_alias NOT IN ($nList)";
}
if (!empty($cond)) {
$cond = implode(' AND ', $cond);
}
$sql = "SELECT nsh_title FROM tm_sites " .
"LEFT JOIN tm_nishes ON nsh_id = site_nisheid " .
"WHERE " . $cond . " AND " .
"site_index = '1' AND " .
"site_formstatus = 'open' AND " .
"site_gallerytype IN ('TGP','MGP','TGP/MGP','CJ-Tube','Tube','Blog') " .
"GROUP BY site_nisheid " .
"ORDER BY RAND() " .
"LIMIT 1";
$nishe = $db->cell($sql);
$nsh_alias = titleToAlias($nishe);
if ($type == 'cjtube') {
$sql = "SELECT site_domain, site_url, site_description, site_uselinks, site_links, nsh_title FROM tm_sites " .
"LEFT JOIN tm_nishes ON (nsh_id = site_nisheid) " .
"WHERE nsh_alias = '" . $nsh_alias . "' " .
"AND site_index = 1 " .
"AND site_description <> '' " .
"AND site_formstatus = 'open' " .
"AND site_gallerytype IN ('CJ-Tube') " .
"ORDER BY RAND() " .
"LIMIT 1";
}else{
$sql = "SELECT site_domain, site_url, site_description, site_uselinks, site_links, nsh_title FROM tm_sites " .
"LEFT JOIN tm_nishes ON (nsh_id = site_nisheid) " .
"WHERE nsh_alias = '" . $nsh_alias . "' " .
"AND site_formstatus = 'open' " .
"AND site_index = 1 " .
"AND site_description <> '' " .
"ORDER BY RAND() " .
"LIMIT 1";
};
$siteinfo = $db->line($sql);
//if (!$siteinfo) echo $sql;
$random = mt_rand(0, 100);
if (intval($siteinfo['site_uselinks']) and $random>30)
{
$items = explode(PHP_EOL, $siteinfo['site_links']);
$items = $items[array_rand($items)];
$items = explode('|', $items);
$siteinfo['site_url'] = $items[0];
$siteinfo['site_description'] = $items[1];
}
$descTemplates = formatTemplates($db->query("SELECT dst_template, dst_pattern FROM tm_desctemplates"));
$i = 0;
$wordsCount = 0;
while ($i < 1000 && $wordsCount != 2) {
$key2 = getDescription($descTemplates, $siteinfo['site_description'], getQid());
$wordsCount = str_word_count($key2, 0);
$i++;
}
$i = 0;
$wordsCount = 0;
while ($i < 1000 && $wordsCount != 3) {
$key3 = getDescription($descTemplates, $siteinfo['site_description'], getQid());
$wordsCount = str_word_count($key3, 0);
$i++;
}
$data['domain'] = $siteinfo['site_domain'];
$data['niche'] = $siteinfo['nsh_title'];
$data['keyword'] = $key2;
$data['description'] = $key3;
ob_start();
if ($tmpl) {
$data['url'] = $siteinfo['site_url'];
include('templates/keywords/' . $tmpl . '.php');
} else {
echo implode("\r\n", $data);
}
$content = ob_get_contents();
if (!empty($cacheKey) && !empty($cache)) {
echo $cache->set($content);
}
ob_flush();
if (httpRequest('debug'))
{
echo '';
var_dump($data);
var_dump($db);
}
expired()) {
echo $cache->get();
exit();
}
}
if ($nishe == 'drawn') {
$cond[] = "nsh_alias IN ($drawn)";
} else if ($nishe == 'nodrawn') {
$cond[] = "nsh_alias NOT IN ($drawn)";
} else {
$nList = preg_split("/[^a-z0-9-]+/i", $nishe, -1, PREG_SPLIT_NO_EMPTY);
$nList = "'" . implode("', '", $nList) . "'";
$cond[] = "nsh_alias IN ($nList)";
}
if (!empty($except)) {
$nList = preg_split("/[^a-z0-9-]+/i", $except, -1, PREG_SPLIT_NO_EMPTY);
$nList = "'" . implode("', '", $nList) . "'";
$cond[] = "nsh_alias NOT IN ($nList)";
}
if (!empty($cond)) {
$cond = implode(' AND ', $cond);
}
$sql = "SELECT nsh_title FROM tm_sites " .
"LEFT JOIN tm_nishes ON nsh_id = site_nisheid " .
"WHERE " . $cond . " AND " .
"site_index = '1' AND " .
"site_formstatus = 'open' AND " .
"site_gallerytype IN ('TGP','MGP','TGP/MGP','CJ-Tube','Tube','Blog') " .
"GROUP BY site_nisheid " .
"ORDER BY RAND() " .
"LIMIT 1";
$nishe = $db->cell($sql);
$nsh_alias = titleToAlias($nishe);
if ($type == 'cjtube') {
$sql = "SELECT site_domain, site_url, site_description, site_uselinks, site_links, nsh_title FROM tm_sites " .
"LEFT JOIN tm_nishes ON (nsh_id = site_nisheid) " .
"WHERE nsh_alias = '" . $nsh_alias . "' " .
"AND site_index = 1 " .
"AND site_description <> '' " .
"AND site_formstatus = 'open' " .
"AND site_gallerytype IN ('CJ-Tube') " .
"ORDER BY RAND() " .
"LIMIT 1";
}else{
$sql = "SELECT site_domain, site_url, site_description, site_uselinks, site_links, nsh_title FROM tm_sites " .
"LEFT JOIN tm_nishes ON (nsh_id = site_nisheid) " .
"WHERE nsh_alias = '" . $nsh_alias . "' " .
"AND site_formstatus = 'open' " .
"AND site_index = 1 " .
"AND site_description <> '' " .
"ORDER BY RAND() " .
"LIMIT 1";
};
$siteinfo = $db->line($sql);
//if (!$siteinfo) echo $sql;
$random = mt_rand(0, 100);
if (intval($siteinfo['site_uselinks']) and $random>30)
{
$items = explode(PHP_EOL, $siteinfo['site_links']);
$items = $items[array_rand($items)];
$items = explode('|', $items);
$siteinfo['site_url'] = $items[0];
$siteinfo['site_description'] = $items[1];
}
$descTemplates = formatTemplates($db->query("SELECT dst_template, dst_pattern FROM tm_desctemplates"));
$i = 0;
$wordsCount = 0;
while ($i < 1000 && $wordsCount != 2) {
$key2 = getDescription($descTemplates, $siteinfo['site_description'], getQid());
$wordsCount = str_word_count($key2, 0);
$i++;
}
$i = 0;
$wordsCount = 0;
while ($i < 1000 && $wordsCount != 3) {
$key3 = getDescription($descTemplates, $siteinfo['site_description'], getQid());
$wordsCount = str_word_count($key3, 0);
$i++;
}
$data['domain'] = $siteinfo['site_domain'];
$data['niche'] = $siteinfo['nsh_title'];
$data['keyword'] = $key2;
$data['description'] = $key3;
ob_start();
if ($tmpl) {
$data['url'] = $siteinfo['site_url'];
include('templates/keywords/' . $tmpl . '.php');
} else {
echo implode("\r\n", $data);
}
$content = ob_get_contents();
if (!empty($cacheKey) && !empty($cache)) {
echo $cache->set($content);
}
ob_flush();
if (httpRequest('debug'))
{
echo '';
var_dump($data);
var_dump($db);
}