示例#1
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);
 }