NobuNobu
nobun****@users*****
2006年 3月 29日 (水) 22:52:01 JST
Index: xoops2jp/html/modules/base/admin/class/ModuleInstaller.class.php diff -u xoops2jp/html/modules/base/admin/class/ModuleInstaller.class.php:1.1.2.8 xoops2jp/html/modules/base/admin/class/ModuleInstaller.class.php:1.1.2.9 --- xoops2jp/html/modules/base/admin/class/ModuleInstaller.class.php:1.1.2.8 Tue Mar 28 22:28:56 2006 +++ xoops2jp/html/modules/base/admin/class/ModuleInstaller.class.php Wed Mar 29 22:52:01 2006 @@ -52,22 +52,38 @@ // // Add a permission which administrators can manage. // - $adminPerm =& $this->_createPermission(); + $adminPerm =& $this->_createPermission(XOOPS_GROUP_ADMIN); $adminPerm->setVar('gperm_name', 'module_admin'); if (!$gpermHandler->insert($adminPerm)) { $log->addError("Could not set admin permission " . $this->mModule->getVar('mid')); } - - // - // Add a permission which administrators can read. - // - $readPerm =& $this->_createPermission(); - $readPerm->setVar('gperm_name', 'module_read'); - - if (!$gpermHandler->insert($readPerm)) { - $log->addError("Could not set read permission " . $this->mModule->getVar('mid')); - } + $read_any = $this->mModule->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)) { + $log->addError("Could not set read permission " . $this->mModule->getVar('mid')); + } + } + } else { + // + // Add a permission which administrators can read. + // + $readPerm =& $this->_createPermission(XOOPS_GROUP_ADMIN); + $readPerm->setVar('gperm_name', 'module_read'); + + if (!$gpermHandler->insert($readPerm)) { + $log->addError("Could not set read permission " . $this->mModule->getVar('mid')); + } + } } } @@ -75,14 +91,15 @@ * Create a permission object which has been initialized for admin. * For flexibility, creation only and not save it. * @access private + * @param $group */ - function &_createPermission() + function &_createPermission($group) { $gpermHandler =& xoops_gethandler('groupperm'); $perm =& $gpermHandler->create(); - $perm->setVar('gperm_groupid', XOOPS_GROUP_ADMIN); + $perm->setVar('gperm_groupid', $group); $perm->setVar('gperm_itemid', $this->mModule->getVar('mid')); $perm->setVar('gperm_modid', 1); @@ -118,7 +135,7 @@ $newBlock =& Legacy_ModuleUtils::createBlockByInfo($this->mModule, $block); $newBlock->setVar('func_num', $func_num); - Legacy_ModuleUtils::installBlock($this->mModule, $newBlock, $this->mLog); + Legacy_ModuleUtils::installBlock($this->mModule, $newBlock, $block, $this->mLog); } } Index: xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php diff -u xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php:1.1.2.4 xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php:1.1.2.5 --- xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php:1.1.2.4 Tue Mar 28 22:28:56 2006 +++ xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php Wed Mar 29 22:52:01 2006 @@ -114,30 +114,23 @@ // if (count($installedBlocks) == 0) { $newBlock->setVar('func_num', $func_num); - $installedBlocks[] =& $newBlock; + $installBlocks[] = array($newBlock, $block); unset($newBlock); continue; } - $oldBlock =& $installedBlocks[0]; - - // - // Check update - // $changedFlag = false; - $changedFlag |= ($newBlock->getVar('name') != $oldBlock->getVar('name')); - $changedFlag |= ($newBlock->getVar('func_file') != $oldBlock->getVar('func_file')); - $changedFlag |= ($newBlock->getVar('show_func') != $oldBlock->getVar('show_func')); - $changedFlag |= ($newBlock->getVar('edit_func') != $oldBlock->getVar('edit_func')); - $changedFlag |= ($newBlock->getVar('template') != $oldBlock->getVar('template')); + + $oldBlock =& $installedBlocks[0]; + $newBlock =& Legacy_ModuleUtils::mergeBlockObject($oldBlock, $newBlock, $changedFlag); if ($changedFlag) { - $installedBlocks[] =& $newBlock; + $installBlocks[] = array($newBlock, $block); } else { - if (!Legacy_ModuleUtils::installBlockTemplate($this->mModule, $block)) { - $this->mLog->addError("ERROR : Could not update block template ".$block->getVar('name')); + if (!Legacy_ModuleUtils::installBlockTemplate($this->mModule, $oldBlock)) { + $this->mLog->addError("ERROR : Could not update block template ".$oldBlock->getVar('name')); } } @@ -148,21 +141,21 @@ $criteria = new CriteriaCompo(); $criteria->add(new Criteria('mid', $this->mModule->getVar('mid'))); $installedBlocks =& $blockHandler->getObjectsDirectly($criteria); - foreach ($installedBlocks as $block) { - $name = $block->getVar('name'); + foreach ($installedBlocks as $blockObj) { + $name = $blockObj->getVar('name'); $findFlag = false; foreach ($definedBlocks as $definedBlock) { - $findFlag |= ($definedBlock['name'] == $block->getVar('name')); + $findFlag |= ($definedBlock['name'] == $blockObj->getVar('name')); } if (!$findFlag) { - $unInstallBlocks[] =& $block; - unset($block); + $unInstallBlocks[] =& $blockObj; + unset($blockObj); } } foreach ($installBlocks as $block) { - Legacy_ModuleUtils::installBlock($this->mModule, $block, $this->mLog); + Legacy_ModuleUtils::installBlock($this->mModule, $block[0], $block[1], $this->mLog); } /* Index: xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php diff -u xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.11 xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.12 --- xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.11 Tue Mar 28 22:28:56 2006 +++ xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php Wed Mar 29 22:52:01 2006 @@ -183,7 +183,8 @@ { $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(); @@ -193,55 +194,117 @@ $blockObj->setVar('title', $block['name']); $blockObj->setVar('block_type', 'M'); $blockObj->setVar('c_type', 1); + $blockObj->setVar('isactive', 1); $blockObj->setVar('dirname', $module->getVar('dirname')); $blockObj->setVar('func_file', $block['file']); $blockObj->setVar('show_func', $block['show_func']); $blockObj->setVar('edit_func', $edit_func); - $blockObj->setVar('template', $block['template']); + $blockObj->setVar('template', $template); $blockObj->setVar('last_modified', time()); - + $blockObj->setVar('visible', $visible); + return $blockObj; } + /** + * Merge existing block XoopsBlock object and new XoopsBlock object from xoops_verion + * @param $oldBlock XoopsBlock + * @param $newBlock XoopsBlock + * @param $changedFlag bool + * @return XoopsBlock + */ + function &mergeBlockObject(&$oldBlock, &$newBlock, &$changedFlag) + { + $blockObj =& $oldBlock->xoopsClone(); + $blockObj->unsetNew(); + + $changedFlag = false; + $checkValues = array('name', 'func_file', 'show_func', 'edit_func', 'template'); + foreach($checkValues as $checkValue) { + if ($newBlock->getVar($checkValue) != $oldBlock->getVar($checkValue)) { + $blockObj->setVar($checkValue, $newBlock->getVar($checkValue)); + $changedFlag |= true; + } + } + + $old_options=explode("|",$oldBlock->getVar('options')); + $new_options=explode("|",$newBlock->getVar('options')); + if (count($new_options) > count($old_options)) { + $changedFlag |= true; + for ($i=count($old_options); $i<count($new_options); $i++) { + $old_options[$i] = $old_options[$i]; + } + $blockObj->setVar('options', implode("|", $old_options)); + } else if (count($new_options) < count($old_options)) { + $changedFlag |= true; + $blockObj->setVar('options', $newBlock->getVar('options')); + } + + return $blockObj; + } + /** * This function can receive both new and update. * @param $module XoopsModule - * @param $block XoopsBlock + * @param $blockObj XoopsBlock + * @param $block array * @return bool */ - function installBlock(&$module, &$block, &$log) + function installBlock(&$module, &$blockObj, &$block, &$log) { - $isNew = $block->isNew(); - + $isNew = $blockObj->isNew(); $blockHandler =& xoops_gethandler('block'); - $blockObj =& $blockHandler->create(); - if (!$blockHandler->insert($block, true)) { + if (!empty($block['show_all_module'])) { + $autolink = false; + } else { + $autolink = true; + } + if (!$blockHandler->insert($blockObj, $autolink)) { $log->addError("ERROR : Could not install block whose name is " . $blockObj->getVar('name')); return false; } else { - $log->addReport("block " . $block->getVar('name') . " has been installed"); + $log->addReport("block " . $blockObj->getVar('name') . " has been installed"); $tplHandler =& xoops_gethandler('tplfile'); - if (!Legacy_ModuleUtils::installBlockTemplate($module, $block)) { - $log->addError("Could not install block template " . $block->getVar('name')); + if (!Legacy_ModuleUtils::installBlockTemplate($module, $blockObj)) { + $log->addError("Could not install block template " . $blockObj->getVar('name')); } // // Process of a permission. // if ($isNew) { - $gpermHandler =& xoops_gethandler('groupperm'); - $bperm =& $gpermHandler->create(); - $bperm->setVar('gperm_groupid', XOOPS_GROUP_ADMIN); - $bperm->setVar('gperm_itemid', $block->getVar('bid')); + 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->addWarn("Could not set link with all module " . $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 (!$gpermHandler->insert($bperm)) { - $log->addWarn("Could not set block permission " . $tplfile->getVar('bid')); + + 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->addWarn("Could not set block permission " . $blockObj->getVar('name')); + } + } + } else { + $bperm->setVar('gperm_groupid', XOOPS_GROUP_ADMIN); + if (!$gpermHandler->insert($bperm)) { + $log->addWarn("Could not set block permission " . $blockObj->getVar('name')); + } } }