File: class.dc.rs.extensions.php

package info (click to toggle)
dotclear 2.6.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 8,420 kB
  • sloc: php: 54,270; sql: 1,290; sh: 213; xml: 173; makefile: 158
file content (879 lines) | stat: -rw-r--r-- 20,052 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK -----------------------------------------
if (!defined('DC_RC_PATH')) { return; }

/**
@ingroup DC_CORE
@brief Dotclear post record helpers.

This class adds new methods to database post results.
You can call them on every record comming from dcBlog::getPosts and similar
methods.

@warning You should not give the first argument (usualy $rs) of every described
function.
*/
class rsExtPost
{
	/**
	Returns whether post is editable.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function isEditable($rs)
	{
		# If user is admin or contentadmin, true
		if ($rs->core->auth->check('contentadmin',$rs->core->blog->id)) {
			return true;
		}

		# No user id in result ? false
		if (!$rs->exists('user_id')) {
			return false;
		}

		# If user is usage and owner of the entrie
		if ($rs->core->auth->check('usage',$rs->core->blog->id)
		&& $rs->user_id == $rs->core->auth->userID()) {
			return true;
		}

		return false;
	}

	/**
	Returns whether post is deletable

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function isDeletable($rs)
	{
		# If user is admin, or contentadmin, true
		if ($rs->core->auth->check('contentadmin',$rs->core->blog->id)) {
			return true;
		}

		# No user id in result ? false
		if (!$rs->exists('user_id')) {
			return false;
		}

		# If user has delete rights and is owner of the entrie
		if ($rs->core->auth->check('delete',$rs->core->blog->id)
		&& $rs->user_id == $rs->core->auth->userID()) {
			return true;
		}

		return false;
	}

	/**
	Returns whether post is the first one of its day.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function firstPostOfDay($rs)
	{
		if ($rs->isStart()) {
			return true;
		}

		$cdate = date('Ymd',strtotime($rs->post_dt));
		$rs->movePrev();
		$ndate = date('Ymd',strtotime($rs->post_dt));
		$rs->moveNext();
		return $ndate != $cdate;
	}

	/**
	Returns whether post is the last one of its day.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function lastPostOfDay($rs)
	{
		if ($rs->isEnd()) {
			return true;
		}

		$cdate = date('Ymd',strtotime($rs->post_dt));
		$rs->moveNext();
		$ndate = date('Ymd',strtotime($rs->post_dt));
		$rs->movePrev();
		return $ndate != $cdate;
	}

	/**
	Returns whether comments are enabled on post.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function commentsActive($rs)
	{
		return
		$rs->core->blog->settings->system->allow_comments
		&& $rs->post_open_comment
		&& ($rs->core->blog->settings->system->comments_ttl == 0 ||
		time()-($rs->core->blog->settings->system->comments_ttl*86400) < $rs->getTS());
	}

	/**
	Returns whether trackbacks are enabled on post.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function trackbacksActive($rs)
	{
		return
		$rs->core->blog->settings->system->allow_trackbacks
		&& $rs->post_open_tb
		&& ($rs->core->blog->settings->system->trackbacks_ttl == 0 ||
		time()-($rs->core->blog->settings->system->trackbacks_ttl*86400) < $rs->getTS());
	}

	/**
	Returns whether post has at least one comment.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function hasComments($rs)
	{
		return $rs->nb_comment > 0;
	}

	/**
	Returns whether post has at least one trackbacks.

	@return	<b>boolean</b>
	*/
	public static function hasTrackbacks($rs)
	{
		return $rs->nb_trackback > 0;
	}

	/**
	Returns whether post has been updated since publication.

	@return <b>boolean</b>
	*/
	public static function isRepublished($rs)
	{
		return ($rs->getTS('upddt') + dt::getTimeOffset($rs->post_tz)) > $rs->getTS();
	}

	/**
	Returns full post URL.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getURL($rs)
	{
		return $rs->core->blog->url.$rs->core->getPostPublicURL(
				$rs->post_type,html::sanitizeURL($rs->post_url)
			);
	}

	/**
	Returns full post category URL.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getCategoryURL($rs)
	{
		return $rs->core->blog->url.$rs->core->url->getURLFor('category',html::sanitizeURL($rs->cat_url));
	}

	/**
	Returns whether post has an excerpt.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function isExtended($rs)
	{
		return $rs->post_excerpt_xhtml != '';
	}

	/**
	Returns post timestamp.

	@param	rs	Invisible parameter
	@param	type	<b>string</b>		(dt|upddt|creadt) defaults to post_dt
	@return	<b>integer</b>
	*/
	public static function getTS($rs,$type='')
	{
		if ($type == 'upddt') {
			return strtotime($rs->post_upddt);
		} elseif ($type == 'creadt') {
			return strtotime($rs->post_creadt);
		} else {
			return strtotime($rs->post_dt);
		}
	}

	/**
	Returns post date formating according to the ISO 8601 standard.

	@param	rs	Invisible parameter
	@param	type	<b>string</b>		(dt|upddt|creadt) defaults to post_dt
	@return	<b>string</b>
	*/
	public static function getISO8601Date($rs,$type='')
	{
		if ($type == 'upddt' || $type == 'creadt') {
			return dt::iso8601($rs->getTS($type)+dt::getTimeOffset($rs->post_tz),$rs->post_tz);
		} else {
			return dt::iso8601($rs->getTS(),$rs->post_tz);
		}
	}

	/**
	Returns post date formating according to RFC 822.

	@param	rs	Invisible parameter
	@param	type	<b>string</b>		(dt|upddt|creadt) defaults to post_dt
	@return	<b>string</b>
	*/
	public static function getRFC822Date($rs,$type='')
	{
		if ($type == 'upddt' || $type == 'creadt') {
			return dt::rfc822($rs->getTS($type)+dt::getTimeOffset($rs->post_tz),$rs->post_tz);
		} else {
			return dt::rfc822($rs->getTS($type),$rs->post_tz);
		}
	}

	/**
	Returns post date with <var>$format</var> as formatting pattern. If format
	is empty, uses <var>date_format</var> blog setting.

	@param	rs	Invisible parameter
	@param	format	<b>string</b>		Date format pattern
	@param	type	<b>string</b>		(dt|upddt|creadt) defaults to post_dt
	@return	<b>string</b>
	*/
	public static function getDate($rs,$format,$type='')
	{
		if (!$format) {
			$format = $rs->core->blog->settings->system->date_format;
		}

		if ($type == 'upddt') {
			return dt::dt2str($format,$rs->post_upddt,$rs->post_tz);
		} elseif ($type == 'creadt') {
			return dt::dt2str($format,$rs->post_creadt,$rs->post_tz);
		} else {
			return dt::dt2str($format,$rs->post_dt);
		}
	}

	/**
	Returns post time with <var>$format</var> as formatting pattern. If format
	is empty, uses <var>time_format</var> blog setting.

	@param	rs	Invisible parameter
	@param	format	<b>string</b>		Time format pattern
	@param	type	<b>string</b>		(dt|upddt|creadt) defaults to post_dt
	@return	<b>string</b>
	*/
	public static function getTime($rs,$format,$type='')
	{
		if (!$format) {
			$format = $rs->core->blog->settings->system->time_format;
		}

		if ($type == 'upddt') {
			return dt::dt2str($format,$rs->post_upddt,$rs->post_tz);
		} elseif ($type == 'creadt') {
			return dt::dt2str($format,$rs->post_creadt,$rs->post_tz);
		} else {
			return dt::dt2str($format,$rs->post_dt);
		}
	}

	/**
	Returns author common name using user_id, user_name, user_firstname and
	user_displayname fields.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getAuthorCN($rs)
	{
		return dcUtils::getUserCN($rs->user_id, $rs->user_name,
		$rs->user_firstname, $rs->user_displayname);
	}

	/**
	Returns author common name with a link if he specified one in its
	preferences.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getAuthorLink($rs)
	{
		$res = '%1$s';
		$url = $rs->user_url;
		if ($url) {
			$res = '<a href="%2$s">%1$s</a>';
		}

		return sprintf($res,html::escapeHTML($rs->getAuthorCN()),html::escapeHTML($url));
	}

	/**
	Returns author e-mail address. If <var>$encoded</var> is true, "@" sign is
	replaced by "%40" and "." by "%2e".

	@param	rs	Invisible parameter
	@param	encoded	<b>boolean</b>		Encode address.
	@return	<b>string</b>
	*/
	public static function getAuthorEmail($rs,$encoded=true)
	{
		if ($encoded) {
			return strtr($rs->user_email,array('@'=>'%40','.'=>'%2e'));
		}
		return $rs->user_email;
	}

	/**
	Returns post feed unique ID.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getFeedID($rs)
	{
		return 'urn:md5:'.md5($rs->core->blog->uid.$rs->post_id);

		$url = parse_url($rs->core->blog->url);
		$date_part = date('Y-m-d',strtotime($rs->post_creadt));

		return 'tag:'.$url['host'].','.$date_part.':'.$rs->post_id;
	}

	/**
	Returns trackback RDF information block in HTML comment.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getTrackbackData($rs)
	{
		return
		"<![CDATA[>\n".
		"<!--[\n".
		'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n".
		'  xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n".
		'  xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n".
		"<rdf:Description\n".
		'  rdf:about="'.$rs->getURL().'"'."\n".
		'  dc:identifier="'.$rs->getURL().'"'."\n".
		'  dc:title="'.htmlspecialchars($rs->post_title,ENT_COMPAT,'UTF-8').'"'."\n".
		'  trackback:ping="'.$rs->getTrackbackLink().'" />'."\n".
		"</rdf:RDF>\n".
		"<!]]><!---->\n";
	}

	/**
	Returns post trackback full URL.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getTrackbackLink($rs)
	{
		return $rs->core->blog->url.$rs->core->url->getURLFor('trackback',$rs->post_id);
	}

	/**
	Returns post content. If <var>$absolute_urls</var> is true, appends full
	blog URL to each relative post URLs.

	@param	rs	Invisible parameter
	@param	absolute_urls	<b>boolean</b>		With absolute URLs
	@return	<b>string</b>
	*/
	public static function getContent($rs,$absolute_urls=false)
	{
		if ($absolute_urls) {
			return html::absoluteURLs($rs->post_content_xhtml,$rs->getURL());
		} else {
			return $rs->post_content_xhtml;
		}
	}

	/**
	Returns post excerpt. If <var>$absolute_urls</var> is true, appends full
	blog URL to each relative post URLs.

	@param	rs	Invisible parameter
	@param	absolute_urls	<b>boolean</b>		With absolute URLs
	@return	<b>string</b>
	*/
	public static function getExcerpt($rs,$absolute_urls=false)
	{
		if ($absolute_urls) {
			return html::absoluteURLs($rs->post_excerpt_xhtml,$rs->getURL());
		} else {
			return $rs->post_excerpt_xhtml;
		}
	}

	/**
	Returns post media count using a subquery.

	@param	rs	Invisible parameter
	@return	<b>integer</b>
	*/
	public static function countMedia($rs)
	{
		if (isset($rs->_nb_media[$rs->index()]))
		{
			return $rs->_nb_media[$rs->index()];
		}
		else
		{
			$strReq =
			'SELECT count(media_id) '.
			'FROM '.$rs->core->prefix.'post_media '.
			'WHERE post_id = '.(integer) $rs->post_id.' ';

			$res = (integer) $rs->core->con->select($strReq)->f(0);
			$rs->_nb_media[$rs->index()] = $res;
			return $res;
		}
	}
}

/**
@ingroup DC_CORE
@brief Dotclear comment record helpers.

This class adds new methods to database comment results.
You can call them on every record comming from dcBlog::getComments and similar
methods.

@warning You should not give the first argument (usualy $rs) of every described
function.
*/
class rsExtComment
{
	/**
	Returns comment date with <var>$format</var> as formatting pattern. If
	format is empty, uses <var>date_format</var> blog setting.

	@param	rs	Invisible parameter
	@param	format	<b>string</b>		Date format pattern
	@param	type	<b>string</b>		(dt|upddt) defaults to comment_dt
	@return	<b>string</b>
	*/
	public static function getDate($rs,$format,$type='')
	{
		if (!$format) {
			$format = $rs->core->blog->settings->system->date_format;
		}

		if ($type == 'upddt') {
			return dt::dt2str($format,$rs->comment_upddt,$rs->comment_tz);
		} else {
			return dt::dt2str($format,$rs->comment_dt);
		}
	}

	/**
	Returns comment time with <var>$format</var> as formatting pattern. If
	format is empty, uses <var>time_format</var> blog setting.

	@param	rs	Invisible parameter
	@param	format	<b>string</b>		Date format pattern
	@param	type	<b>string</b>		(dt|upddt) defaults to comment_dt
	@return	<b>string</b>
	*/
	public static function getTime($rs,$format,$type='')
	{
		if (!$format) {
			$format = $rs->core->blog->settings->system->time_format;
		}

		if ($type == 'upddt') {
			return dt::dt2str($format,$rs->comment_updt,$rs->comment_tz);
		} else {
			return dt::dt2str($format,$rs->comment_dt);
		}
	}

	/**
	Returns comment timestamp.

	@param	rs	Invisible parameter
	@param	type	<b>string</b>		(dt|upddt) defaults to comment_dt
	@return	<b>integer</b>
	*/
	public static function getTS($rs,$type='')
	{
		if ($type == 'upddt') {
			return strtotime($rs->comment_upddt);
		} else {
			return strtotime($rs->comment_dt);
		}
	}

	/**
	Returns comment date formating according to the ISO 8601 standard.

	@param	rs	Invisible parameter
	@param	type	<b>string</b>		(dt|upddt) defaults to comment_dt
	@return	<b>string</b>
	*/
	public static function getISO8601Date($rs,$type='')
	{
		if ($type == 'upddt') {
			return dt::iso8601($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz);
		} else {
			return dt::iso8601($rs->getTS(),$rs->comment_tz);
		}
	}

	/**
	Returns comment date formating according to RFC 822.

	@param	rs	Invisible parameter
	@param	type	<b>string</b>		(dt|upddt) defaults to comment_dt
	@return	<b>string</b>
	*/
	public static function getRFC822Date($rs,$type='')
	{
		if ($type == 'upddt') {
			return dt::rfc822($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz);
		} else {
			return dt::rfc822($rs->getTS(),$rs->comment_tz);
		}
	}

	/**
	Returns comment content. If <var>$absolute_urls</var> is true, appends full
	blog URL to each relative post URLs.

	@param	rs	Invisible parameter
	@param	absolute_urls	<b>boolean</b>		With absolute URLs
	@return	<b>string</b>
	*/
	public static function getContent($rs,$absolute_urls=false)
	{
		$res = $rs->comment_content;

		if ($rs->core->blog->settings->system->comments_nofollow) {
			$res = preg_replace_callback('#<a(.*?href=".*?".*?)>#ms',array('self','noFollowURL'),$res);
		}

		if ($absolute_urls) {
			$res = html::absoluteURLs($res,$rs->getPostURL());
		}

		return $res;
	}

	private static function noFollowURL($m)
	{
		if (preg_match('/rel="nofollow"/',$m[1])) {
			return $m[0];
		}

		return '<a'.$m[1].' rel="nofollow">';
	}

	/**
	Returns comment author link to his website if he specified one.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getAuthorURL($rs)
	{
		if (trim($rs->comment_site)) {
			return trim($rs->comment_site);
		}
	}

	/**
	Returns comment post full URL.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getPostURL($rs)
	{
		return $rs->core->blog->url.$rs->core->getPostPublicURL(
				$rs->post_type,html::sanitizeURL($rs->post_url)
			);
	}

	/**
	Returns comment author name in a link to his website if he specified one.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getAuthorLink($rs)
	{
		$res = '%1$s';
		$url = $rs->getAuthorURL();
		if ($url) {
			$res = '<a href="%2$s"%3$s>%1$s</a>';
		}

		$nofollow = '';
		if ($rs->core->blog->settings->system->comments_nofollow) {
			$nofollow = ' rel="nofollow"';
		}

		return sprintf($res,html::escapeHTML($rs->comment_author),html::escapeHTML($url),$nofollow);
	}

	/**
	Returns comment author e-mail address. If <var>$encoded</var> is true,
	"@" sign is replaced by "%40" and "." by "%2e".

	@param	rs	Invisible parameter
	@param	encoded	<b>boolean</b>		Encode address.
	@return	<b>string</b>
	*/
	public static function getEmail($rs,$encoded=true)
	{
		if ($encoded) {
			return strtr($rs->comment_email,array('@'=>'%40','.'=>'%2e'));
		}
		return $rs->comment_email;
	}

	/**
	Returns trackback site title if comment is a trackback.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getTrackbackTitle($rs)
	{
		if ($rs->comment_trackback == 1 &&
		preg_match('|<p><strong>(.*?)</strong></p>|msU',$rs->comment_content,
		$match)) {
			return html::decodeEntities($match[1]);
		}
	}

	/**
	Returns trackback content if comment is a trackback.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getTrackbackContent($rs)
	{
		if ($rs->comment_trackback == 1) {
			return preg_replace('|<p><strong>.*?</strong></p>|msU','',
			$rs->comment_content);
		}
	}

	/**
	Returns comment feed unique ID.

	@param	rs	Invisible parameter
	@return	<b>string</b>
	*/
	public static function getFeedID($rs)
	{
		return 'urn:md5:'.md5($rs->core->blog->uid.$rs->comment_id);

		$url = parse_url($rs->core->blog->url);
		$date_part = date('Y-m-d',strtotime($rs->comment_dt));

		return 'tag:'.$url['host'].','.$date_part.':'.$rs->comment_id;
	}

	/**
	Returns whether comment is from the post author.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function isMe($rs)
	{
		return
		$rs->comment_email && $rs->comment_site &&
		$rs->comment_email == $rs->user_email &&
		$rs->comment_site == $rs->user_url;
	}
}

/**
@ingroup DC_CORE
@brief Dotclear dates record helpers.

This class adds new methods to database dates results.
You can call them on every record comming from dcBlog::getDates.

@warning You should not give the first argument (usualy $rs) of every described
function.
*/
class rsExtDates
{
	/**
	@param	rs	Invisible parameter
	@return	<b>integer</b>		Date timestamp
	*/
	public static function ts($rs)
	{
		return strtotime($rs->dt);
	}

	/**
	@param	rs	Invisible parameter
	@return	<b>string</b>		Date year
	*/
	public static function year($rs)
	{
		return date('Y',strtotime($rs->dt));
	}

	/**
	@param	rs	Invisible parameter
	@return	<b>string</b>		Date month
	*/
	public static function month($rs)
	{
		return date('m',strtotime($rs->dt));
	}

	/**
	@param	rs	Invisible parameter
	@return	<b>integer</b>		Date day
	*/
	public static function day($rs)
	{
		return date('d',strtotime($rs->dt));
	}

	/**
	Returns date month archive full URL.

	@param	rs	Invisible parameter
	@param	core		<b>dcCore</b>		dcCore instance
	@return	<b>integer</b>
	*/
	public static function url($rs,$core)
	{
		$url = date('Y/m',strtotime($rs->dt));

		return $core->blog->url.$core->url->getURLFor('archive',$url);
	}

	/**
	Returns whether date is the first of year.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function yearHeader($rs)
	{
		if ($rs->isStart()) {
			return true;
		}

		$y = $rs->year();
		$rs->movePrev();
		$py = $rs->year();
		$rs->moveNext();

		return $y != $py;
	}

	/**
	Returns whether date is the last of year.

	@param	rs	Invisible parameter
	@return	<b>boolean</b>
	*/
	public static function yearFooter($rs)
	{
		if ($rs->isEnd()) {
			return true;
		}

		$y = $rs->year();
		if ($rs->moveNext()) {
			$ny = $rs->year();
			$rs->movePrev();
			return $y != $ny;
		}
		return false;

	}
}

/**
@ingroup DC_CORE
@brief Dotclear dates record helpers.

This class adds new methods to database dates results.
You can call them on every record comming from dcAuth::checkUser and
dcCore::getUsers.

@warning You should not give the first argument (usualy $rs) of every described
function.
*/
class rsExtUser
{
	/**
	Returns a user option.

	@param	rs	Invisible parameter
	@param	name		<b>string</b>		Option name
	@return	<b>string</b>
	*/
	public static function option($rs,$name)
	{
		$options = self::options($rs);

		if (isset($options[$name])) {
			return $options[$name];
		}
		return null;
	}

	/**
	Returns all user options.

	@param	rs	Invisible parameter
	@return	<b>array</b>
	*/
	public static function options($rs)
	{
		$options = @unserialize($rs->user_options);
		if (is_array($options)) {
			return $options;
		}
		return array();
	}
}