Automad
 All Classes Functions Variables Pages
page.php
1 <?php
2 /*
3  * ....
4  * .: '':.
5  * :::: ':..
6  * ::. ''..
7  * .:'.. ..':.:::' . :. '':.
8  * :. '' '' '. ::::.. ..:
9  * ::::. ..':.. .'''::::: .
10  * :::::::.. '..:::: :. :::: :
11  * ::'':::::::. ':::.'':.:::: :
12  * :.. ''::::::....': '':: :
13  * :::::. '::::: : .. '' .
14  * .''::::::::... ':::.'' ..'' :.''''.
15  * :..:::''::::: :::::...:'' :..:
16  * ::::::. ':::: :::::::: ..:: .
17  * ::::::::.:::: :::::::: :'':.:: .''
18  * ::: '::::::::.' ''::::: :.' '': :
19  * ::: :::::::::..' :::: ::...' .
20  * ::: .:::::::::: :::: :::: .:'
21  * '::' ''::::::: :::: : :: :
22  * ':::: :::: :'' .:
23  * :::: :::: ..''
24  * :::: ..:::: .:''
25  * '''' '''''
26  *
27  *
28  * AUTOMAD
29  *
30  * Copyright (c) 2014 by Marc Anton Dahmen
31  * http://marcdahmen.de
32  *
33  * Licensed under the MIT license.
34  * http://automad.org/license
35  */
36 
37 
38 namespace Automad\Core;
39 
40 
41 defined('AUTOMAD') or die('Direct access not permitted!');
42 
43 
54 class Page {
55 
56 
68  public $data = array();
69 
70 
75  public $tags = array();
76 
77 
82  public $url;
83 
84 
89  public $path;
90 
91 
96  public $level;
97 
98 
103  public $parentUrl;
104 
105 
110  public $theme;
111 
112 
117  public $template;
118 
119 
124  public $hidden;
125 
126 
133  public function getTemplate() {
134 
135  $templatePath = AM_BASE_DIR . AM_DIR_THEMES . '/' . $this->theme . '/' . $this->template . '.php';
136 
137  if (file_exists($templatePath)) {
138  return $templatePath;
139  } else {
140  exit('Template "' . $templatePath . '" not found!');
141  }
142 
143  }
144 
145 
152  public function isCurrent() {
153 
154  return (AM_REQUEST == $this->url);
155 
156  }
157 
158 
165  public function isInCurrentPath() {
166 
167  // Test if AM_REQUEST starts with or is equal to $this->url.
168  // The trailing slash in strpos() is very important (URL . /), since without that slash,
169  // /path/to/page and /path/to/page-1 would both match a current URL like /path/to/page-1/subpage,
170  // while /path/to/page/ would not match.
171  // Since that will also exculde the current page (it will have the trailing slash more that AM_REQUEST), it has to be testes as well if $this->url equals AM_REQUEST.
172  // To always include the homepage as well, rtrim($this->url, '/') avoids a double "//" for the URL "/".
173  return (strpos(AM_REQUEST, rtrim($this->url, '/') . '/') === 0 || $this->url == AM_REQUEST);
174 
175  }
176 
177 
184  public function isHome() {
185 
186  return ($this->url == '/');
187 
188  }
189 
190 }
191 
192 
193 ?>