/** * Search contents. * * @return array $elasticsearches Combine of all results, total and aggregations * * @since 1.5.0 */ public function searchContents() { //Return array $return = array('query' => array('search' => '', 'type' => '', 'paged' => 0, 'perpage' => 0), 'total' => 0, 'types' => array(), 'results' => array()); //Check page if (!is_search()) { return $return; } //Get query vars $request = isset($_REQUEST) ? $_REQUEST : array(); $results = array(); $types = array(); //Check request if (empty($request)) { return $return; } //Get Elasticsearch datas $index = $this->getIndex(); //Check index if (null === $index || empty($index)) { return $return; } //Get search datas $search = isset($request['s']) ? str_replace('\\"', '"', $request['s']) : ''; //Return everything if (empty($search)) { return $return; } //Get search datas $type = isset($request['type']) ? $request['type'] : ''; $paged = isset($request['paged']) && !empty($request['paged']) ? $request['paged'] - 1 : 0; $perpage = isset($request['perpage']) ? $request['perpage'] : TeaThemeOptions::getOption('posts_per_page', 10); //Build query string $es_querystring = new QueryString(); //'And' or 'Or' default: 'Or' $es_querystring->setDefaultOperator('OR'); $es_querystring->setQuery($search); //Create the actual search object with some data. $es_query = new Query(); $es_query->setQuery($es_querystring); //Define options $es_query->setFrom($paged); //Start $es_query->setLimit($perpage); //How many //Search! $es_resultset = $index->search($es_query); //Retrieve data $es_results = $es_resultset->getResults(); //Check results if (null == $es_results || empty($es_results)) { $return['query']['search'] = str_replace(' ', '+', $search); return $return; } //Iterate to retrieve all IDs foreach ($es_results as $res) { $typ = $res->getType(); //Save type $types[$typ] = $typ; //Save datas $results[$typ][] = array('id' => $res->getId(), 'score' => $res->getScore(), 'source' => $res->getSource()); } //Get total $total = $es_resultset->getTotalHits(); //Return everything $return = array('query' => array('search' => str_replace(' ', '+', $search), 'type' => $type, 'paged' => $paged, 'perpage' => $perpage), 'total' => $total, 'types' => $types, 'results' => $results); return $return; }
/** * Retrieve field value * * @param array $details Contains field details to build value to retrieve * @param object $default Contains default value in case we dont find any stored value * @param string $id Contains field ID * @param boolean $multiple Define if the stored value is an array or not * * @return string|integer|array|object|boolean|null * * @since 3.3.0 */ public static function getFieldValue($details, $default, $id = '', $multiple = false) { //Build details $post = isset($details['post']) ? $details['post'] : 0; $prefix = isset($details['prefix']) ? $details['prefix'] : ''; $termid = isset($details['term_id']) ? $details['term_id'] : 0; $structure = isset($details['structure']) ? $details['structure'] : ''; //Post types if (!empty($post)) { $value = get_post_meta($post->ID, $post->post_type . '-' . $id, !$multiple); $value = empty($value) ? $default : $value; } else { if (preg_match('/^tto-configs-/', $id)) { //Update option from tto_configs_frontend_login into frontend_login $option = $prefix . $id; $id = str_replace('tto-configs-', '', $id); //Check id[suboption] if (preg_match('/\\[.*\\]/', $id)) { //Get option $option = substr($id, 0, strpos($id, '[')); //Get suboption $suboption = substr($id, strpos($id, '[')); $suboption = str_replace(array('[', ']'), '', $suboption); //Get value $vals = TeaThemeOptions::getConfigs($option); $value = !$vals ? $default : (isset($vals[$suboption]) ? $vals[$suboption] : $default); } else { //Get value $value = TeaThemeOptions::getConfigs($id); $value = !$value ? $default : $value; } } else { if (function_exists('get_term_meta') && !empty($prefix) && !empty($termid)) { $value = get_term_meta($termid, $prefix . '-' . $id, true); $value = !$value ? $default : $value; } else { $option = !empty($prefix) ? str_replace(array('%TERM%', '%SLUG%'), array($prefix, $id), $structure) : $id; $value = TeaThemeOptions::getOption($option, $default); } } } //Strip slasches? return $multiple || is_array($value) ? $value : stripslashes($value); }
/** * Register post type * * @param array $posttype Contains all posttype details * @return array $posttype * @uses register_post_type() * * @since 3.3.0 */ public function registerPostType($posttype = array()) { //Check post types if (empty($posttype)) { return array(); } //Check slug if (!isset($posttype['slug']) || empty($posttype['slug'])) { return array(); } //Store slug $slug = $posttype['slug']; //Special case: define a post/page as title //to edit default post/page component if (in_array($slug, array('post', 'page'))) { return array(); } //Check if post type already exists if (post_type_exists($slug)) { return array(); } //Build labels $labels = $this->defineLabels($posttype['labels']); //Build args $args = $this->defineArgs($posttype); $args['labels'] = $labels; //Action to register register_post_type($slug, $args); //Update post type $posttype = array_merge($posttype, $args); //Option $opt = str_replace('%SLUG%', $slug, Engine::getPermalink()); //Get value $structure = TeaThemeOptions::getOption($opt, '/%' . $slug . '%-%post_id%'); //Change structure add_rewrite_tag('%' . $slug . '%', '([^/]+)', $slug . '='); add_permastruct($slug, $structure, false); return array($posttype, $slug); }