/**
  * 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);
 }
 /**
  * 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();
         }
     }
 }
Beispiel #3
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;
 }