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: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501:
<?php
class ZenpageCategory extends ZenpageRoot {
public $manage_rights = MANAGE_ALL_NEWS_RIGHTS;
public $manage_some_rights = ZENPAGE_NEWS_RIGHTS;
public $view_rights = ALL_NEWS_RIGHTS;
public $parent = null;
public $parents = null;
protected $sorttype = 'date';
protected $sortdirection = true;
protected $sortSticky = true;
protected $is_public = null;
function __construct($catlink, $create = NULL) {
if (is_array($catlink)) {
$catlink = $catlink['titlelink'];
}
$new = $this->instantiate('news_categories', array('titlelink' => $catlink), 'titlelink', true, empty($catlink), $create);
$this->exists = $this->loaded;
}
function getDesc($locale = NULL) {
$text = $this->get('desc');
if ($locale == 'all') {
return unTagURLs($text);
} else {
return applyMacros(unTagURLs(get_language_string($text, $locale)));
}
}
function setDesc($desc) {
$desc = tagURLs($desc);
$this->set('desc', $desc);
}
function getSortOrder() {
return $this->get('sort_order');
}
function setDefaultSortorder() {
$default = $this->getDefaultSortorder();
$this->setSortorder($default);
}
function getDefaultSortorder() {
global $_zp_zenpage;
return $_zp_zenpage->getItemDefaultSortorder('category', $this->getParentID());
}
function setSortOrder($sortorder) {
$this->set('sort_order', $sortorder);
}
function getSortDirection() {
return $this->sortdirection;
}
function setSortDirection($value) {
$this->sortdirection = (int) ($value && true);
}
function getSortType() {
return $this->sorttype;
}
function setSortType($value) {
$this->sorttype = $value;
}
function getSortSticky() {
return $this->sortSticky;
}
function setSortSticky($value) {
$this->sortSticky = (bool) $value;
}
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() {
return $this->get('password_hint');
}
function setPasswordHint($hint) {
$this->set('password_hint', $hint);
}
function remove() {
if ($success = parent::remove()) {
$sortorder = $this->getSortOrder();
$success = query("DELETE FROM " . prefix('news2cat') . " WHERE cat_id = " . $this->getID());
$mychild = strlen($sortorder) + 4;
$result = query_full_array('SELECT * FROM ' . prefix('news_categories') . " WHERE `sort_order` like '" . $sortorder . "-%'");
if (is_array($result)) {
foreach ($result as $row) {
if (strlen($row['sort_order']) == $mychild) {
$subcat = new ZenpageCategory($row['titlelink']);
$success = $success && $subcat->remove();
}
}
}
}
return $success;
}
function getCategories($visible = true, $sorttype = NULL, $sortdirection = NULL, $directchilds = true) {
global $_zp_zenpage;
$categories = array();
foreach ($_zp_zenpage->getAllCategories($visible, $sorttype, $sortdirection, false) as $cat) {
if ($cat['sort_order'] != $this->getSortOrder() && (!$directchilds && stripos($cat['sort_order'], $this->getSortOrder()) === 0) || $cat['parentid'] == $this->getID()) {
array_push($categories, $cat);
}
}
return $categories;
}
function getSubCategories($visible = true, $sorttype = NULL, $sortdirection = NULL, $directchilds = false) {
return $this->getCategories($visible, $sorttype, $sortdirection, $directchilds);
}
function isSubCategoryOf($catlink) {
if (!empty($catlink)) {
$categories = $this->getParents();
$count = 0;
foreach ($categories as $cat) {
if ($catlink == $cat) {
$count = 1;
break;
}
}
return $count == 1;
} else {
return false;
}
}
function isSubNewsCategoryOf($catlink) {
return $this->isSubCategoryOf($catlink);
}
function getParent() {
if (is_null($this->parent)) {
$parentid = $this->getParentID();
$obj = getItembyID('news_categories', $parentid);
if ($obj) {
return $this->parent = $obj;
}
} else {
return $this->parent;
}
return null;
}
function getParents() {
if (func_num_args() != 0) {
degbuglog(gettext('class ZenpageCategory getParents(): The parameters $parentid and $initparents have been removed in Zenphoto 1.5.5.'));
}
if (is_null($this->parents)) {
$parents = array();
$cat = $this;
while (!is_null($cat = $cat->getParent())) {
array_unshift($parents, $cat->getTitlelink());
}
return $this->parents = $parents;
} else {
return $this->parents;
}
}
function checkforGuest(&$hint = NULL, &$show = NULL) {
if (!parent::checkForGuest()) {
return false;
}
$obj = $this;
$hash = $this->getPassword();
while (empty($hash) && !is_null($obj)) {
$parentID = $obj->getParentID();
if (empty($parentID)) {
$obj = NULL;
} else {
$sql = 'SELECT `titlelink` FROM ' . prefix('news_categories') . ' WHERE `id`=' . $parentID;
$result = query_single_row($sql);
$obj = new ZenpageCategory($result['titlelink']);
$hash = $obj->getPassword();
}
}
if (empty($hash)) {
return 'zp_public_access';
} else {
$authType = "zp_category_auth_" . $this->getID();
$saved_auth = zp_getCookie($authType);
if ($saved_auth == $hash) {
return $authType;
} else {
$user = $this->getUser();
if (!empty($user))
$show = true;
$hint = $this->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 ($action == LIST_RIGHTS && $this->isPublic()) {
return true;
}
$mycategories = $_zp_current_admin_obj->getObjects('news');
if (!empty($mycategories)) {
$allowed = $this->getParents();
array_unshift($allowed, $this->getTitlelink());
$overlap = array_intersect($mycategories, $allowed);
if (!empty($overlap)) {
return true;
}
}
}
return false;
}
function getArticles($articles_per_page = 0, $published = NULL, $ignorepagination = false, $sortorder = NULL, $sortdirection = NULL, $sticky = NULL, $author = null) {
global $_zp_zenpage;
return $_zp_zenpage->getArticles($articles_per_page, $published, $ignorepagination, $sortorder, $sortdirection, $sticky, $this, $author);
}
function getArticle($index, $published = NULL, $sortorder = 'date', $sortdirection = 'desc', $sticky = true) {
$articles = $this->getArticles(0, $published, true, $sortorder, $sortdirection, $sticky);
if ($index >= 0 && $index < count($articles)) {
return $articles[$index];
}
return false;
}
function getIndex($sortorder, $sortdirection, $sticky) {
if ($this->index == NULL) {
$articles = $this->getArticles(0, NULL, true, $sortorder, $sortdirection, $sticky);
for ($i = 0; $i < count($articles); $i++) {
$article = $articles[$i];
if ($this->getTitlelink() == $article['titlelink']) {
$this->index = $i;
break;
}
}
}
return $this->index;
}
function getPrevArticle($sortorder = 'date', $sortdirection = 'desc', $sticky = true) {
global $_zp_zenpage, $_zp_current_zenpage_news;
$index = $this->getIndex($sortorder, $sortdirection, $sticky);
$article = $this->getArticle($index - 1);
return $article;
}
function getNextArticle($sortorder = 'date', $sortdirection = 'desc', $sticky = true) {
global $_zp_zenpage, $_zp_current_zenpage_news;
$index = $this->getIndex($sortorder, $sortdirection, $sticky);
$article = $this->getArticle($index + 1);
return $article;
}
function getLink($page = NULL) {
global $_zp_zenpage;
if ($page > 1) {
$pager = $page . '/';
$page = '&page=' . $page;
} else {
$pager = $page = '';
}
return zp_apply_filter('getLink', rewrite_path(_CATEGORY_ . '/' . $this->getTitlelink() . '/' . $pager, "/index.php?p=news&category=" . $this->getTitlelink() . $page), $this, NULL);
}
}