<?php
/*
**U2自动链 界面主入口
**index.php
**By 冬筠 qq 4 2 6 4 2 0
*/
error_reporting(0);
ini_set('html_errors',false);
ini_set('display_errors',false);
@ini_set('memory_limit', '-1');
@set_time_limit(0);
require_once "./inc/common.inc.php";
require_once "./inc/Template.inc.php";
require_once "./inc/links.inc.php";
//exit($_SERVER['REQUEST_URI']);
$Template->setConfig('PHP_off',true);
$ops = array('index', 'list', 'html', 'tagsall', 'tags');
$isinvite = 0;
$op = (!empty($op) && in_array($op, $ops))?$op:'index';
if($op == 'html'){
if(!$pid) exit("对不起，错误了！");
$pid =ceil($pid);
$fpid=ceil($pid/5000);
$filename=l_path.'./_Cache/site/'.$fpid.'/'.$pid.'.html';
getlocalhtml($filename);
ob_start();
if(!is_dir(l_path.'./_Cache/site/'.$fpid.'/')) {
mkpaths('/_Cache/site/'.$fpid.'/');
}
//Header("Location: $uurl");
//exit("对不起，详细页，停用！正在打开目标站！");
$row = $db -> queryarray("SELECT * FROM {$tablepre}link WHERE id='$pid'");
if($row){
  $newtime=date("Y-m-d", time()+3600*8);
	$id = $row['id'];
	$name = $row['title'];
	$url = $row['url'];
	$furl = $row['lurl'];
	$wurl = d($row['url']);
//	$md99=substr(md5($wurl."2d79#0^jdj"),8,8);
//	$imgs="imgs/".$wurl."/".$md99.".gif";
	$addtime=gmdate("Y-n-d H:i",$row['addtime']+3600*8);
	$uptime=gmdate("Y-n-d H:i",$row['uptime']+3600*8);
  $murl = $siteurl;
 	$keywords=textcut($row['keywords'],100);
  $keyso = "";
  $urlhtml=get_url_content($url);
if($urlhtml){
$name=get_title($urlhtml);
$keywords=get_keywords($urlhtml);
$description=get_description($urlhtml);
$wzhtml=get_enhtml($urlhtml);
}
  $title = $name."_".$webname;
  if($keywords=="无") $keywords="";
 if($keywords){
$b = explode(",",$keywords); 
foreach ($b as $v) {
	$keyso.="<a href=\"".$weburl."/tags/".$v."/\" title=\"" .$v. "\">" .$v. "</a> ";
}
}
$keysdb=explode(',',$sitekey);
$keyhtml='';
for($ii=0;$ii<count($keysdb);$ii++) {
if($ii>0) $keyhtml.=', ';
$keyhtml.='<a href="'.$weburl.'/" title="'.$keysdb[$ii].'">'.$keysdb[$ii].'</a>';
}
/*
$webdbok=Get_webdbok($wurl);
preg_match_all("|<!--b top-->(.*)<!--b end-->|isU",$webdbok,$wwldb);
$baidu=trim($wwldb[1][0]);
preg_match_all("|<!--pr top-->(.*)<!--pr end-->|isU",$webdbok,$wwldb);
$pr=trim($wwldb[1][0]);
preg_match_all("|<!--g top-->(.*)<!--g end-->|isU",$webdbok,$wwldb);
$google=trim($wwldb[1][0]);
preg_match_all("|<!--a top-->(.*)<!--a end-->|isU",$webdbok,$wwldb);
$alexa=trim($wwldb[1][0]);
$link=get_link();
*/
$getdb = new linkscs($db);
$linkclas = $getdb->getclass();
$Template->display('site');
$db->close();
$temp = ob_get_contents(); 
ob_end_clean();
setLocalHtml($filename,$temp);
}
}
if($op == 'list'){
$getdb = new linkscs($db);
$pid = empty($pid)?1:intval($pid);
//$uid = empty($uid)?1:intval($uid);
//$pageurl .= '/index.php/order/'.$pid.'/';
$pageurl .= '/list/';
$upid="uptime";
$links = $getdb->gettoplinks($pid,$tagsnum,$upid);
$linksnum = $getdb->getlinknum(1, 1);
$page_url = paging($linksnum,$tagsnum,$pid,$pageurl);
$title = $sitename."_".$webname;
$keysdb=explode(',',$sitekey);
$keyhtml='';
for($ii=0;$ii<count($keysdb);$ii++) {
if($ii>0) $keyhtml.=', ';
$keyhtml.='<a href="'.$weburl.'/" title="'.$keysdb[$ii].'">'.$keysdb[$ii].'</a>';
}
$keywords=$sitekey;
$description=$sitejs;
$Template->display('list');
$db->close();
}

if($op == 'tags'){
$getdb = new linkscs($db);
if(!$pid) exit("对不起，关键字不允许为空！");
$uid = empty($uid)?1:intval($uid);
$pid = $pid;
$sitename=$pid;
$pageurl .= '/tags/'.$pid.'/';
$keyword = ereg_replace("[\"\r\n\t\*\?\(\)\$%']"," ",trim($pid));
$pid=GetKeywords($keyword);
$links = $getdb->gettagslinks($uid,$tagsnum,$pid);
$virtue = "1";
$setvirtue = "1";
$linksnum = $getdb->getlinknum($virtue,$setvirtue,$pid);
//echo $linksnum;
$page_url = paging($linksnum,$tagsnum,$uid,$pageurl);
$linkclas = $getdb->getclass();
$title = $keyword."_".$webname;
$keysdb=explode(',',$sitekey);
$keyhtml='<script src="/up.php?'.urlencode($pid).'"></script>';
/*
for($ii=0;$ii<count($keysdb);$ii++) {
if($ii>0) $keyhtml.=', ';
$keyhtml.='<a href="'.$weburl.'/" title="'.$keysdb[$ii].'">'.$keysdb[$ii].'</a>';
}
*/
$keywords=$sitename;
$description=$sitejs;
//$keywords=GetKeywords($keyword);
//$likeword=GetLikeWords();
//Gettags();
$Template->display('list');
$db->close();
}

if($op == 'index')
{
$filename=l_path.'./_Cache/i.html';
if($fso==""){
getlocalhtml($filename,1);
}
ob_start();
$title = $sitename."_".$webname;
$getdb = new linkscs($db);
//$toplinks = $getdb->getplinks(10,'count');
$tjlinks = $getdb->gettjlinks(10,'id');
$upslinks = $getdb->getplinks(20,'uptime');
//$daylinks = $getdb->getplinks(10,'dayct');
//$diglinks = $getdb->getplinks(10,'upding');
//$linkclas = $getdb->getclass();
$keysdb=explode(',',$sitekey);
$keyhtml='';
for($ii=0;$ii<count($keysdb);$ii++) {
if($ii>0) $keyhtml.=', ';
$keyhtml.='<a href="'.$weburl.'/" title="'.$keysdb[$ii].'">'.$keysdb[$ii].'</a>';
}
$keywords=$sitekey;
$description=$sitejs;
$Template->display('index');
$db->close();
$temp = ob_get_contents(); 
ob_end_clean();
setLocalHtml($filename,$temp);
}
exit();
?>