function mpp_gallery_show_publish_gallery_activity_button() { if (!mediapress()->is_bp_active()) { return; } $gallery_id = mpp_get_current_gallery_id(); //if not a valid gallery id or no unpublished media exists, just don't show it if (!$gallery_id || !mpp_gallery_has_unpublished_media($gallery_id)) { return; } $gallery = mpp_get_gallery($gallery_id); $unpublished_media = mpp_gallery_get_unpublished_media($gallery_id); //unpublished media count $unpublished_media_count = count($unpublished_media); $type = $gallery->type; $type_name = _n($type, $type . 's', $unpublished_media_count); //if we are here, there are unpublished media ?> <div id="mpp-unpublished-media-info"> <p> <?php printf(__('You have %d %s not published to actvity.', 'mediapress'), $unpublished_media_count, $type_name); ?> <span class="mpp-gallery-publish-activity"><?php mpp_gallery_publish_activity_link($gallery_id); ?> </span> <span class="mpp-gallery-unpublish-activity"><?php mpp_gallery_unpublished_media_delete_link($gallery_id); ?> </span> </p> </div> <?php }
public function display() { $path = mediapress()->get_path(); if (!class_exists('Browser')) { require_once $path . 'admin/tools/lib/browser.php'; } require_once $path . 'admin/tools/debug/mpp-debug-output.php'; }
function mpp_current_component_id_for_user($component_id) { if (mediapress()->is_bp_active() && bp_is_user()) { return bp_displayed_user_id(); //that is displayed user id } return $component_id; }
function mpp_group_extension_load() { $files = array('mpp-bp-groups-actions.php', 'mpp-bp-groups-functions.php', 'mpp-bp-groups-hooks.php', 'mpp-bp-groups-group-extension.php'); $path = mediapress()->get_path() . 'modules/buddypress/groups/'; foreach ($files as $file) { require_once $path . $file; } do_action('mpp_group_extension_loaded'); }
/** * Install tables required by MediaPress * Currently, we create only one table ( Log table ) * * @global WPDB $wpdb */ function mpp_install_db() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset_collate = !empty($wpdb->charset) ? "DEFAULT CHARACTER SET {$wpdb->charset}" : ''; $sql = array(); $log_table = mediapress()->get_table_name('logs'); $sql[] = "CREATE TABLE IF NOT EXISTS {$log_table} (\n\t\tid bigint(20) NOT NULL AUTO_INCREMENT,\n\t\tuser_id bigint(20) NOT NULL,\n\t\titem_id bigint(20) NOT NULL,\n\t\taction varchar(16) NOT NULL,\n\t\tvalue varchar(32) NOT NULL,\n\t\tlogged_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,\n\t\tPRIMARY KEY (id)\n\t) {$charset_collate};"; dbDelta($sql); }
public function load() { $path = mediapress()->get_path() . 'modules/buddypress/'; $files = array('mpp-bp-component.php', 'activity/class-mpp-activity-media-cache-helper.php', 'activity/mpp-activity-functions.php', 'activity/mpp-activity-actions.php', 'activity/mpp-activity-template.php', 'activity/mpp-activity-hooks.php', 'groups/mpp-bp-groups-loader.php'); foreach ($files as $file) { require_once $path . $file; } //MediaPress BuddyPress module is loaded now do_action('mpp_buddypress_module_loaded'); }
private function __construct() { $this->url = mediapress()->get_url(); //load js on front end add_action('wp_enqueue_scripts', array($this, 'load_js')); add_action('wp_enqueue_scripts', array($this, 'add_js_data')); //load admin js add_action('admin_enqueue_scripts', array($this, 'load_js')); add_action('wp_enqueue_scripts', array($this, 'load_css')); add_action('wp_footer', array($this, 'footer')); }
/** * Load ajax handlers * * @return type */ public function load_ajax_handlers() { if (!defined('DOING_AJAX')) { return; } $files = array('core/ajax/mpp-ajax.php', 'core/ajax/class-mpp-ajax-comment-helper.php'); $path = mediapress()->get_path(); foreach ($files as $file) { require_once $path . $file; } }
function mpp_shortcode_reset_data($type, $key = null) { $data = mediapress()->get_data('shortcode'); //, = $shortcode_column; if (!$key) { unset($data[$type]); } else { unset($data[$type][$key]); } mediapress()->add_data('shortcode', $data); //save the updated data }
function mpp_widget_reset_data($type, $key = null) { $data = mediapress()->get_data('widget'); //, = $widget_column; if (!$key) { unset($data[$type]); } else { unset($data[$type][$key]); } mediapress()->add_data('widget', $data); //save the updated data }
function mpp_filter_body_class($classes, $class) { $new_classes = array(); $component = mpp_get_current_component(); //if not mediapress pages, return if (!mpp_is_gallery_component() && !mpp_is_component_gallery()) { return $classes; } //ok, It must be mpp pages $new_classes[] = 'mpp-page'; //for all mediapress pages //if it is a directory page if (mpp_is_gallery_directory()) { $new_classes[] = 'mpp-page-directory'; } elseif (mpp_is_gallery_component() || mpp_is_component_gallery()) { //we are on user gallery page or a component gallery page //append class mpp-page-members or mpp-page-groups or mpp-page-events etc depending on the current associated component $new_classes[] = 'mpp-page-' . $component; if (mpp_is_media_management()) { //is it edit media? $new_classes[] = 'mpp-page-media-management'; $new_classes[] = 'mpp-page-media-management-' . mpp_get_media_type(); //mpp-photo-management, mpp-audio-management $new_classes[] = 'mpp-page-media-manage-action-' . mediapress()->get_edit_action(); //mpp-photo-management, mpp-audio-management } elseif (mpp_is_single_media()) { //is it single media $new_classes[] = 'mpp-page-media-single'; $new_classes[] = 'mpp-page-media-single-' . mpp_get_media_type(); } elseif (mpp_is_gallery_management()) { //id gallery management? $new_classes[] = 'mpp-page-gallery-management'; $new_classes[] = 'mpp-page-gallery-management-' . mpp_get_gallery_type(); $new_classes[] = 'mpp-page-gallery-manage-action-' . mediapress()->get_edit_action(); } elseif (mpp_is_single_gallery()) { //is singe gallery $new_classes[] = 'mpp-page-single-gallery'; $new_classes[] = 'mpp-page-single-gallery-' . mpp_get_gallery_type(); $new_classes[] = 'mpp-page-single-gallery-' . mpp_get_gallery_status(); } else { //it is the gallery listing page of the component $new_classes[] = 'mpp-page-gallery-list'; //home could have been a better name $new_classes[] = 'mpp-page-gallery-list-' . $component; //home could have been a better name } } if (!empty($new_classes)) { $classes = array_merge($classes, $new_classes); } return $classes; }
private function register_taxonomy($taxonomy, $args) { extract($args); if (empty($taxonomy)) { return false; } $labels = self::_get_tax_labels($label, $labels); if (empty($slug)) { $slug = $taxonomy; } register_taxonomy($taxonomy, false, array('hierarchical' => $hierarchical, 'labels' => $labels, 'public' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'show_ui' => false, 'show_tagcloud' => true, 'capabilities' => array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'read'), 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array('with_front' => true, 'hierarchical' => $hierarchical))); mediapress()->taxonomies[$taxonomy] = $args; }
function mpp_admin_load() { if (!is_admin() || is_admin() && defined('DOING_AJAX')) { return; } $path = mediapress()->get_path() . 'admin/'; $files = array('mpp-admin-functions.php', 'mpp-admin.php', 'class-mpp-admin-post-helper.php', 'class-mpp-admin-gallery-list-helper.php', 'tools/debug/mpp-admin-debug-helper.php', 'class-mpp-admin-edit-gallery-panel.php'); foreach ($files as $file) { require_once $path . $file; } //class_alias( 'MPP_Admin_Settings_Page' , 'MPP_Admin_Page' ); do_action('mpp_admin_loaded'); }
/** * Loads directroy gallery list via ajax * */ public function load_dir_list() { $type = isset($_POST['filter']) ? $_POST['filter'] : ''; $page = absint($_POST['page']); $scope = $_POST['scope']; $search_terms = $_POST['search_terms']; //make the query and setup mediapress()->is_directory = true; //get all public galleries, should we do type filtering mediapress()->the_gallery_query = new MPP_Gallery_Query(array('status' => 'public', 'type' => $type, 'page' => $page, 'search_terms' => $search_terms)); mpp_get_template('gallery/loop-gallery.php'); exit(0); }
/** * Add media to the list of unpublished media * * @param int $gallery_id * @param int|array $media_ids single media id or an array of media ids */ function mpp_gallery_add_unpublished_media($gallery_id, $media_ids) { if (!mediapress()->is_bp_active()) { return; } $media_ids = (array) $media_ids; // one or more media is given $unpublished = mpp_gallery_get_unpublished_media($gallery_id); $media_ids = array_diff($media_ids, $unpublished); //add all new media ids to the unpublished list foreach ($media_ids as $new_media_id) { mpp_add_gallery_meta($gallery_id, '_mpp_unpublished_media_id', $new_media_id); } }
/** * Filter get_permalink for mediapress gallery post type( mpp-gallery) * aand make it like site.com/members/username/mediapressslug/gallery-name or site.com/{component-page}/{single-component}/mediapress-slug/gallery-name * It allows us to get the permalink to gallery by using the_permalink/get_permalink functions */ function mpp_filter_gallery_permalink($permalink, $post, $leavename, $sample) { //check if BuddyPress is active, if not, we don't filter it yet //lightweight check if (!mediapress()->is_bp_active()) { return $permalink; } //a little more expensive if (mpp_get_gallery_post_type() != $post->post_type) { return $permalink; } //this is expensive if the post is not cached //If you see too many queries, just make sure to call _prime_post_caches($ids, true, true ); where $ids is collection of post ids //that will save a lot of query $gallery = mpp_get_gallery($post); // do not modify permalinks for Sitewide gallery if ($gallery->component == 'sitewide') { return $permalink; } $slug = $gallery->slug; $base_url = mpp_get_gallery_base_url($gallery->component, $gallery->component_id); return apply_filters('mpp_get_gallery_permalink', $base_url . '/' . $slug, $gallery); }
/** * Render the 'template_notices' feedback message. * * The hook action 'template_notices' is used to call this function, it is not * called directly. */ function mpp_core_render_feedback() { // Get MediaPress $mp = mediapress(); if (!empty($mp->template_message)) { $type = 'success' === $mp->template_message_type ? 'updated' : 'error'; $content = apply_filters('mpp_core_render_feedback_content', $mp->template_message, $type); ?> <div id="message" class="bp-template-notice mpp-template-notice <?php echo esc_attr($type); ?> "> <?php echo wpautop($content); ?> </div> <?php do_action('mpp_core_render_feedback'); } }
/** * Fetch the current comment * * @return type */ function mpp_the_comment() { $the_comment_query = mediapress()->the_comment_query; return $the_comment_query->the_comment(); }
function mpp_get_asset_url($rel_path, $key) { $url = mediapress()->get_asset($key); //check if it exists in users template folder if (!$url) { $template_dir = mpp_get_template_dir_name(); //'mediapress' $url = ''; if (file_exists(STYLESHEETPATH . '/' . $template_dir . '/' . $rel_path)) { $url = get_stylesheet_directory_uri() . '/' . $template_dir . '/' . $rel_path; } elseif (file_exists(TEMPLATEPATH . '/' . $template_dir . '/' . $rel_path)) { $url = get_template_directory_uri() . '/' . $template_dir . '/' . $rel_path; } if (!$url) { $url = mediapress()->get_url() . 'templates/' . $template_dir . '/' . $rel_path; } //assume that the asset exists in our default template //upadet in mpp asset cache mediapress()->add_asset($key, $url); } return apply_filters('mpp_get_asset_url', $url, $rel_path); }
public function is_bp_active() { static $is_active; if (isset($is_active)) { return $is_active; } //if we are here, It is the first time $is_active = function_exists('buddypress'); return $is_active; } public function set_theme_compat($bool) { $this->using_theme_compat = $bool; } public function is_using_theme_compat() { return $this->using_theme_compat; } } /** * A shortcut function to allow access to the singleton instance of the MediaPress * * @return MediaPress */ function mediapress() { return MediaPress::get_instance(); } //initialize mediapress();
/** * * @return MPP_Logger */ function mpp_get_logger() { if (!class_exists('MPP_DB_Logger')) { mediapress()->load_logger(); } return MPP_DB_Logger::get_instance(); }
/** * Get current Gallery * @return MPP_Gallery|null */ function mpp_get_current_gallery() { return mediapress()->current_gallery; }
/** * Maps 'delete_attachment' to mpp_before_media_delete action * Also, cleans up cover, decrements media count and deletes activities associated * * @param type $media_id * @return type */ public function map_before_delete_attachment_action($media_id) { if (!mpp_is_valid_media($media_id)) { //the attachment is not media return; } //this is just a precaution in case some faulty plugin calls it again //if everything is normal, we don't need to check for this if ($this->is_queued($media_id)) { return; // } //push this media to teh queue $this->add_item($media_id, 'media'); /** * mpp_before_media_delete action fires before WordPress starts deleting an attachment which is a valid media( in MediaPress). * Any plugin utilizing this action can access the fully functional media object by using mpp_get_media() on the passed media id * */ do_action('mpp_before_media_delete', $media_id); $storage_manager = mpp_get_storage_manager($media_id); $storage_manager->delete_media($media_id); //delete if it is set as cover delete_metadata('post', null, '_mpp_cover_id', $media_id, true); // delete all for any posts. delete_metadata('post', null, '_mpp_unpublished_media_id', $media_id, true); // delete all for any posts. // //if media has cover, delete the cover $media = mpp_get_media($media_id); $gallery_id = $media->gallery_id; if (mpp_media_has_cover_image($media_id)) { mpp_delete_media(mpp_get_media_cover_id($media_id)); } if (apply_filters('mpp_cleanup_single_media_on_delete', true, $media_id, $gallery_id)) { mpp_gallery_decrement_media_count($gallery_id); if (mediapress()->is_bp_active()) { //delete all activities related to this media //mpp_media_delete_activities( $media_id ); mpp_delete_activity_for_single_published_media($media_id); //delete all activity meta key where this media is associated mpp_media_delete_activity_meta($media_id); } } return; }
/** * Everything starts here */ private function __construct() { parent::start('mediapress', __('Gallery', 'mediapress'), untrailingslashit(mediapress()->get_path())); //mark it as active component, otherwise notifications will not be rendered buddypress()->active_components[$this->id] = 1; }
/** * Load CSS on Add New/Edit Gallery page in admin * @return type */ public function load_css() { if (!$this->is_add_gallery() && !$this->is_edit_gallery()) { return; } $url = mediapress()->get_url(); wp_register_style('mpp-core-css', $url . 'assets/css/mpp-core.css'); wp_register_style('mpp-extra-css', $url . 'assets/css/mpp-pure/mpp-pure.css'); wp_register_style('mpp-admin-css', $url . 'admin/assets/css/mpp-admin.css'); wp_enqueue_style('mpp-core-css'); wp_enqueue_style('mpp-extra-css'); wp_enqueue_style('mpp-admin-css'); }
/** * Render media admin tabs * * @param type $media */ function mpp_media_menu($media) { $media = mpp_get_media($media); mediapress()->get_menu('media')->render($media); }
/** * Retrieves gallery data given a gallery id or gallery object. * * @param int|object $gallery gallery id or gallery object. Optional, default is the current gallery from the loop. * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N. * @param string $filter Optional, default is raw. * * @return MPP_Gallery|null MPP_Gallery on success or null on failure */ function mpp_get_gallery($gallery = null, $output = OBJECT) { $_gallery = null; $needs_caching = false; //if gallery is not given, but we do have current_gallery setup if (empty($gallery) && mediapress()->current_gallery) { $gallery = mediapress()->current_gallery; } if (!$gallery) { return null; } //if already an instance of gallery object if (is_a($gallery, 'MPP_Gallery')) { $_gallery = $gallery; } elseif (is_numeric($gallery)) { $_gallery = mpp_get_gallery_from_cache($gallery); if (!$_gallery) { $_gallery = new MPP_Gallery($gallery); $needs_caching = true; } } elseif (is_object($gallery)) { //first check if we already have it cached $_gallery = mpp_get_gallery_from_cache($gallery->ID); if (!$_gallery) { $_gallery = new MPP_Gallery($gallery); $needs_caching = true; } } //save to cache if not already in cache if ($needs_caching && !empty($_gallery) && $_gallery->id) { mpp_add_gallery_to_cache($_gallery); } if (!$_gallery) { return null; } //if the gallery has no id set if (!$_gallery->id) { return null; } if ($output == ARRAY_A) { return $_gallery->to_array(); } elseif ($output == ARRAY_N) { return array_values($_gallery->to_array()); } return $_gallery; }
/** * * @param string|int $key component term_name keys members|groups etc * * @return MPP_Type|boolean */ function mpp_get_type_object($key) { if (!$key) { return ''; } if (is_numeric($key)) { $key = mpp_get_type_term_slug($key); } $mpp = mediapress(); if (isset($mpp->types[$key]) && is_a($mpp->types[$key], 'MPP_Type')) { return $mpp->types[$key]; } return false; }
function mpp_check_sitewide_gallery_main_loop($query) { if ($query->is_main_query()) { mediapress()->set_theme_compat(true); } else { mediapress()->set_theme_compat(false); } }
function reset_gallery_data() { parent::reset_postdata(); if (!empty($this->post)) { mediapress()->current_gallery = mpp_get_gallery($this->post); } }