示例#1
0
function mpp_get_all_media_ids($args = null)
{
    $component = mpp_get_current_component();
    $component_id = mpp_get_current_component_id();
    $default = array('gallery_id' => mpp_get_current_gallery_id(), 'component' => $component, 'component_id' => $component_id, 'per_page' => -1, 'status' => mpp_get_accessible_statuses($component, $component_id, get_current_user_id()), 'nopaging' => true, 'fields' => 'ids');
    $args = wp_parse_args($args, $default);
    $ids = new MPP_Media_Query($args);
    return $ids->get_ids();
}
    public function fetch_gallery_media()
    {
        //do we need nonce validation for this request too? no
        $items = array();
        $gallery_id = absint($_POST['gallery_id']);
        $gallery = mpp_get_gallery($gallery_id);
        if (!$gallery_id || empty($gallery)) {
            exit(0);
        }
        $statuses = mpp_get_accessible_statuses($gallery->component, $gallery->component_id, get_current_user_id());
        $media_query = new MPP_Media_Query(array('gallery_id' => $gallery_id, 'posts_per_page' => -1, 'status' => $statuses));
        if ($media_query->have_media()) {
            ?>


			<?php 
            while ($media_query->have_media()) {
                $media_query->the_media();
                ?>

				<?php 
                $items[] = array('src' => $this->get_media_lightbox_entry());
                ?>

			<?php 
            }
            ?>

		<?php 
        }
        ?>
		<?php 
        mpp_reset_media_data();
        ?>
		<?php 
        wp_send_json(array('items' => $items));
        exit(0);
    }
 /**
  * Setup everything for BuddyPress Specific installation
  * 
  */
 public function setup_globals($args = array())
 {
     //get current component/component_id
     $this->component = mpp_get_current_component();
     $this->component_id = mpp_get_current_component_id();
     //override the component id if we are on user page
     if (function_exists('bp_is_user') && bp_is_user()) {
         $this->component_id = bp_displayed_user_id();
     }
     //let us setup global queries
     $current_action = '';
     //initialize query objects
     mediapress()->the_gallery_query = new MPP_Gallery_Query();
     mediapress()->the_media_query = new MPP_Media_Query();
     if (!mpp_is_enabled($this->component, $this->component_id)) {
         return;
         //do not setup
     }
     //set the status types allowed for current user
     $this->accessible_statuses = mpp_get_accessible_statuses($this->component, $this->component_id, get_current_user_id());
     $this->status = $this->accessible_statuses;
     //is this sitewide gallery?
     if (mpp_is_enabled('sitewide', $this->component_id)) {
         $this->setup_sitewide_gallery();
     }
     //I know we are not using ifelse, check setup_root_gallery() to know why
     if (mpp_is_gallery_component()) {
         $this->action_variables = buddypress()->action_variables;
         //add the current action at the begining of the stack, we are doing it to unify the things for User gallery and component gallery
         array_unshift($this->action_variables, bp_current_action());
         $this->setup_user_gallery();
     } elseif (mpp_is_component_gallery()) {
         //are we on component gallery like groups or events etc?
         $this->action_variables = buddypress()->action_variables;
         $this->setup_component_gallery();
     }
     //fire this action to allow plugins do their own thing on mediapress()->the_gallery_query
     do_action('mpp_setup_gallery_query', $this);
     //once we are here, the basic action variables for mediapress are setup and so
     //we can go ahead and test for the single gallery/media
     $mp = mediapress();
     //setup Single Gallery specific things
     if (mpp_is_single_gallery()) {
         //will save some db query with a few themes
         if (has_action('wp_head', 'adjacent_posts_rel_link_wp_head')) {
             remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
         }
         $current_action = $this->current_action;
         //setup and see the actions etc to find out what we need to do
         //if it is one of the edit actions, It was already taken care of, don't do anything
         //check if we are on management screen?
         if ($this->current_action == 'manage') {
             //this is media management page
             $mp->set_editing('gallery');
             $mp->set_action('manage');
             $mp->set_edit_action($this->current_manage_action);
             //on edit bulk media page
             if ($mp->is_edit_action('edit')) {
                 $this->setup_gallery_media_query();
             }
         } elseif ($media = $this->get_media_id($this->current_action, $this->component, $this->component_id)) {
             //yes, It is single media
             $this->setup_single_media_query($media);
         } else {
             //we already know it is single gallery, so let us setup the media list query
             $this->setup_gallery_media_query();
         }
     }
     do_action('mpp_setup_globals');
 }
示例#4
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);
}
示例#5
0
 /**
  * Setup everything for BuddyPress Specific installation
  * 
  */
 public function setup_globals($args = array())
 {
     $bp = buddypress();
     //if the 'gallery' slug is not set , set it to mediapress?
     if (!defined('MPP_GALLERY_SLUG')) {
         define('MPP_GALLERY_SLUG', $this->id);
     }
     //get current component/component_id
     $this->component = mpp_get_current_component();
     $this->component_id = mpp_get_current_component_id();
     //override the component id if we are on user page
     if (bp_is_user()) {
         $this->component_id = bp_displayed_user_id();
     }
     $globals = array('slug' => MPP_GALLERY_SLUG, 'root_slug' => isset($bp->pages->mediapress->slug) ? $bp->pages->mediapress->slug : MPP_GALLERY_SLUG, 'notification_callback' => 'mpp_format_notifications', 'has_directory' => mpp_get_option('has_gallery_directory'), 'search_string' => __('Search Galleries...', 'mediapress'), 'directory_title' => isset($bp->pages->mediapress->id) ? get_the_title($bp->pages->mediapress->id) : __('Gallery Directory', 'mediapress'));
     parent::setup_globals($globals);
     //it will call do_action("bp_gallery_setup_global") after setting up the constants properly
     //the only possibility of gallery as component is in case of root galler, gallery directory or user gallery
     //let us setup global queries
     $current_action = '';
     //initialize query objects
     mediapress()->the_gallery_query = new MPP_Gallery_Query();
     mediapress()->the_media_query = new MPP_Media_Query();
     //set the status types allowed for current user
     $this->accessible_statuses = mpp_get_accessible_statuses($this->component, $this->component_id, get_current_user_id());
     //is the root gallery enabled?
     if (mpp_is_root_enabled()) {
         $this->setup_root_gallery();
     }
     //end of root gallery section
     //if it is either member gallery OR Gallery Directory, let us process it
     if (mpp_is_gallery_component()) {
         $this->action_variables = buddypress()->action_variables;
         //add the current action at the begining of the stack, we are doing it to unify the things for User gallery and component gallery
         array_unshift($this->action_variables, bp_current_action());
         $this->setup_user_gallery();
     } elseif (mpp_is_component_gallery()) {
         //are we on component gallery like groups or events etc?
         $this->action_variables = buddypress()->action_variables;
         $this->setup_component_gallery();
     }
     //once we are here, the basic action variables for mediapress are setup and so
     //we can go ahead and test for the single gallery/media
     $mp = mediapress();
     //setup Single Gallery specific things
     if (mpp_is_single_gallery()) {
         $current_action = $this->current_action;
         //setup and see the actions etc to find out what we need to do
         //if it is one of the edit actions, It was already taken care of, don't do anything
         if (in_array($current_action, mpp_get_reserved_actions())) {
             return;
         }
         //check if we are on management screen?
         if ($this->current_action == 'manage') {
             //this is media management page
             $mp->set_editing('gallery');
             $mp->set_action('manage');
             $mp->set_edit_action($this->current_manage_action);
             //on edit bulk media page
             if ($mp->is_edit_action('edit')) {
                 $this->setup_gallery_media_query();
             }
         } elseif ($media = $this->get_media_id($this->current_action, $this->component, $this->component_id)) {
             //yes, It is single media
             $this->setup_single_media_query($media);
         } else {
             //we already know it is single gallery, so let us setup the media list query
             $this->setup_gallery_media_query();
         }
     }
     do_action('mpp_setup_globals');
 }
/**
 * Can the User see this media?
 * 
 * @param type $media_id
 * @param type $user_id
 * @return type
 */
function mpp_user_can_view_media($media_id, $user_id = null)
{
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    $media = mpp_get_media($media_id);
    $gallery = mpp_get_gallery($media->gallery_id);
    //a media is only viewable if the parent gallery is viewable
    $allowed = false;
    if (mpp_user_can_list_media($gallery->id, $user_id)) {
        //nw let us check for media permissions
        $user_permissions = mpp_get_accessible_statuses($gallery->component, $gallery->component_id, $user_id);
        if (in_array($media->status, $user_permissions)) {
            $allowed = true;
        }
    }
    return apply_filters('mpp_user_can_view_media', $allowed, $media, $gallery, $user_id);
}
示例#7
0
/**
 *  Get total galleries|media based on other parameters
 * 
 * @param type $args {
 *  @type component string|array comma separated sting or array of components eg 'groups,members' or array('groups', 'members' )
 *  @type component_id int numeric component id (user id or group id)
 *  @type status string|array comma separated list or array of statuses e.g. 'public,private,friends' or array ( 'public', 'private', 'friends' )
 *  @type type   string|array comma separated list or array of media types e.g 'audio,video,photo' or array ( 'audio', 'video', 'photo' )
 * @param string $post_type
 * 
 * @return int total no of posts
 */
function mpp_get_object_count($args, $post_type)
{
    global $wpdb;
    $post_type_sql = '';
    $sql = array();
    $default = array('component' => '', 'component_id' => false, 'status' => '', 'type' => '', 'post_status' => 'publish');
    //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);
    if (!$status) {
        if ($component && $component_id) {
            $status = mpp_get_accessible_statuses($component, $component_id, get_current_user_id());
        } else {
            $status = array_keys(mpp_get_active_statuses());
        }
    }
    if (!$component) {
        $component = array_keys(mpp_get_active_components());
    }
    if (!$type) {
        $type = array_keys(mpp_get_active_types());
    }
    //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());
    }
    //we need to find all the object ids which are present in these terms
    //since mysql does not have intersect clause and inner join will be causing too large data set
    //let us use another apprioach for now
    //in our case
    //theere are 3 taxonomies
    //so we will be looking for the objects appearing thrice
    $tax_object_sql = " (SELECT DISTINCT t.object_id FROM (" . join(" UNION ALL ", $sql) . ") AS t GROUP BY object_id HAVING count(*) >=3 )";
    $post_type_sql = $wpdb->prepare("SELECT COUNT( DISTINCT ID ) FROM {$wpdb->posts} WHERE post_type = %s AND post_status =%s", $post_type, $post_status);
    //if a user or group id is given
    if ($component_id) {
        $post_type_sql = $wpdb->prepare("SELECT COUNT( DISTINCT p.ID ) AS total FROM {$wpdb->posts} AS p INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id WHERE p.post_type= %s AND p.post_status = %s AND pm.meta_key=%s and pm.meta_value=%d", $post_type, $post_status, '_mpp_component_id', $component_id);
    }
    //$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 .=')';
    
    	 */
    $join_sql = $tax_object_sql;
    $new_sql = $post_type_sql;
    //if the join sql is present, let us append it
    if ($join_sql) {
        $new_sql .= ' AND ID IN ' . $join_sql;
    }
    //echo $new_sql;
    return $wpdb->get_var($new_sql);
}