PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyfaq/admin/stat.search.php

https://github.com/cyrke/phpMyFAQ
PHP | 148 lines | 107 code | 15 blank | 26 comment | 10 complexity | bc047450ca73d1eefd424bf65d0bfb65 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Frontend for search log statistics
  4. *
  5. * PHP Version 5.3
  6. *
  7. * This Source Code Form is subject to the terms of the Mozilla Public License,
  8. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. * obtain one at http://mozilla.org/MPL/2.0/.
  10. *
  11. * @category phpMyFAQ
  12. * @package Administration
  13. * @author Anatoliy Belsky <anatoliy.belsky@mayflower.de>
  14. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  15. * @copyright 2003-2012 phpMyFAQ Team
  16. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  17. * @link http://www.phpmyfaq.de
  18. * @since 2003-03-30
  19. */
  20. if (!defined('IS_VALID_PHPMYFAQ')) {
  21. header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
  22. exit();
  23. }
  24. if ($permission['viewlog']) {
  25. printf('<header><h2>%s</h2></header>', $PMF_LANG['ad_menu_searchstats']);
  26. $perpage = 15;
  27. $pages = PMF_Filter::filterInput(INPUT_GET, 'pages', FILTER_VALIDATE_INT);
  28. $page = PMF_Filter::filterInput(INPUT_GET, 'page' , FILTER_VALIDATE_INT, 1);
  29. $search = new PMF_Search($faqConfig);
  30. $searchesCount = $search->getSearchesCount();
  31. $searchesList = $search->getMostPopularSearches($searchesCount + 1, true);
  32. if (is_null($pages)) {
  33. $pages = round((count($searchesList) + ($perpage / 3)) / $perpage, 0);
  34. }
  35. $start = ($page - 1) * $perpage;
  36. $ende = $start + $perpage;
  37. $baseUrl = sprintf(
  38. '%s?action=searchstats&amp;page=%d',
  39. PMF_Link::getSystemRelativeUri(),
  40. $page
  41. );
  42. // Pagination options
  43. $options = array(
  44. 'baseUrl' => $baseUrl,
  45. 'total' => count($searchesList),
  46. 'perPage' => $perpage,
  47. 'pageParamName' => 'page'
  48. );
  49. $pagination = new PMF_Pagination($faqConfig, $options);
  50. ?>
  51. <div id="ajaxresponse"></div>
  52. <table class="table table-striped">
  53. <thead>
  54. <tr>
  55. <th><?php print $PMF_LANG['ad_searchstats_search_term'] ?></th>
  56. <th><?php print $PMF_LANG['ad_searchstats_search_term_count'] ?></th>
  57. <th><?php print $PMF_LANG['ad_searchstats_search_term_lang'] ?></th>
  58. <th colspan="2"><?php print $PMF_LANG['ad_searchstats_search_term_percentage'] ?></th>
  59. <th>&nbsp;</th>
  60. </tr>
  61. </thead>
  62. <tfoot>
  63. <tr>
  64. <td colspan="6"><?php echo $pagination->render(); ?></td>
  65. </tr>
  66. </tfoot>
  67. <tbody>
  68. <?php
  69. $counter = $displayedCounter = 0;
  70. $self = substr(__FILE__, strlen($_SERVER['DOCUMENT_ROOT']));
  71. foreach($searchesList as $searchItem) {
  72. if ($displayedCounter >= $perpage) {
  73. $displayedCounter++;
  74. continue;
  75. }
  76. $counter++;
  77. if ($counter <= $start) {
  78. continue;
  79. }
  80. $displayedCounter++;
  81. $num = round(($searchItem['number']*100 / $searchesCount), 2);
  82. ?>
  83. <tr class="row_search_id_<?php print $searchItem['id'] ?>">
  84. <td><?php print PMF_String::htmlspecialchars($searchItem['searchterm']); ?></td>
  85. <td><?php print $searchItem['number'] ?></td>
  86. <td><?php print $languageCodes[PMF_String::strtoupper($searchItem['lang'])] ?></td>
  87. <td>
  88. <div class="progress progress-info" style="width: 50px;">
  89. <div class="bar" style="width: <?php print $num; ?>%;"></div>
  90. </div>
  91. </td>
  92. <td><?php print $num; ?>%</td>
  93. <td>
  94. <a onclick="deleteSearchTerm('<?php print $searchItem['searchterm'] ?>', <?php print $searchItem['id'] ?>); return false;"
  95. href="javascript:;">
  96. <span title="<?php print $PMF_LANG["ad_news_delete"]; ?>" class="icon-trash"></span>
  97. </a>
  98. </td>
  99. </tr>
  100. <?php
  101. }
  102. ?>
  103. </tbody>
  104. </table>
  105. <script type="text/javascript">
  106. /* <![CDATA[ */
  107. /**
  108. * Ajax call to delete search term
  109. *
  110. * @param searchterm
  111. */
  112. function deleteSearchTerm(searchterm, searchId)
  113. {
  114. if (confirm('<?php print $PMF_LANG['ad_user_del_3'] ?>')) {
  115. $.getJSON("index.php?action=ajax&ajax=search&ajaxaction=delete_searchterm&searchterm=" + searchterm,
  116. function(response) {
  117. if (response == 1) {
  118. $('#ajaxresponse').
  119. html('<?php printf('<p class="success">%s</p>', $PMF_LANG['ad_search_delsuc']) ?>');
  120. $('.row_search_id_' + searchId).fadeOut('slow');
  121. } else {
  122. $('#ajaxresponse').
  123. html('<?php printf('<p class="error">%s</p>', $PMF_LANG['ad_search_delfail']) ?>');
  124. }
  125. });
  126. }
  127. }
  128. /* ]]> */
  129. </script>
  130. <?php
  131. } else {
  132. print $PMF_LANG['err_NotAuth'];
  133. }