/**
 * Get the view associated with current gallery
 * 
 * @param int $gallery_id
 * @param string $default fallback view id
 * @return string view id
 */
function mpp_get_gallery_view_id($gallery_id, $default = '')
{
    $view_id = mpp_get_gallery_meta($gallery_id, '_mpp_view', true);
    if (!$view_id) {
        $view_id = 'default';
    }
    return $view_id;
}
Exemplo n.º 2
0
 private function get_component_id($post_id)
 {
     //if it is not gallery edit page, let us not worry
     if (!$this->is_gallery_edit()) {
         return mpp_get_current_component_id();
     }
     //we are on edit page,
     //it can be either add new or edit gallery
     //we do not want to modify the component_id(associated component id)
     $component_id = mpp_get_gallery_meta($post_id, '_mpp_component_id', true);
     if (!$component_id) {
         $component_id = get_current_user_id();
         //
     }
     return $component_id;
 }
Exemplo n.º 3
0
 public function __get($key)
 {
     if (isset($this->data[$key])) {
         return $this->data[$key];
     }
     if ('component' == $key) {
         $this->set($key, mpp_get_object_component($this->id));
         return $this->data[$key];
     } elseif ('type' == $key) {
         $this->set($key, mpp_get_object_type($this->id));
         return $this->data[$key];
     } elseif ('status' == $key) {
         $this->set($key, mpp_get_object_status($this->id));
         return $this->data[$key];
     }
     $value = mpp_get_gallery_meta($this->id, '_mpp_' . $key, true);
     return $value;
 }
Exemplo n.º 4
0
/**
 * 
 * @param MPP_Gallery $gallery
 * @param string $iview_id
 * @return boolean|MPP_Gallery_View
 */
function mpp_get_gallery_view($gallery, $view_id = '')
{
    //we always need a gallery to generate gallery view
    $type = $gallery->type;
    $component = $gallery->component;
    if (!$type) {
        return false;
    }
    //if view id is not given, get the single associated view
    if (!$view_id) {
        $view_id = mpp_get_gallery_meta($gallery->id, '_mpp_view', true);
    }
    //if there was no view found, let us fallback to default
    if (!$view_id) {
        //fallback to the current component view
        $view_id = mpp_get_component_gallery_view($component, $type);
    }
    //if view id is still not found, lets fallback to default
    if (!$view_id) {
        $view_id = 'default';
    }
    // if we are here, we know the view_id and the type
    $mpp = mediapress();
    if (isset($mpp->gallery_views[$type][$view_id])) {
        return $mpp->gallery_views[$type][$view_id];
    } else {
        //we will be here if the view type is not registered now but was used, return default view
    }
    return false;
}
Exemplo n.º 5
0
/**
 * Get an array of unpublished media ids
 * 
 * @param int $gallery_id
 * @return array of media ids
 */
function mpp_gallery_get_unpublished_media($gallery_id)
{
    return mpp_get_gallery_meta($gallery_id, '_mpp_unpublished_media_id', false);
    //get an array
}
Exemplo n.º 6
0
 public function __get($key)
 {
     if ('status' == $key) {
         return mpp_get_object_status($this->id);
     }
     if ('type' == $key) {
         return mpp_get_object_type($this->id);
     }
     if ('component' == $key) {
         return mpp_get_object_component($this->id);
     }
     $value = mpp_get_gallery_meta($this->id, '_mpp_' . $key, true);
     return $value;
 }
/**
 * Get the attachment Id which is used for gallery cover
 * 
 * @param type $gallery_id
 * @return int|boolean attachment id or false
 */
function mpp_get_gallery_cover_id($gallery_id)
{
    return mpp_get_gallery_meta($gallery_id, '_mpp_cover_id', true);
}
/**
 * Check if the media can be deleted by the user
 * 
 * @param type $media_id
 * @param type $user_id
 * @return boolean true if allowed false otherwise
 */
function mpp_user_can_delete_media($media_id, $user_id = null)
{
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    $media = mpp_get_media($media_id);
    if (!$media) {
        return false;
    }
    $gallery = mpp_get_gallery($media->gallery_id);
    $allow = false;
    //do not alow editing by default
    //if the user is gallery creator, allow him to delete media
    if ($gallery->user_id == $user_id) {
        //should we consider context here like members gallery or groups gallery?
        $allow = true;
    } elseif ($user_id == $media->user_id) {
        //since current user is uploader/contributor
        //let us check if the gallery allows deleting for contributor
        $allow_deleting = mpp_get_gallery_meta($gallery->id, '_mpp_contributors_can_delete', true);
        if ($allow_deleting == 'yes') {
            $allow = true;
        } elseif ($allow_deleting != 'no' && mpp_get_option('contributors_can_delete')) {
            //check for global settings & make sure it is not overridden in the local settings
            $allow = true;
        }
    }
    return apply_filters('mpp_user_can_delete_media', $allow, $media, $gallery, $user_id);
}
/**
 * Mark a Gallery as sorted
 * 
 */
function mpp_is_gallery_sorted($gallery_id)
{
    return mpp_get_gallery_meta($gallery_id, '_mpp_is_sorted', true);
}