NobuNobu
nobun****@users*****
2007年 4月 30日 (月) 16:30:54 JST
Index: xoops2jp/html/modules/legacy/admin/class/Legacy_SQLScanner.class.php diff -u /dev/null xoops2jp/html/modules/legacy/admin/class/Legacy_SQLScanner.class.php:1.1.4.1 --- /dev/null Mon Apr 30 16:30:54 2007 +++ xoops2jp/html/modules/legacy/admin/class/Legacy_SQLScanner.class.php Mon Apr 30 16:30:54 2007 @@ -0,0 +1,75 @@ +<?php + +if (!defined('XOOPS_ROOT_PATH')) exit(); + +require_once XOOPS_ROOT_PATH . "/modules/legacy/lib/EasyLex/EasyLex_SQLScanner.class.php"; + +class Legacy_SQLScanner extends EasyLex_SQLScanner +{ + var $mDB_PREFIX = ""; + var $mDirname = ""; + + function setDB_PREFIX($prefix) + { + $this->mDB_PREFIX = $prefix; + } + + function setDirname($dirname) + { + $this->mDirname = $dirname; + } + + function &getOperations() + { + $t_lines = array(); + $t_tokens = array(); + $depth = 0; + + foreach (array_keys($this->mTokens) as $key) { + if ($this->mTokens[$key]->mType == EASYLEX_SQL_OPEN_PARENTHESIS) { + $depth++; + } + elseif ($this->mTokens[$key]->mType == EASYLEX_SQL_CLOSE_PARENTHESIS) { + $depth--; + } + + $t_tokens[] =& $this->mTokens[$key]; + + if (count($t_tokens) > 1 && $depth == 0) { + if ($this->mTokens[$key]->mType == EASYLEX_SQL_SEMICOLON) { + $t_lines[] =& $t_tokens; + unset($t_tokens); + $t_tokens = array(); + } + elseif ($this->mTokens[$key]->mType == EASYLEX_SQL_LETTER && (strtoupper($this->mTokens[$key]->mValue) =='CREATE' || strtoupper($this->mTokens[$key]->mValue) =='ALTER' || strtoupper($this->mTokens[$key]->mValue) =='INSERT')) { + array_pop($t_tokens); + $t_lines[] =& $t_tokens; + unset($t_tokens); + $t_tokens = array(); + $t_tokens[] =& $this->mTokens[$key]; + } + } + } + + if (count($t_tokens) > 0) { + $t_lines[] =& $t_tokens; + unset($t_tokens); + } + + // + // Prepare array for str_replace() + // + $t_search = array('{prefix}', '{dirname}', '{Dirname}', '{_dirname_}'); + $t_replace = array($this->mDB_PREFIX, strtolower($this->mDirname), ucfirst(strtolower($this->mDirname)), $this->mDirname); + + foreach (array_keys($t_lines) as $idx) { + foreach (array_keys($t_lines[$idx]) as $op_idx) { + $t_lines[$idx][$op_idx]->mValue = str_replace($t_search, $t_replace, $t_lines[$idx][$op_idx]->mValue); + } + } + + return $t_lines; + } +} + +?> \ No newline at end of file Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstallInformation.class.php diff -u /dev/null xoops2jp/html/modules/legacy/admin/class/ModuleInstallInformation.class.php:1.1.4.1 --- /dev/null Mon Apr 30 16:30:54 2007 +++ xoops2jp/html/modules/legacy/admin/class/ModuleInstallInformation.class.php Mon Apr 30 16:30:54 2007 @@ -0,0 +1,856 @@ +<?php +/** + * @package Legacy + * @brief This file declare some structure-class and stored-system readers for the installer. + * @version $Id: ModuleInstallInformation.class.php,v 1.1.4.1 2007/04/30 07:30:54 nobunobu Exp $ + */ + +define('LEGACY_INSTALLINFO_STATUS_LOADED', "loaded"); +define('LEGACY_INSTALLINFO_STATUS_UPDATED', "updated"); +define('LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED', "order_updated"); +define('LEGACY_INSTALLINFO_STATUS_NEW', "new"); +define('LEGACY_INSTALLINFO_STATUS_DELETED', "deleted"); + +/** + * The structure which is able to keep block's informations without DB. This + * is installer only. + */ +class Legacy_BlockInformation +{ + var $mStatus = LEGACY_INSTALLINFO_STATUS_LOADED; + + var $mFuncNum = 0; + + var $mName = ""; + + var $mOptions = ""; + + var $mFuncFile = ""; + var $mShowFunc = ""; + var $mEditFunc = ""; + var $mTemplate = ""; + + function Legacy_BlockInformation($funcNum, $name, $funcFile, $showFunc, $editFunc, $template, $options = null) + { + $this->mFuncNum = intval($funcNum); + $this->mName = $name; + $this->mFuncFile = $funcFile; + $this->mShowFunc = $showFunc; + $this->mEditFunc = $editFunc; + $this->mTemplate = $template; + $this->mOptions = $options; + } + + /** + * @return bool + */ + function isEqual(&$block) + { + if ($this->mFuncNum != $block->mFuncNum) { + return false; + } + + if ($this->mName != $block->mName) { + return false; + } + + if ($this->mFuncFile != $block->mFuncFile) { + return false; + } + + if ($this->mShowFunc != $block->mShowFunc) { + return false; + } + + if ($this->mEditFunc != $block->mEditFunc) { + return false; + } + + if ($this->mTemplate != $block->mTemplate) { + return false; + } + + return true; + } + + function update(&$block) + { + $this->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED; + + $this->mName = $block->mName; + $this->mFuncFile = $block->mFuncFile; + $this->mShowFunc = $block->mShowFunc; + $this->mEditFunc = $block->mEditFunc; + $this->mTemplate = $block->mTemplate; + } +} + +class Legacy_BlockInfoCollection +{ + var $mBlocks = array(); + var $mShowFuncs = array(); + var $mFuncFiles = array(); + + function add(&$info) + { + if (isset($this->mBlocks[$info->mFuncNum])) { + return false; + } + + $this->mBlocks[$info->mFuncNum] =& $info; + $this->mShowFuncs[] = $info->mShowFunc; + $this->mFuncFiles[] = $info->mFuncFile; + + ksort($this->mBlocks); + + return true; + } + + function &get($funcNum) + { + if (isset($this->mBlocks[$funcNum])) { + return $this->mBlocks[$funcNum]; + } + + $ret = null; + return $ret; + } + + function funcExists($info) { + return (in_array($info->mShowFunc, $this->mShowFuncs) && in_array($info->mFuncFile, $this->mFuncFiles)); + } + + /** + * Updates the list of blocks by comparing with $collection. + */ + function update(&$collection) + { + foreach (array_keys($this->mBlocks) as $idx) { + $t_block =& $collection->get($this->mBlocks[$idx]->mFuncNum); + if ($t_block == null) { + if (!$collection->funcExists($this->mBlocks[$idx])) { + $this->mBlocks[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED; + } else { + $this->mBlocks[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED; // No Action. + } + } + elseif (!$this->mBlocks[$idx]->isEqual($t_block)) { + $this->mBlocks[$idx]->update($t_block); + } + } + + foreach (array_keys($collection->mBlocks) as $idx) { + $func_num = $collection->mBlocks[$idx]->mFuncNum; + if (!isset($this->mBlocks[$func_num])) { + $this->add($collection->mBlocks[$idx]); + $this->mBlocks[$func_num]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW; + } + } + } + + function reset() + { + unset($this->mBlocks); + $this->mBlocks = array(); + } +} + +/** + * The structure which is able to keep preference's informations without DB. + * This is installer only. + */ +class Legacy_PreferenceInformation +{ + var $mStatus = LEGACY_INSTALLINFO_STATUS_LOADED; + + var $mOrder = 0; + + var $mName = ""; + + var $mTitle = ""; + + var $mDescription = ""; + + var $mFormType = ""; + + var $mValueType = ""; + + var $mDefault = null; + + var $mOption = null; + + function Legacy_PreferenceInformation($name, $title, $description, $formType, $valueType, $default, $order = 0) + { + $this->mName = $name; + $this->mTitle = $title; + $this->mDescription = $description; + $this->mFormType = $formType; + $this->mValueType = $valueType; + $this->mDefault = $default; + $this->mOrder = intval($order); + + $this->mOption =& new Legacy_PreferenceOptionInfoCollection(); + } + + /** + * @return bool + */ + function isEqual(&$preference) + { + if ($this->mName != $preference->mName) { + return false; + } + + if ($this->mTitle != $preference->mTitle) { + return false; + } + + if ($this->mDescription != $preference->mDescription) { + return false; + } + + if ($this->mFormType != $preference->mFormType) { + return false; + } + + if ($this->mValueType != $preference->mValueType) { + return false; + } + + if ($this->mOrder != $preference->mOrder) { + return false; + } + + if (!$this->mOption->isEqual($preference->mOption)) { + return false; + } + + return true; + } + + function update(&$preference) + { + $this->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED; + + $this->mName = $preference->mName; + $this->mTitle = $preference->mTitle; + $this->mDescription = $preference->mDescription; + $this->mFormType = $preference->mFormType; + $this->mValueType = $preference->mValueType; + $this->mDefault = $preference->mDefault; + $this->mOrder = $preference->mOrder; + + unset($this->mOption); + $this->mOption =& $preference->mOption; + } +} + +class Legacy_PreferenceInfoCollection +{ + var $mPreferences = array(); + + var $mComments = array(); + + var $mNotifications = array(); + + function Legacy_PreferenceInfoCollection() + { + } + + function add(&$preference) + { + if ($preference->mName == 'com_rule' || $preference->mName == 'com_anonpost') { + if (isset($this->mComments[$preference->mName])) { + return false; + } + $this->mComments[$preference->mName] =& $preference; + $this->_sort(); + return true; + } + + if ($preference->mName == 'notification_enabled' || $preference->mName == 'notification_events') { + if (isset($this->mNotifications[$preference->mName])) { + return false; + } + $this->mNotifications[$preference->mName] =& $preference; + $this->_sort(); + return true; + } + + if (isset($this->mPreferences[$preference->mName])) { + return false; + } + + $this->mPreferences[$preference->mName] =& $preference; + $this->_sort(); + + return true; + } + + /** + * @private + * Renumbers orders of preferences. + */ + function _sort() + { + $currentOrder = 0; + foreach (array_keys($this->mPreferences) as $idx) { + if ($this->mPreferences[$idx]->mOrder != $currentOrder) { + $this->mPreferences[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED; + $this->mPreferences[$idx]->mOrder = $currentOrder; + } + + $currentOrder++; + } + + foreach (array_keys($this->mComments) as $idx) { + if ($this->mComments[$idx]->mOrder != $currentOrder) { + $this->mComments[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED; + $this->mComments[$idx]->mOrder = $currentOrder; + } + + $currentOrder++; + } + + foreach (array_keys($this->mNotifications) as $idx) { + if ($this->mNotifications[$idx]->mOrder != $currentOrder) { + $this->mNotifications[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED; + $this->mNotifications[$idx]->mOrder = $currentOrder; + } + + $currentOrder++; + } + } + + function &get($name) + { + $ret = null; + + if (isset($this->mPreferences[$name])) { + return $this->mPreferences[$name]; + } + + return $ret; + } + + function &getNotify($name) + { + $ret = null; + + if (isset($this->mNotifications[$name])) { + return $this->mNotifications[$name]; + } + + return $ret; + } + + /** + * Updates the list of blocks by comparing with $collection. + * @todo need delete comments' data + * @todo need delete notifications' data + */ + function update(&$collection) + { + // + // Preferences + // + foreach (array_keys($this->mPreferences) as $idx) { + $t_preference =& $collection->get($this->mPreferences[$idx]->mName); + if ($t_preference == null) { + $this->mPreferences[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED; + } + elseif (!$this->mPreferences[$idx]->isEqual($t_preference)) { + $this->mPreferences[$idx]->update($t_preference); + } + } + + foreach (array_keys($collection->mPreferences) as $idx) { + $name = $collection->mPreferences[$idx]->mName; + if (!isset($this->mPreferences[$name])) { + $this->add($collection->mPreferences[$name]); + $this->mPreferences[$name]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW; + } + } + + // + // Comments + // + if (count($this->mComments) > 0 && count($collection->mComments) == 0) { + foreach (array_keys($this->mComments) as $idx) { + $this->mComments[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED; + } + } + elseif (count($this->mComments) == 0 && count($collection->mComments) > 0) { + $this->mComments =& $collection->mComments; + foreach (array_keys($this->mComments) as $idx) { + $this->mComments[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW; + } + } + + // + // Notifications + // + foreach (array_keys($this->mNotifications) as $idx) { + $t_preference =& $collection->getNotify($this->mNotifications[$idx]->mName); + if ($t_preference == null) { + $this->mNotifications[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED; + } + elseif (!$this->mNotifications[$idx]->isEqual($t_preference)) { + $this->mNotifications[$idx]->update($t_preference); + } + } + + foreach (array_keys($collection->mNotifications) as $idx) { + $name = $collection->mNotifications[$idx]->mName; + if (!isset($this->mNotifications[$name])) { + $this->add($collection->mNotifications[$name]); + $this->mNotifications[$name]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW; + } + } + } + + function reset() + { + unset($this->mPreferences); + $this->mPreferences = array(); + } +} + +class Legacy_PreferenceOptionInformation +{ + var $mName = ""; + var $mValue = ""; + + function Legacy_PreferenceOptionInformation($name, $value) + { + $this->mName = $name; + $this->mValue = $value; + } + + function isEqual($option) + { + return (($this->mName == $option->mName) && ($this->mValue == $option->mValue)); + } +} + +class Legacy_PreferenceOptionInfoCollection +{ + var $mOptions = array(); + + function Legacy_PreferenceOptionInfoCollection() + { + } + + function add(&$option) + { + $this->mOptions[] =& $option; + return true; + } + + function isEqual(&$collection) + { + if (count($this->mOptions) != count($collection->mOptions)) { + return false; + } + + foreach (array_keys($this->mOptions) as $idx) { + if (!$this->mOptions[$idx]->isEqual($collection->mOptions[$idx])) { + return false; + } + } + + return true; + } + + function reset() + { + unset($this->mOptions); + $this->mOptions = array(); + } +} + +class Legacy_AbstractModinfoReader +{ + function Legacy_AbstractModinfoReader() + { + } + + /** + * @return Legacy_BlockInfoCollection + */ + function &loadBlockInformations() + { + } + + /** + * @return Legacy_PreferenceInfoCollection + */ + function &loadPreferenceInformations() + { + } +} + +/** + * @note final class + */ +class Legacy_ModinfoX2FileReader extends Legacy_AbstractModinfoReader +{ + /** + * @protected + */ + var $_mDirname = null; + + function Legacy_ModinfoX2FileReader($dirname) + { + $this->_mDirname = $dirname; + } + + /** + * @private + */ + function &_createBlockInformation($funcNum, $arr) + { + $showFunc = ""; + if (isset($arr['class'])) { + $showFunc = 'cl::' . $arr['class']; + } + else { + $showFunc = $arr['show_func']; + } + + $editFunc = isset($arr['edit_func']) ? $arr['edit_func'] : null; + $template = isset($arr['template']) ? $arr['template'] : null; + $options = isset($arr['options']) ? $arr['options'] : null; + + $info =& new Legacy_BlockInformation($funcNum, $arr['name'], $arr['file'], $showFunc, $editFunc, $template, $options); + + return $info; + } + + /** + * @todo Need guarantee of global variables. + */ + function &loadBlockInformations() + { + $collection =& new Legacy_BlockInfoCollection(); + + $t_filePath = XOOPS_ROOT_PATH . '/modules/' . $this->_mDirname . '/xoops_version.php'; + if (!file_exists($t_filePath)) { + return $collection; + } + + include $t_filePath; + + if (!isset($modversion['blocks'])) { + return $collection; + } + + $blockArr = $modversion['blocks']; + + // + // Try (1) --- func_num + // + $successFlag = true; + foreach ($blockArr as $idx => $block) { + if (isset($block['func_num'])) { + $info =& $this->_createBlockInformation($block['func_num'], $block); + $successFlag &= $collection->add($info); + unset($info); + } + else { + $successFlag = false; + break; + } + } + + if ($successFlag) { + return $collection; + } + + // + // Try (2) --- index pattern + // + $collection->reset(); + + $successFlag = true; + foreach ($blockArr as $idx => $block) { + if (is_int($idx)) { + $info =& $this->_createBlockInformation($idx, $block); + $successFlag &= $collection->add($info); + unset($info); + } + else { + $successFlag = false; + break; + } + } + + if ($successFlag) { + return $collection; + } + + // + // Try (3) --- automatic + // + $collection->reset(); + + $idx = 1; + foreach ($blockArr as $block) { + $info =& $this->_createBlockInformation($idx++, $block); + $successFlag &= $collection->add($info); + unset($info); + } + + return $collection; + } + + function &_createPreferenceInformation($arr) + { + $arr['description'] = isset($arr['description']) ? $arr['description'] : null; + $info =& new Legacy_PreferenceInformation($arr['name'], $arr['title'], $arr['description'], $arr['formtype'], $arr['valuetype'], $arr['default']); + if (isset($arr['options'])) { + foreach ($arr['options'] as $name => $value) { + $option =& new Legacy_PreferenceOptionInformation($name, $value); + $info->mOption->add($option); + } + } + + return $info; + } + + function _loadCommentPreferenceInfomations(&$modversion, &$collection) + { + if (isset($modversion['hasComments']) && $modversion['hasComments'] == true) { + require_once XOOPS_ROOT_PATH . "/include/comment_constants.php"; + + $comRule = array('name' => 'com_rule', + 'title' => '_CM_COMRULES', + 'description' => '', + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => 1, + 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN) + ); + $info =& $this->_createPreferenceInformation($comRule); + $collection->add($info); + unset($info); + + $comAnonpost = array('name' => 'com_anonpost', + 'title' => '_CM_COMANONPOST', + 'description' => '', + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0 + ); + $info =& $this->_createPreferenceInformation($comAnonpost); + $collection->add($info); + unset($info); + } + } + + function _loadNotificationPreferenceInfomations(&$modversion, &$collection) + { + if (isset($modversion['hasNotification']) && $modversion['hasNotification'] == true) { + require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; + require_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; + + $t_options = array(); + $t_options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; + $t_options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; + $t_options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; + $t_options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; + + $notifyEnable = array( + 'name' => 'notification_enabled', + 'title' => '_NOT_CONFIG_ENABLE', + 'description' => '_NOT_CONFIG_ENABLEDSC', + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, + 'options' => $t_options + ); + $info =& $this->_createPreferenceInformation($notifyEnable); + $collection->add($info); + unset($info); + + // + // FIXME: doesn't work when update module... can't read back the + // array of options properly... " changing to " + // + + unset ($t_options); + + // + // Get the module object to get mid. + // + $handler =& xoops_gethandler('module'); + $module =& $handler->getByDirname($this->_mDirname); + + $t_options = array(); + $t_categoryArr =& notificationCategoryInfo('', $module->get('mid')); + foreach ($t_categoryArr as $t_category) { + $t_eventArr =& notificationEvents($t_category['name'], false, $module->get('mid')); + foreach ($t_eventArr as $t_event) { + if (!empty($t_event['invisible'])) { + continue; + } + $t_optionName = $t_category['title'] . ' : ' . $t_event['title']; + $t_options[$t_optionName] = $t_category['name'] . '-' . $t_event['name']; + } + } + + $notifyEvents = array( + 'name' => 'notification_events', + 'title' => '_NOT_CONFIG_EVENTS', + 'description' => '_NOT_CONFIG_EVENTSDSC', + 'formtype' => 'select_multi', + 'valuetype' => 'array', + 'default' => array_values($t_options), + 'options' => $t_options + ); + $info =& $this->_createPreferenceInformation($notifyEvents); + $collection->add($info); + unset($info); + } + } + + /** + * @note Because XoopsModule class of X2 kernel is too complex, this method + * parses xoops_version directly. + * @todo Need guarantee of global variables. + */ + function &loadPreferenceInformations() + { + $collection =& new Legacy_PreferenceInfoCollection(); + + $t_filePath = XOOPS_ROOT_PATH . '/modules/' . $this->_mDirname . '/xoops_version.php'; + if (!file_exists($t_filePath)) { + return $collection; + } + + include $t_filePath; + + // + // If the module does not have any pereferences, check comments & notifications, and return. + // + if (!isset($modversion['config'])) { + $this->_loadCommentPreferenceInfomations($modversion, $collection); + $this->_loadNotificationPreferenceInfomations($modversion, $collection); + return $collection; + } + + $preferenceArr = $modversion['config']; + + // + // Try (1) --- name index pattern + // + $successFlag = true; + foreach ($preferenceArr as $idx => $preference) { + if (is_string($idx)) { + $preference['name'] = $idx; + $info =& $this->_createPreferenceInformation($preference); + $successFlag &= $collection->add($info); + unset($info); + } + else { + $successFlag = false; + break; + } + } + + // + // Try (2) --- auto number + // + if (!$successFlag) { + $collection->reset(); + + foreach ($preferenceArr as $preference) { + $info =& $this->_createPreferenceInformation($preference); + $collection->add($info); + unset($info); + } + } + + // + // Add comments & notifications + // + $this->_loadCommentPreferenceInfomations($modversion, $collection); + $this->_loadNotificationPreferenceInfomations($modversion, $collection); + + return $collection; + } +} + +class Legacy_ModinfoX2DBReader extends Legacy_AbstractModinfoReader +{ + /** + * @protected + */ + var $_mDirname = null; + + function Legacy_ModinfoX2DBReader($dirname) + { + $this->_mDirname = $dirname; + } + + function &_createBlockInformation(&$block) + { + $info =& new Legacy_BlockInformation($block->get('func_num'), $block->get('name'), $block->get('func_file'), $block->get('show_func'), $block->get('edit_func'), $block->get('template'), $block->get('options')); + return $info; + } + + function &loadBlockInformations() + { + $collection =& new Legacy_BlockInfoCollection(); + + $handler =& xoops_getmodulehandler('newblocks', 'legacy'); + $criteria =& new Criteria('dirname', $this->_mDirname); + $blockArr =& $handler->getObjects($criteria); + + foreach (array_keys($blockArr) as $idx) { + $info =& $this->_createBlockInformation($blockArr[$idx]); + while (!$collection->add($info)) { + $info->mFuncNum++; + } + } + + return $collection; + } + + function &_createPreferenceInformation(&$config) + { + $info =& new Legacy_PreferenceInformation($config->get('conf_name'), $config->get('conf_title'), $config->get('conf_desc'), $config->get('conf_formtype'), $config->get('conf_valuetype'), $config->get('conf_value')); + + $configOptionArr =& $config->getOptionItems(); + + foreach (array_keys($configOptionArr) as $idx) { + $option =& new Legacy_PreferenceOptionInformation($configOptionArr[$idx]->get('confop_name'), $configOptionArr[$idx]->get('confop_value')); + $info->mOption->add($option); + unset($option); + } + + return $info; + } + + function &loadPreferenceInformations() + { + $collection =& new Legacy_PreferenceInfoCollection(); + + $handler =& xoops_gethandler('module'); + $module =& $handler->getByDirname($this->_mDirname); + + $handler =& xoops_gethandler('config'); + $criteria =& new Criteria('conf_modid', $module->get('mid')); + $criteria->setOrder('conf_order'); + $configArr =& $handler->getConfigs($criteria); + + foreach (array_keys($configArr) as $idx) { + $info =& $this->_createPreferenceInformation($configArr[$idx]); + $collection->add($info); + } + + return $collection; + } +} + +?> \ No newline at end of file Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php diff -u /dev/null xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.4.1 --- /dev/null Mon Apr 30 16:30:54 2007 +++ xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php Mon Apr 30 16:30:54 2007 @@ -0,0 +1,1213 @@ +<?php + +if (!defined('XOOPS_ROOT_PATH')) exit(); + +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallInformation.class.php"; +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstaller.class.php"; +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUpdater.class.php"; +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUninstaller.class.php"; + +require_once XOOPS_ROOT_PATH."/class/template.php"; + +define("MODINSTALL_LOGTYPE_REPORT", "report"); +define("MODINSTALL_LOGTYPE_WARNING", "warning"); +define("MODINSTALL_LOGTYPE_ERROR", "error"); + +/** + * A temporary log class. + */ +class Legacy_ModuleInstallLog +{ + var $mFetalErrorFlag = false; + var $mMessages = array(); + + function add($msg) + { + $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_REPORT, 'message' => $msg); + } + + function addReport($msg) + { + $this->add($msg); + } + + function addWarning($msg) + { + $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_WARNING, 'message' => $msg); + } + + function addError($msg) + { + $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_ERROR, 'message' => $msg); + $this->mFetalErrorFlag = true; + } + + function hasError() + { + return $this->mFetalErrorFlag; + } +} + +/** + * This class is collection of static utility functions for module installation. + * These functions are useful for Legacy modules' system-fixed-installer and + * modules' custom-installer. All functions for the custom-installer are added + * notes as "FOR THE CUSTOM-ISNTALLER". + * + * For more attentions, see base classes for the custom-installer. + * + * @see Legacy_PhasedUpgrader + */ +class Legacy_ModuleInstallUtils +{ + /** + * This is factory for the installer. The factory reads xoops_version + * without modulehandler, to prevent cache in modulehandler. + */ + function &createInstaller($dirname) + { + $installer =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'installer', 'Legacy_ModuleInstaller'); + return $installer; + } + + /** + * This is factory for the updater. The factory reads xoops_version + * without modulehandler, to prevent cache in modulehandler. + */ + function &createUpdater($dirname) + { + $updater =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'updater', 'Legacy_ModulePhasedUpgrader'); + return $updater; + } + + /** + * This is factory for the uninstaller. The factory reads xoops_version + * without modulehandler, to prevent cache in modulehandler. + */ + function &createUninstaller($dirname) + { + $uninstaller =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'uninstaller', 'Legacy_ModuleUninstaller'); + return $uninstaller; + } + + /** + * The generic factory for installers. This function is used by other + * utility functions. + * @param string $dirname + * @param string $mode 'installer' 'updater' or 'uninstaller' + * @param string $defaultClassName + */ + function &_createInstaller($dirname, $mode, $defaultClassName) + { + $info = array(); + + $filepath = XOOPS_MODULE_PATH . "/${dirname}/xoops_version.php"; + if (file_exists($filepath)) { + @include $filepath; + $info = $modversion; + } + + if (isset($info['legacy_installer']) && is_array($info['legacy_installer']) && isset($info['legacy_installer'][$mode])) { + $updateInfo = $info['legacy_installer'][$mode]; + + $className = $updateInfo['class']; + $filePath = isset($updateInfo['filepath']) ? $updateInfo['filepath'] : XOOPS_MODULE_PATH . "/${dirname}/admin/class/${className}.class.php"; + $namespace = isset($updateInfo['namespace']) ? $updateInfo['namespace'] : ucfirst($dirname); + + if ($namespace != null) { + $className = "${namespace}_${className}"; + } + + if (!class_exists($className) && file_exists($filePath)) { + require_once $filePath; + } + + if (class_exists($className)) { + $installer =& new $className(); + return $installer; + } + } + + $installer =& new $defaultClassName(); + return $installer; + } + + + /** + * Executes SQL file which xoops_version of $module specifies. This + * function is usefull for installers, but it's impossible to control + * for detail. + * + * @static + * @param XoopsModule $module + * @param Legacy_ModuleInstallLog $log + * @note FOR THE CUSTOM-INSTALLER + */ + function installSQLAutomatically(&$module, &$log) + { + $sqlfileInfo =& $module->getInfo('sqlfile'); + $dirname = $module->getVar('dirname'); + + if (!isset($sqlfileInfo[XOOPS_DB_TYPE])) { + return; + } + + $sqlfile = $sqlfileInfo[XOOPS_DB_TYPE]; + $sqlfilepath = XOOPS_MODULE_PATH . "/${dirname}/${sqlfile}"; + + if (isset($module->modinfo['cube_style']) && $module->modinfo['cube_style'] == true) { + require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php"; + $scanner =& new Legacy_SQLScanner(); + $scanner->setDB_PREFIX(XOOPS_DB_PREFIX); + $scanner->setDirname($module->get('dirname')); + + if (!$scanner->loadFile($sqlfilepath)) { + $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_SQL_FILE_NOT_FOUND, $sqlfile)); + return false; + } + + $scanner->parse(); + $sqls = $scanner->getSQL(); + + $root =& XCube_Root::getSingleton(); + $db =& $root->mController->getDB(); + + // + // TODO The following variable exists for rollback, but it is not implemented. + // + foreach ($sqls as $sql) { + if (!$db->query($sql)) { + $log->addError($db->error()); + return; + } + } + + $log->addReport(_AD_LEGACY_MESSAGE_DATABASE_SETUP_FINISHED); + } + else { + require_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php'; + + $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups','groups_users_link','group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish'); + + $root =& XCube_Root::getSingleton(); + $db =& $root->mController->mDB; + + $sql_query = fread(fopen($sqlfilepath, 'r'), filesize($sqlfilepath)); + $sql_query = trim($sql_query); + SqlUtility::splitMySqlFile($pieces, $sql_query); + $created_tables = array(); + foreach ($pieces as $piece) { + // [0] contains the prefixed query + // [4] contains unprefixed table name + $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix()); + if (!$prefixed_query) { + $log->addError("${piece} is not a valid SQL!"); + return; + } + + // check if the table name is reserved + if (!in_array($prefixed_query[4], $reservedTables)) { + // not reserved, so try to create one + if (!$db->query($prefixed_query[0])) { + $log->addError($db->error()); + return; + } + else { + if (!in_array($prefixed_query[4], $created_tables)) { + $log->addReport(' Table ' . $db->prefix($prefixed_query[4]) . ' created.'); + $created_tables[] = $prefixed_query[4]; + } + else { + $log->addReport(' Data inserted to table ' . $db->prefix($prefixed_query[4])); + } + } + } + else { + // the table name is reserved, so halt the installation + $log->addError($prefixed_query[4] . " is a reserved table!"); + return; + } + } + } + } + + /** + * Installs all of module templates $module specify. This function is + * usefull for installer and updater. In the case of updater, you should + * uninstall all of module templates before this function. + * + * This function gets informations about templates from xoops_version. + * + * @warning + * + * This function depends the specific spec of Legacy_RenderSystem, but this + * static function is needed by the 2nd installer of Legacy System. + * + * @static + * @param XoopsModule $module + * @param Legacy_ModuleInstallLog $log + * @note FOR THE CUSTOM-INSTALLER + * @see Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates() + */ + function installAllOfModuleTemplates(&$module, &$log) + { + $templates = $module->getInfo('templates'); + if ($templates != false) { + foreach ($templates as $template) { + Legacy_ModuleInstallUtils::installModuleTemplate($module, $template, $log); + } + } + } + + /** + * Inserts the specified template to DB. + * + * @warning + * + * This function depends the specific spec of Legacy_RenderSystem, but this + * static function is needed by the 2nd installer of Legacy System. + * + * @static + * @param XoopsModule $module + * @param string[][] $template + * @param Legacy_ModuleInstallLog $log + * @return bool + * + * @note This is not usefull a litte for custom-installers. + * @todo We'll need the way to specify the template by identity or others. + */ + function installModuleTemplate($module, $template, &$log) + { + $tplHandler =& xoops_gethandler('tplfile'); + + $fileName = trim($template['file']); + + $tpldata = Legacy_ModuleInstallUtils::readTemplateFile($module->get('dirname'), $fileName); + if ($tpldata == false) + return false; + + // + // Create template file object, then store it. + // + $tplfile =& $tplHandler->create(); + $tplfile->setVar('tpl_refid', $module->getVar('mid')); + $tplfile->setVar('tpl_lastimported', 0); + $tplfile->setVar('tpl_lastmodified', time()); + + if (preg_match("/\.css$/i", $fileName)) { + $tplfile->setVar('tpl_type', 'css'); + } + else { + $tplfile->setVar('tpl_type', 'module'); + } + + $tplfile->setVar('tpl_source', $tpldata, true); + $tplfile->setVar('tpl_module', $module->getVar('dirname')); + $tplfile->setVar('tpl_tplset', 'default'); + $tplfile->setVar('tpl_file', $fileName, true); + + $description = isset($template['description']) ? $template['description'] : ''; + $tplfile->setVar('tpl_desc', $description, true); + + if ($tplHandler->insert($tplfile)) { + $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_TEMPLATE_INSTALLED, $fileName)); + } + else { + $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_TEMPLATE, $fileName)); + return false; + } + } + + /** + * Uninstalls all of module templates $module specify. This function is + * usefull for uninstaller and updater. In the case of update, you should + * call this function before installAllOfModuleTemplates(). In the case of + * uninstall, you must set 'false' to $defaultOnly. + * + * This function gets informations about templates from the database. + * + * @warning + * + * This function depends the specific spec of Legacy_RenderSystem, but this + * static function is needed by the 2nd installer of Legacy System. + * + * @static + * @param XoopsModule $module + * @param Legacy_ModuleInstallLog $log + * @param bool $defaultOnly Indicates whether this function deletes templates from all of tplsets. + * @note FOR THE CUSTOM-INSTALLER + * @see Legacy_ModuleInstallUtils::installAllOfModuleTemplates() + */ + function uninstallAllOfModuleTemplates(&$module, &$log, $defaultOnly = true) + { + + // + // The following processing depends on the structure of Legacy_RenderSystem. + // + $tplHandler =& xoops_gethandler('tplfile'); + $delTemplates = null; + + if ($defaultOnly) { + $delTemplates =& $tplHandler->find('default', 'module', $module->get('mid')); + } + else { + $delTemplates =& $tplHandler->find(null, 'module', $module->get('mid')); + } + + if (is_array($delTemplates) && count($delTemplates) > 0) { + // + // clear cache + // + $xoopsTpl =& new XoopsTpl(); + $xoopsTpl->clear_cache(null, "mod_" . $module->get('dirname')); + + foreach ($delTemplates as $tpl) { + if (!$tplHandler->delete($tpl)) { + $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_TEMPLATE_UNINSTALLED, $tpl->get('tpl_file'))); + } + } + } + } + + /** + * Installs all of blocks $module specify. + * + * This function gets informations about blocks from xoops_version. + * + * @static + * @param XoopsModule $module + * @param Legacy_ModuleInstallLog $log + * @note FOR THE CUSTOM-INSTALLER + * @see Legacy_ModuleInstallUtils::uninstallAllOfBlocks() + */ + function installAllOfBlocks(&$module, &$log) + { + $definedBlocks = $module->getInfo('blocks'); + if($definedBlocks == false) { + return true; + } + + $func_num = 0; + foreach ($definedBlocks as $block) { + $func_num++; + $newBlock =& Legacy_ModuleInstallUtils::createBlockByInfo($module, $block, $func_num); + Legacy_ModuleInstallUtils::installBlock($module, $newBlock, $block, $log); + } + } + + /** + * Uninstalls all of blocks which $module specifies, and its permissions. + * + * This function gets informations about templates from the database. + * + * @static + * @param XoopsModule $module + * @param Legacy_ModuleInstallLog $log + * @return bool + * + * @note FOR THE CUSTOM-INSTALLER + * @see Legacy_ModuleInstallUtils::installAllOfBlocks() + * @see Legacy_ModuleInstallUtils::uninstallBlock() + */ + function uninstallAllOfBlocks(&$module, &$log) + { + $handler =& xoops_gethandler('block'); + $criteria = new Criteria('mid', $module->get('mid')); + + $blockArr =& $handler->getObjectsDirectly($criteria); + + $successFlag = true; + + foreach (array_keys($blockArr) as $idx) { + $successFlag &= Legacy_ModuleInstallUtils::uninstallBlock($blockArr[$idx], $log); + } + + return $successFlag; + } + + /** + * Create XoopsBlock object by array that is defined in xoops_version, return it. + * @param $module XoopsModule + * @param $block array + * @return XoopsBlock + */ + function &createBlockByInfo(&$module, $block, $func_num) + { + $options = isset($block['options']) ? $block['options'] : null; + $edit_func = isset($block['edit_func']) ? $block['edit_func'] : null; + $template = isset($block['template']) ? $block['template'] : null; + $visible = isset($block['visible']) ? $block['visible'] : (isset($block['visible_any']) ? $block['visible_any']: 0); + $blockHandler =& xoops_gethandler('block'); + $blockObj =& $blockHandler->create(); + + $blockObj->set('mid', $module->getVar('mid')); + $blockObj->set('options', $options); + $blockObj->set('name', $block['name']); + $blockObj->set('title', $block['name']); + $blockObj->set('block_type', 'M'); + $blockObj->set('c_type', 1); + $blockObj->set('isactive', 1); + $blockObj->set('dirname', $module->getVar('dirname')); + $blockObj->set('func_file', $block['file']); + + // + // IMPORTANT CONVENTION + // + $show_func = ""; + if (isset($block['class'])) { + $show_func = "cl::" . $block['class']; + } + else { + $show_func = $block['show_func']; + } + + $blockObj->set('show_func', $show_func); + $blockObj->set('edit_func', $edit_func); + $blockObj->set('template', $template); + $blockObj->set('last_modified', time()); + $blockObj->set('visible', $visible); + + $func_num = isset($block['func_num']) ? intval($block['func_num']) : $func_num; + $blockObj->set('func_num', $func_num); + + return $blockObj; + } + + /** + * This function can receive both new and update. + * @param $module XoopsModule + * @param $blockObj XoopsBlock + * @param $block array + * @return bool + */ + function installBlock(&$module, &$blockObj, &$block, &$log) + { + $isNew = $blockObj->isNew(); + $blockHandler =& xoops_gethandler('block'); + + if (!empty($block['show_all_module'])) { + $autolink = false; + } else { + $autolink = true; + } + if (!$blockHandler->insert($blockObj, $autolink)) { + $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_BLOCK, $blockObj->getVar('name'))); + + return false; + } + else { + $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_INSTALLED, $blockObj->getVar('name'))); + + $tplHandler =& xoops_gethandler('tplfile'); + + Legacy_ModuleInstallUtils::installBlockTemplate($blockObj, $module, $log); + + // + // Process of a permission. + // + if ($isNew) { + if (!empty($block['show_all_module'])) { + $link_sql = "INSERT INTO " . $blockHandler->db->prefix('block_module_link') . " (block_id, module_id) VALUES (".$blockObj->getVar('bid').", 0)"; + if (!$blockHandler->db->query($link_sql)) { + $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_LINK, $blockObj->getVar('name'))); + } + } + $gpermHandler =& xoops_gethandler('groupperm'); + $bperm =& $gpermHandler->create(); + $bperm->setVar('gperm_itemid', $blockObj->getVar('bid')); + $bperm->setVar('gperm_name', 'block_read'); + $bperm->setVar('gperm_modid', 1); + + if (!empty($block['visible_any'])) { + $memberHandler =& xoops_gethandler('member'); + $groupObjects =& $memberHandler->getGroups(); + foreach($groupObjects as $group) { + $bperm->setVar('gperm_groupid', $group->getVar('groupid')); + $bperm->setNew(); + if (!$gpermHandler->insert($bperm)) { + $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_BLOCK_PERMISSION, $blockObj->getVar('name'))); + } + } + } else { + $root =& XCube_Root::getSingleton(); + $groups = $root->mContext->mXoopsUser->getGroups(); + foreach ($groups as $mygroup) { + $bperm->setVar('gperm_groupid', $mygroup); + $bperm->setNew(); + if (!$gpermHandler->insert($bperm)) { + $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_BLOCK_PERMISSION, $blockObj->getVar('name'))); + } + } + } + } + + return true; + } + } + + /** + * Uninstalls a block which $block specifies. In the same time, deletes + * permissions for the block. + * + * @param XoopsBlock $block + * @param Legacy_ModuleInstallLog $log + * @note FOR THE CUSTOM-INSTALLER + * + * @todo error handling & delete the block's template. + */ + function uninstallBlock(&$block, &$log) + { + $blockHandler =& xoops_gethandler('block'); + $blockHandler->delete($block); + $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_BLOCK_SUCCESSFUL, $block->get('name'))); + + // + // Deletes permissions + // + $gpermHandler =& xoops_gethandler('groupperm'); + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('gperm_name', 'block_read')); + $criteria->add(new Criteria('gperm_itemid', $block->get('bid'))); + $criteria->add(new Criteria('gperm_modid', 1)); + $gpermHandler->deleteAll($criteria); + } + + /** + * Save the information of block's template specified and the source code of it + * to database. + * @return bool + */ + function installBlockTemplate(&$block, &$module, &$log) + { + if ($block->get('template') == null) { + return true; + } + + $tplHandler =& xoops_gethandler('tplfile'); + + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('tpl_type', 'block')); + $criteria->add(new Criteria('tpl_tplset', 'default')); + $criteria->add(new Criteria('tpl_module', $module->get('dirname'))); + $criteria->add(new Criteria('tpl_file', $block->get('template'))); + $tplfiles =& $tplHandler->getObjects($criteria); + + if (count($tplfiles) > 0) { + $tplfile =& $tplfiles[0]; + } + else { + $tplfile =& $tplHandler->create(); + $tplfile->set('tpl_refid', $block->get('bid')); + $tplfile->set('tpl_tplset', 'default'); + $tplfile->set('tpl_file', $block->get('template')); + $tplfile->set('tpl_module', $module->get('dirname')); + $tplfile->set('tpl_type', 'block'); + // $tplfile->setVar('tpl_desc', $tpl_desc); + $tplfile->set('tpl_lastimported', 0); + } + + $tplSource = Legacy_ModuleInstallUtils::readTemplateFile($module->get('dirname'), $block->get('template'), true); + $tplfile->set('tpl_source', $tplSource); + $tplfile->set('tpl_lastmodified', time()); + + if ($tplHandler->insert($tplfile)) { + $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_TEMPLATE_INSTALLED, $block->get('template'))); + return true; + } + else { + $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_BLOCK_TEMPLATE_INSTALL, $blockObj->get('name'))); + return false; + } + } + + /** + * Read template file, return it. + * + * @note This is must, but it depends on ... + */ + function readTemplateFile($dirname, $fileName, $isblock = false) + { + // + // Load template data + // + if ($isblock) { + $filePath = XOOPS_MODULE_PATH . "/" . $dirname . "/templates/blocks/" . $fileName; + } + else { + $filePath = XOOPS_MODULE_PATH . "/" . $dirname . "/templates/" . $fileName; + } + + if (!file_exists($filePath)) { + return false; + } + + $lines = file($filePath); + if ($lines == false) { + return false; + } + + $tpldata = ""; + foreach ($lines as $line) { + // + // Unify linefeed to "\r\n" + // + $tpldata .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $line)); + } + + return $tpldata; + } + + function installAllOfConfigs(&$module, &$log) + { + $dirname = $module->get('dirname'); + + $fileReader =& new Legacy_ModinfoX2FileReader($dirname); + $preferences =& $fileReader->loadPreferenceInformations(); + + // + // Preferences + // + foreach (array_keys($preferences->mPreferences) as $idx) { + Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mPreferences[$idx], $module, $log); + } + + // + // Comments + // + foreach (array_keys($preferences->mComments) as $idx) { + Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mComments[$idx], $module, $log); + } + + // + // Notifications + // + foreach (array_keys($preferences->mNotifications) as $idx) { + Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mNotifications[$idx], $module, $log); + } + } + + function installPreferenceByInfo(&$info, &$module, &$log) + { + $handler =& xoops_gethandler('config'); + $config =& $handler->createConfig(); + $config->set('conf_modid', $module->get('mid')); + $config->set('conf_catid', 0); + $config->set('conf_name', $info->mName); + $config->set('conf_title', $info->mTitle); + $config->set('conf_desc', $info->mDescription); + $config->set('conf_formtype', $info->mFormType); + $config->set('conf_valuetype', $info->mValueType); + $config->setConfValueForInput($info->mDefault); + $config->set('conf_order', $info->mOrder); + + if (count($info->mOption->mOptions) > 0) { + foreach (array_keys($info->mOption->mOptions) as $idx) { + $option =& $handler->createConfigOption(); + $option->set('confop_name', $info->mOption->mOptions[$idx]->mName); + $option->set('confop_value', $info->mOption->mOptions[$idx]->mValue); + $config->setConfOptions($option); + unset($option); + } + } + + if ($handler->insertConfig($config)) { + $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_INSERT_CONFIG, $config->get('conf_name'))); + } + else { + $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSERT_CONFIG, $config->get('conf_name'))); + } + } + + /** + * Get & build config items from Manifesto by specific module object. + */ + function &getConfigInfosFromManifesto(&$module) + { + $configInfos = $module->getInfo('config'); + + // + // Insert comment config by old style. + // + if ($module->getVar('hascomments') !=0 ) { + require_once XOOPS_ROOT_PATH . "/include/comment_constants.php"; + + $configInfos[] = array('name' => 'com_rule', + 'title' => '_CM_COMRULES', + 'description' => '', + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => 1, + 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN) + ); + + $configInfos[] = array('name' => 'com_anonpost', + 'title' => '_CM_COMANONPOST', + 'description' => '', + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0 + ); + } + + // + // Insert comment config by old style. + // + if ($module->get('hasnotification') != 0) { + require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; + require_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; + + $t_options = array(); + $t_options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; + $t_options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; + $t_options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; + $t_options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; + + $configInfos[] = array( + 'name' => 'notification_enabled', + 'title' => '_NOT_CONFIG_ENABLE', + 'description' => '_NOT_CONFIG_ENABLEDSC', + 'formtype' => 'select', + 'valuetype' => 'int', + 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, + 'options' => $t_options + ); + + // + // FIXME: doesn't work when update module... can't read back the + // array of options properly... " changing to " + // + + unset ($t_options); + + $t_options = array(); + $t_categoryArr =& notificationCategoryInfo('', $module->get('mid')); + foreach ($t_categoryArr as $t_category) { + $t_eventArr =& notificationEvents($t_category['name'], false, $module->get('mid')); + foreach ($t_eventArr as $t_event) { + if (!empty($t_event['invisible'])) { + continue; + } + $t_optionName = $t_category['title'] . ' : ' . $t_event['title']; + $t_options[$t_optionName] = $t_category['name'] . '-' . $t_event['name']; + } + } + + $configInfos[] = array( + 'name' => 'notification_events', + 'title' => '_NOT_CONFIG_EVENTS', + 'description' => '_NOT_CONFIG_EVENTSDSC', + 'formtype' => 'select_multi', + 'valuetype' => 'array', + 'default' => array_values($t_options), + 'options' => $t_options + ); + } + + return $configInfos; + } + + /** + * Delete all configs of $module. + * + * @param $module XoopsModule + */ + function uninstallAllOfConfigs(&$module, &$log) + { + if ($module->get('hasconfig') == 0) { + return; + } + + $configHandler =& xoops_gethandler('config'); + $configs =& $configHandler->getConfigs(new Criteria('conf_modid', $module->get('mid'))); + + if (count($configs) == 0) { + return; + } + + foreach ($configs as $config) { + $configHandler->deleteConfig($config); + } + } + + function smartUpdateAllOfBlocks(&$module, &$log) + { + $dirname = $module->get('dirname'); + + $fileReader =& new Legacy_ModinfoX2FileReader($dirname); + $latestBlocks =& $fileReader->loadBlockInformations(); + + $dbReader =& new Legacy_ModinfoX2DBReader($dirname); + $currentBlocks =& $dbReader->loadBlockInformations(); + + $currentBlocks->update($latestBlocks); + + foreach (array_keys($currentBlocks->mBlocks) as $idx) { + switch ($currentBlocks->mBlocks[$idx]->mStatus) { + case LEGACY_INSTALLINFO_STATUS_LOADED: + Legacy_ModuleInstallUtils::updateBlockTemplateByInfo($currentBlocks->mBlocks[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_UPDATED: + Legacy_ModuleInstallUtils::updateBlockByInfo($currentBlocks->mBlocks[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_NEW: + Legacy_ModuleInstallUtils::installBlockByInfo($currentBlocks->mBlocks[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_DELETED: + Legacy_ModuleInstallUtils::uninstallBlockByFuncNum($currentBlocks->mBlocks[$idx]->mFuncNum, $module, $log); + break; + } + } + } + + function smartUpdateAllOfPreferences(&$module, &$log) + { + $dirname = $module->get('dirname'); + + $fileReader =& new Legacy_ModinfoX2FileReader($dirname); + $latestPreferences =& $fileReader->loadPreferenceInformations(); + + $dbReader =& new Legacy_ModinfoX2DBReader($dirname); + $currentPreferences =& $dbReader->loadPreferenceInformations(); + + $currentPreferences->update($latestPreferences); + + // + // Preferences + // + foreach (array_keys($currentPreferences->mPreferences) as $idx) { + switch ($currentPreferences->mPreferences[$idx]->mStatus) { + case LEGACY_INSTALLINFO_STATUS_UPDATED: + Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mPreferences[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED: + Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mPreferences[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_NEW: + Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mPreferences[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_DELETED: + Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mPreferences[$idx]->mOrder, $module, $log); + break; + } + } + + // + // Comments + // + foreach (array_keys($currentPreferences->mComments) as $idx) { + switch ($currentPreferences->mComments[$idx]->mStatus) { + case LEGACY_INSTALLINFO_STATUS_UPDATED: + Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mComments[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED: + Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mComments[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_NEW: + Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mComments[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_DELETED: + Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mComments[$idx]->mOrder, $module, $log); + break; + } + } + + // + // Notifications + // + foreach (array_keys($currentPreferences->mNotifications) as $idx) { + switch ($currentPreferences->mNotifications[$idx]->mStatus) { + case LEGACY_INSTALLINFO_STATUS_UPDATED: + Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mNotifications[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED: + Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mNotifications[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_NEW: + Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mNotifications[$idx], $module, $log); + break; + + case LEGACY_INSTALLINFO_STATUS_DELETED: + Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mNotifications[$idx]->mOrder, $module, $log); + break; + } + } + } + + function updateBlockTemplateByInfo(&$info, &$module, &$log) + { + $handler =& xoops_getmodulehandler('newblocks', 'legacy'); + + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('dirname', $module->get('dirname'))); + $criteria->add(new Criteria('func_num', $info->mFuncNum)); + + $blockArr =& $handler->getObjects($criteria); + foreach (array_keys($blockArr) as $idx) { + Legacy_ModuleInstallUtils::uninstallBlockTemplate($blockArr[$idx], $module, $log); + Legacy_ModuleInstallUtils::installBlockTemplate($blockArr[$idx], $module, $log); + } + } + + function updateBlockByInfo(&$info, &$module, &$log) + { + $handler =& xoops_getmodulehandler('newblocks', 'legacy'); + + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('dirname', $module->get('dirname'))); + $criteria->add(new Criteria('func_num', $info->mFuncNum)); + + $blockArr =& $handler->getObjects($criteria); + foreach (array_keys($blockArr) as $idx) { + $blockArr[$idx]->set('options', $info->mOptions); + $blockArr[$idx]->set('name', $info->mName); + $blockArr[$idx]->set('func_file', $info->mFuncFile); + $blockArr[$idx]->set('show_func', $info->mShowFunc); + $blockArr[$idx]->set('edit_func', $info->mEditFunc); + $blockArr[$idx]->set('template', $info->mTemplate); + + if ($handler->insert($blockArr[$idx])) { + $log->addReport(XCube_Utils::formatMessage('Update {0} block successfully.', $blockArr[$idx]->get('name'))); + } + else { + $log->addError(XCube_Utils::formatMessage('Could not update {0} block.', $blockArr[$idx]->get('name'))); + } + + Legacy_ModuleInstallUtils::uninstallBlockTemplate($blockArr[$idx], $module, $log); + Legacy_ModuleInstallUtils::installBlockTemplate($blockArr[$idx], $module, $log); + } + } + + function updatePreferenceByInfo(&$info, &$module, &$log) + { + $handler =& xoops_gethandler('config'); + + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('conf_modid', $module->get('mid'))); + $criteria->add(new Criteria('conf_catid', 0)); + $criteria->add(new Criteria('conf_name', $info->mName)); + + $configArr =& $handler->getConfigs($criteria); + + if (!(count($configArr) > 0 && is_object($configArr[0]))) { + $log->addError('Execption Error: Could not find config.'); + return; + } + + $config =& $configArr[0]; + + $config->set('conf_title', $info->mTitle); + $config->set('conf_desc', $info->mDescription); + + // + // Decide whether it changes values. + // + if ($config->get('conf_formtype') != $info->mFormType && $config->get('conf_valuetype') != $info->mValueType) { + $config->set('conf_formtype', $info->mFormType); + $config->set('conf_valuetype', $info->mValueType); + $config->setConfValueForInput($info->mDefault); + } + else { + $config->set('conf_formtype', $info->mFormType); + $config->set('conf_valuetype', $info->mValueType); + } + + $config->set('conf_order', $info->mOrder); + + $optionArr =& $handler->getConfigOptions(new Criteria('conf_id', $config->get('conf_id'))); + if (is_array($optionArr)) { + foreach (array_keys($optionArr) as $idx) { + $handler->_oHandler->delete($optionArr[$idx]); + } + } + + if (count($info->mOption->mOptions) > 0) { + foreach (array_keys($info->mOption->mOptions) as $idx) { + $option =& $handler->createConfigOption(); + $option->set('confop_name', $info->mOption->mOptions[$idx]->mName); + $option->set('confop_value', $info->mOption->mOptions[$idx]->mValue); + $option->set('conf_id', $option->get('conf_id')); + $config->setConfOptions($option); + unset($option); + } + } + + if ($handler->insertConfig($config)) { + $log->addReport(XCube_Utils::formatMessage("Preference '{0}' is updateded.", $config->get('conf_name'))); + } + else { + $log->addError(XCube_Utils::formatMessage("Could not update preference '{0}'.", $config->get('conf_name'))); + } + } + + function updatePreferenceOrderByInfo(&$info, &$module, &$log) + { + $handler =& xoops_gethandler('config'); + + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('conf_modid', $module->get('mid'))); + $criteria->add(new Criteria('conf_catid', 0)); + $criteria->add(new Criteria('conf_name', $info->mName)); + + $configArr =& $handler->getConfigs($criteria); + + if (!(count($configArr) > 0 && is_object($configArr[0]))) { + $log->addError('Execption Error: Could not find config.'); + return; + } + + $config =& $configArr[0]; + + $config->set('conf_order', $info->mOrder); + + if (!$handler->insertConfig($config)) { + $log->addError(XCube_Utils::formatMessage("Could not update the order of preference '{0}'.", $config->get('conf_name'))); + } + } + + function installBlockByInfo(&$info, &$module, &$log) + { + $handler =& xoops_gethandler('block'); + $block =& $handler->create(); + + $block->set('mid', $module->get('mid')); + $block->set('func_num', $info->mFuncNum); + $block->set('options', $info->mOptions); + $block->set('name', $info->mName); + $block->set('title', $info->mName); + $block->set('dirname', $module->get('dirname')); + $block->set('func_file', $info->mFuncFile); + $block->set('show_func', $info->mShowFunc); + $block->set('edit_func', $info->mEditFunc); + $block->set('template', $info->mTemplate); + $block->set('block_type', 'M'); + $block->set('c_type', 1); + + if (!$handler->insert($block)) { + $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_BLOCK, $block->get('name'))); + return false; + } + else { + $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_INSTALLED, $block->get('name'))); + + Legacy_ModuleInstallUtils::installBlockTemplate($block, $module, $log); + + return true; + } + } + + /** + * @todo Need a message in the fail case. + */ + function uninstallBlockByFuncNum($func_num, &$module, &$log) + { + $handler =& xoops_getmodulehandler('newblocks', 'legacy'); + + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('dirname', $module->get('dirname'))); + $criteria->add(new Criteria('func_num', $func_num)); + + $blockArr =& $handler->getObjects($criteria); + foreach (array_keys($blockArr) as $idx) { + if ($handler->delete($blockArr[$idx])) { + $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_BLOCK_SUCCESSFUL, $blockArr[$idx]->get('name'))); + } + else { + // Uninstall fail + } + + Legacy_ModuleInstallUtils::uninstallBlockTemplate($blockArr[$idx], $module, $log); + } + } + + function uninstallBlockTemplate(&$block, &$module, &$log) + { + $handler =& xoops_gethandler('tplfile'); + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('tpl_refid', $block->get('bid'))); + $criteria->add(new Criteria('tpl_file', $block->get('template'))); + $criteria->add(new Criteria('tpl_module', $module->get('dirname'))); + $criteria->add(new Criteria('tpl_type', 'block')); + + $handler->deleteAll($criteria); + } + + function uninstallPreferenceByOrder($order, &$module, &$log) + { + $handler =& xoops_gethandler('config'); + + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('conf_modid', $module->get('mid'))); + $criteria->add(new Criteria('conf_catid', 0)); + $criteria->add(new Criteria('conf_order', $order)); + + $configArr =& $handler->getConfigs($criteria); + + foreach (array_keys($configArr) as $idx) { + if ($handler->deleteConfig($configArr[$idx])) { + $log->addReport(XCube_Utils::formatMessage("Delete preference '{0}'.", $configArr[$idx]->get('conf_name'))); + } + else { + $log->addError(XCube_Utils::formatMessage("Could not delete preference '{0}'.", $configArr[$idx]->get('conf_name'))); + } + } + } + + /** + * Executes SQL query as cube style. + */ + function DBquery($query, &$module, $log) + { + require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php"; + + $successFlag = true; + + $scanner =& new Legacy_SQLScanner(); + $scanner->setDB_PREFIX(XOOPS_DB_PREFIX); + $scanner->setDirname($module->get('dirname')); + $scanner->setBuffer($query); + $scanner->parse(); + $sqlArr = $scanner->getSQL(); + + $root =& XCube_Root::getSingleton(); + + foreach ($sqlArr as $sql) { + if ($root->mController->mDB->query($sql)) { + $log->addReport("Success: ${sql}"); + $successFlag &= true; + } + else { + $log->addError("Failure: ${sql}"); + $successFlag = false; + } + } + + return $successFlag; + } + + function deleteAllOfNotifications(&$module, &$log) + { + $handler =& xoops_gethandler('notification'); + $criteria =& new Criteria('not_modid', $module->get('mid')); + $handler->deleteAll($criteria); + } + + function deleteAllOfComments(&$module, &$log) + { + $handler =& xoops_gethandler('comment'); + $criteria =& new Criteria('com_modid', $module->get('mid')); + $handler->deleteAll($criteria); + } +} + +?> \ No newline at end of file Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstaller.class.php diff -u /dev/null xoops2jp/html/modules/legacy/admin/class/ModuleInstaller.class.php:1.1.4.1 --- /dev/null Mon Apr 30 16:30:54 2007 +++ xoops2jp/html/modules/legacy/admin/class/ModuleInstaller.class.php Mon Apr 30 16:30:54 2007 @@ -0,0 +1,268 @@ +<?php +/** + * @package Legacy + * @version $Id: ModuleInstaller.class.php,v 1.1.4.1 2007/04/30 07:30:54 nobunobu Exp $ + */ + +if (!defined('XOOPS_ROOT_PATH')) exit(); + +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallUtils.class.php"; + +/** + * This class extends a base class for the process of install module. This is added + * some private functions. + * + * @todo It seems possibility to abstract with other installer classes. + */ +class Legacy_ModuleInstaller +{ + /** + * @public + * @var Legacy_ModuleInstallLog + */ + var $mLog = null; + + var $_mForceMode = false; + + /** + * @var XoopsModule + * @remark [Precondition] _mXoopsModule has to be an object. + */ + var $_mXoopsModule = null; + + function Legacy_ModuleInstaller() + { + $this->mLog =& new Legacy_ModuleInstallLog(); + } + + /** + * Sets the current XoopsModule. + * + * @public + * @param XoopsModule $xoopsModule + */ + function setCurrentXoopsModule(&$xoopsModule) + { + $this->_mXoopsModule =& $xoopsModule; + } + + /** + * Sets a value indicating whether the force mode is on. + * @param bool $isForceMode + */ + function setForceMode($isForceMode) + { + $this->_mForceMode = $isForceMode; + } + + function _installTables() + { + Legacy_ModuleInstallUtils::installSQLAutomatically($this->_mXoopsModule, $this->mLog); + } + + /** + * @todo Do rewrite. + */ + function _installModule() + { + $moduleHandler =& xoops_gethandler('module'); + if (!$moduleHandler->insert($this->_mXoopsModule)) { + $this->mLog->addError("*Could not install module information*"); + return false; + } + + $gpermHandler =& xoops_gethandler('groupperm'); + + // + // Add a permission which administrators can manage. + // + if ($this->_mXoopsModule->getInfo('hasAdmin')) { + $adminPerm =& $this->_createPermission(XOOPS_GROUP_ADMIN); + $adminPerm->setVar('gperm_name', 'module_admin'); + + if (!$gpermHandler->insert($adminPerm)) { + $this->mLog->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_ADMIN_PERMISSION); + } + } + + // + // Add a permission which administrators can manage. (Special for Legacy System Module) + // + if ($this->_mXoopsModule->getVar('dirname') == 'system') { + $root =& XCube_Root::getSingleton(); + $root->mLanguageManager->loadModuleAdminMessageCatalog('system'); + + require_once XOOPS_ROOT_PATH . "/modules/system/constants.php"; + + $fileHandler = opendir(XOOPS_ROOT_PATH . "/modules/system/admin"); + while ($file = readdir($fileHandler)) { + $infoFile = XOOPS_ROOT_PATH . "/modules/system/admin/" . $file . "/xoops_version.php"; + if (file_exists($infoFile)) { + require_once $infoFile; + if (!empty($modversion['category'])) { + $sysAdminPerm =& $this->_createPermission(XOOPS_GROUP_ADMIN); + $adminPerm->setVar('gperm_itemid', $modversion['category']); + $adminPerm->setVar('gperm_name', 'system_admin'); + if (!$gpermHandler->insert($adminPerm)) { + $this->mLog->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_SYSTEM_PERMISSION); + } + unset($sysAdminPerm); + } + unset($modversion); + } + } + } + + if ($this->_mXoopsModule->getInfo('hasMain')) { + $read_any = $this->_mXoopsModule->getInfo('read_any'); + if ($read_any) { + $memberHandler =& xoops_gethandler('member'); + $groupObjects =& $memberHandler->getGroups(); + // + // Add a permission all group members and guest can read. + // + foreach($groupObjects as $group) { + $readPerm =& $this->_createPermission($group->getVar('groupid')); + $readPerm->setVar('gperm_name', 'module_read'); + + if (!$gpermHandler->insert($readPerm)) { + $this->mLog->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_READ_PERMISSION); + } + } + } else { + // + // Add a permission which administrators can read. + // + $root =& XCube_Root::getSingleton(); + $groups = $root->mContext->mXoopsUser->getGroups(); + foreach($groups as $mygroup) { + $readPerm =& $this->_createPermission($mygroup); + $readPerm->setVar('gperm_name', 'module_read'); + + if (!$gpermHandler->insert($readPerm)) { + $this->mLog->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_READ_PERMISSION); + } + } + } + } + } + + /** + * Create a permission object which has been initialized for admin. + * For flexibility, creation only and not save it. + * @access private + * @param $group + */ + function &_createPermission($group) + { + $gpermHandler =& xoops_gethandler('groupperm'); + + $perm =& $gpermHandler->create(); + + $perm->setVar('gperm_groupid', $group); + $perm->setVar('gperm_itemid', $this->_mXoopsModule->getVar('mid')); + $perm->setVar('gperm_modid', 1); + + return $perm; + } + + /** + * @static + */ + function _installTemplates() + { + Legacy_ModuleInstallUtils::installAllOfModuleTemplates($this->_mXoopsModule, $this->mLog); + } + + function _installBlocks() + { + Legacy_ModuleInstallUtils::installAllOfBlocks($this->_mXoopsModule, $this->mLog); + } + + function _installPreferences() + { + Legacy_ModuleInstallUtils::installAllOfConfigs($this->_mXoopsModule, $this->mLog); + } + + function _processScript() + { + $installScript = trim($this->_mXoopsModule->getInfo('onInstall')); + if ($installScript != false) { + require_once XOOPS_MODULE_PATH . "/" . $this->_mXoopsModule->get('dirname') . "/" . $installScript; + $funcName = 'xoops_module_install_' . $this->_mXoopsModule->get('dirname'); + + if (!preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*$/", $funcName)) { + $this->mLog->addError(XCUbe_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName)); + return; + } + + if (function_exists($funcName)) { + // Because X2 can use reference parameter, Legacy doesn't use the following code;' + // if (!call_user_func($funcName, $this->_mXoopsModule)) { + + $result = $funcName($this->_mXoopsModule); + if (!$result) { + $this->mLog->addError(XCUbe_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName)); + } + } + } + } + + function _processReport() + { + if (!$this->mLog->hasError()) { + $this->mLog->add(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_INSTALLATION_MODULE_SUCCESSFUL, $this->_mXoopsModule->get('name'))); + } + else { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_INSTALLATION_MODULE_FAILURE, $this->_mXoopsModule->get('name'))); + } + } + + /** + * @todo Check whether $this->_mXoopsObject is ready. + */ + function executeInstall() + { + $this->_installTables(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_installModule(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_installTemplates(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_installBlocks(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_installPreferences(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_processScript(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_processReport(); + + return true; + } +} + +?> \ No newline at end of file Index: xoops2jp/html/modules/legacy/admin/class/ModuleUninstaller.class.php diff -u /dev/null xoops2jp/html/modules/legacy/admin/class/ModuleUninstaller.class.php:1.1.4.1 --- /dev/null Mon Apr 30 16:30:54 2007 +++ xoops2jp/html/modules/legacy/admin/class/ModuleUninstaller.class.php Mon Apr 30 16:30:54 2007 @@ -0,0 +1,220 @@ +<?php + +if (!defined('XOOPS_ROOT_PATH')) exit(); + +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallUtils.class.php"; + +class Legacy_ModuleUninstaller +{ + /** + * This instance is prepared automatically in the constructor. + * + * @public + * @var Legacy_ModuleInstallLog + */ + var $mLog = null; + + var $_mForceMode = false; + + /** + * @protected + * @var XoopsModule + * @remark [Precondition] _mXoopsModule has to be an object. + */ + var $_mXoopsModule = null; + + function Legacy_ModuleUninstaller() + { + $this->mLog =& new Legacy_ModuleInstallLog(); + } + + /** + * Sets the current XoopsModule. + * + * @public + * @param XoopsModule $xoopsModule + */ + function setCurrentXoopsModule(&$xoopsModule) + { + $this->_mXoopsModule =& $xoopsModule; + } + + /** + * Sets a value indicating whether the force mode is on. + * @param bool $isForceMode + */ + function setForceMode($isForceMode) + { + $this->_mForceMode = $isForceMode; + } + + /** + * Deletes module information from XOOPS database because this class is + * uninstaller. + * + * @protected + */ + function _uninstallModule() + { + $moduleHandler =& xoops_gethandler('module'); + if (!$moduleHandler->delete($this->_mXoopsModule)) { + $this->mLog->addError(_AD_LEGACY_ERROR_DELETE_MODULEINFO_FROM_DB); + } + else { + $this->mLog->addReport(_AD_LEGACY_MESSAGE_DELETE_MODULEINFO_FROM_DB); + } + } + + /** + * Drop table because this class is uninstaller. + * + * @protected + */ + function _uninstallTables() + { + $root =& XCube_Root::getSingleton(); + $db =& $root->mController->getDB(); + + $dirname = $this->_mXoopsModule->get('dirname'); + $t_search = array('{prefix}', '{dirname}', '{Dirname}', '{_dirname_}'); + $t_replace = array(XOOPS_DB_PREFIX, strtolower($dirname), ucfirst(strtolower($dirname)), $dirname); + + $tables = $this->_mXoopsModule->getInfo('tables'); + if ($tables != false && is_array($tables)) { + foreach($tables as $table) { + // + // TODO Do we need to check reserved core tables? + // + $t_tableName = $table; + if (isset($this->_mXoopsModule->modinfo['cube_style']) && $this->_mXoopsModule->modinfo['cube_style'] == true) { + $t_tableName = str_replace($t_search, $t_replace, $table); + } + else { + $t_tableName = $db->prefix($table); + } + + $sql = "DROP TABLE " . $t_tableName; + + if ($db->query($sql)) { + $this->mLog->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_DROP_TABLE, $t_tableName)); + } + else { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_DROP_TABLE, $t_tableName)); + } + } + } + } + + /** + * Delete template because this class is uninstaller. + * @protected + */ + function _uninstallTemplates() + { + Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates($this->_mXoopsModule, $this->mLog, false); + } + + /** + * Delete all of module's blocks. + * + * @note Templates Delete is move into Legacy_ModuleInstallUtils. + */ + function _uninstallBlocks() + { + Legacy_ModuleInstallUtils::uninstallAllOfBlocks($this->_mXoopsModule, $this->mLog); + + // + // Additional + // + $tplHandler =& xoops_gethandler('tplfile'); + $criteria =& new Criteria('tpl_module', $this->_mXoopsModule->get('dirname')); + if(!$tplHandler->deleteAll($criteria)) { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_DELETE_BLOCK_TEMPLATES, $tplHandler->db->error())); + } + } + + function _uninstallPreferences() + { + Legacy_ModuleInstallUtils::uninstallAllOfConfigs($this->_mXoopsModule, $this->mLog); + Legacy_ModuleInstallUtils::deleteAllOfNotifications($this->_mXoopsModule, $this->mLog); + Legacy_ModuleInstallUtils::deleteAllOfComments($this->_mXoopsModule, $this->mLog); + } + + function _processScript() + { + $installScript = trim($this->_mXoopsModule->getInfo('onUninstall')); + if ($installScript != false) { + require_once XOOPS_MODULE_PATH . "/" . $this->_mXoopsModule->get('dirname') . "/" . $installScript; + $funcName = 'xoops_module_uninstall_' . $this->_mXoopsModule->get('dirname'); + + if (!preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*$/", $funcName)) { + $this->mLog->addError(XCUbe_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName)); + return; + } + + if (function_exists($funcName)) { + if (!call_user_func($funcName, $this->_mXoopsModule)) { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName)); + } + } + } + } + + function _processReport() + { + if (!$this->mLog->hasError()) { + $this->mLog->add(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_MODULE_SUCCESSFUL, $this->_mXoopsModule->get('name'))); + } + else { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_UNINSTALLATION_MODULE_FAILURE, $this->_mXoopsModule->get('name'))); + } + } + + /** + * @todo Check whether $this->_mXoopsObject is ready. + */ + function executeUninstall() + { + $this->_uninstallTables(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + if ($this->_mXoopsModule->get('mid') != null) { + $this->_uninstallModule(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_uninstallTemplates(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_uninstallBlocks(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_uninstallPreferences(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_processScript(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + } + $this->_processReport(); + + return true; + } +} + +?> \ No newline at end of file Index: xoops2jp/html/modules/legacy/admin/class/ModuleUpdater.class.php diff -u /dev/null xoops2jp/html/modules/legacy/admin/class/ModuleUpdater.class.php:1.1.4.1 --- /dev/null Mon Apr 30 16:30:54 2007 +++ xoops2jp/html/modules/legacy/admin/class/ModuleUpdater.class.php Mon Apr 30 16:30:54 2007 @@ -0,0 +1,388 @@ +<?php +/** + * @package Legacy + * @version $Id: ModuleUpdater.class.php,v 1.1.4.1 2007/04/30 07:30:54 nobunobu Exp $ + */ + +if (!defined('XOOPS_ROOT_PATH')) exit(); + +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallUtils.class.php"; + +/** + * @brief The framework for the phased update. + * + * @section Description + * + * You can make your own custom-update-installer for your modules with the + * sub-class of this class. It's easy to make by many utility functions. You + * can write your sub-class as well as batch files. + * + * On Legacy System module, upgrade is called when users try to update. So you + * must implement your sub-class for also correct update. For example, the + * custom-update-install have to update module templates & block templates, + * because users expect that the module-update function does it. + * + * For the custom-update-install, Legacy_ModuleInstallUtils is good for you. + * Plus, this class has some usefull static methods for upgrade. Such functions + * have notes as "The utility method for the custom-update-installer". + * + * And, this class as the template-pattern has some methods you may override. + * These methods have note as "You may do custom". + * + * @section Convention + * + * Module Update function build the current-$xoopsModule from DB, and then sets + * it to this class through setCurrentXoopsModule(). Basically, you can access + * it by $this->_mCurrentXoopsModule. And, that function build the + * target-$xoopsModule from xoops_version, and then set it to this class through + * setTargetXoopsModule(). Also you can access it by $this->_mTargetXoopsModule. + * + * @see Legacy_ModuleInstallUtils + */ +class Legacy_ModulePhasedUpgrader +{ + /** + * This is an array of milestone version informations. Key is a version + * number. Value is a method name called by execute(). + * + * Format: + * {version} => {methodName} + * + * Example: + * var $_mMilestone = array('020' => 'update020', '025' => 'update025'); + * + * @access protected + */ + var $_mMilestone = array(); + + /** + * This instance is prepared automatically in the constructor. + * + * @public + * @var Legacy_ModuleInstallLog + */ + var $mLog = null; + + /** + * @var XoopsModule + * @remark [Precondition] _mXoopsModule has to be an object. + */ + var $_mCurrentXoopsModule; + + /** + * @var int + */ + var $_mCurrentVersion; + + /** + * @var XoopsModule + * @remark [Precondition] _mXoopsModule has to be an object. + */ + var $_mTargetXoopsModule; + + /** + * @var int + */ + var $_mTargetVersion; + + /** + * @var bool + */ + var $_mForceMode = false; + + function Legacy_ModulePhasedUpgrader() + { + $this->mLog =& new Legacy_ModuleInstallLog(); + } + + /** + * Sets a value indicating whether the force mode is on. + * @param bool $isForceMode + */ + function setForceMode($isForceMode) + { + $this->_mForceMode = $isForceMode; + } + + /** + * Sets the current XoopsModule. This method creates the clone of this + * object to prevent cache of the module handler, and then keep it to the + * property. Plus, this method copies the version value of this object to + * the _mCurrentVersion as backup for the case where the value of this + * object is changed for updating. + * + * @public + * @param XoopsModule $xoopsModule + */ + function setCurrentXoopsModule(&$xoopsModule) + { + $handler =& xoops_gethandler('module'); + $cloneModule =& $handler->create(); + + $cloneModule->unsetNew(); + $cloneModule->set('mid', $xoopsModule->get('mid')); + $cloneModule->set('name', $xoopsModule->get('name')); + $cloneModule->set('version', $xoopsModule->get('version')); + $cloneModule->set('last_update', $xoopsModule->get('last_update')); + $cloneModule->set('weight', $xoopsModule->get('weight')); + $cloneModule->set('isactive', $xoopsModule->get('isactive')); + $cloneModule->set('dirname', $xoopsModule->get('dirname')); + $cloneModule->set('hasmain', $xoopsModule->get('hasmain')); + $cloneModule->set('hasadmin', $xoopsModule->get('hasadmin')); + $cloneModule->set('hassearch', $xoopsModule->get('hassearch')); + $cloneModule->set('hasconfig', $xoopsModule->get('hasconfig')); + $cloneModule->set('hascomments', $xoopsModule->get('hascomments')); + $cloneModule->set('hasnotification', $xoopsModule->get('hasnotification')); + + $this->_mCurrentXoopsModule =& $cloneModule; + $this->_mCurrentVersion = $cloneModule->get('version'); + } + + /** + * Sets the target XoopsModule. + * + * @access public + * @param XoopsModule $xoopsModule + */ + function setTargetXoopsModule(&$xoopsModule) + { + $this->_mTargetXoopsModule =& $xoopsModule; + $this->_mTargetVersion = $this->getTargetPhase(); + } + + /** + * Execute upgrade. If the specific method for the milestone, this method + * calls the method. If such milestone doesn't exist, call the automatic + * upgrade method. + * + * @access public + */ + function executeUpgrade() + { + if ($this->hasUpgradeMethod()) { + return $this->_callUpgradeMethod(); + } + else { + return $this->executeAutomaticUpgrade(); + } + } + + /** + * Gets the current version. + * + * @return int + */ + function getCurrentVersion() + { + return $this->_mCurrentVersion; + } + + /** + * Gets the target varsion number at this time. In the case where there are + * milestones, gets the nearest value from the current version. + * + * Of course, this class is good to override by the sub-class. + */ + function getTargetPhase() + { + ksort($this->_mMilestone); + + foreach ($this->_mMilestone as $t_version => $t_value) { + if ($t_version > $this->getCurrentVersion()) { + return $t_version; + } + } + + return $this->_mTargetXoopsModule->get('version'); + } + + /** + * Gets the valude indicating whether this class + */ + function hasUpgradeMethod() + { + ksort($this->_mMilestone); + + foreach ($this->_mMilestone as $t_version => $t_value) { + if ($t_version > $this->getCurrentVersion()) { + if (is_callable(array($this, $t_value))) { + return true; + } + } + } + + return false; + } + + /** + * Dispatches the callback upgrade program. + * + * @access protected + * @return bool The value indicating whether this method can call the + * upgrade-method. + */ + function _callUpgradeMethod() + { + ksort($this->_mMilestone); + + foreach ($this->_mMilestone as $t_version => $t_value) { + if ($t_version > $this->getCurrentVersion()) { + if (is_callable(array($this, $t_value))) { + return $this->$t_value(); + } + } + } + + return false; + } + + /** + * Gets a valude indicating whether this process is upgrade for the latest + * version. + * + * @return bool + */ + function isLatestUpgrade() + { + return ($this->_mTargetXoopsModule->get('version') == $this->getTargetPhase()); + } + + /** + * Saves XoopsModule object to DB. + * + * @access protected + */ + function saveXoopsModule(&$module) + { + $handler =& xoops_gethandler('module'); + if ($handler->insert($module)) { + $this->mLog->addReport("XoopsModule is updated."); + } + else { + $this->mLog->addError("Could not update module information."); + } + } + + function _processScript() + { + $installScript = trim($this->_mTargetXoopsModule->getInfo('onUpdate')); + if ($installScript != false) { + require_once XOOPS_MODULE_PATH . "/" . $this->_mTargetXoopsModule->get('dirname') . "/" . $installScript; + $funcName = 'xoops_module_update_' . $this->_mTargetXoopsModule->get('dirname'); + if (function_exists($funcName)) { + if (!call_user_func($funcName, $this->_mTargetXoopsModule, $this->getCurrentVersion())) { + $this->mLog->addError("Failed to execute " . $funcName); + } + } + } + } + + function _processReport() + { + if (!$this->mLog->hasError()) { + $this->mLog->add(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UPDATING_MODULE_SUCCESSFUL, $this->_mCurrentXoopsModule->get('name'))); + } + else { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_UPDATING_MODULE_FAILURE, $this->_mCurrentXoopsModule->get('name'))); + } + } + + /** + * Updates all of module templates. + * + * @access protected + * @note You may do custom + */ + function _updateModuleTemplates() + { + Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates($this->_mTargetXoopsModule, $this->mLog); + Legacy_ModuleInstallUtils::installAllOfModuleTemplates($this->_mTargetXoopsModule, $this->mLog); + } + + /** + * Updates all of blocks. + * + * @access protected + * @note You may do custom + */ + function _updateBlocks() + { + Legacy_ModuleInstallUtils::smartUpdateAllOfBlocks($this->_mTargetXoopsModule, $this->mLog); + } + + /** + * Updates all of preferences & notifications. + * + * @access protected + * @note You may do custom + */ + function _updatePreferences() + { + Legacy_ModuleInstallUtils::smartUpdateAllOfPreferences($this->_mTargetXoopsModule, $this->mLog); + } + + /** + * This method executes upgrading automatically by the diff of + * xoops_version. + * + * 1) Uninstall all of module templates + * 2) Install all of module templates + * + * @return bool + */ + function executeAutomaticUpgrade() + { + $this->mLog->addReport(_AD_LEGACY_MESSAGE_UPDATE_STARTED); + + // + // Updates all of module templates + // + $this->_updateModuleTemplates(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + // + // Update blocks. + // + $this->_updateBlocks(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + // + // Update preferences & notifications. + // + $this->_updatePreferences(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + // + // Update module object. + // + $this->saveXoopsModule($this->_mTargetXoopsModule); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + // + // call bacl 'onUpdate' + // + $this->_processScript(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_processReport(); + + return true; + } +} + +?> \ No newline at end of file Index: xoops2jp/html/modules/legacy/admin/class/index.html diff -u /dev/null xoops2jp/html/modules/legacy/admin/class/index.html:1.1.4.1 --- /dev/null Mon Apr 30 16:30:54 2007 +++ xoops2jp/html/modules/legacy/admin/class/index.html Mon Apr 30 16:30:54 2007 @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file