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'; }
private function register_post_types() { $label = _x('Gallery', 'The Gallery Post Type Name', 'mediapress'); $label_plural = _x('Galleries', 'The Gallery Post Type Plural Name', 'mediapress'); $_labels = array('name' => $label_plural, 'singular_name' => $label, 'menu_name' => _x('MediaPress', 'MediaPress Admin menu name', 'mediapress'), 'name_admin_bar' => _x('MediaPress', 'MediaPress admin bar menu name', 'mediapress'), 'all_items' => _x('All Galleries', 'MediaPress All galleries label', 'mediapress'), 'add_new' => _x('Add Gallery', 'admin add new gallery menu label', 'mediapress'), 'add_new_item' => _x('Add Gallery', 'admin add gallery label', 'mediapress'), 'edit_item' => _x('Edit Gallery', 'admin edit gallery', 'mediapress'), 'new_item' => _x('Add Gallery', 'admin add new item label', 'mediapress'), 'view_item' => _x('View Gallery', 'admin view galery label', 'mediapress'), 'search_items' => _x('Search Galleries', 'admin search galleries lable', 'mediapress'), 'not_found' => _x('No Galleries found!', 'admin no galleries text', 'mediapress'), 'not_found_in_trash' => _x('No Galleries found in trash!', 'admin no galleries text', 'mediapress'), 'parent_item_colon' => _x('Parent Gallery', 'admin gallery parent label', 'mediapress')); // $this->_get_labels( $label, $label_plural ); $has_archive = false; if (mpp_get_option('enable_gallery_archive')) { $has_archive = mpp_get_option('gallery_archive_slug'); } $args = array('public' => true, 'publicly_queryable' => true, 'exclude_from_search' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'menu_position' => 10, 'menu_icon' => 'dashicons-format-gallery', 'show_in_admin_bar' => true, 'capability_type' => 'post', 'has_archive' => $has_archive, 'rewrite' => array('with_front' => false, 'slug' => mpp_get_gallery_post_type_rewrite_slug()), 'supports' => array('title', 'comments', 'custom-fields')); $args['labels'] = $_labels; register_post_type(mpp_get_gallery_post_type(), $args); add_rewrite_endpoint('edit', EP_PAGES); }
/** * Filter comment open/close status * * If BuddyPress is active, the WordPress comments on gallery/attachment is always disabled and we use the BuddyPress activity instead * * @param type $open * @param type $post_id * @return int */ function mpp_filter_comment_settings($open, $post_id) { $is_bp = 0; //if BuddyPress is active if (mediapress()->is_bp_active()) { $is_bp = 1; } if (mpp_is_valid_gallery($post_id)) { if (!mpp_get_option('enable_gallery_comment') || $is_bp) { $open = 0; } } elseif (mpp_is_valid_media($post_id)) { if (!mpp_get_option('enable_media_comment') || $is_bp) { $open = 0; } } return $open; }
/** * Is my Galleries filter enabled for the groups component * * @return boolean */ function mpp_group_is_my_galleries_enabled() { return mpp_get_option('groups_enable_my_galleries'); }
function mpp_get_gallery_grid_column_class($gallery = null) { //we are using 1-24 col grid, where 3-24 repsesents 1/8th and so on $col = mpp_get_option('gallery_columns'); return mpp_get_grid_column_class($col); }
/** * Setup everything for BuddyPress Specific installation * */ public function setup_globals($args = array()) { $bp = buddypress(); $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); }
/** * Is autopublishing enable for the given gallery action * * @param string $action create_gallery|upload_media * @return boolean */ function mpp_is_auto_publish_to_activity_enabled($action) { $enabled_types = mpp_get_option('autopublish_activities'); if (empty($enabled_types)) { return false; } if (in_array($action, $enabled_types)) { return true; } return false; }
/** * Load CSS on front end * */ public function load_css() { wp_register_style('mpp-core-css', $this->url . 'assets/css/mpp-core.css'); wp_register_style('mpp-extra-css', $this->url . 'assets/css/mpp-pure/mpp-pure.css'); wp_register_style('magnific-css', $this->url . 'assets/vendors/magnific/magnific-popup.css'); // //should we load the css everywhere or just on the gallery page //i am leaving it like this for now to avoid design issues on shortcode pages/widget //only load magnific css if the lightbox is enabled if (mpp_get_option('load_lightbox')) { wp_enqueue_style('magnific-css'); } wp_enqueue_style('mpp-extra-css'); wp_enqueue_style('mpp-core-css'); }
/** * Should we show gallery description on single gallery pages? * * @param type $gallery * @return boolean */ function mpp_show_gallery_description($gallery = false) { $gallery = mpp_get_gallery($gallery); $show = mpp_get_option('show_gallery_description'); //under theme tab in admin panel return apply_filters('mpp_show_gallery_description', $show, $gallery); }
function mpp_activity_create_comment_for_activity($activity_id) { if (!$activity_id || !mpp_get_option('activity_comment_sync')) { return; } $activity = new BP_Activity_Activity($activity_id); if ($activity->type != 'mpp_media_upload') { return; } $gallery_id = mpp_activity_get_gallery_id($activity_id); $media_id = mpp_activity_get_media_id($activity_id); //this is not MediaPress activity if (!$gallery_id && !$media_id) { return; } //parent post id for the comment $parent_id = $media_id > 0 ? $media_id : $gallery_id; //now, create a top level comment and save $comment_data = array('post_id' => $parent_id, 'user_id' => get_current_user_id(), 'comment_parent' => 0, 'comment_content' => $activity->content, 'comment_type' => mpp_get_comment_type()); $comment_id = mpp_add_comment($comment_data); //update comment meta if ($comment_id) { mpp_update_comment_meta($comment_id, '_mpp_activity_id', $activity_id); mpp_activity_update_associated_comment_id($activity_id, $comment_id); //also since there are media attched and we are mirroring activity, let us save the attached media too $media_ids = mpp_activity_get_attached_media_ids($activity_id); //it is a gallery upload post from activity if ($gallery_id && !empty($media_ids)) { //only available when sync is enabled if (function_exists('mpp_comment_update_attached_media_ids')) { mpp_comment_update_attached_media_ids($comment_id, $media_ids); } } //most probably a comment on media if (!empty($media_id)) { //should we add media as the comment meta? no, we don't need that at the moment } } }
/** * Should we show mdia description on single media pages? * * @param type $media * @return boolean */ function mpp_show_media_description($media = false) { $media = mpp_get_media($media); $show = mpp_get_option('show_media_description'); //under theme tab in admin panel return apply_filters('mpp_show_media_description', $show, $media); }
<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } /** * action: mediapress/gallery/gallery_name/ Activity comments * Activity Loop to show Single member's gallery Item Activity * **/ if (!function_exists('bp_is_active') || !bp_is_active('activity')) { return; } //if gallery comment is not enabled do not load it? if (!mpp_get_option('enable_gallery_comment')) { return; } ?> <div class="mpp-activity mpp-media-activity" id="mpp-media-activity-list"> <?php if (is_user_logged_in() && mpp_user_can_comment_on_gallery(mpp_get_current_gallery_id())) { ?> <?php mpp_locate_template(array('buddypress/activity/post-form.php'), true); ?> <?php
private function add_buddypress_panel($page) { if (!mediapress()->is_bp_active() || !(mpp_is_active_component('members') || mpp_is_active_component('groups'))) { return; } $panel = $page->add_panel('buddypress', _x('BuddyPress', 'Admin settings BuddyPress panel tab title', 'mediapress')); //directory settings $panel->add_section('directory-settings', _x('Directory Settings', 'Admin settings section title', 'mediapress'))->add_field(array('name' => 'has_gallery_directory', 'label' => _x('Enable Gallery Directory?', 'Admin settings', 'mediapress'), 'desc' => _x('Create a page to list all galleries?', 'Admin settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'has_media_directory', 'label' => _x('Enable Media directory?', 'Admin settings', 'mediapress'), 'desc' => _x('Create a page to list all photos, videos etc? Please keep it disabled for now )', 'Admin settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); //activity settings $activity_section = $panel->add_section('activity-settings', _x('Activity Settings', 'Admin settings section title', 'mediapress')); $activity_section->add_field(array('name' => 'activity_upload', 'label' => _x('Allow Activity Upload?', 'Admin settings', 'mediapress'), 'desc' => _x('Allow users to uploading from Activity screen?', 'Admin settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); $activity_options = array('create_gallery' => _x('New Gallery is created.', 'Admin settings', 'mediapress'), 'add_media' => _x('New Media added/uploaded.', 'Admin settings', 'mediapress')); $default_activities = mpp_get_option('autopublish_activities'); //if( empty( $default_activities ) ) { //$default_activities = array_keys( $activity_options ); //} if (!empty($default_activities)) { $default_activities = array_combine($default_activities, $default_activities); } $activity_section->add_field(array('name' => 'autopublish_activities', 'label' => _x('Automatically Publish to activity When?', 'Admin settings', 'mediapress'), 'type' => 'multicheck', 'options' => $activity_options, 'default' => $default_activities)); //6th section //directory settings $this->add_activity_views_panel($panel); $panel->add_section('misc-settings', _x('Miscellaneous Settings', 'Admin settings section title', 'mediapress'))->add_field(array('name' => 'show_orphaned_media', 'label' => _x('Show orphaned media to the user?', 'Admin settings option', 'mediapress'), 'desc' => _x('Do you want to list the media if it was uploaded from activity but the activity was not published?', 'Admin settings', 'mediapress'), 'type' => 'radio', 'default' => 0, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'delete_orphaned_media', 'label' => _x('Delete orphaned media automatically?', 'Admin settings', 'mediapress'), 'desc' => _x('Do you want to delete the abandoned media uploade from activity?', 'Admin settings', 'mediapress'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); }
<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } /** * Single Media Activity list * * @package mediapress */ if (!mpp_get_option('enable_media_comment')) { return; } ?> <?php do_action('mpp_before_activity_loop'); ?> <div class="mpp-activity mpp-media-activity " id="mpp-media-activity-list"> <?php if (is_user_logged_in() && mpp_media_user_can_comment(mpp_get_current_media_id())) { ?> <?php mpp_locate_template(array('activity/post-form.php'), true); ?> <?php
/** * 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); }
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 }
/** * 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'); }
function mpp_media_user_can_comment($media_id) { //for now, just return true return true; //in future, add an option in settings and aslo we can think of doing something for the user if (mpp_get_option('allow_media_comment')) { return true; } return false; }
/** * Return default storage method * local|s3|ftp etc * @return string default storage method */ function mpp_get_default_storage_method() { return apply_filters('mpp_get_default_storage_method', mpp_get_option('default_storage', 'local')); }
/** * 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; }
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, 'gallery_id' => false, 'galleries' => false, 'galleries_exclude' => false, 'storage' => '', 'per_page' => mpp_get_option('media_per_page'), 'offset' => false, 'page' => false, 'nopaging' => false, 'order' => 'DESC', 'orderby' => false, 'user_id' => false, 'user_name' => false, 'scope' => false, 'search_terms' => '', 'year' => false, 'month' => false, 'week' => '', 'day' => '', 'hour' => '', 'minute' => '', 'second' => '', 'yearmonth' => '', 'meta_query' => false, 'fields' => false); //build params for WP_Query /** * If are querying for a single gallery * and the gallery media were sorted by the user, show the media s in the sort order insted of the default date */ if (isset($args['gallery_id']) && mpp_is_gallery_sorted($args['gallery_id'])) { $defaults['orderby'] = 'menu_order'; } $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); //build the wp_query args $wp_query_args = array('post_type' => mpp_get_media_post_type(), 'post_status' => 'any', 'p' => $id, 'post__in' => $in, 'post__not_in' => $exclude, 'name' => $slug, 'post_parent' => $gallery_id, 'post_parent__in' => !empty($galleries) ? (array) $galleries : 0, 'post_parent__not_in' => !empty($galleries_exclude) ? (array) $galleries_exclude : 0, 'posts_per_page' => $per_page, 'paged' => $page, 'offset' => $offset, 'nopaging' => $nopaging, 'author' => $user_id, 'author_name' => $user_name, '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); //TODO: SCOPE // //we will need to build tax query/meta query //taxonomy query to filter by component|status|privacy $tax_query = array(); //meta query $gmeta_query = array(); if (isset($meta_key) && $meta_key) { $wp_query_args['meta_key'] = $meta_key; } if (isset($meta_key) && $meta_key && isset($meta_value)) { $wp_query_args['meta_value'] = $meta_value; } //if meta query was specified, let us keep it and we will add our conditions if (!empty($meta_query)) { $gmeta_query = $meta_query; } //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 if ($gallery_id) { //if gallery id is given, avoid worrying about type $type = ''; $component = ''; } if (!empty($type) && mpp_are_registered_types($type)) { $type = mpp_string_to_array($type); //we store the terms with _name such as private becomes _private, members become _members to avoid conflicting terms $type = array_map('mpp_underscore_it', $type); $tax_query[] = array('taxonomy' => mpp_get_type_taxname(), 'field' => 'slug', 'terms' => $type, 'operator' => 'IN'); } //privacy //pass one 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'; } if (!empty($tax_query)) { $wp_query_args['tax_query'] = $tax_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'); } //also make sure that it only looks for gallery media $gmeta_query[] = array('key' => '_mpp_is_mpp_media', 'value' => 1, 'compare' => '=', 'type' => 'UNSIGNED'); //should we avoid the orphaned media //Let us discuss with the community and get it here if (!mpp_get_option('show_orphaned_media')) { $gmeta_query[] = array('key' => '_mpp_is_orphan', 'compare' => 'NOT EXISTS'); } //Let us filter the media by storage method if (!empty($storage)) { $gmeta_query[] = array('key' => '_mpp_storage_method', 'value' => $storage, 'compare' => '='); } //and what to do when a user searches by the media source(say youtube|vimeo|xyz.. how do we do that?) //reset meta query if (!empty($gmeta_query)) { $wp_query_args['meta_query'] = $gmeta_query; } return $wp_query_args; //http://wordpress.stackexchange.com/questions/53783/cant-sort-get-posts-by-post-mime-type }
function mpp_component_get_supported_types($component) { $option = $component . '_active_types'; return mpp_get_option($option, array()); }
/** * Does the gallery or type supports playlist * * @param type $gallery_id * @param type $type * @return boolean */ function mpp_gallery_supports_playlist($gallery_id = null, $type = null) { if ($gallery_id) { $gallery = mpp_get_gallery($gallery_id); $type = $gallery->type; } //currently ardcoded types, in future, we will allow registering support if (!$type) { return false; } if ($type != 'audio' && $type != 'video') { return false; } //let us not worry about individual gallery preference yet if (mpp_get_option('enable_' . $type . '_playlist')) { // enable_audio_playlist, enable_video_playlist return true; } return false; }
/** * Generate meta data for the media * * @since 1.0.0 * * @access private * @param int $attachment_id Media ID to process. * @param string $file Filepath of the Attached image. * * @return mixed Metadata for attachment. */ public function generate_metadata($attachment_id, $file) { $attachment = get_post($attachment_id); $mime_type = get_post_mime_type($attachment); $metadata = array(); if (preg_match('!^image/!', $mime_type) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); //get the registered media sizes $sizes = mpp_get_media_sizes(); $sizes = apply_filters('mpp_intermediate_image_sizes', $sizes, $attachment_id); if ($sizes) { $editor = wp_get_image_editor($file); if (!is_wp_error($editor)) { $metadata['sizes'] = $editor->multi_resize($sizes); } } else { $metadata['sizes'] = array(); } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } elseif (preg_match('#^video/#', $mime_type)) { $metadata = wp_read_video_metadata($file); } elseif (preg_match('#^audio/#', $mime_type)) { $metadata = wp_read_audio_metadata($file); } $dir_path = trailingslashit(dirname($file)) . 'covers'; $url = wp_get_attachment_url($attachment_id); $base_url = str_replace(wp_basename($url), '', $url); //processing for audio/video cover if (!empty($metadata['image']['data'])) { $ext = '.jpg'; switch ($metadata['image']['mime']) { case 'image/gif': $ext = '.gif'; break; case 'image/png': $ext = '.png'; break; } $basename = str_replace('.', '-', basename($file)) . '-image' . $ext; $uploaded = $this->upload_bits($basename, $metadata['image']['data'], array('path' => $dir_path, 'url' => $base_url)); if (false === $uploaded['error']) { $attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => ''); $sub_attachment_id = wp_insert_attachment($attachment, $uploaded['file']); $attach_data = $this->generate_metadata($sub_attachment_id, $uploaded['file']); wp_update_attachment_metadata($sub_attachment_id, $attach_data); //if the option is set to set post thumbnail if (mpp_get_option('set_post_thumbnail')) { mpp_update_media_meta($attachment_id, '_thumbnail_id', $sub_attachment_id); } //set the cover id mpp_update_media_cover_id($attachment_id, $sub_attachment_id); } } // remove the blob of binary data from the array if (isset($metadata['image']['data'])) { unset($metadata['image']['data']); } return apply_filters('mpp_generate_metadata', $metadata, $attachment_id); }
/** * Get activity view id * * @param type $type * @return type */ function mpp_get_activity_view_id($type) { $key = "activity_{$type}_default_view"; $view_id = mpp_get_option($key, 'default'); return $view_id; }