Dotclear

source: inc/core/class.dc.rs.extensions.php @ 3543:3874363133cd

Revision 3543:3874363133cd, 21.0 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Remove unecessary code (thanks adjaya for report)

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3# This file is part of Dotclear 2.
4#
[1179]5# Copyright (c) 2003-2013 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 -----------------------------------------
11if (!defined('DC_RC_PATH')) { return; }
12
13/**
14@ingroup DC_CORE
15@brief Dotclear post record helpers.
16
17This class adds new methods to database post results.
18You can call them on every record comming from dcBlog::getPosts and similar
19methods.
20
21@warning You should not give the first argument (usualy $rs) of every described
22function.
23*/
24class rsExtPost
25{
26     /**
27     Returns whether post is editable.
[2566]28
[0]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          }
[2566]38
[0]39          # No user id in result ? false
40          if (!$rs->exists('user_id')) {
41               return false;
42          }
[2566]43
[0]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          }
[2566]49
[0]50          return false;
51     }
[2566]52
[0]53     /**
54     Returns whether post is deletable
[2566]55
[0]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          }
[2566]65
[0]66          # No user id in result ? false
67          if (!$rs->exists('user_id')) {
68               return false;
69          }
[2566]70
[0]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          }
[2566]76
[0]77          return false;
78     }
[2566]79
[0]80     /**
81     Returns whether post is the first one of its day.
[2566]82
[0]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          }
[2566]91
[0]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     }
[2566]98
[0]99     /**
100     Returns whether post is the last one of its day.
[2566]101
[0]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          }
[2566]110
[0]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     }
[2566]117
[0]118     /**
119     Returns whether comments are enabled on post.
[2566]120
[0]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     }
[2566]132
[0]133     /**
134     Returns whether trackbacks are enabled on post.
[2566]135
[0]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     }
[2566]147
[0]148     /**
149     Returns whether post has at least one comment.
[2566]150
[0]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     }
[2566]158
[0]159     /**
160     Returns whether post has at least one trackbacks.
[2566]161
[0]162     @return   <b>boolean</b>
163     */
164     public static function hasTrackbacks($rs)
165     {
166          return $rs->nb_trackback > 0;
167     }
[912]168
169     /**
170     Returns whether post has been updated since publication.
171
172     @return <b>boolean</b>
173     */
174     public static function isRepublished($rs)
175     {
176          return ($rs->getTS('upddt') + dt::getTimeOffset($rs->post_tz)) > $rs->getTS();
177     }
[2566]178
[0]179     /**
180     Returns full post URL.
[2566]181
[0]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->getPostPublicURL(
188                    $rs->post_type,html::sanitizeURL($rs->post_url)
189               );
190     }
[2566]191
[0]192     /**
193     Returns full post category URL.
[2566]194
[0]195     @param    rs   Invisible parameter
196     @return   <b>string</b>
197     */
198     public static function getCategoryURL($rs)
199     {
[776]200          return $rs->core->blog->url.$rs->core->url->getURLFor('category',html::sanitizeURL($rs->cat_url));
[0]201     }
[2566]202
[0]203     /**
204     Returns whether post has an excerpt.
[2566]205
[0]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     }
[2566]213
[0]214     /**
215     Returns post timestamp.
[2566]216
[0]217     @param    rs   Invisible parameter
218     @param    type <b>string</b>       (dt|upddt|creadt) defaults to post_dt
219     @return   <b>integer</b>
220     */
221     public static function getTS($rs,$type='')
222     {
223          if ($type == 'upddt') {
224               return strtotime($rs->post_upddt);
225          } elseif ($type == 'creadt') {
226               return strtotime($rs->post_creadt);
227          } else {
228               return strtotime($rs->post_dt);
229          }
230     }
[2566]231
[0]232     /**
233     Returns post date formating according to the ISO 8601 standard.
[2566]234
[0]235     @param    rs   Invisible parameter
236     @param    type <b>string</b>       (dt|upddt|creadt) defaults to post_dt
237     @return   <b>string</b>
238     */
239     public static function getISO8601Date($rs,$type='')
240     {
241          if ($type == 'upddt' || $type == 'creadt') {
242               return dt::iso8601($rs->getTS($type)+dt::getTimeOffset($rs->post_tz),$rs->post_tz);
243          } else {
244               return dt::iso8601($rs->getTS(),$rs->post_tz);
245          }
246     }
[2566]247
[0]248     /**
249     Returns post date formating according to RFC 822.
[2566]250
[0]251     @param    rs   Invisible parameter
252     @param    type <b>string</b>       (dt|upddt|creadt) defaults to post_dt
253     @return   <b>string</b>
254     */
255     public static function getRFC822Date($rs,$type='')
256     {
257          if ($type == 'upddt' || $type == 'creadt') {
258               return dt::rfc822($rs->getTS($type)+dt::getTimeOffset($rs->post_tz),$rs->post_tz);
259          } else {
260               return dt::rfc822($rs->getTS($type),$rs->post_tz);
261          }
262     }
[2566]263
[0]264     /**
265     Returns post date with <var>$format</var> as formatting pattern. If format
266     is empty, uses <var>date_format</var> blog setting.
[2566]267
[0]268     @param    rs   Invisible parameter
269     @param    format    <b>string</b>       Date format pattern
270     @param    type <b>string</b>       (dt|upddt|creadt) defaults to post_dt
271     @return   <b>string</b>
272     */
273     public static function getDate($rs,$format,$type='')
274     {
275          if (!$format) {
276               $format = $rs->core->blog->settings->system->date_format;
277          }
[2566]278
[0]279          if ($type == 'upddt') {
280               return dt::dt2str($format,$rs->post_upddt,$rs->post_tz);
281          } elseif ($type == 'creadt') {
282               return dt::dt2str($format,$rs->post_creadt,$rs->post_tz);
283          } else {
284               return dt::dt2str($format,$rs->post_dt);
285          }
286     }
[2566]287
[0]288     /**
289     Returns post time with <var>$format</var> as formatting pattern. If format
290     is empty, uses <var>time_format</var> blog setting.
[2566]291
[0]292     @param    rs   Invisible parameter
293     @param    format    <b>string</b>       Time format pattern
294     @param    type <b>string</b>       (dt|upddt|creadt) defaults to post_dt
295     @return   <b>string</b>
296     */
297     public static function getTime($rs,$format,$type='')
298     {
299          if (!$format) {
300               $format = $rs->core->blog->settings->system->time_format;
301          }
[2566]302
[0]303          if ($type == 'upddt') {
304               return dt::dt2str($format,$rs->post_upddt,$rs->post_tz);
305          } elseif ($type == 'creadt') {
306               return dt::dt2str($format,$rs->post_creadt,$rs->post_tz);
307          } else {
308               return dt::dt2str($format,$rs->post_dt);
309          }
310     }
[2566]311
[0]312     /**
313     Returns author common name using user_id, user_name, user_firstname and
314     user_displayname fields.
[2566]315
[0]316     @param    rs   Invisible parameter
317     @return   <b>string</b>
318     */
319     public static function getAuthorCN($rs)
320     {
321          return dcUtils::getUserCN($rs->user_id, $rs->user_name,
322          $rs->user_firstname, $rs->user_displayname);
323     }
[2566]324
[0]325     /**
326     Returns author common name with a link if he specified one in its
327     preferences.
[2566]328
[0]329     @param    rs   Invisible parameter
330     @return   <b>string</b>
331     */
332     public static function getAuthorLink($rs)
333     {
334          $res = '%1$s';
335          $url = $rs->user_url;
336          if ($url) {
337               $res = '<a href="%2$s">%1$s</a>';
338          }
[2566]339
[0]340          return sprintf($res,html::escapeHTML($rs->getAuthorCN()),html::escapeHTML($url));
341     }
[2566]342
[0]343     /**
344     Returns author e-mail address. If <var>$encoded</var> is true, "@" sign is
345     replaced by "%40" and "." by "%2e".
[2566]346
[0]347     @param    rs   Invisible parameter
348     @param    encoded   <b>boolean</b>      Encode address.
349     @return   <b>string</b>
350     */
351     public static function getAuthorEmail($rs,$encoded=true)
352     {
353          if ($encoded) {
354               return strtr($rs->user_email,array('@'=>'%40','.'=>'%2e'));
355          }
356          return $rs->user_email;
357     }
[2566]358
[0]359     /**
360     Returns post feed unique ID.
[2566]361
[0]362     @param    rs   Invisible parameter
363     @return   <b>string</b>
364     */
365     public static function getFeedID($rs)
366     {
367          return 'urn:md5:'.md5($rs->core->blog->uid.$rs->post_id);
368     }
[2566]369
[0]370     /**
371     Returns trackback RDF information block in HTML comment.
[2566]372
[0]373     @param    rs   Invisible parameter
374     @return   <b>string</b>
375     */
[3424]376     public static function getTrackbackData($rs,$format='html')
[0]377     {
378          return
[3424]379          ($format == 'xml' ? "<![CDATA[>\n" : '').
380          "<!--\n".
[0]381          '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n".
382          '  xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n".
383          '  xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n".
384          "<rdf:Description\n".
385          '  rdf:about="'.$rs->getURL().'"'."\n".
386          '  dc:identifier="'.$rs->getURL().'"'."\n".
387          '  dc:title="'.htmlspecialchars($rs->post_title,ENT_COMPAT,'UTF-8').'"'."\n".
388          '  trackback:ping="'.$rs->getTrackbackLink().'" />'."\n".
389          "</rdf:RDF>\n".
[3424]390          ($format == 'xml' ? "<!]]><!--" : '').
391          "-->\n";
[0]392     }
[2566]393
[0]394     /**
395     Returns post trackback full URL.
[2566]396
[0]397     @param    rs   Invisible parameter
398     @return   <b>string</b>
399     */
400     public static function getTrackbackLink($rs)
401     {
[776]402          return $rs->core->blog->url.$rs->core->url->getURLFor('trackback',$rs->post_id);
[0]403     }
[2566]404
[0]405     /**
406     Returns post content. If <var>$absolute_urls</var> is true, appends full
407     blog URL to each relative post URLs.
[2566]408
[0]409     @param    rs   Invisible parameter
410     @param    absolute_urls  <b>boolean</b>      With absolute URLs
411     @return   <b>string</b>
412     */
413     public static function getContent($rs,$absolute_urls=false)
414     {
415          if ($absolute_urls) {
416               return html::absoluteURLs($rs->post_content_xhtml,$rs->getURL());
417          } else {
418               return $rs->post_content_xhtml;
419          }
420     }
[2566]421
[0]422     /**
423     Returns post excerpt. If <var>$absolute_urls</var> is true, appends full
424     blog URL to each relative post URLs.
[2566]425
[0]426     @param    rs   Invisible parameter
427     @param    absolute_urls  <b>boolean</b>      With absolute URLs
428     @return   <b>string</b>
429     */
430     public static function getExcerpt($rs,$absolute_urls=false)
431     {
432          if ($absolute_urls) {
433               return html::absoluteURLs($rs->post_excerpt_xhtml,$rs->getURL());
434          } else {
435               return $rs->post_excerpt_xhtml;
436          }
437     }
[2566]438
[0]439     /**
440     Returns post media count using a subquery.
[2566]441
[0]442     @param    rs   Invisible parameter
443     @return   <b>integer</b>
444     */
[3167]445     public static function countMedia($rs,$link_type=null)
[0]446     {
447          if (isset($rs->_nb_media[$rs->index()]))
448          {
449               return $rs->_nb_media[$rs->index()];
450          }
451          else
452          {
453               $strReq =
454               'SELECT count(media_id) '.
455               'FROM '.$rs->core->prefix.'post_media '.
456               'WHERE post_id = '.(integer) $rs->post_id.' ';
[3167]457               if ($link_type != null) {
458                    $strReq .= "AND link_type = '".$rs->core->con->escape($link_type)."'";
459               }
[2566]460
[0]461               $res = (integer) $rs->core->con->select($strReq)->f(0);
462               $rs->_nb_media[$rs->index()] = $res;
463               return $res;
464          }
465     }
466}
467
468/**
469@ingroup DC_CORE
470@brief Dotclear comment record helpers.
471
472This class adds new methods to database comment results.
473You can call them on every record comming from dcBlog::getComments and similar
474methods.
475
476@warning You should not give the first argument (usualy $rs) of every described
477function.
478*/
479class rsExtComment
480{
481     /**
482     Returns comment date with <var>$format</var> as formatting pattern. If
483     format is empty, uses <var>date_format</var> blog setting.
[2566]484
[0]485     @param    rs   Invisible parameter
486     @param    format    <b>string</b>       Date format pattern
487     @param    type <b>string</b>       (dt|upddt) defaults to comment_dt
488     @return   <b>string</b>
489     */
490     public static function getDate($rs,$format,$type='')
491     {
492          if (!$format) {
493               $format = $rs->core->blog->settings->system->date_format;
494          }
[2566]495
[0]496          if ($type == 'upddt') {
497               return dt::dt2str($format,$rs->comment_upddt,$rs->comment_tz);
498          } else {
499               return dt::dt2str($format,$rs->comment_dt);
500          }
501     }
[2566]502
[0]503     /**
504     Returns comment time with <var>$format</var> as formatting pattern. If
505     format is empty, uses <var>time_format</var> blog setting.
[2566]506
[0]507     @param    rs   Invisible parameter
508     @param    format    <b>string</b>       Date format pattern
509     @param    type <b>string</b>       (dt|upddt) defaults to comment_dt
510     @return   <b>string</b>
511     */
512     public static function getTime($rs,$format,$type='')
513     {
514          if (!$format) {
515               $format = $rs->core->blog->settings->system->time_format;
516          }
[2566]517
[0]518          if ($type == 'upddt') {
519               return dt::dt2str($format,$rs->comment_updt,$rs->comment_tz);
520          } else {
521               return dt::dt2str($format,$rs->comment_dt);
522          }
523     }
[2566]524
[0]525     /**
526     Returns comment timestamp.
[2566]527
[0]528     @param    rs   Invisible parameter
529     @param    type <b>string</b>       (dt|upddt) defaults to comment_dt
530     @return   <b>integer</b>
531     */
532     public static function getTS($rs,$type='')
533     {
534          if ($type == 'upddt') {
535               return strtotime($rs->comment_upddt);
536          } else {
537               return strtotime($rs->comment_dt);
538          }
539     }
[2566]540
[0]541     /**
542     Returns comment date formating according to the ISO 8601 standard.
[2566]543
[0]544     @param    rs   Invisible parameter
545     @param    type <b>string</b>       (dt|upddt) defaults to comment_dt
546     @return   <b>string</b>
547     */
548     public static function getISO8601Date($rs,$type='')
549     {
550          if ($type == 'upddt') {
551               return dt::iso8601($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz);
552          } else {
553               return dt::iso8601($rs->getTS(),$rs->comment_tz);
554          }
555     }
[2566]556
[0]557     /**
558     Returns comment date formating according to RFC 822.
[2566]559
[0]560     @param    rs   Invisible parameter
561     @param    type <b>string</b>       (dt|upddt) defaults to comment_dt
562     @return   <b>string</b>
563     */
564     public static function getRFC822Date($rs,$type='')
565     {
566          if ($type == 'upddt') {
567               return dt::rfc822($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz);
568          } else {
569               return dt::rfc822($rs->getTS(),$rs->comment_tz);
570          }
571     }
[2566]572
[0]573     /**
574     Returns comment content. If <var>$absolute_urls</var> is true, appends full
575     blog URL to each relative post URLs.
[2566]576
[0]577     @param    rs   Invisible parameter
578     @param    absolute_urls  <b>boolean</b>      With absolute URLs
579     @return   <b>string</b>
580     */
581     public static function getContent($rs,$absolute_urls=false)
582     {
583          $res = $rs->comment_content;
[2566]584
[0]585          if ($rs->core->blog->settings->system->comments_nofollow) {
586               $res = preg_replace_callback('#<a(.*?href=".*?".*?)>#ms',array('self','noFollowURL'),$res);
587          }
[2566]588
[0]589          if ($absolute_urls) {
590               $res = html::absoluteURLs($res,$rs->getPostURL());
591          }
[2566]592
[0]593          return $res;
594     }
[2566]595
[0]596     private static function noFollowURL($m)
597     {
598          if (preg_match('/rel="nofollow"/',$m[1])) {
599               return $m[0];
600          }
[2566]601
[0]602          return '<a'.$m[1].' rel="nofollow">';
603     }
[2566]604
[0]605     /**
606     Returns comment author link to his website if he specified one.
[2566]607
[0]608     @param    rs   Invisible parameter
609     @return   <b>string</b>
610     */
611     public static function getAuthorURL($rs)
612     {
613          if (trim($rs->comment_site)) {
614               return trim($rs->comment_site);
615          }
616     }
[2566]617
[0]618     /**
619     Returns comment post full URL.
[2566]620
[0]621     @param    rs   Invisible parameter
622     @return   <b>string</b>
623     */
624     public static function getPostURL($rs)
625     {
626          return $rs->core->blog->url.$rs->core->getPostPublicURL(
627                    $rs->post_type,html::sanitizeURL($rs->post_url)
628               );
629     }
[2566]630
[0]631     /**
632     Returns comment author name in a link to his website if he specified one.
[2566]633
[0]634     @param    rs   Invisible parameter
635     @return   <b>string</b>
636     */
637     public static function getAuthorLink($rs)
638     {
639          $res = '%1$s';
640          $url = $rs->getAuthorURL();
641          if ($url) {
642               $res = '<a href="%2$s"%3$s>%1$s</a>';
643          }
[2566]644
[0]645          $nofollow = '';
646          if ($rs->core->blog->settings->system->comments_nofollow) {
647               $nofollow = ' rel="nofollow"';
648          }
[2566]649
[0]650          return sprintf($res,html::escapeHTML($rs->comment_author),html::escapeHTML($url),$nofollow);
651     }
[2566]652
[0]653     /**
654     Returns comment author e-mail address. If <var>$encoded</var> is true,
655     "@" sign is replaced by "%40" and "." by "%2e".
[2566]656
[0]657     @param    rs   Invisible parameter
658     @param    encoded   <b>boolean</b>      Encode address.
659     @return   <b>string</b>
660     */
661     public static function getEmail($rs,$encoded=true)
662     {
663          if ($encoded) {
664               return strtr($rs->comment_email,array('@'=>'%40','.'=>'%2e'));
665          }
666          return $rs->comment_email;
667     }
[2566]668
[0]669     /**
670     Returns trackback site title if comment is a trackback.
[2566]671
[0]672     @param    rs   Invisible parameter
673     @return   <b>string</b>
674     */
675     public static function getTrackbackTitle($rs)
676     {
677          if ($rs->comment_trackback == 1 &&
678          preg_match('|<p><strong>(.*?)</strong></p>|msU',$rs->comment_content,
679          $match)) {
680               return html::decodeEntities($match[1]);
681          }
682     }
[2566]683
[0]684     /**
685     Returns trackback content if comment is a trackback.
[2566]686
[0]687     @param    rs   Invisible parameter
688     @return   <b>string</b>
689     */
690     public static function getTrackbackContent($rs)
691     {
692          if ($rs->comment_trackback == 1) {
693               return preg_replace('|<p><strong>.*?</strong></p>|msU','',
694               $rs->comment_content);
695          }
696     }
[2566]697
[0]698     /**
699     Returns comment feed unique ID.
[2566]700
[0]701     @param    rs   Invisible parameter
702     @return   <b>string</b>
703     */
704     public static function getFeedID($rs)
705     {
706          return 'urn:md5:'.md5($rs->core->blog->uid.$rs->comment_id);
707     }
[2566]708
[0]709     /**
710     Returns whether comment is from the post author.
[2566]711
[0]712     @param    rs   Invisible parameter
713     @return   <b>boolean</b>
714     */
715     public static function isMe($rs)
716     {
717          return
718          $rs->comment_email && $rs->comment_site &&
719          $rs->comment_email == $rs->user_email &&
720          $rs->comment_site == $rs->user_url;
721     }
722}
723
724/**
725@ingroup DC_CORE
726@brief Dotclear dates record helpers.
727
728This class adds new methods to database dates results.
729You can call them on every record comming from dcBlog::getDates.
730
731@warning You should not give the first argument (usualy $rs) of every described
732function.
733*/
734class rsExtDates
735{
736     /**
737     @param    rs   Invisible parameter
738     @return   <b>integer</b>      Date timestamp
739     */
740     public static function ts($rs)
741     {
742          return strtotime($rs->dt);
743     }
[2566]744
[0]745     /**
746     @param    rs   Invisible parameter
747     @return   <b>string</b>       Date year
748     */
749     public static function year($rs)
750     {
751          return date('Y',strtotime($rs->dt));
752     }
[2566]753
[0]754     /**
755     @param    rs   Invisible parameter
756     @return   <b>string</b>       Date month
757     */
758     public static function month($rs)
759     {
760          return date('m',strtotime($rs->dt));
761     }
[2566]762
[0]763     /**
764     @param    rs   Invisible parameter
765     @return   <b>integer</b>      Date day
766     */
767     public static function day($rs)
768     {
769          return date('d',strtotime($rs->dt));
770     }
[2566]771
[0]772     /**
773     Returns date month archive full URL.
[2566]774
[0]775     @param    rs   Invisible parameter
776     @param    core      <b>dcCore</b>       dcCore instance
777     @return   <b>integer</b>
778     */
779     public static function url($rs,$core)
780     {
781          $url = date('Y/m',strtotime($rs->dt));
[2566]782
[776]783          return $core->blog->url.$core->url->getURLFor('archive',$url);
[0]784     }
[2566]785
[0]786     /**
787     Returns whether date is the first of year.
[2566]788
[0]789     @param    rs   Invisible parameter
790     @return   <b>boolean</b>
791     */
792     public static function yearHeader($rs)
793     {
794          if ($rs->isStart()) {
795               return true;
796          }
[2566]797
[0]798          $y = $rs->year();
799          $rs->movePrev();
800          $py = $rs->year();
801          $rs->moveNext();
[2566]802
[0]803          return $y != $py;
804     }
[2566]805
[0]806     /**
807     Returns whether date is the last of year.
[2566]808
[0]809     @param    rs   Invisible parameter
810     @return   <b>boolean</b>
811     */
812     public static function yearFooter($rs)
813     {
814          if ($rs->isEnd()) {
815               return true;
816          }
[2566]817
[0]818          $y = $rs->year();
819          if ($rs->moveNext()) {
820               $ny = $rs->year();
821               $rs->movePrev();
822               return $y != $ny;
823          }
824          return false;
[2566]825
[0]826     }
827}
828
829/**
830@ingroup DC_CORE
831@brief Dotclear dates record helpers.
832
833This class adds new methods to database dates results.
834You can call them on every record comming from dcAuth::checkUser and
835dcCore::getUsers.
836
837@warning You should not give the first argument (usualy $rs) of every described
838function.
839*/
840class rsExtUser
841{
[3105]842     private static $sortfield;
843     private static $sortsign;
[0]844     /**
845     Returns a user option.
[2566]846
[0]847     @param    rs   Invisible parameter
848     @param    name      <b>string</b>       Option name
849     @return   <b>string</b>
850     */
851     public static function option($rs,$name)
852     {
853          $options = self::options($rs);
[2566]854
[0]855          if (isset($options[$name])) {
856               return $options[$name];
857          }
858          return null;
859     }
[2566]860
[0]861     /**
862     Returns all user options.
[2566]863
[0]864     @param    rs   Invisible parameter
865     @return   <b>array</b>
866     */
867     public static function options($rs)
868     {
869          $options = @unserialize($rs->user_options);
870          if (is_array($options)) {
871               return $options;
872          }
873          return array();
874     }
[3105]875
876     /**
877     Converts this record to a {@link extStaticRecord} instance.
878
879     @param    rs   Invisible parameter
880      */
881     public static function toExtStatic($rs)
882     {
883          if ($rs instanceof extStaticRecord) {
884               return $rs;
885          }
886          return new extStaticRecord($rs);
887     }
[0]888}
[3105]889
[3106]890class rsExtBlog
891{
892     private static $sortfield;
893     private static $sortsign;
894     /**
895     Converts this record to a {@link extStaticRecord} instance.
896
897     @param    rs   Invisible parameter
898      */
899     public static function toExtStatic($rs)
900     {
901          if ($rs instanceof extStaticRecord) {
902               return $rs;
903          }
904          return new extStaticRecord($rs);
905     }
906}
907
[3105]908class extStaticRecord extends staticRecord
909{
910     private $sortfield;
911     private $sortsign;
912
913     public function __construct($rs)
914     {
915          parent::__construct($rs->__data,$rs->__info);
916     }
917
918     /**
919     Lexically sort.
920
921     @param    field     <b>string<b>   sort field
922     @param  order  <b>string<b>   sort order
923      */
924     public function lexicalSort($field,$order='asc')
925     {
926          $this->sortfield = $field;
927          $this->sortsign = strtolower($order) == 'asc' ? 1 : -1;
928
929          usort($this->__data,array($this,'lexicalSortCallback'));
930
931          $this->sortfield = null;
932          $this->sortsign = null;
933     }
934     private function lexicalSortCallback($a,$b)
935     {
936          $a = $a[$this->sortfield];
937          $b = $b[$this->sortfield];
938
939          # Integer values
940          if ($a == (string) (integer) $a && $b == (string) (integer) $b) {
941               $a = (integer) $a;
942               $b = (integer) $b;
943               return ($a - $b) * $this->sortsign;
944          }
945
946          return strcoll(strtolower(dcUtils::removeDiacritics($a)),strtolower(dcUtils::removeDiacritics($b))) * $this->sortsign;
947     }
948}
Note: See TracBrowser for help on using the repository browser.

Sites map