Automad
 All Classes Functions Variables Pages
delete_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 
44 /*
45  * Move a page to the trash directory and redirect to its parent page afterwards.
46  */
47 
48 
49 $output = array();
50 
51 
52 // Validate $_POST.
53 if (isset($_POST['url']) && array_key_exists($_POST['url'], $this->collection) && $_POST['url'] != '/' && isset($_POST['title']) && $_POST['title']) {
54 
55  $Page = $this->collection[$_POST['url']];
56 
57  // Check if the page's directory and parent directory are wirtable.
58  if (is_writable(dirname($this->pageFile($Page))) && is_writable(dirname(dirname($this->pageFile($Page))))) {
59 
60  $this->movePage($Page->path, '..' . AM_DIR_TRASH . dirname($Page->path), $this->extractPrefixFromPath($Page->path), $_POST['title']);
61  $output['redirect'] = '?context=edit_page&url=' . urlencode($Page->parentUrl);
62 
63  $Cache = new Cache();
64  $Cache->clear();
65 
66  } else {
67 
68  $output['error'] = $this->tb['error_permission'] . '<p>' . dirname(dirname($this->pageFile($Page))) . '</p>';
69 
70  }
71 
72 }
73 
74 
75 echo json_encode($output);
76 
77 
78 ?>