Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
12 KiB

  1. <?php
  2. /**
  3. *
  4. * This file is part of HESK - PHP Help Desk Software.
  5. *
  6. * (c) Copyright Klemen Stirn. All rights reserved.
  7. * https://www.hesk.com
  8. *
  9. * For the full copyright and license agreement information visit
  10. * https://www.hesk.com/eula.php
  11. *
  12. */
  13. /* Check if this is a valid include */
  14. if (!defined('IN_SCRIPT')) {
  15. die('Invalid attempt');
  16. }
  17. /*** FUNCTIONS ***/
  18. function hesk_kbArticleContentPreview($txt)
  19. {
  20. global $hesk_settings;
  21. // Strip HTML tags
  22. $txt = strip_tags($txt);
  23. // If text is larger than article preview length, shorten it
  24. if (strlen($txt) > $hesk_settings['kb_substrart']) {
  25. // The quick but not 100% accurate way (number of chars displayed may be lower than the limit)
  26. return substr($txt, 0, $hesk_settings['kb_substrart']) . '...';
  27. // If you want a more accurate, but also slower way, use this instead
  28. // return hesk_htmlentities( substr( hesk_html_entity_decode($txt), 0, $hesk_settings['kb_substrart'] ) ) . '...';
  29. }
  30. return $txt;
  31. } // END hesk_kbArticleContentPreview()
  32. function hesk_kbTopArticles($how_many, $index = 1)
  33. {
  34. global $hesk_settings, $hesklang;
  35. // Index page or KB main page?
  36. if ($index) {
  37. // Disabled?
  38. if (!$hesk_settings['kb_index_popart']) {
  39. return true;
  40. }
  41. // Show title in italics
  42. $font_weight = 'i';
  43. } else {
  44. // Disabled?
  45. if (!$hesk_settings['kb_popart']) {
  46. return true;
  47. }
  48. // Show title in bold
  49. $font_weight = 'b';
  50. // Print a line for spacing
  51. echo '<hr />';
  52. }
  53. ?>
  54. <div class="panel panel-default">
  55. <div class="panel-heading">
  56. <h4 class="text-left"><?php echo $hesklang['popart_no_colon']; ?></h4>
  57. </div>
  58. <table border="0" width="100%" class="table table-striped table-fixed">
  59. <thead>
  60. <tr>
  61. <?php
  62. /* Get list of articles from the database */
  63. $res = hesk_dbQuery("SELECT `t1`.`id`,`t1`.`subject`,`t1`.`views`,`t1`.`sticky` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` AS `t1`
  64. LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS `t2` ON `t1`.`catid` = `t2`.`id`
  65. WHERE `t1`.`type`='0' AND `t2`.`type`='0'
  66. ORDER BY `t1`.`sticky` DESC, `t1`.`views` DESC, `t1`.`art_order` ASC LIMIT " . intval($how_many));
  67. /* Show number of views? */
  68. if ($hesk_settings['kb_views'] && hesk_dbNumRows($res) != 0) {
  69. echo '<th class="col-xs-8 col-sm-9">&nbsp;</th>';
  70. echo '<th class="col-xs-4 col-sm-3"><i>' . $hesklang['views'] . '</i></th>';
  71. }
  72. ?>
  73. </tr>
  74. </thead>
  75. <tbody>
  76. <?php
  77. /* Get list of articles from the database */
  78. $res = hesk_dbQuery("SELECT `t1`.`id`,`t1`.`subject`,`t1`.`dt`, `t1`.`views`,`t1`.`sticky` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` AS `t1`
  79. LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS `t2` ON `t1`.`catid` = `t2`.`id`
  80. WHERE `t1`.`type`='0' AND `t2`.`type`='0'
  81. ORDER BY `t1`.`sticky` DESC, `t1`.`views` DESC, `t1`.`art_order` ASC LIMIT " . intval($how_many));
  82. /* If no results found end here */
  83. if (hesk_dbNumRows($res) == 0) {
  84. $colspan = '';
  85. if (!$hesk_settings['kb_views']) {
  86. $colspan = 'colspan="2"';
  87. }
  88. echo '<tr><td ' . $colspan . '><i>' . $hesklang['noa'] . '</i></td></tr>';
  89. }
  90. /* We have some results, print them out */
  91. $colspan = '';
  92. if (!$hesk_settings['kb_views']) {
  93. $colspan = 'colspan="2"';
  94. }
  95. while ($article = hesk_dbFetchAssoc($res)) {
  96. $icon = 'fa fa-file';
  97. $style = '';
  98. if ($article['sticky']) {
  99. $icon = 'glyphicon glyphicon-pushpin';
  100. $style = 'style="color: #FF0000"';
  101. }
  102. echo '
  103. <tr>
  104. <td class="col-xs-8 col-sm-9" ' . $colspan . '>
  105. <i class="' . $icon . '" ' . $style . '></i> <a href="knowledgebase.php?article=' . $article['id'] . '">' . $article['subject'] . '</a>
  106. </td>
  107. ';
  108. if ($hesk_settings['kb_views']) {
  109. echo '<td class="col-xs-4 col-sm-3">' . $article['views'] . '</td>';
  110. }
  111. echo '</tr>';
  112. }
  113. ?>
  114. </tbody>
  115. </table>
  116. </div>
  117. <?php
  118. return true;
  119. } // END hesk_kbTopArticles()
  120. function hesk_kbLatestArticles($how_many, $index = 1)
  121. {
  122. global $hesk_settings, $hesklang;
  123. // Index page or KB main page?
  124. if ($index) {
  125. // Disabled?
  126. if (!$hesk_settings['kb_index_latest']) {
  127. return true;
  128. }
  129. // Show title in italics
  130. $font_weight = 'i';
  131. } else {
  132. // Disabled?
  133. if (!$hesk_settings['kb_latest']) {
  134. return true;
  135. }
  136. // Show title in bold
  137. $font_weight = 'b';
  138. // Print a line for spacing if we don't show popular articles
  139. if (!$hesk_settings['kb_popart']) {
  140. echo '<hr />';
  141. }
  142. }
  143. ?>
  144. <div class="panel panel-default">
  145. <div class="panel-heading">
  146. <h4 class="text-left"><?php echo $hesklang['latart_no_colon']; ?></h4>
  147. </div>
  148. <table class="table table-striped table-fixed">
  149. <thead>
  150. <tr>
  151. <?php
  152. $colspan = '';
  153. if (!$hesk_settings['kb_date']) {
  154. $colspan = 'colspan="2"';
  155. }
  156. /* Get list of articles from the database */
  157. $res = hesk_dbQuery("SELECT `t1`.* FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` AS `t1`
  158. LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS `t2` ON `t1`.`catid` = `t2`.`id`
  159. WHERE `t1`.`type`='0' AND `t2`.`type`='0'
  160. ORDER BY `t1`.`dt` DESC LIMIT " . intval($how_many));
  161. /* Show number of views? */
  162. if (hesk_dbNumRows($res) != 0) {
  163. echo '<th class="col-xs-9" ' . $colspan . '>&nbsp;</th>';
  164. if ($hesk_settings['kb_date']) {
  165. echo '<th class="col-xs-3"><i>' . $hesklang['dta'] . '</i></th>';
  166. }
  167. }
  168. ?>
  169. </tr>
  170. </thead>
  171. <tbody>
  172. <?php
  173. /* Get list of articles from the database */
  174. $res = hesk_dbQuery("SELECT `t1`.* FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` AS `t1`
  175. LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS `t2` ON `t1`.`catid` = `t2`.`id`
  176. WHERE `t1`.`type`='0' AND `t2`.`type`='0'
  177. ORDER BY `t1`.`dt` DESC LIMIT " . intval($how_many));
  178. /* If no results found end here */
  179. if (hesk_dbNumRows($res) == 0) {
  180. $colspan = '';
  181. if ($hesk_settings['kb_date']) {
  182. $colspan = 'colspan="2"';
  183. }
  184. echo '<td ' . $colspan . '><i>' . $hesklang['noa'] . '</i></td>';
  185. }
  186. /* We have some results, print them out */
  187. $colspan = $hesk_settings['kb_date'] ? '' : 'colspan="2"';
  188. while ($article = hesk_dbFetchAssoc($res)) {
  189. $icon = 'fa fa-file';
  190. $style = '';
  191. if ($article['sticky']) {
  192. $icon = 'glyphicon glyphicon-pushpin';
  193. $style = 'style="color: #FF0000"';
  194. }
  195. echo '
  196. <tr>
  197. <td class="col-xs-9" ' . $colspan . '>
  198. <i class="' . $icon . '" ' . $style . '></i> <a href="knowledgebase.php?article=' . $article['id'] . '">' . $article['subject'] . '</a>
  199. </td>';
  200. if ($hesk_settings['kb_date']) {
  201. echo '<td class="col-xs-3">' . hesk_date($article['dt'], true) . '</td>';
  202. }
  203. echo '</tr>';
  204. } ?>
  205. </tbody>
  206. </table>
  207. </div>
  208. <?php
  209. return true;
  210. } // END hesk_kbLatestArticles()
  211. function hesk_kbSearchLarge($admin = '')
  212. {
  213. global $hesk_settings, $hesklang;
  214. $action = 'knowledgebase.php';
  215. if ($admin) {
  216. if (!$hesk_settings['kb_search']) {
  217. return '';
  218. }
  219. $action = 'knowledgebase_private.php';
  220. } elseif ($hesk_settings['kb_search'] != 2) {
  221. return '';
  222. }
  223. ?>
  224. <div style="text-align:center">
  225. <form role="form" action="<?php echo $action; ?>" method="get" style="display: inline; margin: 0;"
  226. name="searchform">
  227. <div class="input-group">
  228. <input type="text" class="form-control"
  229. placeholder="<?php echo htmlspecialchars($hesklang['search_the_knowledgebase']); ?>"
  230. name="search">
  231. <span class="input-group-btn">
  232. <button class="btn btn-default" type="submit" value="<?php echo $hesklang['search']; ?>"
  233. title="<?php echo $hesklang['search']; ?>"><?php echo $hesklang['search']; ?></button>
  234. </span>
  235. </div>
  236. </form>
  237. </div>
  238. <br/>
  239. <!-- START KNOWLEDGEBASE SUGGEST -->
  240. <div id="kb_suggestions" style="display:none">
  241. <img src="<?php echo HESK_PATH; ?>img/loading.gif" width="24" height="24" alt="" border="0"
  242. style="vertical-align:text-bottom"/> <i><?php echo $hesklang['lkbs']; ?></i>
  243. </div>
  244. <script language="Javascript" type="text/javascript"><!--
  245. hesk_suggestKBsearch(<?php echo $admin; ?>);
  246. //-->
  247. </script>
  248. <!-- END KNOWLEDGEBASE SUGGEST -->
  249. <br/>
  250. <?php
  251. } // END hesk_kbSearchLarge()
  252. function hesk_kbSearchSmall()
  253. {
  254. global $hesk_settings, $hesklang;
  255. if ($hesk_settings['kb_search'] != 1) {
  256. return '';
  257. }
  258. ?>
  259. <td class="text-right" valign="top" width="300">
  260. <div style="display:inline;margin-left:auto;margin-right:auto">
  261. <form action="knowledgebase.php" method="get" class="form-inline" style="display: inline; margin: 0;">
  262. <div class="input-group" style="margin: 0 15px">
  263. <input type="text" name="search" class="form-control">
  264. <span class="input-group-btn">
  265. <button class="btn btn-default" type="submit"
  266. value="<?php echo $hesklang['search_the_knowledgebase']; ?>"
  267. title="<?php echo $hesklang['search_the_knowledgebase']; ?>">
  268. <?php echo $hesklang['search_the_knowledgebase']; ?>
  269. </button>
  270. </span>
  271. </div>
  272. </form>
  273. <br><br>
  274. </div>
  275. </td>
  276. <?php
  277. } // END hesk_kbSearchSmall()
  278. function hesk_detect_bots()
  279. {
  280. $botlist = array('googlebot', 'msnbot', 'slurp', 'alexa', 'teoma', 'froogle',
  281. 'gigabot', 'inktomi', 'looksmart', 'firefly', 'nationaldirectory',
  282. 'ask jeeves', 'tecnoseek', 'infoseek', 'webfindbot', 'girafabot',
  283. 'crawl', 'www.galaxy.com', 'scooter', 'appie', 'fast', 'webbug', 'spade', 'zyborg', 'rabaz',
  284. 'baiduspider', 'feedfetcher-google', 'technoratisnoop', 'rankivabot',
  285. 'mediapartners-google', 'crawler', 'spider', 'robot', 'bot/', 'bot-', 'voila');
  286. if (!isset($_SERVER['HTTP_USER_AGENT'])) {
  287. return false;
  288. }
  289. $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
  290. foreach ($botlist as $bot) {
  291. if (strpos($ua, $bot) !== false) {
  292. return true;
  293. }
  294. }
  295. return false;
  296. } // END hesk_detect_bots()