コード例 #1
0
ファイル: Configuration.php プロジェクト: ming-hai/XoopsCore
 /**
  * readSanitizerPreferences - read configured sanitizer preferences
  *
  * If configuration file does not exist, create it.
  *
  * If configurable extensions exist that are not in the configuration
  * file, add them, and rewrite the configuration file.
  *
  * @return array of sanitizer preferences
  */
 protected function readSanitizerPreferences()
 {
     $xoops = \Xoops::getInstance();
     $sanitizerPrefs = array();
     try {
         $file = $xoops->path($this->sanitizerPrefsFilename);
         $sanitizerPrefs = Yaml::read($file);
     } catch (\Exception $e) {
         $xoops->events()->triggerEvent('core.exception', $e);
     }
     if (!is_array($sanitizerPrefs)) {
         $sanitizerPrefs = array();
     }
     $changed = false;
     $defaultPrefs = new DefaultConfiguration();
     foreach ($defaultPrefs as $name => $value) {
         if (!array_key_exists($name, $sanitizerPrefs)) {
             $sanitizerPrefs[$name] = $defaultPrefs[$name];
             $changed = true;
         }
     }
     if ($changed) {
         $this->saveSanitizerPrefrences($sanitizerPrefs);
     }
     return $sanitizerPrefs;
 }
コード例 #2
0
ファイル: TableLoad.php プロジェクト: ming-hai/XoopsCore
 /**
  * loadTableFromYamlFile
  *
  * @param string $table    name of table to load without prefix
  * @param string $yamlFile name of file containing data dump in YAML format
  *
  * @return int number of rows inserted
  */
 public static function loadTableFromYamlFile($table, $yamlFile)
 {
     $count = 0;
     $data = Yaml::read($yamlFile);
     if ($data) {
         $count = self::loadTableFromArray($table, $data);
     }
     return $count;
 }
コード例 #3
0
ファイル: YamlTest.php プロジェクト: ming-hai/XoopsCore
 /**
  * @covers Xoops\Core\Yaml::save
  * @covers Xoops\Core\Yaml::read
  */
 public function testSaveAndRead()
 {
     $tmpfname = tempnam(sys_get_temp_dir(), 'TEST');
     $inputArray = array('one' => 1, 'two' => array(1, 2), 'three' => '');
     $byteCount = Yaml::save($inputArray, $tmpfname);
     $this->assertFalse($byteCount === false);
     $this->assertGreaterThan(0, $byteCount);
     $outputArray = Yaml::read($tmpfname);
     $this->assertTrue(is_array($outputArray));
     $this->assertSame($inputArray, $outputArray);
     unlink($tmpfname);
 }
コード例 #4
0
ファイル: Assets.php プロジェクト: RanLee/XoopsCore
 /**
  * readAssetsPrefs - read configured asset preferences
  *
  * @return array of assets preferences
  */
 protected function readAssetsPrefs()
 {
     $xoops = \Xoops::getInstance();
     $assetsPrefs = array();
     try {
         $assetsPrefs = $xoops->cache()->read($this->assetsPrefsCacheKey);
         $file = $xoops->path($this->assetsPrefsFilename);
         $mtime = filemtime($file);
         if ($assetsPrefs === false || !isset($assetsPrefs['mtime']) || !$mtime || isset($assetsPrefs['mtime']) && $assetsPrefs['mtime'] < $mtime) {
             if ($mtime) {
                 $assetsPrefs = Yaml::read($file);
                 if (!is_array($assetsPrefs)) {
                     $xoops->logger()->error("Invalid config in system_assets_prefs.yml");
                     $assetsPrefs = array();
                 } else {
                     $assetsPrefs['mtime'] = $mtime;
                     $xoops->cache()->write($this->assetsPrefsCacheKey, $assetsPrefs);
                 }
             } else {
                 // use defaults to create file
                 $assetsPrefs = array('default_filters' => $this->default_filters, 'default_asset_refs' => $this->default_asset_refs, 'mtime' => time());
                 $this->saveAssetsPrefs($assetsPrefs);
             }
         }
         if (!empty($assetsPrefs['default_filters']) && is_array($assetsPrefs['default_filters'])) {
             $this->default_filters = $assetsPrefs['default_filters'];
         }
         if (!empty($assetsPrefs['default_asset_refs']) && is_array($assetsPrefs['default_asset_refs'])) {
             $this->default_asset_refs = $assetsPrefs['default_asset_refs'];
         }
     } catch (\Exception $e) {
         $xoops->events()->triggerEvent('core.exception', $e);
         $assetsPrefs = array();
     }
     return $assetsPrefs;
 }
コード例 #5
0
ファイル: module.php プロジェクト: redmexico/XoopsCore
 /**
  * update
  *
  * @param string $mod module dirname
  *
  * @return mixed boolean false if failed, XoopsModule if success
  */
 public function update($mod = '')
 {
     $xoops = Xoops::getInstance();
     $module_handler = $xoops->getHandlerModule();
     $module = $module_handler->getByDirname($mod);
     $xoops->templateClearModuleCache($module->getVar('mid'));
     // Save current version for use in the update function
     $prev_version = $module->getVar('version');
     // we dont want to change the module name set by admin
     $temp_name = $module->getVar('name');
     $module->loadInfoAsVar($module->getVar('dirname'));
     $module->setVar('name', $temp_name);
     $module->setVar('last_update', time());
     if (!$module_handler->insertModule($module)) {
         $this->error[] = sprintf(XoopsLocale::EF_NOT_UPDATED, "<strong>" . $module->getVar('name') . "</strong>");
         return false;
     } else {
         // execute module specific preupdate script if any
         $update_script = $module->getInfo('onUpdate');
         if (false != $update_script && trim($update_script) != '') {
             XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($update_script)));
             $func = 'xoops_module_preupdate_' . $mod;
             if (function_exists($func)) {
                 $result = $func($module, $prev_version);
                 if (!$result) {
                     $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
                     $this->trace = array_merge($this->error, $module->getErrors());
                 } else {
                     $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
                     $this->trace = array_merge($this->trace, $module->getMessages());
                 }
             }
         }
         // update schema
         $schema_file = $module->getInfo('schema');
         if (!empty($schema_file)) {
             $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file;
             if (!XoopsLoad::fileExists($schema_file_path)) {
                 $this->error[] = sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>");
                 return false;
             }
             $importer = new ImportSchema();
             $importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path));
             $synchronizer = new SingleDatabaseSynchronizer($xoops->db());
             $synchronizer->updateSchema($importSchema, true);
         }
         // delete templates
         $this->deleteTemplates($module);
         // install templates
         $this->installTemplates($module);
         // install blocks
         $this->installBlocks($module);
         // reset compile_id
         $xoops->tpl()->setCompileId();
         // first delete all config entries
         $this->deleteConfigs($module);
         // Install Configs
         $this->installConfigs($module, 'update');
         // execute module specific update script if any
         $update_script = $module->getInfo('onUpdate');
         if (false != $update_script && trim($update_script) != '') {
             XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($update_script)));
             $func = 'xoops_module_update_' . $mod;
             if (function_exists($func)) {
                 $result = $func($module, $prev_version);
                 if (!$result) {
                     $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
                     $this->trace = array_merge($this->error, $module->getErrors());
                 } else {
                     $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
                     $this->trace = array_merge($this->trace, $module->getMessages());
                 }
             }
         }
         $this->trace[] = sprintf(XoopsLocale::SF_UPDATED, '<strong>' . $module->getVar('name', 's') . '</strong>');
         return $module;
     }
 }
コード例 #6
0
ファイル: Manager.php プロジェクト: ming-hai/XoopsCore
 /**
  * readYamlProviderPrefs - read configured provider preferences from file
  *
  * @return array of configured provider preferences
  */
 public function readYamlProviderPrefs()
 {
     $xoops = \Xoops::getInstance();
     $providerPrefs = array();
     try {
         $file = $xoops->path($this->providerPrefsFilename);
         if (file_exists($file)) {
             $providerPrefs = Yaml::read($xoops->path($file));
         }
         if (empty($providerPrefs)) {
             $providerPrefs = array();
         }
     } catch (\Exception $e) {
         $xoops->events()->triggerEvent('core.exception', $e);
         $providerPrefs = array();
     }
     return $providerPrefs;
 }