Advertisement
Guest User

Untitled

a guest
Oct 6th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. <?php
  2. /******************************************************************************/
  3. // //
  4. // InstantCMS v1.8 //
  5. // http://www.instantcms.ru/ //
  6. // //
  7. // written by InstantCMS Team, 2007-2010 //
  8. // produced by InstantSoft, (www.instantsoft.ru) //
  9. // //
  10. // LICENSED BY GNU/GPL v2 //
  11. // //
  12. /******************************************************************************/
  13.  
  14. function mod_comments($module_id){
  15. include('useragent/useragent.php');
  16. $inCore = cmsCore::getInstance();
  17. $inDB = cmsDatabase::getInstance();
  18. global $_LANG;
  19.  
  20. $cfg = $inCore->loadModuleConfig($module_id);
  21.  
  22. if (!isset($cfg['showrss'])) { $cfg['showrss'] = 1;}
  23. if (!isset($cfg['minrate'])) { $cfg['minrate'] = 0;}
  24. if (!isset($cfg['showguest'])) { $cfg['showguest'] = 0;}
  25.  
  26. $targeting = sizeof($cfg['targets']);
  27.  
  28. if (!$targeting){ echo '<p>'.$_LANG['COMMENTS_NOT_SHOWTYPE'].'</p>'; return true; }
  29.  
  30. $t_list = array();
  31.  
  32. foreach($cfg['targets'] as $type){
  33. $t_list[] = "'$type'";
  34. }
  35.  
  36. $t_list = rtrim(implode(',', $t_list), ',');
  37.  
  38. $target_where = "AND c.target IN ({$t_list})";
  39.  
  40. $guest_sql = $cfg['showguest'] ? "OR c.guestname<>''" : "";
  41.  
  42. $sql = "SELECT c.id as id,
  43. c.target as target,
  44. c.target_id as target_id,
  45. c.target_link as target_link,
  46. c.target_title,
  47. c.content as content,
  48. c.guestname,
  49. c.pubdate as fpubdate,
  50. c.useragent as useragent,
  51. IFNULL(c.user_id, 0) as user_id,
  52. IFNULL(u.nickname, '') as author,
  53. IFNULL(u.login, '') as author_login,
  54. IFNULL(v.total_rating, 0) as rating
  55. FROM cms_comments c
  56. INNER JOIN cms_users u ON u.id = c.user_id {$guest_sql}
  57. LEFT JOIN cms_ratings_total v ON v.item_id=c.id AND v.target='comment'
  58. WHERE c.published=1 {$target_where}
  59. GROUP BY c.id
  60. ORDER BY c.id DESC
  61. LIMIT 70";
  62.  
  63. $result = $inDB->query($sql);
  64. $is_com = false;
  65. if ($inDB->num_rows($result)){
  66. $is_com = true;
  67. $count = 0;
  68. $comments = array();
  69. while($con = $inDB->fetch_assoc($result)){
  70.  
  71. if ($count >= $cfg['shownum']) { break; }
  72.  
  73. if ($con['rating'] >= $cfg['minrate']){
  74.  
  75. $con['link'] = $con['target_link'] . '#c'.$con['id'];
  76. $con['text'] = strip_tags($con['content']);
  77.  
  78. $con['text'] = preg_replace('/\[hide\](.*?)\[\/hide\]/i', '', $con['text']);
  79. $con['text'] = preg_replace('/\[hide\](.*?)$/i', '', $con['text']);
  80.  
  81. if (strlen($con['text'])>60) { $con['text'] = substr($con['text'], 0, 60). '...'; }
  82. if (!$con['text']) { $con['text'] = '...'; }
  83.  
  84. $con['user_url'] = $con['user_id'] ? cmsUser::getProfileURL($con['author_login']) : $con['link'];
  85. $con['author'] = $con['user_id'] ? $con['author'] : $con['guestname'];
  86. $con['fpubdate'] = $inCore->dateFormat($con['fpubdate']);
  87. $useragent_title=$con['useragent'];
  88. $con['useragent']=display_useragent();
  89. $comments[] = $con;
  90. $count++;
  91. }
  92.  
  93. }
  94.  
  95. }
  96.  
  97. $smarty = $inCore->initSmarty('modules', 'mod_comments.tpl');
  98. $smarty->assign('comments', $comments);
  99. $smarty->assign('cfg', $cfg);
  100. $smarty->assign('is_com', $is_com);
  101. $smarty->display('mod_comments.tpl');
  102.  
  103. return true;
  104. }
  105. ?>
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement