block.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 649 行 · 第 1/2 页
PHP
649 行
global $xoopsDB;
static $access_cats;
$block = array();
if(!isset($access_cats)){
$permission_handler =& xoops_getmodulehandler("permission", $GLOBALS["artdirname"]);
$access_cats = $permission_handler->getCategories("access");
}
if (!empty($options[3])) {
$allowed_cats = array_filter(array_slice($options, 3));
}else{
$allowed_cats = $access_cats;
}
$allowed_cats = array_intersect($allowed_cats, $access_cats);
if( count($allowed_cats) ==0 ) {
return $block;
}
$artConfig = art_load_config();
art_define_url_delimiter();
mod_loadFunctions("time", $GLOBALS["artdirname"]);
$spotlight_handler =& xoops_getmodulehandler("spotlight", $GLOBALS["artdirname"]);
$sp_data = $spotlight_handler->getContent(false);
foreach($sp_data as $key => $val){
$block["spotlight"][$key] = $val;
}
if(empty($options[0])):
$sql = " SELECT art_id, art_title, art_time_publish, cat_id, ( art_comments + art_trackbacks ) AS comments ".
" FROM " . art_DB_prefix("article").
" WHERE cat_id IN (" . implode(",", $allowed_cats) . ") ".
" AND art_time_publish >0 ".
" ORDER BY art_time_publish DESC";
if (!$result = $xoopsDB->query($query, $options[1], 0)) {
xoops_error($xoopsDB->error());
return $block;
}
$articles = array();
$cids = array();
while ($row = $xoopsDB->fetchArray($result)) {
$_art = array();
if(!empty($options[2])){
$row["art_title"] = xoops_substr($row["art_title"], 0, $options[2]);
}
$_art["title"] = htmlspecialchars($row["art_title"]);
$_art["time"] = art_formatTimestamp($row["art_time_publish"]);
$_art["comments"] = $row["comments"];
$_art["category"] = $row["cat_id"];
$articles[$row["art_id"]] = $_art;
$cids[$row["cat_id"]] = 1;
}
$category_handler =& xoops_getmodulehandler("category", $GLOBALS["artdirname"]);
$criteria = new Criteria("cat_id", "(".implode(",",array_keys($cids)).")", "IN");
$category_list = $category_handler->getList($criteria);
foreach(array_keys($articles) as $id){
$articles[$id]["category"] = $category_list[$articles[$id]["category"]];
}
$categories = array();
$categories_top = $category_handler->getIds(new Criteria("cat_pid", 0));
foreach(array_intersect($categories_top, array_keys($category_list)) as $cid) {
$categories[$cid] = $category_list[$cid];
}
$block["articles"] =& $articles;
$block["categories"] =& $categories;
else:
$articles_id = array();
$criteria = new Criteria("cat_id", "(".implode(",", $allowed_cats).")", "IN");
$categories_obj = $category_handler->getAll($criteria, array("cat_title", "cat_lastarticles"));
foreach(array_keys($categories_obj) as $id){
$articles_id = array_merge($articles_id, $category_handler->getLastArticleIds($categories_obj[$id], $options[1]));
}
$sql = " SELECT art_id, art_title, art_time_publish, ( art_comments + art_trackbacks ) AS comments ".
" FROM " . art_DB_prefix("article").
" WHERE art_id IN (" . implode(",", array_unique($articles_id)) . ") ";
if (!$result = $xoopsDB->query($query, $options[1], 0)) {
xoops_error($xoopsDB->error());
return $block;
}
$articles = array();
while ($row = $xoopsDB->fetchArray($result)) {
$_art = array();
if(!empty($options[2])){
$row["art_title"] = xoops_substr($row["art_title"], 0, $options[2]);
}
$_art["title"] = htmlspecialchars($row["art_title"]);
$_art["time"] = art_formatTimestamp($row["art_time_publish"]);
$_art["comments"] = $row["comments"];
$articles[$row["art_id"]] = $_art;
}
$categories = array();
foreach(array_keys($categories_obj) as $id){
$category =& $categories_obj[$id];
$cat = array(
"id" => $id,
"title" => $category->getVar("cat_title"),
"image" => $category->getImage(),
"articles" => array(),
);
$articles_category_id = $category_handler->getLastArticleIds($category, $options[1]);
foreach($articles_category_id as $art_id){
if(!isset($articles[$art_id])) continue;
$cat["articles"][] =& $articles[$art_id];
}
$categories[$id] = $cat;
unset($cat);
}
$block["categories"] =& $categories;
endif;
$block["dirname"] = $GLOBALS["artdirname"];
return $block;
}
function [VAR_PREFIX]_news_edit($options)
{
$form = art_constant("MB_SPECIFIED_ONLY")." <input type=\"radio\" name=\"options[0]\" value=\"1\"";
if ($options[0] == 1) $form .= " checked=\"checked\"";
$form .= " />"._YES."<input type=\"radio\" name=\"options[0]\" value=\"0\"";
if ($options[0] == 0) $form .= " checked=\"checked\"";
$form .= " />"._NO."<br />";
$form .= art_constant("MB_SHOW_NOTE")." <input type=\"radio\" name=\"options[1]\" value=\"1\"";
if ($options[1] == 1) $form .= " checked=\"checked\"";
$form .= " />"._YES."<input type=\"radio\" name=\"options[1]\" value=\"0\"";
if ($options[1] == 0) $form .= " checked=\"checked\"";
$form .= " />"._NO."<br />";
return $form;
}
/**#@-*/
/**#@+
* Function to display categories
*
* {@link Xcategory}
* {@link config}
*
* @param array $options (not used)
*/
function [VAR_PREFIX]_category_show($options)
{
art_define_url_delimiter();
$block = array();
$category_handler =& xoops_getmodulehandler("category", $GLOBALS["artdirname"]);
$categories = $category_handler->getTree();
$cats_counts = $category_handler->getArticleCounts(array_keys($categories));
foreach($categories as $id => $cat){
$block["categories"][] = array(
"cat_id" => $id,
"cat_title" => $cat["prefix"].$cat["cat_title"],
"articles" => @$cats_counts[$id]);
}
$block["dirname"] = $GLOBALS["artdirname"];
unset($categories, $cats_stats);
return $block;
}
/**#@-*/
/**#@+
* Function to display topics
*
* {@link Xtopic}
* {@link Xcategory}
* {@link permission}
* {@link config}
*
* @param array $options:
* 0 - limit for topic count;
* 1 - allowed categories;
*/
function [VAR_PREFIX]_topic_show($options)
{
global $xoopsDB;
static $access_cats;
art_define_url_delimiter();
$block = array();
if(!isset($access_cats)){
$permission_handler =& xoops_getmodulehandler("permission", $GLOBALS["artdirname"]);
$access_cats = $permission_handler->getCategories("access"); // get all accessible categories
}
if (!empty($options[1])) {
$allowed_cats = array_filter(array_slice($options, 1)); // get allowed cats
}else{
$allowed_cats = $access_cats;
}
mod_loadFunctions("user", $GLOBALS["artdirname"]);
if(!art_isAdministrator()){
$allowed_cats = array_intersect($allowed_cats, $access_cats);
}
if( count($allowed_cats) == 0 ) return $block;
$query = "SELECT top_id, top_title, top_time, cat_id FROM " . art_DB_prefix("topic");
$query .= " WHERE cat_id IN (" . implode(",", $allowed_cats) . ") ";
$query .= " ORDER BY top_time DESC";
$result = $xoopsDB->query($query, $options[0], 0);
if (!$result) {
xoops_error($xoopsDB->error());
return $block;
}
$tops = array();
$cids = array();
$topic_handler =& xoops_getmodulehandler("topic", $GLOBALS["artdirname"]);
while ($row = $xoopsDB->fetchArray($result)) {
$topic =& $topic_handler->create(false);
$topic->assignVars($row);
$_top = array();
foreach($row as $tag=>$val) {
$_top[$tag] = $topic->getVar($tag);
}
$_top["time"] = $topic->getTime();
$tops[] = $_top;
unset($topic, $_top);
$cids[$row["cat_id"]] = 1;
}
$category_handler =& xoops_getmodulehandler("category", $GLOBALS["artdirname"]);
$criteria = new Criteria("cat_id", "(".implode(",",array_keys($cids)).")", "IN");
$cats = $category_handler->getList($criteria);
for($i=0;$i<count($tops);$i++){
$tops[$i]["category"]=$cats[$tops[$i]["cat_id"]];
}
$block["topics"] = $tops;
unset($cats, $tops);
$block["dirname"] = $GLOBALS["artdirname"];
return $block;
}
function [VAR_PREFIX]_topic_edit($options)
{
$form = art_constant("MB_ITEMS")." <input type=\"text\" name=\"options[0]\" value=\"" . $options[0] . "\" /><br /><br />";
$category_handler =& xoops_getmodulehandler("category", $GLOBALS["artdirname"]);
$isAll = empty($options[1]);
$options_cat = array_slice($options, 1); // get allowed categories
$form .= art_constant("MB_CATEGORYLIST")." <select name=\"options[]\" multiple=\"multiple\">";
$form .= "<option value=\"0\" ";
if ($isAll) $form .= " selected=\"selected\"";
$form .= ">"._ALL."</option>";
$categories = $category_handler->getTree(0, "moderate", "----");
foreach($categories as $id=>$cat){
$sel = ($isAll || in_array($id, $options_cat))?" selected":"";
$form .= "<option value=\"$id\" $sel>".$cat["prefix"].$cat["cat_title"]."</option>";
}
$form .= "</select><br />";
return $form;
}
/**#@-*/
/**#@+
* Function to display authors
*
* {@link config}
*
* @param array $options:
* 0 - limit for author count;
*/
function [VAR_PREFIX]_author_show($options)
{
global $xoopsDB;
$block = array();
$artConfig = art_load_config();
art_define_url_delimiter();
$query = "SELECT COUNT(*) AS count, uid".
" FROM " . art_DB_prefix("article").
" WHERE art_time_publish>0 AND uid>0".
" GROUP BY uid ORDER BY count DESC";
$result = $xoopsDB->query($query, $options[0], 0);
if (!$result) {
xoops_error($xoopsDB->error());
return $block;
}
$rows = array();
$author = array();
while ($row = $xoopsDB->fetchArray($result)) {
$rows[] = $row;
$author[$row["uid"]] = 1;
}
if (count($rows) < 1) return $block;
mod_loadFunctions("user", $GLOBALS["artdirname"]);
$author_name = art_getUnameFromId(array_keys($author));
foreach ($rows as $row) {
$block["authors"][] = array( "uid"=>$row["uid"], "name"=>$author_name[$row["uid"]], "articles"=>$row["count"]);
}
$block["dirname"] = $GLOBALS["artdirname"];
return $block;
}
function [VAR_PREFIX]_author_edit($options)
{
$form = art_constant("MB_ITEMS")." <input type=\"text\" name=\"options[0]\" value=\"" . $options[0] . "\" /><br /><br />";
return $form;
}
/**#@-*/
');
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?