Changeset 377552
- Timestamp:
- 04/26/2011 09:56:57 PM (15 years ago)
- Location:
- custom-menu-images
- Files:
-
- 3 added
- 4 edited
-
tags/0.5/custom-menu-images.php (modified) (10 diffs)
-
tags/0.5/readme.txt (modified) (5 diffs)
-
trunk/css (added)
-
trunk/custom-menu-images.php (modified) (10 diffs)
-
trunk/js (added)
-
trunk/js/custom_menu_images.js (added)
-
trunk/readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
custom-menu-images/tags/0.5/custom-menu-images.php
r322531 r377552 3 3 Plugin Name: Custom menu images 4 4 Plugin 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-admin6 Version: 0. 55 Description: None 6 Version: 0.8 7 7 Author: 8manos 8 8 Author URI: http://8manos.com … … 25 25 } 26 26 27 //add_filter( 'wp_get_nav_menu_items', 'addHomeMenuLink', 10, 2 ); 27 28 28 29 add_filter( 'attachment_fields_to_edit', array(&$this, 'control_add_image_to_menu'), 20,2); 29 30 add_filter("wp_get_nav_menu_items", array(&$this, "get_custom_menu_image_css"), 20, 2); … … 33 34 add_action('admin_head', array(&$this, 'add_js')); 34 35 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')); 36 38 add_action( 'admin_print_scripts-media-upload-popup', array( &$this, 'media_upload_popup_js' ), 2000 ); 37 38 39 add_action('admin_head', array(&$this, 'admin_head')); 39 40 40 add_action('wp_ajax_add_image', array(&$this, "add_image")); 41 41 add_action('wp_ajax_remove_image', array(&$this, "remove_image")); 42 42 43 register_activation_hook(__FILE__, array(&$this, 'custom_menu_image_activation')); 43 44 register_uninstall_hook(__FILE__, array(&$this, 'custom_menu_image_uninstall')); 45 44 46 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 } 46 81 function media_upload_popup_js(){ 47 82 //wp_enqueue_script('wp-ajax-response'); … … 51 86 if(!$options || !is_array($options)) 52 87 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 )); 53 95 } 54 96 function custom_menu_image_uninstall(){ … … 56 98 } 57 99 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); 59 104 $urls = $_POST[$this->prefix.'-url']; 60 105 $urls_type = $_POST[$this->prefix.'-url-type']; … … 69 114 ); 70 115 } 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{ 94 136 background-repeat: no-repeat; 95 137 background-position: 5px center; 96 138 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 } 101 158 return $menuItems; 102 159 } 103 160 function print_custom_menu_image_css(){ 104 print implode("\n", $this->styles);161 //print implode("\n", $this->styles); 105 162 } 106 163 function control_add_image_to_menu( $fields, $post ) { … … 108 165 $id = (int) $post->ID; 109 166 $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; 112 169 } 113 170 return $fields; … … 119 176 wp_enqueue_script('jquery'); 120 177 wp_enqueue_script('wp-ajax-response'); 178 wp_enqueue_script('custom_menu_images', $this->url.'/js/custom_menu_images.js'); 121 179 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>"; 125 185 ?> 126 186 <script> 127 187 var menu_item_options = new Array(); 128 188 <?php 129 $menu_item_options = get_option($this->prefix );189 $menu_item_options = get_option($this->prefix."_".$nav_menu_selected_id); 130 190 if(count($menu_item_options) && is_array($menu_item_options)){ 131 191 foreach($menu_item_options as $k=>$v){ … … 135 195 } 136 196 ?> 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&tab=library&cmi_id='+id+'&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 }) 195 203 </script> 196 204 <?php 197 205 } 198 206 function admin_head(){ 199 200 201 202 207 ?> 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&load=wp-ajax-response,thickbox&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> 209 209 <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 }); 256 215 </script> 257 216 <?php … … 316 275 ))); 317 276 } 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> </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 } 318 343 } 319 344 $custom_menu_image = new CustomMenuImage(); -
custom-menu-images/tags/0.5/readme.txt
r322531 r377552 4 4 Tags: nav_menus, images, custom images, icons, thumbnails, background, media gallery, upload, custom menu, item image 5 5 Requires at least: 3.0 6 <<<<<<< .mine 7 Tested up to: 3.1.2 8 Stable tag: 0.8 9 ======= 6 10 Tested up to: 3.0.3 7 11 Stable tag: 0.5 12 >>>>>>> .r377551 8 13 9 14 Adds an image field to all menu items and generates CSS, for user side background image manipulation. … … 13 18 Adds 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. 14 19 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.20 It can be used to set thumbnails and make mega-dropdowns, or to add a custom icon to each menu item 16 21 22 <<<<<<< .mine 23 Once configured by the developer, the administrator can easily change each image without touching a line of code. 24 ======= 17 25 It wont look nice out of the box, it is intended for developers who want extra functionality in the menu. 26 >>>>>>> .r377551 27 28 It wont always look nicely out of the box (actually it never does), it is intended for developers who want extra functionality in the menu. 18 29 19 30 == Installation == 20 31 21 1. Upload ajax-post-carouselfolder to the /wp-content/plugins/ directory32 1. Upload custom-menu-images folder to the /wp-content/plugins/ directory 22 33 2. Activate the plugin through the 'Plugins' menu in WordPress 23 34 3. Go to manage menus and each item will have a Custom image field. 35 4. You should now go add some images and configure your CSS to display background images as you want. 24 36 25 37 == Frequently Asked Questions == … … 34 46 Because you have to use it in conjuction with your custom CSS 35 47 36 = Any more questions? =48 = More questions? = 37 49 38 50 Please write in the forums or write us to [email protected] we will be speaking in no time. … … 44 56 == Changelog == 45 57 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 ======= 46 67 = 0.5 = 47 68 * Fixed some bugs to allow selection of image size from Media Library ("Thumbnai", "Medium", "Large", "Original Size"). 48 69 70 >>>>>>> .r377551 49 71 = 0.2 = 50 72 * Initial release … … 53 75 == Upgrade Notice == 54 76 77 <<<<<<< .mine 78 = 0.8 = 79 It is getting better, Still testing. 80 81 ======= 55 82 = 0.5 = 56 83 If you want to choose the image size to use and not just thumbnail, this update is for you. 57 84 85 >>>>>>> .r377551 58 86 = 0.2 = 59 87 Initial release, come on and help us test it! -
custom-menu-images/trunk/custom-menu-images.php
r322526 r377552 3 3 Plugin Name: Custom menu images 4 4 Plugin 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-admin6 Version: 0. 55 Description: None 6 Version: 0.8 7 7 Author: 8manos 8 8 Author URI: http://8manos.com … … 25 25 } 26 26 27 //add_filter( 'wp_get_nav_menu_items', 'addHomeMenuLink', 10, 2 ); 27 28 28 29 add_filter( 'attachment_fields_to_edit', array(&$this, 'control_add_image_to_menu'), 20,2); 29 30 add_filter("wp_get_nav_menu_items", array(&$this, "get_custom_menu_image_css"), 20, 2); … … 33 34 add_action('admin_head', array(&$this, 'add_js')); 34 35 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')); 36 38 add_action( 'admin_print_scripts-media-upload-popup', array( &$this, 'media_upload_popup_js' ), 2000 ); 37 38 39 add_action('admin_head', array(&$this, 'admin_head')); 39 40 40 add_action('wp_ajax_add_image', array(&$this, "add_image")); 41 41 add_action('wp_ajax_remove_image', array(&$this, "remove_image")); 42 42 43 register_activation_hook(__FILE__, array(&$this, 'custom_menu_image_activation')); 43 44 register_uninstall_hook(__FILE__, array(&$this, 'custom_menu_image_uninstall')); 45 44 46 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 } 46 81 function media_upload_popup_js(){ 47 82 //wp_enqueue_script('wp-ajax-response'); … … 51 86 if(!$options || !is_array($options)) 52 87 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 )); 53 95 } 54 96 function custom_menu_image_uninstall(){ … … 56 98 } 57 99 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); 59 104 $urls = $_POST[$this->prefix.'-url']; 60 105 $urls_type = $_POST[$this->prefix.'-url-type']; … … 69 114 ); 70 115 } 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{ 94 136 background-repeat: no-repeat; 95 137 background-position: 5px center; 96 138 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 } 101 158 return $menuItems; 102 159 } 103 160 function print_custom_menu_image_css(){ 104 print implode("\n", $this->styles);161 //print implode("\n", $this->styles); 105 162 } 106 163 function control_add_image_to_menu( $fields, $post ) { … … 108 165 $id = (int) $post->ID; 109 166 $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; 112 169 } 113 170 return $fields; … … 119 176 wp_enqueue_script('jquery'); 120 177 wp_enqueue_script('wp-ajax-response'); 178 wp_enqueue_script('custom_menu_images', $this->url.'/js/custom_menu_images.js'); 121 179 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>"; 125 185 ?> 126 186 <script> 127 187 var menu_item_options = new Array(); 128 188 <?php 129 $menu_item_options = get_option($this->prefix );189 $menu_item_options = get_option($this->prefix."_".$nav_menu_selected_id); 130 190 if(count($menu_item_options) && is_array($menu_item_options)){ 131 191 foreach($menu_item_options as $k=>$v){ … … 135 195 } 136 196 ?> 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&tab=library&cmi_id='+id+'&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 }) 195 203 </script> 196 204 <?php 197 205 } 198 206 function admin_head(){ 199 200 201 202 207 ?> 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&load=wp-ajax-response,thickbox&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> 209 209 <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 }); 256 215 </script> 257 216 <?php … … 316 275 ))); 317 276 } 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> </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 } 318 343 } 319 344 $custom_menu_image = new CustomMenuImage(); -
custom-menu-images/trunk/readme.txt
r322526 r377552 4 4 Tags: nav_menus, images, custom images, icons, thumbnails, background, media gallery, upload, custom menu, item image 5 5 Requires at least: 3.0 6 <<<<<<< .mine 7 Tested up to: 3.1.2 8 Stable tag: 0.8 9 ======= 6 10 Tested up to: 3.0.3 7 11 Stable tag: 0.5 12 >>>>>>> .r377551 8 13 9 14 Adds an image field to all menu items and generates CSS, for user side background image manipulation. … … 13 18 Adds 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. 14 19 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.20 It can be used to set thumbnails and make mega-dropdowns, or to add a custom icon to each menu item 16 21 22 <<<<<<< .mine 23 Once configured by the developer, the administrator can easily change each image without touching a line of code. 24 ======= 17 25 It wont look nice out of the box, it is intended for developers who want extra functionality in the menu. 26 >>>>>>> .r377551 27 28 It wont always look nicely out of the box (actually it never does), it is intended for developers who want extra functionality in the menu. 18 29 19 30 == Installation == 20 31 21 1. Upload ajax-post-carouselfolder to the /wp-content/plugins/ directory32 1. Upload custom-menu-images folder to the /wp-content/plugins/ directory 22 33 2. Activate the plugin through the 'Plugins' menu in WordPress 23 34 3. Go to manage menus and each item will have a Custom image field. 35 4. You should now go add some images and configure your CSS to display background images as you want. 24 36 25 37 == Frequently Asked Questions == … … 34 46 Because you have to use it in conjuction with your custom CSS 35 47 36 = Any more questions? =48 = More questions? = 37 49 38 50 Please write in the forums or write us to [email protected] we will be speaking in no time. … … 44 56 == Changelog == 45 57 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 ======= 46 67 = 0.5 = 47 68 * Fixed some bugs to allow selection of image size from Media Library ("Thumbnai", "Medium", "Large", "Original Size"). 48 69 70 >>>>>>> .r377551 49 71 = 0.2 = 50 72 * Initial release … … 53 75 == Upgrade Notice == 54 76 77 <<<<<<< .mine 78 = 0.8 = 79 It is getting better, Still testing. 80 81 ======= 55 82 = 0.5 = 56 83 If you want to choose the image size to use and not just thumbnail, this update is for you. 57 84 85 >>>>>>> .r377551 58 86 = 0.2 = 59 87 Initial release, come on and help us test it!
Note: See TracChangeset
for help on using the changeset viewer.