Plugin Directory

Changeset 391641


Ignore:
Timestamp:
06/01/2011 10:19:33 AM (15 years ago)
Author:
johannesfosseus
Message:
 
Location:
related-images
Files:
7 added
4 edited

Legend:

Unmodified
Added
Removed
  • related-images/trunk/readme.txt

    r391166 r391641  
    55Tested up to: 3.2 beta2
    66
    7 The plugin creates a backend box where you can search your media archive and relate images to the current post.
     7The plugin creates a backend box where you can search your media archive and relate images to the current post to a given position.
    88
    99== Description ==
    1010
    11 Sometimes you dont want all images inside the post. Related images fix this and the current version let you add positions to the images, for example "Firstpage Top" or "Article Top". Then you use a template tag to display the pictures on yor site.
     11Sometimes you dont want all images inside the post. Related images fix this and the current version let you add positions to the images, for example "Firstpage Top" or "Article Top".
     12
     13Then you use a template tag to display the pictures on yor site.
     14
    1215The template tag looks like this: related_image('left_firstpage', '200', '200', 'image class'); You add the position, width, height and optional class to the image.
     16
    1317This can be usefull when you use WordPress as a cms and want to position images better then inside the posts
    14 
    15 Version 1.0 only have 4 positions (top_firstpage,right_firstpage,left_firstpage,top_article), this will be moved to a config in the future for better use.
    16 
    17 Update: fron version 1.2 you can create your positions yourself
    1818
    1919== Installation ==
    2020
    21211. Drop plugin in the plugin folder and activate
     222. Add positions under settings -> Related Images
    22233. Done
    2324
     
    2627
    2728== Changelog ==
     29
     30= 1.2.3 =
     31* Added a remove method, so the "Quick Edit" will not remove related images
     32* Added better cheack for revisions and post_id:s
    2833
    2934= 1.2.2 =
  • related-images/trunk/related-images.class.php

    r391166 r391641  
    8282
    8383    }
     84   
     85    // returne the "default" post_id, not the revision
     86    function get_correct_post_id($post_id){
     87       
     88    //$revision = wp_is_post_revision ($post_id);
     89    //if($revision){
     90        //$post_id = $revision;
     91    //}
     92    //$post = get_post ($post_id);
     93
     94
     95
     96        $post_id_parent = get_post($post_id)->post_parent;
     97       
     98        // det finns inga revisions
     99        if($post_id_parent != 0){
     100            $post_id = $post_id_parent;
     101        }
     102
     103        return $post_id;
     104    }
    84105
    85106    // save on 'save_post'
    86107    function save_related_images($post_id){
    87108        global $wpdb;
    88 
    89         // save to the correct post_id
    90         $post_id = get_post($post_id)->post_parent;
    91 
     109       
     110        // allways use the "default" post_id, not the revision one
     111        $post_id = $this->get_correct_post_id($post_id);
     112       
    92113        // get saved positions
    93114        if($_POST['saved_img_position']){
     
    271292    }
    272293
     294    // remova image
     295    function remove_image(){
     296        global $wpdb, $post;
     297
     298        if (!wp_verify_nonce($_POST['image_search_nonce'],__FILE__)){
     299            die();
     300        }
     301       
     302        // get the search string
     303        $img_id = $_POST['img_id'];
     304        $post_ID = $_POST['post_ID'];
     305       
     306        // get saved options
     307        $related_images = get_option($post_ID."_related_images");
     308       
     309        // if there is only one saved, remove it all, or unset a specific image and then update the options
     310        $len = sizeof($related_images);
     311       
     312        if($related_images == 1){
     313            delete_option($post_ID."_related_images");
     314        } else {   
     315            unset($related_images[$img_id]);
     316            update_option($post_ID."_related_images", $related_images);
     317        }
     318       
     319        die();     
     320       
     321    }
     322   
     323   
    273324    // run the search
    274325    function do_image_search(){
     
    282333
    283334        // get the search string
    284         $image_search_string = "%".esc_attr($_POST['image_search_string'])."%";
     335        $image_search_string = "%".$_POST['image_search_string']."%";
    285336
    286337        // had to create the search by myself, did not find any native??
  • related-images/trunk/related-images.js

    r389263 r391641  
    2525        var value = jQuery(this).val();
    2626        var img_id = jQuery(this).attr('data-img-id');
     27        var image_search_nonce = jQuery("#image_search_nonce").val();
     28        var post_ID = jQuery("#post_ID").attr('value');     
     29       
    2730        if(value === 'Remove'){
    2831            jQuery('#img_' + img_id).css({ 'backgroundColor':'#fbe986' }).fadeOut(300, function() { jQuery(this).remove(); });
     32
     33            // run the image remove
     34            jQuery.post(ajaxurl, { action : 'remove_related_images', img_id : img_id, post_ID : post_ID, image_search_nonce : image_search_nonce } );
     35           
     36           
    2937        }
    3038        return false;
  • related-images/trunk/related-images.php

    r391167 r391641  
    55Description: Relate one or more images to a post
    66Author: johannesfosseus
    7 Version: 1.2.2
     7Version: 1.2.3
    88*/
    99
     
    1818    wp_enqueue_script('related_images_js', WP_PLUGIN_URL.'/related-images/related-images.js', array('jquery'));
    1919    wp_enqueue_style('related_images_css', WP_PLUGIN_URL.'/related-images/style.css');
    20     add_action('wp_ajax_search_related_images',  array($related_images, 'do_image_search')); // k�r s�ket
     20    add_action('wp_ajax_search_related_images',  array($related_images, 'do_image_search')); // do the search
     21    add_action('wp_ajax_remove_related_images',  array($related_images, 'remove_image')); // remove a image
    2122}
    2223
Note: See TracChangeset for help on using the changeset viewer.