PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/manage/expressionengine/controllers/cp/search.php

https://bitbucket.org/myockey/clearcreek-chapel-website
PHP | 151 lines | 76 code | 24 blank | 51 comment | 8 complexity | 7281d68aea6d3aab35661b18889fa4bc MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine CP Home Page Class
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Control Panel
  19. * @category Control Panel
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class Search extends CI_Controller {
  24. /**
  25. * Constructor
  26. */
  27. function __construct()
  28. {
  29. parent::__construct();
  30. $this->lang->loadfile('admin');
  31. $this->load->library('Cp_search');
  32. }
  33. // --------------------------------------------------------------------
  34. /**
  35. * Index function
  36. *
  37. * @access public
  38. * @return void
  39. */
  40. function index()
  41. {
  42. $this->load->helper('html');
  43. $this->load->helper('search');
  44. $vars['cp_page_title'] = lang('search_results');
  45. $this->cp->set_variable('cp_page_title', $vars['cp_page_title']);
  46. // Saved search
  47. if ($search = $this->input->get('saved'))
  48. {
  49. $search = base64_decode(rawurldecode($search));
  50. }
  51. else
  52. {
  53. $search = $this->input->get_post('cp_search_keywords', TRUE);
  54. }
  55. if ( ! $this->cp_search->_check_index())
  56. {
  57. // Save the search
  58. $search = rawurlencode(base64_encode($search));
  59. if (AJAX_REQUEST)
  60. {
  61. // Force a js redirect
  62. $url = str_replace('&amp;', '&', BASE).'&C=search&M=build_index&saved='.$search;
  63. echo '<script type="text/javascript">window.location="'.$url.'";</script>';
  64. exit;
  65. }
  66. // Degrade 'nicely'
  67. $this->functions->redirect(BASE.AMP.'C=search'.AMP.'M=build_index'.AMP.'saved='.$search);
  68. }
  69. $vars['keywords'] = sanitize_search_terms($search);
  70. $vars['can_rebuild'] = $this->cp->allowed_group('can_access_utilities');
  71. $vars['search_data'] = $this->cp_search->generate_results($search);
  72. $vars['num_rows'] = count($vars['search_data']);
  73. if (AJAX_REQUEST)
  74. {
  75. echo $this->load->view('search/sidebar', $vars, TRUE);
  76. exit;
  77. }
  78. $this->javascript->compile();
  79. $this->load->view('search/results', $vars);
  80. }
  81. // --------------------------------------------------------------------
  82. /**
  83. * Build Index
  84. *
  85. * Shows a 'working' page and orchestrates the rebuilding process
  86. *
  87. * @access public
  88. * @return mixed
  89. */
  90. function build_index()
  91. {
  92. // Did they specify a language
  93. $language = $this->input->get('language');
  94. $language = $language ? $language : $this->config->item('language');
  95. // Show an intermediate page so they don't refresh and make sure we keep any saved searches
  96. $flag = $this->input->get('working');
  97. $saved = $this->input->get('saved') ? AMP.'saved='.$this->input->get('saved') : '';
  98. if ( ! $flag)
  99. {
  100. $vars['cp_page_title'] = 'Rebuilding Index';
  101. $this->cp->set_variable('cp_page_title', $vars['cp_page_title']);
  102. // Meta refresh to start the process
  103. $meta = '<meta http-equiv="refresh" content="1;url='.BASE.AMP.'C=search'.AMP.'M=build_index'.AMP.'language='.$language.AMP.'working=y'.$saved.'" />';
  104. $this->cp->add_to_head($meta);
  105. $this->load->view('search/rebuild', $vars);
  106. }
  107. elseif ($flag == 'y')
  108. {
  109. // Clear all keywords for this language
  110. $this->db->where('language', $language);
  111. $this->db->delete('cp_search_index');
  112. // And we're on our way
  113. $this->cp_search->_build_index($language);
  114. $this->functions->redirect(BASE.AMP.'C=search'.AMP.'M=build_index'.AMP.'working=n'.$saved);
  115. }
  116. else
  117. {
  118. if ($saved)
  119. {
  120. $this->functions->redirect(BASE.AMP.'C=search'.$saved);
  121. }
  122. $this->functions->redirect(BASE.AMP.'C=homepage');
  123. }
  124. }
  125. }
  126. /* End of file search.php */
  127. /* Location: ./system/expressionengine/controllers/cp/search.php */