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