Exemple #1
0
 /**
  * Get the correct view for the form
  *
  * @param $view
  * @return View|null|Template
  */
 public function getView($view)
 {
     if (Template::exists('Form/' . $view)) {
         return Template::getAdminTemplate('Form/' . $view);
     }
     return new View($view, B8_PATH . 'Form/View/');
 }
 public function render($item)
 {
     if (!is_null($item)) {
         $parts = explode('\\', get_class($item));
         $class = array_pop($parts);
         $view = Template::getAdminTemplate('Search/Type/' . $class);
         $view->result = $item;
         return $view->render();
     }
 }
Exemple #3
0
 /**
  * Handle the requested action
  *
  * @param $action
  * @param $params
  * @return mixed
  */
 public function handleAction($action, $params)
 {
     try {
         $thisClass = explode('\\', get_class($this));
         $module = $thisClass[1];
         $this->view = Template::getAdminTemplate($this->className . '/' . $action, $module);
         $this->view->currentUser = $this->currentUser;
     } catch (\Exception $ex) {
         $error = '<div class="alert alert-danger">You have not created a view for: ';
         $error .= $this->className . '/' . $action . '</div>';
         $this->view = new Template($error);
     }
     // Set up GlobalMessage:
     if (!empty($this->view)) {
         if (!empty($_SESSION['GlobalMessage']['success'])) {
             $this->view->GlobalMessage()->success = $_SESSION['GlobalMessage']['success'];
             unset($_SESSION['GlobalMessage']['success']);
         }
         if (!empty($_SESSION['GlobalMessage']['error'])) {
             $this->view->GlobalMessage()->error = $_SESSION['GlobalMessage']['error'];
             unset($_SESSION['GlobalMessage']['error']);
         }
         if (!empty($_SESSION['GlobalMessage']['info'])) {
             $this->view->GlobalMessage()->info = $_SESSION['GlobalMessage']['info'];
             unset($_SESSION['GlobalMessage']['info']);
         }
     }
     $output = parent::handleAction($action, $params);
     if (empty($output) && !empty($this->view)) {
         $output = $this->view->render();
     }
     $this->response->setContent($output);
     if ($this->response->hasLayout()) {
         $this->layout->user = $_SESSION['user'];
         $this->layout->content = $this->response->getContent();
         $this->response->setContent($this->layout->render());
     }
     return $this->response;
 }
Exemple #4
0
 protected function loadTimeline()
 {
     $logStore = Store::get('Log');
     $items = $logStore->getTimeline();
     $timeline = [];
     $lastDate = new \DateTime('1970-01-01');
     foreach ($items as $item) {
         if ($item->getLogDate()->format('Y-m-d') != $lastDate->format('Y-m-d')) {
             $date = $item->getLogDate()->format('M j Y');
             $timeline[] = "<li class=\"time-label\">\n                                    <span class=\"bg-blue\">\n                                        {$date}\n                                    </span>\n                                </li>";
             $lastDate = $item->getLogDate();
         }
         $keyDate = $item->getLogDate()->format('Y-m-d');
         $key = md5($keyDate . $item->getScope() . '.' . $item->getType() . '.' . $item->getScopeId());
         if (array_key_exists($key, $timeline)) {
             continue;
         }
         $template = 'Dashboard/Timeline/' . $item->getScope();
         if (!Template::exists($template)) {
             $template = 'Dashboard/Timeline/default';
         }
         $template = Template::getAdminTemplate($template);
         $template->icon = 'info';
         $template->item = $item;
         $template->decoded = @json_decode($item->getMessage(), true);
         switch ($item->getType()) {
             case 2:
                 $template->color = 'green';
                 $template->verb = 'created';
                 break;
             case 4:
                 $template->color = 'red';
                 $template->verb = 'deleted';
                 break;
             case 8:
                 $template->color = 'blue';
                 $template->verb = 'edited';
                 break;
             case 128:
                 $template->color = 'blue';
                 $template->verb = 'published';
                 break;
         }
         switch ($item->getScope()) {
             case 'user':
                 $template->icon = 'user';
                 break;
             case 'page':
                 $template->icon = 'file-text';
                 break;
             case 'file':
                 $template->icon = 'image';
                 break;
             case 'info':
                 $template->icon = 'user';
                 break;
         }
         $timeline[$key] = $template->render();
         if (count($timeline) >= 20) {
             break;
         }
     }
     return $timeline;
 }
Exemple #5
0
 public function adminTemplateFunctions(AdminTemplate &$template)
 {
     $template->addFunction('canAccess', function ($args) {
         return $_SESSION['user']->canAccess($args['uri']);
     });
     $config = Config::getInstance();
     $template->addFunction('date_format', function ($args) {
         $date = $args['date'];
         $format = null;
         if (isset($args['format'])) {
             $format = $args['format'];
         }
         if (!$date instanceof \DateTime) {
             return '';
         }
         switch ($format) {
             case 'friendly':
                 return $this->friendlyDate($date);
             case 'short':
                 $format = 'd/m/Y g:ia';
                 break;
             case 'long_date':
                 $format = 'jS F Y';
                 break;
             case 'date':
                 $format = 'd/m/Y';
                 break;
             case 'time':
                 $format = 'g:ia';
                 break;
             case 'system_date':
                 $format = 'Y-m-d';
                 break;
             case 'system_datetime':
                 $format = 'Y-m-d H:i:s';
                 break;
             default:
                 $format = 'jS F Y, g:ia';
                 break;
         }
         return $date->format($format);
     });
     $template->set('date_now', new \DateTime());
     $template->set('adminUri', $config->get('site.full_admin_url'));
     $template->set('config', $config);
     $template->set('settings', Setting::getAllAsArray());
     $template->set('GET', $_GET);
     $template->addFunction('pagination', array($this, 'handlePagination'));
     $template->addFunction('var_dump', function ($args) {
         ob_start();
         var_dump($args['variable']);
         $rtn = ob_get_contents();
         ob_end_clean();
         return $rtn;
     });
     $template->addFunction('is_mobile', function () {
         if (class_exists('\\Mobile_Detect')) {
             $mobileDetect = new \Mobile_Detect();
             return $mobileDetect->isMobile();
         }
         return false;
     });
     $theme = 'blue';
     if (!is_null($config->get('site.admin_theme', null))) {
         $theme = $config->get('site.admin_theme');
     }
     $template->set('theme', $theme);
 }
Exemple #6
0
 protected function setupLegacyTemplate($controller, $action)
 {
     if (LegacyTemplate::exists($controller . '/' . $action)) {
         $this->template = new Template('legacy', 'admin');
         $this->view = LegacyTemplate::getAdminTemplate($controller . '/' . $action);
         $this->view->currentUser = $this->currentUser;
     }
 }