/**
  * When a gallery is created/edit from dashboard, simulate the same behaviour as front end created galleries
  * 
  * @param type $post_id
  * @param type $post
  * @param type $update
  * @return type
  */
 public function update_gallery_details($post_id, $post, $update)
 {
     if (defined('DOING_AJAX') && DOING_AJAX || !is_admin()) {
         return;
     }
     $type = $this->get_editing_gallery_type();
     $gallery = mpp_get_gallery($post);
     if (empty($gallery->type) && $type) {
         wp_set_object_terms($post_id, mpp_underscore_it($type), mpp_get_type_taxname());
         $gallery->type = $type;
     }
     /**
      * On the front end, we are using the taxonomy term slugs as the value while on the backend we are using the term_id as the value
      * 
      * So, we are attaching this function only for the Dashboar created gallery
      * 
      * We do need to make it uniform in the futuer
      * 
      */
     //we need to set the object terms
     //we need to update the media count?
     //do we need to do anything else?
     //gallery-type
     //gallery-component
     //gallery status
     $type = empty($_POST['mpp-gallery-type']) ? '' : trim($_POST['mpp-gallery-type']);
     $status = empty($_POST['mpp-gallery-status']) ? '' : trim($_POST['mpp-gallery-status']);
     $component = empty($_POST['mpp-gallery-component']) ? '' : trim($_POST['mpp-gallery-component']);
     if ($type && mpp_is_registered_type($type)) {
         wp_set_object_terms($post_id, mpp_underscore_it($type), mpp_get_type_taxname());
     }
     if ($component && mpp_is_registered_component($component)) {
         wp_set_object_terms($post_id, mpp_underscore_it($component), mpp_get_component_taxname());
     }
     if ($status && mpp_is_registered_status($status)) {
         wp_set_object_terms($post_id, mpp_underscore_it($status), mpp_get_status_taxname());
     }
     //update media cout or recount?
     if (!empty($_POST['mpp-gallery-component-id'])) {
         mpp_update_gallery_meta($post_id, '_mpp_component_id', absint($_POST['mpp-gallery-component-id']));
     } else {
         //if component id is not given, check if it is members gallery, if so,
     }
     if (!$update) {
         do_action('mpp_gallery_created', $post_id);
     }
 }
Example #2
0
/**
 * Register a new Associated/Supported component
 * 
 * @param type $args
 */
function mpp_register_component($args)
{
    $default = array('key' => '', 'label' => '', 'labels' => array(), 'description' => '');
    $args = wp_parse_args($args, $default);
    //extract( $args );
    $key = $args['key'];
    if (empty($key) || empty($args['label'])) {
        _doing_it_wrong(__FUNCTION__, __('You must provide valid key and label for associated component.', 'mediapress'), '1.0');
    }
    $mediapress = mediapress();
    //if it was not already registered
    if (!isset($mediapress->components[$key])) {
        $term_slug = mpp_underscore_it($key);
        $taxonomy = mpp_get_component_taxname();
        //if the terms does not exists, add it
        if (!mpp_term_exists($term_slug, $taxonomy)) {
            wp_insert_term($args['label'], $taxonomy, array('slug' => $term_slug, 'description' => $args['description']));
        }
        $component_object = new MPP_Component(array('key' => $key, 'label' => $args['label'], 'labels' => $args['labels']));
        $mediapress->components[$key] = $component_object;
    }
}
Example #3
0
function mpp_update_media($args = null)
{
    //updating media can not change the Id & SRC, so
    if (!isset($args['id'])) {
        return false;
    }
    $default = array('user_id' => get_current_user_id(), 'gallery_id' => false, 'post_parent' => false, 'is_orphan' => false, 'is_uploaded' => '', 'is_remote' => '', 'is_imorted' => '', 'is_embedded' => '', 'embed_url' => '', 'embed_html' => '', 'component_id' => '', 'component' => '', 'context' => '', 'status' => '', 'type' => '', 'storage_method' => '', 'mime_type' => '', 'description' => '', 'sort_order' => 0);
    $args = wp_parse_args($args, $default);
    extract($args);
    //print_r($args );
    //return ;
    if (!$title) {
        return false;
    }
    $post_data = get_post($id, ARRAY_A);
    if (!$gallery_id) {
        $gallery_id = $post_data['post_parent'];
    }
    if ($title) {
        $post_data['post_title'] = $title;
    }
    if ($description) {
        $post_data['post_content'] = $description;
    }
    if ($gallery_id) {
        $post_data['post_parent'] = $gallery_id;
    }
    //check if the gallery is sorted and the sorting order is not set explicitly
    //we update it
    if (!$sort_order && !$post_data['menu_order'] && mpp_is_gallery_sorted($gallery_id)) {
        //current max sort order +1
        $sort_order = (int) mpp_get_max_media_order($gallery_id) + 1;
    }
    if ($sort_order) {
        $post_data['menu_order'] = absin($sort_order);
    }
    // Save the data
    $id = wp_insert_attachment($post_data, false, $gallery_id);
    if (!is_wp_error($id)) {
        //set component
        if ($component) {
            wp_set_object_terms($id, mpp_underscore_it($component), mpp_get_component_taxname());
        }
        //set _component_id meta key user_id/gallery_id/group id etc
        if ($component_id) {
            mpp_update_media_meta($id, '_mpp_component_id', $component_id);
        }
        //set upload context
        if ($context) {
            mpp_update_media_meta($id, '_mpp_context', $context);
        }
        //set media privacy
        if ($status) {
            wp_set_object_terms($id, mpp_underscore_it($status), mpp_get_status_taxname());
        }
        //set media type internally as audio/video etc
        if ($type) {
            wp_set_object_terms($id, mpp_underscore_it($type), mpp_get_type_taxname());
        }
        //
        if ($storage_method) {
            mpp_update_media_meta($id, '_mpp_storage_method', $storage_method);
        }
        //
        //add all extraz here
        if ($is_orphan) {
            mpp_update_media_meta($id, '_mpp_is_orphan', $is_orphan);
        } else {
            mpp_delete_media_meta($id, '_mpp_is_orphan');
        }
        do_action('mpp_media_updated', $id, $gallery_id);
        return $id;
    }
    return false;
    // there was an error
}
Example #4
0
/**
 * Check if given post exists
 * 
 * @param type $args array(
 *     'id'=> //optional,
 *     '
 * )
 * 
 * @return boolean|object post data row on success else false
 */
function mpp_post_exists($args)
{
    extract($args);
    if (!empty($id)) {
        //if ID is give, just shortcircuit the check
        $post = get_post($post_id);
        if (!$post) {
            return false;
        } else {
            return $post->ID;
        }
    }
    if (!$component_id || !$slug || !$post_type) {
        return false;
    }
    $posts = get_posts(array('post_type' => $post_type, 'post_status' => $post_status, 'name' => $slug, mpp_get_component_taxname() => mpp_underscore_it($component), 'meta_query' => array(array('key' => '_mpp_component_id', 'value' => $component_id, 'compare' => '=', 'type' => 'UNSIGNED')), 'fields' => 'all'));
    if (!empty($posts)) {
        return array_pop($posts);
    }
    return false;
}
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;
}