add cms, add todo
[ssproject1617.git] / testcms-final-anon / system / functions / comments.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 /**
4 Theme functions for comments
5 */
6
7 function has_comments() {
8 if(($itm = IoC::resolve('article')) === false) {
9 return false;
10 }
11
12 if(($items = IoC::resolve('comments')) === false) {
13 $items = Comments::list_all(array('status' => 'published', 'post' => $itm->id));
14 IoC::instance('comments', $items, true);
15 }
16
17 return $items->length() > 0;
18 }
19
20 function total_comments() {
21 if(has_comments() === false) {
22 return 0;
23 }
24
25 $items = IoC::resolve('comments');
26 return $items->length();
27 }
28
29 // loop comments
30 function comments() {
31 if(has_comments() === false) {
32 return false;
33 }
34
35 $items = IoC::resolve('comments');
36
37 if($result = $items->valid()) {
38 // register single comment
39 IoC::instance('comment', $items->current(), true);
40
41 // move to next
42 $items->next();
43 }
44
45 return $result;
46 }
47
48 // single comments
49 function comment_id() {
50 if($itm = IoC::resolve('comment')) {
51 return $itm->id;
52 }
53
54 return '';
55 }
56
57 function comment_time() {
58 if($itm = IoC::resolve('comment')) {
59 return $itm->date;
60 }
61
62 return '';
63 }
64
65 function comment_date() {
66 if($itm = IoC::resolve('comment')) {
67 return date(Config::get('metadata.date_format'), $itm->date);
68 }
69
70 return '';
71 }
72
73 function comment_name() {
74 if($itm = IoC::resolve('comment')) {
75 return $itm->name;
76 }
77
78 return '';
79 }
80
81 function comment_text() {
82 if($itm = IoC::resolve('comment')) {
83 return $itm->text;
84 }
85
86 return '';
87 }
88
89 function comments_open() {
90 if($itm = IoC::resolve('article')) {
91 return $itm->comments ? true : false;
92 }
93
94 return false;
95 }
96
97 // form elements
98 function comment_form_notifications() {
99 return Notifications::read();
100 }
101
102 function comment_form_input_name($extra = '') {
103 return '<input name="name" id="name" type="text" ' . $extra . '>';
104 }
105
106 function comment_form_input_email($extra = '') {
107 return '<input name="email" id="email" type="email" ' . $extra . '>';
108 }
109
110 function comment_form_input_text($extra = '') {
111 return '<textarea name="text" id="text" ' . $extra . '></textarea>';
112 }
113
114 function comment_form_button($text = 'Post Comment', $extra = '') {
115 return '<button class="btn" type="submit" ' . $extra . '>' . $text . '</button>';
116 }