Ejemplo n.º 1
0
 /**
  * Constructor method to instantiate the user controller object
  *
  * @param  Request  $request
  * @param  Response $response
  * @param  Project  $project
  * @param  string   $viewPath
  * @return self
  */
 public function __construct(Request $request = null, Response $response = null, Project $project = null, $viewPath = null)
 {
     // Create the session object and get the user type
     $this->sess = Session::getInstance();
     $this->type = $project->getService('acl')->getType();
     if (null === $viewPath) {
         $cfg = $project->module('Phire')->asArray();
         $viewPath = __DIR__ . '/../../../../view/phire';
         if (isset($cfg['view'])) {
             $class = get_class($this);
             if (is_array($cfg['view']) && isset($cfg['view'][$class])) {
                 $viewPath = $cfg['view'][$class];
             } else {
                 if (is_array($cfg['view']) && isset($cfg['view']['*'])) {
                     $viewPath = $cfg['view']['*'];
                 } else {
                     if (is_string($cfg['view'])) {
                         $viewPath = $cfg['view'];
                     }
                 }
             }
         }
         // If it is not a user, or a user globally logged into another area
         if (strtolower($this->type->type) != 'user' && !$this->type->global_access || substr($_SERVER['REQUEST_URI'], 0, strlen(BASE_PATH . APP_URI)) != BASE_PATH . APP_URI) {
             $site = Table\Sites::getSite();
             $theme = Table\Extensions::findBy(array('type' => 0, 'active' => 1), null, 1);
             $themePath = $site->document_root . $site->base_path . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $this->type->type;
             $activeThemePath = null;
             if (isset($theme->rows[0])) {
                 $activeThemePath = $site->document_root . $site->base_path . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme->rows[0]->name . DIRECTORY_SEPARATOR . $this->type->type;
             }
             if (null !== $activeThemePath && file_exists($activeThemePath)) {
                 $viewPath = $activeThemePath;
             } else {
                 if (file_exists($themePath)) {
                     $viewPath = $themePath;
                 }
             }
         }
     }
     // Set the correct base path and user URI based on user type
     if (get_called_class() == 'Phire\\Controller\\Phire\\IndexController') {
         $basePath = strtolower($this->type->type) != 'user' ? BASE_PATH . '/' . strtolower($this->type->type) : BASE_PATH . APP_URI;
         $request = new Request(null, $basePath);
     }
     parent::__construct($request, $response, $project, $viewPath);
 }
Ejemplo n.º 2
0
 /**
  * Process themes method
  *
  * @param  array $post
  * @return void
  */
 public function processModules($post)
 {
     foreach ($post as $key => $value) {
         if (strpos($key, 'module_active_') !== false) {
             $id = substr($key, strrpos($key, '_') + 1);
             $ext = Table\Extensions::findById($id);
             if (isset($ext->id)) {
                 $ext->active = (int) $value;
                 $ext->save();
             }
         }
     }
     $path = BASE_PATH . APP_URI;
     if ($path == '') {
         $path = '/';
     }
     $modulePath1 = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules';
     $modulePath2 = __DIR__ . '/../../../../../module';
     $phireCookie = null;
     if (php_sapi_name() != 'cli') {
         $cookie = Cookie::getInstance(array('path' => $path));
         if (isset($cookie->phire)) {
             if (null === $phireCookie) {
                 $phireCookie = $cookie->phire;
             }
         }
     }
     if (isset($post['remove_modules'])) {
         foreach ($post['remove_modules'] as $id) {
             $ext = Table\Extensions::findById($id);
             if (isset($ext->id)) {
                 $modPath = file_exists($modulePath1 . '/' . $ext->file) ? $modulePath1 : $modulePath2;
                 $assets = unserialize($ext->assets);
                 if (count($assets['tables']) > 0) {
                     $db = Table\Extensions::getDb();
                     if (DB_INTERFACE == 'Mysqli' || DB_TYPE == 'mysql') {
                         $db->adapter()->query('SET foreign_key_checks = 0;');
                         foreach ($assets['tables'] as $table) {
                             $db->adapter()->query('DROP TABLE ' . $table);
                         }
                         $db->adapter()->query('SET foreign_key_checks = 1;');
                     } else {
                         if (DB_INTERFACE == 'Pgsql' || DB_TYPE == 'pgsql') {
                             foreach ($assets['tables'] as $table) {
                                 $db->adapter()->query('DROP TABLE ' . $table . ' CASCADE');
                             }
                         } else {
                             foreach ($assets['tables'] as $table) {
                                 $db->adapter()->query('DROP TABLE ' . $table);
                             }
                         }
                     }
                 }
                 $contentPath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH;
                 $exts = array('.zip', '.tar.gz', '.tar.bz2', '.tgz', '.tbz', '.tbz2');
                 // Check for a config and remove function
                 if (file_exists($modPath . '/' . $ext->name . '/config') && file_exists($modPath . '/' . $ext->name . '/config/module.php')) {
                     $config = (include $modPath . '/' . $ext->name . '/config/module.php');
                     if (null !== $config[$ext->name]->remove) {
                         $removeFunc = $config[$ext->name]->remove;
                         $removeFunc();
                     }
                 }
                 if (file_exists($contentPath . '/extensions/modules/' . $ext->name)) {
                     $dir = new Dir($contentPath . '/extensions/modules/' . $ext->name);
                     $dir->emptyDir(null, true);
                 }
                 foreach ($exts as $e) {
                     if (file_exists($contentPath . '/extensions/modules/' . $ext->name . $e) && is_writable($contentPath . '/extensions/modules/' . $ext->name . $e)) {
                         unlink($contentPath . '/extensions/modules/' . $ext->name . $e);
                     }
                 }
                 if (file_exists(__DIR__ . '/../../../../../module/' . $ext->name)) {
                     $dir = new Dir(__DIR__ . '/../../../../../module/' . $ext->name);
                     $dir->emptyDir(null, true);
                 }
                 foreach ($exts as $e) {
                     if (file_exists(__DIR__ . '/../../../../../module/' . $ext->name . $e) && is_writable(__DIR__ . '/../../../../../module/' . $ext->name . $e)) {
                         unlink(__DIR__ . '/../../../../../module/' . $ext->name . $e);
                     }
                 }
                 if (file_exists($contentPath . '/assets/' . strtolower($ext->name))) {
                     $dir = new Dir($contentPath . '/assets/' . strtolower($ext->name));
                     $dir->emptyDir(null, true);
                 }
                 if (null !== $phireCookie) {
                     foreach ($phireCookie->modules as $key => $value) {
                         if ($value->name == $ext->name) {
                             $modules = (array) $phireCookie->modules;
                             unset($modules[$key]);
                             $phireCookie->modules = $modules;
                         }
                     }
                 }
                 $ext->delete();
             }
         }
     }
     if (null !== $phireCookie) {
         $cookie = Cookie::getInstance(array('path' => $path));
         $cookie->set('phire', $phireCookie);
     }
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * Config update method
  *
  * @return void
  */
 public function update()
 {
     $this->prepareView('update.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav')));
     if (null !== $this->request->getQuery('module')) {
         $type = 'module';
         $name = $this->request->getQuery('module');
         $version = null;
         $title = $this->view->i18n->__('Module Update') . ' ' . $this->view->separator . ' ' . $name;
         $linkParam = '&module=' . $name;
         $ext = Table\Extensions::findBy(array('name' => $name));
         if (isset($ext->id)) {
             $assets = unserialize($ext->assets);
             $version = $assets['info']['Version'];
         }
     } else {
         if (null !== $this->request->getQuery('theme')) {
             $type = 'theme';
             $name = $this->request->getQuery('theme');
             $version = null;
             $title = $this->view->i18n->__('Theme Update') . ' ' . $this->view->separator . ' ' . $name;
             $linkParam = '&theme=' . $name;
             $ext = Table\Extensions::findBy(array('name' => $name));
             if (isset($ext->id)) {
                 $assets = unserialize($ext->assets);
                 $version = $assets['info']['Version'];
             }
         } else {
             $type = 'system';
             $name = 'phire';
             $version = \Phire\Project::VERSION;
             $title = $this->view->i18n->__('System Update');
             $linkParam = null;
         }
     }
     $format = null;
     $formats = \Pop\Archive\Archive::formats();
     if (isset($formats['zip'])) {
         $format = 'zip';
     } else {
         if (isset($formats['tar']) && isset($formats['gz'])) {
             $format = 'tar.gz';
         }
     }
     $this->view->set('title', $this->view->i18n->__('Configuration') . ' ' . $this->view->separator . ' ' . $title);
     $config = new Model\Config();
     $writable = false;
     if ($type == 'system' && is_writable(__DIR__ . '/../../../../../../../')) {
         $writable = true;
     } else {
         if ($type == 'module' && is_writable(__DIR__ . '/../../../../../../../../' . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules')) {
             $writable = true;
         } else {
             if ($type == 'theme' && is_writable(__DIR__ . '/../../../../../../../../' . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes')) {
                 $writable = true;
             }
         }
     }
     if ($writable) {
         if (null !== $this->request->getQuery('writable')) {
             $config->getUpdate(array('type' => $type, 'name' => $name, 'version' => $version, 'format' => $format));
             if (null !== $config->error) {
                 $this->view->set('msg', $config->error);
                 $this->send();
             } else {
                 $this->view->set('msg', $config->msg);
                 $this->send();
             }
         } else {
             $link = $this->request->getFullUri() . '?writable=1' . $linkParam;
             $form = '<div id="update-form">' . $this->view->i18n->__('The %1 folder has been detected as writable.', $type) . ' ' . $this->view->i18n->__('You can proceed with the %1 update by clicking the update button below.', $type) . '<br /><br /><a href="' . $link . '" class="save-btn" style="display: block; width: 220px; height: 20px; color: #fff; text-decoration: none;">' . $this->view->i18n->__('UPDATE') . '</a></div>';
             $this->view->set('form', $form);
             $this->send();
         }
     } else {
         $form = new Form\Update($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $type, $name, $version, $format);
         if ($this->request->isPost()) {
             $form->setFieldValues($this->request->getPost(), array('htmlentities' => array(ENT_QUOTES, 'UTF-8')));
             if ($form->isValid()) {
                 $config->getUpdate($this->request->getPost());
                 if (null !== $config->error) {
                     $this->view->set('msg', $config->error);
                     $this->send();
                 } else {
                     $this->view->set('msg', $config->msg);
                     $this->send();
                 }
             } else {
                 $this->view->set('form', $form);
                 $this->send();
             }
         } else {
             $this->view->set('form', $form);
             $this->send();
         }
     }
 }
Ejemplo n.º 5
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');
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Register and load any other modules
  *
  * @param  \Pop\Loader\Autoloader $autoloader
  * @param  boolean                $site
  * @throws Exception
  * @return self
  */
 public function load($autoloader, $site = false)
 {
     if ($site) {
         $s = Table\Sites::getSite();
         $docRoot = $s->document_root;
         $basePath = $s->base_path;
     } else {
         $docRoot = $_SERVER['DOCUMENT_ROOT'];
         $basePath = BASE_PATH;
     }
     $events = array();
     // Load Phire any overriding Phire configuration
     if (!$site) {
         $this->loadAssets(__DIR__ . '/../../../Phire/data', 'Phire', $docRoot);
     }
     // Check if Phire is installed
     self::isInstalled();
     $sess = Session::getInstance();
     $errors = self::checkDirsQuick($docRoot . $basePath . CONTENT_PATH, true, $docRoot);
     if (count($errors) > 0) {
         $sess->errors = '            ' . implode('<br />' . PHP_EOL . '            ', $errors) . PHP_EOL;
     } else {
         unset($sess->errors);
     }
     $modulesAry = array();
     $modulesDirs = array(__DIR__ . '/../../../', __DIR__ . '/../../../../module/', __DIR__ . '/../../../../..' . CONTENT_PATH . '/extensions/modules/');
     // Check for overriding Phire config
     if (file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/extensions/modules/config/phire.php')) {
         $phireCfg = (include $docRoot . BASE_PATH . CONTENT_PATH . '/extensions/modules/config/phire.php');
         if (isset($phireCfg['Phire'])) {
             // If the overriding config is set to allow changes, merge new nav with the original nav
             // else, the entire original nav will be overwritten with the new nav.
             if (isset($phireCfg['Phire']->nav) && $phireCfg['Phire']->changesAllowed()) {
                 $nav = array_merge($phireCfg['Phire']->nav->asArray(), $this->module('Phire')->nav->asArray());
                 $phireCfg['Phire']->nav = new \Pop\Config($nav);
             }
             $this->module('Phire')->merge($phireCfg['Phire']);
             // Get any Phire event
             if (null !== $this->module('Phire')->events) {
                 $events['Phire'] = $this->module('Phire')->events->asArray();
             }
         }
     }
     // Register and load any other modules
     foreach ($modulesDirs as $directory) {
         if (file_exists($directory) && is_dir($directory)) {
             $dir = new Dir($directory);
             $dirs = $dir->getFiles();
             sort($dirs);
             foreach ($dirs as $d) {
                 $moduleCfg = null;
                 if ($d != 'PopPHPFramework' && $d != 'Phire' && $d != 'config' && $d != 'vendor' && is_dir($directory . $d)) {
                     $ext = Table\Extensions::findBy(array('name' => $d));
                     if (!isset($ext->id) || isset($ext->id) && $ext->active) {
                         $modulesAry[] = $d;
                         // Load assets
                         if (!$site) {
                             $this->loadAssets($directory . $d . '/data', $d, $docRoot);
                         }
                         // Get module config
                         if (file_exists($directory . $d . '/config/module.php')) {
                             $moduleCfg = (include $directory . $d . '/config/module.php');
                         }
                         // Check for any module config overrides
                         if (file_exists($directory . '/config/' . strtolower($d) . '.php')) {
                             $override = (include $directory . '/config/' . strtolower($d) . '.php');
                             if (isset($override[$d]) && null !== $moduleCfg) {
                                 $moduleCfg[$d]->merge($override[$d]);
                             }
                         }
                         // Load module configs
                         if (null !== $moduleCfg) {
                             // Register the module source
                             if (file_exists($moduleCfg[$d]->src)) {
                                 $autoloader->register($d, $moduleCfg[$d]->src);
                             }
                             // Get any module events
                             if (null !== $moduleCfg[$d]->events) {
                                 $events[$d] = $moduleCfg[$d]->events->asArray();
                             }
                             $this->loadModule($moduleCfg);
                         }
                     }
                 }
             }
         }
     }
     // Attach any event hooks
     if (count($events) > 0) {
         foreach ($events as $module => $evts) {
             foreach ($evts as $event => $action) {
                 $act = null;
                 $priority = 0;
                 if (is_array($action)) {
                     if (!isset($action['action'])) {
                         throw new Exception("The 'action' parameter is not set for the '" . $event . "' event within the " . $module . " module configuration file.");
                     }
                     $act = $action['action'];
                     $priority = isset($action['priority']) ? $action['priority'] : 0;
                 } else {
                     $act = $action;
                 }
                 if (null !== $act) {
                     $this->attachEvent($event, $act, $priority);
                 }
             }
         }
     }
     // Add Phire CSS override file if it exists
     if (file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/css/phire.css')) {
         $this->assets['css'] .= '    <style type="text/css">@import "' . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/css/phire.css";</style>' . PHP_EOL;
     }
     // If logged in, set Phire path cookie
     if (!$site && isset($sess->user)) {
         $path = BASE_PATH . APP_URI;
         if ($path == '') {
             $path = '/';
         }
         $cookie = Cookie::getInstance(array('path' => $path));
         if (!isset($cookie->phire)) {
             $modsAry = array();
             foreach ($modulesAry as $modName) {
                 $i18n = file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/assets/' . strtolower($modName) . '/i18n');
                 $modsAry[] = array('name' => $modName, 'i18n' => $i18n);
             }
             $cookie->set('phire', array('base_path' => BASE_PATH, 'app_path' => APP_PATH, 'content_path' => CONTENT_PATH, 'app_uri' => APP_URI, 'server_tz_offset' => abs(date('Z')) / 60, 'modules' => $modsAry));
         }
     }
     // Initiate the router object
     $this->loadRouter(new \Pop\Mvc\Router(array(), new \Pop\Http\Request(null, BASE_PATH)));
     return $this;
 }