ConvertArray() public static method

将数组数据转换为Metas实例
public static ConvertArray ( array $a ) : Metas
$a array
return Metas
Example #1
0
 /**
  * 导出用户列表模块数据
  * @param int $level 要导出的用户最低等级,默认为4(即协作者)
  * @return string 模块内容
  */
 public static function Authors($level = 4)
 {
     global $zbp;
     $template = $zbp->template;
     $tags = array();
     $authors = array();
     $w = array();
     $w[] = array('<=', 'mem_Level', $level);
     $array = $zbp->GetMemberList('*', $w, array('mem_ID' => 'ASC'), null, null);
     foreach ($array as $member) {
         $m = Metas::ConvertArray($member->GetData());
         unset($m->Guid);
         unset($m->Password);
         $authors[] = $m;
     }
     $tags['authors'] = $authors;
     $template->SetTagsAll($tags);
     $ret = $template->Output('module-authors');
     return $ret;
 }
Example #2
0
function ViewList($page, $cate, $auth, $date, $tags, $isrewrite = false)
{
    global $zbp;
    foreach ($GLOBALS['Filter_Plugin_ViewList_Begin'] as $fpname => &$fpsignal) {
        $fpreturn = $fpname($page, $cate, $auth, $date, $tags);
        if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
            return $fpreturn;
        }
    }
    //if($cate=='index.php'|$auth=='index.php'|$date=='index.php'|$tags=='index.php'){
    //	$cate=$auth=$date=$tags=null;
    //}
    $type = 'index';
    if ($cate !== null) {
        $type = 'category';
    }
    if ($auth !== null) {
        $type = 'author';
    }
    if ($date !== null) {
        $type = 'date';
    }
    if ($tags !== null) {
        $type = 'tag';
    }
    $category = null;
    $author = null;
    $datetime = null;
    $tag = null;
    $w = array();
    $w[] = array('=', 'log_Istop', 0);
    $w[] = array('=', 'log_Status', 0);
    $page = (int) $page == 0 ? 1 : (int) $page;
    $articles_top = array();
    $articles = array();
    if ($type == 'index' && $page == 1) {
        $articles_top = $zbp->GetArticleList(array('*'), array(array('=', 'log_Istop', 1), array('=', 'log_Status', 0)), array('log_PostTime' => 'DESC'), null, null);
    }
    switch ($type) {
        ########################################################################################################
        case 'index':
            $pagebar = new Pagebar($zbp->option['ZC_INDEX_REGEX']);
            $pagebar->Count = $zbp->cache->normal_article_nums;
            $category = new Metas();
            $author = new Metas();
            $datetime = new Metas();
            $tag = new Metas();
            $template = $zbp->option['ZC_INDEX_DEFAULT_TEMPLATE'];
            if ($page == 1) {
                $zbp->title = $zbp->subname;
            } else {
                $zbp->title = str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            break;
            ########################################################################################################
        ########################################################################################################
        case 'category':
            $pagebar = new Pagebar($zbp->option['ZC_CATEGORY_REGEX']);
            $author = new Metas();
            $datetime = new Metas();
            $tag = new Metas();
            $category = new Category();
            if (strpos($zbp->option['ZC_CATEGORY_REGEX'], '{%id%}') !== false) {
                $category = $zbp->GetCategoryByID($cate);
            }
            if (strpos($zbp->option['ZC_CATEGORY_REGEX'], '{%alias%}') !== false) {
                $category = $zbp->GetCategoryByAliasOrName($cate);
            }
            if ($category->ID == 0) {
                if ($isrewrite == true) {
                    return ZC_REWRITE_GO_ON;
                }
                $zbp->ShowError(2);
            }
            if ($page == 1) {
                $zbp->title = $category->Name;
            } else {
                $zbp->title = $category->Name . ' ' . str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            $template = $category->Template;
            if (!$zbp->option['ZC_DISPLAY_SUBCATEGORYS']) {
                $w[] = array('=', 'log_CateID', $category->ID);
                $pagebar->Count = $category->Count;
            } 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);
            }
            $pagebar->UrlRule->Rules['{%id%}'] = $category->ID;
            $pagebar->UrlRule->Rules['{%alias%}'] = $category->Alias == '' ? urlencode($category->Name) : $category->Alias;
            break;
            ########################################################################################################
        ########################################################################################################
        case 'author':
            $pagebar = new Pagebar($zbp->option['ZC_AUTHOR_REGEX']);
            $category = new Metas();
            $datetime = new Metas();
            $tag = new Metas();
            $author = new Member();
            if (strpos($zbp->option['ZC_AUTHOR_REGEX'], '{%id%}') !== false) {
                $author = $zbp->GetMemberByID($auth);
            }
            if (strpos($zbp->option['ZC_AUTHOR_REGEX'], '{%alias%}') !== false) {
                $author = $zbp->GetMemberByAliasOrName($auth);
            }
            if ($author->ID == 0) {
                if ($isrewrite == true) {
                    return ZC_REWRITE_GO_ON;
                }
                $zbp->ShowError(2);
            }
            if ($page == 1) {
                $zbp->title = $author->Name;
            } else {
                $zbp->title = $author->Name . ' ' . str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            $template = $author->Template;
            $w[] = array('=', 'log_AuthorID', $author->ID);
            $pagebar->Count = $author->Articles;
            $pagebar->UrlRule->Rules['{%id%}'] = $author->ID;
            $pagebar->UrlRule->Rules['{%alias%}'] = $author->Alias == '' ? urlencode($author->Name) : $author->Alias;
            break;
            ########################################################################################################
        ########################################################################################################
        case 'date':
            $pagebar = new Pagebar($zbp->option['ZC_DATE_REGEX']);
            $category = new Metas();
            $author = new Metas();
            $tag = new Metas();
            $datetime = strtotime($date);
            $datetitle = str_replace(array('%y%', '%m%'), array(date('Y', $datetime), date('n', $datetime)), $zbp->lang['msg']['year_month']);
            if ($page == 1) {
                $zbp->title = $datetitle;
            } else {
                $zbp->title = $datetitle . ' ' . str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            $zbp->modulesbyfilename['calendar']->Content = BuildModule_calendar(date('Y', $datetime) . '-' . date('n', $datetime));
            $template = $zbp->option['ZC_INDEX_DEFAULT_TEMPLATE'];
            $w[] = array('BETWEEN', 'log_PostTime', $datetime, strtotime('+1 month', $datetime));
            $pagebar->UrlRule->Rules['{%date%}'] = $date;
            $datetime = Metas::ConvertArray(getdate($datetime));
            break;
            ########################################################################################################
        ########################################################################################################
        case 'tag':
            $pagebar = new Pagebar($zbp->option['ZC_TAGS_REGEX']);
            $category = new Metas();
            $author = new Metas();
            $datetime = new Metas();
            $tag = new Tag();
            if (strpos($zbp->option['ZC_TAGS_REGEX'], '{%id%}') !== false) {
                $tag = $zbp->GetTagByID($tags);
            }
            if (strpos($zbp->option['ZC_TAGS_REGEX'], '{%alias%}') !== false) {
                $tag = $zbp->GetTagByAliasOrName($tags);
            }
            if ($tag->ID == 0) {
                if ($isrewrite == true) {
                    return ZC_REWRITE_GO_ON;
                }
                $zbp->ShowError(2);
            }
            if ($page == 1) {
                $zbp->title = $tag->Name;
            } else {
                $zbp->title = $tag->Name . ' ' . str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            $template = $tag->Template;
            $w[] = array('LIKE', 'log_Tag', '%{' . $tag->ID . '}%');
            $pagebar->UrlRule->Rules['{%id%}'] = $tag->ID;
            $pagebar->UrlRule->Rules['{%alias%}'] = $tag->Alias == '' ? urlencode($tag->Name) : $tag->Alias;
            break;
    }
    $pagebar->PageCount = $zbp->displaycount;
    $pagebar->PageNow = $page;
    $pagebar->PageBarCount = $zbp->pagebarcount;
    $pagebar->UrlRule->Rules['{%page%}'] = $page;
    $articles = $zbp->GetArticleList(array('*'), $w, array('log_PostTime' => 'DESC'), array(($pagebar->PageNow - 1) * $pagebar->PageCount, $pagebar->PageCount), array('pagebar' => $pagebar));
    $zbp->template->SetTags('title', $zbp->title);
    $zbp->template->SetTags('articles', array_merge($articles_top, $articles));
    if ($pagebar->PageAll == 0) {
        $pagebar = null;
    }
    $zbp->template->SetTags('pagebar', $pagebar);
    $zbp->template->SetTags('type', $type);
    $zbp->template->SetTags('page', $page);
    $zbp->template->SetTags('date', $datetime);
    $zbp->template->SetTags('tag', $tag);
    $zbp->template->SetTags('author', $author);
    $zbp->template->SetTags('category', $category);
    if (isset($zbp->templates[$template])) {
        $zbp->template->SetTemplate($template);
    } else {
        $zbp->template->SetTemplate('index');
    }
    foreach ($GLOBALS['Filter_Plugin_ViewList_Template'] as $fpname => &$fpsignal) {
        $fpreturn = $fpname($zbp->template);
    }
    $zbp->template->Display();
}
Example #3
0
/**
 * 显示列表页面
 * @api Filter_Plugin_ViewList_Begin
 * @api Filter_Plugin_ViewList_Template
 * @param int $page
 * @param int|string $cate
 * @param int|string $auth
 * @param string   $date
 * @param string $tags tags列表
 * @param bool $isrewrite 是否启用urlrewrite
 * @return string
 */
function ViewList($page, $cate, $auth, $date, $tags, $isrewrite = false)
{
    global $zbp;
    foreach ($GLOBALS['hooks']['Filter_Plugin_ViewList_Begin'] as $fpname => &$fpsignal) {
        $fpreturn = $fpname($page, $cate, $auth, $date, $tags);
        if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
            $fpsignal = PLUGIN_EXITSIGNAL_NONE;
            return $fpreturn;
        }
    }
    $type = 'index';
    if ($cate !== null) {
        $type = 'category';
    }
    if ($auth !== null) {
        $type = 'author';
    }
    if ($date !== null) {
        $type = 'date';
    }
    if ($tags !== null) {
        $type = 'tag';
    }
    $category = null;
    $author = null;
    $datetime = null;
    $tag = null;
    $w = array();
    $w[] = array('=', 'log_IsTop', 0);
    $w[] = array('=', 'log_Status', 0);
    $page = (int) $page == 0 ? 1 : (int) $page;
    $articles = array();
    $articles_top = array();
    switch ($type) {
        ########################################################################################################
        case 'index':
            $pagebar = new Pagebar($zbp->option['ZC_INDEX_REGEX']);
            $pagebar->Count = $zbp->cache->normal_article_nums;
            $template = $zbp->option['ZC_INDEX_DEFAULT_TEMPLATE'];
            if ($page == 1) {
                $zbp->title = $zbp->subname;
            } else {
                $zbp->title = str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            break;
            ########################################################################################################
        ########################################################################################################
        case 'category':
            $pagebar = new Pagebar($zbp->option['ZC_CATEGORY_REGEX']);
            $category = new Category();
            if (!is_array($cate)) {
                $cateId = $cate;
                $cate = array();
                if (strpos($zbp->option['ZC_CATEGORY_REGEX'], '{%id%}') !== false) {
                    $cate['id'] = $cateId;
                }
                if (strpos($zbp->option['ZC_CATEGORY_REGEX'], '{%alias%}') !== false) {
                    $cate['alias'] = $cateId;
                }
            }
            if (isset($cate['id'])) {
                $category = $zbp->GetCategoryByID($cate['id']);
            } else {
                $category = $zbp->GetCategoryByAlias($cate['alias']);
            }
            if ($category->ID == 0) {
                if ($isrewrite == true) {
                    return false;
                }
                $zbp->ShowError(2, __FILE__, __LINE__);
            }
            if ($page == 1) {
                $zbp->title = $category->Name;
            } else {
                $zbp->title = $category->Name . ' ' . str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            $template = $category->Template;
            if (!$zbp->option['ZC_DISPLAY_SUBCATEGORYS']) {
                $w[] = array('=', 'log_CateID', $category->ID);
                $pagebar->Count = $category->Count;
            } else {
                $arysubcate = array();
                $arysubcate[] = array('log_CateID', $category->ID);
                foreach ($zbp->categories[$category->ID]->ChildrenCategories as $subcate) {
                    $arysubcate[] = array('log_CateID', $subcate->ID);
                }
                $w[] = array('array', $arysubcate);
            }
            $pagebar->UrlRule->Rules['{%id%}'] = $category->ID;
            $pagebar->UrlRule->Rules['{%alias%}'] = $category->Alias == '' ? rawurlencode($category->Name) : $category->Alias;
            break;
            ########################################################################################################
        ########################################################################################################
        case 'author':
            $pagebar = new Pagebar($zbp->option['ZC_AUTHOR_REGEX']);
            $author = new Member();
            if (!is_array($auth)) {
                $authId = $auth;
                $auth = array();
                if (strpos($zbp->option['ZC_AUTHOR_REGEX'], '{%id%}') !== false) {
                    $auth['id'] = $authId;
                }
                if (strpos($zbp->option['ZC_AUTHOR_REGEX'], '{%alias%}') !== false) {
                    $auth['alias'] = $authId;
                }
            }
            if (isset($auth['id'])) {
                $author = $zbp->GetMemberByID($auth['id']);
            } else {
                $author = $zbp->GetMemberByAliasOrName($auth['alias']);
            }
            if ($author->ID == 0) {
                if ($isrewrite == true) {
                    return false;
                }
                $zbp->ShowError(2, __FILE__, __LINE__);
            }
            if ($page == 1) {
                $zbp->title = $author->StaticName;
            } else {
                $zbp->title = $author->StaticName . ' ' . str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            $template = $author->Template;
            $w[] = array('=', 'log_AuthorID', $author->ID);
            $pagebar->Count = $author->Articles;
            $pagebar->UrlRule->Rules['{%id%}'] = $author->ID;
            $pagebar->UrlRule->Rules['{%alias%}'] = $author->Alias == '' ? rawurlencode($author->Name) : $author->Alias;
            break;
            ########################################################################################################
        ########################################################################################################
        case 'date':
            $pagebar = new Pagebar($zbp->option['ZC_DATE_REGEX']);
            if (!is_array($date)) {
                $datetime = $date;
            } else {
                $datetime = $date['date'];
            }
            $dateregex_ymd = '/[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}/i';
            $dateregex_ym = '/[0-9]{1,4}-[0-9]{1,2}/i';
            if (preg_match($dateregex_ymd, $datetime) == 0 && preg_match($dateregex_ym, $datetime) == 0) {
                return false;
            }
            $datetime_txt = $datetime;
            $datetime = strtotime($datetime);
            if ($datetime == false) {
                return false;
            }
            if (preg_match($dateregex_ymd, $datetime_txt) != 0 && isset($zbp->lang['msg']['year_month_day'])) {
                $datetitle = str_replace(array('%y%', '%m%', '%d%'), array(date('Y', $datetime), date('n', $datetime), date('j', $datetime)), $zbp->lang['msg']['year_month_day']);
            } else {
                $datetitle = str_replace(array('%y%', '%m%'), array(date('Y', $datetime), date('n', $datetime)), $zbp->lang['msg']['year_month']);
            }
            if ($page == 1) {
                $zbp->title = $datetitle;
            } else {
                $zbp->title = $datetitle . ' ' . str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            $zbp->modulesbyfilename['calendar']->Content = ModuleBuilder::Calendar(date('Y', $datetime) . '-' . date('n', $datetime));
            $template = $zbp->option['ZC_INDEX_DEFAULT_TEMPLATE'];
            if (preg_match($dateregex_ymd, $datetime_txt) != 0) {
                $w[] = array('BETWEEN', 'log_PostTime', $datetime, strtotime('+1 day', $datetime));
                $pagebar->UrlRule->Rules['{%date%}'] = date('Y-n-j', $datetime);
            } else {
                $w[] = array('BETWEEN', 'log_PostTime', $datetime, strtotime('+1 month', $datetime));
                $pagebar->UrlRule->Rules['{%date%}'] = date('Y-n', $datetime);
            }
            $datetime = Metas::ConvertArray(getdate($datetime));
            break;
            ########################################################################################################
        ########################################################################################################
        case 'tag':
            $pagebar = new Pagebar($zbp->option['ZC_TAGS_REGEX']);
            $tag = new Tag();
            if (!is_array($tags)) {
                $tagId = $tags;
                $tags = array();
                if (strpos($zbp->option['ZC_TAGS_REGEX'], '{%id%}') !== false) {
                    $tags['id'] = $tagId;
                }
                if (strpos($zbp->option['ZC_TAGS_REGEX'], '{%alias%}') !== false) {
                    $tags['alias'] = $tagId;
                }
            }
            if (isset($tags['id'])) {
                $tag = $zbp->GetTagByID($tags['id']);
            } else {
                $tag = $zbp->GetTagByAliasOrName($tags['alias']);
            }
            if ($tag->ID == 0) {
                if ($isrewrite == true) {
                    return false;
                }
                $zbp->ShowError(2, __FILE__, __LINE__);
            }
            if ($page == 1) {
                $zbp->title = $tag->Name;
            } else {
                $zbp->title = $tag->Name . ' ' . str_replace('%num%', $page, $zbp->lang['msg']['number_page']);
            }
            $template = $tag->Template;
            $w[] = array('LIKE', 'log_Tag', '%{' . $tag->ID . '}%');
            $pagebar->UrlRule->Rules['{%id%}'] = $tag->ID;
            $pagebar->UrlRule->Rules['{%alias%}'] = $tag->Alias == '' ? rawurlencode($tag->Name) : $tag->Alias;
            break;
    }
    $pagebar->PageCount = $zbp->displaycount;
    $pagebar->PageNow = $page;
    $pagebar->PageBarCount = $zbp->pagebarcount;
    $pagebar->UrlRule->Rules['{%page%}'] = $page;
    foreach ($GLOBALS['hooks']['Filter_Plugin_ViewList_Core'] as $fpname => &$fpsignal) {
        $fpname($type, $page, $category, $author, $datetime, $tag, $w, $pagebar);
    }
    if ($zbp->option['ZC_LISTONTOP_TURNOFF'] == false) {
        $articles_top_notorder = $zbp->GetTopArticle();
        foreach ($articles_top_notorder as $articles_top_notorder_post) {
            if ($articles_top_notorder_post->TopType == 'global') {
                $articles_top[] = $articles_top_notorder_post;
            }
        }
        if ($type == 'index' && $page == 1) {
            foreach ($articles_top_notorder as $articles_top_notorder_post) {
                if ($articles_top_notorder_post->TopType == 'index') {
                    $articles_top[] = $articles_top_notorder_post;
                }
            }
        }
        if ($type == 'category') {
            foreach ($articles_top_notorder as $articles_top_notorder_post) {
                if ($articles_top_notorder_post->TopType == 'category' && $articles_top_notorder_post->CateID == $category->ID) {
                    $articles_top[] = $articles_top_notorder_post;
                }
            }
        }
    }
    $select = '*';
    $order = array('log_PostTime' => 'DESC');
    $limit = array(($pagebar->PageNow - 1) * $pagebar->PageCount, $pagebar->PageCount);
    $option = array('pagebar' => $pagebar);
    foreach ($GLOBALS['hooks']['Filter_Plugin_LargeData_Article'] as $fpname => &$fpsignal) {
        $fpreturn = $fpname($select, $w, $order, $limit, $option);
    }
    $articles = $zbp->GetArticleList($select, $w, $order, $limit, $option, true);
    $zbp->template->SetTags('title', $zbp->title);
    $zbp->template->SetTags('articles', array_merge($articles_top, $articles));
    if ($pagebar->PageAll == 0) {
        $pagebar = null;
    }
    $zbp->template->SetTags('pagebar', $pagebar);
    $zbp->template->SetTags('type', $type);
    $zbp->template->SetTags('page', $page);
    $zbp->template->SetTags('date', $datetime);
    $zbp->template->SetTags('tag', $tag);
    $zbp->template->SetTags('author', $author);
    $zbp->template->SetTags('category', $category);
    if ($zbp->template->hasTemplate($template)) {
        $zbp->template->SetTemplate($template);
    } else {
        $zbp->template->SetTemplate('index');
    }
    foreach ($GLOBALS['hooks']['Filter_Plugin_ViewList_Template'] as $fpname => &$fpsignal) {
        $fpreturn = $fpname($zbp->template);
    }
    $zbp->template->Display();
    return true;
}