📄 module.class.inc.php
字号:
// -----------------------------------------------------------------------------
/**
* Administration
*
* @access public
*/
function administration($module)
{
$module_container = t12l_module::container();
$admin = $module_container[trim($module)];
$result = array(
'module_name' => $module,
'module_title' => $admin->get_property('name'),
'module_description' => $admin->get_property('description'),
'module_form' => t12l_module::administration_form($admin)
);
return $result;
}
// -----------------------------------------------------------------------------
/**
* Administration form
*
* $property elements:
* - type
* - label
* - description
* - required
* - option (radio|select)
* - attribute
*
* @access public
*/
function administration_form(&$instance)
{
global $t12l;
require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm('module_admin', 'POST');
$settings = $instance->administration($t12l);
$additional = array();
foreach ($settings AS $name => $property)
{
$skip = false;
$add_html = '';
switch ($property['type']) {
case 'string':
$form->addElement('text', $name, $property['label']);
break;
case 'email':
$form->addElement('text', $name, $property['label']);
$form->addRule($name, $t12l['text']['txt_syntax_email'], 'email');
break;
case 'numeric':
$form->addElement('text', $name, $property['label']);
$form->addRule($name, $t12l['text']['txt_syntax_numeric'], 'numeric');
break;
case 'bool':
$bool = array();
$bool[] = &HTML_QuickForm::createElement('radio', null, null, $t12l['text']['txt_yes'], 'Y');
$bool[] = &HTML_QuickForm::createElement('radio', null, null, $t12l['text']['txt_no'], 'N');
$form->addGroup($bool, $name, $property['label'], ' ');
break;
case 'select':
$bool = array();
$select =& $form->addElement('select', $name, $property['label'], $property['option']);
if (!isset($property['size']) or $property['size'] == '' or !is_numeric($property['size'])) {
$select->setSize(1);
} else {
$select->setSize($property['size']);
}
break;
case 'radio':
$radio = array();
foreach ($property['option'] AS $value => $label)
{
$radio[] = &HTML_QuickForm::createElement('radio', null, null, $label, $value);
}
$form->addGroup($radio, $name, $property['label'], '<br />');
break;
case 'textarea':
$attribute = '';
if (isset($property['attribute'])) {
$attribute = $property['attribute'];
}
$form->addElement('textarea', $name, $property['label'], $attribute);
break;
case 'color':
$color_attribute = array( 'onfocus' => 'style.backgroundColor = \'\'; style.color = \'\';',
'onblur' => 'style.backgroundColor = value; style.color = value;');
$form->addElement('text', $name, $property['label'], $color_attribute);
$add_html = '<script language="javascript">var cp_' . $name . ' = new ColorPicker();cp_' . $name . '.offsetX = 30; document.forms[0].' . $name . '.style.backgroundColor = document.forms[0].' . $name . '.value; document.forms[0].' . $name . '.style.color = document.forms[0].' . $name . '.value;</script><a href="#" onclick="cp_' . $name . '.select(document.forms[0].' . $name . ',\'pick\'); return false;" name="pick" id="pick"><img src="../template/admin/image/icon/color_picker.png" border="0" align="absmiddle" /></a><script language="javascript">cp_' . $name . '.writeDiv()</script>';
break;
default:
$skip = true;
break;
}
if ($skip == false) {
$additional[] = array( 'description' => $property['description'],
'add_html' => $add_html
);
}
if ($property['required']) {
$form->addRule($name, $t12l['text']['txt_error_required'], 'required');
}
}
$form->addElement('submit', 'save', $t12l['text']['txt_save_settings']);
$additional[] = array( 'description' => '',
'add_html' => '');
$form->addElement('hidden', 'm', get_class($instance));
$additional[] = array( 'description' => '',
'add_html' => '');
// Validate form
$message = array();
if ($form->validate()) {
// Write data as settings
if (false == $t12l['demo_mode']) {
foreach ($t12l['_post'] AS $name => $value)
{
if (!in_array($name, $instance->get_property('setting_names'))) {
continue;
}
t12l_setting::write($name, $value);
$instance->add_property($name, $value);
}
$message[] = $t12l['text']['txt_update_data_successful'];
// Reload modules
t12l_module::container(true);
} else {
$message[] = $t12l['text']['txt_disabled_in_demo_mode'];
}
}
// Get setting data
$settings = t12l_setting::read_all();
$input_data = array_merge($instance->get_all_properties(), $settings);
$form->setDefaults($input_data);
$result = $form->toArray();
$merged = array();
foreach ($result['elements'] AS $key => $item)
{
if (!isset($item['elements'])) {
$item['elements'] = false;
}
$merged[] = array_merge($item, $additional[$key]);
}
$result['elements'] = $merged;
$result['module_message'] = $message;
$result['module_additional'] = array(); //$additional;
return $result;
}
// -----------------------------------------------------------------------------
/**
* Get module folder list
*/
function folder_list($path)
{
if (!is_dir($path)) {
return false;
}
include 'Find.php';
$items = &File_Find::glob('#gentlesource_([a-zA-Z0-9]+)#', $path, 'perl');
if (!is_array($items)) {
return false;
}
return $items;
}
// -----------------------------------------------------------------------------
/**
* Install module
*/
function install($module)
{
global $t12l;
$module = trim($module);
$t12l['installed_modules'][] = $module;
$installed_modules = serialize(array_unique($t12l['installed_modules']));
t12l_setting::write('installed_modules', $installed_modules);
$t12l['installed_modules'] = array_unique($t12l['installed_modules']);
return true;
}
// -----------------------------------------------------------------------------
/**
* Uninstall module
*/
function uninstall($module)
{
global $t12l;
$module = trim($module);
$arr = array_flip($t12l['installed_modules']);
unset($arr[$module]);
$arr = array_flip($arr);
$installed_modules = serialize(array_unique($arr));
t12l_setting::write('installed_modules', $installed_modules);
// $t12l['installed_modules'] = unserialize($t12l['installed_modules']);
$t12l['installed_modules'] = array_unique($t12l['installed_modules']);
return true;
}
// -----------------------------------------------------------------------------
/**
* Module order
*/
function order($module, $direction)
{
global $t12l;
$installed_modules = $t12l['installed_modules'];
if ($direction == 'up') {
$installed_modules = array_reverse($installed_modules);
}
$arr = array();
$insert = false;
foreach ($installed_modules AS $item)
{
if ($module == $item) {
$insert = true;
continue;
}
$arr[] = $item;
if ($insert == true) {
$arr[] = $module;
$insert = false;
}
}
if ($insert == true) {
$arr[] = $module;
$insert = false;
}
$installed_modules = $arr;
if ($direction == 'up') {
$installed_modules = array_reverse($installed_modules);
}
$installed_modules = serialize(array_unique($installed_modules));
t12l_setting::write('installed_modules', $installed_modules);
// $t12l['installed_modules'] = unserialize($t12l['installed_modules']);
$t12l['installed_modules'] = unserialize($installed_modules);
return true;
}
// -----------------------------------------------------------------------------
} // End of class
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -