95 echo enano_json_encode($ret); |
95 echo enano_json_encode($ret); |
96 return $ret; |
96 return $ret; |
97 } |
97 } |
98 $ret = Array(); |
98 $ret = Array(); |
99 $ret['mode'] = $data['mode']; |
99 $ret['mode'] = $data['mode']; |
|
100 if ( isset($data['passback']) ) |
|
101 $ret['passback'] = $data['passback']; |
100 switch ( $data['mode'] ) |
102 switch ( $data['mode'] ) |
101 { |
103 { |
102 case 'fetch': |
104 case 'fetch': |
103 if ( !$template->theme_loaded ) |
105 if ( !$template->theme_loaded ) |
104 $template->load_theme(); |
106 $template->load_theme(); |
105 if ( !isset($data['have_template']) ) |
107 if ( !isset($data['have_template']) ) |
106 { |
108 { |
107 $ret['template'] = file_get_contents(ENANO_ROOT . '/themes/' . $template->theme . '/comment.tpl'); |
109 $ret['template'] = file_get_contents(ENANO_ROOT . '/themes/' . $template->theme . '/comment.tpl'); |
108 } |
110 } |
|
111 $approve_clause = $this->perms->get_permissions('mod_comments') ? '' : " AND approved = " . COMMENT_APPROVED; |
|
112 // Get totals |
|
113 $q = $db->sql_query('SELECT approved FROM ' . table_prefix . "comments WHERE page_id = '$this->page_id' AND namespace = '$this->namespace'{$approve_clause};"); |
|
114 if ( !$q ) |
|
115 $db->die_json(); |
|
116 $counts = array('total' => 0, 'approved' => 0, 'unapproved' => 0, 'spam' => 0); |
|
117 while ( $row = $db->fetchrow() ) |
|
118 { |
|
119 $counts['total']++; |
|
120 switch($row['approved']): |
|
121 case COMMENT_APPROVED: $counts['approved']++; break; |
|
122 case COMMENT_UNAPPROVED: $counts['unapproved']++; break; |
|
123 case COMMENT_SPAM: $counts['spam']++; break; |
|
124 endswitch; |
|
125 } |
|
126 $counts['unapproved'] = $counts['total'] - $counts['approved']; |
|
127 $data['counts'] = $counts; |
|
128 // FIXME, this should be a user preference eventually |
|
129 $ret['per_page'] = $per_page = getConfig('comments_per_page', 10); |
|
130 $page = ( !empty($data['pagenum']) ) ? intval($data['pagenum']) : 0; |
|
131 if ( $page > 0 ) |
|
132 { |
|
133 $ret['mode'] = 'refetch'; |
|
134 } |
|
135 $limit_clause = "LIMIT $per_page OFFSET " . ($page * $per_page); |
109 $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,( c.ip_address IS NOT NULL ) AS have_ip,u.user_level,u.user_id,u.email,u.signature,u.user_has_avatar,u.avatar_type, b.buddy_id IS NOT NULL AS is_buddy, ( b.is_friend IS NOT NULL AND b.is_friend=1 ) AS is_friend FROM '.table_prefix.'comments AS c |
136 $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,( c.ip_address IS NOT NULL ) AS have_ip,u.user_level,u.user_id,u.email,u.signature,u.user_has_avatar,u.avatar_type, b.buddy_id IS NOT NULL AS is_buddy, ( b.is_friend IS NOT NULL AND b.is_friend=1 ) AS is_friend FROM '.table_prefix.'comments AS c |
110 LEFT JOIN '.table_prefix.'users AS u |
137 LEFT JOIN '.table_prefix.'users AS u |
111 ON (u.user_id=c.user_id) |
138 ON (u.user_id=c.user_id) |
112 LEFT JOIN '.table_prefix.'buddies AS b |
139 LEFT JOIN '.table_prefix.'buddies AS b |
113 ON ( ( b.user_id=' . $session->user_id.' AND b.buddy_user_id=c.user_id ) OR b.user_id IS NULL) |
140 ON ( ( b.user_id=' . $session->user_id.' AND b.buddy_user_id=c.user_id ) OR b.user_id IS NULL) |
114 LEFT JOIN '.table_prefix.'ranks AS r |
141 LEFT JOIN '.table_prefix.'ranks AS r |
115 ON ( ( u.user_rank = r.rank_id ) ) |
142 ON ( ( u.user_rank = r.rank_id ) ) |
116 WHERE page_id=\'' . $this->page_id . '\' |
143 WHERE page_id=\'' . $this->page_id . '\' |
117 AND namespace=\'' . $this->namespace . '\' |
144 AND namespace=\'' . $this->namespace . '\' |
|
145 ' . $approve_clause . ' |
118 GROUP BY c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,c.ip_address,u.user_level,u.user_id,u.email,u.signature,u.user_has_avatar,u.avatar_type,b.buddy_id,b.is_friend |
146 GROUP BY c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,c.ip_address,u.user_level,u.user_id,u.email,u.signature,u.user_has_avatar,u.avatar_type,b.buddy_id,b.is_friend |
119 ORDER BY c.time ASC;'); |
147 ORDER BY c.time ASC |
120 $count_appr = 0; |
148 ' . $limit_clause . ';'); |
121 $count_total = 0; |
|
122 $count_unappr = 0; |
|
123 $ret['comments'] = Array(); |
149 $ret['comments'] = Array(); |
124 if (!$q) |
150 if (!$q) |
125 $db->die_json(); |
151 $db->die_json(); |
126 if ( $row = $db->fetchrow($q) ) |
152 if ( $row = $db->fetchrow($q) ) |
127 { |
153 { |
128 do { |
154 do { |
129 |
|
130 // Increment counters |
|
131 $count_total++; |
|
132 ( $row['approved'] == 1 ) ? $count_appr++ : $count_unappr++; |
|
133 |
155 |
134 if ( !$this->perms->get_permissions('mod_comments') && $row['approved'] != COMMENT_APPROVED ) |
156 if ( !$this->perms->get_permissions('mod_comments') && $row['approved'] != COMMENT_APPROVED ) |
135 continue; |
157 continue; |
136 |
158 |
137 // Localize the rank |
159 // Localize the rank |
172 $ret['comments'][] = $row; |
194 $ret['comments'][] = $row; |
173 |
195 |
174 } while ( $row = $db->fetchrow($q) ); |
196 } while ( $row = $db->fetchrow($q) ); |
175 } |
197 } |
176 $db->free_result(); |
198 $db->free_result(); |
177 $ret['count_appr'] = $count_appr; |
199 $ret['count_appr'] = $counts['approved']; |
178 $ret['count_total'] = $count_total; |
200 $ret['count_total'] = $counts['total']; |
179 $ret['count_unappr'] = $count_unappr; |
201 $ret['count_visible'] = $this->perms->get_permissions('mod_comments') ? $counts['total'] : $counts['approved']; |
|
202 $ret['count_unappr'] = $counts['unapproved']; |
180 $ret['auth_mod_comments'] = $this->perms->get_permissions('mod_comments'); |
203 $ret['auth_mod_comments'] = $this->perms->get_permissions('mod_comments'); |
181 $ret['auth_post_comments'] = $this->perms->get_permissions('post_comments'); |
204 $ret['auth_post_comments'] = $this->perms->get_permissions('post_comments'); |
182 $ret['auth_edit_comments'] = $this->perms->get_permissions('edit_comments'); |
205 $ret['auth_edit_comments'] = $this->perms->get_permissions('edit_comments'); |
183 $ret['auth_edit_wysiwyg'] = $this->perms->get_permissions('edit_wysiwyg'); |
206 $ret['auth_edit_wysiwyg'] = $this->perms->get_permissions('edit_wysiwyg'); |
184 $ret['user_id'] = $session->user_id; |
207 $ret['user_id'] = $session->user_id; |