Exemplo n.º 1
0
 /**
  * Set the tag 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\Content\Controller\IndexController && $controller->hasView() && $controller->view()->isStream()) {
         if (null !== $controller->view()->tag_title) {
             $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Tag ' . $controller->view()->tag_title]);
             if (!isset($template->id)) {
                 $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Tag']);
             }
         } else {
             $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Tag']);
         }
         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\Content\Controller\IndexController && $controller->hasView() && $controller->view()->isFile()) {
             $theme = \Phire\Themes\Table\Themes::findBy(['active' => 1]);
             if (isset($theme->id)) {
                 $template = null;
                 $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder . '/';
                 if (null !== $controller->view()->tag_slug) {
                     $tagSlug = 'tag-' . str_replace('/', '-', $controller->view()->tag_slug);
                     if (file_exists($themePath . $tagSlug . '.phtml') || file_exists($themePath . $tagSlug . '.php')) {
                         $template = file_exists($themePath . $tagSlug . '.phtml') ? $tagSlug . '.phtml' : $tagSlug . '.php';
                     } else {
                         if (file_exists($themePath . 'tag.phtml') || file_exists($themePath . 'tag.php')) {
                             $template = file_exists($themePath . 'tag.phtml') ? 'tag.phtml' : 'tag.php';
                         }
                     }
                 } else {
                     if (file_exists($themePath . 'tag.phtml') || file_exists($themePath . 'tag.php')) {
                         $template = file_exists($themePath . 'tag.phtml') ? 'tag.phtml' : 'tag.php';
                     }
                 }
                 if (null !== $template) {
                     $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);
                 }
             }
         }
     }
 }
Exemplo n.º 2
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);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Get update info
  *
  * @param  boolean $live
  * @return \ArrayObject
  */
 public function getUpdates($live = true)
 {
     $themeUpdates = [];
     if ($live) {
         $headers = ['Authorization: ' . base64_encode('phire-updater-' . time()), 'User-Agent: ' . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0')];
         $themes = Table\Themes::findAll();
         if ($themes->hasRows()) {
             foreach ($themes->rows() as $theme) {
                 $name = $theme->folder;
                 $version = substr($name, strrpos($name, '-') + 1);
                 if (is_numeric($version)) {
                     $name = substr($name, 0, strrpos($name, '-'));
                 }
                 $curl = new Curl('http://updates.phirecms.org/latest/' . $name . '?theme=1', [CURLOPT_HTTPHEADER => $headers]);
                 $curl->send();
                 if ($curl->getCode() == 200) {
                     $json = json_decode($curl->getBody(), true);
                     $themeUpdates[$theme->name] = $json['version'];
                 }
             }
         }
     }
     return $themeUpdates;
 }
Exemplo n.º 4
0
 /**
  * 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);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
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);
                 }
             }
         }
     }
 }