[ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2005 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 /** 24 @ingroup DC_CORE 25 @brief Dotclear post record helpers. 26 27 This class adds new methods to database post results. 28 You can call them on every record comming from dcBlog::getPosts and similar 29 methods. 30 31 @warning You should not give the first argument (usualy $rs) of every described 32 function. 33 */ 34 class rsExtPost 35 { 36 /** 37 Returns whether post is editable. 38 39 @param rs Invisible parameter 40 @return <b>boolean</b> 41 */ 42 public static function isEditable(&$rs) 43 { 44 # If user is admin or contentadmin, true 45 if ($rs->core->auth->check('contentadmin',$rs->core->blog->id)) { 46 return true; 47 } 48 49 # No user id in result ? false 50 if (!$rs->exists('user_id')) { 51 return false; 52 } 53 54 # If user is usage and owner of the entrie 55 if ($rs->core->auth->check('usage',$rs->core->blog->id) 56 && $rs->user_id == $rs->core->auth->userID()) { 57 return true; 58 } 59 60 return false; 61 } 62 63 /** 64 Returns whether post is deletable 65 66 @param rs Invisible parameter 67 @return <b>boolean</b> 68 */ 69 public static function isDeletable(&$rs) 70 { 71 # If user is admin, or contentadmin, true 72 if ($rs->core->auth->check('contentadmin',$rs->core->blog->id)) { 73 return true; 74 } 75 76 # No user id in result ? false 77 if (!$rs->exists('user_id')) { 78 return false; 79 } 80 81 # If user has delete rights and is owner of the entrie 82 if ($rs->core->auth->check('delete',$rs->core->blog->id) 83 && $rs->user_id == $rs->core->auth->userID()) { 84 return true; 85 } 86 87 return false; 88 } 89 90 /** 91 Returns whether post is the first one of its day. 92 93 @param rs Invisible parameter 94 @return <b>boolean</b> 95 */ 96 public static function firstPostOfDay(&$rs) 97 { 98 if ($rs->isStart()) { 99 return true; 100 } 101 102 $cdate = date('Ymd',strtotime($rs->post_dt)); 103 $rs->movePrev(); 104 $ndate = date('Ymd',strtotime($rs->post_dt)); 105 $rs->moveNext(); 106 return $ndate != $cdate; 107 } 108 109 /** 110 Returns whether post is the last one of its day. 111 112 @param rs Invisible parameter 113 @return <b>boolean</b> 114 */ 115 public static function lastPostOfDay(&$rs) 116 { 117 if ($rs->isEnd()) { 118 return true; 119 } 120 121 $cdate = date('Ymd',strtotime($rs->post_dt)); 122 $rs->moveNext(); 123 $ndate = date('Ymd',strtotime($rs->post_dt)); 124 $rs->movePrev(); 125 return $ndate != $cdate; 126 } 127 128 /** 129 Returns whether comments are enabled on post. 130 131 @param rs Invisible parameter 132 @return <b>boolean</b> 133 */ 134 public static function commentsActive(&$rs) 135 { 136 return 137 $rs->core->blog->settings->allow_comments 138 && $rs->post_open_comment 139 && ($rs->core->blog->settings->comments_ttl == 0 || 140 time()-($rs->core->blog->settings->comments_ttl*86400) < $rs->getTS()); 141 } 142 143 /** 144 Returns whether trackbacks are enabled on post. 145 146 @param rs Invisible parameter 147 @return <b>boolean</b> 148 */ 149 public static function trackbacksActive(&$rs) 150 { 151 return 152 $rs->core->blog->settings->allow_trackbacks 153 && $rs->post_open_tb 154 && ($rs->core->blog->settings->comments_ttl == 0 || 155 time()-($rs->core->blog->settings->comments_ttl*86400) < $rs->getTS()); 156 } 157 158 /** 159 Returns whether post has at least one comment. 160 161 @param rs Invisible parameter 162 @return <b>boolean</b> 163 */ 164 public static function hasComments(&$rs) 165 { 166 return $rs->nb_comment > 0; 167 } 168 169 /** 170 Returns whether post has at least one trackbacks. 171 172 @return <b>boolean</b> 173 */ 174 public static function hasTrackbacks(&$rs) 175 { 176 return $rs->nb_trackback > 0; 177 } 178 179 /** 180 Returns full post URL. 181 182 @param rs Invisible parameter 183 @return <b>string</b> 184 */ 185 public static function getURL(&$rs) 186 { 187 return $rs->core->blog->url.$rs->core->url->getBase('post').'/'. 188 html::sanitizeURL($rs->post_url); 189 } 190 191 /** 192 Returns full post category URL. 193 194 @param rs Invisible parameter 195 @return <b>string</b> 196 */ 197 public static function getCategoryURL(&$rs) 198 { 199 return $rs->core->blog->url.$rs->core->url->getBase('category').'/'. 200 html::sanitizeURL($rs->cat_url); 201 } 202 203 /** 204 Returns whether post has an excerpt. 205 206 @param rs Invisible parameter 207 @return <b>boolean</b> 208 */ 209 public static function isExtended(&$rs) 210 { 211 return $rs->post_excerpt_xhtml != ''; 212 } 213 214 /** 215 Returns post timestamp. 216 217 @param rs Invisible parameter 218 @return <b>integer</b> 219 */ 220 public static function getTS(&$rs) 221 { 222 return strtotime($rs->post_dt); 223 } 224 225 /** 226 Returns post date formating according ISO 8601 standard. 227 228 @param rs Invisible parameter 229 @return <b>string</b> 230 */ 231 public static function getISO8601Date(&$rs) 232 { 233 return dt::iso8601($rs->getTS(),$rs->post_tz); 234 } 235 236 /** 237 Returns post date formating according RFC 822. 238 239 @param rs Invisible parameter 240 @return <b>string</b> 241 */ 242 public static function getRFC822Date(&$rs) 243 { 244 return dt::rfc822($rs->getTS(),$rs->post_tz); 245 } 246 247 /** 248 Returns post date with <var>$format</var> as formatting pattern. If format 249 is empty, uses <var>date_format</var> blog setting. 250 251 @param rs Invisible parameter 252 @param format <b>string</b> Date format pattern 253 @return <b>string</b> 254 */ 255 public static function getDate(&$rs,$format) 256 { 257 if ($format) { 258 return dt::dt2str($format,$rs->post_dt); 259 } else { 260 return dt::dt2str($rs->core->blog->settings->date_format,$rs->post_dt); 261 } 262 } 263 264 /** 265 Returns post time with <var>$format</var> as formatting pattern. If format 266 is empty, uses <var>time_format</var> blog setting. 267 268 @param rs Invisible parameter 269 @param format <b>string</b> Time format pattern 270 @return <b>string</b> 271 */ 272 public static function getTime(&$rs,$format) 273 { 274 if ($format) { 275 return dt::dt2str($format,$rs->post_dt); 276 } else { 277 return dt::dt2str($rs->core->blog->settings->time_format,$rs->post_dt); 278 } 279 } 280 281 /** 282 Returns author common name using user_id, user_name, user_firstname and 283 user_displayname fields. 284 285 @param rs Invisible parameter 286 @return <b>string</b> 287 */ 288 public static function getAuthorCN(&$rs) 289 { 290 return dcUtils::getUserCN($rs->user_id, $rs->user_name, 291 $rs->user_firstname, $rs->user_displayname); 292 } 293 294 /** 295 Returns author common name with a link if he specified one in its 296 preferences. 297 298 @param rs Invisible parameter 299 @return <b>string</b> 300 */ 301 public static function getAuthorLink(&$rs) 302 { 303 $res = '%1$s'; 304 $url = $rs->user_url; 305 if ($url) { 306 $res = '<a href="%2$s">%1$s</a>'; 307 } 308 309 return sprintf($res,$rs->getAuthorCN(),$url); 310 } 311 312 /** 313 Returns author e-mail address. If <var>$encoded</var> is true, "@" sign is 314 replaced by "%40" and "." by "%2e". 315 316 @param rs Invisible parameter 317 @param encoded <b>boolean</b> Encode address. 318 @return <b>string</b> 319 */ 320 public static function getAuthorEmail(&$rs,$encoded=true) 321 { 322 if ($encoded) { 323 return strtr($rs->user_email,array('@'=>'%40','.'=>'%2e')); 324 } 325 return $rs->user_email; 326 } 327 328 /** 329 Returns post feed unique ID. 330 331 @param rs Invisible parameter 332 @return <b>string</b> 333 */ 334 public static function getFeedID(&$rs) 335 { 336 return 'urn:md5:'.md5($rs->core->blog->uid.$rs->post_id); 337 338 $url = parse_url($rs->core->blog->url); 339 $date_part = date('Y-m-d',strtotime($rs->post_creadt)); 340 341 return 'tag:'.$url['host'].','.$date_part.':'.$rs->post_id; 342 } 343 344 /** 345 Returns trackback RDF information block in HTML comment. 346 347 @param rs Invisible parameter 348 @return <b>string</b> 349 */ 350 public static function getTrackbackData(&$rs) 351 { 352 return 353 "<!--\n". 354 '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n". 355 ' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n". 356 ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n". 357 "<rdf:Description\n". 358 ' rdf:about="'.$rs->getURL().'"'."\n". 359 ' dc:identifier="'.$rs->getURL().'"'."\n". 360 ' dc:title="'.htmlspecialchars($rs->post_title,ENT_COMPAT,'UTF-8').'"'."\n". 361 ' trackback:ping="'.$rs->getTrackbackLink().'" />'."\n". 362 "</rdf:RDF>\n". 363 "-->\n"; 364 } 365 366 /** 367 Returns post trackback full URL. 368 369 @param rs Invisible parameter 370 @return <b>string</b> 371 */ 372 public static function getTrackbackLink(&$rs) 373 { 374 return $rs->core->blog->url.$rs->core->url->getBase('trackback').'/'.$rs->post_id; 375 } 376 377 /** 378 Returns post content. If <var>$absolute_urls</var> is true, appends full 379 blog URL to each relative post URLs. 380 381 @param rs Invisible parameter 382 @param absolute_urls <b>boolean</b> With absolute URLs 383 @return <b>string</b> 384 */ 385 public static function getContent(&$rs,$absolute_urls=false) 386 { 387 if ($absolute_urls) { 388 return html::absoluteURLs($rs->post_content_xhtml,$rs->getURL()); 389 } else { 390 return $rs->post_content_xhtml; 391 } 392 } 393 394 /** 395 Returns post excerpt. If <var>$absolute_urls</var> is true, appends full 396 blog URL to each relative post URLs. 397 398 @param rs Invisible parameter 399 @param absolute_urls <b>boolean</b> With absolute URLs 400 @return <b>string</b> 401 */ 402 public static function getExcerpt(&$rs,$absolute_urls=false) 403 { 404 if ($absolute_urls) { 405 return html::absoluteURLs($rs->post_excerpt_xhtml,$rs->getURL()); 406 } else { 407 return $rs->post_excerpt_xhtml; 408 } 409 } 410 411 /** 412 Returns post media count using a subquery. 413 414 @param rs Invisible parameter 415 @return <b>integer</b> 416 */ 417 public static function countMedia(&$rs) 418 { 419 if (isset($rs->_nb_media[$rs->index()])) 420 { 421 return $rs->_nb_media[$rs->index()]; 422 } 423 else 424 { 425 $strReq = 426 'SELECT count(media_id) '. 427 'FROM '.$rs->core->prefix.'post_media '. 428 'WHERE post_id = '.(integer) $rs->post_id.' '; 429 430 $res = (integer) $rs->core->con->select($strReq)->f(0); 431 $rs->_nb_media[$rs->index()] = $res; 432 return $res; 433 } 434 } 435 } 436 437 /** 438 @ingroup DC_CORE 439 @brief Dotclear comment record helpers. 440 441 This class adds new methods to database comment results. 442 You can call them on every record comming from dcBlog::getComments and similar 443 methods. 444 445 @warning You should not give the first argument (usualy $rs) of every described 446 function. 447 */ 448 class rsExtComment 449 { 450 /** 451 Returns comment date with <var>$format</var> as formatting pattern. If 452 format is empty, uses <var>date_format</var> blog setting. 453 454 @param rs Invisible parameter 455 @param format <b>string</b> Date format pattern 456 @return <b>string</b> 457 */ 458 public static function getDate(&$rs,$format) 459 { 460 if ($format) { 461 return dt::dt2str($format,$rs->comment_dt); 462 } else { 463 return dt::dt2str($rs->core->blog->settings->date_format,$rs->comment_dt); 464 } 465 } 466 467 /** 468 Returns comment time with <var>$format</var> as formatting pattern. If 469 format is empty, uses <var>time_format</var> blog setting. 470 471 @param rs Invisible parameter 472 @param format <b>string</b> Date format pattern 473 @return <b>string</b> 474 */ 475 public static function getTime(&$rs,$format) 476 { 477 if ($format) { 478 return dt::dt2str($format,$rs->comment_dt); 479 } else { 480 return dt::dt2str($rs->core->blog->settings->time_format,$rs->comment_dt); 481 } 482 } 483 484 /** 485 Returns comment timestamp. 486 487 @param rs Invisible parameter 488 @return <b>integer</b> 489 */ 490 public static function getTS(&$rs) 491 { 492 return strtotime($rs->comment_dt); 493 } 494 495 /** 496 Returns comment date formating according ISO 8601 standard. 497 498 @param rs Invisible parameter 499 @return <b>string</b> 500 */ 501 public static function getISO8601Date(&$rs) 502 { 503 return dt::iso8601($rs->getTS(),$rs->comment_tz); 504 } 505 506 /** 507 Returns comment date formating according RFC 822. 508 509 @param rs Invisible parameter 510 @return <b>string</b> 511 */ 512 public static function getRFC822Date(&$rs) 513 { 514 return dt::rfc822($rs->getTS(),$rs->comment_tz); 515 } 516 517 /** 518 Returns comment content. If <var>$absolute_urls</var> is true, appends full 519 blog URL to each relative post URLs. 520 521 @param rs Invisible parameter 522 @param absolute_urls <b>boolean</b> With absolute URLs 523 @return <b>string</b> 524 */ 525 public static function getContent(&$rs,$absolute_urls=false) 526 { 527 $res = $rs->comment_content; 528 529 if ($rs->core->blog->settings->comments_nofollow) { 530 $res = preg_replace_callback('#<a(.*?href=".*?".*?)>#ms',array('self','noFollowURL'),$res); 531 } 532 533 if ($absolute_urls) { 534 $res = html::absoluteURLs($res,$rs->getPostURL()); 535 } 536 537 return $res; 538 } 539 540 private static function noFollowURL($m) 541 { 542 if (preg_match('/rel="nofollow"/',$m[1])) { 543 return $m[0]; 544 } 545 546 return '<a'.$m[1].' rel="nofollow">'; 547 } 548 549 /** 550 Returns comment author link to his website if he specified one. 551 552 @param rs Invisible parameter 553 @return <b>string</b> 554 */ 555 public static function getAuthorURL(&$rs) 556 { 557 if (trim($rs->comment_site)) { 558 return trim($rs->comment_site); 559 } 560 } 561 562 /** 563 Returns comment post full URL. 564 565 @param rs Invisible parameter 566 @return <b>string</b> 567 */ 568 public static function getPostURL(&$rs) 569 { 570 return $rs->core->blog->url.$rs->core->url->getBase('post').'/'. 571 html::sanitizeURL($rs->post_url); 572 } 573 574 /** 575 Returns comment author name in a link to his website if he specified one. 576 577 @param rs Invisible parameter 578 @return <b>string</b> 579 */ 580 public static function getAuthorLink(&$rs) 581 { 582 $res = '%1$s'; 583 $url = $rs->getAuthorURL(); 584 if ($url) { 585 $res = '<a href="%2$s"%3$s>%1$s</a>'; 586 } 587 588 $nofollow = ''; 589 if ($rs->core->blog->settings->comments_nofollow) { 590 $nofollow = ' rel="nofollow"'; 591 } 592 593 return sprintf($res,html::escapeHTML($rs->comment_author),$url,$nofollow); 594 } 595 596 /** 597 Returns comment author e-mail address. If <var>$encoded</var> is true, 598 "@" sign is replaced by "%40" and "." by "%2e". 599 600 @param rs Invisible parameter 601 @param encoded <b>boolean</b> Encode address. 602 @return <b>string</b> 603 */ 604 public static function getEmail(&$rs,$encoded=true) 605 { 606 if ($encoded) { 607 return strtr($rs->comment_email,array('@'=>'%40','.'=>'%2e')); 608 } 609 return $rs->comment_email; 610 } 611 612 /** 613 Returns trackback site title if comment is a trackback. 614 615 @param rs Invisible parameter 616 @return <b>string</b> 617 */ 618 public static function getTrackbackTitle(&$rs) 619 { 620 if ($rs->comment_trackback == 1 && 621 preg_match('|<p><strong>(.*?)</strong></p>|msU',$rs->comment_content, 622 $match)) { 623 return $match[1]; 624 } 625 } 626 627 /** 628 Returns trackback content if comment is a trackback. 629 630 @param rs Invisible parameter 631 @return <b>string</b> 632 */ 633 public static function getTrackbackContent(&$rs) 634 { 635 if ($rs->comment_trackback == 1) { 636 return preg_replace('|<p><strong>.*?</strong></p>|msU','', 637 $rs->comment_content); 638 } 639 } 640 641 /** 642 Returns comment feed unique ID. 643 644 @param rs Invisible parameter 645 @return <b>string</b> 646 */ 647 public static function getFeedID(&$rs) 648 { 649 return 'urn:md5:'.md5($rs->core->blog->uid.$rs->comment_id); 650 651 $url = parse_url($rs->core->blog->url); 652 $date_part = date('Y-m-d',strtotime($rs->comment_dt)); 653 654 return 'tag:'.$url['host'].','.$date_part.':'.$rs->comment_id; 655 } 656 657 /** 658 Returns whether comment is from the post author. 659 660 @param rs Invisible parameter 661 @return <b>boolean</b> 662 */ 663 public static function isMe(&$rs) 664 { 665 return 666 $rs->comment_email && $rs->comment_site && 667 $rs->comment_email == $rs->user_email && 668 $rs->comment_site == $rs->user_url; 669 } 670 } 671 672 /** 673 @ingroup DC_CORE 674 @brief Dotclear dates record helpers. 675 676 This class adds new methods to database dates results. 677 You can call them on every record comming from dcBlog::getDates. 678 679 @warning You should not give the first argument (usualy $rs) of every described 680 function. 681 */ 682 class rsExtDates 683 { 684 /** 685 @param rs Invisible parameter 686 @return <b>integer</b> Date timestamp 687 */ 688 public static function ts(&$rs) 689 { 690 return strtotime($rs->dt); 691 } 692 693 /** 694 @param rs Invisible parameter 695 @return <b>string</b> Date year 696 */ 697 public static function year(&$rs) 698 { 699 return date('Y',strtotime($rs->dt)); 700 } 701 702 /** 703 @param rs Invisible parameter 704 @return <b>string</b> Date month 705 */ 706 public static function month(&$rs) 707 { 708 return date('m',strtotime($rs->dt)); 709 } 710 711 /** 712 @param rs Invisible parameter 713 @return <b>integer</b> Date day 714 */ 715 public static function day(&$rs) 716 { 717 return date('d',strtotime($rs->dt)); 718 } 719 720 /** 721 Returns date month archive full URL. 722 723 @param rs Invisible parameter 724 @param core <b>dcCore</b> dcCore instance 725 @return <b>integer</b> 726 */ 727 public static function url(&$rs,&$core) 728 { 729 $url = date('Y/m',strtotime($rs->dt)); 730 731 return $core->blog->url.$core->url->getBase('archive').'/'.$url; 732 } 733 734 /** 735 Returns whether date is the first of year. 736 737 @param rs Invisible parameter 738 @return <b>boolean</b> 739 */ 740 public static function yearHeader(&$rs) 741 { 742 if ($rs->isStart()) { 743 return true; 744 } 745 746 $y = $rs->year(); 747 $rs->movePrev(); 748 $py = $rs->year(); 749 $rs->moveNext(); 750 751 return $y != $py; 752 } 753 754 /** 755 Returns whether date is the last of year. 756 757 @param rs Invisible parameter 758 @return <b>boolean</b> 759 */ 760 public static function yearFooter(&$rs) 761 { 762 if ($rs->isEnd()) { 763 return true; 764 } 765 766 $y = $rs->year(); 767 if ($rs->moveNext()) { 768 $ny = $rs->year(); 769 $rs->movePrev(); 770 return $y != $ny; 771 } 772 return false; 773 774 } 775 } 776 777 /** 778 @ingroup DC_CORE 779 @brief Dotclear dates record helpers. 780 781 This class adds new methods to database dates results. 782 You can call them on every record comming from dcAuth::checkUser and 783 dcCore::getUsers. 784 785 @warning You should not give the first argument (usualy $rs) of every described 786 function. 787 */ 788 class rsExtUser 789 { 790 /** 791 Returns a user option. 792 793 @param rs Invisible parameter 794 @param name <b>string</b> Option name 795 @return <b>string</b> 796 */ 797 public static function option(&$rs,$name) 798 { 799 $options = self::options($rs); 800 801 if (isset($options[$name])) { 802 return $options[$name]; 803 } 804 return null; 805 } 806 807 /** 808 Returns all user options. 809 810 @param rs Invisible parameter 811 @return <b>array</b> 812 */ 813 public static function options(&$rs) 814 { 815 $options = @unserialize($rs->user_options); 816 if (is_array($options)) { 817 return $options; 818 } 819 return array(); 820 } 821 } 822 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |