//跨表调用相关链接//返回相关链接操作类型functionu_OtherLinkQuery($classid,$line,$enews,$doing){global$empire,$public_r,$class_r,$class_zr,$navinfor,$dbtbpre,$eyh_r,$etable_r,$class_tr;if($enews==1)//按表{if(strstr($classid,','))//多表{$tbr=explode(',',$classid);$duo=1;}else{$tbname=$classid;$duo=0;}}elseif($enews==2)//按栏目{if($classid=='selfinfo')//当前栏目{$classid=$navinfor['classid'];}$tbname=$class_r[$classid]['tbname'];if($class_r[$classid][islast]){$and="classid='$classid'";}else{$and=ReturnClass($class_r[$classid][sonclass]);}}elseif($enews==3)//按标题分类{$tbname=$class_tr[$classid]['tbname'];$and="ttid='$classid'";}else//默认{$tbname=$class_r[$navinfor[classid]]['tbname'];}//关键字$keys='';if(!empty($enews)){$repadd='';$keyr=explode(',',$navinfor['keyboard']);$count=count($keyr);for($i=0;$i<$count;$i++){if($i==0){$or='';}else{$or=' or ';}$repadd.=$or."[!--f--!] like '%".$keyr[$i]."%'";}//搜索范围if($public_r['newslink']==1){$keys='('.str_replace('[!--f--!]','keyboard',$repadd).')';}elseif($public_r['newslink']==2){$keys='('.str_replace('[!--f--!]','keyboard',$repadd).' or '.str_replace('[!--f--!]','title',$repadd).')';}else{$keys='('.str_replace('[!--f--!]','title',$repadd).')';}}else{$keys='id in ('.$navinfor['keyid'].')';}//当前信息if($tbname==$class_r[$navinfor[classid]][tbname]){$and.=empty($and)?"id<>'$navinfor[id]'":" and id<>'$navinfor[id]'";}//图片信息if($doing){$and.=empty($and)?"ispic=1":" and ispic=1";}if($and){$and.=' and ';}if(empty($line)){$line=$class_r[$navinfor[classid]]['link_num'];}//优化$yhvar='otherlink';$yhid=$etable_r[$tbname][yhid];$yhadd='';if($yhid){$yhadd=ReturnYhSql($yhid,$yhvar,1);}if($duo==0){$query="select * from {$dbtbpre}ecms_".$tbname." where ".$yhadd.$and.$keys." order by newstime desc limit $line";}else{$nowtb=$class_r[$navinfor['classid']]['tbname'];$nowid=$navinfor['id'];$query='';foreach($tbras$n=>$tbname){$t=$n+1;if($tbname==$nowtb){$q.$n="select title,titleurl,newstime,classid,titlepic from ".$dbtbpre."ecms_".$tbname." where ".$yhadd.$and.$keys." and (id>$nowid or id<$nowid) order by newstime desc limit ".$line;}else{$q.$n="select title,titleurl,newstime,classid,titlepic from ".$dbtbpre."ecms_".$tbname." where ".$yhadd.$and.$keys." order by newstime desc limit ".$line;}$query.='select * from ('.$q.$n.') t'.$t.' union all ';}$query=substr($query,0,-10).' order by newstime desc limit '.$line;}$sql=$empire->query1($query);if(!$sql){echo"SQL Error: ".ReRepSqlTbpre($query);}return$sql;}//相关链接标签functionu_GetOtherLinkInfo($tempid,$classid='',$line=0,$strlen=60,$have_class=0,$enews=0,$doing=0){global$empire,$navinfor,$public_r;if(empty($navinfor['keyboard'])||(empty($enews)&&!$navinfor['keyid'])){return'';}$sql=u_OtherLinkQuery($classid,$line,$enews,$doing);if(!$sql){return"";}//取得模板$tr=sys_ReturnBqTemp($tempid);if(empty($tr['tempid'])){return"";}$listtemp=str_replace('[!--news.url--]',$public_r[newsurl],$tr[temptext]);$subnews=$tr[subnews];$listvar=str_replace('[!--news.url--]',$public_r[newsurl],$tr[listvar]);$rownum=$tr[rownum];$formatdate=$tr[showdate];$docode=$tr[docode];//替换变量$listtemp=ReplaceEcmsinfoClassname($listtemp,$enews,$classid);if(empty($rownum)){$rownum=1;}//字段$ret_r=ReturnReplaceListF($tr[modid]);//列表$list_exp="[!--empirenews.listtemp--]";$list_r=explode($list_exp,$listtemp);$listtext=$list_r[1];$no=1;$changerow=1;while($r=$empire->fetch($sql)){$r[oldtitle]=$r[title];//替换列表变量$repvar=ReplaceListVars($no,$listvar,$subnews,$strlen,$formatdate,$url,$have_class,$r,$ret_r,$docode);$listtext=str_replace("<!--list.var".$changerow."-->",$repvar,$listtext);$changerow+=1;//超过行数if($changerow>$rownum){$changerow=1;$string.=$listtext;$listtext=$list_r[1];}$no++;}//多余数据if($changerow<=$rownum&&$listtext<>$list_r[1]){$string.=$listtext;}$string=$list_r[0].$string.$list_r[2];echo$string;}