From a41a50508ce3eb88af2bf38b96ebf79245145dd5 Mon Sep 17 00:00:00 2001 From: Fawaz Date: Fri, 19 Mar 2010 11:39:18 +0000 Subject: [PATCH] ADDED : Basic Comment Moderation in Admin Area --- upload/actions/admin.php | 98 ++++++++++++++ upload/admin_area/comments.php | 56 ++++++++ .../styles/cbv2/layout/comments.html | 120 ++++++++++++++++++ upload/includes/classes/my_queries.class.php | 27 +++- upload/includes/classes/video.class.php | 111 ++++++++++++++-- upload/includes/functions.php | 21 ++- upload/js/admin_functions.js | 61 ++++++++- .../install_global_announcement.php | 2 +- .../uninstall_global_announcement.php | 2 +- 9 files changed, 476 insertions(+), 22 deletions(-) create mode 100644 upload/admin_area/comments.php create mode 100644 upload/admin_area/styles/cbv2/layout/comments.html diff --git a/upload/actions/admin.php b/upload/actions/admin.php index bc3754bf..d085e082 100644 --- a/upload/actions/admin.php +++ b/upload/actions/admin.php @@ -30,5 +30,103 @@ switch($mode) $myquery->delete_note($id); } break; + + case 'delete_comment': + { + $type = $_POST['type']; + switch($type) + { + case 'v': + case 'video': + default: + { + $cid = mysql_clean($_POST['cid']); + $type_id = $myquery->delete_comment($cid); + $cbvid->update_comments_count($type_id); + } + break; + case 'u': + case 'c': + { + $cid = mysql_clean($_POST['cid']); + $type_id = $myquery->delete_comment($cid); + $userquery->update_comments_count($type_id); + } + break; + case 't': + case 'topic': + { + $cid = mysql_clean($_POST['cid']); + $type_id = $myquery->delete_comment($cid); + $cbgroup->update_comments_count($type_id); + } + break; + + } + if(msg()) + { + $msg = msg_list(); + $msg = $msg[0]; + } + if(error()) + { + $err = error_list(); + $err = $err[0]; + } + + $ajax['msg'] = $msg; + $ajax['err'] = $err; + + echo json_encode($ajax); + } + break; + + case 'spam_comment': + { + $cid = mysql_clean($_POST['cid']); + + + $rating = $myquery->spam_comment($cid); + if(msg()) + { + $msg = msg_list(); + $msg = $msg[0]; + } + if(error()) + { + $err = error_list(); + $err = $err[0]; + } + + $ajax['msg'] = $msg; + $ajax['err'] = $err; + + echo json_encode($ajax); + } + break; + + case 'remove_spam': + { + $cid = mysql_clean($_POST['cid']); + + + $rating = $myquery->remove_spam($cid); + if(msg()) + { + $msg = msg_list(); + $msg = $msg[0]; + } + if(error()) + { + $err = error_list(); + $err = $err[0]; + } + + $ajax['msg'] = $msg; + $ajax['err'] = $err; + + echo json_encode($ajax); + } + break; } ?> diff --git a/upload/admin_area/comments.php b/upload/admin_area/comments.php new file mode 100644 index 00000000..3f6bbd97 --- /dev/null +++ b/upload/admin_area/comments.php @@ -0,0 +1,56 @@ +admin_login_check(); +$pages->page_redir(); + +$mode = $_GET['mode']; +$cid = $_GET['cid']; +$comment = array(); +$comment['order'] = " comment_id DESC"; + +/* By default only video comments list but when you change this is used list video comments */ +if(isset($_GET['filter'])) { + $comment['type'] = $_GET['filter']; + assign('filters',$_GET['filter']); +} + +/* Used to list topic posts */ +if(isset($_GET['filter'])) { + $comment['type'] = $_GET['filter']; + assign('filters',$_GET['filter']); +} + +/* Used to list topic posts */ +if(isset($_GET['filter'])) { + $comment['type'] = $_GET['filter']; + assign('filters',$_GET['filter']); +} + +/* Used to update a comment */ +if($cid) { + if(isset($_POST['update_comment'])) { + $updated_comment = $_POST['comment']; + $cbvid->update_comment($cid,$updated_comment); + } +} + +/* Getting comments and assigning smarty variables */ +$page = mysql_clean($_GET['page']); +$get_limit = create_query_limit($page,RESULTS); +$comment['limit'] = $get_limit; +$comments = $cbvideo->get_comments($comment); +assign("comments",$comments); +if($mode) { + assign('mode',$mode); +} +/* Pagination */ +$ccount = $comment; +$ccount['count_only'] = true; +$total_rows = $cbvideo->get_comments($ccount); +$total_pages = count_pages($total_rows,RESULTS); +$pages->paginate($total_pages,$page); + +subtitle("Comments"); +template_files('comments.html'); +display_it(); +?> \ No newline at end of file diff --git a/upload/admin_area/styles/cbv2/layout/comments.html b/upload/admin_area/styles/cbv2/layout/comments.html new file mode 100644 index 00000000..0f185765 --- /dev/null +++ b/upload/admin_area/styles/cbv2/layout/comments.html @@ -0,0 +1,120 @@ +Comments Manager +
+{if $mode == '' || $mode == "list_comments"} + + + + + + + +
+ CIDComment 
+
+View Video Comments | View Topic Posts | View Channel Comments +{if $comments} + +{foreach from=$comments item=comment} + +{if $comment.anonym_name != ""} + {assign var=comment_owner value=$comment.anonym_name} +{else} + {assign var=comment_owner value=$userquery->get_user_details($comment.userid)} +{/if} + + + + + + + + +{/if} + +{if $filters == 't'} + + {if is_array($comment_owner)} {$comment_owner.username} {else} {$comment_owner} {/if} commented on {$comment.date_added|date_format} on a topic named {$comment.topic_title|truncate:40} + +
+{$comment.comment|truncate:150}
+ + +{/if} + +{if $filters == 'c'} + + {if is_array($comment_owner)} {$comment_owner.username} {else} {$comment_owner} {/if} commented on {$comment.date_added|date_format} on a channel named {$comment.username|truncate:40} + +
+{$comment.comment|truncate:150}
+ + +{/if} + +{if $bgcolor == ""} +{assign var = bgcolor value = "#EEE"} +{else} +{assign var = bgcolor value = ""} +{/if} +{/foreach} +
{$comment.comment_id} + {if $filters == '' || $filters == 'v'} + + {if is_array($comment_owner)} {$comment_owner.username} {else} {$comment_owner} {/if} commented on {$comment.date_added|date_format} on a video named {$comment.title|truncate:40} + + +
+{$comment.comment|truncate:150}
+ + +
 
+{/if} + +
+{include file="$style_dir/blocks/pagination.html" } +{/if} + +{if $mode == 'edit_comment'} +{assign var=cid value=$smarty.get.cid} +{assign var=comment value=$cbvid->get_comment($cid)} + + + + + + + +
 Edit Comment 
+
+
+
+ {ANCHOR place='before_compose_box'} + +
+ +
+{/if} \ No newline at end of file diff --git a/upload/includes/classes/my_queries.class.php b/upload/includes/classes/my_queries.class.php index 8c7c5fb2..6c625b30 100644 --- a/upload/includes/classes/my_queries.class.php +++ b/upload/includes/classes/my_queries.class.php @@ -210,6 +210,31 @@ class myquery { return false; } + /** + * Function used to set comment as spam + */ + function remove_spam($cid) { + global $db; + $comment = $this->get_comment($cid); + $vote = '0'; + $none = ''; + + if($comment) { + $votes = $comment['spam_votes']; + if(!$votes) { + e(lang('Comment is not a spam')); + } elseif(!userid()) { + e(lang('login_to_mark_as_spam')); + } else { + $db->update(tbl('comments'),array('spam_votes','spam_voters'),array($vote,$none)," comment_id='$cid'"); + e(lang('Spam removed from comment.'),"m"); + } + } else { + e(lang('no_comment_exists')); + } + } + + /** * Function used to delete all comments of particlar object */ @@ -751,7 +776,7 @@ class myquery { case "u": case "c": { - if($obj['allow_comments'] == 'yes' && config('channel_comments')==1) + if($obj['allow_comments'] == 'Yes' && config('channel_comments')==1) return true; } } diff --git a/upload/includes/classes/video.class.php b/upload/includes/classes/video.class.php index 86d3ec45..1cc6d31a 100644 --- a/upload/includes/classes/video.class.php +++ b/upload/includes/classes/video.class.php @@ -1077,24 +1077,107 @@ class CBvideo extends CBCategory /** * Function used get comments of videos */ - function get_comments($type=NULL) + function get_comments($params=NULL) { global $db; - $cond = ""; + $comtbl = tbl("comments"); + $limit = $params['limit']; + $order = $params['order']; + $type = $params['type']; - if($type) { - $cond = " ".tbl("comments").".type='$type'"; - } - - $result = $db->select(tbl("comments"),"*",$cond); - - if($result) { - return $result; - } else { - return false; - } - } + if($type) + $cond = " $comtbl.type = '$type'"; + else + $cond = ''; + + switch($type) { + case 'v': + { + $sectbl = tbl('video'); + $sectblName = 'video'; + $secfields = $sectbl.".videokey,".$sectbl.".videoid,".$sectbl.".file_name,".$sectbl.".title"; + if($cond) { + $cond .= " AND"; + } + $cond .= " $comtbl.type_id = $sectbl.videoid"; + } + break; + + case 't': + { + $sectbl = tbl('group_topics'); + $sectblName = 'group_topics'; + $secfields = $sectbl.".topic_title,".$sectbl.".topic_id,".$sectbl.".topic_title"; + if($cond) { + $cond .= " AND"; + } + $cond .= " $comtbl.type_id = $sectbl.topic_id"; + } + break; + + case 'c': + { + $sectbl = tbl('users'); + $sectblName = 'users'; + $secfields = $sectbl.".username,".$sectbl.".userid"; + if($cond) { + $cond .= " AND"; + } + $cond .= " $comtbl.type_id = $sectbl.userid"; + } + break; + + + default: + { + $sectbl = tbl('video'); + $sectblName = 'video'; + $secfields = $sectbl.".videokey,".$sectbl.".videoid,".$sectbl.".file_name,".$sectbl.".title"; + if($cond) { + $cond .= " AND"; + } + $cond .= " $comtbl.type_id = $sectbl.videoid"; + } + } + if(!$params['count_only']) { + $result = $db->select(tbl("comments,".$sectblName.""), + "$comtbl.*,$secfields", + $cond,$limit,$order); + echo $db->db_query; + } + if($params['count_only']) + return $result = $db->count(tbl("comments,video"),"*",$cond); + else + return $result; + } + + /** + * Function used get single comment + */ + + function get_comment($cid) { + global $db; + $result = $db->select(tbl("comments"),"*", " comment_id = $cid"); + if($result) + return $result[0]; + else + return false; + } + + /** + * Function used update comment + */ + + function update_comment($cid,$comment) { + global $db; + if(!$comment) { + e(lang('usr_cmt_err1'),e); + } else { + $db->update(tbl("comments"),array("comment"),array($comment)," comment_id = $cid"); + e(lang("Comment Updated"),m); + } + } } ?> \ No newline at end of file diff --git a/upload/includes/functions.php b/upload/includes/functions.php index a8610df3..a90244f2 100644 --- a/upload/includes/functions.php +++ b/upload/includes/functions.php @@ -3717,6 +3717,7 @@ $path = get_binaries($path); $array = array(); $result = shell_output($path." -version"); + if($result) { if($params['assign']) @@ -3750,8 +3751,12 @@ { case 'ffmpeg': { - preg_match("/svn-r([0-9]+)/i",$result,$matches); - return $matches[1]; + preg_match("/svn-([0-9]+)/i",$result,$matches); + if(is_numeric($matches[1])) { + return $matches[1]; + } else { + return false; + } } break; case 'php': @@ -3762,13 +3767,21 @@ case 'flvtool2': { preg_match("/flvtool2 ([0-9\.]+)/i",$result,$matches); - return $matches[1]; + if(is_numeric($matches[1])){ + return $matches[1]; + } else { + return false; + } } break; case 'mp4box': { preg_match("/version ([0-9\.]+)/i",$result,$matches); - return $matches[1]; + if(is_numeric($matches[1])){ + return $matches[1]; + } else { + return false; + } } } } diff --git a/upload/js/admin_functions.js b/upload/js/admin_functions.js index 94436a94..cfc97431 100644 --- a/upload/js/admin_functions.js +++ b/upload/js/admin_functions.js @@ -75,4 +75,63 @@ function toggle_menu() $.cookie("admin_menu","show"); } -} \ No newline at end of file +} + +function admin_spam_comment(cid) + { + + $.post(page, + { + mode : 'spam_comment', + cid : cid + }, + function(data) + { + if(!data) + alert("No data"); + else + { + if(data.msg) + { + $("#comment_"+cid).css({'backgroundColor' : '#ffd7d7'}); + $("#spam_comment_"+cid).fadeOut(350, function() { + $("#remove_spam_comment_"+cid).fadeIn(350); + }); + + } + if(data.err) + { + alert(data.err) + } + } + },'json'); + } + +function admin_remove_spam(cid) + { + + $.post(page, + { + mode : 'remove_spam', + cid : cid + }, + function(data) + { + if(!data) + alert("No data"); + else + { + if(data.msg) + { + $("#comment_"+cid).css({'backgroundColor' : '#f3f3f3'}); + $("#remove_spam_comment_"+cid).fadeOut(350, function() { + $("#spam_comment_"+cid).fadeIn(350); + }); + } + if(data.err) + { + alert(data.err) + } + } + },'json'); + } \ No newline at end of file diff --git a/upload/plugins/global_announcement/install_global_announcement.php b/upload/plugins/global_announcement/install_global_announcement.php index b81c0662..5de925c3 100644 --- a/upload/plugins/global_announcement/install_global_announcement.php +++ b/upload/plugins/global_announcement/install_global_announcement.php @@ -7,7 +7,7 @@ function install_global_announcement() { global $db; $db->Execute( - 'CREATE TABLE IF NOT EXISTS `'.tbl("global_announcement").'` ( + 'CREATE TABLE IF NOT EXISTS '.tbl("global_announcement").' ( `announcement` text NOT NULL ) ENGINE=MyISAM;' ); diff --git a/upload/plugins/global_announcement/uninstall_global_announcement.php b/upload/plugins/global_announcement/uninstall_global_announcement.php index 7d81d068..7fe1fc10 100644 --- a/upload/plugins/global_announcement/uninstall_global_announcement.php +++ b/upload/plugins/global_announcement/uninstall_global_announcement.php @@ -4,7 +4,7 @@ { global $db; $db->Execute( - 'DROP TABLE `'.tbl("global_announcement").'`' + 'DROP TABLE '.tbl("global_announcement").'' ); }