Ejemplo n.º 1
0
        public static function print_theme_landing_page_field()
        {
            $field_name = 'theme_landing_page';
            printf('<select id="%1$s" name="nelioab_settings[%1$s]" %2$s>', $field_name, self::get_basic_details());
            ?>
				<option value='0'><?php 
            _e('Regular Front Page («Latest Posts» or «Static Page»)', 'nelioab');
            ?>
</option>
				<option value='1'<?php 
            if (NelioABSettings::does_theme_use_a_custom_landing_page()) {
                echo ' selected="selected"';
            }
            ?>
><?php 
            _e('Theme-based Front Page', 'nelioab');
            ?>
</option>
			</select>
			<div class="the-descr" style="display:none;"><span class="description"><?php 
            printf(__('As stated in the <a href="%s">WordPress Codex</a>, by default WordPress shows your most recent posts in reverse chronological order on the front page (also known as "landing page") of your site. If you want a static front page or splash page as the front page instead, you may select it using the "Front page display" setting Dashboard » Settings » Reading.<br>Some themes, however, define "dynamic front pages", which can not be A/B tested by Nelio. If you want to track Heatmaps for such a front page, simply select "Theme-based Front Page". ', 'nelioab'), 'http://codex.wordpress.org/Creating_a_Static_Front_Page');
            ?>
</span></div><?php 
        }
Ejemplo n.º 2
0
 /**
  * This function is an AJAX callback that looks for posts.
  *
  * It returns a list of up to 20 posts (or pages). It is used by the
  * select2 widget (an item selector that looks more beautiful than regular
  * the "select>option" combo.
  *
  * Accepted POST params are:
  *
  * * term: {string} the (part of the) string used to look for items.
  * * type: {array}  array containing the types of element are we looking.
  * * default_id: {int} (optional) if set, the item with that ID will be
  * returned. If that item is not found, then we'll perform a regular search
  * (as if the param had not been set).
  *
  * @return array a list of matching posts.
  *
  * @since PHPDOC
  */
 public static function search_posts()
 {
     $term = false;
     if (isset($_POST['term']) & !empty($_POST['term'])) {
         $term = $_POST['term'];
     }
     $types = array();
     if (isset($_POST['type'])) {
         $types = $_POST['type'];
     }
     if (!is_array($types)) {
         $types = array($types);
     }
     $status = 'publish';
     if (isset($_POST['drafts']) && 'show-drafts' == $_POST['drafts']) {
         $status = array('publish', 'draft');
     }
     $default_id = false;
     if (isset($_POST['default_id'])) {
         $default_id = $_POST['default_id'];
     }
     if ($default_id == -1) {
         $default_id = false;
     }
     $default_thumbnail = sprintf('<img src="data:image/gif;%s" class="%s" alt="%s" />', 'base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'attachment-thumbnail wp-post-image nelioab-no-thumbnail', __('No featured image available', 'nelioab'));
     $args = array('post_title_like' => $term, 'posts_per_page' => 20, 'meta_key' => '_is_nelioab_alternative', 'meta_compare' => 'NOT EXISTS', 'post_status' => $status);
     if (count($types) > 0) {
         $aux = array();
         foreach ($types as $type) {
             if (strpos($type, 'nelioab-') === false) {
                 array_push($aux, $type);
             }
         }
         foreach ($types as $type) {
             if ('nelioab-all-post-types' == $type) {
                 array_push($aux, 'page');
                 array_push($aux, 'post');
                 foreach (NelioABWpHelper::get_custom_post_types() as $cpt) {
                     array_push($aux, $cpt->name);
                 }
             }
         }
         if (count($aux) > 0) {
             $args['post_type'] = $aux;
         }
     }
     if ($types && count($types) == 1 && 'page' === $types[0] && !$term) {
         $args['order'] = 'asc';
         $args['orderby'] = 'title';
     }
     $latest_post_item = false;
     if (in_array('nelioab-latest-posts', $types) || false !== $default_id) {
         $lp_title = __('Your latest posts', 'nelioab');
         if (!$term || strpos(strtolower($lp_title), strtolower($term)) !== false) {
             $latest_post_item = array('id' => NelioABController::FRONT_PAGE__YOUR_LATEST_POSTS, 'type' => '<i>latest-posts</i>', 'title' => self::fix_title($lp_title), 'status' => '<i>dynamic</i>', 'date' => '', 'author' => 'WordPress', 'thumbnail' => $default_thumbnail);
         }
     }
     $theme_based_landing_page = false;
     if (in_array('nelioab-theme-landing-page', $types) && NelioABSettings::does_theme_use_a_custom_landing_page() || NelioABController::FRONT_PAGE__THEME_BASED_LANDING == $default_id) {
         $lp_title = __('Landing Page (Theme-based)', 'nelioab');
         if (!$term || strpos(strtolower($lp_title), strtolower($term)) !== false) {
             $theme_based_landing_page = array('id' => NelioABController::FRONT_PAGE__THEME_BASED_LANDING, 'type' => '<i>landing-page</i>', 'title' => self::fix_title($lp_title), 'status' => '<i>dynamic</i>', 'date' => '', 'author' => 'WordPress', 'thumbnail' => $default_thumbnail);
         }
     }
     // If there's a default_id set, it means that the user is interested
     // in one post only; I'm going to return that post to him
     if ($default_id !== false) {
         $id = $default_id;
         $post = false;
         if ($id == NelioABController::FRONT_PAGE__YOUR_LATEST_POSTS) {
             header('Content-Type: application/json');
             echo json_encode(array($latest_post_item));
             die;
         }
         if ($id == NelioABController::FRONT_PAGE__THEME_BASED_LANDING) {
             header('Content-Type: application/json');
             echo json_encode(array($theme_based_landing_page));
             die;
         }
         if ($id > 0) {
             $post = get_post($id);
         }
         if ($post) {
             $thumbnail = get_the_post_thumbnail($post->ID, 'thumbnail');
             if ($thumbnail === '') {
                 $thumbnail = $default_thumbnail;
             }
             $item = array('id' => $post->ID, 'title' => self::fix_title($post->post_title), 'thumbnail' => $thumbnail, 'excerpt' => $post->post_excerpt);
             header('Content-Type: application/json');
             echo json_encode(array($item));
             die;
         }
     }
     $result = array();
     add_filter('posts_where', array('NelioABWpHelper', 'add_title_filter_to_wpquery'), 10, 2);
     $my_query = new WP_Query($args);
     remove_filter('posts_where', array('NelioABWpHelper', 'add_title_filter_to_wpquery'), 10, 2);
     if ($my_query->have_posts()) {
         global $post;
         while ($my_query->have_posts()) {
             $my_query->the_post();
             $thumbnail = get_the_post_thumbnail($post->ID, 'thumbnail');
             if ($thumbnail === '') {
                 $thumbnail = $default_thumbnail;
             }
             $item = array('id' => $post->ID, 'type' => $post->post_type, 'title' => self::fix_title($post->post_title), 'status' => $post->post_status, 'date' => $post->post_date, 'excerpt' => $post->post_excerpt, 'author' => get_the_author(), 'thumbnail' => $thumbnail);
             array_push($result, $item);
         }
     }
     if ($latest_post_item) {
         array_unshift($result, $latest_post_item);
     }
     if ($theme_based_landing_page) {
         array_unshift($result, $theme_based_landing_page);
     }
     header('Content-Type: application/json');
     echo json_encode($result);
     die;
 }