Changeset 848:ad18a33a3cef for inc/core/class.dc.rs.extensions.php
- Timestamp:
- 07/31/12 13:18:23 (13 years ago)
- Branch:
- sexy
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.rs.extensions.php
r776 r848 117 117 118 118 /** 119 Returns whether comments are enabled on post.120 121 @param rs Invisible parameter122 @return <b>boolean</b>123 */124 public static function commentsActive($rs)125 {126 return127 $rs->core->blog->settings->system->allow_comments128 && $rs->post_open_comment129 && ($rs->core->blog->settings->system->comments_ttl == 0 ||130 time()-($rs->core->blog->settings->system->comments_ttl*86400) < $rs->getTS());131 }132 133 /**134 Returns whether trackbacks are enabled on post.135 136 @param rs Invisible parameter137 @return <b>boolean</b>138 */139 public static function trackbacksActive($rs)140 {141 return142 $rs->core->blog->settings->system->allow_trackbacks143 && $rs->post_open_tb144 && ($rs->core->blog->settings->system->trackbacks_ttl == 0 ||145 time()-($rs->core->blog->settings->system->trackbacks_ttl*86400) < $rs->getTS());146 }147 148 /**149 Returns whether post has at least one comment.150 151 @param rs Invisible parameter152 @return <b>boolean</b>153 */154 public static function hasComments($rs)155 {156 return $rs->nb_comment > 0;157 }158 159 /**160 Returns whether post has at least one trackbacks.161 162 @return <b>boolean</b>163 */164 public static function hasTrackbacks($rs)165 {166 return $rs->nb_trackback > 0;167 }168 169 /**170 119 Returns full post URL. 171 120 … … 361 310 362 311 return 'tag:'.$url['host'].','.$date_part.':'.$rs->post_id; 363 }364 365 /**366 Returns trackback RDF information block in HTML comment.367 368 @param rs Invisible parameter369 @return <b>string</b>370 */371 public static function getTrackbackData($rs)372 {373 return374 "<![CDATA[>\n".375 "<!--[\n".376 '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n".377 ' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n".378 ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n".379 "<rdf:Description\n".380 ' rdf:about="'.$rs->getURL().'"'."\n".381 ' dc:identifier="'.$rs->getURL().'"'."\n".382 ' dc:title="'.htmlspecialchars($rs->post_title,ENT_COMPAT,'UTF-8').'"'."\n".383 ' trackback:ping="'.$rs->getTrackbackLink().'" />'."\n".384 "</rdf:RDF>\n".385 "<!]]><!---->\n";386 }387 388 /**389 Returns post trackback full URL.390 391 @param rs Invisible parameter392 @return <b>string</b>393 */394 public static function getTrackbackLink($rs)395 {396 return $rs->core->blog->url.$rs->core->url->getURLFor('trackback',$rs->post_id);397 312 } 398 313 … … 459 374 /** 460 375 @ingroup DC_CORE 461 @brief Dotclear comment record helpers.462 463 This class adds new methods to database comment results.464 You can call them on every record comming from dcBlog::getComments and similar465 methods.466 467 @warning You should not give the first argument (usualy $rs) of every described468 function.469 */470 class rsExtComment471 {472 /**473 Returns comment date with <var>$format</var> as formatting pattern. If474 format is empty, uses <var>date_format</var> blog setting.475 476 @param rs Invisible parameter477 @param format <b>string</b> Date format pattern478 @param type <b>string</b> (dt|upddt) defaults to comment_dt479 @return <b>string</b>480 */481 public static function getDate($rs,$format,$type='')482 {483 if (!$format) {484 $format = $rs->core->blog->settings->system->date_format;485 }486 487 if ($type == 'upddt') {488 return dt::dt2str($format,$rs->comment_upddt,$rs->comment_tz);489 } else {490 return dt::dt2str($format,$rs->comment_dt);491 }492 }493 494 /**495 Returns comment time with <var>$format</var> as formatting pattern. If496 format is empty, uses <var>time_format</var> blog setting.497 498 @param rs Invisible parameter499 @param format <b>string</b> Date format pattern500 @param type <b>string</b> (dt|upddt) defaults to comment_dt501 @return <b>string</b>502 */503 public static function getTime($rs,$format,$type='')504 {505 if (!$format) {506 $format = $rs->core->blog->settings->system->time_format;507 }508 509 if ($type == 'upddt') {510 return dt::dt2str($format,$rs->comment_updt,$rs->comment_tz);511 } else {512 return dt::dt2str($format,$rs->comment_dt);513 }514 }515 516 /**517 Returns comment timestamp.518 519 @param rs Invisible parameter520 @param type <b>string</b> (dt|upddt) defaults to comment_dt521 @return <b>integer</b>522 */523 public static function getTS($rs,$type='')524 {525 if ($type == 'upddt') {526 return strtotime($rs->comment_upddt);527 } else {528 return strtotime($rs->comment_dt);529 }530 }531 532 /**533 Returns comment date formating according to the ISO 8601 standard.534 535 @param rs Invisible parameter536 @param type <b>string</b> (dt|upddt) defaults to comment_dt537 @return <b>string</b>538 */539 public static function getISO8601Date($rs,$type='')540 {541 if ($type == 'upddt') {542 return dt::iso8601($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz);543 } else {544 return dt::iso8601($rs->getTS(),$rs->comment_tz);545 }546 }547 548 /**549 Returns comment date formating according to RFC 822.550 551 @param rs Invisible parameter552 @param type <b>string</b> (dt|upddt) defaults to comment_dt553 @return <b>string</b>554 */555 public static function getRFC822Date($rs,$type='')556 {557 if ($type == 'upddt') {558 return dt::rfc822($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz);559 } else {560 return dt::rfc822($rs->getTS(),$rs->comment_tz);561 }562 }563 564 /**565 Returns comment content. If <var>$absolute_urls</var> is true, appends full566 blog URL to each relative post URLs.567 568 @param rs Invisible parameter569 @param absolute_urls <b>boolean</b> With absolute URLs570 @return <b>string</b>571 */572 public static function getContent($rs,$absolute_urls=false)573 {574 $res = $rs->comment_content;575 576 if ($rs->core->blog->settings->system->comments_nofollow) {577 $res = preg_replace_callback('#<a(.*?href=".*?".*?)>#ms',array('self','noFollowURL'),$res);578 }579 580 if ($absolute_urls) {581 $res = html::absoluteURLs($res,$rs->getPostURL());582 }583 584 return $res;585 }586 587 private static function noFollowURL($m)588 {589 if (preg_match('/rel="nofollow"/',$m[1])) {590 return $m[0];591 }592 593 return '<a'.$m[1].' rel="nofollow">';594 }595 596 /**597 Returns comment author link to his website if he specified one.598 599 @param rs Invisible parameter600 @return <b>string</b>601 */602 public static function getAuthorURL($rs)603 {604 if (trim($rs->comment_site)) {605 return trim($rs->comment_site);606 }607 }608 609 /**610 Returns comment post full URL.611 612 @param rs Invisible parameter613 @return <b>string</b>614 */615 public static function getPostURL($rs)616 {617 return $rs->core->blog->url.$rs->core->getPostPublicURL(618 $rs->post_type,html::sanitizeURL($rs->post_url)619 );620 }621 622 /**623 Returns comment author name in a link to his website if he specified one.624 625 @param rs Invisible parameter626 @return <b>string</b>627 */628 public static function getAuthorLink($rs)629 {630 $res = '%1$s';631 $url = $rs->getAuthorURL();632 if ($url) {633 $res = '<a href="%2$s"%3$s>%1$s</a>';634 }635 636 $nofollow = '';637 if ($rs->core->blog->settings->system->comments_nofollow) {638 $nofollow = ' rel="nofollow"';639 }640 641 return sprintf($res,html::escapeHTML($rs->comment_author),html::escapeHTML($url),$nofollow);642 }643 644 /**645 Returns comment author e-mail address. If <var>$encoded</var> is true,646 "@" sign is replaced by "%40" and "." by "%2e".647 648 @param rs Invisible parameter649 @param encoded <b>boolean</b> Encode address.650 @return <b>string</b>651 */652 public static function getEmail($rs,$encoded=true)653 {654 if ($encoded) {655 return strtr($rs->comment_email,array('@'=>'%40','.'=>'%2e'));656 }657 return $rs->comment_email;658 }659 660 /**661 Returns trackback site title if comment is a trackback.662 663 @param rs Invisible parameter664 @return <b>string</b>665 */666 public static function getTrackbackTitle($rs)667 {668 if ($rs->comment_trackback == 1 &&669 preg_match('|<p><strong>(.*?)</strong></p>|msU',$rs->comment_content,670 $match)) {671 return html::decodeEntities($match[1]);672 }673 }674 675 /**676 Returns trackback content if comment is a trackback.677 678 @param rs Invisible parameter679 @return <b>string</b>680 */681 public static function getTrackbackContent($rs)682 {683 if ($rs->comment_trackback == 1) {684 return preg_replace('|<p><strong>.*?</strong></p>|msU','',685 $rs->comment_content);686 }687 }688 689 /**690 Returns comment feed unique ID.691 692 @param rs Invisible parameter693 @return <b>string</b>694 */695 public static function getFeedID($rs)696 {697 return 'urn:md5:'.md5($rs->core->blog->uid.$rs->comment_id);698 699 $url = parse_url($rs->core->blog->url);700 $date_part = date('Y-m-d',strtotime($rs->comment_dt));701 702 return 'tag:'.$url['host'].','.$date_part.':'.$rs->comment_id;703 }704 705 /**706 Returns whether comment is from the post author.707 708 @param rs Invisible parameter709 @return <b>boolean</b>710 */711 public static function isMe($rs)712 {713 return714 $rs->comment_email && $rs->comment_site &&715 $rs->comment_email == $rs->user_email &&716 $rs->comment_site == $rs->user_url;717 }718 }719 720 /**721 @ingroup DC_CORE722 376 @brief Dotclear dates record helpers. 723 377
Note: See TracChangeset
for help on using the changeset viewer.