defined('IN_PHPCMS') or exit('No permission resources.');
/* phpcms v9 uses session to log in. There are two ways to save session, one is database storage, and the other is File storage method, the default is database storage method. Sometimes the database method does not work. You can modify the session storage method in cachesconfigssystem.php //Session configuration 'session_storage' => 'mysql' and change it to //Session configuration 'session_storage' => 'files'. Anyway, it cannot be empty, otherwise the login will not be successful. */
$session_storage = 'session_'.pc_base::load_config('system','session_storage');//session storage method is saved to the file
pc_base::load_sys_class($session_storage);
if(param::get_cookie( 'sys_lang')) { //Language pack
define('SYS_STYLE',param::get_cookie('sys_lang')); // Set when logging in
} else {
define('SYS_STYLE','zh- cn');
}
//Defined in the background
define('IN_ADMIN',true);
class admin {
public $userid;
public $username;
public function __construct() {
self::check_admin( ; (L('module_not_exists')); //The module does not exist. Self::manage_log();
self::check_ip(); Lock screen
through using 'admin_url')) {
Header("http/1.1 /
final public function check_admin() {
Array ('Login', 'Public_card')) {
Return true; // Once returned to true, the execution of the follow -up code
} else {
// determine whether the session has userid, rootid, do not do it if there is any case. Process, if not, return to the login interface
$userid = param::get_cookie('userid');
if(!isset($_SESSION['userid']) || !isset($_SESSION['roleid']) || !$_SESSION['userid'] || !$_SESSION['roleid'] || $userid != $_SESSION['userid']) showmessage(L('admin_login'),'?m=admin&c=index&a=login ');
}
}
/**
* Determine whether the user has logged in
*/
using using using using ‐ ‐ ‐ ‐ ‐ final public static function admin_tpl($file, $m = '') { if(empty($m)) return false; //Return false if $m is empty
Return PC_PATH.'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$file.'.tpl.php' ; //Return to modules/ROUTE_M/templates/ The suffix is $file.tpl.php
}
/**
* Get the management menu
* Find menu items by parent ID
* @param integer $parentid Parent menu ID
* @param integer $with_self Whether to include himself
* @param The menu is stored in the menu data table.When we need to add a new menu in secondary development, we only need to insert the id, name, parentid, m, c, a, data and other information of the corresponding menu into the menu table. Of course, in order to allow roles other than super administrators to access the menu, permissions need to be configured in the admin_role_priv table.
‐ 1 to 1 to 1 menu_model'); //Reference the model subclass to implement database and other operations
’ display '= & gt; 1); // Parentid's parent node ID
if ($ site_model && $ parentid) {
$ when [$ site_model] = 1;
}
}
$ result = $ menudb->select($where,'*',1000,'listorder ASC'); //listorder is the number before sorting in the background, which can be edited
if($with_self) {
$result2[] = $menudb->get_one(array('id'=>$parentid));
$result = array_merge($result2,$result); //array_merge — Assign the value of the array to the previous array
/permission check. If it is a super administrator, return all
using use using using admin using admin ’s admin ’ ‐ ‐ . $array = array();
$privdb = pc_base::load_model('admin_role_priv_model'); // Call model subclass
$siteid = param::get_cookie('siteid');
foreach($result as $v) {
$action = $v['a']; ] = $ V; e} Else {
// For the method of AJAX, only the last half of the method is taken (preg_match ('/^ajax _ ([a-z]+) _/', $ __match)) $ action = $_match[1];
// Try to get whether the current role $roleid has the corresponding operation permission records of m, c, and a // Try to get whether the current role $roleid has the corresponding operation permissions to m, c, and a Record
$r = $privdb->get_one(array('m'=>$v['m'],'c'=>$v['c'],'a'=>$action ,'roleid'=>$_SESSION['roleid'],'siteid'=>$siteid));
.Assign $v to an $array[]
final public static function submenu($parentid = '', $big_menu = false) {
>ROUTE_M,'c'=>ROUTE_C,'a'=>ROUTE_A)); self::admin_menu($parentid,1); //The name in the parent menu $parentid, including the parent menu
if (! isset($_GET['s'])) {
$classname = ROUTE_M == $_value['m'] && ROUTE_C == $_value['c'] && ROUTE_A == $_value['a'] ? ' class="on"' : '';
} else {
, =')) : '';
$classname = ROUTE_M == $_value['m'] && ROUTE_C == $_value['c'] && ROUTE_A == $_value['a'] && $_GET['s '] == $_s ? 'class="on"' : '; if($classname) {
$string .= "".L($_value['name'])." |";
} else {
. "&a=".$_value['a']."&menuid=$parentid&pc_hash=$pc_hash".'&'.$_value['data']."' $classname>".L($_value ['name'])."|";
return $string;
}
/**
* Get the menu header menu navigation
*
* @param $parentid menu id
* @param is mainly used to generate all sub-menu navigation of the related menu (generally displayed in the upper part of the iframe frame content page)
*/
//Use recursion to get all the parent menu levels of a menu and return it as an HTML fragment
final public static function current_pos($id) {
$menudb = pc_base::load_model('menu_model');
$r =$menudb->get_one(array('id'=>$id),'id,name,parentid');
$str = '';
if($r['parentid']) {
$str = self::current_pos($r['parentid']); ';
}
/**
* Get the current site ID
*/
final public static function get_siteid() {
return get_siteid();
}
/**获 *
* Get the current site information
@param Integer $ Siteid Site ID number, please take the current site information
@Return array
**/
final public static function get_site ($siteid = '' ) {
; ',',$sites->get_role_siteid($_SESSION['roleid']));
Return current($siteid);
}
/**
* Permission judgment
*/
//Check whether the user is accessing m, c, a, operation permission
final public function check_priv() {
//Login interface: Once true is returned, the execution of subsequent code will be terminated
if(ROUTE_M =='admin' && ROUTE_C =='index' && in_array( ROUTE_A, array('login', 'init', 'public_card'))) return true;
,,, ROUTE_A, '] == 1) return true;
$siteid = param::get_cookie('siteid'); //Site id
$action = ROUTE_A; //Method
$privdb = pc_base::load_model('admin_role_priv_model');
using using using using if(preg_match('/^public_/',ROUTE_A)) return true; //If the method starts with public_
‐ out out out out out out out through out using ‐ ‐ ‐ ‐ ‐‐‐‐‐ if(preg_match('/^public_/',ROUTE_A)) return true; //If the method starts with public_
if(preg_match('/^ajax_([a-z]+)_/',ROUTE_A,$_match )) { //Methods starting with ajax_, only intercept the second half as the query condition
$action = $_match[1]; Composite permission records
$r =$privdb->get_one(array('m'=>ROUTE_M,'c'=>ROUTE_C,'a'=>$action,'roleid'=>$ _SESSION['roleid'],'siteid'=>$siteid));
if(!$r) showmessage('You do not have permission to operate this item','blank');
}
/**
*
* Record log
*/
final private function manage_log() {
use using ‐ to use ’s ’ to use ’ use using using ’ using using ’ ‐ ’ through using ’ ‐ ’ through out using using using out out out out out out out out out out out out ’'s' ‐ ‐‐‐‐‐‐‐‐ ? Record background operation log
using using using using using using ’ ’s ’ through ’ using ’s ’ using using ‐ ‐ ‐ ‐ ‐ ') {
return false;else {
$ip = ip(); $userid = isset($_SESSION['userid']) ? $_SESSION['userid'] : '';//User id
isset($_SESSION['userid']) '?m='.ROUTE_M.'&c='.ROUTE_C.'&a='.ROUTE_A; //Operation address
$username,'userid'=>$userid,'action'=>ROUTE_C, 'querystring'=>$url,'time'=>$time,'ip'=>$ip)); / /Record operation logs into the database }
}
}
/**
*
* Backend IP ban judgment...
*/
’ ’ use ’ ’s ’ ’ through ’ through through through ’ way through ’ through ’' through through''‐‐‐ ‐‐‐‐‐‐ to be recorded. ipbanned_model');
$ This-& gt; ipbanned-& gt; check_ip ();
}
/**
* Check lock screen status
*/
Final Private Function Lock_Screen () {
(_ _Session ['lock_screen'] && $_Session ['Lock_screen ']==1) {
if(preg_match('/^public_/', ROUTE_A) || (ROUTE_M == 'content' && ROUTE_C == 'create_html') || (ROUTE_M == 'release') || (ROUTE_A == 'login') || (ROUTE_M == 'search' && ROUTE_C == 'search_admin' && ROUTE_A=='createindex')) return true; admin&c=index&a=login');
}
}
/**
* Check the hash value to verify the security of user data
*/
final private function check_hash() {
use using using use with using using ‐ using using through off through off ‐ off ‐ through through through through through through through through through through over through through through through through through through through through through through through‐with‐through‐to‐under‐stage to be used to admin to admin&c=index&a=login'); The release p p p p p (preg_match ('/^public_/', route_a) || route_m == 'admin' && route_c == 'Index' || in_array (Route_a, Array ('Login')) {
Ret urn true; }
// Whether it is GET or POST, if the pc_hash comes from GET or POST, if it can match the server pc_hash, then pass
&& ($_SESSION['pc_hash'] == $_GET['pc_hash'])) {
' && ($_SESSION['pc_hash'] == $_POST['pc_hash'])) {
return true;
}
}
/**
* Backend information list template
* @param string $id The name of the selected template
* @param string $str The attribute name in the form
*/
以上就介绍了phpcms的adminclassphp,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。