Esempio n. 1
0
 /**
  * Get overview configuration values
  *
  * @return array
  */
 public function getOverview()
 {
     $cfg = Table\Config::getConfig();
     $config = array();
     $overview = array();
     foreach ($cfg->rows as $c) {
         $config[$c->setting] = $c->setting == 'media_allowed_types' || $c->setting == 'media_actions' ? unserialize($c->value) : $c->value;
     }
     $sysVersion = $config['system_version'];
     $latest = '';
     $handle = fopen('http://update.phirecms.org/system/version', 'r');
     if ($handle !== false) {
         $latest = trim(stream_get_contents($handle));
         fclose($handle);
     }
     if (version_compare(\Phire\Project::VERSION, $latest) < 0 && $this->data['acl']->isAuth('Phire\\Controller\\Phire\\Config\\IndexController', 'update')) {
         $sysVersion .= ' (<a href="' . BASE_PATH . APP_URI . '/config/update">' . $this->i18n->__('Update to') . ' ' . $latest . '</a>?)';
     }
     // Set server config settings
     $overview['system'] = array('system_version' => $sysVersion, 'system_domain' => $config['system_domain'], 'server_operating_system' => $config['server_operating_system'], 'server_software' => $config['server_software'], 'database_version' => $config['database_version'], 'php_version' => $config['php_version'], 'installed_on' => date($this->config->datetime_format, strtotime($config['installed_on'])), 'updated_on' => $config['updated_on'] != '0000-00-00 00:00:00' ? date($this->config->datetime_format, strtotime($config['updated_on'])) : '(' . $this->i18n->__('Never') . ')');
     $overview['sites'] = array();
     $overview['sites'][$config['system_domain'] . BASE_PATH] = $config['live'];
     $sites = Table\Sites::findAll('id ASC');
     foreach ($sites->rows as $site) {
         $overview['sites'][$site->domain . $site->base_path] = $site->live;
     }
     return $overview;
 }
Esempio n. 2
0
 /**
  * Set the field values
  *
  * @param  array                  $values
  * @param  array                  $filters
  * @param  \Phire\Auth\Auth       $auth
  * @param  \Phire\Table\UserTypes $type
  * @param  \Phire\Model\User      $user
  * @return \Pop\Form\Form
  */
 public function setFieldValues(array $values = null, $filters = null, $auth = null, $type = null, $user = null)
 {
     parent::setFieldValues($values, $filters);
     if ($_POST) {
         // Authenticate and get the auth result
         $auth->authenticate($this->username, $this->password);
         $result = $auth->getAuthResult($type, $this->username);
         if (null !== $result) {
             $user->login($this->username, $type, false);
             if ($auth->getResult() == \Pop\Auth\Auth::PASSWORD_INCORRECT) {
                 $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, $result));
             } else {
                 $this->getElement('username')->addValidator(new Validator\NotEqual($this->username, $result));
             }
         }
         // Check the user's allowed sites
         if (strtolower($type->type) != 'user') {
             $u = Table\Users::findBy(array('username' => $this->username));
             if (isset($u->id)) {
                 $siteIds = unserialize($u->site_ids);
                 $site = Table\Sites::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT']));
                 $siteId = isset($site->id) ? $site->id : '0';
                 if (!in_array($siteId, $siteIds)) {
                     $this->getElement('username')->addValidator(new Validator\NotEqual($this->username, $this->i18n->__('That user is not allowed on this site.')));
                 }
             }
         }
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Constructor method to instantiate the form object
  *
  * @param  string $action
  * @param  string $method
  * @param  string $type
  * @param  string $name
  * @param  string $format
  * @param  string $version
  * @return self
  */
 public function __construct($action = null, $method = 'post', $type = null, $name = null, $format = null, $version = null)
 {
     parent::__construct($action, $method, null, '        ');
     $site = Table\Sites::getSite();
     if (strpos($site->domain, 'www.') !== false) {
         $domain = 'ftp.' . str_replace('www.', '', $site->domain);
     } else {
         $domain = $site->domain;
     }
     $rootValue = $_POST && isset($_POST['change_ftp_root']) ? $_POST['change_ftp_root'] : null;
     $fields1 = array('ftp_address' => array('type' => 'text', 'label' => $this->i18n->__('FTP Address'), 'required' => true, 'attributes' => array('size' => 40), 'value' => $domain), 'username' => array('type' => 'text', 'label' => $this->i18n->__('Username'), 'required' => true, 'attributes' => array('size' => 40)), 'password' => array('type' => 'text', 'label' => $this->i18n->__('Password'), 'required' => true, 'attributes' => array('size' => 40)), 'ftp_root' => array('type' => 'radio', 'label' => $this->i18n->__('FTP Root'), 'value' => array('0' => $this->i18n->__('Log directly into the document root.') . '<br /><br />', '1' => $this->i18n->__('No, change the directory to') . ' <input style="margin-left: 5px; width: 150px; height: 15px; font-size: 0.9em;" type="text" size="18" name="change_ftp_root" value="' . $rootValue . '" />'), 'marked' => '0'));
     $fields2 = array('submit' => array('type' => 'submit', 'value' => $this->i18n->__('UPDATE'), 'attributes' => array('class' => 'save-btn')), 'use_pasv' => array('type' => 'radio', 'label' => $this->i18n->__('Use PASV'), 'value' => array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), 'marked' => '1'), 'protocol' => array('type' => 'radio', 'label' => $this->i18n->__('Protocol'), 'value' => array('0' => $this->i18n->__('FTP'), '1' => $this->i18n->__('FTPS')), 'marked' => '0'), 'type' => array('type' => 'hidden', 'value' => $type), 'name' => array('type' => 'hidden', 'value' => $name), 'version' => array('type' => 'hidden', 'value' => $version), 'format' => array('type' => 'hidden', 'value' => $format), 'base_path' => array('type' => 'hidden', 'value' => BASE_PATH), 'content_path' => array('type' => 'hidden', 'value' => CONTENT_PATH), 'app_path' => array('type' => 'hidden', 'value' => APP_PATH));
     $this->initFieldsValues = array($fields2, $fields1);
     $this->setAttributes('id', 'update-form');
 }
Esempio n. 4
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @param  array $filters
  * @return \Pop\Form\Form
  */
 public function setFieldValues(array $values = null, $filters = null)
 {
     parent::setFieldValues($values, $filters);
     // Add validators for checking dupe names and devices
     if ($_POST && isset($_POST['id'])) {
         $site = Table\Sites::findBy(array('domain' => $this->domain));
         if (isset($site->id) && $this->id != $site->id || $this->domain == $_SERVER['HTTP_HOST']) {
             $this->getElement('domain')->addValidator(new Validator\NotEqual($this->domain, $this->i18n->__('That site domain already exists.')));
         }
         $site = Table\Sites::findBy(array('document_root' => $this->document_root));
         if (isset($site->id) && $this->id != $site->id) {
             $this->getElement('document_root')->addValidator(new Validator\NotEqual($this->document_root, $this->i18n->__('That site document root already exists.')));
         }
         $docRoot = substr($this->document_root, -1) == '/' || substr($this->document_root, -1) == "\\" ? substr($this->document_root, 0, -1) : $this->document_root;
         if ($this->base_path != '') {
             $basePath = substr($this->base_path, 0, 1) != '/' || substr($this->base_path, 0, 1) != "\\" ? '/' . $this->base_path : $this->base_path;
             if (substr($basePath, -1) == '/' || substr($basePath, -1) == "\\") {
                 $basePath = substr($basePath, 0, -1);
             }
         } else {
             $basePath = '';
         }
         if (!file_exists($docRoot)) {
             $this->getElement('document_root')->addValidator(new Validator\NotEqual($this->document_root, $this->i18n->__('That site document root does not exists.')));
         } else {
             if (!file_exists($docRoot . $basePath)) {
                 $this->getElement('base_path')->addValidator(new Validator\NotEqual($this->base_path, $this->i18n->__('The base path does not exist under that document root.')));
             } else {
                 if (!file_exists($docRoot . $basePath . DIRECTORY_SEPARATOR . 'index.php')) {
                     $this->getElement('base_path')->addValidator(new Validator\NotEqual($this->base_path, $this->i18n->__('The index controller does not exist under that document root and base path.')));
                 } else {
                     if (!file_exists($docRoot . $basePath . DIRECTORY_SEPARATOR . CONTENT_PATH)) {
                         $this->getElement('base_path')->addValidator(new Validator\NotEqual($this->base_path, $this->i18n->__('The content path does not exist under that document root and base path.')));
                     } else {
                         if (!is_writable($docRoot . $basePath . DIRECTORY_SEPARATOR . CONTENT_PATH)) {
                             $this->getElement('base_path')->addValidator(new Validator\NotEqual($this->base_path, $this->i18n->__('The content path is not writable under that document root and base path.')));
                         }
                     }
                 }
             }
         }
     }
     $this->checkFiles();
     return $this;
 }
Esempio n. 5
0
 /**
  * Static method to get base configuration values
  *
  * @return \ArrayObject
  */
 public static function getSystemConfig()
 {
     $settings = array('system_title', 'system_email', 'reply_email', 'site_title', 'separator', 'default_language', 'datetime_format', 'media_allowed_types', 'media_max_filesize', 'media_actions', 'media_image_adapter', 'pagination_limit', 'pagination_range', 'force_ssl', 'live');
     $config = array();
     $cfg = static::findAll();
     foreach ($cfg->rows as $c) {
         if (in_array($c->setting, $settings)) {
             $config[$c->setting] = $c->setting == 'media_allowed_types' || $c->setting == 'media_actions' ? unserialize($c->value) : $c->value;
         }
     }
     $allowedTypes = Model\Config::getMediaTypes();
     foreach ($allowedTypes as $key => $value) {
         if (!in_array($key, $config['media_allowed_types'])) {
             unset($allowedTypes[$key]);
         }
     }
     if ($config['media_max_filesize'] > 999999) {
         $maxSize = round($config['media_max_filesize'] / 1000000) . ' MB';
     } else {
         if ($config['media_max_filesize'] > 999) {
             $maxSize = round($config['media_max_filesize'] / 1000) . ' KB';
         } else {
             $maxSize = $config['media_max_filesize'] . ' B';
         }
     }
     $config['media_max_filesize_formatted'] = $maxSize;
     $config['media_allowed_types'] = $allowedTypes;
     $site = Sites::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT']));
     if (isset($site->id)) {
         $config['site_title'] = $site->title;
         $config['base_path'] = $site->base_path;
         $config['force_ssl'] = $site->force_ssl;
         $config['live'] = $site->live;
     } else {
         $config['base_path'] = BASE_PATH;
     }
     return new \ArrayObject($config, \ArrayObject::ARRAY_AS_PROPS);
 }
 /**
  * Prepare view method
  *
  * @param  string $template
  * @param  array  $data
  * @return void
  */
 public function prepareView($template = null, array $data = array())
 {
     $site = \Phire\Table\Sites::getSite();
     if (null !== $template) {
         $template = $this->getCustomView($template, $site);
     }
     $sess = \Pop\Web\Session::getInstance();
     $config = \Phire\Table\Config::getSystemConfig();
     $i18n = \Phire\Table\Config::getI18n();
     $this->live = (bool) $config->live;
     $jsVars = null;
     $this->view = View::factory($template, $data);
     $this->view->set('base_path', $site->base_path)->set('content_path', CONTENT_PATH);
     // Check for an override Phire theme for the header/footer
     if (file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/header.phtml') && file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/footer.phtml')) {
         $this->view->set('phireHeader', $site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/header.phtml')->set('phireFooter', $site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/footer.phtml');
         // Else, just use the default header/footer
     } else {
         $this->view->set('phireHeader', $site->document_root . $site->base_path . APP_PATH . '/vendor/Phire/view/phire/header.phtml')->set('phireFooter', $site->document_root . $site->base_path . APP_PATH . '/vendor/Phire/view/phire/footer.phtml');
     }
     if (isset($this->view->assets)) {
         $jsVars = '?lang=' . $config->default_language;
     }
     if (isset($sess->user)) {
         if (isset($this->sess->user->last_action)) {
             $this->sess->user->last_action = date('Y-m-d H:i:s');
         }
         // Set the timeout warning, giving a 30 second buffer to act
         if (isset($this->view->assets)) {
             if (isset($this->view->acl) && $this->view->acl->getType()->session_expiration > 0 && $this->view->acl->getType()->timeout_warning) {
                 $exp = $this->view->acl->getType()->session_expiration * 60 - 30;
                 $uri = $site->base_path . (strtolower($this->view->acl->getType()->type) != 'user' ? '/' . strtolower($this->view->acl->getType()->type) : APP_URI);
                 $jsVars .= '&_exp=' . $exp . '&_base=' . urlencode($uri);
             }
         }
         $this->view->set('user', $sess->user)->set('role', \Phire\Table\UserRoles::getRole($sess->user->role_id))->set('globalAccess', $sess->user->global_access);
         if (isset($this->view->phireNav) && isset($this->view->acl) && $this->view->acl->hasRole($this->view->role->getName())) {
             $this->view->phireNav->setConfig(array('top' => array('node' => 'ul', 'id' => 'phire-nav')));
             $this->view->phireNav->setAcl($this->view->acl);
             $this->view->phireNav->setRole($this->view->role);
             $tree = $this->view->phireNav->getTree();
             // If the sub-children haven't been added yet
             if (isset($tree[0])) {
                 // And any user types to the main phire nav
                 $userTypes = \Phire\Table\UserTypes::findAll('id ASC');
                 if (isset($userTypes->rows)) {
                     foreach ($userTypes->rows as $type) {
                         $perm = 'index_' . $type->id;
                         if ($this->view->acl->isAuth('Phire\\Controller\\Phire\\User\\IndexController', 'index') && $this->view->acl->isAuth('Phire\\Controller\\Phire\\User\\IndexController', 'index_' . $type->id)) {
                             $perm = 'index';
                         }
                         $this->view->phireNav->addLeaf('Users', array('name' => ucwords(str_replace('-', ' ', $type->type)), 'href' => 'index/' . $type->id, 'acl' => array('resource' => 'Phire\\Controller\\Phire\\User\\IndexController', 'permission' => $perm)), 1);
                     }
                 }
                 // Set the language
                 $tree = $this->view->phireNav->getTree();
                 foreach ($tree as $key => $value) {
                     if (isset($value['name'])) {
                         $tree[$key]['name'] = $i18n->__($value['name']);
                         if (isset($value['children']) && count($value['children']) > 0) {
                             foreach ($value['children'] as $k => $v) {
                                 if ($v['name'] == 'Fields' && isset($tree[$key]['children'][$k]['children'][0]['name'])) {
                                     $tree[$key]['children'][$k]['children'][0]['name'] = $i18n->__($tree[$key]['children'][$k]['children'][0]['name']);
                                 }
                                 $tree[$key]['children'][$k]['name'] = $i18n->__($v['name']);
                             }
                         }
                     }
                 }
                 $this->view->phireNav->setTree($tree);
             }
             $this->view->phireNav->rebuild();
             $this->view->phireNav->nav()->setIndent('    ');
         }
     }
     if (isset($this->view->assets)) {
         $this->view->assets = str_replace('jax.3.2.0.min.js', 'jax.3.2.0.min.js' . $jsVars, $this->view->assets);
     }
     if (isset($sess->errors)) {
         $this->view->set('errors', $sess->errors);
     }
     // Set config object and system/site default data
     $this->view->set('i18n', $i18n)->set('system_title', $config->system_title)->set('system_email', $config->system_email)->set('site_title', $config->site_title)->set('base_path', $config->base_path)->set('separator', $config->separator)->set('default_language', $config->default_language)->set('datetime_format', $config->datetime_format);
 }
Esempio n. 7
0
 /**
  * Static method to remove field values
  *
  * @param int    $modelId
  * @param string $dir
  * @return void
  */
 public static function remove($modelId, $dir = null)
 {
     $fields = \Phire\Table\FieldValues::findAll(null, array('model_id' => $modelId));
     if (null === $dir) {
         $dir = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'media';
     }
     if (isset($fields->rows[0])) {
         foreach ($fields->rows as $field) {
             // Get the field values with the field type to check for any files to delete
             if (isset($field->field_id)) {
                 $sql = \Phire\Table\FieldValues::getSql();
                 $sql->select(array(DB_PREFIX . 'field_values.field_id', DB_PREFIX . 'field_values.model_id', DB_PREFIX . 'field_values.value', DB_PREFIX . 'fields.type'))->join(DB_PREFIX . 'fields', array('field_id', 'id'), 'LEFT JOIN')->where()->equalTo('field_id', ':field_id')->equalTo('model_id', ':model_id');
                 $fld = \Phire\Table\FieldValues::execute($sql->render(true), array('field_id' => $field->field_id, 'model_id' => $modelId));
                 if (isset($fld->field_id)) {
                     // If field type is file, delete file(s)
                     if ($fld->type == 'file') {
                         $file = json_decode($fld->value, true);
                         if (is_array($file)) {
                             foreach ($file as $f) {
                                 if (file_exists($dir . '/' . $f)) {
                                     \Phire\Model\Media::remove($f, $dir);
                                 } else {
                                     $sites = Table\Sites::findAll();
                                     foreach ($sites->rows as $site) {
                                         if (file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/media/' . $f)) {
                                             \Phire\Model\Media::remove($f, $site->document_root . $site->base_path . CONTENT_PATH . '/media');
                                         }
                                     }
                                 }
                             }
                         } else {
                             if (file_exists($dir . '/' . $file)) {
                                 \Phire\Model\Media::remove($file, $dir);
                             } else {
                                 $sites = Table\Sites::findAll();
                                 foreach ($sites->rows as $site) {
                                     if (file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/media/' . $file)) {
                                         \Phire\Model\Media::remove($file, $site->document_root . $site->base_path . CONTENT_PATH . '/media');
                                     }
                                 }
                             }
                         }
                     }
                     $fld->delete();
                 }
             }
         }
     }
 }
 /**
  * Login method
  *
  * @param  string $redirect
  * @return void
  */
 public function login($redirect = null)
 {
     $site = Table\Sites::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT']));
     // Prevent attempting to log into the system from other sites
     if (isset($site->id) && strtolower($this->type->type) == 'user') {
         Response::redirect('http://' . $site->domain . BASE_PATH);
         // If user type is not found, 404
     } else {
         if (!isset($this->type->id)) {
             $this->error();
             // If login is not allowed
         } else {
             if (!$this->type->login) {
                 Response::redirect(BASE_PATH . '/');
                 // Else, render the form
             } else {
                 $this->prepareView('login.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'), 'phire' => new Model\Phire()));
                 $this->view->set('title', $this->view->i18n->__('Login'));
                 // Set up 'forgot,' 'register' and 'unsubscribe' links
                 $uri = strtolower($this->type->type) == 'user' ? APP_URI : '/' . strtolower($this->type->type);
                 $forgot = '<a href="' . BASE_PATH . $uri . '/forgot">' . $this->view->i18n->__('Forgot') . '</a>';
                 $forgot .= $this->type->registration ? ' | <a href="' . BASE_PATH . $uri . '/register">' . $this->view->i18n->__('Register') . '</a>' : null;
                 $forgot .= !$this->type->unsubscribe_login ? ' | <a href="' . BASE_PATH . $uri . '/unsubscribe">' . $this->view->i18n->__('Unsubscribe') . '</a>' : null;
                 $this->view->set('forgot', $forgot);
                 if (isset($this->sess->expired)) {
                     $this->view->set('error', $this->view->i18n->__('Your session has expired.'));
                 } else {
                     if (isset($this->sess->authError)) {
                         $this->view->set('error', $this->view->i18n->__('The user is not allowed in this area.'));
                     }
                 }
                 $form = new Form\Login($this->request->getBasePath() . $this->request->getRequestUri(), 'post');
                 // If form is submitted
                 if ($this->request->isPost()) {
                     $user = new Model\User();
                     $form->setFieldValues($this->request->getPost(), array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')), $this->project->getService('auth')->config($this->type, $this->request->getPost('username')), $this->type, $user);
                     $this->view->set('form', $form);
                     // If form is valid, authenticate the user
                     if ($form->isValid()) {
                         $user->login($form->username, $this->type);
                         if (isset($this->sess->lastUrl)) {
                             $url = $this->sess->lastUrl;
                         } else {
                             $url = null !== $redirect ? $redirect : $this->request->getBasePath();
                         }
                         unset($this->sess->expired);
                         unset($this->sess->authError);
                         unset($this->sess->lastUrl);
                         if ($url == '') {
                             $url = '/';
                         }
                         Response::redirect($url);
                         // Else, re-render the form
                     } else {
                         $this->send();
                     }
                     // Else, render the form
                 } else {
                     $this->view->set('form', $form);
                     $this->send();
                 }
             }
         }
     }
 }
Esempio n. 9
0
 /**
  * Save user
  *
  * @param  \Pop\Form\Form $form
  * @param  \Pop\Config    $config
  * @return void
  */
 public function save(\Pop\Form\Form $form, $config)
 {
     $encOptions = $config->encryptionOptions->asArray();
     $fields = $form->getFields();
     $type = Table\UserTypes::findById($fields['type_id']);
     $password = isset($fields['password1']) ? self::encryptPassword($fields['password1'], $type->password_encryption, $encOptions) : '';
     // Set the username according to user type
     $username = isset($fields['username']) ? $fields['username'] : $fields['email1'];
     // Set the role according to user type
     if (isset($fields['role_id'])) {
         $fields['role_id'] = $fields['role_id'] == 0 ? null : $fields['role_id'];
     } else {
         $fields['role_id'] = $type->approval ? null : $type->default_role_id;
     }
     // Set verified or not
     if (!isset($fields['verified'])) {
         $fields['verified'] = $type->verification ? 0 : 1;
     }
     if (isset($fields['site_ids'])) {
         $siteIds = $fields['site_ids'];
     } else {
         $site = Table\Sites::getSite();
         $siteIds = array($site->id);
     }
     // Save the new user
     $user = new Table\Users(array('type_id' => $fields['type_id'], 'role_id' => $fields['role_id'], 'username' => $username, 'password' => $password, 'email' => $fields['email1'], 'verified' => $fields['verified'], 'logins' => null, 'failed_attempts' => 0, 'site_ids' => serialize($siteIds), 'created' => date('Y-m-d H:i:s')));
     $user->save();
     $this->data['id'] = $user->id;
     $sess = Session::getInstance();
     $sess->last_user_id = $user->id;
     FieldValue::save($fields, $user->id);
     // Send verification if needed
     if ($type->verification && !$user->verified) {
         $this->sendVerification($user, $type);
     }
     // Send registration notification to system admin
     if ($type->registration_notification) {
         $this->sendNotification($user, $type);
     }
     $form->clear();
 }
Esempio n. 10
0
 /**
  * Remove sites
  *
  * @param array $post
  * @return void
  */
 public function remove(array $post)
 {
     if (isset($post['remove_sites'])) {
         foreach ($post['remove_sites'] as $id) {
             $site = Table\Sites::findById($id);
             if (isset($site->id)) {
                 $users = Table\Users::findAll();
                 foreach ($users->rows as $user) {
                     $siteIds = unserialize($user->site_ids);
                     if (in_array($site->id, $siteIds)) {
                         $key = array_search($site->id, $siteIds);
                         unset($siteIds[$key]);
                         $u = Table\Users::findById($user->id);
                         if (isset($u->id)) {
                             $u->site_ids = serialize($siteIds);
                             $u->update();
                         }
                     }
                 }
                 $site->delete();
             }
         }
     }
 }
Esempio n. 11
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;
 }
Esempio n. 12
0
 /**
  * Event-based auth check
  *
  * @param  \Pop\Mvc\Router $router
  * @return mixed
  */
 public static function auth($router)
 {
     $sess = Session::getInstance();
     $site = Sites::getSite();
     $basePath = $site->base_path;
     $resource = $router->getControllerClass();
     $permission = $router->getAction();
     $isFrontController = substr_count($resource, '\\') == 2;
     // Check for the resource and permission
     if (!$isFrontController && $resource != 'Phire\\Controller\\Phire\\Install\\IndexController') {
         if (null === $router->project()->getService('acl')->getResource($resource)) {
             if ($resource != 'Phire\\Controller\\Phire\\IndexController') {
                 $router->project()->getService('acl')->addResource($resource);
             } else {
                 $resource = null;
                 $permission = null;
             }
         }
         if (null !== $permission && null !== $resource && !method_exists($resource, $permission)) {
             $permission = 'error';
         }
         if ($router->controller()->getRequest()->getPath(0) == 'index' || $router->controller()->getRequest()->getPath(0) == 'add') {
             $permId = $router->controller()->getRequest()->getPath(1);
             if (null !== $permId && is_numeric($permId)) {
                 $permission .= '_' . $permId;
             }
         }
         // Get the user URI
         $uri = APP_URI == '' || strtolower($router->project()->getService('acl')->getType()->type) == 'user' ? APP_URI : '/' . strtolower($router->project()->getService('acl')->getType()->type);
         // If reset password flag is set
         if (isset($sess->reset_pwd) && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/profile' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/login' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/logout') {
             \Pop\Http\Response::redirect($basePath . $uri . '/profile');
             return \Pop\Event\Manager::KILL;
             // If not logged in for unsubscribe and required, redirect to the system login
         } else {
             if ($_SERVER['REQUEST_URI'] == $basePath . $uri . '/unsubscribe' && $router->project()->getService('acl')->getType()->unsubscribe_login && !$router->project()->getService('acl')->isAuth($resource, $permission)) {
                 \Pop\Http\Response::redirect($basePath . $uri . '/login');
                 return \Pop\Event\Manager::KILL;
                 // Else, if not logged in or allowed, redirect to the system login
             } else {
                 if ($_SERVER['REQUEST_URI'] != $basePath . $uri . '/login' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/register' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/forgot' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/unsubscribe' && substr($_SERVER['REQUEST_URI'], 0, strlen($basePath . $uri . '/json')) != $basePath . $uri . '/json' && strpos($_SERVER['REQUEST_URI'], $basePath . $uri . '/verify') === false && !$router->project()->getService('acl')->isAuth($resource, $permission)) {
                     \Pop\Http\Response::redirect($basePath . $uri . '/login');
                     return \Pop\Event\Manager::KILL;
                     // Else, if logged in and allowed, and a system access URI, redirect back to the system
                 } else {
                     if (($_SERVER['REQUEST_URI'] == $basePath . $uri . '/login' || $_SERVER['REQUEST_URI'] == $basePath . $uri . '/register' || $_SERVER['REQUEST_URI'] == $basePath . $uri . '/forgot') && $router->project()->getService('acl')->isAuth($resource, $permission)) {
                         \Pop\Http\Response::redirect($basePath . ($uri == '' ? '/' : $uri));
                         return \Pop\Event\Manager::KILL;
                     }
                 }
             }
         }
     }
 }
Esempio n. 13
0
 /**
  * Method to filter the content and replace any placeholders
  *
  * @param   array $data
  * @param   int   $siteId
  * @returns array
  */
 protected function filterContent(array $data = null, $siteId = null)
 {
     $dataAry = null === $data ? $this->data : $data;
     if (isset($dataAry['site_id'])) {
         $siteId = (int) $dataAry['site_id'];
     } else {
         $siteId = (int) $siteId;
     }
     $site = Table\Sites::getSite($siteId);
     $keys = array_keys($dataAry);
     foreach ($dataAry as $key => $value) {
         if (is_string($value)) {
             $value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
             $value = str_replace(array('[{base_path}]', '[{content_path}]'), array($site->base_path, CONTENT_PATH), $value);
             foreach ($keys as $k) {
                 if (strpos($value, '[{' . $k . '}]') !== false && $dataAry[$k]) {
                     $value = str_replace('[{' . $k . '}]', $dataAry[$k], $value);
                 }
             }
             $dataAry[$key] = $value;
         } else {
             if (is_array($value)) {
                 $dataAry[$key] = $this->filterContent($value, $siteId);
             }
         }
     }
     if (null === $data) {
         $this->data = $dataAry;
     } else {
         $this->data = array_merge($this->data, $dataAry);
     }
     return $dataAry;
 }
Esempio n. 14
0
 /**
  * Get the init field values
  *
  * @param  int     $tid
  * @param  boolean $profile
  * @param  int     $uid
  * @param  string  $action
  * @param  boolean $register
  * @return array
  */
 protected function getInitFields($tid = 0, $profile = false, $uid = 0, $action, $register = false)
 {
     $type = Table\UserTypes::findById($tid);
     $fields1 = array();
     // Continue setting up initial user fields
     $fields1['email1'] = array('type' => 'text', 'label' => $this->i18n->__('Email'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\Email());
     if ($type->email_verification) {
         $fields1['email2'] = array('type' => 'text', 'label' => $this->i18n->__('Re-Type Email'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\Email());
     }
     // If not email as username, create username field
     if (!$type->email_as_username) {
         $fields2 = array('username' => array('type' => 'text', 'label' => $this->i18n->__('Username'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => array(new Validator\AlphaNumeric(), new Validator\LengthGte(4))));
         if ($uid != 0) {
             $fields2['username']['attributes']['onkeyup'] = "phire.updateTitle('#username-title', this);";
         }
     } else {
         $fields2 = array();
         if ($uid != 0) {
             $fields1['email1']['attributes']['onkeyup'] = "phire.updateTitle('#username-title', this);";
         }
     }
     // Continue setting up initial user fields
     if ($type->login) {
         $fields3 = array('password1' => array('type' => 'password', 'label' => $this->i18n->__('Enter Password'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\LengthGte(6)), 'password2' => array('type' => 'password', 'label' => $this->i18n->__('Re-Type Password'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\LengthGte(6)));
     } else {
         $fields3 = array();
     }
     $fieldGroups = array();
     $dynamicFields = false;
     $model = str_replace('Form', 'Model', get_class($this));
     $newFields = \Phire\Model\Field::getByModel($model, $tid, $uid);
     if ($newFields['dynamic']) {
         $dynamicFields = true;
     }
     if ($newFields['hasFile']) {
         $this->hasFile = true;
     }
     foreach ($newFields as $key => $value) {
         if (is_numeric($key)) {
             $fieldGroups[] = $value;
         }
     }
     $fields4 = array();
     if ($register) {
         $site = Table\Sites::getSite();
         if ($type->use_csrf) {
             $fields4['csrf'] = array('type' => 'csrf', 'value' => \Pop\Filter\String::random(8));
         }
         if ($type->use_captcha) {
             $fields4['captcha'] = array('type' => 'captcha', 'label' => $this->i18n->__('Enter Code'), 'captcha' => '<br /><img id="captcha-image" src="' . $site->base_path . '/captcha" /><br /><a class="reload-link" href="#" onclick="document.getElementById(\'captcha-image\').src = \'' . $site->base_path . '/captcha?reload=1\';return false;">' . $this->i18n->__('Reload') . '</a>', 'attributes' => array('size' => 5));
         }
     }
     // Finish the initial fields
     $fields4['submit'] = array('type' => 'submit', 'value' => strpos($action, '/register') !== false ? $this->i18n->__('REGISTER') : $this->i18n->__('SAVE'), 'attributes' => array('class' => strpos($action, '/install/user') !== false || $profile ? 'update-btn' : 'save-btn'));
     if ($profile) {
         $fields4['submit']['label'] = '&nbsp;';
         $fields4['submit']['attributes']['style'] = 'width: 250px;';
         $fields4['profile'] = array('type' => 'hidden', 'value' => 1);
         $sess = \Pop\Web\Session::getInstance();
         if (isset($sess->reset_pwd)) {
             $fields4['reset_pwd'] = array('type' => 'hidden', 'value' => 1);
         }
     }
     if (!$profile) {
         $fields4['update'] = array('type' => 'button', 'value' => $this->i18n->__('Update'), 'attributes' => array('onclick' => "return phire.updateForm('#user-form', " . ($this->hasFile || $dynamicFields ? 'true' : 'false') . ");", 'class' => 'update-btn'));
     }
     $fields4['type_id'] = array('type' => 'hidden', 'value' => $tid);
     $fields4['id'] = array('type' => 'hidden', 'value' => 0);
     if (!$profile) {
         $fields4['update_value'] = array('type' => 'hidden', 'value' => 0);
     }
     // If not profile
     if (!$profile) {
         // Get roles for user type
         $rolesAry = array('0' => '(' . $this->i18n->__('Blocked') . ')');
         if ($tid != 0) {
             $roles = Table\UserRoles::findBy(array('type_id' => $tid), 'id ASC');
             foreach ($roles->rows as $role) {
                 $rolesAry[$role->id] = $role->name;
             }
         }
         $siteIds = array('0' => $_SERVER['HTTP_HOST']);
         $sites = Table\Sites::findAll();
         foreach ($sites->rows as $site) {
             $siteIds[(string) $site->id] = $site->domain;
         }
         $fields4['role_id'] = array('type' => 'select', 'required' => true, 'label' => $this->i18n->__('User Role'), 'value' => $rolesAry, 'marked' => $type->default_role_id);
         $fields4['verified'] = array('type' => 'select', 'label' => $this->i18n->__('Verified'), 'value' => array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), 'marked' => '0');
         $fields4['failed_attempts'] = array('type' => 'text', 'label' => $this->i18n->__('Failed Attempts'), 'attributes' => array('size' => 3));
         $fields4['site_ids'] = array('type' => 'checkbox', 'label' => $this->i18n->__('Allowed Sites'), 'value' => $siteIds);
     }
     if (strpos($action, '/install/user') !== false || $profile) {
         $allFields = array($fields1, $fields2, $fields3);
         if (count($fieldGroups) > 0) {
             foreach ($fieldGroups as $fg) {
                 $allFields[] = $fg;
             }
         }
         $allFields[] = $fields4;
     } else {
         $allFields = array($fields4, $fields1, $fields2, $fields3);
         if (count($fieldGroups) > 0) {
             foreach ($fieldGroups as $fg) {
                 $allFields[] = $fg;
             }
         }
     }
     return $allFields;
 }