Plugin Directory

Changeset 386701


Ignore:
Timestamp:
05/19/2011 06:29:03 PM (15 years ago)
Author:
anabelle
Message:

Now is a single CSS file

Location:
custom-menu-images/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • custom-menu-images/trunk/custom-menu-images.php

    r377564 r386701  
    44Plugin URI: http://8manos.com
    55Description: None
    6 Version: 0.8.1
     6Version: 1.0
    77Author: 8manos
    88Author URI: http://8manos.com
     
    3434        add_action('admin_head', array(&$this, 'add_js'));
    3535        add_action('wp_footer', array(&$this, 'print_custom_menu_image_css'));
    36         add_action('admin_menu', array(&$this, 'custom_menu_images_menu'));
     36       
    3737        add_action('wp_head', array(&$this, 'front_end_head'));
    3838        add_action( 'admin_print_scripts-media-upload-popup', array( &$this, 'media_upload_popup_js' ), 2000 );
     
    7373    // add style into front-end header 
    7474    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");
     75        wp_register_style("custom-menu-images", site_url()."/wp-content/plugins/custom-menu-images/css/custom_menu_images.css");
    7776        wp_print_styles(array(
    7877            'custom-menu-images'
     
    9998    function save_config(){
    10099        if(strpos($_POST['_wp_http_referer'], 'nav-menus.php')!==false){
    101            
    102             $parentID = $_POST['menu'];
    103             $menu = $this->findMenu($parentID);
     100   
     101            $needSaveID = $_POST['menu'];
     102
    104103            $urls       = $_POST[$this->prefix.'-url'];
    105104            $urls_type  = $_POST[$this->prefix.'-url-type'];
     
    114113                    );
    115114                }
    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 
     115                $menus = wp_get_nav_menus();
     116               
     117                if(count($menus)){
    122118                $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{
    136                     background-repeat: no-repeat;
    137                     background-position: 5px center;
    138                     padding-left: 23px;
    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                         }';
     119                    $this->styles[] = "@charset \"utf-8\";\n/* 1/CSS Document */";
     120   
     121                   
     122                foreach($menus as $menu){
     123                    $parentID = $menu->term_id;
     124               
     125                    $settings = get_option($this->prefix."_settings");
     126               
     127           
     128                    $element = $menu->slug ? "#menu-".$menu->slug:"";
     129                    $element = "ul".$element;
     130                    $this->styles[] = "\n\n".'/* START <'.strtoupper($menu->slug).'>*/';
     131                    $this->styles[] = $element.' ul{width:auto;}';
     132                    $this->styles[] = ''
     133                    .$element.' li > a,'
     134                    .$element.' li:hover > a{
     135                        background-repeat: no-repeat;
     136                        background-position: 5px center;
     137                        padding-left: 23px;
     138                    }';
     139                    if($menu->term_id== $needSaveID){
     140                        if(get_option($this->prefix."_".$parentID)){
     141                            update_option($this->prefix."_".$parentID, $data);
     142                        }else{
     143                            add_option($this->prefix."_".$parentID, $data);
     144                        }
     145                        $custom_options = (get_option($this->prefix."_".$parentID));
     146                       
     147                    }else{
     148                        $custom_options = (get_option($this->prefix."_".$parentID));
    148149                    }
    149                 }
    150                 file_put_contents($this->dir."/css/custom_menu_images_$parentID.css", implode("\n", $this->styles));
     150                    foreach ($custom_options as $key => $val ) {
     151                        $image_url = ($custom_options[$key]['url_type'] != 'lib' ? $custom_options[$key]['url'] : $custom_options[$key]['media_lib']);
     152                        if($image_url){
     153                            $this->styles[] = ''
     154                            .$element.' li.cmi_menu_item_'.$key.' > a,'
     155                            .$element.' li.cmi_menu_item_'.$key.':hover > a {
     156                                background-image: url('.$image_url.');                     
     157                            }';
     158                        }
     159                    }
     160                    $this->styles[] = '/* END <'.strtoupper($menu->slug).'>*/';
     161                }
     162                }
     163                file_put_contents($this->dir."/css/custom_menu_images.css", preg_replace("#[\t]+#", "\t", implode("\n", $this->styles)));
    151164            }   
    152165        }
     
    182195    function admin_head_script(){
    183196    global $nav_menu_selected_id;
    184     //echo "<pre>1";print_r($nav_menu_selected_id);echo "</pre>";
    185197    ?>
    186198    <script>
     
    196208    ?>
    197209    jQuery(document).ready(function(){
    198 
    199210        CustomMenuImages
    200211            .init({prefix: '<?php echo $this->prefix?>', mediaUploadUrl: '<?php echo admin_url('media-upload.php');?>'})
     
    275286        )));
    276287    }
    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     }
     288   
    343289}
    344290$custom_menu_image = new CustomMenuImage();
  • custom-menu-images/trunk/readme.txt

    r377564 r386701  
    55Requires at least: 3.0
    66Tested up to: 3.1.2
    7 Stable tag: 0.8.1
     7Stable tag: 0.8.5
    88
    99Adds an image field to all menu items and generates CSS, for user side background image manipulation.
     
    1515It can be used to set thumbnails and make mega-dropdowns, or to add a custom icon to each menu item
    1616
    17 Once configured by the developer, the administrator can easily change each image without touching a line of code.
     17Once configured by the developer, the site administrator can easily change each image without touching a line of code.
    1818
    19 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.
     19It wont always look nice out of the box (actually it never does), it is intended for developers who want extra functionality in the menu, and ease of use for their site administrators.
    2020
    2121== Installation ==
     
    24242. Activate the plugin through the 'Plugins' menu in WordPress
    25253. Go to manage menus and each item will have a Custom image field.
    26 4. You should now go add some images and configure your CSS to display background images as you want.
     264. You should now go add some images and save.
     275. Configure your CSS to display background images as you want. Just the image url is set by the menu so you should set background position, repeating, and menu item size. Even sprites can be used, or image replacement techniques.
    2728
    2829== Frequently Asked Questions ==
     
    4748== Changelog ==
    4849
     50= 0.8.5 =
     51* We now generate a single CSS file for all menus, that means less HTTP requests and avoiding a common error where the active menu IDs where not correctly identified.
     52
    4953= 0.8.1 =
    5054* Minor fixes
     
    6367== Upgrade Notice ==
    6468
     69= 0.8.5 =
     70If you are having a 404 error from the CSS file, this version will fix your problem, just update, go and save your menus. CSS will be correctly generated now.
     71
    6572= 0.8.1 =
    6673We like quick iterating. Thank for testing with us.
Note: See TracChangeset for help on using the changeset viewer.