Added : ajax comments

Updated : Playlist
Added : New template functions
This commit is contained in:
Arslan Hassan 2012-06-12 10:31:46 +00:00
parent 69158c5fe5
commit fae5bbe6e3
13 changed files with 348 additions and 28 deletions

View file

@ -1411,12 +1411,20 @@ if(!empty($mode))
assign('comments_voting',$_POST['comments_voting']); assign('comments_voting',$_POST['comments_voting']);
if($_POST['admin']=='yes' && has_access('admin_access',true)) if($_POST['admin']=='yes' && has_access('admin_access',true))
Template(BASEDIR.'/'.ADMINDIR.'/'.TEMPLATEFOLDER.'/cbv2/layout/blocks/comments.html',false); {
else Template(BASEDIR.'/'.ADMINDIR.'/'.TEMPLATEFOLDER.'/cbv3/layout/blocks/comments.html',false);
Template('blocks/comments/comments.html'); exit();
}else
{
$template = get_template('comments');
}
assign('commentPagination','yes'); assign('commentPagination','yes');
Template('blocks/pagination.html');
$template .= get_template('pagination');
echo json_encode(array('success'=>'yes','output'=>$template));
} }
break; break;

View file

@ -226,6 +226,151 @@ switch($mode){
echo json_encode(array('success'=>'ok')); echo json_encode(array('success'=>'ok'));
} }
break; break;
case 'add_comment';
{
$type = $_POST['type'];
switch($type)
{
case 'v':
case 'video':
default:
{
$id = mysql_clean($_POST['obj_id']);
$comment = $_POST['comment'];
if($comment=='undefined')
$comment = '';
$reply_to = $_POST['reply_to'];
$cid = $cbvid->add_comment($comment,$id,$reply_to);
}
break;
case 'u':
case 'c':
{
$id = mysql_clean($_POST['obj_id']);
$comment = $_POST['comment'];
if($comment=='undefined')
$comment = '';
$reply_to = $_POST['reply_to'];
$cid = $userquery->add_comment($comment,$id,$reply_to);
}
break;
case 't':
case 'topic':
{
$id = mysql_clean($_POST['obj_id']);
$comment = $_POST['comment'];
if($comment=='undefined')
$comment = '';
$reply_to = $_POST['reply_to'];
$cid = $cbgroup->add_comment($comment,$id,$reply_to);
}
break;
case 'cl':
case 'collection':
{
$id = mysql_clean($_POST['obj_id']);
$comment = $_POST['comment'];
if($comment=='undefined')
$comment = '';
$reply_to = $_POST['reply_to'];
$cid = $cbcollection->add_comment($comment,$id,$reply_to);
}
break;
case "p":
case "photo":
{
$id = mysql_clean($_POST['obj_id']);
$comment = $_POST['comment'];
if($comment=='undefined')
$comment = '';
$reply_to = $_POST['reply_to'];
$cid = $cbphoto->add_comment($comment,$id,$reply_to);
}
break;
}
if(error())
{
exit(json_encode(array('err'=>error())));
}
$comment = $myquery->get_comment($cid);
assign('comment',$comment);
$template = get_template('single_comment');
$array = array(
'msg' => msg(),
'comment' => $template,
'success' => 'ok',
'cid' => $cid
);
echo json_encode($array);
}
break;
case "get_comments":
{
$params = array();
$limit = config('comments_per_page');
$page = $_POST['page'];
$params['type'] = mysql_clean($_POST['type']);
$params['type_id'] = mysql_clean($_POST['type_id']);
$params['last_update'] = mysql_clean($_POST['last_update']);
$params['limit'] = create_query_limit($page,$limit);
$admin = "";
if($_POST['admin']=='yes' && has_access('admin_access',true))
{
$params['cache'] ='no';
$admin = "yes";
}
$comments = $myquery->getComments($params);
//Adding Pagination
$total_pages = count_pages($_POST['total_comments'],$limit);
assign('object_type',mysql_clean($_POST['object_type']));
//Pagination
$pages->paginate($total_pages,$page,NULL,NULL,'<a href="javascript:void(0)"
onClick="getComments(\''.$params['type'].'\',\''.$params['type_id'].'\',\''.$params['last_update'].'\',
\'#page#\',\''.$_POST['total_comments'].'\',\''.mysql_clean($_POST['object_type']).'\',\''.$admin.'\')">#page#</a>');
assign('comments',$comments);
assign('type',$params['type']);
assign('type_id',$params['type_id']);
assign('last_update',$params['last_update']);
assign('total',$_POST['total_comments']);
assign('total_pages',$total_pages);
assign('comments_voting',$_POST['comments_voting']);
if($_POST['admin']=='yes' && has_access('admin_access',true))
{
Template(BASEDIR.'/'.ADMINDIR.'/'.TEMPLATEFOLDER.'/cbv3/layout/blocks/comments.html',false);
exit();
}else
{
$template = get_template('comments');
}
assign('commentPagination','yes');
$template .= get_template('pagination');
echo json_encode(array('success'=>'yes','output'=>$template));
}
break;
default: default:
exit(json_encode(array('err'=>array(lang('Invalid request'))))); exit(json_encode(array('err'=>array(lang('Invalid request')))));

View file

@ -590,7 +590,7 @@ class cbactions
$db->delete(tbl($this->playlist_items_tbl),array("playlist_item_id"),array($id)); $db->delete(tbl($this->playlist_items_tbl),array("playlist_item_id"),array($id));
//Update total items in the playlist //Update total items in the playlist
$db->update(tbl('playlists'),array('total_items','last_update'), $db->update(tbl('playlists'),array('total_items','last_update'),
array('|f|total_items-1',now())," playlist_id='".$pid."' "); array('|f|total_items-1',now())," playlist_id='".$item['playlist_id']."' ");
e(lang("playlist_item_delete"),"m"); e(lang("playlist_item_delete"),"m");
} }

View file

@ -266,6 +266,7 @@
if(!$mail->Send()) if(!$mail->Send())
{ {
if(!DEVELOPMENT_MODE)
e("Mailer Error: " . $mail->ErrorInfo); e("Mailer Error: " . $mail->ErrorInfo);
return false; return false;
}else }else
@ -3166,6 +3167,25 @@
} }
} }
/**
* set_config
* runtime configuration..
* overwrites existin $Cbucket->configs ...
*
* @param STRING $var
* @param STRING $val
*
* @return true
*/
function set_config($var,$val)
{
global $Cbucket;
$Cbucket->configs[$var] = $val;
return true;
}
if ( !function_exists('cb_show_page') ) { if ( !function_exists('cb_show_page') ) {
function cb_show_page ( $var = false ) { function cb_show_page ( $var = false ) {
global $Cbucket; global $Cbucket;
@ -3242,6 +3262,33 @@ function get_mature_thumb ( $object, $size = null, $output = null ) {
} }
} }
/**
* Get comment author...
*
* @param ARRAY $comment
* @return STRING $author
*/
function comment_author($comment)
{
if($comment['userid'])
{
//means registered user has made a comment..
return $comment['username'];
}else
{
//Show what guest has put in for name
return $comment['anonym_name'];
}
}
/**
* Alias of comment_author
* @param type $comment
* @return type
*/
function get_comment_author($comment){ return comment_author($comment); }
//Including videos functions //Including videos functions
include("functions_videos.php"); include("functions_videos.php");
//Including Users Functions //Including Users Functions

View file

@ -831,7 +831,7 @@
return $value; return $value;
} }
/** /**
* add link in admin area left menu * add link in admin area left menu
* *
@ -1096,4 +1096,40 @@
$rating = apply_filters($rating, 'show-rating'); $rating = apply_filters($rating, 'show-rating');
cb_call_functions('show_rating',$rating); cb_call_functions('show_rating',$rating);
} }
/***
* fetch template files as defined int he template config
* @param file
* @param type , display | fetch
*/
function get_template($file,$type='fetch')
{
$defaults = array(
'single_comment' => 'blocks/comments/comment.html',
'comments' => 'blocks/comments/comments.html',
'pagination' => 'blocks/pagination.html'
);
$files = config('template_files');
if($files[$file])
{
$the_file = $files[$file];
}else
{
$the_file = $defaults[$file];
}
if($the_file)
{
if($type=='fetch')
return fetch($the_file);
else
template($the_file);
}
}
?> ?>

View file

@ -14,7 +14,7 @@ $pages->page_redir();
if(is_installed('editorspick')) if(is_installed('editorspick'))
{ {
assign('editor_picks',get_ep_videos()); assign('editor_picks',get_ep_videos());
} }
//i love coding :) //i love coding :)

View file

@ -8,9 +8,12 @@
</div> </div>
</div> </div>
<div class="span7 comment-text"> <div class="span7 comment-text">
<h6>posted by username 4 days ago</h6> {$time=niceTime($comment.date_added)}
{$phrase=lang('posted by %s %s ')}
{$author=comment_author($comment)}
<h6>{$phrase|sprintf:$author:$time}</h6>
<div class="height5"></div> <div class="height5"></div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. {$comment.comment}
</div> </div>
<div class="inlineBlock pull-right absolute comment-options" style="top:-13px; right: 0px;"> <div class="inlineBlock pull-right absolute comment-options" style="top:-13px; right: 0px;">
@ -29,4 +32,5 @@
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
<hr/>

View file

@ -248,6 +248,33 @@ function toggleBox(bttn,box)
} }
} }
/**
* Get Comments via ajax
*/
var comments_voting = 'no';
function get_comments(type,type_id,last_update,pageNum,total,object_type,admin)
{
amplify.request('main',
{
mode:'get_comments',
page:pageNum,type:type,
type_id:type_id,
object_type : object_type,
last_update : last_update,
total_comments : total,
comments_voting : comments_voting,admin : admin
},function(data){
$('#comments').hide();
$('#comments').html(data.output);
$('#comments').fadeIn('slow');
})
}
// CLIPBUCKET MAIN FUNCTIONS ---------------------- // CLIPBUCKET MAIN FUNCTIONS ----------------------
@ -604,4 +631,26 @@ function send_private_message(e) {
$('#confirm .modal-header h3').text(''); $('#confirm .modal-header h3').text('');
$('#confirm .modal-body').html(''); $('#confirm .modal-body').html('');
$('#confirm-yes').unbind('click'); $('#confirm-yes').unbind('click');
}
/**
* Add comment
*/
function add_comment()
{
var comment_form = '#comment-form';
$('#add-comment-button').button('loading');
form_data = $(comment_form).serialize();
form_data += '&mode=add_comment';
amplify.request('main',form_data,function(data){
$('#add-comment-button').button('reset');
if(data.err)
{
displayError(data.err);
}
})
} }

View file

@ -53,12 +53,12 @@
$(document).ready(function(){ $(document).ready(function(){
//Adding Comment Hover effect //Adding Comment Hover effect
$('.comment').bind('mouseover',function(e){ $('.comment').live('mouseover',function(e){
$(this).find('.comment-options').show(); $(this).find('.comment-options').show();
}); });
//Adding Comment Mouse-leave effect //Adding Comment Mouse-leave effect
$('.comment').bind('mouseout',function(e){ $('.comment').live('mouseout',function(e){
$(this).find('.comment-options').hide(); $(this).find('.comment-options').hide();
}); });

View file

@ -137,10 +137,10 @@
{foreach $playlists as $playlist} {foreach $playlists as $playlist}
{include_template_file file='blocks/playlist.html' playlist=$playlist} {include_template_file file='blocks/playlist.html' playlist=$playlist}
{/foreach} {/foreach}
{/if}
{else}
<div class="no-playlist alert alert-info">{lang code="<strong>Hey there!</strong> You have not created any playlist, please create one now or read our playlist guide."}</div> <div class="no-playlist alert alert-info {if $playlists}display-none{/if}">{lang code="<strong>Hey there!</strong> You have not created any playlist, please create one now or read our playlist guide."}</div>
{/if}
</div> </div>
{/if} {/if}
@ -279,10 +279,12 @@
</ul> </ul>
{/if} {/if}
</form> </form>
<div class="alert alert-info {if $total_items>0}display-none{/if}" id="no-playlist-items-div">{lang code='You do not have any items in this playlist, to add videos, goto any video page and click add to and follow the name'}</div>
{/if} {/if}
<div class="alert alert-info {if $total_items>0}display-none{/if}" id="no-playlist-items-div">{lang code='You do not have any items in this playlist, to add videos, goto any video page and click add to and follow the name'}</div>
</div> </div>

View file

@ -1,4 +1,7 @@
<!-- Watch Video Template $Id$ --> <!-- Watch Video Template $Id$ -->
{$object_type='video'}
{$type='v'}
<h1>{$video.title}</h1> <h1>{$video.title}</h1>
<div class="row"> <div class="row">
@ -116,26 +119,47 @@
<div class="comments video-comments"> <div class="comments video-comments">
<h3>All Comments (4,555)</h3> <h3>All Comments (4,555)</h3>
<div class="add-comment row-fluid"> <form id="comment-form" method="post" onsubmit="return false;">
<div style="background-color: #333; height: 50px" class="spanauto"> <input type="hidden" name="type" value="v"/>
<img src="http://placehold.it/62x62"/> <input type="hidden" name="obj_id" value="{$video.videoid}"/>
<div class="add-comment row-fluid relative">
<div class="inlineblock moveL marginR10 add-comment-uphoto">
<img src="{$userquery->avatar($userquery->udetails)}"/>
</div> </div>
<textarea class="input-xlarge span650 <textarea class="input-xlarge span650
comment-textarea" id="textarea" rows="3"></textarea> comment-textarea" id="comment-text" rows="3" name="comment"
{if userid()} placeholder="{lang code='type something to comment....'}"{else}
disabled{/if}
></textarea>
{if !userid()}
<div class="absolute comment-login"><a href="" class="btn">Please login to make a comment</a></div>
{/if}
<div class="clearfix"></div> <div class="clearfix"></div>
<div align="right"> <div align="right">
<button class="btn btn-primary">Add video response</button> <button class="btn btn-primary">Add video response</button>
<button class="btn">Post comment</button> <button class="btn" onclick="add_comment('v')"
data-loading-text="{lang code='Adding comment..'}"
id="add-comment-button">Post comment</button>
</div> </div>
</div> </div>
</form>
<div class="height20"></div> <div class="height20"></div>
{section name=foo loop=4}
{include file="$layout_dir/blocks/comment.html" cid=$smarty.section.foo.iteration} <div id="comments"></div>
{/section}
<script>
$(document).ready(function()
{
comments_voting = '{$vdo.comment_voting}';
get_comments('{$type}','{$vdo.videoid}','{$vdo.last_commented}',1,'{$vdo.comments_count}','{$object_type}')
}
);
</script>
<div align="right"> <div align="right">
<div class="btn-group inlineblock"> <div class="btn-group inlineblock">

View file

@ -5,7 +5,7 @@
*/ */
include("template_functions.php"); include("template_functions.php");
include("configs.php");
/** /**
* add_thumb_size(336x44) * add_thumb_size(336x44)

View file

@ -40,6 +40,9 @@
.left{left:0px} .left{left:0px}
.right{right:0px} .right{right:0px}
.moveL,.floatL,.float-left{float: left}
.moveR,.floatR,.float-right{float: right}
.valignTop{vertical-align: top} .valignTop{vertical-align: top}
.valignMid{vertical-align: middle} .valignMid{vertical-align: middle}
@ -146,8 +149,10 @@ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff3019', end
/* Comments */ /* Comments */
.comment{margin-top: 10px; margin-bottom: 10px} .comment{margin-top: 10px; margin-bottom: 10px}
.comment .comment-text{margin-left: 10px} .comment .comment-text{margin-left: 10px}
.comment-textarea{margin-left: 10px !important; width: 650px} .comment-textarea{margin-left: 10px !important; width: 660px !important}
.comment-options{display: none} .comment-options{display: none}
.add-comment-uphoto{width: 62px; height: 62px}
.comment-login{top: 10px; left: 90px}
/* Author Box */ /* Author Box */
.author-box-content{width: 220px} .author-box-content{width: 220px}