Minahito
minah****@users*****
2005年 12月 21日 (水) 13:09:37 JST
Index: xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php diff -u xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.2 xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.3 --- xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.2 Mon Dec 19 23:01:16 2005 +++ xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php Wed Dec 21 13:09:36 2005 @@ -2,14 +2,17 @@ require_once XOOPS_ROOT_PATH."/class/template.php"; +/** + * A temporary log class. + */ class Legacy_ModuleUtilsSimpleLog { - var $mFetalErrorFlag=false; - var $mMessages=array(); + var $mFetalErrorFlag = false; + var $mMessages = array(); function add($msg) { - $this->mMessages[]=array('type'=>'report','message'=>$msg); + $this->mMessages[] = array('type' => 'report', 'message' => $msg); } function addReport($msg) @@ -19,13 +22,13 @@ function addWarning($msg) { - $this->mMessages[]=array('type'=>'warning','message'=>$msg); + $this->mMessages[] = array('type' => 'warning', 'message' => $msg); } function addError($msg) { - $this->mMessages[]=array('type'=>'error','message'=>$msg); - $this->mFetalErrorFlag=true; + $this->mMessages[] = array('type' => 'error', 'message' => $msg); + $this->mFetalErrorFlag = true; } function hasError() @@ -34,6 +37,10 @@ } } +/** + * This provides static methods for the module installation. Methods of this class + * may move to base class of installers. + */ class Legacy_ModuleUtils { /** @@ -58,11 +65,11 @@ // // TODO The following variable exists for rollback, but it is not implemented. // - $createdTables=array(); + $createdTables = array(); foreach ($pieces as $piece) { $prefixedQuery =SqlUtility::prefixQuery($piece, $db->prefix()); - if($prefixedQuery==false) { + if ($prefixedQuery == false) { $log->addError("${piece} is not a valid SQL"); return; } @@ -77,9 +84,11 @@ $createdTables[] = $prefixedQuery[4]; } else { - $log->addReport("Data inserted to table ".$db->prefix($prefixedQuery[4])); + $log->addReport("Data inserted to table " . $db->prefix($prefixedQuery[4])); } } + + $log->addReport("*Database table setup finished.*"); } /** @@ -92,45 +101,45 @@ * @param $log Legacy_ModuleUtilsSimpleLog * * @param bool */ - function installTemplate($module,$template,&$log) + function installTemplate($module, $template, &$log) { - $tplHandler=&xoops_gethandler('tplfile'); + $tplHandler =& xoops_gethandler('tplfile'); - $fileName=trim($template['file']); + $fileName = trim($template['file']); - $tpldata=Legacy_ModuleUtils::readTemplateFile($module->getVar('dirname'),$fileName); - if($tpldata==false) + $tpldata = Legacy_ModuleUtils::readTemplateFile($module->getVar('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_lastimpoerted',0); - $tplfile->setVar('tpl_lastmodified',time()); + $tplfile =& $tplHandler->create(); + $tplfile->setVar('tpl_refid', $module->getVar('mid')); + $tplfile->setVar('tpl_lastimpoerted', 0); + $tplfile->setVar('tpl_lastmodified', time()); - if(preg_match("/\.css$/i",$fileName)) { - $tplfile->setVar('tpl_type','css'); + if (preg_match("/\.css$/i", $fileName)) { + $tplfile->setVar('tpl_type', 'css'); } else { - $tplfile->setVar('tpl_type','module'); + $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); + $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($tpl['description']) ? $tpl['description'] : ''; - $tplfile->setVar('tpl_desc',$description,true); + $description = isset($tpl['description']) ? $tpl['description'] : ''; + $tplfile->setVar('tpl_desc', $description, true); - if(!$tplHandler->insert($tplfile)) { - $log->addError(@sprintf(_MD_A_BASE_ERROR_INSERT_TEMPLATE,$fileName)); - return false; + if ($tplHandler->insert($tplfile)) { + $log->addReport(@sprintf("Template '${fileName}' has been installed.")); } else { - $log->addReport(@sprintf("Template '${fileName}' has been installed.")); + $log->addError(@sprintf(_MD_A_BASE_ERROR_INSERT_TEMPLATE, $fileName)); + return false; } return true; @@ -141,31 +150,31 @@ * * @return string or false */ - function readTemplateFile($dirname,$fileName,$isblock=false) + function readTemplateFile($dirname, $fileName, $isblock = false) { // // Load template data // - if($isblock) { - $filePath=XOOPS_MODULE_PATH."/".$dirname."/templates/blocks/".$fileName; + if ($isblock) { + $filePath = XOOPS_MODULE_PATH . "/" . $dirname . "/templates/blocks/" . $fileName; } else { - $filePath=XOOPS_MODULE_PATH."/".$dirname."/templates/".$fileName; + $filePath = XOOPS_MODULE_PATH . "/" . $dirname . "/templates/" . $fileName; } - if(!file_exists($filePath)) + if (!file_exists($filePath)) return false; - $lines=file($filePath); - if($lines==false) + $lines = file($filePath); + if ($lines == false) return false; - $tpldata=""; - foreach($lines as $line) { + $tpldata = ""; + foreach ($lines as $line) { // // Unify linefeed to "\r\n" // - $tpldata.=str_replace("\n","\r\n",str_replace("\r\n","\n",$line)); + $tpldata .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $line)); } return $tpldata; @@ -179,24 +188,24 @@ */ function &createBlockByInfo(&$module, $block) { - $options=isset($block['options']) ? $block['options'] : null; - $edit_func=isset($block['edit_func']) ? $block['edit_func'] : null; + $options = isset($block['options']) ? $block['options'] : null; + $edit_func = isset($block['edit_func']) ? $block['edit_func'] : null; - $blockHandler=&xoops_gethandler('block'); - $blockObj=&$blockHandler->create(); + $blockHandler =& xoops_gethandler('block'); + $blockObj =& $blockHandler->create(); - $blockObj->setVar('mid',$module->getVar('mid')); - $blockObj->setVar('options',$options); - $blockObj->setVar('name',$block['name']); - $blockObj->setVar('title',$block['name']); - $blockObj->setVar('block_type','M'); - $blockObj->setVar('c_type',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('last_modified',time()); + $blockObj->setVar('mid', $module->getVar('mid')); + $blockObj->setVar('options', $options); + $blockObj->setVar('name', $block['name']); + $blockObj->setVar('title', $block['name']); + $blockObj->setVar('block_type', 'M'); + $blockObj->setVar('c_type', 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('last_modified', time()); return $blockObj; } @@ -245,13 +254,6 @@ return true; } - - } - - function unInstallBlock(&$module, &$block) - { - // $blockHandler=&xoops_gethandler('block'); - // $blockHandler->delete($block); } /** @@ -261,7 +263,7 @@ */ function installBlockTemplate(&$module, &$block) { - $tplHandler=&xoops_gethandler('tplfile'); + $tplHandler =& xoops_gethandler('tplfile'); $criteria =& new CriteriaCompo(); $criteria->add(new Criteria('tpl_type', 'block')); @@ -270,23 +272,23 @@ $criteria->add(new Criteria('tpl_file', $block->getVar('template'))); $tplfiles =& $tplHandler->getObjects($criteria); - if (count($tplfiles) == 0) { - $tplfile =& $tplHandler->create(); - $tplfile->setVar('tpl_refid',$block->getVar('bid')); - $tplfile->setVar('tpl_tplset','default'); - $tplfile->setVar('tpl_file',$block->getVar('template')); - $tplfile->setVar('tpl_module',$module->getVar('dirname')); - $tplfile->setVar('tpl_type','block'); - // $tplfile->setVar('tpl_desc',$tpl_desc); - $tplfile->setVar('tpl_lastimported',0); + if (count($tplfiles) > 0) { + $tplfile =& $tplfiles[0]; } else { - $tplfile =& $tplfiles[0]; + $tplfile =& $tplHandler->create(); + $tplfile->setVar('tpl_refid', $block->getVar('bid')); + $tplfile->setVar('tpl_tplset', 'default'); + $tplfile->setVar('tpl_file', $block->getVar('template')); + $tplfile->setVar('tpl_module', $module->getVar('dirname')); + $tplfile->setVar('tpl_type', 'block'); + // $tplfile->setVar('tpl_desc', $tpl_desc); + $tplfile->setVar('tpl_lastimported', 0); } $tplSource = Legacy_ModuleUtils::readTemplateFile($module->getVar('dirname'), $block->getVar('template'), true); $tplfile->setVar('tpl_source', $tplSource); - $tplfile->setVar('tpl_lastmodified',time()); + $tplfile->setVar('tpl_lastmodified', time()); return $tplHandler->insert($tplfile); }