1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10: class ZenpageCategory extends ZenpageRoot {
11:
12: var $manage_rights = MANAGE_ALL_NEWS_RIGHTS;
13: var $manage_some_rights = ZENPAGE_NEWS_RIGHTS;
14: var $view_rights = ALL_NEWS_RIGHTS;
15: protected $sortorder = 'date';
16: protected $sortdirection = true;
17: protected $sortSticky = true;
18:
19: function __construct($catlink, $create = NULL) {
20: if (is_array($catlink)) {
21: $catlink = $catlink['titlelink'];
22: }
23: $new = $this->instantiate('news_categories', array('titlelink' => $catlink), 'titlelink', true, empty($catlink), $create);
24: $this->exists = $this->loaded;
25: }
26:
27: 28: 29: 30: 31:
32: function getDesc($locale = NULL) {
33: $text = $this->get('desc');
34: if ($locale == 'all') {
35: return zpFunctions::unTagURLs($text);
36: } else {
37: return applyMacros(zpFunctions::unTagURLs(get_language_string($text, $locale)));
38: }
39: }
40:
41: 42: 43: 44: 45:
46: function setDesc($desc) {
47: $desc = zpFunctions::tagURLs($desc);
48: $this->set('desc', $desc);
49: }
50:
51: 52: 53: 54: 55:
56: function getContent($locale = NULL) {
57: $content = $this->get("content");
58: if ($locale == 'all') {
59: return zpFunctions::unTagURLs($content);
60: } else {
61: return applyMacros(zpFunctions::unTagURLs(get_language_string($content, $locale)));
62: }
63: }
64:
65: 66: 67: 68: 69:
70: function setContent($c) {
71: $c = zpFunctions::tagURLs($c);
72: $this->set("content", $c);
73: }
74:
75: 76: 77: 78: 79:
80: function getExtraContent($locale = NULL) {
81: $text = $this->get("extracontent");
82: if ($locale == 'all') {
83: return zpFunctions::unTagURLs($text);
84: } else {
85: return applyMacros(zpFunctions::unTagURLs(get_language_string($text, $locale)));
86: }
87: }
88:
89: 90: 91: 92:
93: function setExtraContent($ec) {
94: $this->set("extracontent", zpFunctions::tagURLs($ec));
95: }
96:
97: 98: 99: 100: 101:
102: function getSortOrder() {
103: return $this->get('sort_order');
104: }
105:
106: 107: 108: 109: 110:
111: function setSortOrder($sortorder) {
112: $this->set('sort_order', $sortorder);
113: }
114:
115: function getSortDirection() {
116: return $this->sortdirection;
117: }
118:
119: function setSortDirection($value) {
120: $this->sortdirection = (int) ($value && true);
121: }
122:
123: function getSortType() {
124: return $this->sortorder;
125: }
126:
127: function setSortType($value) {
128: $this->sortorder = $value;
129: }
130:
131: function getSortSticky() {
132: return $this->sortSticky;
133: }
134:
135: function setSortSticky($value) {
136: $this->sortSticky = (bool) $value;
137: }
138:
139: function getUser() {
140: return $this->get('user');
141: }
142:
143: 144: 145: 146: 147:
148: function setUser($user) {
149: $this->set('user', $user);
150: }
151:
152: function getPassword() {
153: if (GALLERY_SECURITY != 'public') {
154: return NULL;
155: } else {
156: return $this->get('password');
157: }
158: }
159:
160: 161: 162: 163: 164:
165: function setPassword($pwd) {
166: $this->set('password', $pwd);
167: }
168:
169: function getPasswordHint() {
170: return $this->get('password_hint');
171: }
172:
173: 174: 175: 176: 177:
178: function setPasswordHint($hint) {
179: $this->set('password_hint', $hint);
180: }
181:
182: 183: 184: 185:
186: function remove() {
187: if ($success = parent::remove()) {
188: $sortorder = $this->getSortOrder();
189: $success = query("DELETE FROM " . prefix('news2cat') . " WHERE cat_id = " . $this->getID());
190:
191: $mychild = strlen($sortorder) + 4;
192: $result = query_full_array('SELECT * FROM ' . prefix('news_categories') . " WHERE `sort_order` like '" . $sortorder . "-%'");
193: if (is_array($result)) {
194: foreach ($result as $row) {
195: if (strlen($row['sort_order']) == $mychild) {
196: $subcat = new ZenpageCategory($row['titlelink']);
197: $success = $success && $subcat->remove();
198: }
199: }
200: }
201: }
202: return $success;
203: }
204:
205: 206: 207: 208: 209: 210: 211:
212: function getSubCategories($visible = true, $sorttype = NULL, $sortdirection = NULL) {
213: global $_zp_zenpage;
214: $subcategories = array();
215: $sortorder = $this->getSortOrder();
216: foreach ($_zp_zenpage->getAllCategories($visible, $sorttype, $sortdirection) as $cat) {
217: $catobj = new ZenpageCategory($cat['titlelink']);
218: if ($catobj->getParentID() == $this->getID() && $catobj->getSortOrder() != $sortorder) {
219: array_push($subcategories, $catobj->getTitlelink());
220: }
221: }
222: if (count($subcategories) != 0) {
223: return $subcategories;
224: }
225: return FALSE;
226: }
227:
228: 229: 230: 231: 232:
233: function isSubNewsCategoryOf($catlink) {
234: if (!empty($catlink)) {
235: $parentid = $this->getParentID();
236: $categories = $this->getParents();
237: $count = 0;
238: foreach ($categories as $cat) {
239: if ($catlink == $cat) {
240: $count = 1;
241: break;
242: }
243: }
244: return $count == 1;
245: } else {
246: return false;
247: }
248: }
249:
250: 251: 252: 253: 254: 255: 256:
257: function getParents(&$parentid = '', $initparents = true) {
258: global $parentcats, $_zp_zenpage;
259: $allitems = $_zp_zenpage->getAllCategories(false);
260: if ($initparents) {
261: $parentcats = array();
262: }
263: if (empty($parentid)) {
264: $currentparentid = $this->getParentID();
265: } else {
266: $currentparentid = $parentid;
267: }
268: foreach ($allitems as $item) {
269: $obj = new ZenpageCategory($item['titlelink']);
270: $itemtitlelink = $obj->getTitlelink();
271: $itemid = $obj->getID();
272: $itemparentid = $obj->getParentID();
273: if ($itemid == $currentparentid) {
274: array_unshift($parentcats, $itemtitlelink);
275: $obj->getParents($itemparentid, false);
276: }
277: }
278: return $parentcats;
279: }
280:
281: 282: 283: 284: 285:
286: function checkforGuest(&$hint = NULL, &$show = NULL) {
287: if (!parent::checkForGuest()) {
288: return false;
289: }
290: $obj = $this;
291: $hash = $this->getPassword();
292: while (empty($hash) && !is_null($obj)) {
293: $parentID = $obj->getParentID();
294: if (empty($parentID)) {
295: $obj = NULL;
296: } else {
297: $sql = 'SELECT `titlelink` FROM ' . prefix('news_categories') . ' WHERE `id`=' . $parentID;
298: $result = query_single_row($sql);
299: $obj = new ZenpageCategory($result['titlelink']);
300: $hash = $obj->getPassword();
301: }
302: }
303: if (empty($hash)) {
304: return 'zp_public_access';
305: } else {
306: $authType = "zp_category_auth_" . $this->getID();
307: $saved_auth = zp_getCookie($authType);
308: if ($saved_auth == $hash) {
309: return $authType;
310: } else {
311: $user = $this->getUser();
312: if (!empty($user))
313: $show = true;
314: $hint = $this->getPasswordHint();
315: return false;
316: }
317: }
318: }
319:
320: 321: 322: 323: 324:
325: function isProtected() {
326: return $this->checkforGuest() != 'zp_public_access';
327: }
328:
329: function isMyItem($action) {
330: global $_zp_current_admin_obj;
331: if (parent::isMyItem($action)) {
332: return true;
333: }
334: if (zp_loggedin($action)) {
335: if ($action == LIST_RIGHTS && $this->getShow()) {
336: return true;
337: }
338: $mycategories = $_zp_current_admin_obj->getObjects('news');
339: if (!empty($mycategories)) {
340: $allowed = $this->getParents();
341: array_unshift($allowed, $this->getTitlelink());
342: $overlap = array_intersect($mycategories, $allowed);
343: if (!empty($overlap)) {
344: return true;
345: }
346: }
347: }
348: return false;
349: }
350:
351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370:
371: function getArticles($articles_per_page = 0, $published = NULL, $ignorepagination = false, $sortorder = NULL, $sortdirection = NULL, $sticky = NULL) {
372: global $_zp_zenpage;
373: return $_zp_zenpage->getArticles($articles_per_page, $published, $ignorepagination, $sortorder, $sortdirection, $sticky, $this);
374: }
375:
376: 377: 378: 379: 380: 381:
382: function getArticle($index, $published = NULL, $sortorder = 'date', $sortdirection = 'desc', $sticky = true) {
383: $articles = $this->getArticles(0, $published, true, $sortorder, $sortdirection, $sticky);
384: if ($index >= 0 && $index < count($articles)) {
385: return $articles[$index];
386: }
387: return false;
388: }
389:
390: 391: 392: 393: 394:
395: function getIndex($sortorder, $sortdirection, $sticky) {
396: global $_zp_zenpage, $_zp_current_zenpage_news;
397: if ($this->index == NULL) {
398: $articles = $_zp_zenpage->getArticles(0, NULL, true, $sortorder, $sortdirection, $sticky);
399: for ($i = 0; $i < count($articles); $i++) {
400: $article = $articles[$i];
401: if ($this->getTitlelink() == $article['titlelink']) {
402: $this->index = $i;
403: break;
404: }
405: }
406: }
407: return $this->index;
408: }
409:
410: 411: 412: 413: 414:
415: function getPrevArticle($sortorder = 'date', $sortdirection = 'desc', $sticky = true) {
416: global $_zp_zenpage, $_zp_current_zenpage_news;
417: $index = $this->getIndex($sortorder, $sortdirection, $sticky);
418: $article = $this->getArticle($index - 1);
419: return $article;
420: }
421:
422: 423: 424: 425: 426:
427: function getNextArticle($sortorder = 'date', $sortdirection = 'desc', $sticky = true) {
428: global $_zp_zenpage, $_zp_current_zenpage_news;
429: $index = $this->getIndex($sortorder, $sortdirection, $sticky);
430: $article = $this->getArticle($index + 1);
431: return $article;
432: }
433:
434: 435: 436: 437: 438: 439: 440:
441: function getLink($page = NULL) {
442: global $_zp_zenpage;
443: if ($page > 1) {
444: $pager = $page . '/';
445: $page = '&page=' . $page;
446: } else {
447: $pager = $page = '';
448: }
449: return zp_apply_filter('getLink', rewrite_path(_CATEGORY_ . '/' . $this->getTitlelink() . '/' . $pager, "/index.php?p=news&category=" . $this->getTitlelink() . $page), $this, NULL);
450: }
451:
452: 453: 454: 455: 456: 457:
458: function getCategoryLink() {
459: Zenpage_internal_deprecations::getCategoryLink();
460: return $this->getLink();
461: }
462:
463: }
464:
465:
466: ?>