예제 #1
0
 public function get_tax_sql_cached($post_table_name, $type)
 {
     if (!empty($this->tax_sql_cache[$post_table_name])) {
         return $this->tax_sql_cache[$post_table_name][$type];
     }
     $this->tax_sql_cache[$post_table_name] = get_tax_sql(array(array('taxonomy' => $this->taxonomy_name, 'terms' => $this->current_language->term_id, 'field' => 'term_id')), $post_table_name, 'ID');
     return $this->tax_sql_cache[$post_table_name][$type];
 }
 /**
  * Generate Movie Grid
  * 
  * If a current letter is passed to the query use it to narrow
  * the list of movies.
  * 
  * @since    2.0
  * 
  * @param    array       Shortcode arguments to use as parameters
  * @param    boolean     Are we actually doing a Shortcode?
  * 
  * @return   string    HTML content
  */
 public static function get_content($args = array(), $shortcode = false)
 {
     global $wpdb, $wp_query;
     $defaults = array('columns' => wpmoly_o('movie-archives-grid-columns', $default = true), 'rows' => wpmoly_o('movie-archives-grid-rows', $default = true), 'paged' => 1, 'category' => null, 'tag' => null, 'collection' => null, 'actor' => null, 'genre' => null, 'meta' => null, 'detail' => null, 'value' => null, 'title' => false, 'year' => false, 'rating' => false, 'letter' => null, 'order' => wpmoly_o('movie-archives-movies-order', $default = true), 'orderby' => 'post_title', 'view' => 'grid');
     $args = wp_parse_args($args, $defaults);
     // Allow URL params to override Shortcode settings
     $_args = WPMOLY_Archives::parse_query_vars($wp_query->query);
     $args = wp_parse_args($_args, $args);
     // debug
     $main_args = $args;
     extract($args, EXTR_SKIP);
     $total = 0;
     $grid_meta = (array) wpmoly_o('movie-archives-movies-meta', $default = true);
     $grid_meta = array_keys($grid_meta['used']);
     $title = $title || in_array('title', $grid_meta);
     $rating = $rating || in_array('rating', $grid_meta);
     $year = $year || in_array('year', $grid_meta);
     $views = array('grid', 'archives', 'list');
     if ('1' == wpmoly_o('rewrite-enable')) {
         $views = array('grid' => __('grid', 'wpmovielibrary'), 'archives' => __('archives', 'wpmovielibrary'), 'list' => __('list', 'wpmovielibrary'));
     }
     if (!isset($views[$view])) {
         $_view = array_search($view, $views);
         if (false != $_view) {
             $view = $_view;
         } else {
             $view = 'grid';
         }
     }
     $movies = array();
     $total = wp_count_posts('movie');
     $total = $total->publish;
     $select = array('SQL_CALC_FOUND_ROWS DISTINCT ID');
     // Limit the maximum number of terms to get
     $number = $columns * $rows;
     $limit = wpmoly_o('movie-archives-movies-limit', $default = true);
     if (-1 == $number) {
         $number = $limit;
     }
     $columns = min($columns, 8);
     if (0 > $columns) {
         $columns = wpmoly_o('movie-archives-grid-columns', $default = true);
     }
     $rows = min($rows, 12);
     if (0 > $rows) {
         $rows = wpmoly_o('movie-archives-grid-rows', $default = true);
     }
     // Calculate offset
     $offset = 0;
     if ($paged) {
         $offset = max(0, $number * ($paged - 1));
     }
     if ('' == $meta && '' != $detail) {
         $meta = $detail;
         $type = 'detail';
     } else {
         $type = 'meta';
     }
     // Don't use LIMIT with weird values
     $limit = "LIMIT 0,{$number}";
     if ($offset >= $number) {
         $limit = sprintf('LIMIT %d,%d', $offset, $number);
     }
     $where = array("post_type='movie'", " AND post_status='publish'");
     if ('' != $letter) {
         $where[] = " AND post_title LIKE '" . wpmoly_esc_like($letter) . "%'";
     }
     $join = array();
     $meta_query = array('join' => array(), 'where' => array());
     if ('' != $value && '' != $meta) {
         $meta_query = call_user_func("WPMOLY_Search::by_{$meta}", $value, 'sql');
         $join[] = $meta_query['join'];
         $where[] = $meta_query['where'];
     }
     $tax_query = array();
     if (!is_null($collection) && !empty($collection)) {
         $tax_query = array('taxonomy' => 'collection', 'terms' => $collection);
     } elseif (!is_null($genre) && !empty($genre)) {
         $tax_query = array('taxonomy' => 'genre', 'terms' => $genre);
     } elseif (!is_null($actor) && !empty($actor)) {
         $tax_query = array('taxonomy' => 'actor', 'terms' => $actor);
     } elseif (!is_null($category) && !empty($category)) {
         $tax_query = array('taxonomy' => 'category', 'terms' => $category);
     } elseif (!is_null($tag) && !empty($tag)) {
         $tax_query = array('taxonomy' => 'post_tag', 'terms' => $tag);
     }
     if (!empty($tax_query)) {
         $tax_query = array('relation' => 'OR', array('taxonomy' => $tax_query['taxonomy'], 'field' => 'slug', 'terms' => $tax_query['terms']), array('taxonomy' => $tax_query['taxonomy'], 'field' => 'name', 'terms' => $tax_query['terms']));
         $tax_query = get_tax_sql($tax_query, $wpdb->posts, 'ID');
         $join[] = $tax_query['join'];
         $where[] = $tax_query['where'];
     }
     $_orderby = array('year' => 'release_date', 'date' => 'release_date', 'localdate' => 'local_release_date', 'rating' => 'rating');
     if (in_array($orderby, array_keys($_orderby))) {
         $select[] = ' pm.meta_value AS value';
         $join[] = ' INNER JOIN wp_postmeta AS pm ON ( wp_posts.ID = pm.post_id )';
         $where[] = ' AND pm.meta_key = "_wpmoly_movie_' . $_orderby[$orderby] . '"';
         $orderby = 'value';
     } elseif ('post_date' == $orderby) {
         $orderby = 'post_date';
     } else {
         $orderby = 'post_title';
     }
     $where = implode('', $where);
     $join = implode('', $join);
     $select = implode(',', $select);
     $query = "SELECT {$select} FROM {$wpdb->posts} {$join} WHERE {$where} ORDER BY {$orderby} {$order} {$limit}";
     $movies = $wpdb->get_col($query);
     $total = $wpdb->get_var('SELECT FOUND_ROWS() AS total');
     $movies = array_map('get_post', $movies);
     if ('list' == $view) {
         $movies = self::prepare_list_view($movies);
     }
     $baseurl = get_permalink();
     /*if ( true === $shortcode ) {
     			$baseurl = get_permalink();
     		} else {
     			$baseurl = get_post_type_archive_link( 'movie' );
     		}*/
     $args = array('order' => $order, 'columns' => $columns, 'rows' => $rows, 'letter' => $letter, 'value' => $value, $type => $meta, 'l10n' => false, 'view' => $view, 'baseurl' => $baseurl);
     $url = WPMOLY_Utils::build_meta_permalink($args);
     // debug
     $permalinks_args = $args;
     global $wp_rewrite;
     $format = '/page/%#%';
     if ('' == $wp_rewrite->permalink_structure) {
         $format = '&paged=%#%';
     }
     $args = array('type' => 'list', 'total' => ceil($total / $number), 'current' => max(1, $paged), 'format' => $url . $format);
     $paginate = WPMOLY_Utils::paginate_links($args);
     $paginate = '<div id="wpmoly-movies-pagination">' . $paginate . '</div>';
     $theme = wp_get_theme();
     if (!is_null($theme->stylesheet)) {
         $theme = ' theme-' . $theme->stylesheet;
     } else {
         $theme = '';
     }
     // debug
     $debug = null;
     if (current_user_can('manage_options') && '1' == wpmoly_o('debug-mode')) {
         $debug = compact('main_args', 'permalinks_args');
     }
     $attributes = compact('movies', 'columns', 'title', 'year', 'rating', 'theme', 'debug');
     $content = self::render_template("movies/grid/{$view}-loop.php", $attributes, $require = 'always');
     $content = $content . $paginate;
     return $content;
 }
예제 #3
0
 /**
  * Get locations of objects.
  *
  * <code>
  * $results = GeoMashupDB::get_object_locations( array( 
  * 	'object_name' => 'user', 
  * 	'minlat' => 30,
  * 	'maxlat' => 40, 
  * 	'minlon' => -106, 
  * 	'maxlat' => -103 ) 
  * );
  * </code>
  * 
  * @since 1.3
  *
  * @param string $query_args Override default args.
  * @return array Array of matching rows.
  */
 public static function get_object_locations($query_args = '')
 {
     global $wpdb;
     $default_args = array('minlat' => null, 'maxlat' => null, 'minlon' => null, 'maxlon' => null, 'radius_km' => null, 'radius_mi' => null, 'map_cat' => null, 'tax_query' => null, 'map_post_type' => 'any', 'object_name' => 'post', 'show_future' => 'false', 'suppress_filters' => false, 'limit' => 0, 'map_offset' => 0);
     $query_args = wp_parse_args($query_args, $default_args);
     // Construct the query
     $object_name = $query_args['object_name'];
     $object_store = self::object_storage($object_name);
     if (empty($object_store)) {
         return null;
     }
     // Giving tables an alias was a mistake, now filters depend on them
     $field_string = "gmlr.object_id, gmlr.geo_date, o.{$object_store['label_column']} as label, gml.*";
     $table_string = "{$wpdb->prefix}geo_mashup_locations gml " . "INNER JOIN {$wpdb->prefix}geo_mashup_location_relationships gmlr " . $wpdb->prepare('ON gmlr.object_name = %s AND gmlr.location_id = gml.id ', $object_name) . "INNER JOIN {$object_store['table']} o ON o.{$object_store['id_column']} = gmlr.object_id";
     $wheres = array();
     $groupby = '';
     $having = '';
     if ('post' == $object_name) {
         $field_string .= ', o.post_author';
         if ($query_args['show_future'] == 'true') {
             $wheres[] = 'post_status in ( \'publish\',\'future\' )';
         } else {
             if ($query_args['show_future'] == 'only') {
                 $wheres[] = 'post_status = \'future\'';
             } else {
                 $wheres[] = 'post_status = \'publish\'';
             }
         }
     } else {
         if ('comment' == $object_name) {
             $wheres[] = 'comment_approved = \'1\'';
         }
     }
     $location_args = wp_array_slice_assoc($query_args, array_keys(GM_Location_Query::get_defaults()));
     $location_query = new GM_Location_Query($location_args);
     // Handle inclusion and exclusion of terms
     if (!empty($query_args['tax_query']) and is_array($query_args['tax_query'])) {
         $tax_query = $query_args['tax_query'];
     } else {
         $tax_query = array();
     }
     if (!empty($query_args['map_cat'])) {
         $cats = preg_split('/[,\\s]+/', $query_args['map_cat']);
         $escaped_include_ids = array();
         $escaped_exclude_ids = array();
         foreach ($cats as $cat) {
             if (is_numeric($cat)) {
                 if ($cat < 0) {
                     $escaped_exclude_ids[] = abs($cat);
                     $escaped_exclude_ids = array_merge($escaped_exclude_ids, get_term_children($cat, 'category'));
                 } else {
                     $escaped_include_ids[] = intval($cat);
                     $escaped_include_ids = array_merge($escaped_include_ids, get_term_children($cat, 'category'));
                 }
             } else {
                 // Slugs might begin with a dash, so we only include them
                 $term = get_term_by('slug', $cat, 'category');
                 if ($term) {
                     $escaped_include_ids[] = $term->term_id;
                     $escaped_include_ids = array_merge($escaped_include_ids, get_term_children($term->term_id, 'category'));
                 }
             }
         }
         if (!empty($escaped_include_ids)) {
             $tax_query[] = array('taxonomy' => 'category', 'terms' => $escaped_include_ids, 'field' => 'term_id');
         }
         if (!empty($escaped_exclude_ids)) {
             $tax_query[] = array('taxonomy' => 'category', 'terms' => $escaped_exclude_ids, 'operator' => 'NOT IN', 'field' => 'term_id');
         }
     }
     // end if map_cat exists
     if (!empty($tax_query)) {
         $tax_clauses = get_tax_sql($tax_query, 'o', $object_store['id_column']);
         $table_string .= $tax_clauses['join'];
         $wheres[] = preg_replace('/^ AND/', '', $tax_clauses['where']);
         $groupby = 'GROUP BY gmlr.object_id';
     }
     if ('post' == $object_name) {
         // Handle inclusion and exclusion of post types
         if ('any' == $query_args['map_post_type']) {
             $include_post_types = '';
             $searchable_post_types = GeoMashup::get_searchable_post_types();
             if (!empty($searchable_post_types)) {
                 $include_post_types .= "o.post_type IN ('" . join("', '", array_map('esc_sql', $searchable_post_types)) . "')";
             }
             $wheres[] = $include_post_types;
         } else {
             if (!is_array($query_args['map_post_type'])) {
                 $query_args['map_post_type'] = preg_split('/[,\\s]+/', $query_args['map_post_type']);
             }
             $wheres[] = "o.post_type IN ('" . join("', '", $query_args['map_post_type']) . "')";
         }
     }
     if (!empty($query_args['object_id'])) {
         $wheres[] = 'gmlr.object_id = ' . esc_sql($query_args['object_id']);
     } else {
         if (!empty($query_args['object_ids'])) {
             $wheres[] = 'gmlr.object_id IN ( ' . esc_sql($query_args['object_ids']) . ' )';
         }
     }
     if (!empty($query_args['exclude_object_ids'])) {
         $wheres[] = 'gmlr.object_id NOT IN ( ' . esc_sql($query_args['exclude_object_ids']) . ' )';
     }
     list($l_cols, $l_join, $l_where, $l_groupby) = $location_query->get_sql('o', $object_store['id_column']);
     $field_string .= $l_cols;
     $table_string .= $l_join;
     if (empty($groupby) and !empty($l_groupby)) {
         $groupby = 'GROUP BY ' . $l_groupby;
     }
     $where = empty($wheres) ? '' : 'WHERE ' . implode(' AND ', $wheres) . $l_where;
     $sort = isset($query_args['sort']) ? $query_args['sort'] : $object_store['sort'];
     $sort = empty($sort) ? '' : 'ORDER BY ' . esc_sql($sort);
     $offset = absint($query_args['map_offset']);
     $limit = absint($query_args['limit']);
     if ($limit or $offset) {
         $limit = " LIMIT {$offset},{$limit}";
     } else {
         $limit = '';
     }
     if (!$query_args['suppress_filters']) {
         $field_string = apply_filters('geo_mashup_locations_fields', $field_string);
         $table_string = apply_filters('geo_mashup_locations_join', $table_string);
         $where = apply_filters('geo_mashup_locations_where', $where);
         $sort = apply_filters('geo_mashup_locations_orderby', $sort);
         $groupby = apply_filters('geo_mashup_locations_groupby', $groupby);
         $limit = apply_filters('geo_mashup_locations_limits', $limit);
         $suppress_post_filters = defined('GEO_MASHUP_SUPPRESS_POST_FILTERS') && GEO_MASHUP_SUPPRESS_POST_FILTERS;
         if ('post' === $object_name and !$suppress_post_filters and isset($GLOBALS['sitepress'])) {
             // Ok, we're catering to WPML here. If we ever integrate with a WP_Query object for posts,
             // this could be made more general
             // This filter will include all translatable post types, I hope
             add_filter('get_translatable_documents', array(__CLASS__, 'wpml_filter_get_translatable_documents'));
             // Apply post query filters, changing posts table references to our alias
             // As of WPML 2.9 these calls can trigger undefined variable notices
             $table_string = $GLOBALS['sitepress']->posts_join_filter($table_string, null);
             $table_string = str_replace($wpdb->posts . '.', 'o.', $table_string);
             $where = $GLOBALS['sitepress']->posts_where_filter($where, null);
             $where = str_replace($wpdb->posts . '.', 'o.', $where);
             remove_filter('get_translatable_documents', array(__CLASS__, 'wpml_filter_get_translatable_documents'));
         }
     }
     $query_string = "SELECT {$field_string} FROM {$table_string} {$where} {$groupby} {$having} {$sort} {$limit}";
     $wpdb->query($query_string);
     return $wpdb->last_result;
 }
예제 #4
0
/**
 * Listing query where clause SQL part for widgets.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @param string $where Where clause SQL.
 * @return string Modified where clause SQL.
 */
function geodir_function_widget_listings_where($where)
{
    global $wpdb, $plugin_prefix, $gd_query_args_widgets;
    $query_args = $gd_query_args_widgets;
    if (empty($query_args) || empty($query_args['is_geodir_loop'])) {
        return $where;
    }
    $post_type = empty($query_args['post_type']) ? 'gd_place' : $query_args['post_type'];
    $table = $plugin_prefix . $post_type . '_detail';
    if (!empty($query_args)) {
        if (!empty($query_args['gd_location']) && function_exists('geodir_default_location_where')) {
            $where = geodir_default_location_where($where, $table);
        }
        if (!empty($query_args['show_featured_only'])) {
            $where .= " AND " . $table . ".is_featured = '1'";
        }
        if (!empty($query_args['show_special_only'])) {
            $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )";
        }
        if (!empty($query_args['with_pics_only'])) {
            $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL ";
        }
        if (!empty($query_args['featured_image_only'])) {
            $where .= " AND " . $table . ".featured_image IS NOT NULL AND " . $table . ".featured_image!='' ";
        }
        if (!empty($query_args['with_videos_only'])) {
            $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )";
        }
        if (!empty($query_args['tax_query'])) {
            $tax_queries = get_tax_sql($query_args['tax_query'], $wpdb->posts, 'ID');
            if (!empty($tax_queries['join']) && !empty($tax_queries['where'])) {
                $where .= $tax_queries['where'];
            }
        }
    }
    return $where;
}
 /**
  * Generated user taxonomy query SQL
  *
  * @since 0.1.0
  *
  * @param  object  $user_query
  */
 public function user_tax_query($user_query = '')
 {
     return get_tax_sql($user_query->tax_query, $GLOBALS['wpdb']->users, 'ID');
 }