This commit is contained in:
Flavio Copes
2016-10-03 16:03:01 +02:00
parent c6f8fe259a
commit bc3943b386

View File

@@ -164,8 +164,8 @@ class Page
unset($process_fields[$field]);
}
}
$text_header = Grav::instance()['twig']->processString(json_encode($process_fields), ['page'=>$this]);
$this->header((object) (json_decode($text_header, true) + $ignored_fields));
$text_header = Grav::instance()['twig']->processString(json_encode($process_fields), ['page' => $this]);
$this->header((object)(json_decode($text_header, true) + $ignored_fields));
}
}
@@ -419,7 +419,7 @@ class Page
$this->last_modified = (bool)$this->header->last_modified;
}
if (isset($this->header->ssl)) {
$this->ssl = (bool) $this->header->ssl;
$this->ssl = (bool)$this->header->ssl;
}
if (isset($this->header->template_format)) {
$this->template_format = $this->header->template_format;
@@ -507,6 +507,7 @@ class Page
}
$summary = Utils::truncateHTML($content, $size);
return html_entity_decode($summary);
}
@@ -629,6 +630,7 @@ class Page
if ($this->content === null) {
$this->content();
}
return $this->getContentMeta();
}
@@ -647,18 +649,20 @@ class Page
* Return the whole contentMeta array as it currently stands
*
* @param null $name
*
* @return mixed
*/
public function getContentMeta($name = null)
{
if ($name) {
if(isset($this->content_meta[$name])) {
if (isset($this->content_meta[$name])) {
return $this->content_meta[$name];
} else {
return null;
}
}
return $this->content_meta;
}
@@ -666,6 +670,7 @@ class Page
* Sets the whole content meta array in one shot
*
* @param $content_meta
*
* @return mixed
*/
public function setContentMeta($content_meta)
@@ -1108,6 +1113,7 @@ class Page
* in the URL. (e.g. `html`, `json`, `xml`, etc).
*
* @param null $var
*
* @return null
*/
public function templateFormat($var = null)
@@ -1117,7 +1123,7 @@ class Page
}
if (empty($this->template_format)) {
$this->template_format = Grav::instance()['uri']->extension();
$this->template_format = Grav::instance()['uri']->extension();
}
return $this->template_format;
@@ -1131,16 +1137,16 @@ class Page
* @return null|string
*/
public function extension($var = null)
{
if ($var !== null) {
$this->extension = $var;
}
if (empty($this->extension)) {
$this->extension = '.' . pathinfo($this->name(), PATHINFO_EXTENSION);
}
{
if ($var !== null) {
$this->extension = $var;
}
if (empty($this->extension)) {
$this->extension = '.' . pathinfo($this->name(), PATHINFO_EXTENSION);
}
return $this->extension;
}
return $this->extension;
}
/**
* Returns the page extension, got from the page `url_extension` config and falls back to the
@@ -1156,7 +1162,8 @@ class Page
// if not set in the page get the value from system config
if (empty($this->url_extension)) {
$this->url_extension = trim(isset($this->header->append_url_extension) ? $this->header->append_url_extension : Grav::instance()['config']->get('system.pages.append_url_extension', false));
$this->url_extension = trim(isset($this->header->append_url_extension) ? $this->header->append_url_extension : Grav::instance()['config']->get('system.pages.append_url_extension',
false));
}
return $this->url_extension;
@@ -1318,7 +1325,7 @@ class Page
public function ssl($var = null)
{
if ($var !== null) {
$this->ssl = (bool) $var;
$this->ssl = (bool)$var;
}
return $this->ssl;
@@ -1379,21 +1386,28 @@ class Page
// Backward compatibility for nested arrays in metas
if (is_array($value)) {
foreach ($value as $property => $prop_value) {
$prop_key = $key . ":" . $property;
$this->metadata[$prop_key] = ['name' => $prop_key, 'property' => $prop_key, 'content' => htmlspecialchars($prop_value, ENT_QUOTES, 'UTF-8')];
$prop_key = $key . ":" . $property;
$this->metadata[$prop_key] = [
'name' => $prop_key,
'property' => $prop_key,
'content' => htmlspecialchars($prop_value, ENT_QUOTES, 'UTF-8')
];
}
} else {
// If it this is a standard meta data type
if ($value) {
if (in_array($key, $header_tag_http_equivs)) {
$this->metadata[$key] = ['http_equiv' => $key, 'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')];
$this->metadata[$key] = [
'http_equiv' => $key,
'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
];
} elseif ($key == 'charset') {
$this->metadata[$key] = ['charset' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')];
} else {
// if it's a social metadata with separator, render as property
$separator = strpos($key, ':');
$separator = strpos($key, ':');
$hasSeparator = $separator && $separator < strlen($key) - 1;
$entry = ['name' => $key, 'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')];
$entry = ['name' => $key, 'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')];
if ($hasSeparator) {
$entry['property'] = $key;
@@ -1421,8 +1435,8 @@ class Page
{
if ($var !== null && $var !== "") {
$this->slug = $var;
if(!preg_match('/^[a-z0-9][-a-z0-9]*$/', $this->slug)){
Grav::instance()['log']->notice("Invalid slug set in YAML frontmatter: " . $this->rawRoute() . " => ". $this->slug);
if (!preg_match('/^[a-z0-9][-a-z0-9]*$/', $this->slug)) {
Grav::instance()['log']->notice("Invalid slug set in YAML frontmatter: " . $this->rawRoute() . " => " . $this->slug);
}
}
@@ -1431,7 +1445,6 @@ class Page
}
return $this->slug;
}
@@ -2180,6 +2193,7 @@ class Page
{
$home = Grav::instance()['config']->get('system.home.alias');
$is_home = ($this->route() == $home || $this->rawRoute() == $home);
return $is_home;
}