Beispiel #1
0
 /**
  * Static method to get i18n object
  *
  * @return \Pop\I18n\I18n
  */
 public static function getI18n()
 {
     $lang = static::findById('default_language')->value;
     if (!defined('POP_LANG')) {
         define('POP_LANG', $lang);
         $i18n = \Pop\I18n\I18n::factory($lang);
     } else {
         $i18n = \Pop\I18n\I18n::factory(POP_LANG);
     }
     $i18n->loadFile(__DIR__ . '/../../../data/assets/i18n/' . $i18n->getLanguage() . '.xml');
     // Load any module language files
     $modules = Extensions::findAll(null, array('type' => 1));
     foreach ($modules->rows as $module) {
         if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name) && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name . '/data') && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name . '/data/assets/i18n') && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name . '/data/assets/i18n/' . $i18n->getLanguage() . '.xml')) {
             $i18n->loadFile($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name . '/data/assets/i18n/' . $i18n->getLanguage() . '.xml');
         }
     }
     return $i18n;
 }
 /**
  * Get all modules method
  *
  * @param  \Phire\Project $project
  * @return void
  */
 public function getModules(\Phire\Project $project = null)
 {
     $modules = Table\Extensions::findAll('id ASC', array('type' => 1));
     $moduleRows = $modules->rows;
     $moduleDir1 = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules', false, false, false);
     $moduleDir2 = new Dir(__DIR__ . '/../../../../../module', false, false, false);
     $dirs = array_merge($moduleDir1->getFiles(), $moduleDir2->getFiles());
     $moduleFiles = array();
     $formats = Archive::formats();
     foreach ($dirs as $file) {
         if (array_key_exists(substr($file, strrpos($file, '.') + 1), $formats)) {
             $moduleFiles[substr($file, 0, strpos($file, '.'))] = $file;
         }
     }
     foreach ($moduleRows as $key => $module) {
         $moduleName = $module->name;
         if (null !== $project) {
             $cfg = $project->module($module->name);
             if (null !== $cfg && null !== $cfg->module_nav) {
                 $n = !is_array($cfg->module_nav) ? $cfg->module_nav->asArray() : $cfg->module_nav;
                 $modNav = new Nav($n, array('top' => array('id' => strtolower($module->name) . '-nav', 'class' => 'module-nav')));
                 $modNav->setAcl($this->data['acl']);
                 $modNav->setRole($this->data['role']);
                 $moduleRows[$key]->module_nav = $modNav;
             }
         }
         if (isset($moduleFiles[$module->name])) {
             unset($moduleFiles[$module->name]);
         }
         // Get module info
         $assets = unserialize($module->assets);
         $moduleRows[$key]->author = '';
         $moduleRows[$key]->desc = '';
         $moduleRows[$key]->version = '';
         foreach ($assets['info'] as $k => $v) {
             if (stripos($k, 'name') !== false) {
                 $moduleRows[$key]->name = $v;
             } else {
                 if (stripos($k, 'author') !== false) {
                     $moduleRows[$key]->author = $v;
                 } else {
                     if (stripos($k, 'desc') !== false) {
                         $moduleRows[$key]->desc = $v;
                     } else {
                         if (stripos($k, 'version') !== false) {
                             $moduleRows[$key]->version = $v;
                         }
                     }
                 }
             }
         }
         $latest = '';
         $handle = @fopen('http://update.phirecms.org/modules/' . strtolower($moduleName) . '/version', 'r');
         if ($handle !== false) {
             $latest = trim(stream_get_contents($handle));
             fclose($handle);
         }
         if (version_compare($moduleRows[$key]->version, $latest) < 0 && $this->data['acl']->isAuth('Phire\\Controller\\Phire\\Config\\IndexController', 'update')) {
             $moduleRows[$key]->version .= ' (<a href="' . BASE_PATH . APP_URI . '/config/update?module=' . $moduleName . '">' . $this->i18n->__('Update to') . ' ' . $latest . '</a>?)';
         }
     }
     $this->data['modules'] = $moduleRows;
     $this->data['new'] = $moduleFiles;
 }
Beispiel #3
0
 /**
  * Update site
  *
  * @param \Pop\Form\Form $form
  * @return void
  */
 public function update(\Pop\Form\Form $form)
 {
     $fields = $form->getFields();
     $site = Table\Sites::findById($fields['id']);
     $docRoot = substr($fields['document_root'], -1) == '/' && substr($fields['document_root'], -1) == "\\" ? substr($fields['document_root'], 0, -1) : $fields['document_root'];
     $oldDocRoot = $site->document_root;
     $docRoot = str_replace('\\', '/', $docRoot);
     if ($fields['base_path'] != '') {
         $basePath = substr($fields['base_path'], 0, 1) != '/' && substr($fields['base_path'], 0, 1) != "\\" ? '/' . $fields['base_path'] : $fields['base_path'];
         if (substr($basePath, -1) == '/' && substr($basePath, -1) == "\\") {
             $basePath = substr($basePath, 0, -1);
         }
     } else {
         $basePath = '';
     }
     $basePath = str_replace('\\', '/', $basePath);
     $site->domain = $fields['domain'];
     $site->document_root = $docRoot;
     $site->base_path = $basePath;
     $site->title = $fields['title'];
     $site->force_ssl = (int) $fields['force_ssl'];
     $site->live = (int) $fields['live'];
     $site->update();
     $this->data['id'] = $site->id;
     FieldValue::update($fields, $site->id);
     if ($oldDocRoot != $docRoot) {
         $this->createFolders($docRoot, $basePath);
         // Copy any themes over
         $themes = Table\Extensions::findAll(null, array('type' => 0));
         if (isset($themes->rows[0])) {
             $themePath = $docRoot . $basePath . CONTENT_PATH . '/extensions/themes';
             foreach ($themes->rows as $theme) {
                 if (!file_exists($themePath . '/' . $theme->name)) {
                     copy($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . BASE_PATH . DIRECTORY_SEPARATOR . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme->file, $themePath . '/' . $theme->file);
                     $archive = new \Pop\Archive\Archive($themePath . '/' . $theme->file);
                     $archive->extract($themePath . '/');
                     if ((stripos($theme->file, 'gz') || stripos($theme->file, 'bz')) && file_exists($themePath . '/' . $theme->name . '.tar')) {
                         unlink($themePath . '/' . $theme->name . '.tar');
                     }
                 }
             }
         }
     }
 }