/**
  * Prepare view
  *
  * @param  string $template
  * @return void
  */
 protected function prepareView($template)
 {
     $this->view = new View($this->viewPath . '/' . $template);
     $this->view->application_title = $this->application->config()['application_title'];
     if (isset($this->sess->failed)) {
         $this->view->failed = true;
     }
     if (isset($this->sess->expired)) {
         $this->view->expired = true;
     }
     if (isset($this->sess->saved)) {
         $this->view->saved = true;
     }
     if (isset($this->sess->removed)) {
         $this->view->removed = true;
     }
     if (isset($this->sess->user)) {
         $this->services['nav.top']->setRole($this->services['acl']->getRole($this->sess->user->role));
         $this->services['nav.top']->returnFalse(true);
         if ($this->services->isAvailable('nav.fluid')) {
             $this->services['nav.fluid']->setRole($this->services['acl']->getRole($this->sess->user->role));
             $this->services['nav.fluid']->returnFalse(true);
         }
         if ($this->services->isAvailable('nav.static')) {
             $this->services['nav.static']->setRole($this->services['acl']->getRole($this->sess->user->role));
             $this->services['nav.static']->returnFalse(true);
         }
         $this->view->popNav = $this->services['nav.top'];
         $this->view->acl = $this->services['acl'];
         $this->view->user = $this->sess->user;
         $cookie = \Pop\Cookie\Cookie::getInstance(['path' => '/']);
         $this->view->windowWidth = $cookie['pop_current_width'];
     }
 }
Example #2
0
 /**
  * Add content types to models of the module config for the application
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     $resources = $application->config()['resources'];
     $params = $application->services()->getParams('nav.phire');
     $config = $application->module('phire-content');
     $models = isset($config['models']) ? $config['models'] : null;
     $types = Table\ContentTypes::findAll(['order' => 'order ASC']);
     foreach ($types->rows() as $type) {
         if (null !== $models) {
             if (!isset($models['Phire\\Content\\Model\\Content'])) {
                 $models['Phire\\Content\\Model\\Content'] = [];
             }
             $models['Phire\\Content\\Model\\Content'][] = ['type_field' => 'type_id', 'type_value' => $type->id, 'type_name' => $type->name];
         }
         $resources['content-type-' . $type->id . '|content-type-' . str_replace(' ', '-', strtolower($type->name))] = ['index', 'add', 'edit', 'remove'];
         if (!isset($params['tree']['content']['children'])) {
             $params['tree']['content']['children'] = [];
         }
         $params['tree']['content']['children']['content-type-' . $type->id] = ['name' => $type->name, 'href' => '/content/' . $type->id, 'acl' => ['resource' => 'content-type-' . $type->id, 'permission' => 'index']];
     }
     $application->mergeConfig(['resources' => $resources]);
     $application->services()->setParams('nav.phire', $params);
     if (null !== $models) {
         $application->module('phire-content')->mergeConfig(['models' => $models]);
     }
     $content = Table\Content::findBy(['roles!=' => 'a:0:{}']);
     if ($content->hasRows()) {
         foreach ($content->rows() as $c) {
             $application->services()->get('acl')->addResource(new \Pop\Acl\Resource\Resource('content-' . $c->id));
         }
     }
 }
Example #3
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     $resources = $application->config()['resources'];
     $params = $application->services()->getParams('nav.phire');
     $config = $application->module('phire-media');
     $models = isset($config['models']) ? $config['models'] : null;
     $libraries = Table\MediaLibraries::findAll(['order' => 'order ASC']);
     foreach ($libraries->rows() as $library) {
         if (null !== $models) {
             if (!isset($models['Phire\\Media\\Model\\Media'])) {
                 $models['Phire\\Media\\Model\\Media'] = [];
             }
             $models['Phire\\Media\\Model\\Media'][] = ['type_field' => 'library_id', 'type_value' => $library->id, 'type_name' => $library->name];
         }
         $resources['media-library-' . $library->id . '|media-library-' . str_replace(' ', '-', strtolower($library->name))] = ['index', 'add', 'edit', 'remove'];
         if (!isset($params['tree']['media']['children'])) {
             $params['tree']['media']['children'] = [];
         }
         $params['tree']['media']['children']['media-library-' . $library->id] = ['name' => $library->name, 'href' => '/media/' . $library->id, 'acl' => ['resource' => 'media-library-' . $library->id, 'permission' => 'index']];
     }
     $application->mergeConfig(['resources' => $resources]);
     $application->services()->setParams('nav.phire', $params);
     if (null !== $models) {
         $application->module('phire-media')->mergeConfig(['models' => $models]);
     }
 }
Example #4
0
 /**
  * Check if the application requires an SSL connection
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     if ($application->config()['force_ssl'] && $_SERVER['SERVER_PORT'] != '443') {
         Response::redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
         exit;
     }
 }
Example #5
0
 /**
  * Check for the user session
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     $sess = $application->getService('session');
     $action = $application->router()->getRouteMatch()->getAction();
     $route = $application->router()->getRouteMatch()->getRoute();
     $isInstall = substr($route, 0, strlen(APP_URI . '/install')) == APP_URI . '/install';
     // Special install check
     if (isset($sess->app_uri) && strpos($_SERVER['REQUEST_URI'], 'install/config') !== false) {
         if (BASE_PATH . APP_URI == BASE_PATH . $sess->app_uri && $application->config()['db']) {
             Response::redirect(BASE_PATH . APP_URI . '/install/user');
             exit;
         }
     }
     // If logged in, and a system URL, redirect to dashboard
     if (isset($sess->user) && ($action == 'login' || $action == 'register' || $action == 'verify' || $action == 'forgot' || $isInstall)) {
         Response::redirect(BASE_PATH . (APP_URI != '' ? APP_URI : '/'));
         exit;
         // Else, if NOT logged in and NOT a system URL, redirect to login
     } else {
         if (!isset($sess->user) && ($action != 'login' && $action != 'register' && !$isInstall && $action != 'unsubscribe' && $action != 'verify' && $action != 'forgot' && null !== $action) && substr($route, 0, strlen(APP_URI)) == APP_URI) {
             Response::redirect(BASE_PATH . APP_URI . '/login');
             exit;
         }
     }
 }
Example #6
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     $forms = $application->config()['forms'];
     if (isset($forms['Phire\\Content\\Form\\Content'])) {
         $forms['Phire\\Content\\Form\\Content'][0]['content_tags'] = ['type' => 'text', 'label' => 'Tags', 'attributes' => ['size' => 15, 'class' => 'tags-field']];
         $application->mergeConfig(['forms' => $forms], true);
     }
 }
Example #7
0
 /**
  * Check if the database has been installed and a database connection is available
  *
  * @param  Application $application
  * @throws \Phire\Exception
  * @return void
  */
 public static function check(Application $application)
 {
     $route = $application->router()->getRouteMatch()->getRoute();
     if (!$application->config()['db'] && substr($route, 0, strlen(APP_URI . '/install')) != APP_URI . '/install') {
         $exception = new \Phire\Exception('Error: The database has not been installed. ' . 'Please check the config file or <a href="' . BASE_PATH . APP_URI . '/install">install</a> the system.');
         $exception->setInstallErrorFlag(true);
         throw $exception;
     }
 }
Example #8
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     $forms = $application->config()['forms'];
     if (isset($forms['Phire\\Content\\Form\\Content'])) {
         $forms['Phire\\Content\\Form\\Content'][0]['feed'] = ['type' => 'radio', 'label' => 'Include in Feed?', 'value' => ['1' => 'Yes', '0' => 'No'], 'marked' => '0'];
         $forms['Phire\\Content\\Form\\Content'][0]['feed_type'] = ['type' => 'hidden', 'value' => 'content'];
     }
     if (isset($forms['Phire\\Media\\Form\\Media'])) {
         $forms['Phire\\Media\\Form\\Media'][0]['feed'] = ['type' => 'radio', 'label' => 'Include in Feed?', 'value' => ['1' => 'Yes', '0' => 'No'], 'marked' => '0'];
         $forms['Phire\\Media\\Form\\Media'][0]['feed_type'] = ['type' => 'hidden', 'value' => 'media'];
     }
     $application->mergeConfig(['forms' => $forms], true);
 }
Example #9
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     if ($application->isRegistered('phire-content')) {
         $templates = Table\Templates::findBy(['parent_id' => null]);
         if ($templates->hasRows()) {
             $forms = $application->config()['forms'];
             foreach ($templates->rows() as $template) {
                 if ($template->visible) {
                     $forms['Phire\\Content\\Form\\Content'][0]['content_template']['value'][$template->id] = $template->name;
                 }
             }
             $application->mergeConfig(['forms' => $forms], true);
         }
     }
 }
Example #10
0
 /**
  * Prepare view
  *
  * @param  string $template
  * @return void
  */
 protected function prepareView($template)
 {
     // Check for any override templates
     $headerTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/header.phtml') ? CONTENT_ABS_PATH . '/phire/view/phire/header.phtml' : __DIR__ . '/../../view/phire/header.phtml';
     $footerTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/footer.phtml') ? CONTENT_ABS_PATH . '/phire/view/phire/footer.phtml' : __DIR__ . '/../../view/phire/footer.phtml';
     $viewTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/' . $template) ? CONTENT_ABS_PATH . '/phire/view/' . $template : $this->viewPath . '/' . $template;
     $this->view = new View($viewTemplate);
     $this->view->phire = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
     $this->view->assets = $this->application->module('phire')->getAssets();
     $this->view->systemTitle = $this->application->config()['system_title'];
     $this->view->phireHeader = $headerTemplate;
     $this->view->phireFooter = $footerTemplate;
     $this->view->phireUri = BASE_PATH . APP_URI;
     $this->view->basePath = BASE_PATH;
     $this->view->base_path = BASE_PATH;
     $this->view->contentPath = CONTENT_PATH;
     $this->view->content_path = CONTENT_PATH;
     if (isset($this->sess->installed)) {
         $this->view->installed = true;
     }
     if (isset($this->sess->saved)) {
         $this->view->saved = true;
     }
     if (isset($this->sess->removed)) {
         $this->view->removed = true;
     }
     if (isset($this->sess->user)) {
         $this->services['nav.phire']->setRole($this->services['acl']->getRole($this->sess->user->role));
         $this->services['nav.phire']->returnFalse(true);
         $this->view->phireNav = $this->services['nav.phire'];
         $this->view->phirePath = BASE_PATH . APP_PATH;
         $this->view->docRoot = $_SERVER['DOCUMENT_ROOT'];
         $this->view->user = $this->sess->user;
         $this->view->acl = $this->services['acl'];
         $this->view->config = $this->config;
         $this->view->headers = $this->application->config()['headers'];
         $this->view->dashboard = $this->application->config()['dashboard'];
         $this->view->dashboardSide = $this->application->config()['dashboard_side'];
         $this->view->footers = $this->application->config()['footers'];
     } else {
         $this->view->phireNav = null;
     }
 }
Example #11
0
 /**
  * Check if the user session is allowed with the ACL service
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     if ($application->config()['db']) {
         $application->module('phire')->initAcl();
         $sess = $application->getService('session');
         $acl = $application->getService('acl');
         if (isset($sess->user) && isset($sess->user->role) && $acl->hasRole($sess->user->role)) {
             // Get routes with slash options
             $route = $application->router()->getRouteMatch()->getRoute();
             $routes = $application->router()->getRouteMatch()->getRoutes();
             if (isset($routes[$route]) && isset($routes[$route]['acl']) && isset($routes[$route]['acl']['resource'])) {
                 $resource = $routes[$route]['acl']['resource'];
                 $permission = isset($routes[$route]['acl']['permission']) ? $routes[$route]['acl']['permission'] : null;
                 if (!$acl->isAllowed($sess->user->role, $resource, $permission)) {
                     Response::redirect(BASE_PATH . (APP_URI != '' ? APP_URI : '/'));
                     exit;
                 }
             }
         }
     }
 }
Example #12
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     $forms = $application->config()['forms'];
     $cat = new Model\Category();
     $cat->getAll();
     if (count($cat->getFlatMap()) > 0) {
         $categoryValues = $cat->getCategoryValues();
         if (isset($forms['Phire\\Content\\Form\\Content'])) {
             $forms['Phire\\Content\\Form\\Content'][0]['categories'] = ['type' => 'checkbox', 'label' => 'Categories', 'value' => $categoryValues];
             $forms['Phire\\Content\\Form\\Content'][0]['category_type'] = ['type' => 'hidden', 'value' => 'content'];
         }
         if (isset($forms['Phire\\Media\\Form\\Media'])) {
             $forms['Phire\\Media\\Form\\Media'][0]['categories'] = ['type' => 'checkbox', 'label' => 'Categories', 'value' => $categoryValues];
             $forms['Phire\\Media\\Form\\Media'][0]['category_type'] = ['type' => 'hidden', 'value' => 'media'];
         }
         if (isset($forms['Phire\\Media\\Form\\Batch'])) {
             $forms['Phire\\Media\\Form\\Batch'][0]['categories'] = ['type' => 'checkbox', 'label' => 'Categories', 'value' => $categoryValues];
             $forms['Phire\\Media\\Form\\Batch'][0]['category_type'] = ['type' => 'hidden', 'value' => 'media'];
         }
         $application->mergeConfig(['forms' => $forms], true);
     }
 }
Example #13
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     if ($application->isRegistered('phire-content')) {
         $theme = Table\Themes::findBy(['active' => 1]);
         if (isset($theme->id)) {
             $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder, ['filesOnly' => true]);
             $parentDir = null;
             if (null !== $theme->parent_id) {
                 $parentTheme = Table\Themes::findById($theme->parent_id);
                 if (isset($parentTheme->id)) {
                     $parentDir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $parentTheme->folder, ['filesOnly' => true]);
                 }
             }
             $forms = $application->config()['forms'];
             if (null !== $parentDir) {
                 $dirFiles = $dir->getFiles();
                 foreach ($dirFiles as $file) {
                     if (strpos($file, '.ph') !== false && !in_array($file, $application->module('phire-themes')['invisible'])) {
                         $forms['Phire\\Content\\Form\\Content'][0]['content_template']['value'][$file] = $file;
                     }
                 }
                 foreach ($parentDir->getFiles() as $file) {
                     if (!in_array($file, $dirFiles) && strpos($file, '.ph') !== false && !in_array($file, $application->module('phire-themes')['invisible'])) {
                         $forms['Phire\\Content\\Form\\Content'][0]['content_template']['value'][$file] = $file . ' (parent)';
                     }
                 }
             } else {
                 foreach ($dir->getFiles() as $file) {
                     if (strpos($file, '.ph') !== false && !in_array($file, $application->module('phire-themes')['invisible'])) {
                         $forms['Phire\\Content\\Form\\Content'][0]['content_template']['value'][$file] = $file;
                     }
                 }
             }
             $application->mergeConfig(['forms' => $forms], true);
         }
     }
 }
Example #14
0
 /**
  * Add dynamic fields to the form configs
  *
  * @param  Application $application
  * @return void
  */
 public static function addFields(Application $application)
 {
     $forms = $application->config()['forms'];
     $fields = Table\Fields::findBy(['group_id' => null], ['order' => 'order'], Table\FieldGroups::ROW_AS_ARRAYOBJECT);
     $groups = Table\FieldGroups::findAll(['order' => 'order'], Table\FieldGroups::ROW_AS_ARRAYOBJECT);
     if ($fields->count() > 0) {
         foreach ($fields->rows() as $field) {
             $field->validators = unserialize($field->validators);
             $field->models = unserialize($field->models);
             foreach ($field->models as $i => $model) {
                 if ($model['model'] == 'Phire\\Model\\User') {
                     $register = $model;
                     $registerEmail = $model;
                     $profile = $model;
                     $profileEmail = $model;
                     $register['model'] = 'Phire\\Model\\Register';
                     $registerEmail['model'] = 'Phire\\Model\\RegisterEmail';
                     $profile['model'] = 'Phire\\Model\\Profile';
                     $profileEmail['model'] = 'Phire\\Model\\ProfileEmail';
                     $field->models[] = $register;
                     $field->models[] = $registerEmail;
                     $field->models[] = $profile;
                     $field->models[] = $profileEmail;
                 }
             }
             foreach ($field->models as $model) {
                 $form = str_replace('Model', 'Form', $model['model']);
                 if (isset($forms[$form]) && self::isAllowed($model, $application)) {
                     end($forms[$form]);
                     $key = key($forms[$form]);
                     reset($forms[$form]);
                     $fieldConfig = self::createFieldConfig($field);
                     if ($form == 'Phire\\Form\\Register' || $form == 'Phire\\Form\\RegisterEmail' || $form == 'Phire\\Form\\Profile' || $form == 'Phire\\Form\\ProfileEmail') {
                         $forms[$form][1]['field_' . $field->id] = $fieldConfig;
                     } else {
                         if ($field->dynamic) {
                             if (isset($fieldConfig['label'])) {
                                 $fieldConfig['label'] = '<a href="#" onclick="return phire.addField(' . $field->id . ');">[+]</a> ' . $fieldConfig['label'];
                             } else {
                                 $fieldConfig['label'] = '<a href="#" onclick="return phire.addField(' . $field->id . ');">[+]</a>';
                             }
                             if (isset($fieldConfig['attributes'])) {
                                 $fieldConfig['attributes']['data-path'] = BASE_PATH . APP_URI;
                                 $fieldConfig['attributes']['data-model'] = $model['model'];
                             } else {
                                 $fieldConfig['attributes'] = ['data-path' => BASE_PATH . APP_URI, 'data-model' => $model['model']];
                             }
                         }
                         if (is_numeric($key)) {
                             if ($field->prepend) {
                                 $forms[$form][$key] = array_merge(['field_' . $field->id => $fieldConfig], $forms[$form][$key]);
                             } else {
                                 $forms[$form][$key]['field_' . $field->id] = $fieldConfig;
                             }
                         } else {
                             if ($field->prepend) {
                                 $forms[$form] = array_merge(['field_' . $field->id => $fieldConfig], $forms[$form]);
                             } else {
                                 $forms[$form]['field_' . $field->id] = $fieldConfig;
                             }
                         }
                     }
                 }
             }
         }
     }
     $fieldGroups = [];
     $groupPrepend = [];
     if ($groups->count() > 0) {
         $tab = 1001;
         foreach ($groups->rows() as $group) {
             $groupPrepend[$group->id] = (bool) $group->prepend;
             $fields = Table\Fields::findBy(['group_id' => $group->id], ['order' => 'order']);
             if ($fields->count() > 0) {
                 $i = 0;
                 foreach ($fields->rows() as $field) {
                     $field->validators = unserialize($field->validators);
                     $field->models = unserialize($field->models);
                     foreach ($field->models as $model) {
                         $form = str_replace('Model', 'Form', $model['model']);
                         if (isset($forms[$form]) && self::isAllowed($model, $application)) {
                             $fieldConfig = self::createFieldConfig($field);
                             if ($field->dynamic) {
                                 if (isset($fieldConfig['label'])) {
                                     $fieldConfig['label'] = '<a href="#" onclick="return phire.addField(' . $field->id . ');">[+]</a> ' . $fieldConfig['label'];
                                 } else {
                                     $fieldConfig['label'] = '<a href="#" onclick="return phire.addField(' . $field->id . ']);">[+]</a>';
                                 }
                             }
                             if (isset($fieldConfig['attributes'])) {
                                 $fieldConfig['attributes']['tabindex'] = $tab;
                                 $fieldConfig['attributes']['data-path'] = BASE_PATH . APP_URI;
                                 $fieldConfig['attributes']['data-model'] = $model['model'];
                             } else {
                                 $fieldConfig['attributes'] = ['tabindex' => $tab, 'data-path' => BASE_PATH . APP_URI, 'data-model' => $model['model']];
                             }
                             $tab++;
                             if (!isset($fieldGroups[$form])) {
                                 $fieldGroups[$form] = [];
                             }
                             if (!isset($fieldGroups[$form][$field->group_id])) {
                                 $fieldGroups[$form][$field->group_id] = [];
                             }
                             if ($field->prepend) {
                                 $fieldGroups[$form][$field->group_id] = array_merge(['field_' . $field->id => $fieldConfig], $fieldGroups[$form][$field->group_id]);
                             } else {
                                 $fieldGroups[$form][$field->group_id]['field_' . $field->id] = $fieldConfig;
                             }
                         }
                     }
                     $i++;
                 }
             }
         }
     }
     foreach ($fieldGroups as $form => $configs) {
         $keys = array_keys($forms[$form]);
         $numeric = true;
         foreach ($keys as $key) {
             if (!is_numeric($key)) {
                 $numeric = false;
             }
         }
         $formConfig = $numeric ? $forms[$form] : [$forms[$form]];
         foreach ($configs as $id => $config) {
             if ($groupPrepend[$id]) {
                 $formConfig = array_merge($config, $formConfig);
             } else {
                 $formConfig[] = $config;
             }
         }
         $forms[$form] = $formConfig;
     }
     $application->mergeConfig(['forms' => $forms], true);
 }