/** * 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(); } }
/** * 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); } } }
/** * Parse any media group placeholders * * @param AbstractController $controller * @param Application $application * @return void */ public static function parseMedia(AbstractController $controller, Application $application) { if ($controller->hasView() && ($controller instanceof \Phire\Categories\Controller\IndexController || $controller instanceof \Phire\Content\Controller\IndexController)) { $data = $controller->view()->getData(); foreach ($data as $key => $value) { if (is_string($value)) { $subIds = self::parseLibraryIds($value); if (count($subIds) > 0) { $media = new Model\Media(); foreach ($subIds as $sid) { $view = new \Pop\View\View($value, ['media_' . $sid => $media->getAllByLibraryId($sid)]); $controller->view()->{$key} = $view->render(); } } } } $body = $controller->response()->getBody(); $ids = self::parseLibraryIds($body); if (count($ids) > 0) { $media = new Model\Media(); foreach ($ids as $id) { $key = 'media_' . $id; $controller->view()->{$key} = $media->getAllByLibraryId($id); } } } }
/** * Parse view object * * @param AbstractController $controller * @param Application $application * @return void */ public static function parseSitemap(AbstractController $controller, Application $application) { if ($controller->hasView() && $controller instanceof \Phire\Content\Controller\IndexController) { $body = $controller->response()->getBody(); if (strpos($body, '[{sitemap') !== false) { $sitemaps = []; preg_match_all('/\\[\\{sitemap.*\\}\\]/', $body, $sitemaps); if (isset($sitemaps[0]) && isset($sitemaps[0][0])) { foreach ($sitemaps[0] as $sitemap) { $node = 'nav'; $tid = substr($sitemap, strpos($sitemap, 'sitemap') + 7); $tid = str_replace('}]', '', $tid); if ($tid != '') { if (substr($tid, 0, 1) == '_') { $tid = substr($tid, 1); } if (strpos($tid, '_') !== false) { $tidAry = explode('_', $tid); $node = $tidAry[0]; $tid = $tidAry[1]; } else { $node = $tid; $tid = null; } } else { $tid = null; } $siteMapObject = (new Model\Sitemap())->getSitemapObject($node, $tid); $body = str_replace($sitemap, $siteMapObject, $body); } } $controller->response()->setBody($body); } } }
/** * 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'); } }
/** * Parse social navigation * * @param AbstractController $controller * @param Application $application * @return void */ public static function parse(AbstractController $controller, Application $application) { if ($controller->hasView() && ($controller instanceof \Phire\Content\Controller\IndexController || $controller instanceof \Phire\Categories\Controller\IndexController)) { $body = $controller->response()->getBody(); if (strpos($body, '[{social_nav') !== false) { $social = new Model\Social(); $body = str_replace(['[{social_nav}]', '[{social_nav_styles}]'], [$social->buildNav(), $social->getStyles()], $body); $controller->response()->setBody($body); } } }
/** * Parse SEO * * @param AbstractController $controller * @param Application $application * @return void */ public static function parse(AbstractController $controller, Application $application) { if ($controller->hasView() && ($controller instanceof \Phire\Content\Controller\IndexController || $controller instanceof \Phire\Categories\Controller\IndexController)) { $seo = new Model\Seo(); $body = $controller->response()->getBody(); if (strpos($body, '[{seo_meta_tags}]') !== false) { $body = str_replace('[{seo_meta_tags}]', $seo->buildMetaTags($controller->view()->description, $controller->view()->keywords), $body); } if (!empty($seo->tracking)) { $body = str_replace('</head>', $seo->tracking . PHP_EOL . PHP_EOL . '</head>', $body); } $controller->response()->setBody($body); } }
/** * 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); } } } } }
/** * Parse view object * * @param AbstractController $controller * @param Application $application * @return void */ public static function parseViews(AbstractController $controller, Application $application) { if (!$controller instanceof \Phire\Content\Controller\ContentController && !$controller instanceof \Phire\Templates\Controller\IndexController && $controller->hasView()) { $body = $controller->response()->getBody(); if (strpos($body, '[{view_') !== false) { // Parse any view placeholders $groupIds = []; $singleIds = []; $modelId = null; $views = []; $viewModel = new Model\View(['pagination' => $controller->config()->pagination]); preg_match_all('/\\[\\{view.*\\}\\]/', $body, $views); if (isset($views[0]) && isset($views[0][0])) { foreach ($views[0] as $view) { $id = substr($view, strpos($view, 'view_') + 5); $id = str_replace('}]', '', $id); if (strpos($id, '_') !== false) { $idAry = explode('_', $id); if (!empty($idAry[1])) { $modelId = $idAry[1]; } else { if (!empty($controller->view()->id)) { $modelId = $controller->view()->id; } } $singleIds[] = ['view_id' => $idAry[0], 'model_id' => $modelId]; } else { $groupIds[] = $id; } } } if (count($groupIds) > 0) { foreach ($groupIds as $id) { $body = str_replace('[{view_' . $id . '}]', $viewModel->renderPages($id) . PHP_EOL . $viewModel->render($id), $body); } } if (count($singleIds) > 0) { foreach ($singleIds as $id) { if (null !== $id['model_id']) { $body = str_replace('[{view_' . $id['view_id'] . '_' . $id['model_id'] . '}]', $viewModel->renderSingle($id['view_id'], $id['model_id']), $body); $body = str_replace('[{view_' . $id['view_id'] . '_}]', $viewModel->renderSingle($id['view_id'], $id['model_id']), $body); } } } $controller->response()->setBody($body); } } }
/** * Parse maps navigation * * @param AbstractController $controller * @param Application $application * @return void */ public static function parse(AbstractController $controller, Application $application) { if ($controller->hasView() && ($controller instanceof \Phire\Content\Controller\IndexController || $controller instanceof \Phire\Categories\Controller\IndexController)) { $body = $controller->response()->getBody(); if (strpos($body, '[{map_') !== false) { $ids = self::parseMapIds($body); if (count($ids) > 0) { $map = new Model\Map(); foreach ($ids as $id) { $body = str_replace('[{map_' . $id . '}]', $map->getMap($id), $body); } } $controller->response()->setBody($body); } } }
/** * 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); } } }
/** * Save feed relationships * * @param AbstractController $controller * @param Application $application * @return void */ public static function save(AbstractController $controller, Application $application) { if ($_POST && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Pop\Form\Form) { $id = $controller->view()->id; $feed = $controller->view()->form->feed; $type = $controller->view()->form->feed_type; if (null !== $feed && null !== $type) { if ($feed == '1') { $f = Table\Feed::findById([$id, $type]); if (!isset($f->id)) { $feed = new Table\Feed(['id' => $id, 'type' => $type]); $feed->save(); } } else { if ($feed == '0') { $f = Table\Feed::findById([$id, $type]); if (isset($f->id)) { $f->delete(); } } } } } }
/** * Save category relationships * * @param AbstractController $controller * @param Application $application * @return void */ public static function save(AbstractController $controller, Application $application) { $type = null; $contentId = null; if ($_POST && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form instanceof \Pop\Form\Form) { $categories = $controller->view()->form->categories; $type = $controller->view()->form->category_type; $contentId = $controller->view()->id; // Clear categories if (null !== $type && null !== $contentId) { if (!is_array($contentId)) { $contentId = [$contentId]; } foreach ($contentId as $id) { $itemId = $type == 'media' ? 'media_id' : 'content_id'; $c2c = new Table\CategoryItems(); $c2c->delete([$itemId => $id]); } if (is_array($categories) && count($categories) > 0) { foreach ($categories as $category) { foreach ($contentId as $id) { if ($type == 'media') { $fields = ['category_id' => $category, 'content_id' => null, 'media_id' => $id, 'order' => (int) $_POST['category_order_' . $category]]; } else { $fields = ['category_id' => $category, 'content_id' => $id, 'media_id' => null, 'order' => (int) $_POST['category_order_' . $category]]; } $catItem = new Table\CategoryItems($fields); $catItem->save(); } } } } } }
/** * 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); } } }
/** * Save dynamic field values * * @param AbstractController $controller * @param Application $application * @return void */ public static function save(AbstractController $controller, Application $application) { if ($_POST && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Pop\Form\Form) { $fields = $controller->view()->form->getFields(); $modelId = $controller->view()->id; $model = str_replace('Form', 'Model', get_class($controller->view()->form)); $uploadFolder = BASE_PATH . CONTENT_PATH . '/files'; $mediaLibrary = $application->module('phire-fields')->config()['media_library']; // Remove any files foreach ($_POST as $key => $value) { if (substr($key, 0, 14) == 'rm_field_file_' && isset($value[0])) { $fieldId = substr($key, 14); if (strpos($fieldId, '_') !== false) { $fieldId = substr($fieldId, 0, strpos($fieldId, '_')); } $field = Table\Fields::findById($fieldId); if (isset($field->id)) { if ($field->storage == 'eav') { $fv = Table\FieldValues::findById([$fieldId, $modelId, $model]); if (isset($fv->field_id)) { $oldValue = json_decode($fv->value); if (is_array($oldValue)) { if (array_search($value[0], $oldValue) !== false) { $k = array_search($value[0], $oldValue); if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $oldValue[$k])) { unlink($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $oldValue[$k]); if (null !== $mediaLibrary && $application->isRegistered('phire-media')) { $media = new \Phire\Media\Model\Media(); $media->getByFile($oldValue[$k]); if (isset($media->id) && $media->library_folder == $mediaLibrary) { $media->remove(['rm_media' => [$media->id]]); } } } unset($oldValue[$k]); } if (count($oldValue) == 0) { $fv->delete(); } else { $oldValue = array_values($oldValue); $fv->value = json_encode($oldValue); $fv->save(); } } else { if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $oldValue)) { unlink($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $oldValue); if (null !== $mediaLibrary && $application->isRegistered('phire-media')) { $media = new \Phire\Media\Model\Media(); $media->getByFile($oldValue); if (isset($media->id) && $media->library_folder == $mediaLibrary) { $media->remove(['rm_media' => [$media->id]]); } } } $fv->delete(); } } } else { $fv = new Record(); $fv->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name); $fv->findRecordsBy(['model_id' => $modelId, 'model' => $model, 'value' => $value[0]]); if (isset($fv->model_id)) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $value[0])) { unlink($_SERVER['DOCUMENT_ROOT'] . $uploadFolder . '/' . $value[0]); if (null !== $mediaLibrary && $application->isRegistered('phire-media')) { $media = new \Phire\Media\Model\Media(); $media->getByFile($value[0]); if (isset($media->id) && $media->library_folder == $mediaLibrary) { $media->remove(['rm_media' => [$media->id]]); } } } $fv = new Record(); $fv->setPrefix(DB_PREFIX)->setPrimaryKeys(['id'])->setTable('field_' . $field->name); $fv->delete(['model_id' => $modelId, 'model' => $model, 'value' => $value[0]]); } } } } } // Save field values foreach ($fields as $key => $value) { if (substr($key, 0, 6) == 'field_' && substr_count($key, '_') == 1) { $fieldId = (int) substr($key, 6); $field = Table\Fields::findById($fieldId); if (isset($field->id)) { if ($field->storage == 'eav') { Value\Eav::save($application, $field, $value, $model, $modelId, $uploadFolder, $mediaLibrary); } else { Value\Table::save($application, $field, $value, $model, $modelId, $uploadFolder, $mediaLibrary); } } } } } }
/** * Init category nav and categories * * @param AbstractController $controller * @param Application $application * @return void */ public static function setTemplate(AbstractController $controller, Application $application) { if ($controller->hasView() && $controller instanceof \Phire\Members\Controller\IndexController) { $template = basename($controller->view()->getTemplate()->getTemplate()); $memberName = $controller->view()->memberName; $memberUri = $controller->view()->memberUri; $templateName = null; if ($application->isRegistered('phire-templates')) { switch ($template) { case 'login.phtml': $templateName = $memberName . ' Login'; break; case 'forgot.phtml': $templateName = $memberName . ' Forgot'; break; case 'index.phtml': $templateName = $memberName . ' Index'; break; case 'profile.phtml': $templateName = $memberName . ' Profile'; break; case 'register.phtml': $templateName = $memberName . ' Register'; break; case 'unsubscribe.phtml': $templateName = $memberName . ' Unsubscribe'; break; case 'verify.phtml': $templateName = $memberName . ' Verify'; break; } if (null !== $templateName) { $tmpl = \Phire\Templates\Table\Templates::findBy(['name' => $templateName]); if (isset($tmpl->id)) { $controller->view()->setTemplate($tmpl->template); } } } else { if ($application->isRegistered('phire-themes')) { switch ($template) { case 'login.phtml': $templateName = $memberUri . '/login'; break; case 'forgot.phtml': $templateName = $memberUri . '/forgot'; break; case 'index.phtml': $templateName = $memberUri . '/index'; break; case 'profile.phtml': $templateName = $memberUri . '/profile'; break; case 'register.phtml': $templateName = $memberUri . '/register'; break; case 'unsubscribe.phtml': $templateName = $memberUri . '/unsubscribe'; break; case 'verify.phtml': $templateName = $memberUri . '/verify'; break; } if (null !== $templateName) { $theme = \Phire\Themes\Table\Themes::findBy(['active' => 1]); if (isset($theme->id)) { $templateName = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder . $templateName; $tmpl = null; if (file_exists($templateName . '.phtml')) { $tmpl = $templateName . '.phtml'; } else { if (file_exists($templateName . '.php')) { $tmpl = $templateName . '.php'; } } if (null !== $tmpl) { $controller->view()->setTemplate($tmpl); } } } } } } }
/** * 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); } } } } }
/** * Parse the body * * @param AbstractController $controller * @param Application $application * @return void */ public static function parseBody(AbstractController $controller, Application $application) { if ($controller->hasView() && ($application->isRegistered('phire-categories') && $controller instanceof \Phire\Categories\Controller\IndexController || $application->isRegistered('phire-content') && $controller instanceof \Phire\Content\Controller\IndexController)) { $controller->response()->setBody(self::parse($controller->response()->getBody())); } }
/** * 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); } } }
/** * Save tag relationships * * @param AbstractController $controller * @param Application $application * @return void */ public static function save(AbstractController $controller, Application $application) { $contentId = null; if ($_POST && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Pop\Form\Form) { $tags = $controller->view()->form->content_tags; $contentId = $controller->view()->id; if (null !== $contentId) { $c2t = new Table\TagItems(); $c2t->delete(['content_id' => $contentId]); } if (!empty($tags)) { $tags = explode(',', $tags); foreach ($tags as $tag) { $tag = trim($tag); $t = Table\Tags::findBy(['title' => $tag]); if (!isset($t->id)) { $t = new Table\Tags(['title' => $tag, 'slug' => Slug::filter($tag)]); $t->save(); } $c2t = new Table\TagItems(['content_id' => $contentId, 'tag_id' => $t->id]); $c2t->save(); } } } }