Пример #1
0
 /**
  * Get config values.
  *
  * @return array $configs Contains all config values
  *
  * @since 3.3.0
  */
 public static function getConfigs()
 {
     //Build defaults
     $defaults = array('status' => 0, 'server_host' => 'localhost', 'server_port' => '9200', 'index_name' => 'ttosearch', 'read_timeout' => 5, 'write_timeout' => 10, 'template' => 'no', 'posttypes' => array(), 'terms' => array(), 'scores' => array());
     //Return merge values
     return array_merge($defaults, TeaThemeOptions::getConfigs(self::getIndex() . '-data'));
 }
Пример #2
0
 /**
  * Build admin hooks.
  *
  * @since 3.3.0
  */
 public function commonHooks()
 {
     //Get configs
     $modules = TeaThemeOptions::getConfigs('modules');
     if (isset($modules['database']) && $modules['database']) {
         add_action('shutdown', array(&$this, 'hookCloseDbLink'), 99);
     }
     if (isset($modules['customlogin']) && $modules['customlogin']) {
         add_action('login_head', array(&$this, 'hookLoginPage'));
     }
 }
Пример #3
0
 /**
  * Build admin hooks.
  *
  * @since 3.3.0
  */
 public function makeHooks()
 {
     //Admin panel
     if (!TTO_IS_ADMIN) {
         return;
     }
     //i18n
     $locale = apply_filters('theme_locale', get_locale(), TTO_I18N);
     load_textdomain(TTO_I18N, TTO_PATH . '/languages/' . $locale . '.mo');
     //Add custom CSS colors ~ Earth
     wp_admin_css_color('teatocss-earth', TeaThemeOptions::__('Tea T.O. ~ Earth'), TTO_URI . '/assets/css/teato.admin.earth.css?ver=v' . TTO_VERSION_NUM, array('#222', '#303231', '#55bb3a', '#91d04d'));
     //Add custom CSS colors ~ Ocean
     wp_admin_css_color('teatocss-ocean', TeaThemeOptions::__('Tea T.O. ~ Ocean'), TTO_URI . '/assets/css/teato.admin.ocean.css?ver=v' . TTO_VERSION_NUM, array('#222', '#303231', '#3a80bb', '#4d9dd0'));
     //Add custom CSS colors ~ Vulcan
     wp_admin_css_color('teatocss-vulcan', TeaThemeOptions::__('Tea T.O. ~ Vulcan'), TTO_URI . '/assets/css/teato.admin.vulcan.css?ver=v' . TTO_VERSION_NUM, array('#222', '#303231', '#bb3a3a', '#d04d4d'));
     //Add custom CSS colors ~ Wind
     wp_admin_css_color('teatocss-wind', TeaThemeOptions::__('Tea T.O. ~ Wind'), TTO_URI . '/assets/css/teato.admin.wind.css?ver=v' . TTO_VERSION_NUM, array('#222', '#303231', '#69d2e7', '#a7dbd8'));
     //Hooks
     add_action('admin_menu', array(&$this, 'hookAssets'), 999);
     //Get configs
     $hooks = TeaThemeOptions::getConfigs('backendhooks');
     $modules = TeaThemeOptions::getConfigs('modules');
     if (isset($hooks['emojicons']) && $hooks['emojicons']) {
         add_action('init', array(&$this, 'hookDisableWPEmojicons'));
     }
     if (isset($hooks['versioncheck']) && $hooks['versioncheck']) {
         add_action('after_setup_theme', array(&$this, 'hookRemoveAdminWPVersionCheck'));
     }
     if (isset($hooks['baricons']) && $hooks['baricons']) {
         add_action('wp_before_admin_bar_render', array(&$this, 'hookRemoveBarIcons'));
     }
     if (isset($hooks['menus']) && $hooks['menus']) {
         add_action('admin_menu', array(&$this, 'hookRemoveMenus'));
     }
     if (isset($modules['sanitizedfilename']) && $modules['sanitizedfilename']) {
         add_filter('sanitize_file_name', array(&$this, 'hookSanitizeFilename'), 10);
     }
 }
Пример #4
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);
 }
Пример #5
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'));
         }
     }
 }
Пример #6
0
 /**
  * Build default contents.
  *
  * @uses current_user_can()
  * @todo other 3rd-party modules
  *
  * @since 3.3.0
  */
 protected function initialize()
 {
     //Admin panel
     if (!TTO_IS_ADMIN) {
         return;
     }
     //Check identifier
     if (empty($this->identifier)) {
         TeaThemeOptions::notify('error', TeaThemeOptions::__('Something went wrong in your parameters
             definition. You need at least an identifier.'));
         return;
     }
     //Get current user capabilities
     $canuser = current_user_can(TTO_WP_CAP_MAX);
     $contents = array();
     //Build page with contents
     $ttoquote = TTO_QUOTE;
     $settingslink = admin_url('admin.php?page=' . $this->identifier . '-settings');
     include ME_TPL_DASHBOARD;
     $contents[] = $configs;
     //Options
     $thirdsearch = $thirdrelated = $thirdcomments = $thirdnetworks = false;
     //Settings page's contents
     if ($this->identifier . '-settings' === $this->currentPage) {
         //Get modules
         $thirdcomments = TeaThemeOptions::getConfigs('3rd-comments');
         $thirdnetworks = TeaThemeOptions::getConfigs('3rd-networks');
         $thirdrelated = TeaThemeOptions::getConfigs('3rd-related');
         $thirdsearch = TeaThemeOptions::getConfigs('3rd-search');
     }
     //Build page with contents
     include ME_TPL_SETTINGS;
     $contents[] = $configs;
     /**
      * Add extra pages.
      *
      * @param array $contents
      * @param boolean $canuser
      * @return array $contents
      *
      * @since 3.2.0
      */
     $contents = apply_filters('tto_menu_engine_initialize', $contents, $canuser);
     //Iterate on all contents
     foreach ($contents as $s => $ctn) {
         $this->addMenu($ctn);
     }
 }
Пример #7
0
 /**
  * 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);
 }
Пример #8
0
 /**
  * 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) {
     }
 }
Пример #9
0
 /**
  * Build admin hooks.
  *
  * @since 3.0.0
  */
 public function makeHooks()
 {
     //Admin panel
     if (TTO_IS_ADMIN) {
         return;
     }
     //Get configs
     $hooks = TeaThemeOptions::getConfigs('frontendhooks');
     //Auto-generated tags
     if (isset($hooks['generated']) && $hooks['generated']) {
         //Remove admin bar since v3.1
         add_filter('show_admin_bar', '__return_false');
         remove_action('init', 'wp_admin_bar_init');
         //Remove automatic feed links since WP v.3.x
         remove_theme_support('automatic-feed-links');
         //Remove feed links
         //<link rel="alternate" type="application/rss+xml" title="__SITE_NAME__ &raquo; Comments Feed" href="__SITE_URL__/comments/feed/" />
         remove_action('wp_head', 'feed_links', 2);
         //Remove extra feed links, such as categories, tags, etc.
         //<link rel="alternate" type="application/rss+xml" title="__SITE_NAME__ &raquo; Comments Feed" href="__SITE_URL__/category/__CAT__/feed/" />
         remove_action('wp_head', 'feed_links_extra', 3);
         //Remove WORDPRESS version.
         //<meta name="generator" content="WordPress __WP_VERSION__" />
         remove_action('wp_head', 'wp_generator');
         //Link to adjacent posts.
         //<link rel="prev" title="adjacent_posts_rel_link" href="__SITE_URL__" />
         remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
         //Link to blog index.
         //<link rel="index" title="__SITE_NAME__" href="__SITE_URL__" />
         remove_action('wp_head', 'index_rel_link');
         //Really Simple Discovery support.
         //<link rel="EditURI" type="application/rsd+xml" title="RSD" href="__SITE_URL__" />
         remove_action('wp_head', 'rsd_link');
         //Remove Shortlink Link Rel Hook
         remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
         //Windows Live Writter support.
         //<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="__SITE_URL__" />
         remove_action('wp_head', 'wlwmanifest_link');
         //Others
         remove_action('wp_head', 'parent_post_rel_link', 10, 0);
         remove_action('wp_head', 'start_post_rel_link', 10, 0);
         //Remove i18n styles
         remove_action('wp_head', 'wp_dlmp_l10n_style');
         //Shortcodes
         remove_filter('the_content', 'wpautop');
         remove_filter('the_content', 'wptexturize');
     }
     //Hooks
     if (isset($hooks['bodyclass']) && $hooks['bodyclass']) {
         add_filter('body_class', array(&$this, 'hookCleanBodyClass'), 10, 2);
     }
     if (isset($hooks['emojicons']) && $hooks['emojicons']) {
         add_action('init', array(&$this, 'hookDisableWPEmojicons'));
     }
     if (isset($hooks['version']) && $hooks['version']) {
         add_filter('the_generator', array(&$this, 'hookRemoveVersion'));
     }
     if (isset($hooks['shortcodeformatter']) && $hooks['shortcodeformatter']) {
         add_filter('the_content', array(&$this, 'hookShortcodeFormatter'), 99);
     }
 }
Пример #10
0
 /**
  * Create roles and capabilities.
  *
  * @since 3.3.0
  */
 protected function updateFooter($make = 'capabilities')
 {
     //Admin panel
     if (!TTO_IS_ADMIN) {
         return;
     }
     //Update capabilities
     if ('capabilities' === $make) {
         //Get global WP roles
         global $wp_roles;
         //Check them
         if (class_exists('WP_Roles')) {
             $wp_roles = !isset($wp_roles) ? new WP_Roles() : $wp_roles;
         }
         if (!is_object($wp_roles)) {
             return;
         }
         //Add custom role
         $wp_roles->add_cap('administrator', TTO_WP_CAP_MAX);
         //Update DB
         TeaThemeOptions::setConfigs('capabilities', true);
     } elseif ('posttypes' === $make || 'terms' === $make) {
         //Get post type's index
         $index = 'posttypes' === $make ? PostTypeEngine::getIndex() : TermEngine::getIndex();
         //Get all registered pages
         $contents = TeaThemeOptions::getConfigs($index);
         //Check params and if a master page already exists
         if (!empty($contents)) {
             //Delete configurations to built them back
             TeaThemeOptions::setConfigs($index, array());
         }
         //Flush all rewrite rules
         flush_rewrite_rules();
     }
     //Redirect to Tea TO homepage
     wp_safe_redirect(admin_url('admin.php?page=' . $this->identifier . '&do=tto-action&from=dashboard'));
 }
Пример #11
0
 /**
  * Create the index for all datas.
  *
  * @param array $request Contains all data sent in $_REQUEST method
  *
  * @since 3.0.0
  */
 public function makeCreate($request)
 {
     //Admin panel
     if (!TTO_IS_ADMIN) {
         return;
     }
     //Get index
     $index = Search::getIndex();
     //Get enable
     $enable = TeaThemeOptions::getConfigs($index, false);
     //Check if this action was properly called
     if (!$enable) {
         return;
     }
     //Get contents
     $status = TeaThemeOptions::getConfigs($index . '-status', 0);
     //Check status
     if (200 === $status) {
         //We do not need to create the Index
         return;
     }
     //Create new occurrence
     $this->search->getEngine()->makeSearch();
     //Get Connection status
     $status = $this->search->getEngine()->connection();
     //Define data in DB
     TeaThemeOptions::setConfigs($index . '-status', $status);
 }