<?php
/**
* Z-Blog with PHP
* @author
* @copyright (C) RainbowSoft Studio
* @version 2.0 2013-06-14
*/
################################################################################################################
function GetPost($idorname, $option = null) {
global $zbp;
if (!is_array($option)) {
$option = array();
}
if (!isset($option['only_article']))
$option['only_article'] = false;
if (!isset($option['only_page']))
$option['only_page'] = false;
if(is_string($idorname)){
$w[] = array('array', array(array('log_Alias', $idorname), array('log_Title', $idorname)));
if($option['only_article']==true){
$w[]=array('=','log_Type','0');
}
elseif($option['only_page']==true){
$w[]=array('=','log_Type','1');
}
$articles = $zbp->GetPostList('*', $w, null, 1, null);
if (count($articles) == 0) {
return new Post;
}
return $articles[0];
}
if(is_integer($idorname)){
return $zbp->GetPostByID($idorname);
}
}
function GetList($count = 10, $cate = null, $auth = null, $date = null, $tags = null, $search = null, $option = null) {
global $zbp;
if (!is_array($option)) {
$option = array();
}
if (!isset($option['only_ontop']))
$option['only_ontop'] = false;
if (!isset($option['only_not_ontop']))
$option['only_not_ontop'] = false;
if (!isset($option['has_subcate']))
$option['has_subcate'] = false;
if (!isset($option['is_related']))
$option['is_related'] = false;
if ($option['is_related']) {
$at = $zbp->GetPostByID($option['is_related']);
$tags = $at->Tags;
if (!$tags)
return array();
$count = $count + 1;
}
if ($option['only_ontop'] == true) {
$w[] = array('=', 'log_IsTop', 0);
} elseif ($option['only_not_ontop'] == true) {
$w[] = array('=', 'log_IsTop', 1);
}
$w = array();
$w[] = array('=', 'log_Status', 0);
$articles = array();
if ($cate) {
$category = new Category;
$category = $zbp->GetCategoryByID($cate);
if ($category->ID > 0) {
if (!$option['has_subcate']) {
$w[] = array('=', 'log_CateID', $category->ID);
} else {
$arysubcate = array();
$arysubcate[] = array('log_CateID', $category->ID);
foreach ($zbp->categorys[$category->ID]->SubCategorys as $subcate) {
$arysubcate[] = array('log_CateID', $subcate->ID);
}
$w[] = array('array', $arysubcate);
}
}
}
if ($auth) {
$author = new Member;
$author = $zbp->GetMemberByID($auth);
if ($author->ID > 0) {
$w[] = array('=', 'log_AuthorID', $author->ID);
}
}
if ($date) {
$datetime = strtotime($date);
if ($datetime) {
$datetitle = str_replace(array('%y%', '%m%'), array(date('Y', $datetime), date('n', $datetime)), $zbp->lang['msg']['year_month']);
$w[] = array('BETWEEN', 'log_PostTime', $datetime, strtotime('+1 month', $datetime));
}
}
if ($tags) {
$tag = new Tag;
if (is_array($tags)) {
$ta = array();
foreach ($tags as $t) {
$ta[] = array('log_Tag', '%{' . $t->ID . '}%');
}
$w[] = array('array_like', $ta);
unset($ta);
} else {
if (is_int($tags)) {
$tag = $zbp->GetTagByID($tags);
} else {
$tag = $zbp->GetTagByAliasOrName($tags);
}
if ($tag->ID > 0) {
$w[] = array('LIKE', 'log_Tag', '%{' . $tag->ID . '}%');
}
}
}
if ($search) {
$w[] = array('search', 'log_Content', 'log_Intro', 'log_Title', $search);
}
$articles = $zbp->GetArticleList('*', $w, array('log_PostTime' => 'DESC'), $count, null, false);
if ($option['is_related']) {
foreach ($articles as $k => $a) {
if ($a->ID == $option['is_related'])
unset($articles[$k]);
}
if (count($articles) == $count)
$articles = array_pop($articles);
}
return $articles;
}
################################################################################################################
function VerifyLogin() {
global $zbp;
if (isset($zbp->membersbyname[GetVars('username', 'POST')])) {
if ($zbp->Verify_MD5(GetVars('username', 'POST'), GetVars('password', 'POST'))) {
$un = GetVars('username', 'POST');
$ps = md5($zbp->user->Password . $zbp->guid);
if (GetVars('savedate') == 0) {
setcookie("username", $un, 0, $zbp->cookiespath);
setcookie("password", $ps, 0, $zbp->cookiespath);
} else {
setcookie("username", $un, time() + 3600 * 24 * GetVars('savedate', 'POST'), $zbp->cookiespath);
setcookie("password", $ps, time() + 3600 * 24 * GetVars('savedate', 'POST'), $zbp->cookiespath);
}
return true;
} else {
$zbp->ShowError(8, __FILE__, __LINE__);
}
} else {
$zbp->ShowError(8, __FILE__, __LINE__);
}
}
function Logout() {
global $zbp;
setcookie('username', '', time() - 3600, $zbp->cookiespath);
setcookie('password', '', time() - 3600, $zbp->cookiespath);
}
################################################################################################################
function ViewAuto($inpurl) {
global $zbp;
if ($zbp->option['ZC_STATIC_MODE'] == 'ACTIVE') {
$zbp->ShowError(2, __FILE__, __LINE__);
return null;
}
$url=GetValueInArray(explode('?',$inpurl),'0');
if($zbp->cookiespath === substr($url, 0 , strlen($zbp->cookiespath)))
$url = substr($url, strlen($zbp->cookiespath));
if (isset($_SERVER['SERVER_SOFTWARE'])) {
if ((strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false) && (isset($_GET['rewrite']) == true)){
//iis+httpd.ini下如果存在真实文件
$realurl = $zbp->path . urldecode($url);
if(is_readable($realurl)&&is_file($realurl)){
die(file_get_contents($realurl));
}
unset($realurl);
}
}
$url = urldecode($url);
$r = UrlRule::Rewrite_url($zbp->option['ZC_INDEX_REGEX'], 'index');
$m = array();
if (preg_match($r, $url, $m) == 1) {
ViewList($m[1], null, null, null, null, true);
return null;
}
$r = UrlRule::Rewrite_url($zbp->option['ZC_DATE_REGEX'], 'date');
$m = array();
if (preg_match($r, $url, $m) == 1) {
ViewList($m[2], null, null, $m[1], null, true);
return null;
}
$r = UrlRule::Rewrite_url($zbp->option['ZC_AUTHOR_REGEX'], 'auth');
$m = array();
if (preg_match($r, $url, $m) == 1) {
ViewList($m[2], null, $m[1], null, null, true);
return null;
}
$r = UrlRule::Rewrite_url($zbp->option['ZC_TAGS_REGEX'], 'tags');
$m = array();
if (preg_match($r, $url, $m) == 1) {
ViewList($m[2], null, null, null, $m[1], true);
return null;
}
$r = UrlRule::Rewrite_url($zbp->option['ZC_CATEGORY_REGEX'], 'cate');
$m = array();
if (preg_match($r, $url, $m) == 1) {
$result = ViewList($m[2], $m[1], null, null, null, true);
if ($result <> ZC_REWRITE_GO_ON)
return null;
}
$r = UrlRule::Rewrite_url($zbp->option['ZC_ARTICLE_REGEX'], 'article');
$m = array();
if (preg_match($r, $url, $m) == 1) {
if (strpos($zbp->option['ZC_ARTICLE_REGEX'], '{%id%}') !== false) {
$result = ViewPost($m[1], null, true);
} else {
$result = ViewPost(null, $m[1], true);
}
if ($result == ZC_REWRITE_GO_ON)
$zbp->ShowError(2, __FILE__, __LINE__);
return null;
}
$r = UrlRule::Rewrite_url($zbp->option['ZC_PAGE_REGEX'], 'page');
$m = array();
if (preg_match($r, $url, $m) == 1) {
if (strpos($zbp->option['ZC_PAGE_REGEX'], '{%id%}') !== false) {
$result = ViewPost($m[1], null, true);
} else {
$result = ViewPost(null, $m[1], true);
}
if ($result == ZC_REWRITE_GO_ON)
$zbp->ShowError(2, __FILE__, __LINE__);
return null;
}
if($url==''||$url=='index.php'){
return ViewList(null,null,null,null,null);
}
foreach ($GLOBALS['Filter_Plugin_ViewAuto_End'] as $fpname => &$fpsignal) {
$fpreturn = $fpname($url);
if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
return $fpreturn;
}
}
$zbp->ShowError(2, __FILE__, __LINE__);
}
function ViewList($page, $cate, $auth, $date, $tags, $isrewrite = false) {
globa