function mpp_group_is_gallery_enabled($group_id = false) { //is groups component enabled? if (mpp_is_active_component('groups')) { $is_enabled = true; } else { $is_enabled = false; } //if component is not enabled, return false if (!$is_enabled) { return false; } if (!$group_id) { $group = groups_get_current_group(); if (!empty($group)) { $group_id = $group->id; } } if (!$group_id) { return false; } //check for group settings $is_enabled = groups_get_groupmeta($group_id, '_mpp_is_enabled', true); //if current group has no preference set, fallback to global preference //this global preference can be set by visting Dashboard->MediaPress->Settings->Groups if (empty($is_enabled)) { $is_enabled = mpp_get_option('enable_group_galleries_default', 'yes'); } return $is_enabled == 'yes'; }
/** * Are we on component gallery * * Is gallery associated to a component(groups/events etc) * * @return boolean */ function mpp_is_component_gallery() { $is_gallery = false; if (bp_is_current_action(MPP_GALLERY_SLUG) && mpp_is_active_component(bp_current_component())) { $is_gallery = true; } return apply_filters('mpp_is_component_gallery', $is_gallery); }
function mppp_group_enable_form() { if (!mpp_is_active_component('groups')) { return; //do not show if gallery is not enabled for group component } ?> <div class="checkbox mpp-group-gallery-enable"> <label><input type="checkbox" name="mpp-enable-gallery" id="mpp-enable-gallery" value="yes" <?php echo checked(1, mpp_group_is_gallery_enabled()); ?> /> <?php _e('Enable Gallery', 'mediapress'); ?> </label> </div> <?php }
public function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); if (mpp_is_active_component($new_instance['component'])) { $instance['component'] = $new_instance['component']; } if (mpp_is_active_type($new_instance['type'])) { $instance['type'] = $new_instance['type']; } if (mpp_is_active_status($new_instance['status'])) { $instance['status'] = $new_instance['status']; } $instance['per_page'] = absint($new_instance['per_page']); $instance['orderby'] = $new_instance['orderby']; $instance['order'] = $new_instance['order']; return $instance; }
function mpp_group_is_gallery_enabled($group_id = false) { if (!$group_id) { $group = groups_get_current_group(); if (!empty($group)) { $group_id = $group->id; } } if (!$group_id) { return false; } //default settings from gloabl $is_enabled = groups_get_groupmeta($group_id, '_mpp_is_enabled', true); //if not set, get the global settings if (empty($is_enabled)) { if (mpp_is_active_component('groups')) { $is_enabled = 'yes'; } else { $is_enabled = 'no'; } } return $is_enabled == 'yes'; // if is_enabled is set to yes }
/** * Load the Page template for MediaPress Single Sitewide Gallery * Looks for mediapress/default/single-gallery-$type-$status.php * mediapress/default/single-gallery-$type.php * mediapress/default/single-gallery.php * single-mpp-gallery.php * singular.php * index.php * in the child theme, then parent theme and finally falls back to check in wp-content/mediapress/template/mediapress/default * We don't provide any default copy for this as we are not going to mess with the page layout. Still, a theme developer has the choice to do it their own way * * Look at template_include hook and * * @see get_single_template() * @see get_query_template() * * @param string $template absolute path to the template file * @return string absolute path to the template file */ function mpp_filter_single_template_for_sitewide_gallery($template) { //our sitewide gallery is not enabled or we are not on single sitewide gallery no need to bother if (!mpp_is_active_component('sitewide') || !mpp_is_sitewide_gallery_component()) { return $template; } $default_template = 'mediapress/default/sitewide/home.php'; //modify it to use the current default template //load our template //should we load separate template for edit actions? $gallery = mpp_get_current_gallery(); $media = mpp_get_current_media(); $templates = array($default_template); /*if( $media ) { $type = $media->type; $status = $media->status; $slug = 'single-media'; //this is single media page } elseif( $gallery ) { //single gallery page $slug = 'single-gallery'; $type = $gallery->type; $status = $gallery->status; } //look inside theme's mediapress/ directory $templates = $default_template . $slug . '-' . $type . '-' . $status . '.php';//single-gallery-photo-public.php/single-media-photo-public.php $templates = $default_template . $slug . '-' . $type . '.php'; //single-gallery-photo.php/single-media-photo.php $templates = $default_template . $slug . '.php'; //single-gallery.php/single-media.php */ //we need to locate the template and if the template is not present in the themes, we need to setup theme compat $located = locate_template($templates); if ($located) { //mediapress()->set_theme_compat( false ); $template = $located; } else { //if not found, setup theme compat mpp_setup_sitewide_gallery_theme_compat(); } return $template; }
public function show_status_drodown() { if (!$this->is_add_gallery() && !$this->is_edit_gallery()) { return; } $is_new = false; if ($this->is_add_gallery()) { $is_new = true; } global $post; //_prime_post_caches( (array) $id , true, true ); $gallery = mpp_get_gallery($post); $component = $is_new ? '' : $gallery->component; $type = $is_new ? '' : $gallery->type; if (empty($type)) { $type = $this->get_editing_gallery_type(); } $selected = $is_new ? mpp_get_default_status() : $gallery->status; if (!$component && mpp_is_active_component('sitewide')) { $component = 'sitewide'; } ?> <div class='misc-status-section'> <label for='mpp-gallery-status'> <strong><?php _e('Status', 'mediapress'); ?> </strong> <?php mpp_status_dd(array('selected' => $selected, 'component' => $component)); // ?> </label> <input type='hidden' name="mpp-gallery-component-id" value="<?php echo $this->get_component_id($post->ID); ?> " /> <input type='hidden' name="mpp-gallery-type" value="<?php echo $type; ?> " /> <input type='hidden' name="mpp-gallery-component" value="<?php echo $component; ?> " /> </div> <?php }
/** * For sitewide galleries, we add rewrite end points * * @return type */ public function add_rewrite_endpoints() { if (!mpp_is_active_component('sitewide')) { return; } add_rewrite_endpoint('manage', EP_PERMALINK); add_rewrite_endpoint('media', EP_PERMALINK); }
/** * Set up the Toolbar. * * @param array $wp_admin_nav See {BP_Component::setup_admin_bar()} * for details. */ public function setup_admin_bar($wp_admin_nav = array()) { $bp = buddypress(); // Menus for logged in user if the members gallery is enabled if (is_user_logged_in() && mpp_is_active_component('members')) { $component = 'members'; $component_id = get_current_user_id(); $gallery_link = trailingslashit(mpp_get_gallery_base_url($component, $component_id)); $title = __('Gallery', 'mediapress'); $my_galleries = __('My Gallery', 'mediapress'); $create = __('Create', 'mediapress'); // Add main mediapress menu $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => trailingslashit($gallery_link)); // Add main mediapress menu $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-my-galleries', 'title' => $my_galleries, 'href' => trailingslashit($gallery_link)); if (mpp_user_can_create_gallery($component, $component_id)) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => $create, 'href' => mpp_get_gallery_create_url($component, $component_id)); } } parent::setup_admin_bar($wp_admin_nav); }
/** * Can the current user upload? * * @param type $component * @param type $component_id * @param type $gallery * @return boolean */ function mpp_user_can_upload($component, $component_id, $gallery = null) { if (!is_user_logged_in()) { return false; } $can_do = false; $user_id = get_current_user_id(); if (is_super_admin()) { $can_do = true; } elseif (mediapress()->is_bp_active() && $component == 'members' && $component_id == $user_id) { $can_do = true; } elseif (mpp_is_active_component('groups') && $component == 'groups' && function_exists('groups_is_user_member') && groups_is_user_member($user_id, $component_id)) { $can_do = true; } elseif (mpp_is_active_component('sitewide') && $component == 'sitewide' && $component_id == $user_id) { $can_do = true; } $can_do = apply_filters('mpp_user_can_upload', $can_do, $component, $component_id, $gallery); return apply_filters("mpp_can_user_upload_to_{$component}", $can_do, $gallery); }
function mpp_update_gallery($args) { if (!isset($args['id'])) { return new WP_Error(0, __('Must provide ID to update a gallery.', 'mediapress')); } $gallery = get_post($args['id']); //we need meaning full error handling in future if (!$gallery) { return new WP_Error(0, __('Gallery Does not exist!', 'mediapress')); } // $gdata = get_object_vars( $gallery ); $gallery_data = array('id' => $gallery->ID, 'title' => $gallery->post_title, 'description' => $gallery->post_content, 'slug' => $gallery->post_name, 'creator_id' => $gallery->post_author, 'order' => $gallery->menu_order, 'component_id' => mpp_get_gallery_meta($gallery->ID, '_mpp_component_id'), 'component' => '', 'status' => '', 'type' => '', 'date_created' => '', 'date_modified' => ''); $args = wp_parse_args($args, $gallery_data); extract($args); if (empty($id) || empty($title)) { return false; } //now let us check which fields need to be updated if ($creator_id) { $gallery->post_author = $creator_id; } if ($title) { $gallery->post_title = $title; } if ($description) { $gallery->post_content = $description; } if ($slug) { $gallery->post_name = $slug; } if ($order) { $gallery->menu_order = $order; } $post = get_object_vars($gallery); $tax = array(); if ($component && mpp_is_active_component($component)) { $tax[mpp_get_component_taxname()] = mpp_underscore_it($component); } if ($type && mpp_is_active_type($type)) { $tax[mpp_get_type_taxname()] = mpp_underscore_it($type); } if ($status && mpp_is_active_status($status)) { $tax[mpp_get_status_taxname()] = mpp_underscore_it($status); } if (!empty($tax)) { $post['tax_input'] = $tax; } //$post['ID'] = $gallery->id; if (!empty($date_created)) { $post_data['post_date'] = $date_created; } if (!empty($date_updated)) { $post_data['post_modified'] = $date_updated; } $gallery_id = wp_update_post($post); if (is_wp_error($gallery_id)) { return $gallery_id; //error } do_action('mpp_gallery_updated', $gallery_id); return $gallery_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; }
/** * Add various upload icons to activity post form * @return type */ function mpp_activity_upload_buttons() { if (!mpp_is_activity_upload_enabled(mpp_get_current_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 (bp_is_user() && !mpp_is_active_component('members')) { 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; } $component = mpp_get_current_component(); ?> <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 }
/** * 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); }
private function add_groups_panel($page) { if (!mediapress()->is_bp_active() || !mpp_is_active_component('groups')) { return; } $panel = $page->add_panel('groups', _x('Groups Gallery', 'Admin settings BuddyPress panel tab title', 'mediapress')); $this->add_type_settings($panel, 'groups'); $this->add_gallery_views_panel($panel, 'groups'); $panel->add_section('group-settings', _x('Group Settings', 'Admin settings section title', 'mediapress'))->add_field(array('name' => 'enable_group_galleries_default', 'label' => _x('Enable group galleries by default?', 'Admin settings group section', 'mediapress'), 'desc' => _x('If you set yes, Group galleries will be On by default for all the groups. A group admin can turn off by visiting settings though.', 'Admin settings group section', 'mediapress'), 'type' => 'radio', 'default' => 'yes', 'options' => array('yes' => _x('Yes', 'Admin settings option', 'mediapress'), 'no' => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'contributors_can_edit', 'label' => _x('Contributors can edit their own media?', 'Admin settings group section', 'mediapress'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'contributors_can_delete', 'label' => _x('Contributors can delete their own media?', 'Admin settings group section', 'mediapress'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); }
/** * Get current component type * @return type */ function mpp_get_current_component() { if (isset($_POST['_mpp_current_component'])) { $component = trim($_POST['_mpp_current_component']); if (!mpp_is_active_component($component)) { $component = ''; } } elseif (!mediapress()->is_bp_active() || mpp_is_sitewide_gallery_component()) { //if BuddyPress is not active, or BuddyPress is active and we are on the sitewide gallery page $component = 'sitewide'; } else { $component = 'members'; //may not be the best idea } return strtolower(apply_filters('mpp_get_current_component', $component)); //context sensitive }