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: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764:
<?php
class PHPShopRssParser {
var $debug = false;
function __construct() {
global $PHPShopNav, $PHPShopSystem;
if ($PHPShopNav->index() and $PHPShopSystem->getSerilizeParam('admoption.rss_graber_enabled') == 1)
$this->rss_graber();
}
function utf8_win($s) {
if (function_exists('iconv')) {
$s = iconv("utf-8", "windows-1251", $s);
} else {
$s = strtr($s, array("\xD0\xB0" => "", "\xD0\x90" => "", "\xD0\xB1" => "", "\xD0\x91" => "", "\xD0\xB2" => "", "\xD0\x92" => "", "\xD0\xB3" => "", "\xD0\x93" => "", "\xD0\xB4" => "", "\xD0\x94" => "", "\xD0\xB5" => "", "\xD0\x95" => "", "\xD1\x91" => "", "\xD0\x81" => "", "\xD0\xB6" => "", "\xD0\x96" => "", "\xD0\xB7" => "", "\xD0\x97" => "", "\xD0\xB8" => "", "\xD0\x98" => "", "\xD0\xB9" => "", "\xD0\x99" => "", "\xD0\xBA" => "", "\xD0\x9A" => "", "\xD0\xBB" => "", "\xD0\x9B" => "", "\xD0\xBC" => "", "\xD0\x9C" => "", "\xD0\xBD" => "", "\xD0\x9D" => "", "\xD0\xBE" => "", "\xD0\x9E" => "", "\xD0\xBF" => "", "\xD0\x9F" => "", "\xD1\x80" => "", "\xD0\xA0" => "", "\xD1\x81" => "", "\xD0\xA1" => "", "\xD1\x82" => "", "\xD0\xA2" => "", "\xD1\x83" => "", "\xD0\xA3" => "", "\xD1\x84" => "", "\xD0\xA4" => "", "\xD1\x85" => "", "\xD0\xA5" => "", "\xD1\x86" => "", "\xD0\xA6" => "", "\xD1\x87" => "", "\xD0\xA7" => "", "\xD1\x88" => "", "\xD0\xA8" => "", "\xD1\x89" => "", "\xD0\xA9" => "", "\xD1\x8A" => "", "\xD0\xAA" => "", "\xD1\x8B" => "", "\xD0\xAB" => "", "\xD1\x8C" => "", "\xD0\xAC" => "", "\xD1\x8D" => "", "\xD0\xAD" => "", "\xD1\x8E" => "", "\xD0\xAE" => "", "\xD1\x8F" => "", "\xD0\xAF" => ""));
}
return $s;
}
function get_list() {
global $SysValue, $link_db;
$date1 = strtotime(date("Y-m-d"));
$date = time();
$sec_day = 86400;
$sql = "
SELECT f.link, f.id, f.news_num, s.date, f.day_num, f.last_load, count(s.id)
FROM " . $SysValue['base']['table_name38'] . " as f LEFT JOIN " . $SysValue['base']['table_name39'] . " as s
ON f.id = s.link_id AND s.status = '1' AND s.date > $date1
WHERE
f.enabled = '1' AND
f.start_date <= $date AND
f.end_date >= $date
GROUP BY f.id
HAVING COUNT(s.id) < f.day_num AND
($sec_day/(f.day_num+1)) < ($date - f.last_load)
";
$result = @mysqli_query($link_db, $sql);
return $result;
}
function parse_rss($link, $news_num) {
$rdf = new fase4_rdf;
$rdf->use_dynamic_display(false);
$rdf->set_max_item($news_num);
$temp = $rdf->parse_RDF($link);
$rdf->finish();
$rdf->clear_cache();
$nnn = $rdf->get_array_item();
if ($temp) {
return $nnn;
}
else
return false;
}
function add_rss_jurnal($link_id, $status, $last_date, $day_num) {
global $SysValue, $link_db;
if ($status) {
if ($last_date < strtotime(date("Y-m-d")))
$date = strtotime(date("Y-m-d")) + round(86400 / $day_num);
else
$date = $last_date + round(86400 / $day_num);
}
else
$date = time();
$sql = "
UPDATE " . $SysValue['base']['table_name38'] . "
set
last_load = '$date' WHERE id = '$link_id'
";
mysqli_query($link_db, $sql);
$sql = "
INSERT INTO " . $SysValue['base']['table_name39'] . "
VALUES ('','$date','$link_id','$status')
";
mysqli_query($link_db, $sql);
}
function add_news($news, $num) {
global $SysValue, $PHPShopModules, $link_db;
$date = date("d-m-Y");
$dateU = date("U");
for ($i = $num - 1; $i >= 0; $i--) {
$title = $this->utf8_win($news[$i]['title']);
$sql = "
SELECT id FROM " . $SysValue['base']['table_name8'] . "
WHERE title LIKE '$title' LIMIT 1
";
@$result = mysqli_query($link_db, @$sql);
@$n = mysqli_num_rows(@$result);
if (empty($n) and !empty($title)) {
$PHPShopOrm = new PHPShopOrm($SysValue['base']['table_name8']);
$PHPShopOrm->debug = $this->debug;
$description = $this->utf8_win($news[$i]['description']);
$content = $description . '<p><a href="' . $news[$i]['link'] . '';
$data_array = array('date_new' => $date, 'title_new' => $title, 'description_new' => $description, 'content_new' => $content, 'datau_new' => $dateU);
$PHPShopModules->setHookHandler(__CLASS__, __FUNCTION__, $this, array(&$data_array));
$PHPShopOrm->insert($data_array);
}
}
}
function rss_graber() {
global $SysValue, $link_db;
mysqli_query($link_db, "SET NAMES `cp1251`");
$sql = "SELECT rss_use FROM " . $SysValue['base']['table_name3'] . " WHERE 1";
$result = mysqli_query($link_db, $sql);
$row = mysqli_fetch_array($result);
if (!$row['rss_use']) {
$sql = "
UPDATE " . $SysValue['base']['table_name3'] . "
SET
rss_use = '1'
";
mysqli_query($link_db, $sql);
$result = $this->get_list();
if (!empty($result))
while ($row = @mysqli_fetch_array($result)) {
$news = $this->parse_rss($row['link'], $row['news_num']);
if ($news) {
$this->add_news($news, $row['news_num']);
$this->add_rss_jurnal($row['id'], 1, $row['last_load'], $row['day_num']);
}
else
$this->add_rss_jurnal($row['id'], 0, $row['last_load'], $row['day_num']);
}
}
$sql = "
UPDATE " . $SysValue['base']['table_name3'] . "
SET
rss_use = '0'
";
mysqli_query($link_db, $sql);
}
}
class fase4_rdf {
var $_link_target = "_blank";
var $_phost = "";
var $_pport = "";
var $_pname = "";
var $_ppasswd = "";
var $_use_proxy = false;
var $_use_proxy_auth = false;
var $_refresh = 0;
var $_cached_file = "";
var $_use_cached_file = false;
var $_cache_type = "";
var $_remote_file = "";
var $_cache_dir = "UserFiles/Files/";
var $_cache_dir_ok = false;
var $_type = "";
var $_display_opt = array();
var $_table_width = 400;
var $_use_dynamic_display = false;
var $_item_count = 0;
var $_max_count = false;
var $_array_channel = array();
var $_array_item = array();
var $_array_textinput = array();
var $_array_image = array();
var $_citem = array();
var $_cdepth = array();
var $_ctags = array("x");
var $_item = array();
var $_depth = array();
var $_tags = array("x");
var $gc_probability = 1;
var $_output = "";
function __construct() {
$this->_refresh = (time() - 1200);
}
function parse_RDF($rdf) {
unset($this->_array_item);
$this->_remote_file = $rdf;
$tmp = $this->cache();
unset($this->_output);
$this->_item_count = 0;
return $tmp;
}
function finish() {
flush();
$this->_garbage_collection();
}
function use_dynamic_display($bool) {
$this->_use_dynamic_display = $bool;
return true;
}
function _parse_xRDF($data) {
$this->_clear_Items();
$xml_parser = xml_parser_create();
xml_set_object($xml_parser, $this);
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "_startElement", "_endElement");
xml_set_character_data_handler($xml_parser, "_parseData");
if (!xml_parse($xml_parser, trim($data))) {
$this->_throw_exception(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)) . "<br /><br />Exception in function parse_RDF().");
}
xml_parser_free($xml_parser);
}
function set_refresh($seconds) {
$this->_refresh = (time() - $seconds);
return true;
}
function set_max_item($int) {
$this->_max_count = $int;
return true;
}
function set_CacheDir($dir) {
if (substr($dir, -1) != "/") {
$dir = $dir . "/";
}
$this->_cache_dir = $dir;
}
function _throw_exception($msg) {
return true;
}
function _clear_Items($array = "") {
$this->_item = array("title" => "", "link" => "", "description" => "", "url" => "");
}
function _clear_cItems($array = "") {
$this->_citem = array("title" => "", "link" => "", "description" => "", "url" => "");
}
function _startElement($parser, $name, $attrs) {
if ($name == "rss") {
$this->_type = "rss";
} elseif ($name == "rdf:RDF" OR $name == "rdf") {
$this->_type = "rdf";
}
if ($name == "channel" AND $this->_type != "rdf") {
$this->_parse_mode = "channel";
} elseif (($name == "item") || ($name == "image") || ($name == "textinput") || (($name == "channel") && ($this->_type != "rss"))) {
if ($this->_parse_mode == "channel") {
$this->_get_ChannelData($parser);
}
$this->_parse_mode = "all";
}
$this->_depth[$parser]++;
array_push($this->_tags, $name);
$this->_cdepth[$parser]++;
array_push($this->_ctags, $name);
}
function _get_ChannelData($parser) {
if (empty($this->_display_opt["channel"]) OR
$this->_display_opt["channel"] != "hidden") {
$this->_output .= "<tr><td>\n";
$this->_output .= '<table border="0" width="100%" class="fase4_rdf_meta" cellspacing="5" cellpadding="2">' . "\n";
$this->_output .= "<tr><td class=\"fase4_rdf\"><div class=\"fase4_rdf_title\">" . htmlspecialchars($this->_citem["title"]) . "</div></td></tr>\n";
$this->_output .= "<tr><td class=\"fase4_rdf\">" . strip_tags($this->_citem["description"], "<a>, <img>") . "</td></tr>\n";
$this->_output .= "<tr><td> </td></tr>\n";
$this->_output .= "<tr><td class=\"fase4_rdf\">\n";
if ($this->_display_opt["build"] != "hidden") {
if ($this->_citem["lastBuildDate"]) {
$this->_output .= "build: " . $this->_citem["lastBuildDate"] . "<br />";
}
}
if ($this->_display_opt["cache_update"] != "hidden" && ( $_update = $this->get_cache_update_time())) {
$this->_output .= "cache update: " . $_update . "<br />\n";
}
$this->_output .= "<a href=\"" . $this->_citem["link"] . "\" ";
if (isset($this->_link_target)) {
$this->_output .= "target=\"" . $this->_link_target . "\" ";
}
$this->_output .= ">" . $this->_cut_string($this->_citem["link"]) . "</a>";
$this->_output .= "</td></tr>\n";
$this->_output .= "</table></td></tr>";
}
$this->_array_channel = array("title" => $this->_citem["title"],
"link" => $this->_citem["link"],
"description" => $this->_citem["description"],
"lastBuildDate" => $this->_citem["lastBuildDate"]);
}
function _endElement($parser, $name) {
array_pop($this->_tags);
$this->_depth[$parser]--;
array_pop($this->_ctags);
$this->_cdepth[$parser]--;
switch ($name) {
case "item":
if (empty($this->_max_count) OR $this->_item_count < $this->_max_count) {
if ($this->_item["title"] != $this->_item["description"] AND $this->_item["description"]) {
$this->_output .= "<tr><td class=\"fase4_rdf\">" . strip_tags($this->_item["description"], "<a>, <img>") . "</td></tr>\n";
$this->_output .= "<tr><td class=\"fase4_rdf\"><a href=\"" . $this->_item["link"] . "\" ";
if (isset($this->_link_target)) {
$this->_output .= "target=\"" . $this->_link_target . "\" ";
}
$this->_output .= ">" . strip_tags($this->_item["title"], "<a>, <img>") . "</a></td></tr>\n";
$this->_output .= "<tr><td><hr noshade=\"noshade\" size=\"1\" /></td></tr>\n";
} else {
$this->_output .= "<tr><td class=\"fase4_rdf\">\n";
$this->_output .= "<a href=\"" . $this->_item["link"] . "\" ";
if (isset($this->_link_target)) {
$this->_output .= "target=\"" . $this->_link_target . "\" ";
}
$this->_output .= ">" . $this->_item["title"] . "</a></td></tr>\n";
}
$this->_array_item[] = array("title" => $this->_item["title"],
"link" => $this->_item["link"],
"description" => $this->_item["description"]);
++$this->_item_count;
}
$this->_clear_Items();
break;
case "image":
if ($this->_display_opt["image"] != "hidden" && $this->_item["url"]) {
$this->_output .= "<tr><td class=\"fase4_rdf\">\n";
$this->_output .= "<a href=\"" . $this->_item["link"] . "\" ";
if (isset($this->_link_target)) {
$this->_output .= "target=\"" . $this->_link_target . "\" ";
}
$this->_output .= "><img src=\"" . $this->_item["url"] . "\"";
if ($this->_item["width"] && $this->_item["height"]) {
$this->_output .= " width=\"" . $this->_item["width"] . "\" height=\"" . $this->_item["height"] . "\"";
}
$this->_output .= " alt=\"" . $this->_item["title"] . "\" border=\"0\" /></a></td></tr>\n";
$this->_array_image[] = array("url" => $this->_item["url"],
"link" => $this->_item["link"],
"width" => $this->_item["width"],
"height" => $this->_item["height"]);
$this->_clear_Items();
} elseif ($this->_display_opt["image"] == "hidden") {
$this->_clear_Items();
}
break;
case "channel":
if ($this->_display_opt["channel"] != "hidden" AND $this->_item["title"] != "") {
$this->_output .= "<tr><td>\n";
$this->_output .= '<table border="0" width="100%" class="fase4_rdf_meta" cellspacing="5" cellpadding="2">' . "\n";
$this->_output .= "<tr><td class=\"fase4_rdf\"><div class=\"fase4_rdf_title\">" . htmlspecialchars($this->_item["title"]) . "</div></td></tr>\n";
$this->_output .= "<tr><td class=\"fase4_rdf\">" . strip_tags($this->_item["description"], "<a>, <img>") . "</td></tr>\n";
$this->_output .= "<tr><td> </td></tr>\n";
$this->_output .= "<tr><td class=\"fase4_rdf\">\n";
if ($this->_display_opt["build"] != "hidden") {
if ($this->_item["lastBuildDate"]) {
$this->_output .= "build: " . $this->_item["lastBuildDate"] . "<br />";
}
}
if ($this->_display_opt["cache_update"] != "hidden" && ( $_update = $this->get_cache_update_time())) {
$this->_output .= "cache update: " . $_update . "<br />\n";
}
$this->_output .= "<a href=\"" . $this->_item["link"] . "\" ";
if (isset($this->_link_target)) {
$this->_output .= "target=\"" . $this->_link_target . "\" ";
}
$this->_output .= ">" . $this->_cut_string($this->_item["link"]) . "</a>\n";
$this->_output .= "</td></tr>\n";
$this->_output .= "</table></td></tr>\n";
}
$this->_array_channel = array("title" => $this->_item["title"],
"link" => $this->_item["link"],
"description" => $this->_item["description"],
"lastBuildDate" => $this->_item["lastBuildDate"]);
$this->_clear_Items();
$this->_clear_cItems();
break;
case "textinput":
if ($this->_display_opt["textinput"] != "hidden" && $this->_item["name"] && $this->_item["link"]) {
$this->_output .= "<tr><td class=\"fase4_rdf\">\n";
$this->_output .= "<form action=\"" . $this->_item["link"] . "\" ";
if (isset($this->_link_target)) {
$this->_output .= "target=\"" . $this->_link_target . "\" ";
}
$this->_output .= "method=\"get\">\n";
$this->_output .= "<div class=\"fase4_rdf_title\">" . $this->_item["title"] . "</div>";
$this->_output .= strip_tags($this->_item["description"], "<a>, <img>") . "<br><br>\n";
$this->_output .= "<input class=\"fase4_rdf_input\" type=\"text\" name=\"" . $this->_item["name"] . "\"> \n";
$this->_output .= "<input class=\"fase4_rdf_input\" type=\"submit\" value=\"go\">";
$this->_output .= "</form>\n";
$this->_output .= "</td></tr>\n";
$this->_array_textinput = array("title" => $this->_item["title"],
"name" => $this->_item["name"],
"link" => $this->_item["link"],
"description" => $this->_item["description"]);
$this->_clear_Items();
} elseif ($this->_display_opt["textinput"] == "hidden") {
$this->_clear_Items();
}
break;
}
}
function get_array_channel() {
return $this->_array_channel;
}
function get_array_item() {
return $this->_array_item;
}
function get_array_textinput() {
return $this->_array_textinput;
}
function get_array_image() {
return $this->_array_image;
}
function _parseData($parser, $text) {
$clean = preg_replace("/\s/", "", $text);
if ($clean) {
$text = preg_replace("/^\s+/", "", $text);
if ($this->_parse_mode == "all") {
if ($this->_item[$this->_tags[$this->_depth[$parser]]]) {
$this->_item[$this->_tags[$this->_depth[$parser]]] .= $text;
} else {
$this->_item[$this->_tags[$this->_depth[$parser]]] = $text;
}
} elseif ($this->_parse_mode == "channel") {
if ($this->_citem[$this->_ctags[$this->_cdepth[$parser]]]) {
$this->_citem[$this->_ctags[$this->_cdepth[$parser]]] .= $text;
} else {
$this->_citem[$this->_ctags[$this->_cdepth[$parser]]] = $text;
}
}
}
}
function set_Options($options = "") {
if (is_array($options)) {
$this->_display_opt = $options;
return true;
} else {
unset($this->_display_opt);
return false;
}
}
function set_table_width($width = 400) {
$this->_table_width = $width;
return true;
}
function get_Options() {
$options = array("image" => "If 'image' is set to \"hidden\" no image provided by the RDF Publisher will be displayed.",
"channel" => "If 'channel' is set to \"hidden\" the Channel Meta Data (i.e the Title and the short description regarding the RDF Publisher will not be displayed",
"textinput" => "If set to \"hidden\" no Input Form will be displayed",
"build" => "If set to \"hidden\" the Build Date (if provided) of the RDF File will not be displayed",
"cache_update" => "If set to \"hidden\" the Update Date/Time of the cached Rdf File will not be displayed");
return $options;
}
function cache() {
if (!$this->_cache_dir_ok) {
$this->_create_cache_dir();
}
if ($this->_use_dynamic_display == true) {
$this->_cached_file = md5("dynamic" . $this->_remote_file);
$this->_cache_type = "normal";
} else {
$this->_cached_file = md5($this->_remote_file);
$this->_cache_type = "fast";
}
$_cache_f = $this->_cache_dir . $this->_cached_file;
if ((!file_exists($_cache_f)) || (filemtime($_cache_f) < $this->_refresh) || (filesize($_cache_f) == 0)) {
$this->_use_cached_file = false;
clearstatcache();
if ($this->_use_dynamic_display == true) {
$_rdf = @implode(" ", $this->_rdf_data());
if (!$_rdf) {
return false;
}
$this->_parse_xRDF($_rdf);
$this->_update_cache($_rdf);
$data = $this->_output;
} else {
$_rdf = @implode(" ", $this->_rdf_data());
if (!$_rdf) {
return false;
}
$this->_parse_xRDF($_rdf);
$this->_update_cache($this->_output);
$data = $this->_output;
}
} else {
$this->_use_cached_file = true;
if ($this->_use_dynamic_display == true) {
$this->_parse_xRDF(implode(" ", file($_cache_f)));
$data = $this->_output;
} else {
$data = @implode(" ", file($_cache_f));
}
}
return true;
}
function _create_cache_dir() {
if (!@is_dir($this->_cache_dir)) {
$arr = explode("/", $this->_cache_dir);
$c = count($arr);
if ($arr[0] == "") {
$path = "/";
}
for ($i = 0; $i < $c; $i++) {
if ($arr[$i] != "") {
$path .= $arr[$i] . "/";
if (!@is_dir($path)) {
if (!@mkdir($path, 0777)) {
$this->_throw_exception("failed to create directory:<b>" . $this->_cache_dir . "</b>.<br /><br />Exception on Line: " . __LINE__);
return false;
}
}
}
}
$this->_cache_dir_ok = true;
return true;
} else {
$this->_cache_dir_ok = true;
return true;
}
}
function _update_cache($content = "") {
$_local = @fopen($this->_cache_dir . $this->_cached_file, "w");
if (!$_local) {
return false;
}
if (!fwrite($_local, $content)) {
$this->_throw_exception("Cannot write to: " . $this->_cached_file . "<br /><br />Exception at Line: " . __LINE__);
return false;
}
fclose($_local);
return true;
}
function get_cache_update_time() {
return (file_exists($this->_cache_dir . $this->_cached_file)) ? date("d.m.Y H:i:s", filemtime($this->_cache_dir . $this->_cached_file)) : "Cachemiss";
}
function get_CacheType() {
return $this->_cache_type;
}
function is_cachedFile() {
return $this->_use_cached_file;
}
function clear_cache() {
$dir = dir($this->_cache_dir);
while ($file = $dir->read()) {
if ($file != "." && $file != "..") {
if (!@unlink($dir->path . $file)) {
$this->_throw_exception(
"Unable to unlink " . $dir->path . $file
. "<br /><br />Exception at Line: " . __LINE__);
return false;
}
}
}
$dir->close();
return true;
}
function _cut_string($string, $str_len = "30") {
if (strlen(trim($string)) > $str_len) {
$string = substr(trim($string), 0, $str_len - 4);
$string .= " ...";
}
return $string;
}
function _garbage_collection() {
srand((double) microtime() * 1000000);
if (rand(1, 100) <= $this->gc_probability) {
$dir = dir($this->_cache_dir);
while ($file = $dir->read()) {
if ($file != "." AND $file != ".." AND filemtime($dir->path . $file) <= time() - $this->_refresh) {
@unlink($dir->path . $file);
}
}
$dir->close();
}
}
function set_proxy($phost, $pport) {
$this->_use_proxy = true;
if ($phost != "")
$this->_phost = $phost;
if ($pport != "")
$this->_pport = $pport;
}
function set_proxy_auth($pname, $ppasswd) {
$this->_use_proxy_auth = true;
if ($pname != "")
$this->_pname = $pname;
if ($ppasswd != "")
$this->_ppasswd = $ppasswd;
}
function _rdf_data() {
if ($this->_use_proxy == true) {
$fp = fsockopen($this->_phost, $this->_pport);
if (!$fp) {
$this->_throw_exception($this->_remote_file . " is not available with proxy");
} else {
if ($this->_use_proxy_auth == true) {
fputs($fp, "GET " . $this->_remote_file . " HTTP/1.0\r\n\r\n");
} else {
fputs($fp, "GET " . $this->_remote_file . " HTTP/1.0\r\nProxy-Authorization: Basic " . base64_encode("$this->_pname:$this->_ppasswd") . "\r\n\r\n");
}
}
for ($i = 0; !feof($fp); $i++) {
$usable_data[$i] = "";
$usable_data[$i] = fgets($fp, 4096);
if (($usable_data[$i][0] == "<" ) &&
($usable_data[$i][1] == "?" ) &&
($usable_data[$i][2] == "x" ) &&
($usable_data[$i][3] == "m" ) &&
($usable_data[$i][4] == "l" )) {
$usable_data[0] = $usable_data[$i];
$i = 1;
}
if ((
($usable_data[$i][0] == "<" ) &&
($usable_data[$i][1] == "r" ) &&
($usable_data[$i][2] == "d" ) &&
($usable_data[$i][3] == "f" ) &&
($usable_data[$i][4] == ":" )
) ||
(
($usable_data[$i][0] == "<" ) &&
($usable_data[$i][1] == "r" ) &&
($usable_data[$i][2] == "s" ) &&
($usable_data[$i][3] == "s" )
)
) {
$usable_data[1] = $usable_data[$i];
$usable_data[2] = "\n";
$i = 2;
}
}
fclose($fp);
return $usable_data;
} else {
return (file($this->_remote_file));
}
}
}
?>