Plugin Directory

Changeset 377552


Ignore:
Timestamp:
04/26/2011 09:56:57 PM (15 years ago)
Author:
anabelle
Message:

version 0.8

Location:
custom-menu-images
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • custom-menu-images/tags/0.5/custom-menu-images.php

    r322531 r377552  
    33Plugin Name: Custom menu images
    44Plugin URI: http://8manos.com
    5 Description: This plugin lets you add images as CSS backgrounds to your menu items using the menu editor in wp-admin
    6 Version: 0.5
     5Description: None
     6Version: 0.8
    77Author: 8manos
    88Author URI: http://8manos.com
     
    2525        }
    2626   
    27         //add_filter( 'wp_get_nav_menu_items', 'addHomeMenuLink', 10, 2 );
     27           
     28
    2829        add_filter( 'attachment_fields_to_edit', array(&$this, 'control_add_image_to_menu'), 20,2);
    2930        add_filter("wp_get_nav_menu_items", array(&$this, "get_custom_menu_image_css"), 20, 2);
     
    3334        add_action('admin_head', array(&$this, 'add_js'));
    3435        add_action('wp_footer', array(&$this, 'print_custom_menu_image_css'));
    35        
     36        add_action('admin_menu', array(&$this, 'custom_menu_images_menu'));
     37        add_action('wp_head', array(&$this, 'front_end_head'));
    3638        add_action( 'admin_print_scripts-media-upload-popup', array( &$this, 'media_upload_popup_js' ), 2000 );
    37        
    3839        add_action('admin_head', array(&$this, 'admin_head'));
    39        
    4040        add_action('wp_ajax_add_image', array(&$this, "add_image"));
    4141        add_action('wp_ajax_remove_image', array(&$this, "remove_image"));
     42
    4243        register_activation_hook(__FILE__, array(&$this, 'custom_menu_image_activation'));     
    4344        register_uninstall_hook(__FILE__, array(&$this, 'custom_menu_image_uninstall'));
     45
    4446        if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') $this->save_config();
    45     }   
     47    }
     48    //
     49    function findMenu($id = null){     
     50        $locations = get_registered_nav_menus();
     51        $menus = wp_get_nav_menus();
     52        if($id){
     53            foreach ( $menus as $menu ){
     54                if($id == $menu->term_id ){
     55                    return $menu;
     56                }
     57            }
     58            return null;
     59        }
     60        $menu_locations = get_nav_menu_locations();
     61        $return = null;
     62        // find current menu
     63        foreach ( $locations as $location => $description ) {
     64            foreach ( $menus as $menu ){
     65                if( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ){
     66                    $return = $menu;
     67                    break; 
     68                }
     69            }               
     70        }   
     71        return $return;
     72    }
     73    // add style into front-end header 
     74    function front_end_head(){
     75        $menu = $this->findMenu();
     76        wp_register_style("custom-menu-images", site_url()."/wp-content/plugins/custom-menu-images/css/custom_menu_images_".$menu->term_id.".css");
     77        wp_print_styles(array(
     78            'custom-menu-images'
     79        ));
     80    }
    4681    function media_upload_popup_js(){
    4782        //wp_enqueue_script('wp-ajax-response');
     
    5186        if(!$options || !is_array($options))
    5287            add_option($this->prefix, array());
     88       
     89        $options = get_option($this->prefix."_settings");
     90        if(!$options || !is_array($options))
     91            add_option($this->prefix."_settings", array(
     92                "cmi_id"    => "menu-main-menu",
     93                "cmi_class" => "menu"
     94            ));
    5395    }
    5496    function custom_menu_image_uninstall(){
     
    5698    }
    5799    function save_config(){
    58         if(count($_POST)){
     100        if(strpos($_POST['_wp_http_referer'], 'nav-menus.php')!==false){
     101           
     102            $parentID = $_POST['menu'];
     103            $menu = $this->findMenu($parentID);
    59104            $urls       = $_POST[$this->prefix.'-url'];
    60105            $urls_type  = $_POST[$this->prefix.'-url-type'];
     
    69114                    );
    70115                }
    71                 update_option($this->prefix, $data);
    72             }   
    73         }
    74     }
    75     function get_custom_menu_image_css($menuItems, $args){
    76         //print_r($menuItems);
    77         $this->styles[] = '<style>';
    78         $this->styles[] = '
    79             body{
    80                 font-weight: bold;
    81                 color: red;
    82             }
    83         ';
    84         $custom_options = (get_option($this->prefix));
    85         foreach ($menuItems as $key => $val ) {
    86             $menuItems[$key]->classes = array('menu_item_'.$val->ID);
    87             $image_url = ($custom_options[$val->ID]['url_type'] != 'lib' ? $custom_options[$val->ID]['url'] : $custom_options[$val->ID]['media_lib']);
    88             $this->styles[] = '
    89                 #access li.menu_item_'.$val->ID.' > a,
    90                 #access li.menu_item_'.$val->ID.':hover > a,
    91                 li.menu-item.menu_item_'.$val->ID.' a,
    92                 li.menu-item.menu_item_'.$val->ID.':hover a{
    93                     background-image: url('.$image_url.');
     116                if(get_option($this->prefix."_".$parentID)){
     117                    update_option($this->prefix."_".$parentID, $data);
     118                }else{
     119                    add_option($this->prefix."_".$parentID, $data);
     120                }
     121
     122                $this->styles = array();
     123                $this->styles[] = "@charset \"utf-8\";\n/* 1/CSS Document */";
     124                //echo $nav_menu_selected_id;
     125                $custom_options = (get_option($this->prefix."_".$parentID));
     126               
     127                $settings = get_option($this->prefix."_settings");
     128                $element = $menu->slug ? "#menu-".$menu->slug:"";
     129                //$element .= $settings['cmi_class'] ? ".".$settings['cmi_class'] : "";
     130                $element = "ul".$element;
     131               
     132                $this->styles[] = $element.' ul{width:auto;}';
     133                $this->styles[] = ''
     134                .$element.' li > a,'
     135                .$element.' li:hover > a{
    94136                    background-repeat: no-repeat;
    95137                    background-position: 5px center;
    96138                    padding-left: 23px;
    97                 }
    98             ';         
    99         }
    100         $this->styles[] = '</style>';
     139                }';
     140                foreach ($urls as $key => $val ) {
     141                    $image_url = ($custom_options[$key]['url_type'] != 'lib' ? $custom_options[$key]['url'] : $custom_options[$key]['media_lib']);
     142                    if($image_url){
     143                        $this->styles[] = ''
     144                        .$element.' li.cmi_menu_item_'.$key.' > a,'
     145                        .$element.' li.cmi_menu_item_'.$key.':hover > a {
     146                            background-image: url('.$image_url.');                     
     147                        }';
     148                    }
     149                }
     150                file_put_contents($this->dir."/css/custom_menu_images_$parentID.css", implode("\n", $this->styles));
     151            }   
     152        }
     153    }
     154    function get_custom_menu_image_css($menuItems, $args){
     155        foreach ($menuItems as $key => $val ) {
     156            $menuItems[$key]->classes = array('cmi_menu_item_'.$val->ID);
     157        }
    101158        return $menuItems;
    102159    }
    103160    function print_custom_menu_image_css(){
    104         print implode("\n", $this->styles);
     161        //print implode("\n", $this->styles);
    105162    }
    106163    function control_add_image_to_menu( $fields, $post ) {
     
    108165            $id = (int) $post->ID;
    109166            $text = __( 'Add Thumbnail Menu' );
    110             $button = '<a rel="'.$id.'" class="button-primary" href="javascript:void(0);" onclick="add_image(this);">'.$text.'</a>';
    111             $fields['image-size']['extra_rows']['asdadadadada']['html'] = $button;
     167            $button = '<a rel="'.$id.'" class="button-primary" href="javascript:void(0);" onclick="CustomMenuImages.addImage(this, \''.$_GET['cmi_id'].'\');">'.$text.'</a>';
     168            $fields['image-size']['extra_rows']['button_add_to_menu']['html'] = $button;
    112169        }
    113170        return $fields;
     
    119176        wp_enqueue_script('jquery');
    120177        wp_enqueue_script('wp-ajax-response');
     178        wp_enqueue_script('custom_menu_images', $this->url.'/js/custom_menu_images.js');
    121179        wp_enqueue_script('thickbox');
    122         add_action("admin_head", array(&$this, "xxxx"));
    123     }
    124     function xxxx(){
     180        add_action("admin_head", array(&$this, "admin_head_script"));
     181    }
     182    function admin_head_script(){
     183    global $nav_menu_selected_id;
     184    //echo "<pre>1";print_r($nav_menu_selected_id);echo "</pre>";
    125185    ?>
    126186    <script>
    127187    var menu_item_options = new Array();
    128188    <?php
    129     $menu_item_options = get_option($this->prefix);
     189    $menu_item_options = get_option($this->prefix."_".$nav_menu_selected_id);
    130190    if(count($menu_item_options) && is_array($menu_item_options)){
    131191        foreach($menu_item_options as $k=>$v){
     
    135195    }
    136196    ?>
    137    
    138     jQuery(document).ready(function(){
    139         var p = jQuery("div.menu-item-settings");
    140        
    141         var url = '<?php echo admin_url( 'media-upload.php' )?>';
    142        
    143         for(var i = 0; i < p.length; i++){
    144             var id = p[i].id.substr(19);       
    145             var sibling = jQuery("#edit-menu-item-attr-title-"+id).parent().parent();
    146             var checked = (menu_item_options[id] ? (menu_item_options[id].url_type == 'lib' ? 'lib' : 'url') : 'url');
    147             var str_e = '\
    148                     <'+'fieldset style="border:1px solid #CCCCCC;padding: 3px;width:380px;">\
    149                     <'+'legend style="margin-left:5px;">Navigation Image</'+'legend>\
    150                         <'+'p class="description description-thin" style="height:auto;">\
    151                         <'+'input type="radio" name="<?php echo $this->prefix;?>-url-type['+id+']" value="url" '+(checked=='url' ? 'checked="checked"' : '')+' />From URL\
    152                         <'+'input type="text" value="'+(menu_item_options[id] ? menu_item_options[id].url : "")+'" name="<?php echo $this->prefix;?>-url['+id+']" class="widefat edit-menu-item-title" id="edit-menu-item-title-'+id+'">\
    153                         <'+'br />\
    154                         <'+'input type="radio" name="<?php echo $this->prefix;?>-url-type['+id+']" value="lib" '+(checked!='url' ? 'checked="checked"' : '')+'/>From Media Library\
    155                         <'+'br />\
    156                         <'+'img src="'+(menu_item_options[id] ? menu_item_options[id].media_lib : "")+'" id="<?php echo $this->prefix;?>-preview-'+id+'" style="max-width:150px;max-height:150px;" />\
    157                         <'+'input type="hidden" name="<?php echo $this->prefix;?>-ml['+id+']" id="<?php echo $this->prefix;?>-ml-'+id+'" value="'+(menu_item_options[id] ? menu_item_options[id].media_lib : "")+'" />\
    158                         <'+'br />\
    159                         <'+'a class="XXX" href="'+url+'?type=image&amp;tab=library&amp;cmi_id='+id+'&amp;TB_iframe=true" onclick="return false;">Add</'+'a>\
    160                         <'+'a class="YYY" href="javascript:void(0);" onclick="remove_image(this);" rel="'+id+'">Remove</'+'a>\
    161                         <'+'div style="clear:both;"></'+'div>\
    162                     <'+'/p>\
    163                     <'+'/fieldset>';
    164             var new_e = jQuery(str_e);         
    165             sibling.after(new_e);
    166             //jQuery(p[i]).before(new_e);
    167         }       
    168         tb_init('a.XXX');//pass where to apply thickbox
    169     })
    170     function remove_image(el){
    171         var data = {
    172             cmi_id: jQuery(el).attr("rel"),
    173             action: 'remove_image',
    174         }
    175         jQuery.ajax({
    176             url: ajaxurl,
    177             type: "POST",
    178             data: data,
    179             dataType: 'json',
    180             cache: false,
    181             success: function (data, textStatus ) {
    182                 data = eval( data );
    183                 var prev_id = '<?php echo $this->prefix;?>-preview-'+data.cmi_id;   
    184                 jQuery( parent.document.getElementById( prev_id ) )
    185                 .css({display: 'none'})
    186                 .attr("src", "")
    187                
    188                 var ml_id = '<?php echo $this->prefix;?>-ml-'+data.cmi_id;         
    189                 /* Refresh the image on the screen below */
    190                 jQuery( parent.document.getElementById( ml_id ) )
    191                 .val("")
    192             }
    193         });
    194     }
     197    jQuery(document).ready(function(){
     198
     199        CustomMenuImages
     200            .init({prefix: '<?php echo $this->prefix?>', mediaUploadUrl: '<?php echo admin_url('media-upload.php');?>'})
     201            .loadCustomFields();       
     202    }) 
    195203    </script>
    196204    <?php
    197205    }
    198206    function admin_head(){
    199        
    200        
    201        
    202207    ?>
    203     <!--
    204     <script type='text/javascript' src='http://localhost/wordpress301/wp-includes/js/thickbox/thickbox.js'></script>
    205     <script type='text/javascript' src='http://localhost/wordpress301/wp-admin/load-scripts.php?c=1&amp;load=wp-ajax-response,thickbox&amp;ver=ccc374ca1616213ca9ed109e93676b0e'></script>
    206    
    207     <link rel="stylesheet" href="http://localhost/wordpress301/wp-includes/js/thickbox/thickbox.css" />-->
    208    
     208    <script src="<?php echo $this->url;?>/js/custom_menu_images.js"></script>
    209209    <script>
    210    
    211    
    212     function add_image(el){
    213         var sizes = jQuery("td.field input");
    214         var size = '';
    215         for(var i = 0;i <sizes.length;i++){
    216             if(sizes[i].name == 'attachments['+jQuery(el).attr('rel')+'][image-size]'){
    217                 if(sizes[i].checked){
    218                     size = (sizes[i].value)
    219                     break;
    220                 }
    221             }
    222         }
    223         var data = {
    224             cmi_id: '<?php echo $_GET['cmi_id'];?>',
    225             action: 'add_image',
    226             attachment_id : jQuery(el).attr('rel'),
    227             size: size
    228         }
    229         jQuery.ajax({
    230             url: ajaxurl,
    231             type: "POST",
    232             data: data,
    233             dataType: 'json',
    234             cache: false,
    235             success: function (data, textStatus ) {
    236                
    237                 /* Vars */
    238                 data = eval( data );
    239 
    240                 var prev_id = '<?php echo $this->prefix;?>-preview-'+data.cmi_id;   
    241                 jQuery( parent.document.getElementById( prev_id ) )
    242                 .css({width: '100px', height: '100px', display: 'block'})
    243                 .attr("src", data.thumb)
    244                
    245                 var ml_id = '<?php echo $this->prefix;?>-ml-'+data.cmi_id;         
    246                 /* Refresh the image on the screen below */
    247                 jQuery( parent.document.getElementById( ml_id ) )
    248                 .val(data.thumb)
    249                
    250                 /* Close Thickbox */
    251                 self.parent.tb_remove();
    252             }
    253         });
    254     }
    255    
     210    var menuID = '<?php echo $_GET['cmi_id'];?>';
     211    jQuery(document).ready(function(){
     212        CustomMenuImages
     213            .init({prefix: '<?php echo $this->prefix?>', mediaUploadUrl: '<?php echo admin_url('media-upload.php');?>'})
     214    });   
    256215    </script>
    257216    <?php
     
    316275        )));
    317276    }
     277    function custom_menu_images_menu(){
     278        return;
     279        add_options_page('Custom Menu Images', 'Custom Menu Images', 7, __FILE__, array($this, 'cmi_settings') );
     280    }
     281    function cmi_settings(){
     282        $key = $this->prefix."_settings";
     283       
     284        if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
     285            $settings = $_POST['cmi_settings'];
     286            update_option($key, $settings);
     287        }
     288        $options = get_option($key);
     289        $styles = array();
     290        $styles[] = "@charset \"utf-8\";\n/* 1/CSS Document */";
     291   
     292        $settings = get_option($this->prefix."_settings");
     293        $element = $settings['cmi_id'] ? "#".$settings['cmi_id']:"";
     294        $element .= $settings['cmi_class'] ? ".".$settings['cmi_class'] : "";
     295        $element = "ul".$element;
     296        $styles[] = $element.' ul{width:auto;}';
     297        $styles[] = ''
     298        .$element.' li > a,'
     299        .$element.' li:hover > a{
     300            background-repeat: no-repeat;
     301            background-position: 5px center;
     302            padding-left: 23px;
     303        }';
     304        $menu = $this->findMenu();
     305        $item_options = get_option($this->prefix."_".$menu->term_id);
     306        foreach ($item_options as $key => $val ) {
     307            //$menuItems[$key]->classes = array('menu_item_'.$key);
     308            $image_url = ($item_options[$key]['url_type'] != 'lib' ? $item_options[$key]['url'] : $item_options[$key]['media_lib']);
     309            if($image_url){
     310                $styles[] = ''
     311                .$element.' li.cmi_menu_item_'.$key.' > a,'
     312                .$element.' li.cmi_menu_item_'.$key.':hover > a {
     313                    background-image: url('.$image_url.');                     
     314                }';
     315            }
     316        }
     317        file_put_contents($this->dir."/css/custom_menu_images_".$menu->term_id.".css", implode("\n", $styles));
     318    ?>
     319        <div class='wrap'>
     320            <h2><?php echo wp_specialchars( "Custom Menu Images Settings" ) ;?></h2>
     321            <div>
     322            <form name="" action="" method="post">
     323                <table>
     324                    <tr>
     325                        <td>Menu ID/Class</td>
     326                        <td>
     327                            <input type="text" name="cmi_settings[cmi_id]" value="<?php echo $options['cmi_id'];?>" /> /
     328                            <input type="text" name="cmi_settings[cmi_class]" value="<?php echo $options['cmi_class'];?>" />
     329                        </td>
     330                    </tr>
     331                    <tr>
     332                        <td>&nbsp;</td>
     333                        <td>
     334                            <input type="submit" value="Save Settings" />
     335                        </td>
     336                    </tr>
     337                </table>
     338            </form>               
     339            </div>
     340        </div>           
     341    <?php
     342    }
    318343}
    319344$custom_menu_image = new CustomMenuImage();
  • custom-menu-images/tags/0.5/readme.txt

    r322531 r377552  
    44Tags: nav_menus, images, custom images, icons, thumbnails, background, media gallery, upload, custom menu, item image
    55Requires at least: 3.0
     6<<<<<<< .mine
     7Tested up to: 3.1.2
     8Stable tag: 0.8
     9=======
    610Tested up to: 3.0.3
    711Stable tag: 0.5
     12>>>>>>> .r377551
    813
    914Adds an image field to all menu items and generates CSS, for user side background image manipulation.
     
    1318Adds an optional image field to all menu items. Images can be uploaded or linked. The plugin then generates basic CSS so you can work with images.
    1419
    15 It can be used to set thumbnails and make mega-dropdowns, or to add a custom icon to each item that the administrator can easily change without touching a line of code.
     20It can be used to set thumbnails and make mega-dropdowns, or to add a custom icon to each menu item
    1621
     22<<<<<<< .mine
     23Once configured by the developer, the administrator can easily change each image without touching a line of code.
     24=======
    1725It wont look nice out of the box, it is intended for developers who want extra functionality in the menu.
     26>>>>>>> .r377551
     27
     28It wont always look nicely out of the box (actually it never does), it is intended for developers who want extra functionality in the menu.
    1829
    1930== Installation ==
    2031
    21 1. Upload ajax-post-carousel folder to the /wp-content/plugins/ directory
     321. Upload custom-menu-images folder to the /wp-content/plugins/ directory
    22332. Activate the plugin through the 'Plugins' menu in WordPress
    23343. Go to manage menus and each item will have a Custom image field.
     354. You should now go add some images and configure your CSS to display background images as you want.
    2436
    2537== Frequently Asked Questions ==
     
    3446Because you have to use it in conjuction with your custom CSS
    3547
    36 = Any  more questions? =
     48= More questions? =
    3749
    3850Please write in the forums or write us to [email protected] we will be speaking in no time.
     
    4456== Changelog ==
    4557
     58<<<<<<< .mine
     59= 0.8 =
     60* Multiple menus now supported
     61* CSS Simplified and moved to external file
     62
     63= 0.5 =
     64* Now supports choosing of image size to add
     65
     66=======
    4667= 0.5 =
    4768* Fixed some bugs to allow selection of image size from Media Library ("Thumbnai", "Medium", "Large", "Original Size").
    4869
     70>>>>>>> .r377551
    4971= 0.2 =
    5072* Initial release
     
    5375== Upgrade Notice ==
    5476
     77<<<<<<< .mine
     78= 0.8 =
     79It is getting better, Still testing.
     80
     81=======
    5582= 0.5 =
    5683If you want to choose the image size to use and not just thumbnail, this update is for you.
    5784
     85>>>>>>> .r377551
    5886= 0.2 =
    5987Initial release, come on and help us test it!
  • custom-menu-images/trunk/custom-menu-images.php

    r322526 r377552  
    33Plugin Name: Custom menu images
    44Plugin URI: http://8manos.com
    5 Description: This plugin lets you add images as CSS backgrounds to your menu items using the menu editor in wp-admin
    6 Version: 0.5
     5Description: None
     6Version: 0.8
    77Author: 8manos
    88Author URI: http://8manos.com
     
    2525        }
    2626   
    27         //add_filter( 'wp_get_nav_menu_items', 'addHomeMenuLink', 10, 2 );
     27           
     28
    2829        add_filter( 'attachment_fields_to_edit', array(&$this, 'control_add_image_to_menu'), 20,2);
    2930        add_filter("wp_get_nav_menu_items", array(&$this, "get_custom_menu_image_css"), 20, 2);
     
    3334        add_action('admin_head', array(&$this, 'add_js'));
    3435        add_action('wp_footer', array(&$this, 'print_custom_menu_image_css'));
    35        
     36        add_action('admin_menu', array(&$this, 'custom_menu_images_menu'));
     37        add_action('wp_head', array(&$this, 'front_end_head'));
    3638        add_action( 'admin_print_scripts-media-upload-popup', array( &$this, 'media_upload_popup_js' ), 2000 );
    37        
    3839        add_action('admin_head', array(&$this, 'admin_head'));
    39        
    4040        add_action('wp_ajax_add_image', array(&$this, "add_image"));
    4141        add_action('wp_ajax_remove_image', array(&$this, "remove_image"));
     42
    4243        register_activation_hook(__FILE__, array(&$this, 'custom_menu_image_activation'));     
    4344        register_uninstall_hook(__FILE__, array(&$this, 'custom_menu_image_uninstall'));
     45
    4446        if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') $this->save_config();
    45     }   
     47    }
     48    //
     49    function findMenu($id = null){     
     50        $locations = get_registered_nav_menus();
     51        $menus = wp_get_nav_menus();
     52        if($id){
     53            foreach ( $menus as $menu ){
     54                if($id == $menu->term_id ){
     55                    return $menu;
     56                }
     57            }
     58            return null;
     59        }
     60        $menu_locations = get_nav_menu_locations();
     61        $return = null;
     62        // find current menu
     63        foreach ( $locations as $location => $description ) {
     64            foreach ( $menus as $menu ){
     65                if( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ){
     66                    $return = $menu;
     67                    break; 
     68                }
     69            }               
     70        }   
     71        return $return;
     72    }
     73    // add style into front-end header 
     74    function front_end_head(){
     75        $menu = $this->findMenu();
     76        wp_register_style("custom-menu-images", site_url()."/wp-content/plugins/custom-menu-images/css/custom_menu_images_".$menu->term_id.".css");
     77        wp_print_styles(array(
     78            'custom-menu-images'
     79        ));
     80    }
    4681    function media_upload_popup_js(){
    4782        //wp_enqueue_script('wp-ajax-response');
     
    5186        if(!$options || !is_array($options))
    5287            add_option($this->prefix, array());
     88       
     89        $options = get_option($this->prefix."_settings");
     90        if(!$options || !is_array($options))
     91            add_option($this->prefix."_settings", array(
     92                "cmi_id"    => "menu-main-menu",
     93                "cmi_class" => "menu"
     94            ));
    5395    }
    5496    function custom_menu_image_uninstall(){
     
    5698    }
    5799    function save_config(){
    58         if(count($_POST)){
     100        if(strpos($_POST['_wp_http_referer'], 'nav-menus.php')!==false){
     101           
     102            $parentID = $_POST['menu'];
     103            $menu = $this->findMenu($parentID);
    59104            $urls       = $_POST[$this->prefix.'-url'];
    60105            $urls_type  = $_POST[$this->prefix.'-url-type'];
     
    69114                    );
    70115                }
    71                 update_option($this->prefix, $data);
    72             }   
    73         }
    74     }
    75     function get_custom_menu_image_css($menuItems, $args){
    76         //print_r($menuItems);
    77         $this->styles[] = '<style>';
    78         $this->styles[] = '
    79             body{
    80                 font-weight: bold;
    81                 color: red;
    82             }
    83         ';
    84         $custom_options = (get_option($this->prefix));
    85         foreach ($menuItems as $key => $val ) {
    86             $menuItems[$key]->classes = array('menu_item_'.$val->ID);
    87             $image_url = ($custom_options[$val->ID]['url_type'] != 'lib' ? $custom_options[$val->ID]['url'] : $custom_options[$val->ID]['media_lib']);
    88             $this->styles[] = '
    89                 #access li.menu_item_'.$val->ID.' > a,
    90                 #access li.menu_item_'.$val->ID.':hover > a,
    91                 li.menu-item.menu_item_'.$val->ID.' a,
    92                 li.menu-item.menu_item_'.$val->ID.':hover a{
    93                     background-image: url('.$image_url.');
     116                if(get_option($this->prefix."_".$parentID)){
     117                    update_option($this->prefix."_".$parentID, $data);
     118                }else{
     119                    add_option($this->prefix."_".$parentID, $data);
     120                }
     121
     122                $this->styles = array();
     123                $this->styles[] = "@charset \"utf-8\";\n/* 1/CSS Document */";
     124                //echo $nav_menu_selected_id;
     125                $custom_options = (get_option($this->prefix."_".$parentID));
     126               
     127                $settings = get_option($this->prefix."_settings");
     128                $element = $menu->slug ? "#menu-".$menu->slug:"";
     129                //$element .= $settings['cmi_class'] ? ".".$settings['cmi_class'] : "";
     130                $element = "ul".$element;
     131               
     132                $this->styles[] = $element.' ul{width:auto;}';
     133                $this->styles[] = ''
     134                .$element.' li > a,'
     135                .$element.' li:hover > a{
    94136                    background-repeat: no-repeat;
    95137                    background-position: 5px center;
    96138                    padding-left: 23px;
    97                 }
    98             ';         
    99         }
    100         $this->styles[] = '</style>';
     139                }';
     140                foreach ($urls as $key => $val ) {
     141                    $image_url = ($custom_options[$key]['url_type'] != 'lib' ? $custom_options[$key]['url'] : $custom_options[$key]['media_lib']);
     142                    if($image_url){
     143                        $this->styles[] = ''
     144                        .$element.' li.cmi_menu_item_'.$key.' > a,'
     145                        .$element.' li.cmi_menu_item_'.$key.':hover > a {
     146                            background-image: url('.$image_url.');                     
     147                        }';
     148                    }
     149                }
     150                file_put_contents($this->dir."/css/custom_menu_images_$parentID.css", implode("\n", $this->styles));
     151            }   
     152        }
     153    }
     154    function get_custom_menu_image_css($menuItems, $args){
     155        foreach ($menuItems as $key => $val ) {
     156            $menuItems[$key]->classes = array('cmi_menu_item_'.$val->ID);
     157        }
    101158        return $menuItems;
    102159    }
    103160    function print_custom_menu_image_css(){
    104         print implode("\n", $this->styles);
     161        //print implode("\n", $this->styles);
    105162    }
    106163    function control_add_image_to_menu( $fields, $post ) {
     
    108165            $id = (int) $post->ID;
    109166            $text = __( 'Add Thumbnail Menu' );
    110             $button = '<a rel="'.$id.'" class="button-primary" href="javascript:void(0);" onclick="add_image(this);">'.$text.'</a>';
    111             $fields['image-size']['extra_rows']['asdadadadada']['html'] = $button;
     167            $button = '<a rel="'.$id.'" class="button-primary" href="javascript:void(0);" onclick="CustomMenuImages.addImage(this, \''.$_GET['cmi_id'].'\');">'.$text.'</a>';
     168            $fields['image-size']['extra_rows']['button_add_to_menu']['html'] = $button;
    112169        }
    113170        return $fields;
     
    119176        wp_enqueue_script('jquery');
    120177        wp_enqueue_script('wp-ajax-response');
     178        wp_enqueue_script('custom_menu_images', $this->url.'/js/custom_menu_images.js');
    121179        wp_enqueue_script('thickbox');
    122         add_action("admin_head", array(&$this, "xxxx"));
    123     }
    124     function xxxx(){
     180        add_action("admin_head", array(&$this, "admin_head_script"));
     181    }
     182    function admin_head_script(){
     183    global $nav_menu_selected_id;
     184    //echo "<pre>1";print_r($nav_menu_selected_id);echo "</pre>";
    125185    ?>
    126186    <script>
    127187    var menu_item_options = new Array();
    128188    <?php
    129     $menu_item_options = get_option($this->prefix);
     189    $menu_item_options = get_option($this->prefix."_".$nav_menu_selected_id);
    130190    if(count($menu_item_options) && is_array($menu_item_options)){
    131191        foreach($menu_item_options as $k=>$v){
     
    135195    }
    136196    ?>
    137    
    138     jQuery(document).ready(function(){
    139         var p = jQuery("div.menu-item-settings");
    140        
    141         var url = '<?php echo admin_url( 'media-upload.php' )?>';
    142        
    143         for(var i = 0; i < p.length; i++){
    144             var id = p[i].id.substr(19);       
    145             var sibling = jQuery("#edit-menu-item-attr-title-"+id).parent().parent();
    146             var checked = (menu_item_options[id] ? (menu_item_options[id].url_type == 'lib' ? 'lib' : 'url') : 'url');
    147             var str_e = '\
    148                     <'+'fieldset style="border:1px solid #CCCCCC;padding: 3px;width:380px;">\
    149                     <'+'legend style="margin-left:5px;">Navigation Image</'+'legend>\
    150                         <'+'p class="description description-thin" style="height:auto;">\
    151                         <'+'input type="radio" name="<?php echo $this->prefix;?>-url-type['+id+']" value="url" '+(checked=='url' ? 'checked="checked"' : '')+' />From URL\
    152                         <'+'input type="text" value="'+(menu_item_options[id] ? menu_item_options[id].url : "")+'" name="<?php echo $this->prefix;?>-url['+id+']" class="widefat edit-menu-item-title" id="edit-menu-item-title-'+id+'">\
    153                         <'+'br />\
    154                         <'+'input type="radio" name="<?php echo $this->prefix;?>-url-type['+id+']" value="lib" '+(checked!='url' ? 'checked="checked"' : '')+'/>From Media Library\
    155                         <'+'br />\
    156                         <'+'img src="'+(menu_item_options[id] ? menu_item_options[id].media_lib : "")+'" id="<?php echo $this->prefix;?>-preview-'+id+'" style="max-width:150px;max-height:150px;" />\
    157                         <'+'input type="hidden" name="<?php echo $this->prefix;?>-ml['+id+']" id="<?php echo $this->prefix;?>-ml-'+id+'" value="'+(menu_item_options[id] ? menu_item_options[id].media_lib : "")+'" />\
    158                         <'+'br />\
    159                         <'+'a class="XXX" href="'+url+'?type=image&amp;tab=library&amp;cmi_id='+id+'&amp;TB_iframe=true" onclick="return false;">Add</'+'a>\
    160                         <'+'a class="YYY" href="javascript:void(0);" onclick="remove_image(this);" rel="'+id+'">Remove</'+'a>\
    161                         <'+'div style="clear:both;"></'+'div>\
    162                     <'+'/p>\
    163                     <'+'/fieldset>';
    164             var new_e = jQuery(str_e);         
    165             sibling.after(new_e);
    166             //jQuery(p[i]).before(new_e);
    167         }       
    168         tb_init('a.XXX');//pass where to apply thickbox
    169     })
    170     function remove_image(el){
    171         var data = {
    172             cmi_id: jQuery(el).attr("rel"),
    173             action: 'remove_image',
    174         }
    175         jQuery.ajax({
    176             url: ajaxurl,
    177             type: "POST",
    178             data: data,
    179             dataType: 'json',
    180             cache: false,
    181             success: function (data, textStatus ) {
    182                 data = eval( data );
    183                 var prev_id = '<?php echo $this->prefix;?>-preview-'+data.cmi_id;   
    184                 jQuery( parent.document.getElementById( prev_id ) )
    185                 .css({display: 'none'})
    186                 .attr("src", "")
    187                
    188                 var ml_id = '<?php echo $this->prefix;?>-ml-'+data.cmi_id;         
    189                 /* Refresh the image on the screen below */
    190                 jQuery( parent.document.getElementById( ml_id ) )
    191                 .val("")
    192             }
    193         });
    194     }
     197    jQuery(document).ready(function(){
     198
     199        CustomMenuImages
     200            .init({prefix: '<?php echo $this->prefix?>', mediaUploadUrl: '<?php echo admin_url('media-upload.php');?>'})
     201            .loadCustomFields();       
     202    }) 
    195203    </script>
    196204    <?php
    197205    }
    198206    function admin_head(){
    199        
    200        
    201        
    202207    ?>
    203     <!--
    204     <script type='text/javascript' src='http://localhost/wordpress301/wp-includes/js/thickbox/thickbox.js'></script>
    205     <script type='text/javascript' src='http://localhost/wordpress301/wp-admin/load-scripts.php?c=1&amp;load=wp-ajax-response,thickbox&amp;ver=ccc374ca1616213ca9ed109e93676b0e'></script>
    206    
    207     <link rel="stylesheet" href="http://localhost/wordpress301/wp-includes/js/thickbox/thickbox.css" />-->
    208    
     208    <script src="<?php echo $this->url;?>/js/custom_menu_images.js"></script>
    209209    <script>
    210    
    211    
    212     function add_image(el){
    213         var sizes = jQuery("td.field input");
    214         var size = '';
    215         for(var i = 0;i <sizes.length;i++){
    216             if(sizes[i].name == 'attachments['+jQuery(el).attr('rel')+'][image-size]'){
    217                 if(sizes[i].checked){
    218                     size = (sizes[i].value)
    219                     break;
    220                 }
    221             }
    222         }
    223         var data = {
    224             cmi_id: '<?php echo $_GET['cmi_id'];?>',
    225             action: 'add_image',
    226             attachment_id : jQuery(el).attr('rel'),
    227             size: size
    228         }
    229         jQuery.ajax({
    230             url: ajaxurl,
    231             type: "POST",
    232             data: data,
    233             dataType: 'json',
    234             cache: false,
    235             success: function (data, textStatus ) {
    236                
    237                 /* Vars */
    238                 data = eval( data );
    239 
    240                 var prev_id = '<?php echo $this->prefix;?>-preview-'+data.cmi_id;   
    241                 jQuery( parent.document.getElementById( prev_id ) )
    242                 .css({width: '100px', height: '100px', display: 'block'})
    243                 .attr("src", data.thumb)
    244                
    245                 var ml_id = '<?php echo $this->prefix;?>-ml-'+data.cmi_id;         
    246                 /* Refresh the image on the screen below */
    247                 jQuery( parent.document.getElementById( ml_id ) )
    248                 .val(data.thumb)
    249                
    250                 /* Close Thickbox */
    251                 self.parent.tb_remove();
    252             }
    253         });
    254     }
    255    
     210    var menuID = '<?php echo $_GET['cmi_id'];?>';
     211    jQuery(document).ready(function(){
     212        CustomMenuImages
     213            .init({prefix: '<?php echo $this->prefix?>', mediaUploadUrl: '<?php echo admin_url('media-upload.php');?>'})
     214    });   
    256215    </script>
    257216    <?php
     
    316275        )));
    317276    }
     277    function custom_menu_images_menu(){
     278        return;
     279        add_options_page('Custom Menu Images', 'Custom Menu Images', 7, __FILE__, array($this, 'cmi_settings') );
     280    }
     281    function cmi_settings(){
     282        $key = $this->prefix."_settings";
     283       
     284        if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
     285            $settings = $_POST['cmi_settings'];
     286            update_option($key, $settings);
     287        }
     288        $options = get_option($key);
     289        $styles = array();
     290        $styles[] = "@charset \"utf-8\";\n/* 1/CSS Document */";
     291   
     292        $settings = get_option($this->prefix."_settings");
     293        $element = $settings['cmi_id'] ? "#".$settings['cmi_id']:"";
     294        $element .= $settings['cmi_class'] ? ".".$settings['cmi_class'] : "";
     295        $element = "ul".$element;
     296        $styles[] = $element.' ul{width:auto;}';
     297        $styles[] = ''
     298        .$element.' li > a,'
     299        .$element.' li:hover > a{
     300            background-repeat: no-repeat;
     301            background-position: 5px center;
     302            padding-left: 23px;
     303        }';
     304        $menu = $this->findMenu();
     305        $item_options = get_option($this->prefix."_".$menu->term_id);
     306        foreach ($item_options as $key => $val ) {
     307            //$menuItems[$key]->classes = array('menu_item_'.$key);
     308            $image_url = ($item_options[$key]['url_type'] != 'lib' ? $item_options[$key]['url'] : $item_options[$key]['media_lib']);
     309            if($image_url){
     310                $styles[] = ''
     311                .$element.' li.cmi_menu_item_'.$key.' > a,'
     312                .$element.' li.cmi_menu_item_'.$key.':hover > a {
     313                    background-image: url('.$image_url.');                     
     314                }';
     315            }
     316        }
     317        file_put_contents($this->dir."/css/custom_menu_images_".$menu->term_id.".css", implode("\n", $styles));
     318    ?>
     319        <div class='wrap'>
     320            <h2><?php echo wp_specialchars( "Custom Menu Images Settings" ) ;?></h2>
     321            <div>
     322            <form name="" action="" method="post">
     323                <table>
     324                    <tr>
     325                        <td>Menu ID/Class</td>
     326                        <td>
     327                            <input type="text" name="cmi_settings[cmi_id]" value="<?php echo $options['cmi_id'];?>" /> /
     328                            <input type="text" name="cmi_settings[cmi_class]" value="<?php echo $options['cmi_class'];?>" />
     329                        </td>
     330                    </tr>
     331                    <tr>
     332                        <td>&nbsp;</td>
     333                        <td>
     334                            <input type="submit" value="Save Settings" />
     335                        </td>
     336                    </tr>
     337                </table>
     338            </form>               
     339            </div>
     340        </div>           
     341    <?php
     342    }
    318343}
    319344$custom_menu_image = new CustomMenuImage();
  • custom-menu-images/trunk/readme.txt

    r322526 r377552  
    44Tags: nav_menus, images, custom images, icons, thumbnails, background, media gallery, upload, custom menu, item image
    55Requires at least: 3.0
     6<<<<<<< .mine
     7Tested up to: 3.1.2
     8Stable tag: 0.8
     9=======
    610Tested up to: 3.0.3
    711Stable tag: 0.5
     12>>>>>>> .r377551
    813
    914Adds an image field to all menu items and generates CSS, for user side background image manipulation.
     
    1318Adds an optional image field to all menu items. Images can be uploaded or linked. The plugin then generates basic CSS so you can work with images.
    1419
    15 It can be used to set thumbnails and make mega-dropdowns, or to add a custom icon to each item that the administrator can easily change without touching a line of code.
     20It can be used to set thumbnails and make mega-dropdowns, or to add a custom icon to each menu item
    1621
     22<<<<<<< .mine
     23Once configured by the developer, the administrator can easily change each image without touching a line of code.
     24=======
    1725It wont look nice out of the box, it is intended for developers who want extra functionality in the menu.
     26>>>>>>> .r377551
     27
     28It wont always look nicely out of the box (actually it never does), it is intended for developers who want extra functionality in the menu.
    1829
    1930== Installation ==
    2031
    21 1. Upload ajax-post-carousel folder to the /wp-content/plugins/ directory
     321. Upload custom-menu-images folder to the /wp-content/plugins/ directory
    22332. Activate the plugin through the 'Plugins' menu in WordPress
    23343. Go to manage menus and each item will have a Custom image field.
     354. You should now go add some images and configure your CSS to display background images as you want.
    2436
    2537== Frequently Asked Questions ==
     
    3446Because you have to use it in conjuction with your custom CSS
    3547
    36 = Any  more questions? =
     48= More questions? =
    3749
    3850Please write in the forums or write us to [email protected] we will be speaking in no time.
     
    4456== Changelog ==
    4557
     58<<<<<<< .mine
     59= 0.8 =
     60* Multiple menus now supported
     61* CSS Simplified and moved to external file
     62
     63= 0.5 =
     64* Now supports choosing of image size to add
     65
     66=======
    4667= 0.5 =
    4768* Fixed some bugs to allow selection of image size from Media Library ("Thumbnai", "Medium", "Large", "Original Size").
    4869
     70>>>>>>> .r377551
    4971= 0.2 =
    5072* Initial release
     
    5375== Upgrade Notice ==
    5476
     77<<<<<<< .mine
     78= 0.8 =
     79It is getting better, Still testing.
     80
     81=======
    5582= 0.5 =
    5683If you want to choose the image size to use and not just thumbnail, this update is for you.
    5784
     85>>>>>>> .r377551
    5886= 0.2 =
    5987Initial release, come on and help us test it!
Note: See TracChangeset for help on using the changeset viewer.