📄 module.php
字号:
<?php
// $Id: module.php 1290 2008-02-10 13:09:25Z phppp $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <http://www.xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
/**
* A Module
*
* @package kernel
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright (c) 2000-2003 The Xoops Project - www.xoops.org
*/
class XoopsModule extends XoopsObject
{
/**
* @var string
*/
var $modinfo;
/**
* @var string
*/
var $adminmenu;
/**
* Constructor
*/
function XoopsModule()
{
$this->XoopsObject();
$this->initVar('mid', XOBJ_DTYPE_INT, null, false);
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 150);
$this->initVar('version', XOBJ_DTYPE_INT, 100, false);
$this->initVar('last_update', XOBJ_DTYPE_INT, null, false);
$this->initVar('weight', XOBJ_DTYPE_INT, 0, false);
$this->initVar('isactive', XOBJ_DTYPE_INT, 1, false);
$this->initVar('dirname', XOBJ_DTYPE_OTHER, null, true);
$this->initVar('hasmain', XOBJ_DTYPE_INT, 0, false);
$this->initVar('hasadmin', XOBJ_DTYPE_INT, 0, false);
$this->initVar('hassearch', XOBJ_DTYPE_INT, 0, false);
$this->initVar('hasconfig', XOBJ_DTYPE_INT, 0, false);
$this->initVar('hascomments', XOBJ_DTYPE_INT, 0, false);
// RMV-NOTIFY
$this->initVar('hasnotification', XOBJ_DTYPE_INT, 0, false);
}
/**
* Load module info
*
* @param string $dirname Directory Name
* @param boolean $verbose
**/
function loadInfoAsVar($dirname, $verbose = true)
{
if ( !isset($this->modinfo) ) {
$this->loadInfo($dirname, $verbose);
}
$this->setVar('name', $this->modinfo['name'], true);
$this->setVar('version', intval(100 * ($this->modinfo['version']+0.001)), true);
$this->setVar('dirname', $this->modinfo['dirname'], true);
$hasmain = (isset($this->modinfo['hasMain']) && $this->modinfo['hasMain'] == 1) ? 1 : 0;
$hasadmin = (isset($this->modinfo['hasAdmin']) && $this->modinfo['hasAdmin'] == 1) ? 1 : 0;
$hassearch = (isset($this->modinfo['hasSearch']) && $this->modinfo['hasSearch'] == 1) ? 1 : 0;
$hasconfig = ((isset($this->modinfo['config']) && is_array($this->modinfo['config'])) || !empty($this->modinfo['hasComments'])) ? 1 : 0;
$hascomments = (isset($this->modinfo['hasComments']) && $this->modinfo['hasComments'] == 1) ? 1 : 0;
// RMV-NOTIFY
$hasnotification = (isset($this->modinfo['hasNotification']) && $this->modinfo['hasNotification'] == 1) ? 1 : 0;
$this->setVar('hasmain', $hasmain);
$this->setVar('hasadmin', $hasadmin);
$this->setVar('hassearch', $hassearch);
$this->setVar('hasconfig', $hasconfig);
$this->setVar('hascomments', $hascomments);
// RMV-NOTIFY
$this->setVar('hasnotification', $hasnotification);
}
/**
* Get module info
*
* @param string $name
* @return array|string Array of module information.
* If {@link $name} is set, returns a singel module information item as string.
**/
function &getInfo($name=null)
{
if ( !isset($this->modinfo) ) {
$this->loadInfo($this->getVar('dirname'));
}
if ( isset($name) ) {
if ( isset($this->modinfo[$name]) ) {
return $this->modinfo[$name];
}
$return = false;
return $return;
}
return $this->modinfo;
}
/**
* Get a link to the modules main page
*
* @return string FALSE on fail
*/
function mainLink()
{
if ( $this->getVar('hasmain') == 1 ) {
$ret = '<a href="'.XOOPS_URL.'/modules/'.$this->getVar('dirname').'/">'.$this->getVar('name').'</a>';
return $ret;
}
return false;
}
/**
* Get links to the subpages
*
* @return string
*/
function subLink()
{
$ret = array();
if ( $this->getInfo('sub') && is_array($this->getInfo('sub')) ) {
foreach ( $this->getInfo('sub') as $submenu ) {
$ret[] = array('name' => $submenu['name'], 'url' => $submenu['url']);
}
}
return $ret;
}
/**
* Load the admin menu for the module
*/
function loadAdminMenu()
{
if ($this->getInfo('adminmenu') && $this->getInfo('adminmenu') != '' && file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$this->getInfo('adminmenu'))) {
include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$this->getInfo('adminmenu');
$this->adminmenu =& $adminmenu;
}
}
/**
* Get the admin menu for the module
*
* @return string
*/
function &getAdminMenu()
{
if ( !isset($this->adminmenu) ) {
$this->loadAdminMenu();
}
return $this->adminmenu;
}
/**
* Load the module info for this module
*
* @param string $dirname Module directory
* @param bool $verbose Give an error on fail?
*/
function loadInfo($dirname, $verbose = true)
{
global $xoopsConfig;
if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$dirname.'/language/'.$xoopsConfig['language'].'/modinfo.php')) {
include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/language/'.$xoopsConfig['language'].'/modinfo.php';
} elseif (file_exists(XOOPS_ROOT_PATH.'/modules/'.$dirname.'/language/english/modinfo.php')) {
include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/language/english/modinfo.php';
}
if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$dirname.'/xoops_version.php')) {
include XOOPS_ROOT_PATH.'/modules/'.$dirname.'/xoops_version.php';
} else {
if (false != $verbose) {
echo "Module File for $dirname Not Found!";
}
return false;
}
$this->modinfo =& $modversion;
return true;
}
/**
* Search contents within a module
*
* @param string $term
* @param string $andor 'AND' or 'OR'
* @param integer $limit
* @param integer $offset
* @param integer $userid
* @return mixed Search result.
**/
function search($term = '', $andor = 'AND', $limit = 0, $offset = 0, $userid = 0)
{
if ($this->getVar('hassearch') != 1) {
return false;
}
$search =& $this->getInfo('search');
if ($this->getVar('hassearch') != 1 || !isset($search['file']) || !isset($search['func']) || $search['func'] == '' || $search['file'] == '') {
return false;
}
if (file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname').'/'.$search['file'])) {
include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$search['file'];
} else {
return false;
}
if (function_exists($search['func'])) {
$func = $search['func'];
return $func($term, $andor, $limit, $offset, $userid);
}
return false;
}
/**#@+
* For backward compatibility only!
* @deprecated
*/
function mid()
{
return $this->getVar('mid');
}
function dirname()
{
return $this->getVar('dirname');
}
function name()
{
return $this->getVar('name');
}
function &getByDirName($dirname)
{
$modhandler =& xoops_gethandler('module');
$inst =& $modhandler->getByDirname($dirname);
return $inst;
}
/**#@-*/
}
/**
* XOOPS module handler class.
*
* This class is responsible for providing data access mechanisms to the data source
* of XOOPS module class objects.
*
* @package kernel
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright (c) 2000-2003 The Xoops Project - www.xoops.org
*/
class XoopsModuleHandler extends XoopsObjectHandler
{
/**
* holds an array of cached module references, indexed by module id
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -