[html] view plain copy print? |
<?php |
//路径:phpcms/modules/admin/category.php控制器,主要用来完成栏目相关的操作 |
defined( 'IN_PHPCMS' ) or exit ( 'No permission resources.' ); //防止恶意访问 |
pc_base::load_app_class( 'admin' , 'admin' ,0); //加载admin模块下的admin.class.php类库文件 |
|
class category extends admin { |
private $db ; //代表当前category_model类的实例化对象 |
public $siteid ; |
function __construct() { |
parent::__construct(); //父类的构造函数,即:admin.class.php类的构造函数 |
$this ->db = pc_base::load_model( 'category_model' ); //加载 category_model |
$this ->siteid = $this ->get_siteid(); //获取当前的站点ID,父类方法 |
} |
/** |
* 管理栏目 |
*/ |
public function init () { |
$show_pc_hash = '' ; |
$tree = pc_base::load_sys_class( 'tree' ); //加载系统通用的树型类,可以生成任何树型结构,返回一个树类的实例化对象 |
$models = getcache( 'model' , 'commons' ); //获取"caches/caches_commons/caches_data/model.cache.php"中缓存的模型相关数据 |
$sitelist = getcache( 'sitelist' , 'commons' ); //获取"caches/caches_commons/caches_data/sitelist.cache.php"中缓存数据 |
$category_items = array (); //定义一个数组 |
foreach ( $models as $modelid => $model ) { //模型id=>模型信息(模型:文章模型、下载模型、图片模型) |
//$modelid:模型id |
$category_items [ $modelid ] = getcache( 'category_items_' . $modelid , 'commons' ); //当前模型id下所有栏目是否有子栏目,1-有 0-没有 |
} |
$tree ->icon = array ( ' │ ' , ' ├─ ' , ' └─ ' ); //树形图标 |
$tree ->nbsp = ' ' ; //三个空格 |
$categorys = array (); |
//读取缓存 |
$result = getcache( 'category_content_' . $this ->siteid, 'commons' ); //当前站点ID下所有栏目的详细配置信息 |
$show_detail = count ( $result ) < 500 ? 1 : 0; //如果缓存文件中的分类数量小于500,则$show_detail=1 |
$parentid = $_GET [ 'parentid' ] ? intval ( $_GET [ 'parentid' ]) : 0; //此时$parentid=0,代表顶级分类 |
$html_root = pc_base::load_config( 'system' , 'html_root' ); //生成静态文件的路径 ,默认为"/html" |
//0-内部栏目、1-<font color="blue">单网页</font> 、2-<font color="red">外部链接</font> |
$types = array (0 => L( 'category_type_system' ),1 => L( 'category_type_page' ),2 => L( 'category_type_link' )); |
if (! empty ( $result )) { |
foreach ( $result as $r ) { |
$r [ 'modelname' ] = $models [ $r [ 'modelid' ]][ 'name' ]; //空、文章模型、下载模型、图片模型 |
$r [ 'str_manage' ] = '' ; |
if (! $show_detail ) { |
if ( $r [ 'parentid' ]!= $parentid ) continue ; |
$r [ 'parentid' ] = 0; |
$r [ 'str_manage' ] .= '<a href="?m=admin&c=category&a=init&parentid=' . $r [ 'catid' ]. '&menuid=' . $_GET [ 'menuid' ]. '&s=' . $r [ 'type' ]. '&pc_hash=' . $_SESSION [ 'pc_hash' ]. '">' .L( 'manage_sub_category' ). '</a> | ' ; |
} |
//添加子栏目的url链接 $r['type']:1-单网页 0-有子栏目的分类 |
$r [ 'str_manage' ] .= '<a href="?m=admin&c=category&a=add&parentid=' . $r [ 'catid' ]. '&menuid=' . $_GET [ 'menuid' ]. '&s=' . $r [ 'type' ]. '&pc_hash=' . $_SESSION [ 'pc_hash' ]. '">' .L( 'add_sub_category' ). '</a> | ' ; |
//修改、删除、批量移动 的url链接 |
$r [ 'str_manage' ] .= '<a href="?m=admin&c=category&a=edit&catid=' . $r [ 'catid' ]. '&menuid=' . $_GET [ 'menuid' ]. '&type=' . $r [ 'type' ]. '&pc_hash=' . $_SESSION [ 'pc_hash' ]. '">' .L( 'edit' ). '</a> | <a href="javascript:confirmurl(\'?m=admin&c=category&a=delete&catid=' . $r [ 'catid' ]. '&menuid=' . $_GET [ 'menuid' ]. '\',\'' .L( 'confirm' , array ( 'message' => addslashes ( $r [ 'catname' ]))). '\')">' .L( 'delete' ). '</a> | <a href="?m=admin&c=category&a=remove&catid=' . $r [ 'catid' ]. '&pc_hash=' . $_SESSION [ 'pc_hash' ]. '">' .L( 'remove' , '' , 'content' ). '</a>' ; |
//0-内部栏目、1-单网页、2-外部链接 |
$r [ 'typename' ] = $types [ $r [ 'type' ]]; |
//是否在导航显示:1-显示 2-不显示 注意:不显示时会出现一个不在导航显示的小图标 |
$r [ 'display_icon' ] = $r [ 'ismenu' ] ? '' : ' <img src ="' .IMG_PATH. 'icon/gear_disable.png" title="' .L( 'not_display_in_menu' ). '">' ; |
//如果为单网页或无子分类 |
if ( $r [ 'type' ] || $r [ 'child' ]) { |
$r [ 'items' ] = '' ; //数据量为空 |
} else { |
//数据量 |
$r [ 'items' ] = $category_items [ $r [ 'modelid' ]][ $r [ 'catid' ]]; |
} |
$r [ 'help' ] = '' ; |
//将字符串转换为数组:$r['setting']-添加分类时的配置项,是一个字符串 |
$setting = string2array( $r [ 'setting' ]); |
//访问:如, 'url' => 'http://zhencms.com/html/dajiafengfan/' |
if ( $r [ 'url' ]) { |
if (preg_match( '/^(http|https):\/\//' , $r [ 'url' ])) { |
//分类目录名称 |
$catdir = $r [ 'catdir' ]; |
//是否生成到根目录 |
$prefix = $r [ 'sethtml' ] ? '' : $html_root ; |
if ( $this ->siteid==1) { |
//分类目录:"html/父级目录名称/当前目录名称" |
$catdir = $prefix . '/' . $r [ 'parentdir' ]. $catdir ; |
} else { |
$catdir = $prefix . '/' . $sitelist [ $this ->siteid][ 'dirname' ]. $html_root . '/' . $catdir ; |
} |
if ( $r [ 'type' ]==0 && $setting [ 'ishtml' ] && strpos ( $r [ 'url' ], '?' )===false && substr_count( $r [ 'url' ], '/' )<4) $r [ 'help' ] = '<img src="' .IMG_PATH. 'icon/help.png" title="' .L( 'tips_domain' ). $r [ 'url' ].' |
'.L(' directory_binding ').' |
'.$catdir.' /">'; |
} else { |
//分站点 |
$r [ 'url' ] = substr ( $sitelist [ $this ->siteid][ 'domain' ],0,-1). $r [ 'url' ]; |
} |
//访问 |
$r [ 'url' ] = "<a href='$r[url]' target='_blank'>" .L( 'vistor' ). "</a>" ; |
} else { |
$r [ 'url' ] = "<a href='?m=admin&c=category&a=public_cache&menuid=43&module=admin'><font color='red'>" .L( 'update_backup' ). "</font></a>" ; |
} |
//分类信息 |
$categorys [ $r [ 'catid' ]] = $r ; |
} |
} |
$str = "<tr> |
<td align= 'center' ><input name= 'listorders[\$id]' type= 'text' size= '3' value= '\$listorder' class = 'input-text-c' ></td> |
<td align= 'center' >\ $id </td> |
<td >\ $spacer \ $catname \ $display_icon </td> |
<td>\ $typename </td> |
<td>\ $modelname </td> |
<td align= 'center' >\ $items </td> |
<td align= 'center' >\ $url </td> |
<td align= 'center' >\ $help </td> |
<td align= 'center' >\ $str_manage </td> |
</tr>"; |
//判断$categorys是否是一个数组 |
$tree ->init( $categorys ); |
//生成分类树相关的html代码 |
$categorys = $tree ->get_tree(0, $str ); |
//模板文件 |
include $this ->admin_tpl( 'category_manage' ); |
} |
/** |
* 添加栏目 |
*/ |
public function add() { |
//点击"提交"按钮 |
if (isset( $_POST [ 'dosubmit' ])) { |
pc_base::load_sys_func( 'iconv' ); |
$_POST [ 'info' ][ 'type' ] = intval ( $_POST [ 'type' ]); //0-内部栏目 1-单网页 2-外部链接 |
|
if (isset( $_POST [ 'batch_add' ]) && empty ( $_POST [ 'batch_add' ])) { //如果不是批量添加栏目名称 |
if ( $_POST [ 'info' ][ 'catname' ]== '' ) showmessage(L( 'input_catname' )); //如果单条添加栏目名称为空,则给出提示 |
if ( $_POST [ 'info' ][ 'type' ]!=2) { //如果不是外部链接 |
if ( $_POST [ 'info' ][ 'catdir' ]== '' ) showmessage(L( 'input_dirname' )); //如果英文目录为空,则给出提示信息 |
if (! $this ->public_check_catdir(0, $_POST [ 'info' ][ 'catdir' ])) showmessage(L( 'catname_have_exists' )); |
} |
} |
|
$_POST [ 'info' ][ 'siteid' ] = $this ->siteid; //当前站点ID |
$_POST [ 'info' ][ 'module' ] = 'content' ; //content模块 |
$setting = $_POST [ 'setting' ]; |
if ( $_POST [ 'info' ][ 'type' ]!=2) { //如果不是外部链接 |
//栏目生成静态配置 |
if ( $setting [ 'ishtml' ]) { //如果栏目生成HTML |
$setting [ 'category_ruleid' ] = $_POST [ 'category_html_ruleid' ]; //栏目页的url规则 |
} else { //如果栏目不生成HTML |
$setting [ 'category_ruleid' ] = $_POST [ 'category_php_ruleid' ]; //栏目页的url规则 |
$_POST [ 'info' ][ 'url' ] = '' ; //绑定域名 |
} |
} |
|
//内容生成静态配置 |
if ( $setting [ 'content_ishtml' ]) { //如果内容生成HTML |
$setting [ 'show_ruleid' ] = $_POST [ 'show_html_ruleid' ]; //内容页的url规则 |
} else { //如果内容不生成HTML |
$setting [ 'show_ruleid' ] = $_POST [ 'show_php_ruleid' ]; //内容页的url规则 |
} |
if ( $setting [ 'repeatchargedays' ]<1) $setting [ 'repeatchargedays' ] = 1; //重复收费设置,如:一天内不重复收费 |
$_POST [ 'info' ][ 'sethtml' ] = $setting [ 'create_to_html_root' ]; //是否生成到根目录 |
$_POST [ 'info' ][ 'setting' ] = array2string( $setting ); //将这些设置项转化为一个字符串 |
|
$end_str = $old_end = '<script type="text/javascript">window.top.art.dialog({id:"test"}).close();window.top.art.dialog({id:"test",content:\'<h2>' .L( "add_success" ). '</h2><span style="fotn-size:16px;">' .L( "following_operation" ). '</span><br /><ul style="fotn-size:14px;"><li><a href="?m=admin&c=category&a=public_cache&menuid=43&module=admin" target="right" onclick="window.top.art.dialog({id:\\\'test\\\'}).close()">' .L( "following_operation_1" ). '</a></li><li><a href="' .HTTP_REFERER. '" target="right" onclick="window.top.art.dialog({id:\\\'test\\\'}).close()">' .L( "following_operation_2" ). '</a></li></ul>\',width:"400",height:"200"});</script>' ; |
if (!isset( $_POST [ 'batch_add' ]) || empty ( $_POST [ 'batch_add' ])) { |
//目录的名称必须是gbk编码格式 |
$catname = CHARSET == 'gbk' ? $_POST [ 'info' ][ 'catname' ] : iconv( 'utf-8' , 'gbk' , $_POST [ 'info' ][ 'catname' ]); |
//将gbk编码格式的中文目录名称转化为拼音 |
$letters = gbk_to_pinyin( $catname ); |
$_POST [ 'info' ][ 'letter' ] = strtolower (implode( '' , $letters )); |
//将数据插入到category数据表,并返回刚插入的栏目id,注意:insert函数在libs/classes/model.class.php类库中 |
$catid = $this ->db->insert( $_POST [ 'info' ], true); |
//角色权限 |
$this ->update_priv( $catid , $_POST [ 'priv_roleid' ]); |
//会员组权限 |
$this ->update_priv( $catid , $_POST [ 'priv_groupid' ],0); |
} else { //批量添加 |
$end_str = '' ; |
$batch_adds = explode ( "\n" , $_POST [ 'batch_add' ]); //批量添加栏目,以\n分割多个栏目名称 |
foreach ( $batch_adds as $_v ) { |
if (trim( $_v )== '' ) continue ; |
$names = explode ( '|' , $_v ); //以"|"分割栏目中文名称与栏目英文名称 |
$catname = $names [0]; //栏目中文名称 |
$_POST [ 'info' ][ 'catname' ] = trim( $names [0]); //栏目中文名称 |
$letters = gbk_to_pinyin( $catname ); //栏目的拼音 |
$_POST [ 'info' ][ 'letter' ] = strtolower (implode( '' , $letters )); |
//如果栏目英文名称存在,则使用英文名称作为英文目录,否则使用拼音作为英文目录 |
$_POST [ 'info' ][ 'catdir' ] = trim( $names [1]) ? trim( $names [1]) : trim( $_POST [ 'info' ][ 'letter' ]); |
//如果目录不存在 |
if (! $this ->public_check_catdir(0, $_POST [ 'info' ][ 'catdir' ])) { |
$end_str .= $end_str ? ',' . $_POST [ 'info' ][ 'catname' ]. '(' . $_POST [ 'info' ][ 'catdir' ]. ')' : $_POST [ 'info' ][ 'catname' ]. '(' . $_POST [ 'info' ][ 'catdir' ]. ')' ; |
continue ; |
} |
$catid = $this ->db->insert( $_POST [ 'info' ], true); //插入category数据表 |
$this ->update_priv( $catid , $_POST [ 'priv_roleid' ]); //更新角色权限 |
$this ->update_priv( $catid , $_POST [ 'priv_groupid' ],0); //更新会员组权限 |
} |
$end_str = $end_str ? L( 'follow_catname_have_exists' ). $end_str : $old_end ; |
} |
$this ->cache(); //更新缓存 |
showmessage(L( 'add_success' ). $end_str ); //添加成功提示信息 |
} else { |
//获取站点模板信息 |
pc_base::load_app_func( 'global' ); //加载global.func.php文件 |
|
$template_list = template_list( $this ->siteid, 0); |
foreach ( $template_list as $k => $v ) { |
//$template_list['default']='默认模板' |
$template_list [ $v [ 'dirname' ]] = $v [ 'name' ] ? $v [ 'name' ] : $v [ 'dirname' ]; |
unset( $template_list [ $k ]); |
} |
$show_validator = '' ; |
if (isset( $_GET [ 'parentid' ])) { //添加子栏目 |
$parentid = $_GET [ 'parentid' ]; |
$r = $this ->db->get_one( array ( 'catid' => $parentid )); |
if ( $r ) extract( $r ,EXTR_SKIP); |
$setting = string2array( $setting ); |
} |
|
pc_base::load_sys_class( 'form' , '' ,0); //加载form.class.php类库 |
$type = $_GET [ 's' ]; //添加子栏目时会传递此参数:0-内部栏目、1-单网页、2-外部链接 |
if ( $type ==0) { //0-内部栏目 |
$exists_model = false; //模型是否存在的标识 |
$models = getcache( 'model' , 'commons' ); //获取默认的三种模型信息:文章模型、下载模型、图片模型 |
foreach ( $models as $_m ) { |
if ( $this ->siteid == $_m [ 'siteid' ]) { //如果这默认的三种模型属于当前站点ID |
$exists_model = true; //将模型是否存在标识赋值给true |
break ; //跳出foreach循环 |
} |
} |
//如果模型不存在,则给出提示信息 |
if (! $exists_model ) showmessage(L( 'please_add_model' ), '?m=content&c=sitemodel&a=init&menuid=59' ,5000); |
//显示模板文件 |
include $this ->admin_tpl( 'category_add' ); |
} elseif ( $type ==1) { |
include $this ->admin_tpl( 'category_page_add' ); |
} else { |
include $this ->admin_tpl( 'category_link' ); |
} |
} |
} |
} |