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.

suggest_email.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. define('IN_SCRIPT', 1);
  14. define('HESK_PATH', './');
  15. // Get all the required files and functions
  16. require(HESK_PATH . 'hesk_settings.inc.php');
  17. require(HESK_PATH . 'inc/common.inc.php');
  18. // Feature enabled?
  19. if (!$hesk_settings['detect_typos']) {
  20. die('');
  21. }
  22. // Print XML header
  23. header('Content-Type: text/html; charset=' . $hesklang['ENCODING']);
  24. header("Cache-Control: no-store, no-cache, must-revalidate");
  25. header("Cache-Control: post-check=0, pre-check=0", false);
  26. header("Pragma: no-cache");
  27. // Get the search query composed of the subject and message
  28. $address = hesk_REQUEST('e') or die('');
  29. $email_field = hesk_REQUEST('ef') or die('');
  30. $display_div = hesk_REQUEST('dd') or die('');
  31. $pad_div = hesk_REQUEST('pd') ? 1 : 0;
  32. $div = 1;
  33. // Do we allow multiple emails? If yes, check all
  34. if ($hesk_settings['multi_eml'] || hesk_REQUEST('am')) {
  35. // Make sure the format is correct
  36. $address = preg_replace('/\s/', '', $address);
  37. $address = str_replace(';', ',', $address);
  38. // Loops through emails and check for typos
  39. $div = 1;
  40. $all = explode(',', $address);
  41. foreach ($all as $address) {
  42. if (($suggest = hesk_emailTypo($address)) !== false) {
  43. hesk_emailTypoShow($address, $suggest, $div);
  44. $div++;
  45. }
  46. }
  47. } // If multiple emails are not allowed, check just first one
  48. elseif (($suggest = hesk_emailTypo($address)) !== false) {
  49. hesk_emailTypoShow($address, $suggest);
  50. }
  51. exit();
  52. function hesk_emailTypoShow($address, $suggest, $div = '')
  53. {
  54. global $hesk_settings, $hesklang, $email_field, $display_div, $pad_div;
  55. ?>
  56. <div id="emailtypo<?php echo $display_div.$div; ?>" style="display:block">
  57. <table border="0" width="100%">
  58. <tr>
  59. <td width="150">&nbsp;</td>
  60. <td width="80%">
  61. <div class="alert alert-info">
  62. <?php echo sprintf($hesklang['didum'], str_replace('@', '@<b>', $suggest . '</b>')); ?>
  63. <br/><br/>
  64. <a class="btn btn-default" href="javascript:void(0);" onclick="var eml=document.getElementById('<?php echo $email_field; ?>').value;document.getElementById('<?php echo $email_field; ?>').value=eml.replace(/<?php echo preg_quote($address, '/'); ?>/gi, '<?php echo addslashes($suggest); ?>' );document.getElementById('emailtypo<?php echo $display_div.$div; ?>').style.display='none';"><?php echo $hesklang['yfix']; ?></a>
  65. <a class="btn btn-default" href="javascript:void(0);" onclick="document.getElementById('emailtypo<?php echo $display_div.$div; ?>').style.display='none';"><?php echo $hesklang['nole']; ?></a>
  66. </div>
  67. </td>
  68. </tr>
  69. </table>
  70. </div>
  71. <?php
  72. } // END hesk_emailTypoShow()
  73. function hesk_emailTypo($address)
  74. {
  75. global $hesk_settings;
  76. // Remove anything more than a single address
  77. $address = str_replace(strstr($address, ','), '', $address);
  78. $address = str_replace(strstr($address, ';'), '', $address);
  79. $address = strtolower(trim($address));
  80. // Get email domain
  81. $domain = substr(strrchr($address, '@'), 1);
  82. // If no domain return false
  83. if (!$domain) {
  84. return false;
  85. }
  86. // If we have an exact match return false
  87. if (in_array($domain, $hesk_settings['email_providers'])) {
  88. return false;
  89. }
  90. $shortest = -1;
  91. $closest = '';
  92. foreach ($hesk_settings['email_providers'] as $provider) {
  93. $similar = levenshtein($domain, $provider, 2, 1, 3);
  94. if ($similar < 1) {
  95. return false;
  96. }
  97. if ($similar < $shortest || $shortest < 0) {
  98. $closest = $provider;
  99. $shortest = $similar;
  100. }
  101. }
  102. if ($shortest < 4) {
  103. return str_replace($domain, $closest, $address);
  104. } else {
  105. return false;
  106. }
  107. } // END hesk_emailTypo()
  108. ?>