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.

knowledgebase_functions.inc.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. }
  51. ?>
  52. <div class="panel panel-default">
  53. <div class="panel-heading">
  54. <h4 class="text-left"><?php echo $hesklang['popart_no_colon']; ?></h4>
  55. </div>
  56. <table border="0" width="100%" class="table table-striped table-fixed">
  57. <thead>
  58. <tr>
  59. <?php
  60. /* Get list of articles from the database */
  61. $res = hesk_dbQuery("SELECT `t1`.`id`,`t1`.`subject`,`t1`.`views`,`t1`.`sticky` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` AS `t1`
  62. LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS `t2` ON `t1`.`catid` = `t2`.`id`
  63. WHERE `t1`.`type`='0' AND `t2`.`type`='0'
  64. ORDER BY `t1`.`sticky` DESC, `t1`.`views` DESC, `t1`.`art_order` ASC LIMIT " . intval($how_many));
  65. /* Show number of views? */
  66. if ($hesk_settings['kb_views'] && hesk_dbNumRows($res) != 0) {
  67. echo '<th class="col-xs-8 col-sm-9">&nbsp;</th>';
  68. echo '<th class="col-xs-4 col-sm-3"><i>' . $hesklang['views'] . '</i></th>';
  69. }
  70. ?>
  71. </tr>
  72. </thead>
  73. <tbody>
  74. <?php
  75. /* If no results found end here */
  76. if (hesk_dbNumRows($res) == 0) {
  77. $colspan = '';
  78. if (!$hesk_settings['kb_views']) {
  79. $colspan = 'colspan="2"';
  80. }
  81. echo '<tr><td ' . $colspan . '><i>' . $hesklang['noa'] . '</i></td></tr>';
  82. }
  83. /* We have some results, print them out */
  84. $colspan = '';
  85. if (!$hesk_settings['kb_views']) {
  86. $colspan = 'colspan="2"';
  87. }
  88. // Remember what articles are printed for "Top" so we don't print them again in "Latest"
  89. $hesk_settings['kb_top_articles_printed'] = array();
  90. while ($article = hesk_dbFetchAssoc($res)) {
  91. $hesk_settings['kb_spacing']--;
  92. $hesk_settings['kb_top_articles_printed'][] = $article['id'];
  93. $icon = 'fa fa-file';
  94. $style = '';
  95. if ($article['sticky']) {
  96. $icon = 'glyphicon glyphicon-pushpin';
  97. $style = 'style="color: #FF0000"';
  98. }
  99. echo '
  100. <tr>
  101. <td class="col-xs-8 col-sm-9" ' . $colspan . '>
  102. <i class="' . $icon . '" ' . $style . '></i> <a href="knowledgebase.php?article=' . $article['id'] . '">' . $article['subject'] . '</a>
  103. </td>
  104. ';
  105. if ($hesk_settings['kb_views']) {
  106. echo '<td class="col-xs-4 col-sm-3">' . $article['views'] . '</td>';
  107. }
  108. echo '</tr>';
  109. }
  110. ?>
  111. </tbody>
  112. </table>
  113. </div>
  114. <?php
  115. return true;
  116. } // END hesk_kbTopArticles()
  117. function hesk_kbLatestArticles($how_many, $index = 1)
  118. {
  119. global $hesk_settings, $hesklang;
  120. // Index page or KB main page?
  121. if ($index) {
  122. // Disabled?
  123. if (!$hesk_settings['kb_index_latest']) {
  124. return true;
  125. }
  126. // Show title in italics
  127. $font_weight = 'i';
  128. } else {
  129. // Disabled?
  130. if (!$hesk_settings['kb_latest']) {
  131. return true;
  132. }
  133. // Show title in bold
  134. $font_weight = 'b';
  135. // Print a line for spacing if we don't show popular articles
  136. if (!$hesk_settings['kb_popart']) {
  137. echo '<hr />';
  138. }
  139. }
  140. ?>
  141. <div class="panel panel-default">
  142. <div class="panel-heading">
  143. <h4 class="text-left"><?php echo $hesklang['latart_no_colon']; ?></h4>
  144. </div>
  145. <table class="table table-striped table-fixed">
  146. <thead>
  147. <tr>
  148. <?php
  149. // Don't include articles that have already been printed under "Top" articles
  150. $sql_top = '';
  151. if (isset($hesk_settings['kb_top_articles_printed']) && count($hesk_settings['kb_top_articles_printed'])) {
  152. $sql_top = ' AND `t1`.`id` NOT IN ('.implode(',', $hesk_settings['kb_top_articles_printed']).')';
  153. }
  154. $colspan = '';
  155. if (!$hesk_settings['kb_date']) {
  156. $colspan = 'colspan="2"';
  157. }
  158. /* Get list of articles from the database */
  159. $res = hesk_dbQuery("SELECT `t1`.* FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` AS `t1`
  160. LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` AS `t2` ON `t1`.`catid` = `t2`.`id`
  161. WHERE `t1`.`type`='0' AND `t2`.`type`='0' {$sql_top}
  162. ORDER BY `t1`.`dt` DESC LIMIT " . intval($how_many));
  163. /* Show number of views? */
  164. if (hesk_dbNumRows($res) != 0) {
  165. echo '<th class="col-xs-9" ' . $colspan . '>&nbsp;</th>';
  166. if ($hesk_settings['kb_date']) {
  167. echo '<th class="col-xs-3"><i>' . $hesklang['dta'] . '</i></th>';
  168. }
  169. }
  170. ?>
  171. </tr>
  172. </thead>
  173. <tbody>
  174. <?php
  175. /* If no results found end here */
  176. if (hesk_dbNumRows($res) == 0) {
  177. $colspan = '';
  178. if ($hesk_settings['kb_date']) {
  179. $colspan = 'colspan="2"';
  180. }
  181. echo '<td ' . $colspan . '><i>' . $hesklang['noa'] . '</i></td>';
  182. }
  183. /* We have some results, print them out */
  184. $colspan = $hesk_settings['kb_date'] ? '' : 'colspan="2"';
  185. while ($article = hesk_dbFetchAssoc($res)) {
  186. $hesk_settings['kb_spacing']--;
  187. $icon = 'fa fa-file';
  188. $style = '';
  189. if ($article['sticky']) {
  190. $icon = 'glyphicon glyphicon-pushpin';
  191. $style = 'style="color: #FF0000"';
  192. }
  193. echo '
  194. <tr>
  195. <td class="col-xs-9" ' . $colspan . '>
  196. <i class="' . $icon . '" ' . $style . '></i> <a href="knowledgebase.php?article=' . $article['id'] . '">' . $article['subject'] . '</a>
  197. </td>';
  198. if ($hesk_settings['kb_date']) {
  199. echo '<td class="col-xs-3">' . hesk_date($article['dt'], true) . '</td>';
  200. }
  201. echo '</tr>';
  202. } ?>
  203. </tbody>
  204. </table>
  205. </div>
  206. <?php
  207. return true;
  208. } // END hesk_kbLatestArticles()
  209. function hesk_kbSearchLarge($admin = '')
  210. {
  211. global $hesk_settings, $hesklang;
  212. $action = 'knowledgebase.php';
  213. if ($admin) {
  214. if (!$hesk_settings['kb_search']) {
  215. return '';
  216. }
  217. $action = 'knowledgebase_private.php';
  218. } elseif ($hesk_settings['kb_search'] != 2) {
  219. return '';
  220. }
  221. ?>
  222. <div style="text-align:center">
  223. <form role="form" action="<?php echo $action; ?>" method="get" style="display: inline; margin: 0;"
  224. name="searchform">
  225. <div class="input-group">
  226. <input type="text" class="form-control"
  227. placeholder="<?php echo htmlspecialchars($hesklang['search_the_knowledgebase']); ?>"
  228. name="search">
  229. <span class="input-group-btn">
  230. <button class="btn btn-default" type="submit" value="<?php echo $hesklang['search']; ?>"
  231. title="<?php echo $hesklang['search']; ?>"><?php echo $hesklang['search']; ?></button>
  232. </span>
  233. </div>
  234. </form>
  235. </div>
  236. <br/>
  237. <!-- START KNOWLEDGEBASE SUGGEST -->
  238. <div id="kb_suggestions" style="display:none">
  239. <img src="<?php echo HESK_PATH; ?>img/loading.gif" width="24" height="24" alt="" border="0"
  240. style="vertical-align:text-bottom"/> <i><?php echo $hesklang['lkbs']; ?></i>
  241. </div>
  242. <script language="Javascript" type="text/javascript"><!--
  243. hesk_suggestKBsearch(<?php echo $admin; ?>);
  244. //-->
  245. </script>
  246. <!-- END KNOWLEDGEBASE SUGGEST -->
  247. <br/>
  248. <?php
  249. } // END hesk_kbSearchLarge()
  250. function hesk_kbSearchSmall()
  251. {
  252. global $hesk_settings, $hesklang;
  253. if ($hesk_settings['kb_search'] != 1) {
  254. return '';
  255. }
  256. ?>
  257. <td class="text-right" valign="top" width="300">
  258. <div style="display:inline;margin-left:auto;margin-right:auto">
  259. <form action="knowledgebase.php" method="get" class="form-inline" style="display: inline; margin: 0;">
  260. <div class="input-group" style="margin: 0 15px">
  261. <input type="text" name="search" class="form-control">
  262. <span class="input-group-btn">
  263. <button class="btn btn-default" type="submit"
  264. value="<?php echo $hesklang['search_the_knowledgebase']; ?>"
  265. title="<?php echo $hesklang['search_the_knowledgebase']; ?>">
  266. <?php echo $hesklang['search_the_knowledgebase']; ?>
  267. </button>
  268. </span>
  269. </div>
  270. </form>
  271. <br><br>
  272. </div>
  273. </td>
  274. <?php
  275. } // END hesk_kbSearchSmall()
  276. function hesk_detect_bots()
  277. {
  278. $botlist = array('googlebot', 'msnbot', 'slurp', 'alexa', 'teoma', 'froogle',
  279. 'gigabot', 'inktomi', 'looksmart', 'firefly', 'nationaldirectory',
  280. 'ask jeeves', 'tecnoseek', 'infoseek', 'webfindbot', 'girafabot',
  281. 'crawl', 'www.galaxy.com', 'scooter', 'appie', 'fast', 'webbug', 'spade', 'zyborg', 'rabaz',
  282. 'baiduspider', 'feedfetcher-google', 'technoratisnoop', 'rankivabot',
  283. 'mediapartners-google', 'crawler', 'spider', 'robot', 'bot/', 'bot-', 'voila');
  284. if (!isset($_SERVER['HTTP_USER_AGENT'])) {
  285. return false;
  286. }
  287. $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
  288. foreach ($botlist as $bot) {
  289. if (strpos($ua, $bot) !== false) {
  290. return true;
  291. }
  292. }
  293. return false;
  294. } // END hesk_detect_bots()