Example #1
0
 /**
  * Set the category 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\Categories\Controller\IndexController && $controller->hasView()) {
         if (null !== $controller->view()->category_title) {
             $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Category ' . $controller->view()->category_title]);
             if (!isset($template->id)) {
                 $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Category']);
             }
         } else {
             $template = \Phire\Templates\Table\Templates::findBy(['name' => 'Category']);
         }
         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\Categories\Controller\IndexController && $controller->hasView()) {
             $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()->category_slug) {
                     $catSlug = 'category-' . str_replace('/', '-', $controller->view()->category_slug);
                     if (file_exists($themePath . $catSlug . '.phtml') || file_exists($themePath . $catSlug . '.php')) {
                         $template = file_exists($themePath . $catSlug . '.phtml') ? $catSlug . '.phtml' : $catSlug . '.php';
                     } else {
                         if (file_exists($themePath . 'category.phtml') || file_exists($themePath . 'category.php')) {
                             $template = file_exists($themePath . 'category.phtml') ? 'category.phtml' : 'category.php';
                         }
                     }
                 } else {
                     if (file_exists($themePath . 'category.phtml') || file_exists($themePath . 'category.php')) {
                         $template = file_exists($themePath . 'category.phtml') ? 'category.phtml' : 'category.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);
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Template
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name) {
         // Check for dupe device
         if ($this->template_parent_id != '----' && $this->device != '----') {
             $parent = Table\Templates::findBy(['id' => (int) $this->template_parent_id, 'device' => $this->device]);
             $children = Table\Templates::findBy(['parent_id' => (int) $this->template_parent_id, 'device' => $this->device, 'id !=' => $this->id]);
             if ($parent->hasRows() || $children->hasRows()) {
                 $this->getElement('device')->addValidator(new Validator\NotEqual($this->device, 'That device has already been added for this template set.'));
             }
         }
     }
     return $this;
 }
Example #3
0
 /**
  * Get count of templates
  *
  * @return int
  */
 public function getCount()
 {
     return Table\Templates::findAll()->count();
 }
Example #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);
                         }
                     }
                 }
             }
         }
     }
 }
Example #5
0
 /**
  * Parse the template
  *
  * @param  string $template
  * @param  mixed  $id
  * @param  mixed  $pid
  * @return boolean
  */
 public static function parse($template, $id = null, $pid = null)
 {
     // Parse any date placeholders
     $dates = [];
     preg_match_all('/\\[\\{date.*\\}\\]/', $template, $dates);
     if (isset($dates[0]) && isset($dates[0][0])) {
         foreach ($dates[0] as $date) {
             $pattern = str_replace('}]', '', substr($date, strpos($date, '_') + 1));
             $template = str_replace($date, date($pattern), $template);
         }
     }
     // Parse any template placeholders
     $templates = [];
     preg_match_all('/\\[\\{template_.*\\}\\]/', $template, $templates);
     if (isset($templates[0]) && isset($templates[0][0])) {
         foreach ($templates[0] as $tmpl) {
             $t = str_replace('}]', '', substr($tmpl, strpos($tmpl, '_') + 1));
             if ($t != $id && $t != $pid) {
                 $newTemplate = is_numeric($t) ? Table\Templates::findById($t) : Table\Templates::findBy(['name' => $t]);
                 if (isset($newTemplate->id)) {
                     $t = self::parse($newTemplate->template, $newTemplate->id, $id);
                     $template = str_replace($tmpl, $t, $template);
                 } else {
                     $template = str_replace($tmpl, '', $template);
                 }
             } else {
                 $template = str_replace($tmpl, '', $template);
             }
         }
     }
     // Parse any session placeholders
     $open = [];
     $close = [];
     $merge = [];
     $sess = [];
     preg_match_all('/\\[\\{sess\\}\\]/msi', $template, $open, PREG_OFFSET_CAPTURE);
     preg_match_all('/\\[\\{\\/sess\\}\\]/msi', $template, $close, PREG_OFFSET_CAPTURE);
     // If matches are found, format and merge the results.
     if (isset($open[0][0]) && isset($close[0][0])) {
         foreach ($open[0] as $key => $value) {
             $merge[] = [$open[0][$key][0] => $open[0][$key][1], $close[0][$key][0] => $close[0][$key][1]];
         }
     }
     foreach ($merge as $match) {
         $sess[] = substr($template, $match['[{sess}]'], $match['[{/sess}]'] - $match['[{sess}]'] + 9);
     }
     if (count($sess) > 0) {
         $session = Session::getInstance();
         foreach ($sess as $s) {
             $sessString = str_replace(['[{sess}]', '[{/sess}]'], ['', ''], $s);
             $isSess = null;
             $noSess = null;
             if (strpos($sessString, '[{or}]') !== false) {
                 $sessValues = explode('[{or}]', $sessString);
                 if (isset($sessValues[0])) {
                     $isSess = $sessValues[0];
                 }
                 if (isset($sessValues[1])) {
                     $noSess = $sessValues[1];
                 }
             } else {
                 $isSess = $sessString;
             }
             if (null !== $isSess) {
                 if (!isset($session->user)) {
                     $template = str_replace($s, $noSess, $template);
                 } else {
                     $newSess = $isSess;
                     foreach ($_SESSION as $sessKey => $sessValue) {
                         if ((is_array($sessValue) || $sessValue instanceof \ArrayObject) && strpos($template, '[{' . $sessKey . '->') !== false) {
                             foreach ($sessValue as $sessK => $sessV) {
                                 if (!is_array($sessV)) {
                                     $newSess = str_replace('[{' . $sessKey . '->' . $sessK . '}]', $sessV, $newSess);
                                 }
                             }
                         } else {
                             if (!is_array($sessValue) && !$sessValue instanceof \ArrayObject && strpos($template, '[{' . $sessKey) !== false) {
                                 $newSess = str_replace('[{' . $sessKey . '}]', $sessValue, $newSess);
                             }
                         }
                     }
                     if ($newSess != $isSess) {
                         $template = str_replace('[{sess}]' . $sessString . '[{/sess}]', $newSess, $template);
                     } else {
                         $template = str_replace($s, $noSess, $template);
                     }
                 }
             } else {
                 $template = str_replace($s, '', $template);
             }
         }
     }
     return $template;
 }
 /**
  * Json action method
  *
  * @param  int $id
  * @param  int $marked
  * @return void
  */
 public function json($id, $marked)
 {
     $json = [];
     $template = Table\Templates::findById($id);
     if (isset($template->id) && null !== $template->history) {
         $history = json_decode($template->history, true);
         if (isset($history[$marked])) {
             $json['value'] = $history[$marked];
         }
     }
     $this->response->setBody(json_encode($json, JSON_PRETTY_PRINT));
     $this->send(200, ['Content-Type' => 'application/json']);
 }