/** * 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]); } }
/** * 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); } } }
/** * Constructor for the controller * * @param Application $application * @param Request $request * @param Response $response * @return AbstractController */ public function __construct(Application $application, Request $request, Response $response) { $this->application = $application; $this->services = $application->services(); $this->request = $request; $this->response = $response; $this->sess = $this->services['session']; $this->viewPath = __DIR__ . '/../../view'; }
/** * 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(); } }
/** * Constructor for the controller * * @param Application $application * @param Request $request * @param Response $response * @return AbstractController */ public function __construct(Application $application, Request $request, Response $response) { $this->application = $application; $this->services = $application->services(); $this->request = $request; $this->response = $response; $this->sess = $this->services['session']; $this->viewPath = __DIR__ . '/../../view'; if ($this->services->isAvailable('database')) { $this->config = (new \Phire\Model\Config())->getAll(); } }
/** * 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; }
/** * 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]); } } }
/** * 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); } } }
/** * 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; }
/** * Initialize page editor * * @param AbstractController $controller * @param Application $application * @return void */ public static function initPageEditor(AbstractController $controller, Application $application) { if ($controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView() && $controller->response()->getCode() == 200) { $sess = $application->services()->get('session'); $acl = $application->services()->get('acl'); if (isset($sess->user) && $acl->isAllowed($sess->user->role, 'content', 'in-edit') && $acl->isAllowed($sess->user->role, 'content', 'edit')) { $body = $controller->response()->getBody(); $head = substr($body, strpos($body, '<head>')); $head = substr($head, 0, strpos($head, '</head>') + 7); $newHead = $head; $assets = ' <link type="text/css" rel="stylesheet" href="' . BASE_PATH . CONTENT_PATH . '/assets/' . $controller->config()->system_theme . '/css/font-awesome.min.css" />' . PHP_EOL; $assets .= ' <link type="text/css" rel="stylesheet" href="' . BASE_PATH . CONTENT_PATH . '/assets/phire-content/css/phire.content.edit.css" />' . PHP_EOL . PHP_EOL; if (strpos($newHead, 'jax.4.0.0.min.js') === false && strpos($newHead, 'jax.4.0.0.js') === false) { if (strpos($newHead, '<script') !== false) { $newHead1 = substr($newHead, 0, strpos($newHead, '<script')); $newHead2 = substr($newHead, strpos($newHead, '<script')); $newHead1 .= '<script type="text/javascript" src="' . BASE_PATH . CONTENT_PATH . '/assets/phire/js/jax.4.0.0.min.js"></script>' . PHP_EOL; $newHead1 .= ' <script type="text/javascript">' . PHP_EOL; $newHead1 .= ' jax.noConflict();' . PHP_EOL; $newHead1 .= ' </script>' . PHP_EOL . ' '; $newHead = $newHead1 . $newHead2; } else { $assets .= ' <script type="text/javascript" src="' . BASE_PATH . CONTENT_PATH . '/assets/phire/js/jax.4.0.0.min.js"></script>' . PHP_EOL; $assets .= ' <script type="text/javascript">' . PHP_EOL; $assets .= ' jax.noConflict();' . PHP_EOL; $assets .= ' </script>' . PHP_EOL; } } $assets .= ' <script type="text/javascript" src="' . BASE_PATH . CONTENT_PATH . '/assets/phire/js/phire.js"></script>' . PHP_EOL; $assets .= ' <script type="text/javascript" src="' . BASE_PATH . CONTENT_PATH . '/assets/phire-content/js/phire.content.edit.js"></script>' . PHP_EOL . PHP_EOL; $assets .= '</head>'; $systemUri = BASE_PATH . APP_URI; if ($systemUri == '') { $systemUri = '/'; } $contentUri = BASE_PATH . APP_URI . '/content/edit/' . $controller->view()->type_id . '/' . $controller->view()->id . '?in_edit=1'; $nav = PHP_EOL . '<nav id="phire-in-edit-nav">' . PHP_EOL; $nav .= ' <a href="' . $contentUri . '" title="Edit Page" onclick="phire.launchPageEditor(this.href); return false;"><span>Edit</span></a>' . PHP_EOL; $nav .= ' <a href="' . $systemUri . '" title="Dashboard"><span>Dashboard</span></a>' . PHP_EOL; $nav .= '</nav>' . PHP_EOL . PHP_EOL; $nav .= '</body>'; $newHead = str_replace('</head>', $assets, $newHead); $body = str_replace($head, $newHead, $body); $body = str_replace('</body>', $nav, $body); $controller->response()->setBody($body); } } }