PageRenderTime 136ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/knowledgebase_functions.inc.php

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