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: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613:
<?php
require_once(SERVERPATH . '/' . ZENFOLDER . '/template-functions.php');
class feed {
protected $feed = 'feed';
protected $mode;
protected $options;
protected $feedtype = NULL;
protected $itemnumber = NULL;
protected $locale = NULL;
protected $locale_xml = NULL;
protected $host = NULL;
protected $sortorder = NULL;
protected $sortdirection = NULL;
protected $albumfolder = NULL;
protected $collection = NULL;
protected $albumpath = NULL;
protected $imagepath = NULL;
protected $imagesize = NULL;
protected $modrewritesuffix = NULL;
protected $catlink = NULL;
protected $cattitle = NULL;
protected $newsoption = NULL;
protected $titleappendix = NULL;
protected $id = NULL;
protected $commentfeedtype = NULL;
protected $itemobj = NULL;
protected $channel_title = NULL;
protected $feeditem = array();
protected function getCacheFilename() {
$filename = array();
foreach ($this->options as $key => $value) {
if (empty($value) || $key == 'albumsmode') {
$filename[] = $key;
} else {
$filename[] = $value;
}
}
$filename = seoFriendly(implode('_', $filename));
return $filename . ".xml";
}
protected function startCache() {
$caching = getOption($this->feed . "_cache") && !zp_loggedin();
if ($caching) {
$cachefilepath = SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/' . strtolower($this->feed) . '/' . internalToFilesystem($this->getCacheFilename());
if (file_exists($cachefilepath) AND time() - filemtime($cachefilepath) < getOption($this->feed . "_cache_expire")) {
echo file_get_contents($cachefilepath);
exitZP();
} else {
if (file_exists($cachefilepath)) {
@chmod($cachefilepath, 0777);
@unlink($cachefilepath);
}
ob_start();
}
}
}
protected function endCache() {
$caching = getOption($this->feed . "_cache") && !zp_loggedin();
if ($caching) {
$cachefilepath = internalToFilesystem($this->getCacheFilename());
if (!empty($cachefilepath)) {
$cachefilepath = SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/' . strtolower($this->feed) . '/' . $cachefilepath;
mkdir_recursive(SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/' . strtolower($this->feed) . '/', FOLDER_MOD);
$pagecontent = ob_get_contents();
ob_end_clean();
if ($fh = @fopen($cachefilepath, "w")) {
fputs($fh, $pagecontent);
fclose($fh);
clearstatcache();
}
echo $pagecontent;
}
}
}
function clearCache($cachefolder = NULL) {
removeDir(SERVERPATH . '/' . STATIC_CACHE_FOLDER . '/' . strtolower($this->feed) . '/' . $cachefolder, true);
}
function __construct($options) {
$this->options = $options;
$invalid_options = array();
$this->locale = $this->getLang();
$this->locale_xml = strtr($this->locale, '_', '-');
$this->sortdirection = $this->getSortdir();
$this->sortorder = $this->getSortorder();
switch ($this->feedtype) {
case 'comments':
$this->commentfeedtype = $this->getCommentFeedType();
$this->id = $this->getId();
$invalid_options = array('albumsmode', 'folder', 'albumname', 'category', 'size');
break;
case 'gallery':
if (isset($this->options['albumsmode'])) {
$this->mode = 'albums';
}
if (isset($this->options['folder'])) {
$this->albumfolder = $this->getAlbum('folder');
$this->collection = true;
} else if (isset($this->options['albumname'])) {
$this->albumfolder = $this->getAlbum('albumname');
$this->collection = false;
} else {
$this->collection = false;
}
if (is_null($this->sortorder)) {
if ($this->mode == "albums") {
$this->sortorder = getOption($this->feed . "_sortorder_albums");
} else {
$this->sortorder = getOption($this->feed . "_sortorder");
}
}
$this->imagesize = $this->getImageSize();
$invalid_options = array('id', 'type', 'category');
break;
case 'news':
if ($this->sortorder == 'latest') {
$this->sortorder = NULL;
}
$this->catlink = $this->getCategory();
if (!empty($this->catlink)) {
$catobj = new ZenpageCategory($this->catlink);
$this->cattitle = $catobj->getTitle();
$this->newsoption = 'category';
} else {
$this->catlink = '';
$this->cattitle = '';
$this->newsoption = 'news';
}
$invalid_options = array('folder', 'albumname', 'albumsmode', 'type', 'id', 'size');
break;
case 'pages':
$invalid_options = array('folder', 'albumname', 'albumsmode', 'type', 'id', 'category', 'size');
break;
case 'null':
return;
}
$this->unsetOptions($invalid_options);
if (isset($this->options['itemnumber'])) {
$this->itemnumber = (int) $this->options['itemnumber'];
} else {
$this->itemnumber = getOption($this->feed . '_items');
}
}
protected function getLang() {
if (isset($this->options['lang'])) {
$langs = generateLanguageList();
$valid = array_values($langs);
if (in_array($this->options['lang'], $valid)) {
return $this->options['lang'];
}
}
return getOption('locale');
}
protected function getSortdir() {
$valid = array('desc', 'asc');
if (isset($this->options['sortdir']) && in_array($this->options['sortdir'], $valid)) {
return strtolower($this->options['sortdir']) != 'asc';
}
$this->options['sortdir'] = 'desc';
return true;
}
protected function getSortorder() {
if (isset($this->options['sortorder'])) {
$valid = array('latest', 'latest-date', 'latest-mtime', 'latest-publishdate', 'popular', 'toprated', 'mostrated', 'random', 'id');
if (in_array($this->options['sortorder'], $valid)) {
$this->options['sortdir'] = $this->options['sortorder'];
return $this->options['sortorder'];
} else {
$this->unsetOptions(array('sortorder'));
}
}
return null;
}
protected function getCommentFeedType() {
$valid = false;
if (isset($this->options['type'])) {
$valid = array( 'all', 'album' , 'image', 'news', 'page');
if (in_array($this->options['type'], $valid)) {
return $this->options['type'];
}
}
return 'all';
}
protected function getID() {
if (isset($this->options['id'])) {
$type = $this->getCommentFeedType();
$table = '';
if ($type != 'all') {
switch ($this->commentfeedtype) {
case 'album':
$table = 'albums';
break;
case 'image':
$table = 'images';
break;
case 'news':
$table = 'news';
break;
case 'page':
$table = 'pages';
break;
}
if ($table) {
$id = (int) $this->options['id'];
$result = query_single_row('SELECT `id` FROM ' . prefix($table) . ' WHERE id =' . $id);
if ($result) {
return $id;
}
}
}
}
$this->unsetOptions(array('id'));
return '';
}
protected function getAlbum($option) {
if (in_array($option, array('folder', 'albumname')) && isset($this->options[$option])) {
$albumobj = newAlbum($this->options[$option], true, true);
if ($albumobj->exists) {
return $this->options[$option];
}
}
$this->unsetOptions(array($option));
return '';
}
protected function getCategory() {
if (isset($this->options['category']) && class_exists('ZenpageCategory')) {
$catobj = new ZenpageCategory($this->options['category']);
if ($catobj->exists) {
return $this->options['category'];
}
}
$this->unsetOptions(array('category'));
return '';
}
protected function getImageSize() {
if (isset($this->options['size'])) {
$imagesize = (int) $this->options['size'];
} else {
$imagesize = NULL;
}
if ($this->mode == 'albums') {
if (is_null($imagesize) || $imagesize > getOption($this->feed . '_imagesize_albums')) {
$imagesize = getOption($this->feed . '_imagesize_albums');
}
} else {
if (is_null($imagesize) || $imagesize > getOption($this->feed . '_imagesize')) {
$imagesize = getOption($this->feed . '_imagesize');
}
}
return $imagesize;
}
protected function unsetOptions($options = null) {
if (!empty($options)) {
foreach ($options as $option) {
unset($this->options[$option]);
}
}
}
protected function getChannelTitleExtra() {
switch ($this->sortorder) {
default:
case 'latest':
case 'latest-date':
case 'latest-mtime':
case 'latest-publishdate':
if ($this->mode == 'albums') {
$albumextra = ' (' . gettext('Latest albums') . ')';
} else {
$albumextra = ' (' . gettext('Latest images') . ')';
}
break;
case 'latestupdated':
$albumextra = ' (' . gettext('latest updated albums') . ')';
break;
case 'popular':
if ($this->mode == 'albums') {
$albumextra = ' (' . gettext('Most popular albums') . ')';
} else {
$albumextra = ' (' . gettext('Most popular images') . ')';
}
break;
case 'toprated':
if ($this->mode == 'albums') {
$albumextra = ' (' . gettext('Top rated albums') . ')';
} else {
$albumextra = ' (' . gettext('Top rated images') . ')';
}
break;
case 'random':
if ($this->mode == 'albums') {
$albumextra = ' (' . gettext('Random albums') . ')';
} else {
$albumextra = ' (' . gettext('Random images') . ')';
}
break;
}
return $albumextra;
}
public function getitems() {
global $_zp_zenpage;
switch ($this->feedtype) {
case 'gallery':
if ($this->mode == "albums") {
$items = getAlbumStatistic($this->itemnumber, $this->sortorder, $this->albumfolder, $this->sortdirection);
} else {
$items = getImageStatistic($this->itemnumber, $this->sortorder, $this->albumfolder, $this->collection, 0, $this->sortdirection);
}
break;
case 'news':
switch ($this->newsoption) {
case "category":
if ($this->sortorder) {
$items = getZenpageStatistic($this->itemnumber, 'categories', $this->sortorder, $this->sortdirection);
} else {
$items = getLatestNews($this->itemnumber, $this->catlink, false, $this->sortdirection);
}
break;
default:
case "news":
if ($this->sortorder) {
$items = getZenpageStatistic($this->itemnumber, 'news', $this->sortorder, $this->sortdirection);
} else {
$items = getLatestNews($this->itemnumber, '', false, $this->sortdirection);
}
break;
}
break;
case "pages":
if ($this->sortorder) {
$items = getZenpageStatistic($this->itemnumber, 'pages', $this->sortorder, $this->sortdirection);
} else {
$items = $_zp_zenpage->getPages(NULL, false, $this->itemnumber);
}
break;
case 'comments':
switch ($this->commentfeedtype) {
case 'album':
$items = getLatestComments($this->itemnumber, 'album', $this->id);
break;
case 'image':
$items = getLatestComments($this->itemnumber, 'image', $this->id);
break;
case 'news':
case 'page':
if (function_exists('getLatestZenpageComments')) {
$items = getLatestZenpageComments($this->itemnumber, $this->commentfeedtype, $this->id);
}
break;
case 'gallery':
case 'allcomments':
case 'all':
$items = getLatestComments($this->itemnumber, 'all');
$items_zenpage = array();
if (function_exists('getLatestZenpageComments')) {
$items_zenpage = getLatestZenpageComments($this->itemnumber, 'all', $this->id);
$items = array_merge($items, $items_zenpage);
$items = sortMultiArray($items, 'date', true);
$items = array_slice($items, 0, $this->itemnumber);
}
break;
}
break;
}
if (isset($items)) {
return $items;
}
if (TEST_RELEASE) {
trigger_error(gettext('Bad ' . $this->feed . ' feed respectively no items available:' . $this->feedtype), E_USER_WARNING);
}
return NULL;
}
protected function getitemPages($item, $len) {
$obj = new ZenpagePage($item['titlelink']);
$feeditem['title'] = $feeditem['title'] = get_language_string($obj->getTitle('all'), $this->locale);
$feeditem['link'] = $obj->getLink();
$desc = $obj->getContent($this->locale);
$desc = str_replace('//<![CDATA[', '', $desc);
$desc = str_replace('//]]>', '', $desc);
$feeditem['desc'] = shortenContent($desc, $len, '...');
$feeditem['enclosure'] = '';
$feeditem['category'] = '';
$feeditem['media_content'] = '';
$feeditem['media_thumbnail'] = '';
$feeditem['pubdate'] = date("r", strtotime($obj->getDatetime()));
return zp_apply_filter('feed_page', $feeditem, $obj);
}
protected function getitemComments($item) {
if ($item['anon']) {
$author = "";
} else {
$author = " " . gettext("by") . " " . $item['name'];
}
$commentpath = $imagetag = $title = '';
$obj = null;
switch ($item['type']) {
case 'images':
$title = get_language_string($item['title']);
$obj = newImage(NULL, array('folder' => $item['folder'], 'filename' => $item['filename']));
$link = $obj->getlink();
$feeditem['pubdate'] = date("r", strtotime($item['date']));
$category = get_language_string($item['albumtitle']);
$website = $item['website'];
$title = $category . ": " . $title;
$commentpath = PROTOCOL . '://' . $this->host . $link . "#zp_comment_id_" . $item['id'];
break;
case 'albums':
$obj = newAlbum($item['folder']);
$link = rtrim($obj->getLink(), '/');
$feeditem['pubdate'] = date("r", strtotime($item['date']));
$title = get_language_string($item['albumtitle']);
$website = $item['website'];
$commentpath = PROTOCOL . '://' . $this->host . $link . "#zp_comment_id_" . $item['id'];
break;
case 'news':
case 'pages':
if (extensionEnabled('zenpage')) {
$album = '';
$feeditem['pubdate'] = date("r", strtotime($item['date']));
$category = '';
$title = get_language_string($item['title']);
$titlelink = $item['titlelink'];
$website = $item['website'];
if ($item['type'] == 'news') {
$obj = new ZenpageNews($titlelink);
} else {
$obj = new ZenpagePage($titlelink);
}
$commentpath = PROTOCOL . '://' . $this->host . html_encode($obj->getLink()) . "#zp_comment_id_" . $item['id'];
} else {
$commentpath = '';
}
break;
}
$feeditem['title'] = getBare($title . $author);
$feeditem['link'] = $commentpath;
$feeditem['desc'] = $item['comment'];
return zp_apply_filter('feed_comment', $feeditem, $item, $obj);
}
static protected function feed404() {
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
include(SERVERPATH . '/' . ZENFOLDER . '/404.php');
exitZP();
}
}