1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10: class ZenpagePage extends ZenpageItems {
11:
12: var $manage_rights = MANAGE_ALL_PAGES_RIGHTS;
13: var $manage_some_rights = ZENPAGE_PAGES_RIGHTS;
14: var $view_rights = ALL_PAGES_RIGHTS;
15:
16: function __construct($titlelink, $allowCreate = NULL) {
17: if (is_array($titlelink)) {
18: $titlelink = $titlelink['titlelink'];
19: }
20: $new = $this->instantiate('pages', array('titlelink' => $titlelink), 'titlelink', true, empty($titlelink), $allowCreate);
21: $this->exists = $this->loaded;
22: }
23:
24: 25: 26: 27: 28:
29: function getSortOrder() {
30: return $this->get('sort_order');
31: }
32:
33: 34: 35: 36: 37:
38: function setSortOrder($sortorder) {
39: $this->set('sort_order', $sortorder);
40: }
41:
42: 43: 44: 45: 46:
47: function getUser() {
48: return $this->get('user');
49: }
50:
51: 52: 53: 54: 55:
56: function setUser($user) {
57: $this->set('user', $user);
58: }
59:
60: 61: 62: 63: 64:
65: function getPassword() {
66: if (GALLERY_SECURITY != 'public') {
67: return NULL;
68: } else {
69: return $this->get('password');
70: }
71: }
72:
73: 74: 75: 76: 77:
78: function setPassword($pwd) {
79: $this->set('password', $pwd);
80: }
81:
82: 83: 84: 85: 86:
87: function getPasswordHint($locale = NULL) {
88: $text = ($this->get('password_hint'));
89: if ($locale !== 'all') {
90: $text = get_language_string($text, $locale);
91: }
92: $text = zpFunctions::unTagURLs($text);
93: return $text;
94: }
95:
96: 97: 98: 99: 100:
101: function setPasswordHint($hint) {
102: $this->set('password_hint', zpFunctions::tagURLs($hint));
103: }
104:
105: 106: 107: 108:
109: function copy($newtitle) {
110: $newID = $newtitle;
111: $id = parent::copy(array('titlelink' => $newID));
112: if (!$id) {
113: $newID = $newtitle . ':' . seoFriendly(date('Y-m-d_H-i-s'));
114: $id = parent::copy(array('titlelink' => $newID));
115: }
116: if ($id) {
117: $newobj = new ZenpagePage($newID);
118: $newobj->setTitle($newtitle);
119: $newobj->setSortOrder(NULL);
120: $newobj->setTags($this->getTags());
121: $newobj->setDateTime(date('Y-m-d H:i:s'));
122: $newobj->setShow(0);
123: $newobj->save();
124: return $newobj;
125: }
126: return false;
127: }
128:
129: 130: 131: 132:
133: function remove() {
134: if ($success = parent::remove()) {
135: $sortorder = $this->getSortOrder();
136: if ($this->id) {
137: $success = $success && query("DELETE FROM " . prefix('obj_to_tag') . "WHERE `type`='pages' AND `objectid`=" . $this->id);
138: $success = $success && query("DELETE FROM " . prefix('comments') . " WHERE ownerid = " . $this->getID() . ' AND type="pages"');
139:
140: $mychild = strlen($sortorder) + 4;
141: $result = query_full_array('SELECT * FROM ' . prefix('pages') . " WHERE `sort_order` like '" . $sortorder . "-%'");
142: if (is_array($result)) {
143: foreach ($result as $row) {
144: if (strlen($row['sort_order']) == $mychild) {
145: $subpage = new ZenpagePage($row['titlelink']);
146: $success = $success && $subpage->remove();
147: }
148: }
149: }
150: }
151: }
152: return $success;
153: }
154:
155: 156: 157: 158: 159: 160: 161:
162: function getParents(&$parentid = '', $initparents = true) {
163: global $parentpages, $_zp_zenpage;
164: $allitems = $_zp_zenpage->getPages();
165: if ($initparents) {
166: $parentpages = array();
167: }
168: if (empty($parentid)) {
169: $currentparentid = $this->getParentID();
170: } else {
171: $currentparentid = $parentid;
172: }
173: foreach ($allitems as $item) {
174: $obj = new ZenpagePage($item['titlelink']);
175: $itemtitlelink = $obj->getTitlelink();
176: $itemid = $obj->getID();
177: $itemparentid = $obj->getParentID();
178: if ($itemid == $currentparentid) {
179: array_unshift($parentpages, $itemtitlelink);
180: $obj->getParents($itemparentid, false);
181: }
182: }
183: return $parentpages;
184: }
185:
186: 187: 188: 189: 190: 191: 192: 193: 194:
195: function getPages($published = NULL, $toplevel = false, $number = NULL, $sorttype = NULL, $sortdirection = NULL) {
196: global $_zp_zenpage;
197: $subpages = array();
198: $sortorder = $this->getSortOrder();
199: $pages = $_zp_zenpage->getPages($published, false, $number, $sorttype, $sortdirection, $this);
200: foreach ($pages as $page) {
201: if ($page['parentid'] == $this->getID() && $page['sort_order'] != $sortorder) {
202: array_push($subpages, $page);
203: }
204: }
205: return $subpages;
206: }
207:
208: 209: 210: 211: 212:
213: function getSubPages() {
214: Zenpage_internal_deprecations::getSubPages();
215: return $this->getPages();
216: }
217:
218:
219: 220: 221: 222: 223:
224: function checkforGuest(&$hint = NULL, &$show = NULL) {
225: if (!parent::checkForGuest()) {
226: return false;
227: }
228: $pageobj = $this;
229: $hash = $pageobj->getPassword();
230: while (empty($hash) && !is_null($pageobj)) {
231: $parentID = $pageobj->getParentID();
232: if (empty($parentID)) {
233: $pageobj = NULL;
234: } else {
235: $sql = 'SELECT `titlelink` FROM ' . prefix('pages') . ' WHERE `id`=' . $parentID;
236: $result = query_single_row($sql);
237: $pageobj = new ZenpagePage($result['titlelink']);
238: $hash = $pageobj->getPassword();
239: }
240: }
241: if (empty($hash)) {
242: return 'zp_public_access';
243: } else {
244: $authType = "zp_page_auth_" . $pageobj->getID();
245: $saved_auth = zp_getCookie($authType);
246: if ($saved_auth == $hash) {
247: return $authType;
248: } else {
249: $user = $pageobj->getUser();
250: $show = (!empty($user));
251: $hint = $pageobj->getPasswordHint();
252: return false;
253: }
254: }
255: }
256:
257: 258: 259: 260: 261: 262:
263: function isProtected() {
264: return $this->checkforGuest() != 'zp_public_access';
265: }
266:
267: 268: 269: 270: 271: 272:
273: function isMyItem($action) {
274: global $_zp_current_admin_obj;
275: if (parent::isMyItem($action)) {
276: return true;
277: }
278: if (zp_loggedin($action)) {
279: if (GALLERY_SECURITY != 'public' && $this->getShow() && $action == LIST_RIGHTS) {
280: return LIST_RIGHTS;
281: }
282: if ($_zp_current_admin_obj->getUser() == $this->getAuthor()) {
283: return true;
284: }
285: $mypages = $_zp_current_admin_obj->getObjects('pages');
286: if (!empty($mypages)) {
287: if (array_search($this->getTitlelink(), $mypages) !== false) {
288: return true;
289: }
290: }
291: }
292: return false;
293: }
294:
295: 296: 297: 298: 299:
300: function getLink() {
301: return zp_apply_filter('getLink', rewrite_path(_PAGES_ . '/' . $this->getTitlelink() . '/', '/index.php?p=pages&title=' . $this->getTitlelink()), $this, NULL);
302: }
303:
304: 305: 306: 307: 308: 309:
310: function getPageLink() {
311: Zenpage_internal_deprecations::getPageLink();
312: return $this->getLink();
313: }
314:
315: }
316:
317: ?>