Exemple #1
0
 /**
  * Index all search datas.
  *
  * @since 3.0.0
  */
 public function makeIndex()
 {
     //Admin panel
     if (!TTO_IS_ADMIN) {
         return;
     }
     //Index contents
     $count = $this->search->getEngine()->indexContents();
     //Update counter
     $index = Search::getIndex();
     TeaThemeOptions::setConfigs($index . '-count', $count);
 }
Exemple #2
0
 /**
  * Display HTML component.
  *
  * @param array $content Contains all field data
  * @param array $details Contains all field options
  *
  * @since 3.0.0
  */
 public function prepareField($content, $details = array())
 {
     //Build details
     $post = isset($details['post']) ? $details['post'] : 0;
     $prefix = isset($details['prefix']) ? $details['prefix'] : '';
     $tpl = empty($prefix) ? 'pages' : 'terms';
     //Get indexed content count and status
     $count = TeaThemeOptions::getConfigs(SearchEngine::getIndex() . '-count', 0);
     $status = TeaThemeOptions::getConfigs(SearchEngine::getIndex() . '-status', 0);
     //Get page
     $page = $this->getSearchCurrentPage() . '&do=tto-action&make=create';
     //Get right page
     if (0 < $status) {
         $page = $this->getSearchCurrentPage() . '&do=tto-action&make=index';
     }
     //Build defaults data
     $template = array('count' => $count, 'page' => $page, 'status' => $status, 'post' => $post, 'prefix' => $prefix, 'template' => $tpl, 't_es_notify_n' => sprintf(TeaThemeOptions::__('<small>Check your configurations to properly use the Search Engine.</small>
                 <a href="%s" class="button button-primary">Create now your Search Index</a>'), $page), 't_es_notify_0' => sprintf(TeaThemeOptions::__('<small>Your parameters are well configured but your contents have not been indexed.</small>
                 <a href="%s" class="button button-primary">Let\'s do it!</a>'), $page), 't_es_notify_s' => sprintf(TeaThemeOptions::__('<small>Well done: <code>%d</code> posts have been indexed!</small>
                 <a href="%s" class="button button-main">Update contents!</a>'), $count, $page));
     //Get template
     return $this->renderField('fields/search.html.twig', $template);
 }
Exemple #3
0
 /**
  * Constructor.
  *
  * @param array $configs Contains all Search Engine configurations
  * @param boolean $hook Define if we have to use hooks or not
  *
  * @since 3.3.3
  */
 public function __construct($configs, $hook)
 {
     //Initialize Elastica
     $this->engine = new Elastica($configs);
     $status = TeaThemeOptions::getConfigs(Search::getIndex() . '-status', 0);
     //Check global status
     if (200 !== $status) {
         return;
     }
     //Check index
     if ($hook && isset($configs['status']) && 200 == $configs['status']) {
         //Add WP Hooks
         if (TTO_IS_ADMIN) {
             add_action('delete_post', array(&$this, 'hookDeleteItem'));
             add_action('trash_post', array(&$this, 'hookDeleteItem'));
             add_action('save_post', array(&$this, 'hookSaveItem'));
         } else {
             $this->template = isset($ctn['template']) && 'yes' == $ctn['template'] ? true : false;
             add_action('pre_get_posts', array(&$this, 'hookSearchProcess'), 500, 2);
             add_filter('the_posts', array(&$this, 'hookSearchResults'));
             add_action('template_redirect', array(&$this, 'hookSearchTemplate'));
         }
     }
 }
 /**
  * Delete post from Elastica Client.
  *
  * @param object $post Post to delete
  *
  * @since 3.0.0
  */
 public function postDelete($post)
 {
     //Get configs
     $ctn = $this->getConfig();
     //Check post integrity
     if (null == $post || !in_array($post->post_type, $ctn['posttypes'])) {
         return;
     }
     //Get index
     $index = $this->getIndex();
     //Get type
     $type = $index->getType($post->post_type);
     //Try to delete post
     try {
         //Delete post by its ID
         $type->deleteById($post->ID);
         //Update counter
         $index = Search::getIndex();
         $count = TeaThemeOptions::getConfigs($index . '-count');
         $count = empty($count) ? 0 : $count[0] - 1;
         //Save in DB
         TeaThemeOptions::setConfigs($index . '-count', $count);
     } catch (NotFoundException $ex) {
     }
 }