Exemplo n.º 1
0
/**
 * Are we on Sitewide gallery page?
 * 
 * @return boolean
 */
function mpp_is_sitewide_gallery_component()
{
    if (is_singular(mpp_get_gallery_post_type()) && mpp_is_sitewide_gallery(get_queried_object_id())) {
        return true;
    }
    return false;
}
Exemplo n.º 2
0
/**
 * Check if we are on the Dashboard->Gallery listing page
 * 
 * @return boolean
 */
function mpp_admin_is_gallery_list()
{
    $screen_id = 'edit-' . mpp_get_gallery_post_type();
    if (is_admin() && !defined('DOING_AJAX') && function_exists('get_current_screen') && get_current_screen()->id == $screen_id) {
        return true;
    }
    return false;
}
Exemplo n.º 3
0
 /**
  * Update the global $post with dummy data
  *
  * @since BuddyPress (1.7)
  */
 public function dummy_post()
 {
     // Registration page
     if (mpp_is_gallery_directory()) {
         $title = __('Gallery Directory', 'mediapress');
     }
     bp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bp_get_directory_title('mediapress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => mpp_get_gallery_post_type(), 'post_status' => 'publish', 'is_page' => true, 'comment_status' => 'closed'));
 }
Exemplo n.º 4
0
/**
 * Filter get_permalink for mediapress gallery post type( mpp-gallery)
 * aand make it like site.com/members/username/mediapressslug/gallery-name or site.com/{component-page}/{single-component}/mediapress-slug/gallery-name
 * It allows us to get the permalink to gallery by using the_permalink/get_permalink functions
 */
function mpp_filter_gallery_permalink($permalink, $post, $leavename, $sample)
{
    if (mpp_get_gallery_post_type() != $post->post_type) {
        return $permalink;
    }
    $gallery = mpp_get_gallery($post);
    $slug = $gallery->slug;
    $base_url = mpp_get_gallery_base_url($gallery->component, $gallery->component_id);
    return apply_filters('mpp_get_gallery_permalink', $base_url . '/' . $slug, $gallery);
}
Exemplo n.º 5
0
 public function register_taxonomies()
 {
     //register type
     //register status
     // register component
     $this->register_taxonomy(mpp_get_type_taxname(), array('label' => _x('Media Type', 'Gallery Media Type', 'mediapress'), 'labels' => _x('Media Types', 'Gallery Media Type Plural Name', 'mediapress'), 'hierarchical' => false));
     $this->register_taxonomy(mpp_get_component_taxname(), array('label' => _x('Component', 'Gallery Associated Type', 'mediapress'), 'labels' => _x('Components', 'Gallery Associated Component Plural Name', 'mediapress'), 'hierarchical' => false));
     $this->register_taxonomy(mpp_get_status_taxname(), array('label' => _x('Gallery Status', 'Gallery privacy/status Type', 'mediapress'), 'labels' => _x('Galery Statuses', 'Gallery Privacy Plural Name', 'mediapress'), 'hierarchical' => false));
     register_taxonomy_for_object_type(mpp_get_type_taxname(), mpp_get_gallery_post_type());
     register_taxonomy_for_object_type(mpp_get_component_taxname(), mpp_get_gallery_post_type());
     register_taxonomy_for_object_type(mpp_get_status_taxname(), mpp_get_gallery_post_type());
     register_taxonomy_for_object_type(mpp_get_type_taxname(), mpp_get_media_post_type());
     register_taxonomy_for_object_type(mpp_get_component_taxname(), mpp_get_media_post_type());
     register_taxonomy_for_object_type(mpp_get_status_taxname(), mpp_get_media_post_type());
 }
Exemplo n.º 6
0
/**
 * Check if we are on the Dashboard->Gallery listing page
 * 
 * @return boolean
 */
function mpp_admin_is_gallery_list()
{
    $screen_id = 'edit-' . mpp_get_gallery_post_type();
    //on ajax request, shortcircuit
    if (defined('DOING_AJAX')) {
        return false;
    }
    if (is_admin() && function_exists('get_current_screen')) {
        $screen = get_current_screen();
        if (isset($screen->id) && $screen->id == $screen_id) {
            return true;
        }
    }
    return false;
}
 /**
  * Load the MediaPress js files/codes  
  * 
  */
 public function load_js()
 {
     //use it to avoid loading mediapress js where not required
     if (!apply_filters('mpp_load_js', true)) {
         return;
         //is this  a good idea? should we allow this?
     }
     //we can further refine it in future to only load a part of it on the pages, depending on current context and user state
     //for now, let us keep it all together
     //Uploader class
     wp_register_script('mpp_uploader', $this->url . 'assets/js/uploader.js', array('plupload', 'plupload-all', 'jquery', 'underscore', 'json2', 'media-models'));
     //'plupload-all'
     //popup
     wp_register_script('magnific-js', $this->url . 'assets/vendors/magnific/jquery.magnific-popup.min.js', array('jquery'));
     //'plupload-all'
     //comment+posting activity on single gallery/media page
     wp_register_script('mpp_activity', $this->url . 'assets/js/activity.js', array('jquery'));
     //'plupload-all'
     //everything starts here
     wp_register_script('mpp_core', $this->url . 'assets/js/mpp.js', array('jquery', 'jquery-ui-sortable'));
     wp_register_script('mpp_settings_uploader', $this->url . 'admin/mpp-settings-manager/core/_inc/uploader.js', array('jquery'));
     //we have to be selective about admin only? we always load it on front end
     //do not load on any admin page except the edit gallery?
     if (is_admin() && function_exists('get_current_screen') && get_current_screen()->post_type != mpp_get_gallery_post_type()) {
         return;
     }
     wp_enqueue_script('mpp_uploader');
     //load lightbox only on edit gallery page or not admin
     if (!is_admin()) {
         //only load the lightbox if it is enabled in the admin settings
         if (mpp_get_option('load_lightbox')) {
             wp_enqueue_script('magnific-js');
         }
         wp_enqueue_script('mpp_activity');
     }
     wp_enqueue_script('mpp_core');
     //we only need these to be loaded for activity page, should we put a condition here?
     wp_enqueue_style('wp-mediaelement');
     wp_enqueue_script('wp-mediaelement');
     //force wp to load _js template for the playlist and the code to
     do_action('wp_playlist_scripts');
     //may not be a good idea
     $this->defult_settings();
     $this->plupload_localize();
     $this->localize_strings();
 }
Exemplo n.º 8
0
function mpp_filter_archive_page_galleries($query)
{
    if (is_admin()) {
        return;
    }
    if (!$query->is_main_query() || !$query->is_post_type_archive(mpp_get_gallery_post_type())) {
        return;
    }
    //confirmed that we are on gallery archive page
    $active_components = mpp_get_active_components();
    $active_types = mpp_get_active_types();
    $status = 'public';
    $tax_query = $query->get('tax_query');
    if (empty($tax_query)) {
        $tax_query = array();
    }
    //it will be always true
    if ($status) {
        $status = mpp_string_to_array($status);
        //future proofing
        $status_keys = array_map('mpp_underscore_it', $status);
        $tax_query[] = array('taxonomy' => mpp_get_status_taxname(), 'field' => 'slug', 'terms' => $status_keys, 'operator' => 'IN');
    }
    //should we only show sitewide galleries here? will update based on feedback
    if (!empty($active_components)) {
        $component_keys = array_keys($active_components);
        $component_keys = array_map('mpp_underscore_it', $component_keys);
        $tax_query[] = array('taxonomy' => mpp_get_component_taxname(), 'field' => 'slug', 'terms' => $component_keys, 'operator' => 'IN');
    }
    if (!empty($active_types)) {
        $type_keys = array_keys($active_types);
        $type_keys = array_map('mpp_underscore_it', $type_keys);
        $tax_query[] = array('taxonomy' => mpp_get_type_taxname(), 'field' => 'slug', 'terms' => $type_keys, 'operator' => 'IN');
    }
    if (count($tax_query) > 1) {
        $tax_query['relation'] = 'AND';
    }
    $query->set('tax_query', $tax_query);
    $query->set('update_post_term_cache', true);
    $query->set('update_post_meta_cache', true);
    $query->set('cache_results', true);
}
Exemplo n.º 9
0
/**
 * Filter get_permalink for mediapress gallery post type( mpp-gallery)
 * aand make it like site.com/members/username/mediapressslug/gallery-name or site.com/{component-page}/{single-component}/mediapress-slug/gallery-name
 * It allows us to get the permalink to gallery by using the_permalink/get_permalink functions
 */
function mpp_filter_gallery_permalink($permalink, $post, $leavename, $sample)
{
    //check if BuddyPress is active, if not, we don't filter it yet
    //lightweight check
    if (!mediapress()->is_bp_active()) {
        return $permalink;
    }
    //a little more expensive
    if (mpp_get_gallery_post_type() != $post->post_type) {
        return $permalink;
    }
    //this is expensive if the post is not cached
    //If you see too many queries, just make sure to call _prime_post_caches($ids, true, true ); where $ids is collection of post ids
    //that will save a lot of query
    $gallery = mpp_get_gallery($post);
    // do not modify permalinks for Sitewide gallery
    if ($gallery->component == 'sitewide') {
        return $permalink;
    }
    $slug = $gallery->slug;
    $base_url = mpp_get_gallery_base_url($gallery->component, $gallery->component_id);
    return apply_filters('mpp_get_gallery_permalink', $base_url . '/' . $slug, $gallery);
}
Exemplo n.º 10
0
/**
 * Are we on a root gallry page
 * 
 * @return type
 */
function mpp_is_root_gallery()
{
    $is_gallery = false;
    if (mpp_is_root_enabled() && is_singular(mpp_get_gallery_post_type())) {
        $is_gallery = true;
    }
    return apply_filters('mpp_is_root_gallery', $is_gallery);
}
 /**
  * Handle http://site.com/gallery/xyzgallery/page/{page_number}/
  * @param type $redirect_url
  * @param type $requested_url
  * @return type
  */
 public function redirect_canonical($redirect_url, $requested_url)
 {
     if (is_singular(mpp_get_gallery_post_type()) && get_query_var('paged')) {
         return $requested_url;
     }
     return $redirect_url;
 }
Exemplo n.º 12
0
 private function __construct()
 {
     $this->menu_slug = 'edit.php?post_type=' . mpp_get_gallery_post_type();
 }
Exemplo n.º 13
0
function mpp_get_adjacent_object_id($args, $post_type)
{
    global $wpdb;
    $post_type_sql = '';
    $sql = array();
    $default = array('component' => '', 'component_id' => false, 'status' => mpp_get_accessible_statuses(mpp_get_current_component(), mpp_get_current_component_id()), 'type' => '', 'post_status' => 'any', 'next' => true, 'object_id' => '', 'object_parent' => 0);
    if ($post_type == mpp_get_gallery_post_type()) {
        $default['post_status'] = 'publish';
        //for gallery, the default post type should be published status
    }
    //if component is set to user, we can simply avoid component query
    //may be next iteration someday
    $args = wp_parse_args($args, $default);
    extract($args);
    //whether we are looking for next post or previous post
    if ($next) {
        $op = '>';
    } else {
        $op = '<';
    }
    //do we have a component set
    if ($component) {
        $sql[] = mpp_get_tax_sql($component, mpp_get_component_taxname());
    }
    //do we have a component set
    if ($status) {
        $sql[] = mpp_get_tax_sql($status, mpp_get_status_taxname());
    }
    //for type, repeat it
    if ($type) {
        $sql[] = mpp_get_tax_sql($type, mpp_get_type_taxname());
    }
    //so let us build one
    /* $term_object_sql = "SELECT object_id FROM (
    	  (SELECT DISTINCT value FROM table_a)
    	  UNION ALL
    	  (SELECT DISTINCT value FROM table_b)
    	  ) AS t1 GROUP BY value HAVING count(*) >= 2; */
    $post_type_sql = $wpdb->prepare("SELECT DISTINCT ID as object_id FROM {$wpdb->posts} WHERE post_type = %s ", $post_type);
    //if a user or group id is given
    if ($component_id) {
        $post_type_sql = $wpdb->prepare("SELECT DISTINCT p.ID  as object_id FROM {$wpdb->posts} AS p INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id WHERE p.post_type= %s  AND pm.meta_key=%s and pm.meta_value=%d", $post_type, '_mpp_component_id', $component_id);
    }
    $post_status_sql = '';
    if ($post_status && $post_status != 'any') {
        $post_status_sql = $wpdb->prepare(" AND post_status =%s", $post_status);
    }
    //$sql[] = $post_type_sql;
    $new_sql = $join_sql = '';
    //array();
    //let us generate inner sub queries
    if ($sql) {
        $join_sql = ' (' . join(' AND object_id IN (', $sql);
    }
    //we need to append the ) for closing the sub queries
    for ($i = 0; $i < count($sql); $i++) {
        $join_sql .= ')';
    }
    $new_sql = $post_type_sql . $post_status_sql;
    //if the join sql is present, let us append it
    if ($join_sql) {
        $new_sql .= ' AND ID IN ' . $join_sql;
    }
    //for next/prev
    //sorted gallery
    //or by date
    //
    $post = get_post($object_id);
    $sorted = false;
    if ($object_parent && mpp_is_gallery_sorted($object_parent)) {
        $new_sql .= $wpdb->prepare(" AND p.menu_order {$op} %d ", $post->menu_order);
        $sorted = true;
    } else {
        $new_sql .= $wpdb->prepare(" AND p.ID {$op} %d ", $object_id);
        $sorted = false;
    }
    if ($object_parent) {
        $new_sql .= $wpdb->prepare(" AND post_parent = %d ", $object_parent);
    }
    $oreder_by_clause = '';
    if ($sorted) {
        $oreder_by_clause = " ORDER BY p.menu_order ";
    } else {
        $oreder_by_clause = "ORDER BY p.ID";
    }
    if (!$next) {
        //for previous
        //find the last element les than give
        $oreder_by_clause .= " DESC ";
    } else {
        $oreder_by_clause .= " ASC";
    }
    if (!empty($new_sql)) {
        $new_sql .= $oreder_by_clause . ' LIMIT 0, 1';
    }
    return $wpdb->get_var($new_sql);
}
Exemplo n.º 14
0
 private function is_settings_page()
 {
     global $pagenow;
     //we need to load on options.php otherwise settings won't be reistered
     if ($pagenow == 'options.php') {
         return true;
     }
     if (isset($_GET['page']) && $_GET['page'] == 'mpp-settings' && isset($_GET['post_type']) && $_GET['post_type'] == mpp_get_gallery_post_type()) {
         return true;
     }
     return false;
 }
 private function __construct()
 {
     $this->post_type = mpp_get_gallery_post_type();
     $this->template_dir = mediapress()->get_path() . 'admin/templates/';
     $this->setup();
 }
 public function filter_actions($actions, $post)
 {
     if ($post->post_type != mpp_get_gallery_post_type()) {
         return $actions;
     }
     unset($actions['inline hide-if-no-js']);
     return $actions;
 }
Exemplo n.º 17
0
 /**
  * Setup Root Galleries
  * @todo Make it work in 1.1 when we introduce site galleries
  * 
  */
 public function setup_root_gallery()
 {
     if (is_singular(mpp_get_gallery_post_type())) {
         $gallery_id = get_queried_object_id();
         //setup current gallery
         mediapress()->current_gallery = mpp_get_gallery($gallery_id);
         //setup gallery query
         mediapress()->the_gallery_query = new MPP_Gallery_Query(array('id' => $gallery_id));
         //check for end points to edit
         if (get_query_var('edit')) {
             $action = get_query_var('edit');
             if (in_array($action, mpp_get_reserved_actions())) {
                 //$this->setup_edit_action( get_query_var( 'edit' ) );
             }
         }
     } elseif (is_post_type_archive(mpp_get_gallery_post_type())) {
         mediapress()->the_gallery_query = new MPP_Gallery_Query(array());
     }
 }
/**
 * Get total gallery count for user|group etc
 * 
 * @param type $args
 * @see mpp_get_object_count for parameter details
 * @return type
 * 
 * @todo to save queries, in future, I believe It will be a better option to save the count in user meta, i have left it for now to avoid any syn issue
 * We will do it when we introduce mpp-tools
 * 
 * 
 */
function mpp_get_gallery_count($args)
{
    return mpp_get_object_count($args, mpp_get_gallery_post_type());
}
Exemplo n.º 19
0
 /**
  * Map gallery parameters to wp_query native parameters
  * 
  * @param type $args
  * @return string
  */
 public function build_params($args)
 {
     $defaults = array('type' => array_keys(mpp_get_active_types()), 'id' => false, 'in' => false, 'exclude' => false, 'slug' => false, 'status' => array_keys(mpp_get_active_statuses()), 'component' => array_keys(mpp_get_active_components()), 'component_id' => false, 'per_page' => mpp_get_option('galleries_per_page'), 'offset' => false, 'page' => false, 'nopaging' => false, 'order' => 'DESC', 'orderby' => 'date', 'user_id' => false, 'include_users' => false, 'exclude_users' => false, 'user_name' => false, 'scope' => false, 'search_terms' => '', 'year' => false, 'month' => false, 'week' => '', 'day' => '', 'hour' => '', 'minute' => '', 'second' => '', 'yearmonth' => false, 'fields' => false);
     //build params for WP_Query
     $r = wp_parse_args($args, $defaults);
     extract($r, EXTR_SKIP);
     //build the wp_query args
     $wp_query_args = array('post_type' => mpp_get_gallery_post_type(), 'post_status' => 'any', 'p' => $id, 'post__in' => $in, 'post__not_in' => $exclude, 'name' => $slug, 'posts_per_page' => $per_page, 'paged' => $page, 'offset' => $offset, 'nopaging' => $nopaging, 'author' => $user_id, 'author_name' => $user_name, 'author__in' => $include_users, 'author__not_in' => $exclude_users, 'year' => $year, 'monthnum' => $month, 'w' => $week, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $second, 'm' => $yearmonth, 'order' => $order, 'orderby' => $orderby, 's' => $search_terms, 'fields' => $fields, '_mpp_mapped_query' => true);
     $tax_query = array();
     $gmeta_query = array();
     //meta
     if (isset($meta_key) && $meta_key) {
         $wp_query_args['meta_key'] = $meta_key;
     }
     if (isset($meta_value)) {
         $wp_query_args['meta_value'] = $meta_value;
     }
     if (isset($meta_query)) {
         $gmeta_query = $meta_query;
     }
     //TODO: SCOPE
     //
     //we will need to build tax query/meta query
     //type, audio video etc
     //if type is given and it is valid gallery type
     //Pass one or more types
     //should we restrict to active types only here? I guss no, Insteacd the calling scope should take care of that
     if (!empty($type) && mpp_are_registered_types($type)) {
         $type = mpp_string_to_array($type);
         $type = array_map('mpp_underscore_it', $type);
         $tax_query[] = array('taxonomy' => mpp_get_type_taxname(), 'field' => 'slug', 'terms' => $type, 'operator' => 'IN');
     }
     //privacy
     //pass ne or more privacy level
     if (!empty($status) && mpp_are_registered_statuses($status)) {
         $status = mpp_string_to_array($status);
         $status = array_map('mpp_underscore_it', $status);
         $tax_query[] = array('taxonomy' => mpp_get_status_taxname(), 'field' => 'slug', 'terms' => $status, 'operator' => 'IN');
     }
     if (!empty($component) && mpp_are_registered_components($component)) {
         $component = mpp_string_to_array($component);
         $component = array_map('mpp_underscore_it', $component);
         $tax_query[] = array('taxonomy' => mpp_get_component_taxname(), 'field' => 'slug', 'terms' => $component, 'operator' => 'IN');
     }
     //done with the tax query
     if (count($tax_query) > 1) {
         $tax_query['relation'] = 'AND';
     }
     $wp_query_args['tax_query'] = $tax_query;
     // print_nice($wp_query_args);
     //meta query
     //now, for component
     if (!empty($component_id)) {
         $meta_compare = '=';
         if (is_array($component_id)) {
             $meta_compare = 'IN';
         }
         $gmeta_query[] = array('key' => '_mpp_component_id', 'value' => $component_id, 'compare' => $meta_compare, 'type' => 'UNSIGNED');
     }
     //reset meta query
     if (!empty($gmeta_query)) {
         $wp_query_args['meta_query'] = $gmeta_query;
     }
     // print_r($wp_query_args);
     return $wp_query_args;
 }
function mpp_get_previous_gallery_id($gallery_id)
{
    if (!$gallery_id) {
        return false;
    }
    $gallery = mpp_get_gallery($gallery_id);
    $args = array('component' => $gallery->component, 'component_id' => $gallery->component_id, 'object_id' => $gallery->id, 'next' => false);
    $prev_gallery_id = mpp_get_adjacent_object_id($args, mpp_get_gallery_post_type());
    return $prev_gallery_id;
}
 public function __construct()
 {
     $this->post_type = mpp_get_gallery_post_type();
     //setup hooks
     $this->setup();
 }
Exemplo n.º 22
0
    public function generate_css()
    {
        global $post_type;
        $gallery_post_type = mpp_get_gallery_post_type();
        if (!(isset($_GET['post_type']) && $_GET['post_type'] == $gallery_post_type || $post_type == $gallery_post_type)) {
            return;
        }
        ?>
		
		<style type='text/css'>
			#mpp-taxonomy-metabox label{
				display: inline-block;
				margin-top: 10px;
				text-align: center;
				width: 28%;
				font-weight: bold;
			}
			#mpp-taxonomy-metabox strong{
				display: inline-block;
				margin-top: 10px;
				text-align: center;
				vertical-align: middle;

				font-weight: bold;
			}

		</style>
		<?php 
    }
Exemplo n.º 23
0
function mpp_admin_is_add_gallery()
{
    if (is_admin() && isset($_GET['post_type']) && $_GET['post_type'] == mpp_get_gallery_post_type() && isset($_GET['mpp-gallery-type'])) {
        return true;
    }
    return false;
}