<?php
#注册插件
RegisterPlugin("sf_skin2","ActivePlugin_sf_skin2");
require dirname(__FILE__).'/sf_skin2.php';
function ActivePlugin_sf_skin2() {
	Add_Filter_Plugin('Filter_Plugin_Admin_TopMenu','sf_skin2_AddMenu');
	Add_Filter_Plugin('Filter_Plugin_Zbp_Load','sf_skin2_load');
	Add_Filter_Plugin('Filter_Plugin_Edit_Response3','sf_skin2_Response3');
	Add_Filter_Plugin('Filter_Plugin_PostArticle_Succeed','sf_skin2_Succeed');	
	Add_Filter_Plugin('Filter_Plugin_Index_Begin','sf_skin2_begin');
	Add_Filter_Plugin('Filter_Plugin_Index_End','sf_skin2_end');
}
function InstallPlugin_sf_skin2() {
	global $zbp;
	$zbp->RegBuildModule('comments','sf_skin2_Avatarcomments');
	$zbp->RegBuildModule('tags','sf_skin2_tags');
}
function UninstallPlugin_sf_skin2() {
	global $zbp;
	$zbp->AddBuildModule('comments');
	$zbp->AddBuildModule('tags');
}


function sf_skin2_Succeed(&$article){
	global $zbp;
	if(isset($_POST['sf_skin2_xingji'])){
		$article->Metas->sf_skin2_xingji=$_POST['sf_skin2_xingji'];
	}
	$article->Save();
}

function sf_skin2_Response3(){
	global $zbp;
	global $article;
	echo '<dl style="padding-left:10px;">';
	echo '<dt></dt>';
	echo '<dd><b>文章星级</b>&nbsp;<select name="sf_skin2_xingji"><option value ="10">5星</option><option value ="9">4星半</option><option value ="8">4星</option><option value ="7">3星半</option><option value ="6">3星</option><option value ="5">2星半</option><option value ="4">2星</option><option value ="3">1星半</option><option value ="2">1星</option><option value ="1">半星</option><option value ="0">无星</option></select>';
	echo '</dl>';
	$xingji=$article->Metas->sf_skin2_xingji;
	if(empty($xingji)){
		$xingji=10;
	}
	echo '<script type=\'text/javascript\'>jQuery(\'select[name="sf_skin2_xingji"]\').find(\'option[value="'.$xingji.'"]\').attr(\'selected\',true);</script>';
}

function sf_skin2_tags(){
	global $zbp;
	$str = '';
	$i = $zbp->modulesbyfilename['tags']->MaxLi;
	if ($i == 0) $i = 33;
	$array = $zbp->GetTagList('','',array('tag_Count'=>'DESC'),array($i),'');
	foreach ($array as $tag) {
		$str .= '<a title="' . $tag->Name . '" href="' . $tag->Url . '">' . $tag->Name . '<span class="tag-count"> (' . $tag->Count . ')</span></a>';
	}
	return $str;
}

function sf_skin2_Avatarcomments() {
	global $zbp;

	$i = $zbp->modulesbyfilename['comments']->MaxLi;
	if ($i == 0) $i = 10;
	$comments = $zbp->GetCommentList('*', array(array('=', 'comm_IsChecking', 0)), array('comm_PostTime' => 'DESC'), $i, null);
	$s = '';
	foreach ($comments as $comment) {
		$s .= '<li class="cmtface"><a href="' . $comment->Post->Url .'#cmt' . $comment->ID .'" title="'.$comment->Time('Y年m月d日 H:i:s').'  post by '.$comment->Author->StaticName.'"><img src="'.$comment->Author->Avatar.'" height="36" width="36" class="side_avatar"/>'.$comment->Author->StaticName.'<span class="muted">：<br>' . TransferHTML($comment->Content, '[noenter]') . '</span></a></li>';
	}
	return $s;
}

function sf_skin2_load(){
	global $zbp;
	$zbp->RegBuildModule('comments','sf_skin2_Avatarcomments');
	$zbp->RegBuildModule('tags','sf_skin2_tags');
}

function sf_skin2_begin(){
	global $zbp;
	if(!isset($zbp->modulesbyfilename['sf_skin2_3tag']))
	{
		$t = new Module();
		$t->Name = "随机/热门/热评文章";
		$t->FileName = "sf_skin2_3tag";
		$t->Source = "plugin_sf_skin2";
		$t->SidebarID = 0;
		$t->Content = "";
		$t->IsHideTitle=true;
		$t->HtmlID = "sf_skin2_3tag";
 		$t->Type = "div";
		$t->Content = '';
		$t->Save();
	}
	SF_skin2::indexbegin();
}



function sf_skin2_end(){
	SF_skin2::indexend();
	
}



function sf_skin2_AddMenu(&$m){
	global $zbp;
	$m[]=MakeTopMenu("root",'主题配置',$zbp->host . "zb_users/theme/sf_skin2/main.php","","topmenu_sf_skin2");
}