Skip to content
Browse files

Added thanks for comments and comments sorting by thanks

  • Loading branch information...
1 parent 452d524 commit 5e58f5d38d34b7d1f27b6834a185e0d565bdc227 @trustmaster committed
Showing with 120 additions and 9 deletions.
  1. +2 −1 lang/thanks.ru.lang.php
  2. +47 −0 thanks.comments.loop.php
  3. +37 −0 thanks.comments.query.php
  4. +28 −5 thanks.php
  5. +6 −3 thanks.setup.php
View
3 lang/thanks.ru.lang.php
@@ -3,7 +3,7 @@
* Thanks Russian language file
*
* @package thanks
- * @version 1.0
+ * @version 1.2
* @author Trustmaster
* @copyright Copyright (c) Vladimir Sibirov 2011
* @license BSD
@@ -13,6 +13,7 @@
$L['cfg_maxday'] = 'Макс. благодарностей для раздачи в день';
$L['cfg_maxuser'] = 'Макс. благодарностей в день 1 получателю';
+$L['cfg_comorder'] = 'Сортировать комментарии по количеству благодарностей';
$L['thanks_back'] = 'Вернуться';
$L['thanks_done'] = 'Вы поблагодарили этого человека';
View
47 thanks.comments.loop.php
@@ -0,0 +1,47 @@
+<?php
+/* ====================
+[BEGIN_COT_EXT]
+Hooks=comments.loop
+Tags=comments.tpl:{COMMENTS_ROW_THANK_CAN},{COMMENTS_ROW_THANK_URL},{COMMENTS_ROW_THANK_LINK},{COMMENTS_ROW_THANK_COUNT}
+[END_COT_EXT]
+==================== */
+
+/**
+ * Thanks comments loop
+ *
+ * @package thanks
+ * @version 1.2
+ * @author Trustmaster
+ * @copyright Copyright (c) Vladimir Sibirov 2011-2012
+ * @license BSD
+ */
+
+defined('COT_CODE') or die('Wrong URL');
+
+require_once cot_incfile('thanks', 'plug');
+
+// Fallback
+$t->assign(array(
+ 'COMMENTS_ROW_THANK_CAN' => false,
+ 'COMMENTS_ROW_THANK_URL' => cot_url('plug', 'e=thanks&ext=comments&item='.$row['com_id']),
+ 'COMMENTS_ROW_THANK_LINK' => '',
+ 'COMMENTS_ROW_THANK_COUNT' => (int) $row['thanks_count']
+));
+
+if (cot_auth('plug', 'thanks', 'W') && $usr['id'] != $row['com_authorid'])
+{
+ $thanks_today = $db->query("SELECT COUNT(*) FROM `$db_thanks` WHERE `th_fromuser` = {$usr['id']} AND DATE(`th_date`) = DATE(NOW())")->fetchColumn();
+ $thanks_touser_today = $row['thanks_touser_today'];
+ $thanks_toitem = $row['thanks_toitem'];
+
+ if ($thanks_today < $cfg['plugin']['thanks']['maxday'] && $thanks_touser_today < $cfg['plugin']['thanks']['maxuser'] && $thanks_toitem < 1)
+ {
+ $t->assign(array(
+ 'COMMENTS_ROW_THANK_CAN' => true,
+ 'COMMENTS_ROW_THANK_URL' => cot_url('plug', 'e=thanks&a=thank&ext=comments&item='.$row['com_id']),
+ 'COMMENTS_ROW_THANK_LINK' => cot_rc_link(cot_url('plug', 'e=thanks&a=thank&ext=comments&item='.$row['com_id']), $L['thanks_thanks'])
+ ));
+ }
+}
+
+?>
View
37 thanks.comments.query.php
@@ -0,0 +1,37 @@
+<?php
+/* ====================
+[BEGIN_COT_EXT]
+Hooks=comments.query
+[END_COT_EXT]
+==================== */
+
+/**
+ * Thanks comments query
+ *
+ * @package thanks
+ * @version 1.2
+ * @author Trustmaster
+ * @copyright Copyright (c) Vladimir Sibirov 2011-2012
+ * @license BSD
+ */
+
+defined('COT_CODE') or die('Wrong URL');
+
+global $db_thanks;
+
+require_once cot_incfile('thanks', 'plug');
+
+$comments_join_columns .= ", (SELECT COUNT(*) FROM `$db_thanks` WHERE th_ext = 'comments' AND th_item = c.com_id) AS thanks_count";
+
+if ($usr['id'] > 0 && cot_auth('plug', 'thanks', 'W'))
+{
+ $comments_join_columns .= ", (SELECT COUNT(*) FROM `$db_thanks` WHERE `th_fromuser` = {$usr['id']} AND `th_touser` = c.com_authorid AND DATE(`th_date`) = DATE(NOW())) AS thanks_touser_today
+ , (SELECT COUNT(*) FROM `$db_thanks` WHERE `th_fromuser` = {$usr['id']} AND `th_ext` = 'comments' AND `th_item` = c.com_id) AS thanks_toitem";
+}
+
+if ($cfg['plugin']['comments']['comorder'])
+{
+ $comments_order = "thanks_count DESC, " . $comments_order;
+}
+
+?>
View
33 thanks.php
@@ -9,9 +9,9 @@
* Thanks main script
*
* @package thanks
- * @version 1.0
+ * @version 1.2
* @author Trustmaster
- * @copyright Copyright (c) Vladimir Sibirov 2011
+ * @copyright Copyright (c) Vladimir Sibirov 2011-2012
* @license BSD
*/
@@ -33,6 +33,11 @@
require_once cot_incfile('forums', 'module');
$res = $db->query("SELECT fp_posterid FROM $db_forum_posts WHERE fp_id = $item");
}
+ elseif ($ext == 'comments')
+ {
+ require_once cot_incfile('comments', 'plug');
+ $res = $db->query("SELECT com_authorid FROM $db_com WHERE com_id = $item");
+ }
else
{
$res = false;
@@ -78,17 +83,25 @@
// List all user's thanks here
require_once cot_incfile('page', 'module');
require_once cot_incfile('forums', 'module');
+ if (cot_plugin_active('comments'))
+ {
+ require_once cot_incfile('comments', 'plug');
+ $thanks_join_columns = ", com.*, pag2.*";
+ $thanks_join_tables = "LEFT JOIN $db_com AS com ON t.th_ext = 'comments' AND t.th_item = com.com_id
+ LEFT JOIN $db_pages AS pag2 ON com.com_area = 'page' AND com.com_code = pag2.page_id";
+ }
list($pg, $d, $durl) = cot_import_pagenav('d', $cfg['plugin']['thanks']['maxrowsperpage']);
$totalitems = $db->query("SELECT COUNT(*) FROM $db_thanks WHERE th_touser = $user")->fetchColumn();
- $res = $db->query("SELECT t.*, pag.page_alias, pag.page_title, pag.page_cat, ft.ft_title, p.fp_cat, u.user_name
+ $res = $db->query("SELECT t.*, pag.page_alias, pag.page_title, pag.page_cat, ft.ft_title, p.fp_cat, u.user_name $thanks_join_columns
FROM $db_thanks AS t
LEFT JOIN $db_users AS u ON t.th_fromuser = u.user_id
LEFT JOIN $db_pages AS pag ON t.th_ext = 'page' AND t.th_item = pag.page_id
LEFT JOIN $db_forum_posts AS p ON t.th_ext = 'forums' AND t.th_item = p.fp_id
LEFT JOIN $db_forum_topics AS ft ON p.fp_id > 0 AND p.fp_topicid = ft.ft_id
+ $thanks_join_tables
WHERE th_touser = $user
ORDER BY th_date DESC
LIMIT $d, {$cfg['plugin']['thanks']['maxrowsperpage']}");
@@ -100,7 +113,17 @@
'THANKS_ROW_FROM_URL' => cot_url('users', 'm=details&id='.$row['th_fromuser'].'&u='.urlencode($row['user_name'])),
'THANKS_ROW_FROM_NAME' => htmlspecialchars($row['user_name'])
));
- if (!empty($row['page_title']))
+ if (!empty($row['com_author']))
+ {
+ $urlp = empty($row['page_alias']) ? array('c' => $row['page_cat'], 'id' => $row['page_id']) : array('c' => $row['page_cat'], 'al' => $row['page_alias']);
+ $t->assign(array(
+ 'THANKS_ROW_URL' => cot_url($row['com_area'], $urlp, '#c' . $row['th_item']),
+ 'THANKS_ROW_CAT_TITLE' => htmlspecialchars($structure['page'][$row['page_cat']]['title']),
+ 'THANKS_ROW_CAT_URL' => cot_url('page', 'c='.$row['page_cat']),
+ 'THANKS_ROW_TITLE' => $L['comments_comment'] . ': ' . htmlspecialchars($row['page_title'])
+ ));
+ }
+ elseif (!empty($row['page_title']))
{
// For a page
$t->assign(array(
@@ -110,7 +133,7 @@
'THANKS_ROW_TITLE' => htmlspecialchars($row['page_title'])
));
}
- else if (!empty($row['ft_title']))
+ elseif (!empty($row['ft_title']))
{
// For a page
$t->assign(array(
View
9 thanks.setup.php
@@ -3,9 +3,10 @@
[BEGIN_COT_EXT]
Code=thanks
Name=Thanks
-Description=Users can thank each other for pages and posts
-Version=1.1
-Date=2012-03-28
+Category=community-social
+Description=Users can thank each other for pages, posts and comments
+Version=1.2
+Date=2012-04-28
Author=Trustmaster
Copyright=All rights reserved (c) Vladimir Sibirov 2011-2012
Notes=BSD License
@@ -15,12 +16,14 @@
Auth_members=RW
Lock_members=12345
Recommends_modules=page,forums
+Recommends_plugins=comments
[END_COT_EXT]
[BEGIN_COT_EXT_CONFIG]
maxday=01:string::10:Max thanks a user can give a day
maxuser=02:string::5:Max thanks a day a user can give to a particular user
maxrowsperpage=03:string::20:Max thanks displayed per page
+comorder=04:radio::0:Sort comments by thanks
[END_COT_EXT_CONFIG]
==================== */

0 comments on commit 5e58f5d

Please sign in to comment.
Something went wrong with that request. Please try again.