- Timestamp:
- Sep 19, 2006, 12:51:09 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/feed.php
r1331 r1549 110 110 $user = mysql_fetch_array(pwg_query($query)); 111 111 } 112 else 113 { 114 echo l10n('Unknown feed identifier'); 115 exit();112 113 if ( empty($user) ) 114 { 115 page_not_found('Unknown/missing feed identifier'); 116 116 } 117 117 … … 127 127 include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php'); 128 128 129 $base_url = 'http://'.$_SERVER["HTTP_HOST"].cookie_path(); 130 if ( strrpos($base_url, '/') !== strlen($base_url)-1 ) 131 { 132 $base_url .= '/'; 133 } 134 $page['root_path']=$base_url; 135 129 136 $rss = new UniversalFeedCreator(); 130 137 131 $rss->title = $conf['gallery_title'] .', notifications';138 $rss->title = $conf['gallery_title']; 132 139 $rss->title.= ' (as '.$user['username'].')'; 133 140 … … 138 145 // +-----------------------------------------------------------------------+ 139 146 140 $news = news($user['last_check'], $dbnow );147 $news = news($user['last_check'], $dbnow, true); 141 148 142 149 if (count($news) > 0) 143 150 { 144 $item = new FeedItem(); 151 $item = new FeedItem(); 145 152 $item->title = sprintf(l10n('New on %s'), $dbnow); 146 153 $item->link = $conf['gallery_url']; 147 154 148 155 // content creation 149 156 $item->description = '<ul>'; … … 154 161 $item->description.= '</ul>'; 155 162 $item->descriptionHtmlSyndicated = true; 156 163 157 164 $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow)); 158 $item->author = 'PhpWebGallery notifier'; 159 165 $item->author = 'PhpWebGallery notifier'; 166 $item->guid= sprintf('%s', $dbnow);; 167 160 168 $rss->addItem($item); 161 } 162 163 $query = ' 169 170 $query = ' 164 171 UPDATE '.USER_FEED_TABLE.' 165 172 SET last_check = \''.$dbnow.'\' 166 173 WHERE id = \''.$_GET['feed'].'\' 167 174 ;'; 168 pwg_query($query); 175 pwg_query($query); 176 } 177 178 179 // build items for new images/albums 180 $query = ' 181 SELECT date_available, 182 COUNT(DISTINCT id) nb_images, 183 COUNT(DISTINCT category_id) nb_cats 184 FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id 185 WHERE category_id NOT IN ('.$user['forbidden_categories'].') 186 GROUP BY date_available 187 ORDER BY date_available DESC 188 LIMIT 0,5 189 ;'; 190 $result = pwg_query($query); 191 $dates = array(); 192 while ($row = mysql_fetch_array($result)) 193 { 194 array_push($dates, $row); 195 } 196 197 foreach($dates as $date_detail) 198 { // for each recent post date we create a feed item 199 $date = $date_detail['date_available']; 200 $exploded_date = explode_mysqldt($date); 201 $item = new FeedItem(); 202 $item->title = sprintf(l10n('%d new elements'), $date_detail['nb_images']); 203 $item->title .= ' ('.$lang['month'][(int)$exploded_date['month']].' '.$exploded_date['day'].')'; 204 $item->link = make_index_url( 205 array( 206 'chronology_field' => 'posted', 207 'chronology_style'=> 'monthly', 208 'chronology_view' => 'calendar', 209 'chronology_date' => explode('-', substr($date,0,10) ) 210 ) 211 ); 212 213 $item->description .= 214 '<a href="'.make_index_url().'">'.$conf['gallery_title'].'</a><br/> '; 215 216 $item->description .= 217 '<li>' 218 .sprintf(l10n('%d new elements'), $date_detail['nb_images']) 219 .' (' 220 .'<a href="'.make_index_url(array('section'=>'recent_pics')).'">' 221 .l10n('recent_pics_cat').'</a>' 222 .')' 223 .'</li>'; 224 225 // get some thumbnails ... 226 $query = ' 227 SELECT DISTINCT id, path, name, tn_ext 228 FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id 229 WHERE category_id NOT IN ('.$user['forbidden_categories'].') 230 AND date_available="'.$date.'" 231 AND tn_ext IS NOT NULL 232 LIMIT 0,6 233 ;'; 234 $result = pwg_query($query); 235 while ($row = mysql_fetch_array($result)) 236 { 237 $tn_src = get_thumbnail_src($row['path'], @$row['tn_ext']); 238 $item->description .= '<img src="'.$tn_src.'"/>'; 239 } 240 $item->description .= '...<br/>'; 241 242 243 $item->description .= 244 '<li>' 245 .sprintf(l10n('%d categories updated'), $date_detail['nb_cats']) 246 .'</li>'; 247 // get some categories ... 248 $query = ' 249 SELECT DISTINCT c.uppercats, COUNT(DISTINCT i.id) img_count 250 FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id 251 INNER JOIN '.CATEGORIES_TABLE.' c ON c.id=category_id 252 WHERE category_id NOT IN ('.$user['forbidden_categories'].') 253 AND date_available="'.$date.'" 254 GROUP BY category_id 255 ORDER BY img_count DESC 256 LIMIT 0,6 257 ;'; 258 $result = pwg_query($query); 259 $item->description .= '<ul>'; 260 while ($row = mysql_fetch_array($result)) 261 { 262 $item->description .= 263 '<li>' 264 .get_cat_display_name_cache($row['uppercats']) 265 .' ('.sprintf(l10n('%d new elements'), $row['img_count']).')' 266 .'</li>'; 267 } 268 $item->description .= '</ul>'; 269 270 $item->descriptionHtmlSyndicated = true; 271 272 $item->date = ts_to_iso8601(mysqldt_to_ts($date)); 273 $item->author = 'PhpWebGallery notifier'; 274 $item->guid= sprintf('%s', 'pics-'.$date);; 275 276 $rss->addItem($item); 277 } 169 278 170 279 // send XML feed -
trunk/include/feedcreator.class.php
r801 r1549 79 79 added support for mbox 80 80 tentative support for echo/necho/atom/pie/??? 81 81 82 82 v1.2 07-20-03 83 83 intelligent auto-truncating of RSS 0.91 attributes … … 101 101 /*** GENERAL USAGE ********************************************************* 102 102 103 include("feedcreator.class.php"); 104 105 $rss = new UniversalFeedCreator(); 103 include("feedcreator.class.php"); 104 105 $rss = new UniversalFeedCreator(); 106 106 $rss->useCached(); // use cached version if age<1 hour 107 $rss->title = "PHP news"; 108 $rss->description = "daily news from the PHP scripting world"; 107 $rss->title = "PHP news"; 108 $rss->description = "daily news from the PHP scripting world"; 109 109 110 110 //optional … … 112 112 $rss->descriptionHtmlSyndicated = true; 113 113 114 $rss->link = "http://www.dailyphp.net/news"; 115 $rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"]; 116 117 $image = new FeedImage(); 118 $image->title = "dailyphp.net logo"; 119 $image->url = "http://www.dailyphp.net/images/logo.gif"; 120 $image->link = "http://www.dailyphp.net"; 121 $image->description = "Feed provided by dailyphp.net. Click to visit."; 114 $rss->link = "http://www.dailyphp.net/news"; 115 $rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"]; 116 117 $image = new FeedImage(); 118 $image->title = "dailyphp.net logo"; 119 $image->url = "http://www.dailyphp.net/images/logo.gif"; 120 $image->link = "http://www.dailyphp.net"; 121 $image->description = "Feed provided by dailyphp.net. Click to visit."; 122 122 123 123 //optional … … 125 125 $image->descriptionHtmlSyndicated = true; 126 126 127 $rss->image = $image; 128 129 // get your news items from somewhere, e.g. your database: 130 mysql_select_db($dbHost, $dbUser, $dbPass); 131 $res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); 132 while ($data = mysql_fetch_object($res)) { 133 $item = new FeedItem(); 134 $item->title = $data->title; 135 $item->link = $data->url; 136 $item->description = $data->short; 137 127 $rss->image = $image; 128 129 // get your news items from somewhere, e.g. your database: 130 mysql_select_db($dbHost, $dbUser, $dbPass); 131 $res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); 132 while ($data = mysql_fetch_object($res)) { 133 $item = new FeedItem(); 134 $item->title = $data->title; 135 $item->link = $data->url; 136 $item->description = $data->short; 137 138 138 //optional 139 139 item->descriptionTruncSize = 500; 140 140 item->descriptionHtmlSyndicated = true; 141 141 142 $item->date = $data->newsdate; 143 $item->source = "http://www.dailyphp.net"; 144 $item->author = "John Doe"; 145 146 $rss->addItem($item); 147 } 142 $item->date = $data->newsdate; 143 $item->source = "http://www.dailyphp.net"; 144 $item->author = "John Doe"; 145 146 $rss->addItem($item); 147 } 148 148 149 149 // valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated), … … 180 180 */ 181 181 var $title, $description, $link; 182 182 183 183 /** 184 184 * Optional attributes of an item. 185 185 */ 186 186 var $author, $authorEmail, $image, $category, $comments, $guid, $source, $creator; 187 187 188 188 /** 189 189 * Publishing date of an item. May be in one of the following formats: … … 200 200 */ 201 201 var $date; 202 202 203 203 /** 204 204 * Any additional elements to include as an assiciated array. All $key => $value pairs … … 227 227 */ 228 228 var $title, $url, $link; 229 229 230 230 /** 231 231 * Optional attributes of an image. … … 245 245 */ 246 246 var $descriptionHtmlSyndicated; 247 247 248 248 /** 249 249 * Indicates whether and to how many characters a description should be truncated. 250 250 */ 251 251 var $descriptionTruncSize; 252 252 253 253 /** 254 254 * Returns a formatted description field, depending on descriptionHtmlSyndicated and 255 255 * $descriptionTruncSize properties 256 * @return string the formatted description 256 * @return string the formatted description 257 257 */ 258 258 function getDescription() { … … 268 268 /** 269 269 * An FeedHtmlField describes and generates 270 * a feed, item or image html field (probably a description). Output is 270 * a feed, item or image html field (probably a description). Output is 271 271 * generated based on $truncSize, $syndicateHtml properties. 272 272 * @author Pascal Van Hecke <feedcreator.class.php@vanhecke.info> … … 278 278 */ 279 279 var $rawFieldContent; 280 280 281 281 /** 282 282 * Optional attributes of a FeedHtmlField. 283 * 283 * 284 284 */ 285 285 var $truncSize, $syndicateHtml; 286 286 287 287 /** 288 288 * Creates a new instance of FeedHtmlField. … … 294 294 } 295 295 } 296 297 296 297 298 298 /** 299 299 * Creates the right output, depending on $truncSize, $syndicateHtml properties. … … 301 301 */ 302 302 function output() { 303 // when field available and syndicated in html we assume 303 // when field available and syndicated in html we assume 304 304 // - valid html in $rawFieldContent and we enclose in CDATA tags 305 305 // - no truncation (truncating risks producing invalid html) … … 333 333 class UniversalFeedCreator extends FeedCreator { 334 334 var $_feed; 335 335 336 336 function _setFormat($format) { 337 337 switch (strtoupper($format)) { 338 338 339 339 case "2.0": 340 340 // fall through … … 342 342 $this->_feed = new RSSCreator20(); 343 343 break; 344 344 345 345 case "1.0": 346 346 // fall through … … 348 348 $this->_feed = new RSSCreator10(); 349 349 break; 350 350 351 351 case "0.91": 352 352 // fall through … … 354 354 $this->_feed = new RSSCreator091(); 355 355 break; 356 356 357 357 case "PIE0.1": 358 358 $this->_feed = new PIECreator01(); 359 359 break; 360 360 361 361 case "MBOX": 362 362 $this->_feed = new MBOXCreator(); 363 363 break; 364 364 365 365 case "OPML": 366 366 $this->_feed = new OPMLCreator(); 367 367 break; 368 368 369 369 case "ATOM": 370 370 // fall through: always the latest ATOM version 371 371 372 372 case "ATOM0.3": 373 373 $this->_feed = new AtomCreator03(); 374 374 break; 375 375 376 376 case "HTML": 377 377 $this->_feed = new HTMLCreator(); 378 378 break; 379 379 380 380 case "JS": 381 381 // fall through … … 383 383 $this->_feed = new JSCreator(); 384 384 break; 385 385 386 386 default: 387 387 $this->_feed = new RSSCreator091(); 388 388 break; 389 389 } 390 390 391 391 $vars = get_object_vars($this); 392 392 foreach ($vars as $key => $value) { … … 397 397 } 398 398 } 399 399 400 400 /** 401 401 * Creates a syndication feed based on the items previously added. … … 410 410 return $this->_feed->createFeed(); 411 411 } 412 413 414 412 413 414 415 415 /** 416 416 * Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect 417 417 * header may be sent to redirect the use to the newly created file. 418 418 * @since 1.4 419 * 419 * 420 420 * @param string format format the feed should comply to. Valid values are: 421 421 * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", "ATOM0.3", "HTML", "JS" … … 463 463 */ 464 464 var $title, $description, $link; 465 466 465 466 467 467 /** 468 468 * Optional attributes of a feed. … … 475 475 */ 476 476 var $xslStyleSheet = ""; 477 478 477 478 479 479 /** 480 480 * @access private 481 481 */ 482 482 var $items = Array(); 483 484 483 484 485 485 /** 486 486 * This feed's MIME content type. … … 489 489 */ 490 490 var $contentType = "application/xml"; 491 492 491 492 493 493 /** 494 494 * This feed's character encoding. … … 496 496 **/ 497 497 var $encoding = "ISO-8859-1"; 498 499 498 499 500 500 /** 501 501 * Any additional elements to include as an assiciated array. All $key => $value pairs … … 507 507 */ 508 508 var $additionalElements = Array(); 509 510 509 510 511 511 /** 512 512 * Adds an FeedItem to the feed. … … 518 518 $this->items[] = $item; 519 519 } 520 521 520 521 522 522 /** 523 523 * Truncates a string to a certain length at the most sensible point. … … 526 526 * If the string is truncated, " ..." is appended. 527 527 * If the string is already shorter than $length, it is returned unchanged. 528 * 528 * 529 529 * @static 530 530 * @param string string A string to be truncated. … … 536 536 return $string; 537 537 } 538 538 539 539 $pos = strrpos($string,"."); 540 540 if ($pos>=$length-4) { … … 545 545 return substr($string,0,$pos+1)." ..."; 546 546 } 547 547 548 548 $pos = strrpos($string," "); 549 549 if ($pos>=$length-4) { … … 554 554 return substr($string,0,$pos)." ..."; 555 555 } 556 556 557 557 return substr($string,0,$length-4)." ..."; 558 559 } 560 561 558 559 } 560 561 562 562 /** 563 563 * Creates a comment indicating the generator of this feed. … … 568 568 return "<!-- generator=\"".FEEDCREATOR_VERSION."\" -->\n"; 569 569 } 570 571 570 571 572 572 /** 573 573 * Creates a string containing all additional elements specified in … … 586 586 return $ae; 587 587 } 588 588 589 589 function _createStylesheetReferences() { 590 590 $xml = ""; … … 593 593 return $xml; 594 594 } 595 596 595 596 597 597 /** 598 598 * Builds the feed's text. 599 599 * @abstract 600 * @return string the feed's complete text 600 * @return string the feed's complete text 601 601 */ 602 602 function createFeed() { 603 603 } 604 604 605 605 /** 606 606 * Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml. 607 607 * For example: 608 * 608 * 609 609 * echo $_SERVER["PHP_SELF"]."\n"; 610 610 * echo FeedCreator::_generateFilename(); 611 * 611 * 612 612 * would produce: 613 * 613 * 614 614 * /rss/latestnews.php 615 615 * latestnews.xml … … 623 623 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml"; 624 624 } 625 626 625 626 627 627 /** 628 628 * @since 1.4 … … 631 631 function _redirect($filename) { 632 632 // attention, heavily-commented-out-area 633 633 634 634 // maybe use this in addition to file time checking 635 635 //Header("Expires: ".date("r",time()+$this->_timeout)); 636 636 637 637 /* no caching at all, doesn't seem to work as good: 638 638 Header("Cache-Control: no-cache"); 639 639 Header("Pragma: no-cache"); 640 640 */ 641 641 642 642 // HTTP redirect, some feed readers' simple HTTP implementations don't follow it 643 643 //Header("Location: ".$filename); … … 648 648 die(); 649 649 } 650 650 651 651 /** 652 652 * Turns on caching and checks if there is a recent version of this feed in the cache. … … 668 668 } 669 669 } 670 671 670 671 672 672 /** 673 673 * Saves this feed as a file on the local disk. After the file is saved, a redirect 674 674 * header may be sent to redirect the user to the newly created file. 675 675 * @since 1.4 676 * 676 * 677 677 * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). 678 678 * @param redirect boolean optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. … … 693 693 } 694 694 } 695 695 696 696 } 697 697 … … 703 703 class FeedDate { 704 704 var $unix; 705 705 706 706 /** 707 707 * Creates a new instance of FeedDate representing a given date. … … 711 711 function FeedDate($dateString="") { 712 712 if ($dateString=="") $dateString = date("r"); 713 713 714 714 if (is_integer($dateString)) { 715 715 $this->unix = $dateString; … … 767 767 return $date; 768 768 } 769 769 770 770 /** 771 771 * Gets the date stored in this FeedDate as an ISO 8601 date. … … 779 779 return $date; 780 780 } 781 781 782 782 /** 783 783 * Gets the date stored in this FeedDate as unix time stamp. … … 803 803 * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. 804 804 * The feed will contain all items previously added in the same order. 805 * @return string the feed's complete text 806 */ 807 function createFeed() { 805 * @return string the feed's complete text 806 */ 807 function createFeed() { 808 808 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; 809 809 $feed.= $this->_createGeneratorComment(); … … 814 814 $feed.= "<rdf:RDF\n"; 815 815 $feed.= " xmlns=\"http://purl.org/rss/1.0/\"\n"; 816 $feed.= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; 816 $feed.= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; 817 817 $feed.= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n"; 818 818 $feed.= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"; … … 842 842 } 843 843 $feed.= $this->_createAdditionalElements($this->additionalElements, " "); 844 844 845 845 for ($i=0;$i<count($this->items);$i++) { 846 846 $feed.= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n"; … … 889 889 $this->contentType = "application/rss+xml"; 890 890 } 891 891 892 892 /** 893 893 * Sets this RSS feed's version number. … … 901 901 * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. 902 902 * The feed will contain all items previously added in the same order. 903 * @return string the feed's complete text 903 * @return string the feed's complete text 904 904 */ 905 905 function createFeed() { … … 907 907 $feed.= $this->_createGeneratorComment(); 908 908 $feed.= $this->_createStylesheetReferences(); 909 $feed.= "<rss version=\"".$this->RSSVersion."\">\n"; 909 $feed.= "<rss version=\"".$this->RSSVersion."\">\n"; 910 910 $feed.= " <channel>\n"; 911 911 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n"; … … 919 919 if ($this->image!=null) { 920 920 $feed.= " <image>\n"; 921 $feed.= " <url>".$this->image->url."</url>\n"; 922 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n"; 921 $feed.= " <url>".$this->image->url."</url>\n"; 922 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n"; 923 923 $feed.= " <link>".$this->image->link."</link>\n"; 924 924 if ($this->image->width!="") { … … 974 974 $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; 975 975 $feed.= " <description>".$this->items[$i]->getDescription()."</description>\n"; 976 976 977 977 if ($this->items[$i]->author!="") { 978 978 $feed.= " <author>".htmlspecialchars($this->items[$i]->author)."</author>\n"; … … 995 995 } 996 996 if ($this->items[$i]->guid!="") { 997 $feed.= " <guid >".htmlspecialchars($this->items[$i]->guid)."</guid>\n";997 $feed.= " <guid isPermaLink=\"false\">".htmlspecialchars($this->items[$i]->guid)."</guid>\n"; 998 998 } 999 999 $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); … … 1020 1020 parent::_setRSSVersion("2.0"); 1021 1021 } 1022 1022 1023 1023 } 1024 1024 … … 1033 1033 */ 1034 1034 class PIECreator01 extends FeedCreator { 1035 1035 1036 1036 function PIECreator01() { 1037 1037 $this->encoding = "utf-8"; 1038 1038 } 1039 1039 1040 1040 function createFeed() { 1041 1041 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; 1042 1042 $feed.= $this->_createStylesheetReferences(); 1043 $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n"; 1043 $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n"; 1044 1044 $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n"; 1045 1045 $this->truncSize = 500; … … 1082 1082 * 1083 1083 * Some elements have not been implemented yet. These are (incomplete list): 1084 * author URL, item author's email and URL, item contents, alternate links, 1084 * author URL, item author's email and URL, item contents, alternate links, 1085 1085 * other link content types than text/html. Some of them may be created with 1086 1086 * AtomCreator03::additionalElements. … … 1096 1096 $this->encoding = "utf-8"; 1097 1097 } 1098 1098 1099 1099 function createFeed() { 1100 1100 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; … … 1105 1105 $feed.= " xml:lang=\"".$this->language."\""; 1106 1106 } 1107 $feed.= ">\n"; 1107 $feed.= ">\n"; 1108 1108 $feed.= " <title>".htmlspecialchars($this->title)."</title>\n"; 1109 1109 $feed.= " <tagline>".htmlspecialchars($this->description)."</tagline>\n"; … … 1164 1164 $this->encoding = "ISO-8859-15"; 1165 1165 } 1166 1167 function qp_enc($input = "", $line_max = 76) { 1168 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 1169 $lines = preg_split("/(?:\r\n|\r|\n)/", $input); 1170 $eol = "\r\n"; 1171 $escape = "="; 1172 $output = ""; 1173 while( list(, $line) = each($lines) ) { 1174 //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary 1175 $linlen = strlen($line); 1176 $newline = ""; 1177 for($i = 0; $i < $linlen; $i++) { 1178 $c = substr($line, $i, 1); 1179 $dec = ord($c); 1180 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only 1181 $c = "=20"; 1182 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 1183 $h2 = floor($dec/16); $h1 = floor($dec%16); 1184 $c = $escape.$hex["$h2"].$hex["$h1"]; 1185 } 1186 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted 1187 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay 1188 $newline = ""; 1189 } 1190 $newline .= $c; 1191 } // end of for 1192 $output .= $newline.$eol; 1193 } 1194 return trim($output); 1195 } 1196 1166 1167 function qp_enc($input = "", $line_max = 76) { 1168 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 1169 $lines = preg_split("/(?:\r\n|\r|\n)/", $input); 1170 $eol = "\r\n"; 1171 $escape = "="; 1172 $output = ""; 1173 while( list(, $line) = each($lines) ) { 1174 //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary 1175 $linlen = strlen($line); 1176 $newline = ""; 1177 for($i = 0; $i < $linlen; $i++) { 1178 $c = substr($line, $i, 1); 1179 $dec = ord($c); 1180 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only 1181 $c = "=20"; 1182 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 1183 $h2 = floor($dec/16); $h1 = floor($dec%16); 1184 $c = $escape.$hex["$h2"].$hex["$h1"]; 1185 } 1186 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted 1187 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay 1188 $newline = ""; 1189 } 1190 $newline .= $c; 1191 } // end of for 1192 $output .= $newline.$eol; 1193 } 1194 return trim($output); 1195 } 1196 1197 1197 1198 1198 /** 1199 1199 * Builds the MBOX contents. 1200 * @return string the feed's complete text 1200 * @return string the feed's complete text 1201 1201 */ 1202 1202 function createFeed() { … … 1224 1224 return $feed; 1225 1225 } 1226 1226 1227 1227 /** 1228 1228 * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types. … … 1240 1240 /** 1241 1241 * OPMLCreator is a FeedCreator that implements OPML 1.0. 1242 * 1242 * 1243 1243 * @see http://opml.scripting.com/spec 1244 1244 * @author Dirk Clemens, Kai Blankenhorn … … 1250 1250 $this->encoding = "utf-8"; 1251 1251 } 1252 1253 function createFeed() { 1252 1253 function createFeed() { 1254 1254 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; 1255 1255 $feed.= $this->_createGeneratorComment(); … … 1292 1292 1293 1293 /** 1294 * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific 1294 * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific 1295 1295 * location, overriding the createFeed method of the parent FeedCreator. 1296 1296 * The HTML produced can be included over http by scripting languages, or serve 1297 1297 * as the source for an IFrame. 1298 1298 * All output by this class is embedded in <div></div> tags to enable formatting 1299 * using CSS. 1299 * using CSS. 1300 1300 * 1301 1301 * @author Pascal Van Hecke … … 1305 1305 1306 1306 var $contentType = "text/html"; 1307 1307 1308 1308 /** 1309 1309 * Contains HTML to be output at the start of the feed's html representation. 1310 1310 */ 1311 1311 var $header; 1312 1312 1313 1313 /** 1314 1314 * Contains HTML to be output at the end of the feed's html representation. 1315 1315 */ 1316 1316 var $footer ; 1317 1318 /** 1319 * Contains HTML to be output between entries. A separator is only used in 1317 1318 /** 1319 * Contains HTML to be output between entries. A separator is only used in 1320 1320 * case of multiple entries. 1321 1321 */ 1322 1322 var $separator; 1323 1324 /** 1325 * Used to prefix the stylenames to make sure they are unique 1323 1324 /** 1325 * Used to prefix the stylenames to make sure they are unique 1326 1326 * and do not clash with stylenames on the users' page. 1327 1327 */ 1328 1328 var $stylePrefix; 1329 1329 1330 1330 /** 1331 1331 * Determines whether the links open in a new window or not. 1332 1332 */ 1333 1333 var $openInNewWindow = true; 1334 1334 1335 1335 var $imageAlign ="right"; 1336 1336 1337 1337 /** 1338 1338 * In case of very simple output you may want to get rid of the style tags, 1339 * hence this variable. There's no equivalent on item level, but of course you can 1339 * hence this variable. There's no equivalent on item level, but of course you can 1340 1340 * add strings to it while iterating over the items ($this->stylelessOutput .= ...) 1341 1341 * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored … … 1346 1346 /** 1347 1347 * Writes the HTML. 1348 * @return string the scripts's complete text 1348 * @return string the scripts's complete text 1349 1349 */ 1350 1350 function createFeed() { … … 1353 1353 return $this->stylelessOutput; 1354 1354 } 1355 1355 1356 1356 //if no stylePrefix is set, generate it yourself depending on the script name 1357 1357 if ($this->stylePrefix=="") { … … 1363 1363 $targetInsert = " target='_blank'"; 1364 1364 } 1365 1365 1366 1366 // use this array to put the lines in and implode later with "document.write" javascript 1367 1367 $feedArray = array(); … … 1380 1380 $feedArray[] = $imageStr; 1381 1381 } 1382 1382 1383 1383 if ($this->title) { 1384 1384 $feedArray[] = "<div class='".$this->stylePrefix."title'><a href='".$this->link."' ".$targetInsert." class='".$this->stylePrefix."title'>". … … 1390 1390 "</div>"; 1391 1391 } 1392 1392 1393 1393 if ($this->header) { 1394 1394 $feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>"; 1395 1395 } 1396 1396 1397 1397 for ($i=0;$i<count($this->items);$i++) { 1398 1398 if ($this->separator and $i > 0) { 1399 1399 $feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>"; 1400 1400 } 1401 1401 1402 1402 if ($this->items[$i]->title) { 1403 1403 if ($this->items[$i]->link) { 1404 $feedArray[] = 1404 $feedArray[] = 1405 1405 "<div class='".$this->stylePrefix."item_title'><a href='".$this->items[$i]->link."' class='".$this->stylePrefix. 1406 1406 "item_title'".$targetInsert.">".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100). 1407 1407 "</a></div>"; 1408 1408 } else { 1409 $feedArray[] = 1409 $feedArray[] = 1410 1410 "<div class='".$this->stylePrefix."item_title'>". 1411 1411 FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100). … … 1414 1414 } 1415 1415 if ($this->items[$i]->getDescription()) { 1416 $feedArray[] = 1416 $feedArray[] = 1417 1417 "<div class='".$this->stylePrefix."item_description'>". 1418 1418 str_replace("]]>", "", str_replace("<![CDATA[", "", $this->items[$i]->getDescription())). … … 1423 1423 $feedArray[] = "<div class='".$this->stylePrefix."footer'>".$this->footer."</div>"; 1424 1424 } 1425 1425 1426 1426 $feed= "".join($feedArray, "\r\n"); 1427 1427 return $feed; 1428 1428 } 1429 1429 1430 1430 /** 1431 1431 * Overrrides parent to produce .html extensions … … 1439 1439 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html"; 1440 1440 } 1441 } 1442 1443 1444 /** 1445 * JSCreator is a class that writes a js file to a specific 1441 } 1442 1443 1444 /** 1445 * JSCreator is a class that writes a js file to a specific 1446 1446 * location, overriding the createFeed method of the parent HTMLCreator. 1447 1447 * … … 1450 1450 class JSCreator extends HTMLCreator { 1451 1451 var $contentType = "text/javascript"; 1452 1452 1453 1453 /** 1454 1454 * writes the javascript 1455 * @return string the scripts's complete text 1456 */ 1457 function createFeed() 1455 * @return string the scripts's complete text 1456 */ 1457 function createFeed() 1458 1458 { 1459 1459 $feed = parent::createFeed(); 1460 1460 $feedArray = explode("\n",$feed); 1461 1461 1462 1462 $jsFeed = ""; 1463 1463 foreach ($feedArray as $value) { … … 1466 1466 return $jsFeed; 1467 1467 } 1468 1468 1469 1469 /** 1470 1470 * Overrrides parent to produce .js extensions … … 1478 1478 return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js"; 1479 1479 } 1480 1481 } 1480 1481 } 1482 1482 1483 1483 … … 1485 1485 /*** TEST SCRIPT ********************************************************* 1486 1486 1487 //include("feedcreator.class.php"); 1488 1489 $rss = new UniversalFeedCreator(); 1490 $rss->useCached(); 1491 $rss->title = "PHP news"; 1492 $rss->description = "daily news from the PHP scripting world"; 1487 //include("feedcreator.class.php"); 1488 1489 $rss = new UniversalFeedCreator(); 1490 $rss->useCached(); 1491 $rss->title = "PHP news"; 1492 $rss->description = "daily news from the PHP scripting world"; 1493 1493 1494 1494 //optional … … 1497 1497 //$rss->xslStyleSheet = "http://feedster.com/rss20.xsl"; 1498 1498 1499 $rss->link = "http://www.dailyphp.net/news"; 1500 $rss->feedURL = "http://www.dailyphp.net/".$PHP_SELF; 1501 1502 $image = new FeedImage(); 1503 $image->title = "dailyphp.net logo"; 1504 $image->url = "http://www.dailyphp.net/images/logo.gif"; 1505 $image->link = "http://www.dailyphp.net"; 1506 $image->description = "Feed provided by dailyphp.net. Click to visit."; 1499 $rss->link = "http://www.dailyphp.net/news"; 1500 $rss->feedURL = "http://www.dailyphp.net/".$PHP_SELF; 1501 1502 $image = new FeedImage(); 1503 $image->title = "dailyphp.net logo"; 1504 $image->url = "http://www.dailyphp.net/images/logo.gif"; 1505 $image->link = "http://www.dailyphp.net"; 1506 $image->description = "Feed provided by dailyphp.net. Click to visit."; 1507 1507 1508 1508 //optional … … 1510 1510 $image->descriptionHtmlSyndicated = true; 1511 1511 1512 $rss->image = $image; 1513 1514 // get your news items from somewhere, e.g. your database: 1515 //mysql_select_db($dbHost, $dbUser, $dbPass); 1516 //$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); 1517 //while ($data = mysql_fetch_object($res)) { 1518 $item = new FeedItem(); 1519 $item->title = "This is an the test title of an item"; 1520 $item->link = "http://localhost/item/"; 1521 $item->description = "<b>description in </b><br/>HTML"; 1522 1512 $rss->image = $image; 1513 1514 // get your news items from somewhere, e.g. your database: 1515 //mysql_select_db($dbHost, $dbUser, $dbPass); 1516 //$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); 1517 //while ($data = mysql_fetch_object($res)) { 1518 $item = new FeedItem(); 1519 $item->title = "This is an the test title of an item"; 1520 $item->link = "http://localhost/item/"; 1521 $item->description = "<b>description in </b><br/>HTML"; 1522 1523 1523 //optional 1524 1524 //item->descriptionTruncSize = 500; 1525 1525 $item->descriptionHtmlSyndicated = true; 1526 1527 $item->date = time(); 1528 $item->source = "http://www.dailyphp.net"; 1529 $item->author = "John Doe"; 1530 1531 $rss->addItem($item); 1532 //} 1526 1527 $item->date = time(); 1528 $item->source = "http://www.dailyphp.net"; 1529 $item->author = "John Doe"; 1530 1531 $rss->addItem($item); 1532 //} 1533 1533 1534 1534 // valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1, MBOX, OPML, ATOM0.3, HTML, JS 1535 echo $rss->saveFeed("RSS0.91", "feed.xml"); 1535 echo $rss->saveFeed("RSS0.91", "feed.xml"); 1536 1536 1537 1537 -
trunk/include/functions_notification.inc.php
r1432 r1549 128 128 list($count) = mysql_fetch_array(pwg_query($query)); 129 129 return $count; 130 130 131 131 break; 132 132 case 'info': … … 153 153 } 154 154 155 $query = 'SELECT distinct '.implode(', ', $fields).' 155 $query = 'SELECT distinct '.implode(', ', $fields).' 156 156 '.$query; 157 157 $result = pwg_query($query); 158 158 159 159 $infos = array(); 160 160 161 161 while ($row = mysql_fetch_array($result)) 162 162 { … … 346 346 347 347 /** 348 * Formats a news line and adds it to the array (e.g. '5 new elements') 349 */ 350 function add_news_line(&$news, $count, $format, $url='', $add_url=false) 351 { 352 if ($count > 0) 353 { 354 $line = sprintf($format, $count); 355 if ($add_url and !empty($url) ) 356 { 357 $line = '<a href="'.$url.'">'.$line.'</a>'; 358 } 359 array_push($news, $line); 360 } 361 } 362 363 /** 348 364 * What's new between two dates ? 349 365 * … … 355 371 * @param string start date (mysql datetime format) 356 372 * @param string end date (mysql datetime format) 373 * @param bool exclude_img_cats if true, no info about new images/categories 374 * @param bool add_url add html A link around news 357 375 * 358 376 * @return array of news 359 377 */ 360 function news($start, $end )378 function news($start, $end, $exclude_img_cats=false, $add_url=false) 361 379 { 362 380 $news = array(); 363 381 364 $nb_new_comments = nb_new_comments($start, $end); 365 if ($nb_new_comments > 0) 366 { 367 array_push($news, sprintf(l10n('%d new comments'), $nb_new_comments)); 368 } 369 370 $nb_new_elements = nb_new_elements($start, $end); 371 if ($nb_new_elements > 0) 372 { 373 array_push($news, sprintf(l10n('%d new elements'), $nb_new_elements)); 374 } 375 376 $nb_updated_categories = nb_updated_categories($start, $end); 377 if ($nb_updated_categories > 0) 378 { 379 array_push($news, sprintf(l10n('%d categories updated'), 380 $nb_updated_categories)); 381 } 382 382 if (!$exclude_img_cats) 383 { 384 $nb_new_elements = nb_new_elements($start, $end); 385 if ($nb_new_elements > 0) 386 { 387 array_push($news, sprintf(l10n('%d new elements'), $nb_new_elements)); 388 } 389 } 390 391 if (!$exclude_img_cats) 392 { 393 $nb_updated_categories = nb_updated_categories($start, $end); 394 if ($nb_updated_categories > 0) 395 { 396 array_push($news, sprintf(l10n('%d categories updated'), 397 $nb_updated_categories)); 398 } 399 } 400 401 add_news_line( $news, 402 nb_new_comments($start, $end), l10n('%d new comments'), 403 get_root_url().'comments.php', $add_url ); 404 383 405 if (is_admin()) 384 406 { 385 $nb_unvalidated_comments = nb_unvalidated_comments($end); 386 if ($nb_unvalidated_comments > 0) 387 { 388 array_push($news, sprintf(l10n('%d comments to validate'), 389 $nb_unvalidated_comments)); 390 } 391 392 $nb_new_users = nb_new_users($start, $end); 393 if ($nb_new_users > 0) 394 { 395 array_push($news, sprintf(l10n('%d new users'), $nb_new_users)); 396 } 397 398 $nb_waiting_elements = nb_waiting_elements(); 399 if ($nb_waiting_elements > 0) 400 { 401 array_push( 402 $news, 403 sprintf( 404 l10n('%d waiting elements'), 405 $nb_waiting_elements 406 ) 407 ); 408 } 407 add_news_line( $news, 408 nb_unvalidated_comments($end), l10n('%d comments to validate'), 409 get_root_url().'admin.php?page=comments', $add_url ); 410 411 add_news_line( $news, 412 nb_new_users($start, $end), l10n('%d new users'), 413 PHPWG_ROOT_PATH.'admin.php?page=user_list', $add_url ); 414 415 add_news_line( $news, 416 nb_waiting_elements(), l10n('%d waiting elements'), 417 PHPWG_ROOT_PATH.'admin.php?page=waiting', $add_url ); 409 418 } 410 419
Note: See TracChangeset
for help on using the changeset viewer.