예제 #1
0
 /**
  * Determine if this is running under the admin
  *
  * @return bool
  */
 public function isAdmin()
 {
     return Utils::isAdminPlugin();
 }
예제 #2
0
 /**
  * Gets and Sets the header based on the YAML configuration at the top of the .md file
  *
  * @param  object|array $var a YAML object representing the configuration for the file
  *
  * @return object      the current YAML configuration
  */
 public function header($var = null)
 {
     if ($var) {
         $this->header = (object) $var;
         // Update also file object.
         $file = $this->file();
         if ($file) {
             $file->header((array) $var);
         }
         // Force content re-processing.
         $this->id(time() . md5($this->filePath()));
     }
     if (!$this->header) {
         $file = $this->file();
         if ($file) {
             // Set some options
             $file->settings(['native' => true, 'compat' => true]);
             try {
                 $this->raw_content = $file->markdown();
                 $this->frontmatter = $file->frontmatter();
                 $this->header = (object) $file->header();
                 if (!Utils::isAdminPlugin()) {
                     // Process frontmatter with Twig if enabled
                     if (Grav::instance()['config']->get('system.pages.frontmatter.process_twig') === true) {
                         $this->processFrontmatter();
                     }
                     // If there's a `frontmatter.yaml` file merge that in with the page header
                     // note page's own frontmatter has precedence and will overwrite any defaults
                     $frontmatter_file = $this->path . '/' . $this->folder . '/frontmatter.yaml';
                     if (file_exists($frontmatter_file)) {
                         $frontmatter_data = (array) Yaml::parse(file_get_contents($frontmatter_file));
                         $this->header = (object) array_replace_recursive($frontmatter_data, (array) $this->header);
                     }
                 }
             } catch (ParseException $e) {
                 $file->raw(Grav::instance()['language']->translate(['FRONTMATTER_ERROR_PAGE', $this->slug(), $file->filename(), $e->getMessage(), $file->raw()]));
                 $this->raw_content = $file->markdown();
                 $this->frontmatter = $file->frontmatter();
                 $this->header = (object) $file->header();
             }
             $var = true;
         }
     }
     if ($var) {
         if (isset($this->header->slug)) {
             $this->slug($this->header->slug);
         }
         if (isset($this->header->routes)) {
             $this->routes = (array) $this->header->routes;
         }
         if (isset($this->header->title)) {
             $this->title = trim($this->header->title);
         }
         if (isset($this->header->language)) {
             $this->language = trim($this->header->language);
         }
         if (isset($this->header->template)) {
             $this->template = trim($this->header->template);
         }
         if (isset($this->header->menu)) {
             $this->menu = trim($this->header->menu);
         }
         if (isset($this->header->routable)) {
             $this->routable = (bool) $this->header->routable;
         }
         if (isset($this->header->visible)) {
             $this->visible = (bool) $this->header->visible;
         }
         if (isset($this->header->redirect)) {
             $this->redirect = trim($this->header->redirect);
         }
         if (isset($this->header->external_url)) {
             $this->external_url = trim($this->header->external_url);
         }
         if (isset($this->header->order_dir)) {
             $this->order_dir = trim($this->header->order_dir);
         }
         if (isset($this->header->order_by)) {
             $this->order_by = trim($this->header->order_by);
         }
         if (isset($this->header->order_manual)) {
             $this->order_manual = (array) $this->header->order_manual;
         }
         if (isset($this->header->dateformat)) {
             $this->dateformat($this->header->dateformat);
         }
         if (isset($this->header->date)) {
             $this->date($this->header->date);
         }
         if (isset($this->header->markdown_extra)) {
             $this->markdown_extra = (bool) $this->header->markdown_extra;
         }
         if (isset($this->header->taxonomy)) {
             foreach ((array) $this->header->taxonomy as $taxonomy => $taxitems) {
                 $this->taxonomy[$taxonomy] = (array) $taxitems;
             }
         }
         if (isset($this->header->max_count)) {
             $this->max_count = intval($this->header->max_count);
         }
         if (isset($this->header->process)) {
             foreach ((array) $this->header->process as $process => $status) {
                 $this->process[$process] = (bool) $status;
             }
         }
         if (isset($this->header->published)) {
             $this->published = (bool) $this->header->published;
         }
         if (isset($this->header->publish_date)) {
             $this->publishDate($this->header->publish_date);
         }
         if (isset($this->header->unpublish_date)) {
             $this->unpublishDate($this->header->unpublish_date);
         }
         if (isset($this->header->expires)) {
             $this->expires = intval($this->header->expires);
         }
         if (isset($this->header->etag)) {
             $this->etag = (bool) $this->header->etag;
         }
         if (isset($this->header->last_modified)) {
             $this->last_modified = (bool) $this->header->last_modified;
         }
         if (isset($this->header->ssl)) {
             $this->ssl = (bool) $this->header->ssl;
         }
         if (isset($this->header->template_format)) {
             $this->template_format = $this->header->template_format;
         }
     }
     return $this->header;
 }