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