<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config.php';
RegisterPlugin("orangecms","ActivePlugin_orangecms");
function ActivePlugin_orangecms(){
	global $zbp;
	Add_Filter_Plugin('Filter_Plugin_Admin_TopMenu','orangecms_AddMenu');
	Add_Filter_Plugin('Filter_Plugin_ViewList_Template','orangecms_tags_set');
	Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','orangecms_tags_set');
	Add_Filter_Plugin('Filter_Plugin_PostComment_Succeed','orangecms_Avatarcomments');
	if($zbp->Config('orangecms')->displaynocate=='1'){
	Add_Filter_Plugin('Filter_Plugin_ViewList_Core','orangecms_articles_xs');
	}
}
function orangecms_AddMenu(&$m){
	global $zbp;
	array_unshift($m, MakeTopMenu("root",'主题设置',$zbp->host . "zb_users/theme/orangecms/main.php?act=base","","topmenu_orangecms"));
}
function orangecms_articles_xs(&$type,&$page,&$category,&$author,&$datetime,&$tag,&$w,&$pagebar){	
global $zbp;
if($type == 'index'){
$w[]=array('<>','log_CateID',$zbp->Config('orangecms')->nocate);
}	
}
function orangecms_Avatarcomments() {
	global $zbp;
    $zbp->RegBuildModule('comments','orangecms_Avatarcomments');
	$i = $zbp->modulesbyfilename['comments']->MaxLi;
	if ($i == 0) $i = 10;
	$comments=$zbp->GetCommentList(
                                        array('*'),
                                        array(array('=','comm_IsChecking',0),array('<>', 'comm_Email',$zbp->Config('orangecms')->blogger)),
                                        array('comm_PostTime'=>'DESC'),
                                        array($i),
                                        null
                                        );

	$s = '';
	foreach ($comments as $comment) {
		$s .= '<li><a href="'. $comment->Post->Url .'#cmt' . $comment->ID .'" title="发表在《'.$comment->Post->Title.'》"><img src="'.$comment->Author->Avatar.'" height="96" width="96" class="avatar avatar-96 photo"/> <span class="comment_author">'.$comment->Author->Name.'：</span><p>'. TransferHTML($comment->Content, '[noenter]') .'</p><div class="clear"></div></a></li>';
	}
	return $s;
}

function orangecms_Category_gg()
{
    global $zbp;
    $Catenews = $zbp->GetCategoryList(array(
        '*'
    ), null);
    
    foreach ($Catenews as $Catenew) {
        echo '<option value="' . $Catenew->Name . '">' . $Catenew->Name . '</option>';
    }
}

function orangecms_tags_set(&$template){
	global $zbp;
	//基本设置
    $template->SetTags('orangecms_seotitle',$zbp->Config('orangecms')->seotitle); //网站关键词
	$template->SetTags('orangecms_description',$zbp->Config('orangecms')->description); //网站首页描述
	$template->SetTags('orangecms_keyword',$zbp->Config('orangecms')->keyword); //网站关键词
	$template->SetTags('orangecms_contentad',$zbp->Config('orangecms')->contentad); //top导航处广告
	$template->SetTags('orangecms_Displaycontentad',$zbp->Config('orangecms')->Displaycontentad); //开启或关闭top导航处广告
	$template->SetTags('orangecms_contentadx',$zbp->Config('orangecms')->contentadx); //内容页文章相关文章上面广告
	$template->SetTags('orangecms_Displaycontentadx',$zbp->Config('orangecms')->Displaycontentadx); //开启或关闭内容页文章相关文章上面广告
	$template->SetTags('orangecms_Displaycomentad',$zbp->Config('orangecms')->Displaycomentad); //开启或关闭评论框下面的广告
	$template->SetTags('orangecms_comentad',$zbp->Config('orangecms')->comentad); //评论框下面的广告
	//其他
    $template->SetTags('orangecms_Abstractwords',$zbp->Config('orangecms')->Abstractwords); //摘要部分文字数量
    $template->SetTags('orangecms_DisplayRelated',$zbp->Config('orangecms')->DisplayRelated); //开启或关闭相关文章
	$template->SetTags('orangecms_GravatarNow',$zbp->Config('orangecms')->GravatarNow); //开启或关闭评论框头像
	$template->SetTags('orangecms_nocate',$zbp->Config('orangecms')->nocate); //在首页显示不显示某一分类id	
	$template->SetTags('orangecms_syhdp',$zbp->Config('orangecms')->syhdp); //在首页幻灯片文章id	
	$template->SetTags('orangecms_syhdp',$zbp->Config('orangecms')->sycate); //在首页分类文章id	
	$template->SetTags('orangecms_syhdp',$zbp->Config('orangecms')->sytuijian); //在首页推荐文章id	
	
	  /*联系方式*/
	  $template->SetTags('orangecms_add1',$zbp->Config('orangecms')->add1); 
    $template->SetTags('orangecms_add2',$zbp->Config('orangecms')->add2); 
	$template->SetTags('orangecms_add3',$zbp->Config('orangecms')->add3);
	$template->SetTags('orangecms_add4',$zbp->Config('orangecms')->add4); 
	
}
function UninstallPlugin_orangecms(){
          global $zbp;
		  //$zbp->DelConfig('orangecms');
          $zbp->RegBuildModule('comments','BuildModule_comments');
	      $zbp->AddBuildModule('comments');
		
	      
}


function InstallPlugin_orangecms(){
	global $zbp;
	if(!$zbp->Config('orangecms')->HasKey('Version')){
		$zbp->Config('orangecms')->Version = '1.0';
         //基本设置（初始化）
		 $zbp->Config('orangecms')->seotitle = '新乡志远网络公司seotitle';
		$zbp->Config('orangecms')->description = '新乡志远网络公司description';//网站首页描述 
		$zbp->Config('orangecms')->keyword = '新乡志远网络公keyword'; //网站首页关键词
		//广告管理
		$zbp->Config('orangecms')->contentad = '广告内容';//内容页文章内广告
		$zbp->Config('orangecms')->Displaycontentad = '1';//开启关闭top广告
		$zbp->Config('orangecms')->contentadx = '广告内容';//内容页文章下面广告
		$zbp->Config('orangecms')->Displaycontentadx = '1';//开启关闭内容页文章下面广告
		$zbp->Config('orangecms')->comentad = '广告内容';//评论框下面广告
		$zbp->Config('orangecms')->Displaycomentad = '1';//开启关闭评论框下面广告
		//其他	
		
		$zbp->Config('orangecms')->add1 = '10000@qq.com';
	$zbp->Config('orangecms')->add2 = '10000000';
	$zbp->Config('orangecms')->add3 = 'http://weibo.com';
	$zbp->Config('orangecms')->add4 = '© 2018 <a href="http://demo.xxzhiyuan.cn/orangecms/">我的网站</a>&nbsp;Powered By <a href="http://www.zblogcn.com/" title="RainbowSoft Z-BlogPHP" target="_blank">Z-BlogPHP</a>&nbsp;Theme By <a href="http://www.xxzhiyuan.cn/" title="ZBlog模板" target="_blank">ZBlog模板</a>&nbsp;备案信息';
		
		$zbp->Config('orangecms')->Abstractwords = '150';//摘要部分文字数量，默认150
		$zbp->Config('orangecms')->DisplayAbstractwords='0';
		$zbp->Config('orangecms')->DisplayRelated = '1';//开启或关闭相关文章
		$zbp->Config('orangecms')->GravatarNow = '1';//开启或关闭评论框头像
		$zbp->Config('orangecms')->nocate='分类id';
		$zbp->Config('orangecms')->sycate='1';
	$zbp->Config('orangecms')->sytuijian='1';
	$zbp->Config('orangecms')->syhdp='1';
		$zbp->SaveConfig('orangecms');

	}
	$zbp->Config('orangecms')->Version = '1.0';
	$zbp->SaveConfig('orangecms');
	
}

function orangecms_cms(){
global $zbp;
$flids = explode(',',$zbp->Config('orangecms')->sycate);
$s='';
foreach ($flids as $key=> $flid){
$newlists=GetList(1,$flid);
if($key%2==0){
$s .='<section class="catebox"><h3 class="title">'.$zbp->categorys[$flid]->Name.'</h3><span class="more"><a href="'.$zbp->categorys[$flid]->Url.'" target="_blank">更多</a></span>';		
}
else{
$s .='<section class="catebox"><h3 class="title">'.$zbp->categorys[$flid]->Name.'</h3><span class="more"><a href="'.$zbp->categorys[$flid]->Url.'" target="_blank">更多</a></span>';	
}
foreach($newlists as $article){
$s .='<div class="first"><div class="thumbnail"><mip-img src="'.fangmid_thumbnail($article).'" alt="'.$article->Title.'"></mip-img></div><h4><a href="'.$article->Url.'" title="'.$article->Title.'" target="_blank">'.$article->Title.'</a></h4><div class="postmeta"><span><time>'.$article->Time('Y-m-d').'</time></span></div><div class="excerpt">'.preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($article->Content,'[nohtml]'),50)).'...').'</div></div>';}
$newlists2=GetList(6,$flid);
foreach($newlists2 as $key=> $article){
if($key>0){
$s .='<div class="boxitem"><div class="thumbnail"><mip-img src="'.fangmid_thumbnail($article).'" alt="'.$article->Title.'"></mip-img></div><h4><a href="'.$article->Url.'" target="_blank" title="'.$article->Title.'">'.$article->Title.'</a></h4>	<div class="postmeta"><span><i class="far fa-clock"></i> <time>'.$article->Time('Y-m-d').'</time></span>	</div></div>';
}	
}
$s .='</section>';
}
return $s;
}

function orangecms_thumbnail($related) {
    global $zbp;	
	$temp=mt_rand(1,10);
	$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
	$content = $related->Content; 
	preg_match_all($pattern,$content,$matchContent);
	if(isset($matchContent[1][0])){
		$thumb=$matchContent[1][0]; 
	}else{
		$thumb=$zbp->host . "zb_users/theme/" .$zbp->theme. "/style/random/" .$temp. ".jpg";
	}
    return $thumb;
}

function orangecms_description($as,$type,$long,$other) {
    global $zbp;
    $str = '';
    if ($type=='0') {
    //$str .= preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($as->Intro,'[nohtml]'),$long)).$other);
	$str .= trim(SubStrUTF8(TransferHTML($as->Intro,'[nohtml]'),$long)).$other;
    } else {
    //$str .= preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($as->Content,'[nohtml]'),$long)).$other);
	$str .= trim(SubStrUTF8(TransferHTML($as->Content,'[nohtml]'),$long)).$other;
    }
    return $str;
}
function orangecms_hottag(){//top10 tag
        global $zbp,$str;
        $str = '';
        $array = $zbp->GetTagList('','',array('tag_Count'=>'DESC'),array(5),'');
        foreach ($array as $tag) {
            $str .= "<a href=\"{$tag->Url}\" title=\"{$tag->Name}\">{$tag->Name}</a>";
        }
        return $str;
    }
	
	function orangecms_cloud(){//top10 tag
        global $zbp,$str;
        $str = '';
        $array = $zbp->GetTagList('','',array('tag_Count'=>'DESC'),array(15),'');
        foreach ($array as $tag) {
            $str .= "<a href=\"{$tag->Url}\" title=\"{$tag->Name}\">{$tag->Name}</a>";
        }
        return $str;
    }
?>
