コード例 #1
0
 /**
  * __construct
  * @param string|string[] $config fully qualified name of configuration file
  *                                or configuration array
  * @throws Exception
  */
 private final function __construct($config)
 {
     if (!class_exists('XoopsLoad', false)) {
         include __DIR__ . '/xoopsload.php';
     }
     if (is_string($config)) {
         $yamlString = file_get_contents($config);
         if ($yamlString === false) {
             throw new \Exception('XoopsBaseConfig failed to load configuration.');
         }
         $loaderPath = $this->extractLibPath($yamlString) . '/vendor/autoload.php';
         if (file_exists($loaderPath)) {
             include_once $loaderPath;
         }
         self::$configs = Yaml::loadWrapped($yamlString);
         \XoopsLoad::startAutoloader(self::$configs['lib-path']);
     } elseif (is_array($config)) {
         self::$configs = $config;
         \XoopsLoad::startAutoloader(self::$configs['lib-path']);
     }
     if (!isset(self::$configs['lib-path'])) {
         throw new \Exception('XoopsBaseConfig lib-path not defined.');
         return;
     }
     \XoopsLoad::startAutoloader(self::$configs['lib-path']);
 }
コード例 #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::saveWrapped
  * @covers Xoops\Core\Yaml::readWrapped
  */
 public function testSaveAndReadWrapped()
 {
     $tmpfname = tempnam(sys_get_temp_dir(), 'TEST');
     $inputArray = array('one' => 1, 'two' => array(1, 2), 'three' => '');
     $byteCount = Yaml::saveWrapped($inputArray, $tmpfname);
     $this->assertFalse($byteCount === false);
     $this->assertGreaterThan(0, $byteCount);
     $outputArray = Yaml::readWrapped($tmpfname);
     $this->assertTrue(is_array($outputArray));
     $this->assertSame($inputArray, $outputArray);
     unlink($tmpfname);
 }
コード例 #4
0
ファイル: install.php プロジェクト: RanLee/XoopsCore
/**
 * @copyright       XOOPS Project (http://xoops.org)
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
 * @author          Richard Griffith <*****@*****.**>
 */
function xoops_module_install_userrank($module)
{
    $xoops = Xoops::getInstance();
    $xoops->header();
    $lang_rank_titles = array('dummy', _MI_RANK_TITLE_1, _MI_RANK_TITLE_2, _MI_RANK_TITLE_3, _MI_RANK_TITLE_4, _MI_RANK_TITLE_5, _MI_RANK_TITLE_6, _MI_RANK_TITLE_7);
    $filedata = <<<EOT
-
  rank_id: 1
  rank_title: "{$lang_rank_titles[1]}"
  rank_min: 0
  rank_max: 20
  rank_special: 0
  rank_image: "ranks/rank3e632f95e81ca.gif"
-
  rank_id: 2
  rank_title: "{$lang_rank_titles[2]}"
  rank_min: 21
  rank_max: 40
  rank_special: 0
  rank_image: "ranks/rank3dbf8e94a6f72.gif"
-
  rank_id: 3
  rank_title: "{$lang_rank_titles[3]}"
  rank_min: 41
  rank_max: 70
  rank_special: 0
  rank_image: "ranks/rank3dbf8e9e7d88d.gif"
-
  rank_id: 4
  rank_title: "{$lang_rank_titles[4]}"
  rank_min: 71
  rank_max: 150
  rank_special: 0
  rank_image: "ranks/rank3dbf8ea81e642.gif"
-
  rank_id: 5
  rank_title: "{$lang_rank_titles[5]}"
  rank_min: 151
  rank_max: 10000
  rank_special: 0
  rank_image: "ranks/rank3dbf8eb1a72e7.gif"
-
  rank_id: 6
  rank_title: "{$lang_rank_titles[6]}"
  rank_min: 0
  rank_max: 0
  rank_special: 1
  rank_image: "ranks/rank3dbf8edf15093.gif"
-
  rank_id: 7
  rank_title: "{$lang_rank_titles[7]}"
  rank_min: 0
  rank_max: 0
  rank_special: 1
  rank_image: "ranks/rank3dbf8ee8681cd.gif"
EOT;
    $tablerows = Yaml::load($filedata);
    $dbm = $xoops->db();
    $count = $dbm->fetchColumn('SELECT COUNT(*) FROM ' . $dbm->prefix("ranks"));
    if ($count < 1) {
        $dbm->beginTransaction();
        foreach ($tablerows as $row) {
            $dbm->insertPrefix('ranks', $row);
        }
        $dbm->commit();
    }
    return true;
}
コード例 #5
0
ファイル: Assets.php プロジェクト: RanLee/XoopsCore
 /**
  * saveAssetsPrefs - record array of assets preferences in config file, and
  * update cache
  *
  * @param array $assets_prefs array of asset preferences to save
  *
  * @return void
  */
 protected function saveAssetsPrefs($assets_prefs)
 {
     if (is_array($assets_prefs)) {
         $xoops = \Xoops::getInstance();
         try {
             Yaml::save($assets_prefs, $xoops->path($this->assetsPrefsFilename));
             $xoops->cache()->write($this->assetsPrefsCacheKey, $assets_prefs);
         } catch (\Exception $e) {
             $xoops->events()->triggerEvent('core.exception', $e);
         }
     }
 }
コード例 #6
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;
     }
 }
コード例 #7
0
ファイル: schematool.php プロジェクト: ming-hai/XoopsCore
        // of our schema, so we can serialize it.
        $export = new ExportVisitor();
        $newSchema->visit($export);
        $schemaArray = $export->getSchemaArray();
        // enforce utf8mb4 for MySQL
        foreach ($schemaArray['tables'] as $tableName => $table) {
            $schemaArray['tables'][$tableName]['options']['charset'] = 'utf8mb4';
            $schemaArray['tables'][$tableName]['options']['collate'] = 'utf8mb4_unicode_ci';
            foreach ($table['columns'] as $column => $data) {
                if (array_key_exists('collation', $data)) {
                    $schemaArray['tables'][$tableName]['columns'][$column]['collation'] = 'utf8mb4_unicode_ci';
                }
            }
        }
        echo '<h2>' . _MI_SCHEMATOOL_EXPORT_SCHEMA . '</h2>';
        $yamldump = Yaml::dump($schemaArray, 5);
        //echo '<div contenteditable><pre>' . $yamldump . '</pre></div>';
        $schemadump = <<<EOT1
<section>
  <div id="container">
    <div contenteditable><pre>{$yamldump}</pre></div>
    <input type="text" value="schema.yml" placeholder="schema.yml">
    <button onclick="downloadFile()">Create file</button> <output></output>
  </div>
</section>
EOT1;
        $script = <<<EOT2
<script>
var container = document.querySelector('#container');
var typer = container.querySelector('[contenteditable]');
var output = container.querySelector('output');
コード例 #8
0
ファイル: Configuration.php プロジェクト: ming-hai/XoopsCore
 /**
  * saveSanitizerPreferences - record array of sanitizer preferences in config file
  *
  * @param array $sanitizerPrefs array of sanitizer preferences to save
  *
  * @return void
  */
 protected function saveSanitizerPrefrences($sanitizerPrefs)
 {
     if (is_array($sanitizerPrefs)) {
         $xoops = \Xoops::getInstance();
         try {
             Yaml::save($sanitizerPrefs, $xoops->path($this->sanitizerPrefsFilename));
         } catch (\Exception $e) {
             $xoops->events()->triggerEvent('core.exception', $e);
         }
     }
 }
コード例 #9
0
ファイル: schematool.php プロジェクト: redmexico/XoopsCore
        $schemaManager = $xoops->db()->getSchemaManager();
        // create schema from the current database
        $schema = $schemaManager->createSchema();
        // invoke our RemovePrefixes visitor with list of core tables
        $visitor = new RemovePrefixes();
        $visitor->setTableFilter($table_list);
        $schema->visit($visitor);
        // Get the schema we built with the RemovePrefixes visitor.
        // Should be just core tables with no prefix
        $newSchema = $visitor->getNewSchema();
        // Invoke an ExportVisitor that will build a clean array version
        // of our schema, so we can serialize it.
        $export = new ExportVisitor();
        $newSchema->visit($export);
        echo '<h2>' . _MI_SCHEMATOOL_EXPORT_SCHEMA . '</h2>';
        $yamldump = Yaml::dump($export->getSchemaArray(), 5);
        //echo '<div contenteditable><pre>' . $yamldump . '</pre></div>';
        $schemadump = <<<EOT1
<section>
  <div id="container">
    <div contenteditable><pre>{$yamldump}</pre></div>
    <input type="text" value="schema.yml" placeholder="schema.yml">
    <button onclick="downloadFile()">Create file</button> <output></output>
  </div>
</section>
EOT1;
        $script = <<<EOT2
<script>
var container = document.querySelector('#container');
var typer = container.querySelector('[contenteditable]');
var output = container.querySelector('output');
コード例 #10
0
ファイル: CacheManager.php プロジェクト: ming-hai/XoopsCore
 /**
  * Create a default configuration file, used in installation
  *
  * When using Windows NTFS, PHP has a maximum path length of 260 bytes. Each key level in a
  * Stash hierarchical key corresponds to a directory, and is normalized as an md5 hash. Also,
  * Stash uses 2 levels for its own integrity ad locking mechanisms. The full key length used
  * in XoopCore can reach 202 charachters.
  *
  * If the combined path length would excede 260, we will try and switch to SQLite driver if
  * it is available when running on a Windows system.
  *
  * @return void
  */
 public static function createDefaultConfig()
 {
     $configFile = \XoopsBaseConfig::get('var-path') . '/configs/cache.php';
     if (file_exists($configFile)) {
         return;
     }
     $defaults = self::getDefaults();
     if (false !== stripos(PHP_OS, 'WIN')) {
         $pathLen = strlen($defaults['default']['options']['path']);
         if (260 <= $pathLen + 202) {
             // try alternative driver as filesystem has max path length issues on Windows
             if (array_key_exists("SQLite", \Stash\DriverList::getAvailableDrivers())) {
                 $defaults['default']['driver'] = 'SQLite';
                 unset($defaults['default']['options']['dirSplit']);
                 @mkdir($defaults['default']['options']['path']);
             } else {
                 trigger_error("Manual cache configuration required.");
             }
         }
     }
     Yaml::saveWrapped($defaults, $configFile);
 }
コード例 #11
0
 /**
  * This builds a config file suitable for travis-ci.org
  *
  * @param string $configFile fully qualified path to YAML configuration file
  * @param string $baseDir    base directory
  * @return integer|false
  */
 protected function createConfigFile($configFile, $baseDir)
 {
     $url = 'http://localhost';
     $configs = array('root-path' => $baseDir, 'lib-path' => $baseDir . '/xoops_lib', 'var-path' => $baseDir . '/xoops_data', 'trust-path' => $baseDir . '/xoops_lib', 'url' => $url, 'prot' => 'http://', 'asset-path' => $baseDir . '/assets', 'asset-url' => $url . '/assets', 'themes-path' => $baseDir . '/themes', 'themes-url' => $url . '/themes', 'adminthemes-path' => $baseDir . '/modules/system/themes', 'adminthemes-url' => $url . '/modules/system/themes', 'media-path' => $baseDir . '/media', 'media-url' => $url . '/media', 'uploads-path' => $baseDir . '/uploads', 'uploads-url' => $url . '/uploads', 'cookie-domain' => '', 'cookie-path' => '/', 'smarty-cache' => $baseDir . '/xoops_data/caches/smarty_cache', 'smarty-compile' => $baseDir . '/xoops_data/caches/smarty_compile', 'smarty-xoops-plugins' => $baseDir . '/xoops_lib/smarty/xoops_plugins', 'db-type' => 'pdo_mysql', 'db-charset' => 'utf8', 'db-prefix' => 'x300', 'db-host' => 'localhost', 'db-user' => 'travis', 'db-pass' => '', 'db-name' => 'xoops_test', 'db-pconnect' => 0, 'db-parameters' => array('driver' => 'pdo_mysql', 'charset' => 'utf8', 'dbname' => 'xoops_test', 'host' => 'localhost', 'user' => 'travis', 'password' => ''));
     Yaml::saveWrapped($configs, $configFile);
 }