PageLegacyInterface.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <?php
  2. namespace Grav\Common\Page\Interfaces;
  3. use Exception;
  4. use Grav\Common\Data\Blueprint;
  5. use Grav\Common\Page\Collection;
  6. use InvalidArgumentException;
  7. use RocketTheme\Toolbox\File\MarkdownFile;
  8. use SplFileInfo;
  9. /**
  10. * Interface PageLegacyInterface
  11. * @package Grav\Common\Page\Interfaces
  12. */
  13. interface PageLegacyInterface
  14. {
  15. /**
  16. * Initializes the page instance variables based on a file
  17. *
  18. * @param SplFileInfo $file The file information for the .md file that the page represents
  19. * @param string|null $extension
  20. * @return $this
  21. */
  22. public function init(SplFileInfo $file, $extension = null);
  23. /**
  24. * Gets and Sets the raw data
  25. *
  26. * @param string|null $var Raw content string
  27. * @return string Raw content string
  28. */
  29. public function raw($var = null);
  30. /**
  31. * Gets and Sets the page frontmatter
  32. *
  33. * @param string|null $var
  34. * @return string
  35. */
  36. public function frontmatter($var = null);
  37. /**
  38. * Modify a header value directly
  39. *
  40. * @param string $key
  41. * @param mixed $value
  42. */
  43. public function modifyHeader($key, $value);
  44. /**
  45. * @return int
  46. */
  47. public function httpResponseCode();
  48. /**
  49. * @return array
  50. */
  51. public function httpHeaders();
  52. /**
  53. * Get the contentMeta array and initialize content first if it's not already
  54. *
  55. * @return mixed
  56. */
  57. public function contentMeta();
  58. /**
  59. * Add an entry to the page's contentMeta array
  60. *
  61. * @param string $name
  62. * @param mixed $value
  63. */
  64. public function addContentMeta($name, $value);
  65. /**
  66. * Return the whole contentMeta array as it currently stands
  67. *
  68. * @param string|null $name
  69. * @return mixed
  70. */
  71. public function getContentMeta($name = null);
  72. /**
  73. * Sets the whole content meta array in one shot
  74. *
  75. * @param array $content_meta
  76. * @return array
  77. */
  78. public function setContentMeta($content_meta);
  79. /**
  80. * Fires the onPageContentProcessed event, and caches the page content using a unique ID for the page
  81. */
  82. public function cachePageContent();
  83. /**
  84. * Get file object to the page.
  85. *
  86. * @return MarkdownFile|null
  87. */
  88. public function file();
  89. /**
  90. * Save page if there's a file assigned to it.
  91. *
  92. * @param bool|mixed $reorder Internal use.
  93. */
  94. public function save($reorder = true);
  95. /**
  96. * Prepare move page to new location. Moves also everything that's under the current page.
  97. *
  98. * You need to call $this->save() in order to perform the move.
  99. *
  100. * @param PageInterface $parent New parent page.
  101. * @return $this
  102. */
  103. public function move(PageInterface $parent);
  104. /**
  105. * Prepare a copy from the page. Copies also everything that's under the current page.
  106. *
  107. * Returns a new Page object for the copy.
  108. * You need to call $this->save() in order to perform the move.
  109. *
  110. * @param PageInterface $parent New parent page.
  111. * @return $this
  112. */
  113. public function copy(PageInterface $parent);
  114. /**
  115. * Get blueprints for the page.
  116. *
  117. * @return Blueprint
  118. */
  119. public function blueprints();
  120. /**
  121. * Get the blueprint name for this page. Use the blueprint form field if set
  122. *
  123. * @return string
  124. */
  125. public function blueprintName();
  126. /**
  127. * Validate page header.
  128. *
  129. * @throws Exception
  130. */
  131. public function validate();
  132. /**
  133. * Filter page header from illegal contents.
  134. */
  135. public function filter();
  136. /**
  137. * Get unknown header variables.
  138. *
  139. * @return array
  140. */
  141. public function extra();
  142. /**
  143. * Convert page to an array.
  144. *
  145. * @return array
  146. */
  147. public function toArray();
  148. /**
  149. * Convert page to YAML encoded string.
  150. *
  151. * @return string
  152. */
  153. public function toYaml();
  154. /**
  155. * Convert page to JSON encoded string.
  156. *
  157. * @return string
  158. */
  159. public function toJson();
  160. /**
  161. * Returns normalized list of name => form pairs.
  162. *
  163. * @return array
  164. */
  165. public function forms();
  166. /**
  167. * @param array $new
  168. */
  169. public function addForms(array $new);
  170. /**
  171. * Gets and sets the name field. If no name field is set, it will return 'default.md'.
  172. *
  173. * @param string|null $var The name of this page.
  174. * @return string The name of this page.
  175. */
  176. public function name($var = null);
  177. /**
  178. * Returns child page type.
  179. *
  180. * @return string
  181. */
  182. public function childType();
  183. /**
  184. * Gets and sets the template field. This is used to find the correct Twig template file to render.
  185. * If no field is set, it will return the name without the .md extension
  186. *
  187. * @param string|null $var the template name
  188. * @return string the template name
  189. */
  190. public function template($var = null);
  191. /**
  192. * Allows a page to override the output render format, usually the extension provided
  193. * in the URL. (e.g. `html`, `json`, `xml`, etc).
  194. *
  195. * @param string|null $var
  196. * @return string
  197. */
  198. public function templateFormat($var = null);
  199. /**
  200. * Gets and sets the extension field.
  201. *
  202. * @param string|null $var
  203. * @return string|null
  204. */
  205. public function extension($var = null);
  206. /**
  207. * Gets and sets the expires field. If not set will return the default
  208. *
  209. * @param int|null $var The new expires value.
  210. * @return int The expires value
  211. */
  212. public function expires($var = null);
  213. /**
  214. * Gets and sets the cache-control property. If not set it will return the default value (null)
  215. * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control for more details on valid options
  216. *
  217. * @param string|null $var
  218. * @return string|null
  219. */
  220. public function cacheControl($var = null);
  221. /**
  222. * @param bool|null $var
  223. * @return bool
  224. */
  225. public function ssl($var = null);
  226. /**
  227. * Returns the state of the debugger override etting for this page
  228. *
  229. * @return bool
  230. */
  231. public function debugger();
  232. /**
  233. * Function to merge page metadata tags and build an array of Metadata objects
  234. * that can then be rendered in the page.
  235. *
  236. * @param array|null $var an Array of metadata values to set
  237. * @return array an Array of metadata values for the page
  238. */
  239. public function metadata($var = null);
  240. /**
  241. * Gets and sets the option to show the etag header for the page.
  242. *
  243. * @param bool|null $var show etag header
  244. * @return bool show etag header
  245. */
  246. public function eTag($var = null): bool;
  247. /**
  248. * Gets and sets the path to the .md file for this Page object.
  249. *
  250. * @param string|null $var the file path
  251. * @return string|null the file path
  252. */
  253. public function filePath($var = null);
  254. /**
  255. * Gets the relative path to the .md file
  256. *
  257. * @return string The relative file path
  258. */
  259. public function filePathClean();
  260. /**
  261. * Gets and sets the order by which any sub-pages should be sorted.
  262. *
  263. * @param string|null $var the order, either "asc" or "desc"
  264. * @return string the order, either "asc" or "desc"
  265. * @deprecated 1.6
  266. */
  267. public function orderDir($var = null);
  268. /**
  269. * Gets and sets the order by which the sub-pages should be sorted.
  270. *
  271. * default - is the order based on the file system, ie 01.Home before 02.Advark
  272. * title - is the order based on the title set in the pages
  273. * date - is the order based on the date set in the pages
  274. * folder - is the order based on the name of the folder with any numerics omitted
  275. *
  276. * @param string|null $var supported options include "default", "title", "date", and "folder"
  277. * @return string supported options include "default", "title", "date", and "folder"
  278. * @deprecated 1.6
  279. */
  280. public function orderBy($var = null);
  281. /**
  282. * Gets the manual order set in the header.
  283. *
  284. * @param string|null $var supported options include "default", "title", "date", and "folder"
  285. * @return array
  286. * @deprecated 1.6
  287. */
  288. public function orderManual($var = null);
  289. /**
  290. * Gets and sets the maxCount field which describes how many sub-pages should be displayed if the
  291. * sub_pages header property is set for this page object.
  292. *
  293. * @param int|null $var the maximum number of sub-pages
  294. * @return int the maximum number of sub-pages
  295. * @deprecated 1.6
  296. */
  297. public function maxCount($var = null);
  298. /**
  299. * Gets and sets the modular var that helps identify this page is a modular child
  300. *
  301. * @param bool|null $var true if modular_twig
  302. * @return bool true if modular_twig
  303. * @deprecated 1.7 Use ->isModule() or ->modularTwig() method instead.
  304. */
  305. public function modular($var = null);
  306. /**
  307. * Gets and sets the modular_twig var that helps identify this page as a modular child page that will need
  308. * twig processing handled differently from a regular page.
  309. *
  310. * @param bool|null $var true if modular_twig
  311. * @return bool true if modular_twig
  312. */
  313. public function modularTwig($var = null);
  314. /**
  315. * Returns children of this page.
  316. *
  317. * @return PageCollectionInterface|Collection
  318. */
  319. public function children();
  320. /**
  321. * Check to see if this item is the first in an array of sub-pages.
  322. *
  323. * @return bool True if item is first.
  324. */
  325. public function isFirst();
  326. /**
  327. * Check to see if this item is the last in an array of sub-pages.
  328. *
  329. * @return bool True if item is last
  330. */
  331. public function isLast();
  332. /**
  333. * Gets the previous sibling based on current position.
  334. *
  335. * @return PageInterface the previous Page item
  336. */
  337. public function prevSibling();
  338. /**
  339. * Gets the next sibling based on current position.
  340. *
  341. * @return PageInterface the next Page item
  342. */
  343. public function nextSibling();
  344. /**
  345. * Returns the adjacent sibling based on a direction.
  346. *
  347. * @param int $direction either -1 or +1
  348. * @return PageInterface|false the sibling page
  349. */
  350. public function adjacentSibling($direction = 1);
  351. /**
  352. * Helper method to return an ancestor page.
  353. *
  354. * @param bool|null $lookup Name of the parent folder
  355. * @return PageInterface page you were looking for if it exists
  356. */
  357. public function ancestor($lookup = null);
  358. /**
  359. * Helper method to return an ancestor page to inherit from. The current
  360. * page object is returned.
  361. *
  362. * @param string $field Name of the parent folder
  363. * @return PageInterface
  364. */
  365. public function inherited($field);
  366. /**
  367. * Helper method to return an ancestor field only to inherit from. The
  368. * first occurrence of an ancestor field will be returned if at all.
  369. *
  370. * @param string $field Name of the parent folder
  371. * @return array
  372. */
  373. public function inheritedField($field);
  374. /**
  375. * Helper method to return a page.
  376. *
  377. * @param string $url the url of the page
  378. * @param bool $all
  379. * @return PageInterface page you were looking for if it exists
  380. */
  381. public function find($url, $all = false);
  382. /**
  383. * Get a collection of pages in the current context.
  384. *
  385. * @param string|array $params
  386. * @param bool $pagination
  387. * @return Collection
  388. * @throws InvalidArgumentException
  389. */
  390. public function collection($params = 'content', $pagination = true);
  391. /**
  392. * @param string|array $value
  393. * @param bool $only_published
  394. * @return PageCollectionInterface|Collection
  395. */
  396. public function evaluate($value, $only_published = true);
  397. /**
  398. * Returns whether or not the current folder exists
  399. *
  400. * @return bool
  401. */
  402. public function folderExists();
  403. /**
  404. * Gets the Page Unmodified (original) version of the page.
  405. *
  406. * @return PageInterface The original version of the page.
  407. */
  408. public function getOriginal();
  409. /**
  410. * Gets the action.
  411. *
  412. * @return string The Action string.
  413. */
  414. public function getAction();
  415. }