Exemplo n.º 1
0
 /**
  * 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, $block->get('name')));
         return false;
     }
 }