function mpp_shortcode_uploader($atts = array(), $content = '') { $default = array('gallery_id' => 0, 'component' => mpp_get_current_component(), 'component_id' => mpp_get_current_component_id(), 'type' => '', 'status' => mpp_get_default_status(), 'view' => '', 'selected' => 0, 'label_empty' => __('Please select a gallery', 'mediapress'), 'show_error' => 1); $atts = shortcode_atts($default, $atts); //dropdown list of galleries to sllow userselect one $view = 'list'; if (!empty($atts['gallery_id']) && is_numeric($atts['gallery_id'])) { $view = 'single'; //single gallery uploader //override component and $component id $gallery = mpp_get_gallery($atts['gallery_id']); if (!$gallery) { return __('Nonexistent gallery should not be used', 'mediapress'); } //reset $atts['component'] = $gallery->component; $atts['component_id'] = $gallery->component_id; $atts['type'] = $gallery->type; } //the user must be able to upload to current component or galler $can_upload = false; if (mpp_user_can_upload($atts['component'], $atts['component_id'], $atts['gallery_id'])) { $can_upload = true; } if (!$can_upload && $atts['show_error']) { return __('Sorry, you are not allowed to upload here.', 'mediapress'); } //if we are here, the user can upload //we still have one issue, what if the user has not created any gallery and the admin intends to allow the user to upload to their created gallery $atts['context'] = 'shortcode'; //from where it is being uploaded, $atts['view'] = $view; //passing the 2nd arg makes all these variables available to the loaded file mpp_get_template('shortcodes/uploader.php', $atts); }
public function setup_nav($main = array(), $sub = array()) { $bp = buddypress(); $component = 'members'; $component_id = mpp_get_current_component_id(); if (!mpp_is_enabled($component, $component_id)) { //allow to disable user galleries in case they don't want it return false; } $view_helper = MPP_Gallery_Screens::get_instance(); // Add 'Gallery' to the user's main navigation $main_nav = array('name' => sprintf(__('Gallery <span>%d</span>', 'mediapress'), mpp_get_total_gallery_for_user()), 'slug' => $this->slug, 'position' => 86, 'screen_function' => array($view_helper, 'user_galleries'), 'default_subnav_slug' => 'my-galleries', 'item_css_id' => $this->id); if (bp_is_user()) { $user_domain = bp_displayed_user_domain(); } else { $user_domain = bp_loggedin_user_domain(); } $gallery_link = trailingslashit($user_domain . $this->slug); //with a trailing slash // Add the My Gallery nav item $sub_nav[] = array('name' => __('My Gallery', 'mediapress'), 'slug' => 'my-galleries', 'parent_url' => $gallery_link, 'parent_slug' => $this->slug, 'screen_function' => array($view_helper, 'my_galleries'), 'position' => 10, 'item_css_id' => 'gallery-my-gallery'); if (mpp_user_can_create_gallery($component, get_current_user_id())) { // Add the Create gallery link to gallery nav $sub_nav[] = array('name' => __('Create a Gallery', 'mediapress'), 'slug' => 'create', 'parent_url' => $gallery_link, 'parent_slug' => $this->slug, 'screen_function' => array($view_helper, 'my_galleries'), 'user_has_access' => bp_is_my_profile(), 'position' => 20); } if (mpp_component_has_type_filters_enabled($component, $component_id)) { $i = 10; $supported_types = mpp_component_get_supported_types($component); foreach ($supported_types as $type) { if (!mpp_is_active_type($type)) { continue; } $type_object = mpp_get_type_object($type); $sub_nav[] = array('name' => $type_object->label, 'slug' => 'type/' . $type, 'parent_url' => $gallery_link, 'parent_slug' => $this->slug, 'screen_function' => array($view_helper, 'my_galleries'), 'position' => 20 + $i); $i = $i + 10; //increment the position } } // Add the Upload link to gallery nav /*$sub_nav[] = array( 'name' => __( 'Upload', 'mediapress'), 'slug' => 'upload', 'parent_url' => $gallery_link, 'parent_slug' => $this->slug, 'screen_function' => array( $view_helper, 'upload_media' ), 'user_has_access' => bp_is_my_profile(), 'position' => 30 );*/ parent::setup_nav($main_nav, $sub_nav); //disallow these names in various lists //we have yet to implement it $this->forbidden_names = apply_filters('mpp_forbidden_names', array('gallery', 'galleries', 'my-gallery', 'create', 'delete', 'upload', 'add', 'edit', 'admin', 'request', 'upload', 'tags', 'audio', 'video', 'photo')); //use this to extend the valid status $this->valid_status = apply_filters('mpp_valid_gallery_status', array_keys(mpp_get_active_statuses())); do_action('mpp_setup_nav'); // $bp->gallery->current_gallery->user_has_access }
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(); }
/** * Get an array of all the permissions available to the current user for the gallery * * * @param type $component_type * @param type $component_id * @param type $gallery_id * @return type * @deprecated 1.0beta1 * @see mpp_get_accessible_statuses() * */ function mpp_get_current_user_access_permissions($component_type = false, $component_id = false, $gallery_id = false) { if (!$component_type) { $component_type = mpp_get_current_component(); } if (!$component_id) { $component_id = mpp_get_current_component_id(); } return apply_filters("mpp_get_current_user_" . strtolower($component_type) . "_gallery_access", array('public'), $component_id, $gallery_id); }
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; }
/** * 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'); }
/** * Generate/Display breadcrumb * @param array $args * @return string|null */ function mpp_gallery_breadcrumb($args = null) { $default = array('separator' => '/', 'before' => '', 'after' => '', 'show_home' => false); $args = wp_parse_args($args, $default); extract($args); $crumbs = array(); $component = mpp_get_current_component(); $component_id = mpp_get_current_component_id(); if (mediapress()->is_bp_active() && bp_is_active('groups') && bp_is_group()) { $name = bp_get_group_name(groups_get_current_group()); } elseif (mediapress()->is_bp_active() && bp_is_user()) { $name = bp_get_displayed_user_fullname(); } elseif ($component == 'sitewide') { $name = ''; } $my_or_his_gallery = ''; if ($name) { $my_or_his_gallery = sprintf(__("%s's gallery", 'mediapress'), $name); } if (function_exists('bp_is_my_profile') && bp_is_my_profile()) { $my_or_his_gallery = __('Your Galleries', 'mediapress'); } if (mpp_is_media_management()) { $crumbs[] = ucwords(mediapress()->get_edit_action()); } if (mpp_is_single_media()) { $media = mpp_get_current_media(); if (mpp_is_media_management()) { $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_media_permalink($media), mpp_get_media_title($media)); } else { $crumbs[] = sprintf('<span>%s</span>', mpp_get_media_title($media)); } } if (mpp_is_gallery_management()) { $crumbs[] = ucwords(mediapress()->get_edit_action()); } if (mpp_is_single_gallery()) { $gallery = mpp_get_current_gallery(); if (mpp_is_gallery_management() || mpp_is_single_media()) { $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_gallery_permalink($gallery), mpp_get_gallery_title($gallery)); } else { $crumbs[] = sprintf('<span>%s</span>', mpp_get_gallery_title($gallery)); } } if ($my_or_his_gallery) { $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_gallery_base_url($component, $component_id), $my_or_his_gallery); } if (count($crumbs) <= 1 && !$show_home) { return; } $crumbs = array_reverse($crumbs); echo join($separator, $crumbs); }
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); }
public function defult_settings() { global $wp_scripts; $data = $wp_scripts->get_data('mpp_uploader', 'data'); if ($data && false !== strpos($data, '_mppUploadSettings')) { return; } $max_upload_size = wp_max_upload_size(); $defaults = array('runtimes' => 'html5,silverlight,flash,html4', 'file_data_name' => '_mpp_file', 'multiple_queues' => true, 'max_file_size' => $max_upload_size . 'b', 'url' => admin_url('admin-ajax.php'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files'), 'extensions' => '*')), 'multipart' => true, 'urlstream_upload' => true); // Multi-file uploading doesn't currently work in iOS Safari, // single-file allows the built-in camera to be used as source for images if (wp_is_mobile()) { $defaults['multi_selection'] = false; } $defaults = apply_filters('mpp_upload_default_settings', $defaults); $params = array('action' => 'mpp_add_media', '_wpnonce' => wp_create_nonce('mpp_add_media'), 'component' => mpp_get_current_component(), 'component_id' => mpp_get_current_component_id(), 'context' => 'gallery'); $params = apply_filters('mpp_plupload_default_params', $params); // $params['_wpnonce'] = wp_create_nonce( 'media-form' ); $defaults['multipart_params'] = $params; $settings = array('defaults' => $defaults, 'browser' => array('mobile' => wp_is_mobile(), 'supported' => _device_can_upload()), 'limitExceeded' => false); $script = 'var _mppUploadSettings = ' . json_encode($settings) . ';'; if ($data) { $script = "{$data}\n{$script}"; } $wp_scripts->add_data('mpp_uploader', 'data', $script); }
/** * Display a create Gallery Button * * @return string */ function mpp_gallery_create_button() { //check whether to display the link or not $component = mpp_get_current_component(); $component_id = mpp_get_current_component_id(); if (!mpp_user_can_create_gallery($component, $component_id)) { return false; } ?> <a id="add_new_gallery_link" href="<?php mpp_gallery_create_url($component, $component_id); ?> ">Add Gallery</a> <?php }
function mpp_display_space_usage($component = null, $component_id = null) { if (!mpp_get_option('show_upload_quota')) { return; } if (!$component) { $component = mpp_get_current_component(); } if (!$component_id) { $component_id = mpp_get_current_component_id(); } $total_space = mpp_get_allowed_space($component, $component_id); $used = mpp_get_used_space($component, $component_id); if ($used > $total_space) { $percentused = '100'; } else { $percentused = $used / $total_space * 100; } if ($total_space > 1000) { $total_space = number_format($total_space / 1024); $total_space .= __('GB'); } else { $total_space .= __('MB'); } ?> <strong><?php printf(__('You have <span> %1s%%</span> of your %2s space left', 'mediapress'), number_format(100 - $percentused), $total_space); ?> </strong> <?php }
/** * Add various upload icons to activity post form * @return type */ function mpp_activity_upload_buttons() { $component = mpp_get_current_component(); if (!mpp_is_activity_upload_enabled($component)) { return; } //if we are here, the gallery activity stream upload is enabled, //let us see if we are on user profile and gallery is enabled if (!mpp_is_enabled($component, mpp_get_current_component_id())) { return; } //if we are on group page and either the group component is not enabled or gallery is not enabled for current group, do not show the icons if (function_exists('bp_is_group') && bp_is_group() && (!mpp_is_active_component('groups') || !(function_exists('mpp_group_is_gallery_enabled') && mpp_group_is_gallery_enabled()))) { return; } //for now, avoid showing it on single gallery/media activity stream if (mpp_is_single_gallery() || mpp_is_single_media()) { return; } ?> <div id="mpp-activity-upload-buttons" class="mpp-upload-buttons"> <?php do_action("mpp_before_activity_upload_buttons"); //allow to add more type ?> <?php if (mpp_is_active_type('photo') && mpp_component_supports_type($component, 'photo')) { ?> <a href="#" id="mpp-photo-upload" data-media-type="photo"><img src="<?php echo mediapress()->get_url() . 'assets/images/media-button-image.gif'; ?> "/></a> <?php } ?> <?php if (mpp_is_active_type('audio') && mpp_component_supports_type($component, 'audio')) { ?> <a href="#" id="mpp-audio-upload" data-media-type="audio"><img src="<?php echo mediapress()->get_url() . 'assets/images/media-button-music.gif'; ?> "/></a> <?php } ?> <?php if (mpp_is_active_type('video') && mpp_component_supports_type($component, 'video')) { ?> <a href="#" id="mpp-video-upload" data-media-type="video"><img src="<?php echo mediapress()->get_url() . 'assets/images/media-button-video.gif'; ?> "/></a> <?php } ?> <?php if (mpp_is_active_type('doc') && mpp_component_supports_type($component, 'doc')) { ?> <a href="#" id="mpp-doc-upload" data-media-type="doc"><img src="<?php echo mediapress()->get_url() . 'assets/images/media-button-doc.png'; ?> " /></a> <?php } ?> <?php //someone please provide me doc icon and some better icons ?> <?php do_action('mpp_after_activity_upload_buttons'); //allow to add more type ?> </div> <?php }
<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } /** * Create Gallery shortcode * You can overwide it in yourtheme/mediapress/default/shortcodes/create-gallery.php * */ ?> <div id="mpp-create-gallery-form-wrapper" class="mpp-container" > <?php if (mpp_user_can_create_gallery(mpp_get_current_component(), mpp_get_current_component_id())) { ?> <form method="post" action="" id="mpp-create-gallery-form" class="mpp-form mpp-form-stacked mpp-create-gallery-form"> <?php $title = $description = $status = $type = $component = ''; if (!empty($_POST['mpp-gallery-title'])) { $title = $_POST['mpp-gallery-title']; } if (!empty($_POST['mpp-gallery-description'])) { $description = $_POST['mpp-gallery-description']; } if (!empty($_POST['mpp-gallery-status'])) { $status = $_POST['mpp-gallery-status']; } if (!empty($_POST['mpp-gallery-type'])) {
/** * Record Media Activity * * It does not actually records activity, simply simulates the activity update and rest are done by the actions.php functions * * It will be removed in future for a better record_activity method * @param type $args * @return boolean */ function mpp_record_activity($args = null) { //if activity module is not active, why bother if (!bp_is_active('activity')) { return false; } $default = array('id' => false, 'gallery_id' => 0, 'media_id' => 0, 'media_ids' => null, 'action' => '', 'content' => '', 'type' => '', 'component' => mpp_get_current_component(), 'component_id' => mpp_get_current_component_id(), 'user_id' => get_current_user_id(), 'status' => ''); $args = wp_parse_args($args, $default); //atleast a gallery id or a media id should be given if (!$args['gallery_id'] && !$args['media_id'] || !mpp_is_enabled($args['component'], $args['component_id']) || !$args['component_id']) { return false; } $gallery_id = absint($args['gallery_id']); $media_id = absint($args['media_id']); $type = $args['type']; //should we validate type too? $hide_sitewide = 0; $status_object = null; if ($args['status']) { $status_object = mpp_get_status_object($args['status']); if ($status_object && ($status_object->activity_privacy == 'hidden' || $status_object->activity_privacy == 'onlyme')) { $hide_sitewide = 1; } //if BuddyPress Activity privacy plugin is not active, revert back to hiding all non public activity if (!function_exists('bp_activity_privacy_check_config')) { $hide_sitewide = $args['status'] == 'public' ? 0 : 1; //overwrite privacy } } $media_ids = $args['media_ids']; if (!empty($media_ids) && !is_array($media_ids)) { $media_ids = explode(',', $media_ids); } $component = $args['component']; if ($component == buddypress()->members->id) { $component = buddypress()->activity->id; //for user gallery updates, let it be simple activity , do not set the component to 'members' } $activity_args = array('id' => $args['id'], 'user_id' => $args['user_id'], 'action' => $args['action'], 'content' => $args['content'], 'component' => $component, 'type' => 'mpp_media_upload', 'item_id' => absint($args['component_id']), 'secondary_item_id' => false, 'hide_sitewide' => $hide_sitewide); //only update record time if this is a new activity if (empty($args['id'])) { $activity_args['recorded_time'] = bp_core_current_time(); } //let us give an opportunity to customize the activity args //use this filter to work with the activity privacy $activity_args = apply_filters('mpp_record_activity_args', $activity_args, $default); $activity_id = bp_activity_add($activity_args); if (!$activity_id) { return false; //there was a problem } //store the type of gallery activity in meta if ($type) { mpp_activity_update_activity_type($activity_id, $type); } if ($media_ids) { $media_ids = wp_parse_id_list($media_ids); mpp_activity_update_attached_media_ids($activity_id, $media_ids); } if ($gallery_id) { mpp_activity_update_gallery_id($activity_id, $gallery_id); } if ($media_id) { mpp_activity_update_media_id($activity_id, $media_id); } mpp_activity_update_context($activity_id, 'gallery'); //save activity privacy if ($status_object) { bp_activity_update_meta($activity_id, 'activity-privacy', $status_object->activity_privacy); } return $activity_id; }
/** * Record Media Activity * * It does not actually records activity, simply simulates the activity update and rest are done by the actions.php functions * * It will be removed in future for a better record_activity method * @param type $args * @return boolean */ function mpp_record_activity($args = null) { //if activity module is not active, why bother if (!bp_is_active('activity')) { return false; } $default = array('gallery_id' => 0, 'media_id' => 0, 'media_ids' => null, 'action' => '', 'content' => '', 'type' => '', 'component' => mpp_get_current_component(), 'component_id' => mpp_get_current_component_id(), 'user_id' => get_current_user_id(), 'status' => ''); $args = wp_parse_args($args, $default); //atleast a gallery id or a media id should be given if (!$args['gallery_id'] && !$args['media_id'] || !mpp_is_active_component($args['component']) || !$args['component_id']) { return false; } $gallery_id = absint($args['gallery_id']); $media_id = absint($args['media_id']); $type = $args['type']; //should we validate type too? $hide_sitewide = 0; $status_object = null; if ($args['status']) { $status_object = mpp_get_status_object($args['status']); if ($status_object && ($status_object->activity_privacy == 'hidden' || $status_object->activity_privacy == 'onlyme')) { $hide_sitewide = 1; } } $media_ids = $args['media_ids']; if (!empty($media_ids) && !is_array($media_ids)) { $media_ids = explode(',', $media_ids); } $component = $args['component']; if ($component == buddypress()->members->id) { $component = buddypress()->activity->id; //for user gallery updates, let it be simple activity , do not set the component to 'members' } $activity_id = bp_activity_add(array('id' => false, 'user_id' => $args['user_id'], 'action' => $args['action'], 'content' => $args['content'], 'component' => $component, 'type' => 'mpp_media_upload', 'item_id' => absint($args['component_id']), 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => $hide_sitewide)); if (!$activity_id) { return false; //there was a problem } //store the type of gallery activity in meta if ($type) { mpp_activity_update_activity_type($activity_id, $type); } if ($media_ids) { $media_ids = wp_parse_id_list($media_ids); mpp_activity_update_attached_media_ids($activity_id, $media_ids); } if ($gallery_id) { mpp_activity_update_gallery_id($activity_id, $gallery_id); } if ($media_id) { mpp_activity_update_media_id($activity_id, $media_id); } mpp_activity_update_context($activity_id, 'gallery'); //save activity privacy if ($status_object) { bp_activity_update_meta($activity_id, 'activity-privacy', $status_object->activity_privacy); } return $activity_id; }
/** * Handles Gallery creation on the front end in non ajax case * * @return type */ function mpp_action_create_gallery() { //allow gallery to be created from anywhere //the form must have mpp-action set and It should be set to 'create-gallery' if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'create-gallery') { return; } $referer = wp_get_referer(); //if we are here, It is gallery create action if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-create-gallery')) { //add error message and return back to the old page mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //update it to allow passing component/id from the form $component = mpp_get_current_component(); $component_id = mpp_get_current_component_id(); //check for permission //we may want to allow passing of component from the form in future! if (!mpp_user_can_create_gallery($component, $component_id)) { mpp_add_feedback(__("You don't have permission to create gallery!", 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, validate the data and let us see if we can create $title = $_POST['mpp-gallery-title']; $description = $_POST['mpp-gallery-description']; $type = $_POST['mpp-gallery-type']; $status = $_POST['mpp-gallery-status']; $errors = array(); if (!mpp_is_active_status($status)) { $errors['status'] = __('Invalid Gallery status!', 'mediapress'); } if (!mpp_is_active_type($type)) { $errors['type'] = __('Invalid gallery type!', 'mediapress'); } //check for current component if (!mpp_is_active_component($component)) { $errors['component'] = __('Invalid gallery component!', 'mediapress'); } if (empty($title)) { $errors['title'] = __('Title can not be empty', 'mediapress'); } //give opportunity to other plugins to add their own validation errors $validation_errors = apply_filters('mpp-create-gallery-field-validation', $errors, $_POST); if (!empty($validation_errors)) { //let us add the validation error and return back to the earlier page $message = join('\\r\\n', $validation_errors); mpp_add_feedback($message, 'error'); if ($referer) { mpp_redirect($referer); } return; } //let us create gallery $gallery_id = mpp_create_gallery(array('title' => $title, 'description' => $description, 'type' => $type, 'status' => $status, 'creator_id' => get_current_user_id(), 'component' => $component, 'component_id' => $component_id)); if (!$gallery_id) { mpp_add_feedback(__('Unable to create gallery!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, the gallery was created successfully, //let us redirect to the gallery_slug/manage/upload page $redirect_url = mpp_get_gallery_add_media_url($gallery_id); mpp_add_feedback(__('Gallery created successfully!', 'mediapress')); mpp_redirect($redirect_url); }
/** * Not used, Oembed support is not yet available in 1.0 branch */ public function add_oembed_media() { check_ajax_referer('mpp_add_media'); //check for the referrer $media_type = ''; $gallery_id = ''; $component = $_POST['component']; $component_id = $_POST['component_id']; $context = mpp_get_upload_context(false, $_POST['context']); if (!$component) { $component = mpp_get_current_component(); } if (!$component_id) { $component_id = mpp_get_current_component_id(); } //get the uploader $uploader = mpp_get_storage_manager('oembed'); //should we pass the component? //setup for component //$uploader->setup_for( $component, $component_id ); //check if the server can handle the upload? if (!$uploader->can_handle()) { wp_send_json_error(array('message' => __('Server can not handle this much amount of data. Please upload a smaller file or ask your server administrator to change the settings.', 'mediapress'))); } if (!mpp_has_available_space($component, $component_id)) { wp_send_json_error(array('message' => __('Unable to upload. You have used the allowed storage quota!', 'mediapress'))); } //if we are here, the server can handle upload //check should be here $gallery_id = 0; if (isset($_POST['gallery_id'])) { $gallery_id = absint($_POST['gallery_id']); } if ($gallery_id) { $gallery = mpp_get_gallery($gallery_id); } else { $gallery = false; } //not set //if there is no gallery id given and the context is activity, we may want to auto create the gallery $media_type = mpp_get_media_type_from_extension(mpp_get_file_extension($file[$file_id]['name'])); if (!$media_type) { wp_send_json_error(array('message' => __("This file type is not supported.", 'mediapress'))); } //if there is no gallery type defined( It wil happen in case of new gallery creation from admin page //we will set the gallery type as the type of the first media if ($gallery && empty($gallery->type)) { //update gallery type //set it to media type mpp_update_gallery_type($gallery, $media_type); } //If the gallery is not given and It is members component, check if the upload context is activity? //Check if we have a profile gallery set for the current user for this type of media //if yes, then use that gallery to upload the media //otherwise we create a gallery of the current media type and set it as the profile gallery for that type if (!$gallery && $context == 'activity') { //if gallery is not given and the component supports wall gallery //then create if (!mpp_is_activity_upload_enabled($component)) { wp_send_json_error(array('message' => __("The gallery is not selected.", 'mediapress'))); } $gallery_id = mpp_get_wall_gallery_id(array('component' => $component, 'component_id' => $component_id, 'media_type' => $media_type)); if (!$gallery_id) { //if gallery does not exist, create 1 $gallery_id = mpp_create_gallery(array('creator_id' => get_current_user_id(), 'title' => sprintf(_x('Wall %s Gallery', 'wall gallery name', 'mediapress'), $media_type), 'description' => '', 'status' => 'public', 'component' => $component, 'component_id' => $component_id, 'type' => $media_type)); if ($gallery_id) { //save the profile gallery id mpp_update_wall_gallery_id(array('component' => $component, 'component_id' => $component_id, 'media_type' => $media_type, 'gallery_id' => $gallery_id)); } } //setup gallery object from the profile gallery id if ($gallery_id) { $gallery = mpp_get_gallery($gallery_id); } } //we may want to check the upload type and set the gallery to activity gallery etc if it is not set already $error = false; //detect media type of uploaded file here and then upload it accordingly also check if the media type uploaded and the gallery type matches or not //let us build our response for javascript //if we are uploading to a gallery, check for type //since we will be allowin g upload without gallery too, It is required to make sure $gallery is present or not if ($gallery && !mpp_is_mixed_gallery($gallery) && $media_type !== $gallery->type) { //if we are uploading to a gallery and It is not a mixed gallery, the media type must match the gallery type wp_send_json_error(array('message' => sprintf(__('This file type is not allowed in current gallery. Only <strong>%s</strong> files are allowed!', 'mediapress'), mpp_get_allowed_file_extensions_as_string($gallery->type)))); } //if we are here, all is well :) if (!mpp_user_can_upload($component, $component_id, $gallery)) { wp_send_json_error(array('message' => __("You don't have sufficient permissions to upload.", 'mediapress'))); } //if we are here, we have checked for all the basic errors, so let us just upload now $uploaded = $uploader->upload($file, array('file_id' => $file_id, 'gallery_id' => $gallery_id, 'component' => $component, 'component_id' => $component_id)); //upload was succesfull? if (!isset($uploaded['error'])) { //file was uploaded successfully $title = $_FILES[$file_id]['name']; $title_parts = pathinfo($title); $title = trim(substr($title, 0, -(1 + strlen($title_parts['extension'])))); $url = $uploaded['url']; $type = $uploaded['type']; $file = $uploaded['file']; //$title = isset( $_POST['media_title'] ) ? $_POST['media_title'] : ''; $content = isset($_POST['media_description']) ? $_POST['media_description'] : ''; $meta = $uploader->get_meta($uploaded); $title_desc = $this->get_title_desc_from_meta($type, $meta); if (!empty($title_desc)) { if (empty($title) && !empty($title_desc['title'])) { $title = $title_desc['title']; } if (empty($content) && !empty($title_desc['content'])) { $content = $title_desc['content']; } } $status = isset($_POST['media_status']) ? $_POST['media_status'] : ''; if (empty($status) && $gallery) { $status = $gallery->status; } //inherit from parent,gallery must have an status //we may need some more enhancements here if (!$status) { $status = mpp_get_default_status(); } // print_r($upload_info); $is_orphan = 0; //Any media uploaded via activity is marked as orphan( Not associated with the mediapress unless the activity to which it was attached is actually created, check core/activity/actions.php to see how the orphaned media is adopted by the activity :) ) if ($context == 'activity') { $is_orphan = 1; } //by default mark all uploaded media via activity as orphan $media_data = array('title' => $title, 'description' => $content, 'gallery_id' => $gallery_id, 'user_id' => get_current_user_id(), 'is_remote' => false, 'type' => $media_type, 'mime_type' => $type, 'src' => $file, 'url' => $url, 'status' => $status, 'comment_status' => 'open', 'storage_method' => mpp_get_storage_method(), 'component_id' => $component_id, 'component' => $component, 'context' => $context, 'is_orphan' => $is_orphan); $id = mpp_add_media($media_data); //should we update and resize images here? // mpp_gallery_increment_media_count($gallery_id); $attachment = mpp_media_to_json($id); //$attachment['data']['type_id'] = mpp_get_type_term_id( $gallery->type ); echo json_encode(array('success' => true, 'data' => $attachment)); //wp_send_json_success( array('name'=>'what') ); exit(0); } else { wp_send_json_error(array('message' => $uploaded['error'])); } }
/** * Filter Main MPp Gallery Query to add support for "my-gallery" view on group component * @param type $args * @return type */ function mpp_group_filter_gallery_query($args) { if (mpp_group_is_my_galleries_enabled() && bp_is_active('groups') && bp_is_group() && mpp_is_enabled(mpp_get_current_component(), mpp_get_current_component_id())) { //check if the current av0 is 'my-gallery'; if (is_user_logged_in() && bp_is_action_variable('my-gallery', 0)) { $args['user_id'] = bp_loggedin_user_id(); } } return $args; }
<?php } ?> <?php mpp_reset_media_data(); ?> <?php } else { ?> <?php //we should seriously think about adding create gallery button here ?> <?php if (mpp_user_can_upload(mpp_get_current_component(), mpp_get_current_component_id())) { ?> <?php mpp_get_template('gallery/manage/add-media.php'); ?> <?php } else { ?> <div class="mpp-notice mpp-no-gallery-notice"> <p> <?php _ex('Nothing to see here!', 'No media Message', 'mediapress'); ?> </p> </div>
/** * 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'); }