forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoComments.php
380 lines (368 loc) · 22.1 KB
/
videoComments.php
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
<?php
if (User::canSeeCommentTextarea()) {
if (!empty($advancedCustom->commentsNoIndex)) {
echo "<!--googleoff: all-->";
}
if (!empty($video['id'])) {
?>
<div class="input-group">
<textarea class="form-control custom-control" rows="3" style="resize:none" id="comment" maxlength="<?php echo empty($advancedCustom->commentsMaxLength) ? "200" : $advancedCustom->commentsMaxLength ?>" <?php
if (!User::canComment()) {
echo "disabled";
}
?>><?php
if (!User::canComment()) {
echo __("You cannot comment on videos");
}
?></textarea>
<?php if (User::canComment()) { ?>
<span class="input-group-addon btn btn-success" id="saveCommentBtn" <?php
if (!User::canComment()) {
echo "disabled='disabled'";
}
?>><span class="glyphicon glyphicon-comment"></span> <?php echo __("Comment"); ?></span>
<?php } else if(User::isLogged()){ ?>
<a class="input-group-addon btn btn-success" href="<?php echo $global['webSiteRootURL']; ?>user"><span class="glyphicon glyphicon-log-in"></span> <?php echo __("Verify your email to be able to comment"); ?></a>
<?php } else { ?>
<a class="input-group-addon btn btn-success" href="<?php echo $global['webSiteRootURL']; ?>user"><span class="glyphicon glyphicon-log-in"></span> <?php echo __("You must login to be able to comment on videos"); ?></a>
<?php } ?>
</div>
<div class="pull-right" id="count_message"></div>
<script>
$(document).ready(function () {
var text_max = <?php echo empty($advancedCustom->commentsMaxLength) ? "200" : $advancedCustom->commentsMaxLength ?>;
$('#count_message').html(text_max + ' <?php echo __("remaining"); ?>');
$('#comment').keyup(function () {
var text_length = $(this).val().length;
var text_remaining = text_max - text_length;
$('#count_message').html(text_remaining + ' <?php echo __("remaining"); ?>');
});
});
</script>
<?php
}
?>
<style>
.replySet .replySet .divReplyGrid{
padding-left: 0 !important;
}
</style>
<div class="replySet hidden" id="replyTemplate" comments_id="0">
<div>
<?php
if (User::canComment()) {
?>
<button class="btn btn-default no-outline reply btn-xs">
<?php echo __("Reply"); ?>
</button>
<?php
}
?>
<button class="btn btn-default no-outline btn-xs replyLikeBtn">
<span class="fa fa-thumbs-up"></span>
<small>0</small>
</button>
<button class="btn btn-default no-outline btn-xs replyDislikeBtn">
<span class="fa fa-thumbs-down"></span>
<small>0</small>
</button>
<button class="btn btn-default no-outline allReplies btn-xs viewAllReplies">
<?php echo __("View all replies"); ?> (<span class="total_replies">0</span>) <i class="fa fa-chevron-down" aria-hidden="true"></i>
</button>
<button class="btn btn-default no-outline allReplies btn-xs hideAllReplies" style="display: none">
<?php echo __("Hide Replies"); ?> <i class="fa fa-chevron-up" aria-hidden="true"></i>
</button>
<button class="btn btn-default no-outline btn-xs pull-right delete userCanAdminComment">
<i class="fa fa-trash" aria-hidden="true"></i>
</button>
<button class="btn btn-default no-outline btn-xs pull-right edit userCanEditComment">
<i class="fas fa-edit" aria-hidden="true"></i>
</button>
</div>
<div class="divReplyGrid" style="padding-left: 50px;">
<div class="input-group formRepy" style="display: none;">
<textarea class="form-control custom-control" rows="2" style="resize:none" maxlength="<?php echo empty($advancedCustom->commentsMaxLength) ? "200" : $advancedCustom->commentsMaxLength ?>" ></textarea>
<span class="input-group-addon btn btn-success saveReplyBtn">
<span class="glyphicon glyphicon-comment"></span> <?php echo __("Reply"); ?>
</span>
</div>
<div class="replyGrid" style="display: none;">
<table class="table table-condensed table-hover table-striped nowrapCell grid">
<thead>
<tr>
<th data-column-id="comment" data-formatter="commands" ><?php echo __("Comment"); ?></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<h4><?php echo __("Comments"); ?>:</h4>
<table id="grid" class="table table-condensed table-hover table-striped nowrapCell">
<thead>
<tr>
<?php
if (empty($video['id'])) {
?>
<th data-formatter="video" data-width="200px" ><?php echo __("Video"); ?></th>
<?php } ?>
<th data-column-id="comment" data-formatter="commands" ><?php echo __("Comment"); ?></th>
</tr>
</thead>
</table>
<div id="commentFormModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><?php echo __("Comment Form"); ?></h4>
</div>
<div class="modal-body">
<input type="hidden" value="" id="inputEditCommentId"/>
<textarea id="inputEditComment" class="form-control" placeholder="<?php echo __("Comment"); ?>" required></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo __("Close"); ?></button>
<button type="button" class="btn btn-primary" id="saveEditCommentBtn"><?php echo __("Save changes"); ?></button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$(document).ready(function () {
var grid = $("#grid").bootgrid({
labels: {
noResults: "<?php echo __("No results found!"); ?>",
all: "<?php echo __("All"); ?>",
infos: "<?php echo __("Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries"); ?>",
loading: "<?php echo __("Loading..."); ?>",
refresh: "<?php echo __("Refresh"); ?>",
search: "<?php echo __("Search"); ?>",
},
ajax: true,
url: "<?php echo $global['webSiteRootURL']; ?>objects/comments.json.php?video_id=<?php echo empty($video['id']) ? "0" : $video['id']; ?>",
sorting: false,
templates: {
header: ""
},
requestHandler: function (request) {
request.sort.created = "DESC";
return request;
},
formatters: {
"commands": function (column, row) {
return formatRow(row);
},
"video": function (column, row) {
var image;
if (row.video) {
image = '<img src="' + row.poster.thumbsJpg + '" class="img img-thumbnail img-responsive"><br><a href="<?php echo $global['webSiteRootURL']; ?>video/' + row.video.clean_title + '" class="btn btn-default btn-xs">' + row.video.title + '</a>';
} else {
image = 'Not found';
}
return image;
}
}
}).on("loaded.rs.jquery.bootgrid", function () {
gridLoaded();
});
$('#saveCommentBtn').click(function () {
if ($(this).attr('disabled') === 'disabled') {
return false;
}
comment = $('#comment').val();
video = <?php echo empty($video['id']) ? "0" : $video['id']; ?>;
comments_id = 0;
$('#comment').val('');
saveComment(comment, video, comments_id, 0);
});
$('#saveEditCommentBtn').click(function () {
comment = $('#inputEditComment').val();
video = <?php echo empty($video['id']) ? "0" : $video['id']; ?>;
comments_id = 0;
id = $('#inputEditCommentId').val();
$('#commentFormModal').modal('hide');
saveComment(comment, video, comments_id, id);
});
});
function formatRow(row) {
var template = $("#replyTemplate").clone();
template.removeClass("hidden").attr("id", "").attr("comments_id", row.id);
template.find('.total_replies').addClass("total_replies" + row.id);
if (row.total_replies) {
template.find('.total_replies').text(row.total_replies);
} else {
template.find('.total_replies').closest('.replySet').find('.allReplies').hide();
}
template.find(".replyLikeBtn small").text(row.likes);
template.find(".replyDislikeBtn small").text(row.dislikes);
template.find(".grid").addClass("grid" + row.id);
template.find(".viewAllReplies").addClass("viewAllReplies" + row.id);
template.find(".hideAllReplies").addClass("hideAllReplies" + row.id);
template.find(".formRepy").addClass("formRepy" + row.id);
if (!row.userCanAdminComment) {
template.find(".userCanAdminComment").remove();
}
if (!row.userCanEditComment) {
template.find(".userCanEditComment").remove();
}
if (row.myVote === "1") {
template.find(".replyLikeBtn").addClass("myVote");
} else if (row.myVote === "-1") {
template.find(".replyDislikeBtn").addClass("myVote");
}
return row.comment + $('<a></a>').append(template).html();
}
function saveComment(comment, video, comments_id, id) {
if (comment.length > 5) {
modal.showPleaseWait();
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>objects/commentAddNew.json.php',
method: 'POST',
data: {'comment': comment, 'video': video, 'comments_id': comments_id, 'id': id},
success: function (response) {
if (response.status === "1") {
swal("<?php echo __("Congratulations"); ?>!", "<?php echo __("Your comment has been saved!"); ?>", "success");
if (comments_id) {
if ($('.grid' + comments_id).hasClass('bootgrid-table')) {
$('.grid' + comments_id).bootgrid('reload');
} else {
$('.viewAllReplies' + comments_id).trigger('click');
}
$('.formRepy' + comments_id).slideUp();
} else {
$('#grid').bootgrid('reload');
}
addCommentCount(comments_id, 1);
} else {
swal("<?php echo __("Sorry"); ?>!", "<?php echo __("Your comment has NOT been saved!"); ?>", "error");
}
modal.hidePleaseWait();
}
});
} else {
swal("<?php echo __("Sorry"); ?>!", "<?php echo __("Your comment must be bigger then 5 characters!"); ?>", "error");
}
}
function gridLoaded() {
$('.reply, .allReplies, .saveReplyBtn, .replyDislikeBtn, .replyLikeBtn, .viewAllReplies, .hideAllReplies, .delete, .edit').off();
$(".replyDislikeBtn, .replyLikeBtn").click(function () {
comment = $(this).closest('.replySet');
comments_id = $(this).closest('.replySet').attr("comments_id");
console.log(comment);
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>objects/comments_like.json.php?like=' + ($(this).hasClass('replyDislikeBtn') ? "-1" : "1"),
method: 'POST',
data: {'comments_id': comments_id},
success: function (response) {
comment.find(".replyDislikeBtn, .replyLikeBtn").first().removeClass("myVote");
if (response.myVote == 1) {
comment.find(".replyLikeBtn").first().addClass("myVote");
} else if (response.myVote == -1) {
comment.find(".replyDislikeBtn").first().addClass("myVote");
}
comment.find(".replyLikeBtn small").first().text(response.likes);
comment.find(".replyDislikeBtn small").first().text(response.dislikes);
}
});
return false;
});
$('.saveReplyBtn').click(function () {
comment = $(this).closest('.replySet').find('.formRepy textarea').val();
video = <?php echo empty($video['id']) ? "0" : $video['id']; ?>;
comments_id = $(this).closest('.replySet').attr("comments_id");
$(this).closest('.replySet').find('.formRepy textarea').val('');
saveComment(comment, video, comments_id, 0);
});
$('.edit').click(function () {
comments_id = $(this).closest('.replySet').attr("comments_id");
var row_index = $(this).closest('tr').index();
var row = $(this).closest('table').bootgrid("getCurrentRows")[row_index];
$('#inputEditComment').val($('<textarea />').html(row.commentPlain).text());
$('#inputEditCommentId').val(comments_id);
$('#commentFormModal').modal();
});
$('.delete').click(function () {
comments_id = $(this).closest('.replySet').attr("comments_id");
t = this;
swal({
title: "<?php echo __("Are you sure?"); ?>",
text: "<?php echo __("You will not be able to recover this action!"); ?>",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
modal.showPleaseWait();
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>objects/commentDelete.json.php',
method: 'POST',
data: {'id': comments_id},
success: function (response) {
if (response.status) {
$(t).closest('tr').fadeOut();
} else {
swal("<?php echo __("Sorry"); ?>!", "<?php echo __("Your comment has NOT been deleted!"); ?>", "error");
}
modal.hidePleaseWait();
}
});
}
});
});
$('.reply').click(function () {
$(this).closest('.replySet').find('.formRepy').first().slideToggle();
});
$('.viewAllReplies').click(function () {
comments_id = $(this).closest('.replySet').attr("comments_id");
$(this).closest('.replySet').find(".replyGrid").slideDown();
$(this).closest('.replySet').find(".grid").bootgrid({
labels: {
noResults: "<?php echo __("No results found!"); ?>",
all: "<?php echo __("All"); ?>",
infos: "<?php echo __("Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries"); ?>",
loading: "<?php echo __("Loading..."); ?>",
refresh: "<?php echo __("Refresh"); ?>",
search: "<?php echo __("Search"); ?>",
},
ajax: true,
url: "<?php echo $global['webSiteRootURL']; ?>objects/comments.json.php?video_id=<?php echo empty($video['id']) ? "0" : $video['id']; ?>",
sorting: false,
templates: {
header: ""
},
rowCount: -1, navigation: 0,
formatters: {
"commands": function (column, row) {
return formatRow(row);
}
},
requestHandler: function (request) {
request.comments_id = comments_id;
request.sort.created = "DESC";
return request;
}
}).on("loaded.rs.jquery.bootgrid", function () {
gridLoaded();
});
$(this).closest('.replySet').find('.viewAllReplies').hide();
$(this).closest('.replySet').find('.hideAllReplies').show();
});
$('.hideAllReplies').click(function () {
$(this).closest('.replySet').find(".replyGrid").slideUp();
$(this).closest('.replySet').find(".replyGrid").find('table').bootgrid("destroy");
$(this).closest('.replySet').find('.viewAllReplies').show();
$(this).closest('.replySet').find('.hideAllReplies').hide();
});
}
function addCommentCount(comments_id, total) {
$('.total_replies' + comments_id).text(parseInt($('.total_replies' + comments_id).text()) + total);
}
</script>
<?php
if (!empty($advancedCustom->commentsNoIndex)) {
echo "<!--googleon: all-->";
}
}
?>