- Timestamp:
- 08/28/06 00:40:29 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/classes/Content/RssAggregator/RssAggregator.php
r1070 r1080 1 1 <?php 2 2 3 3 4 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ … … 46 47 * Load required class 47 48 */ 48 require_once ('classes/LocaleList.php');49 require_once ('classes/LocaleList.php'); 49 50 50 51 /** … … 61 62 * @copyright 2005-2006 Benoit Grégoire, Technologies Coeus inc. 62 63 */ 63 class RssAggregator extends Content 64 { 64 class RssAggregator extends Content { 65 65 /** 66 66 * @var string … … 90 90 * @access protected 91 91 */ 92 protected function __construct($content_id) 93 { 92 protected function __construct($content_id) { 94 93 // Define globals 95 94 global $db; … … 99 98 $content_rss_aggregator_rows = null; 100 99 101 parent ::__construct($content_id);100 parent :: __construct($content_id); 102 101 $content_id = $db->escapeString($content_id); 103 102 … … 110 109 $db->execSqlUniqueRes($sql, $row, false); 111 110 if ($row == null) { 112 throw new Exception(_("The RssAggregator content with the following id could not be found in the database: ") .$content_id);111 throw new Exception(_("The RssAggregator content with the following id could not be found in the database: ") . $content_id); 113 112 } 114 113 } … … 121 120 if ($content_rss_aggregator_rows != null) { 122 121 $this->content_rss_aggregator_feeds_rows = $content_rss_aggregator_rows; 123 } else { 122 } 123 else { 124 124 $this->content_rss_aggregator_feeds_rows = array (); 125 125 } 126 126 127 127 if (RSS_SUPPORT) { 128 require_once ('lib/RssPressReview/RssPressReview.php');128 require_once ('lib/RssPressReview/RssPressReview.php'); 129 129 130 130 $this->press_review = new RssPressReview(WIFIDOG_ABS_FILE_PATH . MAGPIE_REL_PATH, "UTF-8"); … … 138 138 // Update the stored feed title if it changed. 139 139 //This allows the system to know every feed's title without continuously looking them up 140 if(!empty($title) && $title!=$feed_row['title']) { 141 $title = $db->escapeString($title); 142 $url = $db->escapeString($feed_row['url']); 143 $db->execSqlUpdate("UPDATE content_rss_aggregator_feeds SET title = '$title' WHERE url='$url'", false); 144 $this->refresh(); 145 } 146 } 147 } else { 140 if (!empty ($title) && $title != $feed_row['title']) { 141 $title = $db->escapeString($title); 142 $url = $db->escapeString($feed_row['url']); 143 $db->execSqlUpdate("UPDATE content_rss_aggregator_feeds SET title = '$title' WHERE url='$url'", false); 144 $this->refresh(); 145 } 146 } 147 } 148 else { 148 149 $html = _("RSS support is disabled"); 149 150 } … … 159 160 * @access public 160 161 */ 161 public function getDisplayNumItems() 162 { 162 public function getDisplayNumItems() { 163 163 return $this->content_rss_aggregator_row['number_of_display_items']; 164 164 } … … 174 174 * @access public 175 175 */ 176 public function setDisplayNumItems($num_items, &$errormsg = null) 177 { 176 public function setDisplayNumItems($num_items, & $errormsg = null) { 178 177 // Init values 179 178 $retval = false; … … 190 189 191 190 $retval = true; 192 } elseif ($num_items < 1) { 191 } 192 elseif ($num_items < 1) { 193 193 $errormsg = _("You must display at least one element"); 194 194 195 195 $retval = false; 196 } else { 196 } 197 else { 197 198 /* 198 199 * Successfull, but nothing modified … … 212 213 * @access public 213 214 */ 214 public function getAlgorithmStrength() 215 { 215 public function getAlgorithmStrength() { 216 216 return $this->content_rss_aggregator_row['algorithm_strength']; 217 217 } … … 240 240 * @access public 241 241 */ 242 public function setAlgorithmStrength($strength, &$errormsg = null) 243 { 242 public function setAlgorithmStrength($strength, & $errormsg = null) { 244 243 // Init values 245 244 $retval = false; … … 256 255 257 256 $retval = true; 258 } else { 257 } 258 else { 259 259 /* 260 260 * Successfull, but nothing modified … … 272 272 * @access public 273 273 */ 274 public function getMaxItemAge() 275 { 274 public function getMaxItemAge() { 276 275 $retval = $this->content_rss_aggregator_row['max_item_age_seconds']; 277 276 … … 298 297 * @access public 299 298 */ 300 public function setMaxItemAge($max_item_age, &$errormsg = null) 301 { 299 public function setMaxItemAge($max_item_age, & $errormsg = null) { 302 300 // Init values 303 301 $retval = false; … … 322 320 323 321 $retval = true; 324 } elseif ($max_item_age <= 0) { 322 } 323 elseif ($max_item_age <= 0) { 325 324 $errormsg = _("The maximum age must be a positive integer or null"); 326 325 327 326 $retval = false; 328 } else { 327 } 328 else { 329 329 /* 330 330 * Successfull, but nothing modified … … 345 345 * @access public 346 346 */ 347 public function addFeed($url) 348 { 347 public function addFeed($url) { 349 348 // Define globals 350 349 global $db; … … 373 372 * @access public 374 373 */ 375 public function removeFeed($url) 376 { 374 public function removeFeed($url) { 377 375 // Define globals 378 376 global $db; … … 392 390 } 393 391 394 395 392 /** 396 393 * Shows the administration interface for RssAggregator … … 403 400 * @access public 404 401 */ 405 public function getAdminUI($subclass_admin_interface = null, $title=null) 406 { 402 public function getAdminUI($subclass_admin_interface = null, $title = null) { 407 403 // Define globals 408 404 global $db; … … 414 410 $i = 0; 415 411 416 417 412 $html .= "<ul class='admin_element_list'>\n"; 418 413 /* … … 420 415 */ 421 416 $html .= "<li class='admin_element_item_container'>\n"; 422 $html .= "<div class='admin_element_label'>" ._("Total number of items to display (from all feeds)").": </div>\n";417 $html .= "<div class='admin_element_label'>" . _("Total number of items to display (from all feeds)") . ": </div>\n"; 423 418 $html .= "<div class='admin_element_data'>\n"; 424 419 425 $name = "rss_aggregator_" .$this->id."_display_num_items";420 $name = "rss_aggregator_" . $this->id . "_display_num_items"; 426 421 $value = $this->getDisplayNumItems(); 427 422 $html .= "<input type='text' size='2' value='$value' name='$name'>\n"; … … 436 431 $html .= "<div class='admin_element_label'>\n"; 437 432 $html .= _("How much bonus feeds that do not publish as often get over feed that publish more often. 438 The default is 0.75, with a typical range between 0 and 1.439 At 0, you have a classic RSS aggregator, meaning the n most recent entries picked from all feeds440 will be displayed. 1 is usually as high as you'll want to go: Assuming that all441 an homogenous internal distribution (ex: one feed publishes exactly one entry a day, the442 second once every two days, and the third once every three days), and you ask for 15 entries,443 there will be 5 of each. While that may not sound usefull, it still is, as the feed's distribution is444 usually not homogenous.");433 The default is 0.75, with a typical range between 0 and 1. 434 At 0, you have a classic RSS aggregator, meaning the n most recent entries picked from all feeds 435 will be displayed. 1 is usually as high as you'll want to go: Assuming that all 436 an homogenous internal distribution (ex: one feed publishes exactly one entry a day, the 437 second once every two days, and the third once every three days), and you ask for 15 entries, 438 there will be 5 of each. While that may not sound usefull, it still is, as the feed's distribution is 439 usually not homogenous."); 445 440 $html .= ": </div>\n"; 446 441 $html .= "<div class='admin_element_data'>\n"; 447 442 448 $name = "rss_aggregator_" .$this->id."_algorithm_strength";443 $name = "rss_aggregator_" . $this->id . "_algorithm_strength"; 449 444 $value = $this->getAlgorithmStrength(); 450 445 $html .= "<input type='text' size='2' value='$value' name='$name'>\n"; … … 459 454 $html .= "<div class='admin_element_label'>\n"; 460 455 $html .= _("Set the oldest entries (in seconds) you are willing to see. Any entries older than this will not 461 be considered at all for display, even if it means that the configured number of items to be displayed isn't reached.462 It's only usefull if all your feed publish very rarely, and you don't want very old entries to show up.");456 be considered at all for display, even if it means that the configured number of items to be displayed isn't reached. 457 It's only usefull if all your feed publish very rarely, and you don't want very old entries to show up."); 463 458 $html .= ": </div>\n"; 464 459 $html .= "<div class='admin_element_data'>\n"; 465 460 466 $name = "rss_aggregator_" .$this->id."_max_item_age";461 $name = "rss_aggregator_" . $this->id . "_max_item_age"; 467 462 $value = $this->getMaxItemAge(); 468 463 $html .= "<input type='text' size='10' value='$value' name='$name'>\n"; … … 476 471 */ 477 472 $html .= "<li class='admin_element_item_container'>\n"; 478 $html .= "<div class='admin_element_label'>" ._("Feeds:")."</div>\n";473 $html .= "<div class='admin_element_label'>" . _("Feeds:") . "</div>\n"; 479 474 480 475 $html .= "<ul class='admin_element_list'>\n"; … … 491 486 * Delete feeds 492 487 */ 493 $name = "rss_aggregator_" .$this->id."_feed_".md5($feed_row['url'])."_delete";494 $html .= "<input type='submit' name='$name' value='" ._("Delete")."'>";488 $name = "rss_aggregator_" . $this->id . "_feed_" . md5($feed_row['url']) . "_delete"; 489 $html .= "<input type='submit' name='$name' value='" . _("Delete") . "'>"; 495 490 $html .= "</div>\n"; 496 491 $html .= "</li>\n"; … … 501 496 */ 502 497 $html .= "<li class='admin_element_item_container'>\n"; 503 $html .= "<b>" ._("Add a new feed or pick one from the other feeds in the system (most_popular_first)")."</b><br>";498 $html .= "<b>" . _("Add a new feed or pick one from the other feeds in the system (most_popular_first)") . "</b><br>"; 504 499 505 500 $sql = "SELECT count, content_rss_aggregator_feeds.url, title FROM content_rss_aggregator_feeds 506 JOIN (SELECT url, count(content_rss_aggregator_feeds.url) as count507 FROM content_rss_aggregator_feeds508 WHERE content_rss_aggregator_feeds.url NOT IN (SELECT url FROM content_rss_aggregator_feeds WHERE content_id='{$this->id}')509 GROUP BY content_rss_aggregator_feeds.content_id, content_rss_aggregator_feeds.url)510 AS available_feeds511 ON (available_feeds.url=content_rss_aggregator_feeds.url)512 ORDER by count DESC";501 JOIN (SELECT url, count(content_rss_aggregator_feeds.url) as count 502 FROM content_rss_aggregator_feeds 503 WHERE content_rss_aggregator_feeds.url NOT IN (SELECT url FROM content_rss_aggregator_feeds WHERE content_id='{$this->id}') 504 GROUP BY content_rss_aggregator_feeds.content_id, content_rss_aggregator_feeds.url) 505 AS available_feeds 506 ON (available_feeds.url=content_rss_aggregator_feeds.url) 507 ORDER by count DESC"; 513 508 514 509 $db->execSql($sql, $feed_urls, false); … … 516 511 foreach ($feed_urls as $feed_row) { 517 512 $tab[$i][0] = $feed_row['url']; 518 empty ($feed_row['title']) ? $title = $feed_row['url'] : $title = $feed_row['title'];513 empty ($feed_row['title']) ? $title = $feed_row['url'] : $title = $feed_row['title']; 519 514 $tab[$i][1] = sprintf(_("%s, used %d times"), $title, $feed_row['count']); 520 $i ++;515 $i++; 521 516 } 522 517 … … 526 521 527 522 $name = "rss_aggregator_{$this->id}_feed_add_button"; 528 $html .= "<input type='submit' name='$name' value='" ._("Add")."'>";523 $html .= "<input type='submit' name='$name' value='" . _("Add") . "'>"; 529 524 530 525 $html .= "</li>\n"; … … 534 529 $html .= $subclass_admin_interface; 535 530 536 return parent ::getAdminUI($html, $title);531 return parent :: getAdminUI($html, $title); 537 532 } 538 533 … … 544 539 * @access public 545 540 */ 546 public function processAdminUI() 547 { 541 public function processAdminUI() { 548 542 if ($this->isOwner(User :: getCurrentUser()) || User :: getCurrentUser()->isSuperAdmin()) { 549 parent ::processAdminUI();543 parent :: processAdminUI(); 550 544 551 545 /* 552 546 * number_of_display_items 553 547 */ 554 $name = "rss_aggregator_" .$this->id."_display_num_items";548 $name = "rss_aggregator_" . $this->id . "_display_num_items"; 555 549 $this->setDisplayNumItems($_REQUEST[$name]); 556 550 … … 558 552 * algorithm_strength 559 553 */ 560 $name = "rss_aggregator_" .$this->id."_algorithm_strength";554 $name = "rss_aggregator_" . $this->id . "_algorithm_strength"; 561 555 $this->setAlgorithmStrength($_REQUEST[$name]); 562 556 … … 564 558 * max_item_age 565 559 */ 566 $name = "rss_aggregator_" .$this->id."_max_item_age";560 $name = "rss_aggregator_" . $this->id . "_max_item_age"; 567 561 $this->setMaxItemAge($_REQUEST[$name]); 568 562 … … 582 576 * Delete feeds 583 577 */ 584 $name = "rss_aggregator_" .$this->id."_feed_".md5($feed_row['url'])."_delete";578 $name = "rss_aggregator_" . $this->id . "_feed_" . md5($feed_row['url']) . "_delete"; 585 579 586 580 if (isset ($_REQUEST[$name])) { … … 600 594 * @access private 601 595 */ 602 private function getFeedAdminUI($feed_row) 603 { 596 private function getFeedAdminUI($feed_row) { 604 597 // Init values 605 598 $html = ''; 606 599 $html .= "<ul class='admin_element_list'>\n"; 607 600 $html .= "<li class='admin_element_item_container'>\n"; 608 $html .= "<div class='admin_element_label'>" .$feed_row['title']."</div>\n";601 $html .= "<div class='admin_element_label'>" . $feed_row['title'] . "</div>\n"; 609 602 610 603 $html .= "<div class='admin_element_data'>\n"; … … 614 607 */ 615 608 $html .= "<li class='admin_element_item_container'>\n"; 616 $html .= "<div class='admin_element_label'>" ._("URL").": \n";617 618 if (!$this->press_review->isFeedAvailable($feed_row['url'])) {619 $html .= "<br/><span class='warningmsg'>" ._("WARNING: Either the feed couldn't be retrieved, or it couldn't be parsed. Please double check the URL.")."</span>";609 $html .= "<div class='admin_element_label'>" . _("URL") . ": \n"; 610 611 if (!$this->press_review->isFeedAvailable($feed_row['url'])) { 612 $html .= "<br/><span class='warningmsg'>" . _("WARNING: Either the feed couldn't be retrieved, or it couldn't be parsed. Please double check the URL.") . "</span>"; 620 613 } 621 614 … … 623 616 $html .= "<div class='admin_element_data'>\n"; 624 617 625 $name = "rss_aggregator_" .$this->id."_feed_".md5($feed_row['url'])."_url";618 $name = "rss_aggregator_" . $this->id . "_feed_" . md5($feed_row['url']) . "_url"; 626 619 $value = $feed_row['url']; 627 620 $html .= "<input type='text' size='60' value='$value' name='$name'>\n"; … … 638 631 if ($calculated_pub_interval == true) { 639 632 $html .= sprintf(_("The feed publishes an item every %.2f day(s)"), $calculated_pub_interval / (60 * 60 * 24)); 640 } else { 641 $html .= "<div class='admin_element_label'><span class='warningmsg'>"._("WARNING: This feed does not include the publication dates. 642 The system needs to be able to compute approximate publication 643 date for each entry, so the entry can be weighted against the 644 others. In order for the aggregator to do a good job, you need 645 to estimate fublication frequency of the items, in days. 646 If unset, defaults to one day.").": </span></div>\n"; 633 } 634 else { 635 $html .= "<div class='admin_element_label'><span class='warningmsg'>" . _("WARNING: This feed does not include the publication dates. 636 The system needs to be able to compute approximate publication 637 date for each entry, so the entry can be weighted against the 638 others. In order for the aggregator to do a good job, you need 639 to estimate fublication frequency of the items, in days. 640 If unset, defaults to one day.") . ": </span></div>\n"; 647 641 $html .= "<div class='admin_element_data'>\n"; 648 $name = "rss_aggregator_" .$this->id."_feed_".md5($feed_row['url'])."_default_publication_interval";642 $name = "rss_aggregator_" . $this->id . "_feed_" . md5($feed_row['url']) . "_default_publication_interval"; 649 643 650 644 if (!empty ($feed_row['default_publication_interval'])) { 651 645 $value = $feed_row['default_publication_interval'] / (60 * 60 * 24); 652 } else { 646 } 647 else { 653 648 $value = ''; 654 649 } … … 664 659 */ 665 660 $html .= "<li class='admin_element_item_container'>\n"; 666 $html .= "<div class='admin_element_label'>" ._("The bias to be given to the source by the selection algorithm.667 Bias must be > 0 , typical values would be between 0.75 and 1.5668 and default is 1 (no bias). A bias of 2 will cause the items669 to \"look\" twice as recent to the algorithm. A bias of 0.5 to670 look twice as old. Be carefull, a bias of 2 will statistically671 because the feed to have MORE than twice as many items displayed.").": </div>\n";661 $html .= "<div class='admin_element_label'>" . _("The bias to be given to the source by the selection algorithm. 662 Bias must be > 0 , typical values would be between 0.75 and 1.5 663 and default is 1 (no bias). A bias of 2 will cause the items 664 to \"look\" twice as recent to the algorithm. A bias of 0.5 to 665 look twice as old. Be carefull, a bias of 2 will statistically 666 cause the feed to have MORE than twice as many items displayed.") . ": </div>\n"; 672 667 $html .= "<div class='admin_element_data'>\n"; 673 668 674 $name = "rss_aggregator_" .$this->id."_feed_".md5($feed_row['url'])."_bias";669 $name = "rss_aggregator_" . $this->id . "_feed_" . md5($feed_row['url']) . "_bias"; 675 670 $value = $feed_row['bias']; 676 671 $html .= "<input type='text' size='60' value='$value' name='$name'>\n"; … … 693 688 * @access private 694 689 */ 695 private function processFeedAdminUI($feed_row) 696 { 690 private function processFeedAdminUI($feed_row) { 697 691 // Define globals 698 692 global $db; … … 703 697 * bias 704 698 */ 705 $name = "rss_aggregator_" .$this->id."_feed_".md5($feed_row['url'])."_bias";699 $name = "rss_aggregator_" . $this->id . "_feed_" . md5($feed_row['url']) . "_bias"; 706 700 $original_bias = $db->escapeString($feed_row['bias']); 707 701 $bias = $db->escapeString($_REQUEST[$name]); … … 713 707 $db->execSqlUpdate("UPDATE content_rss_aggregator_feeds SET bias = '$bias' WHERE content_id = '$this->id' AND url='$original_url'", false); 714 708 $this->refresh(); 715 } elseif (!is_numeric($bias) || $bias <= 0) { 709 } 710 elseif (!is_numeric($bias) || $bias <= 0) { 716 711 echo _("The bias must be a positive real number"); 717 } else { 712 } 713 else { 718 714 /* 719 715 * Successfull, but nothing modified … … 724 720 * default_publication_interval 725 721 */ 726 $name = "rss_aggregator_" .$this->id."_feed_".md5($feed_row['url'])."_default_publication_interval";722 $name = "rss_aggregator_" . $this->id . "_feed_" . md5($feed_row['url']) . "_default_publication_interval"; 727 723 728 724 if (isset ($_REQUEST[$name])) { … … 740 736 $db->execSqlUpdate("UPDATE content_rss_aggregator_feeds SET default_publication_interval = $default_publication_interval WHERE content_id = '$this->id' AND url='$original_url'", false); 741 737 $this->refresh(); 742 } elseif (!is_numeric($bias) || $bias <= 0) { 738 } 739 elseif (!is_numeric($bias) || $bias <= 0) { 743 740 echo _("The default publication must must be a positive integer or empty"); 744 } else { 741 } 742 else { 745 743 /* 746 744 * Successfull, but nothing modified … … 752 750 * URL, we must change it last or we won't find the row again 753 751 */ 754 $name = "rss_aggregator_" .$this->id."_feed_".md5($feed_row['url'])."_url";752 $name = "rss_aggregator_" . $this->id . "_feed_" . md5($feed_row['url']) . "_url"; 755 753 $url = $db->escapeString($_REQUEST[$name]); 756 754 … … 761 759 $db->execSqlUpdate("UPDATE content_rss_aggregator_feeds SET url = '$url' WHERE content_id = '$this->id' AND url='$original_url'", false); 762 760 $this->refresh(); 763 } elseif (empty ($url)) { 761 } 762 elseif (empty ($url)) { 764 763 echo _("The URL cannot be empty!"); 765 } else { 764 } 765 else { 766 766 /* 767 767 * Successfull, but nothing modified … … 777 777 * @access public 778 778 */ 779 public function getUserUI() 780 { 779 public function getUserUI() { 781 780 // Init values 782 781 $html = ''; 783 782 784 $html .= "<div class='user_ui_data " .get_class($this)."'>\n";783 $html .= "<div class='user_ui_data " . get_class($this) . "'>\n"; 785 784 786 785 if (RSS_SUPPORT) { … … 788 787 $html = $this->press_review->get_rss_html($this->content_rss_aggregator_row['number_of_display_items']); 789 788 } 790 791 789 catch (Exception $e) { 792 790 $html = sprintf(_("Could not get RSS feed: %s"), $feed_row['url']); 793 791 } 794 } else { 792 /* Handle hyperlink clicktrough logging */ 793 $html = $this->replaceHyperLinks($html); 794 795 } 796 else { 795 797 $html = _("RSS support is disabled"); 796 798 } … … 798 800 $html .= "</div>\n"; 799 801 800 return parent ::getUserUI($html);802 return parent :: getUserUI($html); 801 803 } 802 804 … … 813 815 * @access private 814 816 */ 815 private function refresh() 816 { 817 private function refresh() { 817 818 $this->__construct($this->id); 818 819 } … … 826 827 * End: 827 828 */ 828 829
