Пример #1
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;
     }
 }
Пример #2
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;
         }
     }
 }
Пример #3
0
 /**
  * Add CAPTCHA image to form with a CAPTCHA field
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function addCaptcha(AbstractController $controller, Application $application)
 {
     if ($controller->hasView() && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Pop\Form\Form && null !== $controller->view()->form->getElement('captcha')) {
         $captcha = new \Phire\Captcha\Model\Captcha($application->module('phire-captcha')['config']);
         $captcha->createToken();
         $controller->view()->form->getElement('captcha')->setToken($captcha->token, 'Enter Code');
     }
 }
Пример #4
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;
     }
 }
Пример #5
0
 /**
  * Constructor for the controller
  *
  * @param  Application $application
  * @param  Console     $console
  * @return ConsoleController
  */
 public function __construct(Application $application, Console $console)
 {
     $this->application = $application;
     $this->services = $application->services();
     $this->console = $console;
     if ($this->services->isAvailable('database')) {
         $this->config = (new \Phire\Model\Config())->getAll();
     }
 }
Пример #6
0
 /**
  * Parse calendar
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function parse(AbstractController $controller, Application $application)
 {
     if (!$_POST && $controller->hasView() && $controller instanceof \Phire\Content\Controller\IndexController) {
         $body = $controller->response()->getBody();
         // Parse any calendar placeholders
         $calendars = [];
         $calendarIds = [];
         preg_match_all('/\\[\\{calendar.*\\}\\]/', $body, $calendars);
         if (isset($calendars[0]) && isset($calendars[0][0])) {
             foreach ($calendars[0] as $calendar) {
                 $id = substr($calendar, strpos($calendar, '[{calendar_') + 11);
                 if (strpos($id, '_') !== false) {
                     $id = substr($id, 0, strpos($id, '_'));
                     $replace = '[{calendar_' . $id . '_time}]';
                     $time = true;
                 } else {
                     $id = substr($id, 0, strpos($id, '}]'));
                     $replace = '[{calendar_' . $id . '}]';
                     $time = false;
                 }
                 $calendarIds[] = ['id' => $id, 'replace' => $replace, 'time' => $time];
             }
         }
         if (count($calendarIds) > 0) {
             $sess = $application->services()->get('session');
             $roleId = isset($sess->user) ? $sess->user->role_id : null;
             foreach ($calendarIds as $cal) {
                 $calendar = new Model\Calendar(['user_role_id' => $roleId, 'weekdays' => $application->module('phire-calendar')['weekdays'], 'range' => $application->module('phire-calendar')['range'], 'range_format' => $application->module('phire-calendar')['range_format'], 'day_format' => $application->module('phire-calendar')['day_format'], 'force_list' => $application->module('phire-calendar')['force_list'], 'force_list_mobile' => $application->module('phire-calendar')['force_list_mobile'], 'show_all' => $application->module('phire-calendar')['show_all'], 'date' => $controller->request()->getQuery('date')]);
                 $rendered = $calendar->getById($cal['id'], $cal['time']);
                 $body = str_replace($cal['replace'], $rendered, $body);
             }
             $controller->response()->setBody($body);
         }
     }
 }
Пример #7
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);
 }
Пример #8
0
 /**
  * Init the entity model and parse any entity placeholders
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function init(AbstractController $controller, Application $application)
 {
     if ($application->isRegistered('phire-templates') && $controller->hasView() && $controller->view()->isStream()) {
         $ents = [];
         preg_match_all('/\\[\\{entity_.*\\}\\]/', $controller->view()->getTemplate()->getTemplate(), $ents);
         if (isset($ents[0]) && isset($ents[0][0])) {
             foreach ($ents[0] as $ent) {
                 $id = str_replace('}]', '', substr($ent, strpos($ent, '_') + 1));
                 $controller->view()->{'entity_' . $id} = (new Model\Entity())->getByType($id);
             }
         }
     }
     if ($controller->hasView()) {
         $controller->view()->phire->entity = new Model\Entity();
     }
 }
Пример #9
0
 /**
  * Save click
  *
  * @param  Application $application
  * @return void
  */
 public static function save(Application $application)
 {
     if (!$_POST && $application->router()->getController() instanceof \Phire\Content\Controller\IndexController) {
         $uri = $application->router()->getController()->request()->getRequestUri();
         if ($uri != '/favicon.ico') {
             $click = new Model\Click();
             if ($application->router()->getController()->response()->getCode() == 200) {
                 $click->saveContent($uri, 'content');
             } else {
                 if ($application->router()->getController()->response()->getCode() == 404) {
                     $click->saveContent($uri, 'error');
                 }
             }
         }
     }
 }
Пример #10
0
 /**
  * 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'];
     }
 }
Пример #11
0
 public function init()
 {
     if (null !== $this->router) {
         $this->router->addRouteParams('*', ['services' => $this->services]);
     }
     $this->config = $this->services['config'];
     parent::init();
 }
Пример #12
0
 /**
  * Set the template for the content
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function setTemplate(AbstractController $controller, Application $application)
 {
     $template = null;
     $themePath = null;
     $parentThemePath = null;
     $realThemePath = null;
     $theme = Table\Themes::findBy(['active' => 1]);
     if (isset($theme->id)) {
         $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder . '/';
         if (null !== $theme->parent_id) {
             $parentTheme = Table\Themes::findById($theme->parent_id);
             if (isset($parentTheme->id)) {
                 $parentThemePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $parentTheme->folder . '/';
             }
         }
     }
     if ($application->isRegistered('phire-content') && $controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView()) {
         if (null !== $controller->getTemplate()) {
             if (isset($theme->id)) {
                 $controller->view()->themePath = $themePath;
                 $controller->view()->parentThemePath = $parentThemePath;
                 if ($controller->getTemplate() == -1 && (file_exists($themePath . 'error.phtml') || file_exists($themePath . 'error.php'))) {
                     $template = file_exists($themePath . 'error.phtml') ? 'error.phtml' : 'error.php';
                 } else {
                     if ($controller->getTemplate() == -2 && (file_exists($themePath . 'date.phtml') || file_exists($themePath . 'date.php'))) {
                         $template = file_exists($themePath . 'date.phtml') ? 'date.phtml' : 'date.php';
                     } else {
                         if (file_exists($themePath . $controller->getTemplate())) {
                             $template = $controller->getTemplate();
                         }
                     }
                 }
                 $realThemePath = $themePath;
                 if (null === $template && null !== $parentThemePath) {
                     if ($controller->getTemplate() == -1 && (file_exists($parentThemePath . 'error.phtml') || file_exists($parentThemePath . 'error.php'))) {
                         $template = file_exists($parentThemePath . 'error.phtml') ? 'error.phtml' : 'error.php';
                     } else {
                         if ($controller->getTemplate() == -2 && (file_exists($parentThemePath . 'date.phtml') || file_exists($parentThemePath . 'date.php'))) {
                             $template = file_exists($parentThemePath . 'date.phtml') ? 'date.phtml' : 'date.php';
                         } else {
                             if (file_exists($parentThemePath . $controller->getTemplate())) {
                                 $template = $controller->getTemplate();
                             }
                         }
                     }
                     $realThemePath = $parentThemePath;
                 }
                 if (null !== $template && null !== $realThemePath) {
                     $device = self::getDevice($controller->request()->getQuery('mobile'));
                     if (null !== $device && file_exists($realThemePath . $device . '/' . $template)) {
                         $template = $device . '/' . $template;
                     }
                     $controller->view()->setTemplate($realThemePath . $template);
                 }
             }
         }
     }
 }
Пример #13
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]);
     }
 }
Пример #14
0
 /**
  * Parse form object
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function parseForms(AbstractController $controller, Application $application)
 {
     if ($controller->hasView() && ($application->isRegistered('phire-content') && $controller instanceof \Phire\Content\Controller\IndexController || $application->isRegistered('phire-categories') && $controller instanceof \Phire\Categories\Controller\IndexController)) {
         $body = $controller->response()->getBody();
         if (strpos($body, '[{form_') !== false) {
             // Parse any form placeholders
             $formIds = [];
             $forms = [];
             preg_match_all('/\\[\\{form.*\\}\\]/', $body, $forms);
             if (isset($forms[0]) && isset($forms[0][0])) {
                 foreach ($forms[0] as $form) {
                     $id = substr($form, strpos($form, 'form_') + 5);
                     $formIds[] = str_replace('}]', '', $id);
                 }
             }
             if (count($formIds) > 0) {
                 foreach ($formIds as $id) {
                     try {
                         $form = new \Phire\Forms\Form\Form($id);
                         if ($form->isSubmitted()) {
                             $values = $form->getMethod() == 'post' ? $_POST : $_GET;
                             if ($form->isFiltered()) {
                                 $form->addFilter('strip_tags');
                             }
                             $form->setFieldValues($values);
                             if ($form->isValid()) {
                                 $form->process();
                                 $body = str_replace('[{form_' . $id . '}]', $form->getMessage(), $body);
                             } else {
                                 $body = str_replace('[{form_' . $id . '}]', (string) $form, $body);
                             }
                         } else {
                             $body = str_replace('[{form_' . $id . '}]', (string) $form, $body);
                         }
                     } catch (\Exception $e) {
                         $body = str_replace('[{form_' . $id . '}]', '', $body);
                     }
                 }
             }
             $controller->response()->setBody($body);
         }
     }
 }
Пример #15
0
 /**
  * Register module
  *
  * @param  Application $application
  * @return ModuleInterface
  */
 public function register(Application $application)
 {
     $this->application = $application;
     if (null !== $this->config) {
         // If the autoloader is set and the the module config has a
         // defined prefix and src, register the module with the autoloader
         if (null !== $this->application && null !== $this->application->autoloader() && isset($this->config['prefix']) && isset($this->config['src']) && file_exists($this->config['src'])) {
             // Register as PSR-0
             if (isset($this->config['psr-0']) && $this->config['psr-0']) {
                 $this->application->autoloader()->add($this->config['prefix'], $this->config['src']);
                 // Else, default to PSR-4
             } else {
                 $this->application->autoloader()->addPsr4($this->config['prefix'], $this->config['src']);
             }
         }
         // If routes are set in the module config, register them with the application
         if (isset($this->config['routes']) && null !== $this->application && null !== $this->application->router()) {
             $this->application->router()->addRoutes($this->config['routes']);
         }
         // If services are set in the module config, register them with the application
         if (isset($this->config['services']) && null !== $this->application && null !== $this->application->services()) {
             foreach ($this->config['services'] as $name => $service) {
                 if (isset($service['call']) && isset($service['params'])) {
                     $this->application->setService($name, $service['call'], $service['params']);
                 } else {
                     if (isset($service['call'])) {
                         $this->application->setService($name, $service['call']);
                     }
                 }
             }
         }
         // If events are set in the app config, register them with the application
         if (isset($this->config['events']) && null !== $this->application && null !== $this->application->events()) {
             foreach ($this->config['events'] as $event) {
                 if (isset($event['name']) && isset($event['action'])) {
                     $this->application->on($event['name'], $event['action'], isset($event['priority']) ? $event['priority'] : 0);
                 }
             }
         }
     }
     return $this;
 }
Пример #16
0
 public function bootstrap($autoloader = null)
 {
     parent::bootstrap($autoloader);
     $this->on('app.route.pre', function () {
         echo PHP_EOL;
         echo '    Pop Spider' . PHP_EOL;
         echo '    ----------' . PHP_EOL . PHP_EOL;
     });
     $this->on('app.dispatch.post', function () {
         echo PHP_EOL . PHP_EOL;
     });
 }
Пример #17
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     if ($application->isRegistered('phire-content') && $application->isRegistered('phire-fields')) {
         $fields = \Phire\Fields\Table\Fields::findBy(['models' => "%Phire\\\\Content\\\\Model\\\\Content%"]);
         $names = [];
         foreach ($fields->rows() as $field) {
             $names[] = $field->name;
         }
         if (!in_array('seo_title', $names)) {
             $field = new \Phire\Fields\Table\Fields(['group_id' => null, 'storage' => 'eav', 'type' => 'text', 'name' => 'seo_title', 'label' => 'SEO Title', 'values' => null, 'default_values' => null, 'attributes' => 'size="80" style="width: 99.5%;"', 'validators' => 'a:0:{}', 'encrypt' => 0, 'order' => -3, 'required' => 0, 'prepend' => 0, 'dynamic' => 0, 'editor' => null, 'models' => 'a:1:{i:0;a:3:{s:5:"model";s:27:"Phire\\Content\\Model\\Content";s:10:"type_field";N;s:10:"type_value";N;}}']);
             $field->save();
         }
         if (!in_array('description', $names)) {
             $field = new \Phire\Fields\Table\Fields(['group_id' => null, 'storage' => 'eav', 'type' => 'text', 'name' => 'description', 'label' => 'Description', 'values' => null, 'default_values' => null, 'attributes' => 'size="80" style="width: 99.5%;"', 'validators' => 'a:0:{}', 'encrypt' => 0, 'order' => -2, 'required' => 0, 'prepend' => 0, 'dynamic' => 0, 'editor' => null, 'models' => 'a:1:{i:0;a:3:{s:5:"model";s:27:"Phire\\Content\\Model\\Content";s:10:"type_field";N;s:10:"type_value";N;}}']);
             $field->save();
         }
         if (!in_array('keywords', $names)) {
             $field = new \Phire\Fields\Table\Fields(['group_id' => null, 'storage' => 'eav', 'type' => 'text', 'name' => 'keywords', 'label' => 'Keywords', 'values' => null, 'default_values' => null, 'attributes' => 'size="80" style="width: 99.5%;"', 'validators' => 'a:0:{}', 'encrypt' => 0, 'order' => -1, 'required' => 0, 'prepend' => 0, 'dynamic' => 0, 'editor' => null, 'models' => 'a:1:{i:0;a:3:{s:5:"model";s:27:"Phire\\Content\\Model\\Content";s:10:"type_field";N;s:10:"type_value";N;}}']);
             $field->save();
         }
     }
 }
Пример #18
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();
     if (isset($sess->user) && isset($sess->user->sess_id) && !isset(Table\UserSessions::findById($sess->user->sess_id)->id)) {
         $user = new Model\User();
         $user->logout($sess);
         unset($sess->user);
         $sess->setRequestValue('expired', true);
         Response::redirect('/login');
         exit;
     } else {
         if (isset($sess->user) && ($action == 'login' || $action == 'forgot' || $action == 'verify')) {
             Response::redirect('/');
             exit;
         } else {
             if (!isset($sess->user) && $action != 'login' && $action != 'forgot' && $action != 'verify') {
                 Response::redirect('/login');
                 exit;
             }
         }
     }
 }
Пример #19
0
 /**
  * Set the search template
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function setTemplate(AbstractController $controller, Application $application)
 {
     if ($application->isRegistered('phire-templates') && $controller instanceof \Phire\Search\Controller\IndexController && $controller->hasView()) {
         $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Search']);
         if (isset($template->id)) {
             if (isset($template->id)) {
                 $device = \Phire\Templates\Event\Template::getDevice($controller->request()->getQuery('mobile'));
                 if (null !== $device && $template->device != $device) {
                     $childTemplate = \Phire\Templates\Table\Templates::findBy(['parent_id' => $template->id, 'device' => $device]);
                     if (isset($childTemplate->id)) {
                         $tmpl = $childTemplate->template;
                     } else {
                         $tmpl = $template->template;
                     }
                 } else {
                     $tmpl = $template->template;
                 }
                 $controller->view()->setTemplate(\Phire\Templates\Event\Template::parse($tmpl));
             }
         }
     } else {
         if ($application->isRegistered('phire-themes') && $controller instanceof \Phire\Search\Controller\IndexController && $controller->hasView()) {
             $theme = \Phire\Themes\Table\Themes::findBy(['active' => 1]);
             if (isset($theme->id)) {
                 $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder . '/';
                 if (file_exists($themePath . 'search.phtml') || file_exists($themePath . 'search.php')) {
                     $template = file_exists($themePath . 'search.phtml') ? 'search.phtml' : 'search.php';
                     $device = \Phire\Themes\Event\Theme::getDevice($controller->request()->getQuery('mobile'));
                     if (null !== $device && file_exists($themePath . $device . '/' . $template)) {
                         $template = $device . '/' . $template;
                     }
                     $controller->view()->setTemplate($themePath . $template);
                 }
             }
         }
     }
 }
Пример #20
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;
     }
 }
Пример #21
0
 public function bootstrap($autoloader = null)
 {
     parent::bootstrap($autoloader);
     $this->on('app.init', function ($application) {
         Record::setDb($application->services['database']);
     });
     if ($this->router->isCli()) {
         $this->on('app.route.pre', function () {
             echo PHP_EOL;
             echo '    Pop Tutorial CLI' . PHP_EOL;
             echo '    ----------------' . PHP_EOL . PHP_EOL;
         });
         $this->on('app.dispatch.post', function () {
             echo PHP_EOL;
             echo '    ----------------' . PHP_EOL;
             echo '    Complete!' . PHP_EOL . PHP_EOL;
         });
     }
 }
Пример #22
0
 /**
  * Save content to cache
  *
  * @param  Application $application
  * @return void
  */
 public static function save(Application $application)
 {
     if ($application->router()->getController() instanceof \Phire\Content\Controller\IndexController && $application->router()->getController()->response()->getCode() == 200 && empty($_SERVER['QUERY_STRING']) && !$_POST) {
         $sess = $application->services()->get('session');
         $uri = $application->router()->getController()->request()->getRequestUri();
         $cache = (new Model\Cache())->getCacheAdapter();
         $exclude = $application->module('phire-cache')['exclude'];
         if (null !== $cache && !isset($sess->user) && !in_array($uri, $exclude)) {
             $contentType = $application->router()->getController()->response()->getHeader('Content-Type');
             $body = $application->router()->getController()->response()->getBody();
             if ($contentType == 'text/html') {
                 $body .= PHP_EOL . PHP_EOL . '<!-- Generated by the phire-cache module on ' . date('M j, Y H:i:s') . '. //-->' . PHP_EOL . PHP_EOL;
             } else {
                 if (stripos($contentType, 'xml') !== false) {
                     $body .= PHP_EOL . PHP_EOL . '<!-- Generated by the phire-cache module on ' . date('M j, Y H:i:s') . '. -->' . PHP_EOL . PHP_EOL;
                 }
             }
             $cache->save($uri, ['content-type' => $contentType, 'body' => $body]);
         }
     }
 }
Пример #23
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;
                 }
             }
         }
     }
 }
Пример #24
0
 /**
  * Set the navigation objects
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function getNavigation(AbstractController $controller, Application $application)
 {
     if ($application->isRegistered('phire-categories') && $controller instanceof \Phire\Categories\Controller\IndexController || $application->isRegistered('phire-content') && $controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView()) {
         $navigation = Table\Navigation::findAll();
         foreach ($navigation->rows() as $nav) {
             $tree = (new Model\Navigation())->getTree($nav->id);
             $slug = Slug::filter($nav->title);
             $name = str_replace('-', '_', $slug);
             $topId = empty($nav->top_id) ? $slug : $nav->top_id;
             $config = [];
             if (!empty($nav->on_class)) {
                 $config['on'] = $nav->on_class;
             }
             if (!empty($nav->off_class)) {
                 $config['off'] = $nav->off_class;
             }
             $config['top'] = ['id' => $topId];
             if (!empty($nav->top_node)) {
                 $config['top']['node'] = $nav->top_node;
             }
             if (!empty($nav->top_class)) {
                 $config['top']['class'] = $nav->top_class;
             }
             if (!empty($nav->top_attributes)) {
                 $attribs = explode('" ', $nav->top_attributes);
                 $attribAry = [];
                 foreach ($attribs as $att) {
                     $val = explode('="', $att);
                     $attribAry[trim($val[0])] = trim($val[1]);
                 }
                 $config['top']['attributes'] = $attribAry;
             }
             if (!empty($nav->parent_node)) {
                 if (!isset($config['parent'])) {
                     $config['parent'] = [];
                 }
                 $config['parent']['node'] = $nav->parent_node;
             }
             if (!empty($nav->parent_id)) {
                 if (!isset($config['parent'])) {
                     $config['parent'] = [];
                 }
                 $config['parent']['id'] = $nav->parent_id;
             }
             if (!empty($nav->parent_class)) {
                 if (!isset($config['parent'])) {
                     $config['parent'] = [];
                 }
                 $config['parent']['class'] = $nav->parent_class;
             }
             if (!empty($nav->parent_attributes)) {
                 if (!isset($config['parent'])) {
                     $config['parent'] = [];
                 }
                 $attribs = explode('" ', $nav->parent_attributes);
                 $attribAry = [];
                 foreach ($attribs as $att) {
                     $val = explode('="', $att);
                     $attribAry[trim($val[0])] = trim($val[1]);
                 }
                 $config['parent']['attributes'] = $attribAry;
             }
             if (!empty($nav->child_node)) {
                 if (!isset($config['child'])) {
                     $config['child'] = [];
                 }
                 $config['child']['node'] = $nav->child_node;
             }
             if (!empty($nav->child_id)) {
                 if (!isset($config['child'])) {
                     $config['child'] = [];
                 }
                 $config['child']['id'] = $nav->child_id;
             }
             if (!empty($nav->child_class)) {
                 if (!isset($config['child'])) {
                     $config['child'] = [];
                 }
                 $config['child']['class'] = $nav->child_class;
             }
             if (!empty($nav->child_attributes)) {
                 if (!isset($config['child'])) {
                     $config['child'] = [];
                 }
                 $attribs = explode('" ', $nav->child_attributes);
                 $attribAry = [];
                 foreach ($attribs as $att) {
                     $val = explode('="', $att);
                     $attribAry[trim($val[0])] = trim($val[1]);
                 }
                 $config['child']['attributes'] = $attribAry;
             }
             if (!empty($nav->indent)) {
                 $config['indent'] = str_repeat(' ', (int) $nav->indent);
             }
             if ($application->isRegistered('phire-content')) {
                 $sess = $application->services()->get('session');
                 $roleId = isset($sess->user) && isset($sess->user->role_id) ? $sess->user->role_id : null;
                 self::checkTreeStatus($tree, $roleId);
             }
             $navObject = new Nav($tree, $config);
             $controller->view()->set($name, $navObject);
         }
     }
 }
Пример #25
0
 /**
  * Save dynamic field values to the EAV table
  *
  * @param  Application        $application
  * @param  Table\Fields       $field
  * @param  mixed              $value
  * @param  string             $model
  * @param  int                $modelId
  * @param  string             $uploadFolder
  * @param  string             $mediaLibrary
  * @return void
  */
 public static function save(Application $application, $field, $value, $model, $modelId, $uploadFolder = null, $mediaLibrary = null)
 {
     $dynamicFieldIds = [];
     $fieldId = $field->id;
     $key = 'field_' . $fieldId;
     if ($field->dynamic) {
         $dynamicFieldIds[] = $field->id;
     }
     $fv = Table\FieldValues::findById([$fieldId, $modelId, $model]);
     if ($field->type == 'file' && isset($_FILES[$key]) && !empty($_FILES[$key]['tmp_name']) && !empty($_FILES[$key]['name'])) {
         if (isset($fv->field_id)) {
             $oldFile = json_decode($fv->value);
             if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $oldFile)) {
                 unlink($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $oldFile);
             }
         }
         if (null !== $mediaLibrary && $application->isRegistered('phire-media')) {
             $library = new \Phire\Media\Model\MediaLibrary();
             $library->getByFolder($mediaLibrary);
             if (isset($library->id)) {
                 $settings = $library->getSettings();
                 $mediaUpload = new Upload($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder, $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
                 if ($mediaUpload->test($_FILES[$key])) {
                     $media = new \Phire\Media\Model\Media();
                     $media->save($_FILES[$key], ['library_id' => $library->id]);
                     $value = $media->file;
                     copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder . '/' . $media->file, $_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $media->file);
                 }
             }
         } else {
             $upload = new Upload($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/', $application->module('phire-fields')->config()['max_size'], $application->module('phire-fields')->config()['disallowed_types'], $application->module('phire-fields')->config()['allowed_types']);
             $value = $upload->upload($_FILES[$key]);
         }
     }
     if (!empty($value) && $value != ' ') {
         if ($field->encrypt && !is_array($value)) {
             $value = (new Mcrypt())->create($value);
         }
     }
     if (isset($fv->field_id)) {
         $oldValue = json_decode($fv->value, true);
         if (!empty($value) && $value != ' ') {
             if (strpos($field->type, '-history') !== false) {
                 if ($value != $oldValue) {
                     $ts = null !== $fv->timestamp ? $fv->timestamp : time() - 180;
                     if (null !== $fv->history) {
                         $history = json_decode($fv->history, true);
                         $history[$ts] = $oldValue;
                         if (count($history) > $application->module('phire-fields')->config()['history']) {
                             $history = array_slice($history, 1, $application->module('phire-fields')->config()['history'], true);
                         }
                         $fv->history = json_encode($history);
                     } else {
                         $fv->history = json_encode([$ts => $oldValue]);
                     }
                 }
             }
             if ($field->dynamic && is_array($oldValue) && isset($oldValue[0])) {
                 $oldValue[0] = $value;
                 $newValue = json_encode($oldValue);
             } else {
                 $newValue = json_encode($value);
             }
             $fv->value = $newValue;
             $fv->timestamp = time();
             $fv->save();
         } else {
             if (!$field->dynamic && $field->type != 'file') {
                 $fv->delete();
             } else {
                 if ($field->dynamic && $field->type != 'file' && is_array($oldValue) && isset($oldValue[0])) {
                     $oldValue[0] = '';
                     $newValue = json_encode($oldValue);
                     $fv->value = $newValue;
                     $fv->timestamp = time();
                     $fv->save();
                 }
             }
         }
     } else {
         if (!empty($value) && $value != ' ') {
             $fv = new Table\FieldValues(['field_id' => $fieldId, 'model_id' => $modelId, 'model' => $model, 'value' => $field->dynamic ? json_encode([$value]) : json_encode($value), 'timestamp' => time()]);
             $fv->save();
         }
     }
     foreach ($dynamicFieldIds as $fieldId) {
         $i = 1;
         $offset = 0;
         $fv = Table\FieldValues::findById([$fieldId, $modelId, $model]);
         $checkValue = json_decode($fv->value, true);
         if (is_array($checkValue) && isset($checkValue[0]) && is_array($checkValue[0])) {
             foreach ($checkValue as $k => $v) {
                 $fieldToCheck = $k > 0 ? 'field_' . $fieldId . '_' . $k : 'field_' . $fieldId;
                 if (!isset($_POST[$fieldToCheck])) {
                     unset($checkValue[$k]);
                 }
             }
             $checkValue = array_values($checkValue);
             $fv->value = json_encode($checkValue);
             $fv->timestamp = time();
             $fv->save();
         }
         while (isset($_POST['field_' . $fieldId . '_' . $i])) {
             if (!empty($_POST['field_' . $fieldId . '_' . $i]) && $_POST['field_' . $fieldId . '_' . $i] != ' ') {
                 $postValue = $_POST['field_' . $fieldId . '_' . $i];
                 if (isset($fv->field_id)) {
                     $value = json_decode($fv->value, true);
                     if (isset($value[$i - $offset])) {
                         $value[$i - $offset] = $postValue;
                     } else {
                         $value[] = $postValue;
                     }
                     $fv->value = json_encode($value);
                     $fv->timestamp = time();
                     $fv->save();
                 } else {
                     $fv = new Table\FieldValues(['field_id' => $fieldId, 'model_id' => $modelId, 'model' => $model, 'value' => json_encode([$postValue]), 'timestamp' => time()]);
                     $fv->save();
                 }
             } else {
                 if (isset($fv->field_id)) {
                     $value = json_decode($fv->value, true);
                     if (isset($value[$i])) {
                         unset($value[$i]);
                         $value = array_values($value);
                         $offset++;
                     }
                     $fv->value = json_encode($value);
                     $fv->timestamp = time();
                     $fv->save();
                 }
             }
             $i++;
         }
     }
     foreach ($dynamicFieldIds as $fieldId) {
         $i = 1;
         $offset = 0;
         $fv = Table\FieldValues::findById([$fieldId, $modelId, $model]);
         while (isset($_FILES['field_' . $fieldId . '_' . $i])) {
             if (!empty($_FILES['field_' . $fieldId . '_' . $i]['tmp_name'])) {
                 if (null !== $mediaLibrary && $application->isRegistered('phire-media')) {
                     $library = new \Phire\Media\Model\MediaLibrary();
                     $library->getByFolder($mediaLibrary);
                     if (isset($library->id)) {
                         $settings = $library->getSettings();
                         $mediaUpload = new Upload($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder, $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
                         if ($mediaUpload->test($_FILES['field_' . $fieldId . '_' . $i])) {
                             $media = new \Phire\Media\Model\Media();
                             $media->save($_FILES['field_' . $fieldId . '_' . $i], ['library_id' => $library->id]);
                             $postValue = $media->file;
                             copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder . '/' . $media->file, $_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $media->file);
                         }
                     }
                 } else {
                     $upload = new Upload($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/', $application->module('phire-fields')->config()['max_size'], $application->module('phire-fields')->config()['allowed_types']);
                     $postValue = $upload->upload($_FILES['field_' . $fieldId . '_' . $i]);
                 }
                 if (isset($fv->field_id)) {
                     $value = json_decode($fv->value, true);
                     if (isset($value[$i - $offset])) {
                         $value[$i - $offset] = $postValue;
                     } else {
                         $value[] = $postValue;
                     }
                     $fv->value = json_encode($value);
                     $fv->timestamp = time();
                     $fv->save();
                 } else {
                     $fv = new Table\FieldValues(['field_id' => $fieldId, 'model_id' => $modelId, 'model' => $model, 'value' => json_encode([$postValue]), 'timestamp' => time()]);
                     $fv->save();
                 }
             }
             $i++;
         }
     }
     foreach ($dynamicFieldIds as $fieldId) {
         $fv = Table\FieldValues::findById([$fieldId, $modelId, $model]);
         if (isset($fv->field_id)) {
             $value = json_decode($fv->value, true);
             if (is_array($value) && isset($value[0]) && is_array($value[0])) {
                 foreach ($value as $key => $val) {
                     if (is_array($val) && isset($val[0]) && (empty($val[0]) || $val[0] == ' ')) {
                         unset($val[0]);
                         $value[$key] = array_values($val);
                         if (count($value[$key]) == 0) {
                             unset($value[$key]);
                         }
                     }
                 }
                 $value = array_values($value);
             } else {
                 if (is_array($value) && isset($value[0]) && (empty($value[0]) || $value[0] == ' ')) {
                     unset($value[0]);
                     $value = array_values($value);
                 }
             }
             if (count($value) == 0) {
                 $fv->delete();
             } else {
                 $fv->value = json_encode($value);
                 $fv->save();
             }
         }
     }
 }
Пример #26
0
 /**
  * Constructor for the controller
  *
  * @param  Application $application
  * @param  Console     $console
  * @return ConsoleController
  */
 public function __construct(Application $application, Console $console)
 {
     $this->application = $application;
     $this->services = $application->services();
     $this->console = $console;
 }
Пример #27
0
 /**
  * Run the application.
  *
  * @param  boolean $exit
  * @return void
  */
 public function run($exit = true)
 {
     // If route is allowed for this method
     $this->router->addRoutes($this->routes[strtolower($_SERVER['REQUEST_METHOD'])]);
     $this->router->route();
     if ($this->router->hasRoute() && $this->isAllowed($this->router->getRouteMatch()->getOriginalRoute())) {
         parent::run($exit);
     } else {
         $this->trigger('app.error', ['exception' => new Exception('Error: That route was not ' . ($this->router->hasRoute() ? 'allowed' : 'found') . '.')]);
         $this->router->getRouteMatch()->noRouteFound((bool) $exit);
     }
 }
Пример #28
0
 /**
  * Delete dynamic field files
  *
  * @param  int         $fieldId
  * @param  int         $modelId
  * @param  string      $model
  * @param  boolean     $encrypt
  * @param  Application $app
  * @param  string      $uploadFolder
  * @param  string      $mediaLibrary
  * @return void
  */
 protected static function saveFiles($fieldId, $modelId, $model, $encrypt, $app, $uploadFolder, $mediaLibrary = null)
 {
     $field = T\Fields::findById($fieldId);
     if (isset($field->id)) {
         $time = time();
         $newValues = [];
         $oldValues = new Record();
         $oldValues->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name);
         $oldValues->findRecordsBy(['model_id' => $modelId, 'model' => $model], ['order' => 'id ASC']);
         $old = $oldValues->rows(false);
         foreach ($_FILES as $key => $file) {
             $id = substr_count($key, '_') == 2 ? substr($key, strrpos($key, '_') + 1) : 0;
             if (!empty($_FILES[$key]['tmp_name']) && !empty($_FILES[$key]['name'])) {
                 if (null !== $mediaLibrary) {
                     $library = new \Phire\Media\Model\MediaLibrary();
                     $library->getByFolder($mediaLibrary);
                     if (isset($library->id)) {
                         $settings = $library->getSettings();
                         $mediaUpload = new Upload($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder, $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
                         if ($mediaUpload->test($_FILES[$key])) {
                             $media = new \Phire\Media\Model\Media();
                             $media->save($_FILES[$key], ['library_id' => $library->id]);
                             $value = $media->file;
                             if ($encrypt) {
                                 $value = (new Mcrypt())->create($value);
                             }
                             if (isset($old[$id])) {
                                 $replaceValue = new Record();
                                 $replaceValue->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name);
                                 $replaceValue->findRecordById($old[$id]['id']);
                                 if (isset($replaceValue->id)) {
                                     $replaceValue->value = $value;
                                     $replaceValue->save();
                                     if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $old[$id]['value'])) {
                                         unlink($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $old[$id]['value']);
                                     }
                                     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder . '/' . $old[$id]['value'])) {
                                         $media = new \Phire\Media\Model\Media();
                                         $media->getByFile($old[$id]['value']);
                                         if (isset($media->id)) {
                                             $media->remove(['rm_media' => [$media->id]]);
                                         }
                                     }
                                 }
                             } else {
                                 $newValues[] = $value;
                             }
                             copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder . '/' . $media->file, $_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $media->file);
                         }
                     }
                 } else {
                     $upload = new Upload($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/', $app->module('phire-fields')->config()['max_size'], $app->module('phire-fields')->config()['disallowed_types'], $app->module('phire-fields')->config()['allowed_types']);
                     $value = $upload->upload($_FILES[$key]);
                     if ($encrypt) {
                         $value = (new Mcrypt())->create($value);
                     }
                     if (isset($old[$id])) {
                         $replaceValue = new Record();
                         $replaceValue->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name);
                         $replaceValue->findRecordById($old[$id]['id']);
                         if (isset($replaceValue->id)) {
                             $replaceValue->value = $value;
                             $replaceValue->save();
                             if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $old[$id]['value'])) {
                                 unlink($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $old[$id]['value']);
                             }
                         }
                     } else {
                         $newValues[] = $value;
                     }
                 }
             }
         }
         foreach ($newValues as $v) {
             if (!empty($v)) {
                 $fv = new Record(['model_id' => $modelId, 'model' => $model, 'timestamp' => $time, 'revision' => 0, 'value' => $v]);
                 $fv->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name);
                 $fv->save();
                 $fvs = new Record();
                 $fvs->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name);
                 $sql = $fvs->getSql();
                 $sql->update(['timestamp' => ':timestamp'])->where('model_id = :model_id')->where('model = :model');
                 $fvs->execute($sql, ['timestamp' => $time, 'model_id' => $modelId, 'model' => $model]);
             }
         }
     }
 }
Пример #29
0
 /**
  * Determine if the module has been registered with an application object
  *
  * @return boolean
  */
 public function isRegistered()
 {
     return null !== $this->application && null !== $this->application->modules() && $this->application->modules()->hasModule($this);
 }
Пример #30
0
 /**
  * Get all category values for the form object
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function parseCategories(AbstractController $controller, Application $application)
 {
     if ($controller->hasView() && ($controller instanceof \Phire\Categories\Controller\IndexController || $controller instanceof \Phire\Content\Controller\IndexController)) {
         $body = $controller->response()->getBody();
         $category = new Model\Category();
         $category->show_total = $application->module('phire-categories')['show_total'];
         $category->filters = $application->module('phire-categories')['filters'];
         $category->datetime_formats = $application->module('phire-categories')['datetime_formats'];
         $catIds = self::parseCategoryIds($body);
         $catParentIds = self::parseParentCategoryIds($body);
         if (count($catIds) > 0) {
             foreach ($catIds as $key => $value) {
                 $category->getById($value['id']);
                 $categoryName = 'category_' . $value['id'];
                 if (isset($value['limit']) && $value['limit'] > 0 && $category->hasPages($value['limit'])) {
                     $limit = $value['limit'];
                     $pages = null;
                 } else {
                     if ($category->pagination > 0 && $category->hasPages($category->pagination)) {
                         $limit = $category->pagination;
                         $pages = new \Pop\Paginator\Paginator($category->getCount(), $limit);
                         $pages->useInput(true);
                     } else {
                         $limit = null;
                         $pages = null;
                     }
                 }
                 if (null !== $pages) {
                     $controller->view()->pages = $pages;
                 }
                 $controller->view()->{$categoryName} = $category->getItems($limit, $controller->request()->getQuery('page'));
             }
         }
         if (count($catParentIds) > 0) {
             foreach ($catParentIds as $key => $value) {
                 if (isset($value['limit']) && $value['limit'] > 0) {
                     $limit = $value['limit'];
                     $categoryName = 'categories_' . $value['id'] . '_' . $limit;
                 } else {
                     $limit = null;
                     $categoryName = 'categories_' . $value['id'];
                 }
                 $controller->view()->{$categoryName} = $category->getCategoryChildren($value['id'], $limit);
             }
         }
         $controller->view()->setTemplate($body);
         $body = $controller->view()->render();
         $controller->response()->setBody($body);
     }
 }