Plugin Directory

Changeset 1189406


Ignore:
Timestamp:
06/29/2015 08:57:10 AM (11 years ago)
Author:
mmtechmaster
Message:

Nightly commit for the new 1.2.0 version (in development). Previous version 1.1.4 was discontinued in favor of adding a configuration screen and custom CSS capability.

Location:
militant-moderates-css-parent-selector-mmps/trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • militant-moderates-css-parent-selector-mmps/trunk/css/mmParentSelector.css

    r1188826 r1189406  
    11/**
    22 * @package militant-moderates-css-parent-selector-mmps
    3  * @version 1.1.4
     3 * @version 1.2.0
    44 */
    55/*
     
    77Plugin URI: http://www.militantmoderates.org/mmps-quick-start/
    88Description: Adds CSS "Parent Selector" support to your Theme. Apply your CSS Style to Parent/Sibling elements not just the Selected element.
    9 Version: 1.1.4
     9Version: 1.2.0
    1010Author: MM Techmaster
    1111Author URI: https://profiles.wordpress.org/mmtechmaster
  • militant-moderates-css-parent-selector-mmps/trunk/js/mmParentSelector.js

    r1188826 r1189406  
    11/**
    22 * @package militant-moderates-css-parent-selector-mmps
    3  * @version 1.1.4
     3 * @version 1.2.0
    44 */
    55/*
     
    77Plugin URI: http://www.militantmoderates.org/mmps-quick-start/
    88Description: Adds CSS "Parent Selector" support to your Theme. Apply your CSS Style to Parent/Sibling elements not just the Selected element.
    9 Version: 1.1.4
     9Version: 1.2.0
    1010Author: MM Techmaster
    1111Author URI: https://profiles.wordpress.org/mmtechmaster
     
    2727*/
    2828
     29var packageName = 'militant-moderates-css-parent-selector-mmps';
     30var packageVersion = '1.2.0';
     31
    2932jQuery(document).ready(function( $ ) {
    3033
    31     var evidx = 0, k = 0, i, j,
     34    var styleidx = -1, slctridx = 1, evidx = 0, clsidx = 0,
    3235
    3336     // Class that's added to every styled element
     
    109112        var ret = '';
    110113
    111         for (var i = 0; i < aryRegExp.length; i++)
     114        for (var i = 0; i < aryRegExp.length; i++) {
    112115            ret += aryRegExp[i].source;
     116        }
    113117
    114118        return ret;
    115119    })([
    116120        /[\w\s\/\.\-\:\=\[\]\(\)\~\+\|\,\*\'\"\^$#>]*(?=!)/,
    117         /[\w\s\/\.\-\:\=\[\]\(\)\~\+\|\,\*\'\"\^$#>!]*\{{1}/,
    118         /[^\}]+\}{1}/
     121        /[\w\s\/\.\-\:\=\[\]\(\)\~\+\|\,\*\'\"\^$#>!]*/,
     122        /\{{1}[^\}]+\}{1}/
    119123    ]), "gi");
     124
     125
     126    // stick debug prefix function behind a console.log so it gets stripped when they get stripped
    120127
    121128    parse = function(sRawCSS) {
     
    126133            parsed = '';
    127134
    128             for (i = -1; ++i < matches.length; ) {
    129                 style = $.trim(matches[i]);
     135            for (styleidx = -1; ++styleidx < matches.length; ) {
     136                style = $.trim(matches[styleidx]);
    130137
    131138                // parse Selector portion of Style
     
    146153
    147154                parsedSelectors = '';
    148                 for (j = -1; ++j < selectors.length; ) {
    149                     selector = $.trim(selectors[j]);
     155                for (slctridx = -1; ++slctridx < selectors.length; ) {
     156                    selector = $.trim(selectors[slctridx]);
    150157
    151158                    (parsedSelectors.length) && (parsedSelectors += ",");
     
    157164                        // Split the selector on the '!' and save results
    158165                        var splitsel = selector.split('!');
    159                        
     166
    160167                        // recombine remaining array members in case a second '!' was included
    161168                        if (splitsel.length > 2)
     
    253260                                // If we successfully walked up the DOM tree and found the right parent...
    254261                                if (subject) {
    255                                     var id = CLASS + k++,
     262                                    var id = CLASS + clsidx++,
    256263
    257264                                    addNamespace = function( eType ) {
     
    269276                                        return false;
    270277                                    },
    271                                    
     278
    272279                                    getPseudoEvent = function( ppNorm ) {
    273280                                        if ( eventMap[ ppNorm ] )
     
    407414
    408415            if (parsed.length)
    409                 $('<style type="text/css" mmps_gen="yes">' + parsed + '</style>').appendTo('head');
     416                $('<style type="text/css" mmps_ver="' + packageVersion + '">' + parsed + '</style>').appendTo('head');
    410417
    411418        } else {        // else "if !matches"
     
    456463    }
    457464
    458     $('link[rel="stylesheet"],style').each(function(i) {
    459         if ($(this).is('link')) {
    460             var href = $(this).attr('href');
    461 
    462             $.ajax({
    463                 type: 'GET',
    464                 url: href,
    465                 dataType: 'text'
    466             }).done(function(css) {
    467                 parse(css);
    468             }).fail(function() {
    469             });
    470         } else {
    471             parse($(this).text());
     465    var parseExternal = true;
     466    var parseInline = true;
     467   
     468    $('script[src*="' + packageName + '"]').each(function() {
     469        var src = $(this).attr('src').split('?');
     470        if ( src[1] ) {
     471            var argv = src[1].split('&');
     472            for ( var j=0; j < argv.length; ++j ) {
     473                var pair = argv[j].split('=');
     474                if ( pair[0] == 'ver' ) {
     475                    pair = pair[1].split('+');
     476                    if ( pair[0] != packageVersion ) {
     477                    }
     478                    if ( pair[1] ) {
     479                        if ( pair[1].indexOf('X') < 0 )
     480                            parseExternal = false;
     481                        if ( pair[1].indexOf('I') < 0 )
     482                            parseInline = false;
     483                    } else {
     484                        parseExternal = parseInline = false;
     485                    }
     486                }
     487            }
    472488        }
    473489    });
     490   
     491
     492    $('link[rel="stylesheet"],style').each(function(i) {
     493        if ( $(this).attr('mmps_rev') ) {
     494        } else if ( $(this).attr('mmps_ignore') ) {
     495        } else if ( $(this).is('link') ) {
     496            if ( parseExternal ) {
     497                var href = $(this).attr('href');
     498                $.ajax({
     499                    type: 'GET',
     500                    url: href,
     501                    dataType: 'text'
     502                }).done(function(css) {
     503                    parse(css);
     504                }).fail(function() {
     505                });
     506            }
     507        } else if ( parseInline ) {
     508            parse( $(this).text() );
     509        }
     510    });
    474511
    475512});
  • militant-moderates-css-parent-selector-mmps/trunk/js/mmParentSelector.min.js

    r1188826 r1189406  
    11
    2 jQuery(document).ready(function($){var evidx=0,k=0,i,j,CLASS='mmPpSsPrEfIx',eventMap={abort:'abort',active:'focusin',click:'click',dblclick:'dblclick',focus:'focusin',focusout:'focusout',hover:'mouseover',keyup:'keyup',load:'load',mouseleave:'mouseleave',mousemove:'mousemove',mouseout:'mouseout',mouseup:'mouseup',resize:'resize',scroll:'scroll',select:'select',unload:'unload',visited:'click',wheel:'wheel',},pairedEventMap={focusin:'focusout',keydown:'keyup',mousedown:'mouseup mouseout mouseleave',mouseenter:'mouseleave',mouseover:'mouseout',},stateMap={active:':active',disabled:':disabled',empty:':empty',enabled:':enabled',first_child:':first-child',first_of_type:':first-of-type',in_range:':in-range',invalid:':invalid',lang:':lang',last_child:':last-child',last_of_type:':last-of-type',link:':link',not:':not',nth_child:':nth-child',nth_last_child:':nth-last-child',nth_last_of_type:':nth-last-of-type',nth_of_type:':nth-of-type',only_of_type:':only-of-type',only_child:':only-child',optional:':optional',out_of_range:':out-of-range',read_only:':read-only',read_write:':read-write',required:':required',target:':target',valid:':valid',visited:':visited'},pseudoElements={after:'::after',before:'::before',first_letter:'::first-letter',first_line:'::first-line',selection:'::selection'},parsed,parsedSelectors,matches,selectors,selector,parent,target,child,pseudoTargets,declarations,pseudoParent,pseudoParents,childSelector,childElements,REGEX=new RegExp((function(aryRegExp){var ret='';for(var i=0;i<aryRegExp.length;i++)
    3 ret+=aryRegExp[i].source;return ret;})([/[\w\s\/\.\-\:\=\[\]\(\)\~\+\|\,\*\'\"\^$#>]*(?=!)/,/[\w\s\/\.\-\:\=\[\]\(\)\~\+\|\,\*\'\"\^$#>!]*\{{1}/,/[^\}]+\}{1}/]),"gi");parse=function(sRawCSS){sRawCSS=sRawCSS.replace(/(\/\*([\s\S]*?)\*\/)/gm,'');if(matches=sRawCSS.match(REGEX)){parsed='';for(i=-1;++i<matches.length;){style=$.trim(matches[i]);selectors=$.trim(style.split('{')[0]).split(/\s*,\s*/);declarations='{'+style.split(/\{|\}/)[1].replace(/^\s+|\s+$[\t\n\r]*/g,'')+'}';if(declarations==='{}'){continue;}
     2var packageName='militant-moderates-css-parent-selector-mmps';var packageVersion='1.2.0';jQuery(document).ready(function($){var styleidx=-1,slctridx=1,evidx=0,clsidx=0,CLASS='mmPpSsPrEfIx',eventMap={abort:'abort',active:'focusin',click:'click',dblclick:'dblclick',focus:'focusin',focusout:'focusout',hover:'mouseover',keyup:'keyup',load:'load',mouseleave:'mouseleave',mousemove:'mousemove',mouseout:'mouseout',mouseup:'mouseup',resize:'resize',scroll:'scroll',select:'select',unload:'unload',visited:'click',wheel:'wheel',},pairedEventMap={focusin:'focusout',keydown:'keyup',mousedown:'mouseup mouseout mouseleave',mouseenter:'mouseleave',mouseover:'mouseout',},stateMap={active:':active',disabled:':disabled',empty:':empty',enabled:':enabled',first_child:':first-child',first_of_type:':first-of-type',in_range:':in-range',invalid:':invalid',lang:':lang',last_child:':last-child',last_of_type:':last-of-type',link:':link',not:':not',nth_child:':nth-child',nth_last_child:':nth-last-child',nth_last_of_type:':nth-last-of-type',nth_of_type:':nth-of-type',only_of_type:':only-of-type',only_child:':only-child',optional:':optional',out_of_range:':out-of-range',read_only:':read-only',read_write:':read-write',required:':required',target:':target',valid:':valid',visited:':visited'},pseudoElements={after:'::after',before:'::before',first_letter:'::first-letter',first_line:'::first-line',selection:'::selection'},parsed,parsedSelectors,matches,selectors,selector,parent,target,child,pseudoTargets,declarations,pseudoParent,pseudoParents,childSelector,childElements,REGEX=new RegExp((function(aryRegExp){var ret='';for(var i=0;i<aryRegExp.length;i++){ret+=aryRegExp[i].source;}
     3return ret;})([/[\w\s\/\.\-\:\=\[\]\(\)\~\+\|\,\*\'\"\^$#>]*(?=!)/,/[\w\s\/\.\-\:\=\[\]\(\)\~\+\|\,\*\'\"\^$#>!]*/,/\{{1}[^\}]+\}{1}/]),"gi");parse=function(sRawCSS){sRawCSS=sRawCSS.replace(/(\/\*([\s\S]*?)\*\/)/gm,'');if(matches=sRawCSS.match(REGEX)){parsed='';for(styleidx=-1;++styleidx<matches.length;){style=$.trim(matches[styleidx]);selectors=$.trim(style.split('{')[0]).split(/\s*,\s*/);declarations='{'+style.split(/\{|\}/)[1].replace(/^\s+|\s+$[\t\n\r]*/g,'')+'}';if(declarations==='{}'){continue;}
    44if(!/;}$/.test(declarations))
    5 declarations=declarations.replace(/}/g,';}');declarations=declarations.replace(/;/g,' !important;');parsedSelectors='';for(j=-1;++j<selectors.length;){selector=$.trim(selectors[j]);(parsedSelectors.length)&&(parsedSelectors+=",");var splitsel=selector.split('!');if(/!/.test(selector)){var splitsel=selector.split('!');if(splitsel.length>2)
     5declarations=declarations.replace(/}/g,';}');declarations=declarations.replace(/;/g,' !important;');parsedSelectors='';for(slctridx=-1;++slctridx<selectors.length;){selector=$.trim(selectors[slctridx]);(parsedSelectors.length)&&(parsedSelectors+=",");var splitsel=selector.split('!');if(/!/.test(selector)){var splitsel=selector.split('!');if(splitsel.length>2)
    66splitsel[1]=splitsel.slice(1).join('!');var splitp=splitsel[0].split(/[>~+\s]+/).reverse()[0].split(/[\:]+/);parent=$.trim(splitp[0]);pseudoParents=splitp.slice(1);var splitt=splitsel[1].split(/[>~+\s]+/).reverse()[0].split(/[\:]+/);target=$.trim(splitt[0])||[]._;pseudoTargets=splitt.slice(1);childSelector=selector.replace(/!/g,'').replace('::',':');$(pseudoParents).each(function(){childSelector=childSelector.replace(':'+this,'');});$(pseudoTargets).each(function(){if(eventMap[this.toString()]||pairedEventMap[this.toString()])
    77childSelector=childSelector.replace(':'+this,'');});childElements=childSelector.match(/([\>\+\~]|(\:not\()?((\w[\-\w]*|\*)|[\.\#]\w[\-\w]*|\:{1,2}\w[\-\w\(\)]*|\[[^\]]*\])+\)?\!?)/gi);if(childElements.length>1){var qDOM;do{qDOM=false;try{child=$(childSelector);}
    88catch(err){var ep=':'+$.trim(err.toString().match(/[\w\-]+$/i));if(childSelector.lastIndexOf(ep)>=0){childSelector=childSelector.replace(new RegExp(ep,'g'),'');qDOM=true;}}}while(qDOM);child.each(function(idx){var subject=$(this);var tmpNodes=childElements.slice(0,-1);;var n=$.trim(tmpNodes.pop());do{switch(n){case'>':n=$.trim(tmpNodes.pop());case'*':subject=subject.parent(n);break;case'+':n=$.trim(tmpNodes.pop());subject=subject.prev(n);break;case'~':n=$.trim(tmpNodes.pop());subject=subject.prev();while(subject&&!subject.is(n)){subject=subject.prev();}
    9 break;default:subject=subject.closest(n);break;}}while(subject&&n!=parent&&(n=$.trim(tmpNodes.pop())));if(subject){var id=CLASS+k++,addNamespace=function(eType){return eType.split(/[ ]+/).join('.e'+id+' ')+'.e'+id;},getPseudoElement=function(ppNorm){return pseudoElements[ppNorm.replace(/\-/g,'_')];},getPseudoState=function(ppNorm){var ps=ppNorm.split('(');if(stateMap[ps[0].replace(/\-/g,'_')])
     9break;default:subject=subject.closest(n);break;}}while(subject&&n!=parent&&(n=$.trim(tmpNodes.pop())));if(subject){var id=CLASS+clsidx++,addNamespace=function(eType){return eType.split(/[ ]+/).join('.e'+id+' ')+'.e'+id;},getPseudoElement=function(ppNorm){return pseudoElements[ppNorm.replace(/\-/g,'_')];},getPseudoState=function(ppNorm){var ps=ppNorm.split('(');if(stateMap[ps[0].replace(/\-/g,'_')])
    1010return stateMap[ps[0].replace(/\-/g,'_')]+ps.slice(1).join('(');return false;},getPseudoEvent=function(ppNorm){if(eventMap[ppNorm])
    1111return eventMap[ppNorm];else if(pairedEventMap[ppNorm])
     
    1919if(parsedSelectors.length){parsedSelectors+=' '+declarations;parsed+=parsedSelectors+"\n";}}
    2020if(parsed.length)
    21 $('<style type="text/css" mmps_gen="yes">'+parsed+'</style>').appendTo('head');}else{}};navigator.browserInfo=(function(){var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(M[1])){tem=/\brv[ :]+(\d+)/g.exec(ua)||[];return'IE '+(tem[1]||'');}
     21$('<style type="text/css" mmps_ver="'+packageVersion+'">'+parsed+'</style>').appendTo('head');}else{}};navigator.browserInfo=(function(){var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(M[1])){tem=/\brv[ :]+(\d+)/g.exec(ua)||[];return'IE '+(tem[1]||'');}
    2222if(M[1]==='Chrome'){tem=ua.match(/\b(OPR|Edge)\/(\d+)/);if(tem!=null)
    2323return tem.slice(1).join(' ').replace('OPR','Opera');}
    2424M=M[2]?[M[1],M[2]]:[navigator.appName,navigator.appVersion,'-?'];if((tem=ua.match(/version\/(\d+)/i))!=null)M.splice(1,1,tem[1]);return{'browser':M[0],'version':M[1]};;})();if(navigator.browserInfo.browser=="MSIE"&&navigator.browserInfo.version<=8){pseudoElements={after:':after',before:':before',first_letter:':first-letter',first_line:':first-line',selection:':selection'};stateMap={active:':active',disabled:':disabled',empty:':empty',enabled:':enabled',invalid:':invalid',lang:':lang',link:':link',not:':not',optional:':optional',required:':required',target:':target',valid:':valid',visited:':visited'};}
    25 $('link[rel="stylesheet"],style').each(function(i){if($(this).is('link')){var href=$(this).attr('href');$.ajax({type:'GET',url:href,dataType:'text'}).done(function(css){parse(css);}).fail(function(){});}else{parse($(this).text());}});});
     25var parseExternal=true;var parseInline=true;$('script[src*="'+packageName+'"]').each(function(){var src=$(this).attr('src').split('?');if(src[1]){var argv=src[1].split('&');for(var j=0;j<argv.length;++j){var pair=argv[j].split('=');if(pair[0]=='ver'){pair=pair[1].split('+');if(pair[0]!=packageVersion){}
     26if(pair[1]){if(pair[1].indexOf('X')<0)
     27parseExternal=false;if(pair[1].indexOf('I')<0)
     28parseInline=false;}else{parseExternal=parseInline=false;}}}}});$('link[rel="stylesheet"],style').each(function(i){if($(this).attr('mmps_rev')){}else if($(this).attr('mmps_ignore')){}else if($(this).is('link')){if(parseExternal){var href=$(this).attr('href');$.ajax({type:'GET',url:href,dataType:'text'}).done(function(css){parse(css);}).fail(function(){});}}else if(parseInline){parse($(this).text());}});});
  • militant-moderates-css-parent-selector-mmps/trunk/mmParentSelector.php

    r1188826 r1189406  
    22/**
    33 * @package militant-moderates-css-parent-selector-mmps
    4  * @version 1.1.4
     4 * @version 1.2.0
    55 */
    66/*
     
    88Plugin URI: http://www.militantmoderates.org/mmps-quick-start/
    99Description: Adds CSS "Parent Selector" support to your Theme. Apply your CSS Style to Parent/Sibling elements not just the Selected element.
    10 Version: 1.1.4
     10Version: 1.2.0
    1111Author: MM Techmaster
    1212Author URI: https://profiles.wordpress.org/mmtechmaster
     
    3939 *-------------------------------------------------------------------------------------*/
    4040define( 'MMPS_SCRIPT_DEV', 0 );                     // set as above: 0, 1, 2
    41 define( 'MMPS_SCRIPT_VERSION', '1.1.4' );           // set to script version number as in header
     41define( 'MMPS_SCRIPT_VERSION', '1.2.0' );           // set to script version number as in header
    4242
    4343function mmps_js() {
     
    4646    // pure CSS rules. Depends on jQuery.
    4747   
     48    // Here's where we get funky. The script version number is used to piggyback the option settings
     49    // that control which sources of CSS will be parsed and which will be ignored.
     50    // If the option to
     51    $mmps_ver = '';
     52    $mmps_ccss = get_option('mmpsccss_settings');
     53    if ( !isset( $mmps_ccss[ 'mmps_ccss_parse_external' ] ) )
     54        $mmps_ver .= 'X';
     55    if ( !isset( $mmps_ccss[ 'mmps_ccss_parse_inline' ] ) )
     56        $mmps_ver .= 'I';
     57    $mmps_ver = MMPS_SCRIPT_VERSION . ( $mmps_ver != '' ? '+' . $mmps_ver : '' );
     58
    4859    // If DEBUG mode is selected and the current user has capability to activate plugins ..
    4960    // AND the .dev.js full debug version is available then ...
     
    5263        // the .dev.js version is the working copy with full debugging included
    5364        // it is NOT included in the standard distribution, so protect against attempts to use it
    54         wp_enqueue_script( 'mmps_js', plugins_url( 'js/mmParentSelector.dev.js', __FILE__ ), array( 'jquery' ), MMPS_SCRIPT_VERSION );
     65        wp_enqueue_script( 'mmps_js', plugins_url( 'js/mmParentSelector.dev.js', __FILE__ ), array( 'jquery' ), $mmps_ver );
    5566
    5667    } elseif ( MMPS_SCRIPT_DEV != 1 ) {
    5768        // Either in full DEBUG mode but not allowed (not an admin) or FULL version NOT specified explicitly ...
    5869        // the .min.js version is stripped of all debugging code and minified
    59         wp_enqueue_script( 'mmps_js', plugins_url( 'js/mmParentSelector.min.js', __FILE__ ), array( 'jquery' ), MMPS_SCRIPT_VERSION );
     70        wp_enqueue_script( 'mmps_js', plugins_url( 'js/mmParentSelector.min.js', __FILE__ ), array( 'jquery' ), $mmps_ver );
    6071
    6172    } else {
    6273        // the .js version is stripped of debugging but is NOT minified
    63         wp_enqueue_script( 'mmps_js', plugins_url( 'js/mmParentSelector.js', __FILE__ ), array( 'jquery' ), MMPS_SCRIPT_VERSION );
     74        wp_enqueue_script( 'mmps_js', plugins_url( 'js/mmParentSelector.js', __FILE__ ), array( 'jquery' ), $mmps_ver );
    6475
    6576    }
     
    6778    if ( file_exists( plugin_dir_path( __FILE__ ) . 'js/mmParentSelector.dev.js' ) &&
    6879         file_exists( plugin_dir_path( __FILE__ ) . 'css/mmParentSelector.css' ) )
    69         wp_enqueue_style( 'mmps_js', plugins_url( 'css/mmParentSelector.css', __FILE__ ) );
     80        wp_enqueue_style( 'mmps_js', plugins_url( 'css/mmParentSelector.css', __FILE__ ), array(), MMPS_SCRIPT_VERSION );
    7081}
    7182
    7283add_action( 'wp_enqueue_scripts', 'mmps_js' );
    7384
     85if(!class_exists('MMPSccss')) {
     86    class MMPSccss     {
     87        private $options;
     88
     89        public function __construct() {
     90            add_action( 'admin_menu', array($this, 'add_menu'));
     91            add_action( 'admin_init', array( $this, 'init_settings' ) );
     92            add_action( 'add_meta_boxes', array($this, 'add_meta_box' ) );
     93            add_action( 'save_post', array( $this, 'single_save' ) );
     94            add_action( 'init', array($this, 'init'));
     95            add_filter( 'query_vars', array($this, 'add_wp_var'));
     96            add_action( 'wp_enqueue_scripts', array($this, 'add_mmps'), 999 );
     97            add_action( 'wp_head', array($this, 'single_mmps_css'));
     98        }
     99
     100        public function init() {
     101            load_plugin_textdomain( 'mmps-ccss-add-custom-css', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     102        }
     103
     104        public static function uninstall() {
     105            self::delete_options();
     106            self::delete_custom_meta();
     107        }
     108
     109        public function add_meta_box( $post_type ) {
     110            $post_types = array('post', 'page');
     111            if ( in_array( $post_type, $post_types )) {
     112                // delegate to the WP function add_meta_box
     113                add_meta_box( 'mmps_ccss_add_mmps',
     114                    __( 'Parent Selector CSS', 'mmps-ccss-add-custom-css' ),
     115                    array( $this, 'render_meta_box_content' ),
     116                    $post_type, 'advanced', 'high'
     117                );
     118            }
     119        }
     120
     121        public function single_save( $post_id ) {
     122            if ( ! isset( $_POST['mmps_ccss_add_mmps_box_nonce'] ) || ! wp_verify_nonce( $_POST['mmps_ccss_add_mmps_box_nonce'], 'single_add_mmps_box' ) ) {
     123                return;
     124            }
     125            if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
     126                return;
     127            }
     128            if ( 'page' == $_POST['post_type'] ) {
     129                if ( ! current_user_can( 'edit_page', $post_id ) )
     130                    return;
     131            } else {
     132                if ( ! current_user_can( 'edit_post', $post_id ) )
     133                    return;
     134            }
     135
     136            $single_mmps_css = wp_kses( $_POST['single_mmps_css'], array( '\'', '\"' ) );
     137            update_post_meta( $post_id, '_single_add_mmps', $single_mmps_css );
     138        }
     139
     140        public function render_meta_box_content( $post ) {
     141            wp_nonce_field( 'single_add_mmps_box', 'mmps_ccss_add_mmps_box_nonce' );
     142            $single_mmps_css = get_post_meta( $post->ID, '_single_add_mmps', true );
     143            echo '<p>'.  sprintf( __( 'The normal CSS and Parent Selector CSS Rules entered here will always be scanned by MMPS and will be applied to this %s', 'mmps-ccss-add-custom-css' ), $post->post_type ). '</p> ';
     144            echo '<textarea id="single_mmps_css" name="single_mmps_css" style="width:100%; min-height:200px;">' . esc_attr( $single_mmps_css ) . '</textarea>';
     145        }
     146
     147        public function add_menu() {
     148            global $mmpsccss_settings_page;
     149            $mmpsccss_settings_page = add_menu_page( __('Militant Moderates Parent Selector CSS - Global Settings', 'mmps-ccss-add-custom-css'), __('MMPS', 'mmps-ccss-add-custom-css'), 'manage_options', 'mmps-ccss-add-custom-css_settings', array($this, 'create_settings_page'), plugin_dir_url( __FILE__ ) . '/images/icon.png');
     150        }
     151
     152        public function create_settings_page() {
     153            if (! current_user_can( 'manage_options' ) ) {
     154            ?>
     155            <div class="wrap">
     156        <h2><?php echo __('Militant Moderates Parent Selector CSS', 'mmps-ccss-add-custom-css'); ?></h2>
     157        <p><?php echo __('You do not have permission to change these options.', 'mmps-ccss-add-custom-css'); ?></p>
     158            </div>
     159      <?php
     160            } else {
     161                $this->options = get_option( 'mmpsccss_settings' );
     162            ?>
     163            <div class="wrap">
     164        <h2><?php echo __('Militant Moderates Parent Selector CSS', 'mmps-ccss-add-custom-css'); ?></h2>
     165        <form id="mmps_ccss_form" method="post" action="options.php">
     166        <?php settings_fields( 'mmpsccss_group' ); ?>
     167        <?php do_settings_sections( 'mmps-ccss-add-custom-css_settings' ); ?>
     168                <?php submit_button( __('Save MMPS Settings', 'mmps-ccss-add-custom-css') ); ?>
     169                </form>
     170            </div>
     171      <?php
     172            }
     173        }
     174
     175        public function print_parse_info() {
     176            echo __('CSS Style Rules come from several different sources. Normally MMPS will scan them all<br />for Parent Selector CSS Rules. The following options allow you to choose which sources<br />will be ignored while scanning for Parent Selector CSS Rules.', 'mmps-ccss-add-custom-css');
     177        }
     178
     179        public function print_section_info() {
     180            echo __('The following CSS Rules will apply to the entire web site. They may include both regular<br />CSS and MMPS Parent Selector CSS. Any Rules entered here will always be applied to every<br />Post and Page.', 'mmps-ccss-add-custom-css');
     181        }
     182
     183        public function parse_external_input() {
     184            $checked_state = isset( $this->options['mmps_ccss_parse_external'] ) ? ' checked="checked"' : '';
     185            echo '<label for="mmpsccss_settings[mmps_ccss_parse_external]"><input name="mmpsccss_settings[mmps_ccss_parse_external]" id="mmpsccss_settings[mmps_ccss_parse_external]" type="checkbox"' . $checked_state . '>' . __('Check this option to IGNORE all External CSS Stylesheet files', 'mmps-ccss-add-custom-css') . '</label>';
     186        }
     187        public function parse_inline_input() {
     188            $checked_state = isset( $this->options['mmps_ccss_parse_inline'] ) ? ' checked="checked"' : '';
     189            echo '<label for="mmpsccss_settings[mmps_ccss_parse_inline]"><input name="mmpsccss_settings[mmps_ccss_parse_inline]" id="mmpsccss_settings[mmps_ccss_parse_inline]" type="checkbox"' . $checked_state . '>' . __('Check this option to IGNORE all Inline CSS Styles', 'mmps-ccss-add-custom-css') . '</label>';
     190        }
     191
     192        public function main_css_input() {
     193            $custom_rules = isset( $this->options['mmps_ccss_main_style'] ) ? esc_attr( $this->options['mmps_ccss_main_style'] ) : '';
     194            echo '<textarea name="mmpsccss_settings[mmps_ccss_main_style]" style="width:100%; min-height:300px;">' . $custom_rules . '</textarea>';
     195        }
     196
     197        public function init_settings() {
     198            register_setting(
     199                'mmpsccss_group',
     200                'mmpsccss_settings'
     201            );
     202            add_settings_section(
     203                    'mmpsccss_main_parse',
     204                    __('Select CSS sources to IGNORE while scanning for Parent Selector Rules', 'mmps-ccss-add-custom-css'),
     205                    array( $this, 'print_parse_info' ),
     206                    'mmps-ccss-add-custom-css_settings'
     207            );
     208            add_settings_field(
     209                    'mmps_ccss_parse_external',
     210                    __('Ignore external CSS files?', 'mmps-ccss-add-custom-css'),
     211                    array( $this, 'parse_external_input' ),
     212                    'mmps-ccss-add-custom-css_settings',
     213                    'mmpsccss_main_parse'
     214            );
     215            add_settings_field(
     216                    'mmps_ccss_parse_inline',
     217                    __('Ignore inline CSS rules?', 'mmps-ccss-add-custom-css'),
     218                    array( $this, 'parse_inline_input' ),
     219                    'mmps-ccss-add-custom-css_settings',
     220                    'mmpsccss_main_parse'
     221            );
     222
     223            add_settings_section(
     224                    'mmpsccss_main_style',
     225                    __('Site-wide Parent Selector CSS Rules', 'mmps-ccss-add-custom-css'),
     226                    array( $this, 'print_section_info' ),
     227                    'mmps-ccss-add-custom-css_settings'
     228            );
     229            add_settings_field(
     230                    'mmps_ccss_main_style',
     231                    __('Parent Selector CSS rules', 'mmps-ccss-add-custom-css'),
     232                    array( $this, 'main_css_input' ),
     233                    'mmps-ccss-add-custom-css_settings',
     234                    'mmpsccss_main_style'
     235            );
     236        }
     237
     238        public function delete_options() {
     239            unregister_setting(
     240                'mmpsccss_group',
     241                'mmpsccss_settings'
     242            );
     243            delete_option('mmpsccss_settings');
     244        }
     245
     246        public function delete_custom_meta() {
     247            delete_post_meta_by_key('_single_add_mmps');
     248        }
     249
     250        public static function add_wp_var($public_query_vars) {
     251            $public_query_vars[] = 'display_mmps_ccss';
     252            return $public_query_vars;
     253        }
     254
     255        public static function display_mmps_ccss(){
     256            $display_css = get_query_var('display_mmps_ccss');
     257            if ($display_css == 'css') {
     258                include_once (plugin_dir_path( __FILE__ ) . '/css/mmps-ccss.php');
     259                exit;
     260            }
     261        }
     262
     263        public function add_mmps() {
     264            $this->options = get_option( 'mmpsccss_settings' );
     265            if ( isset($this->options['mmps_ccss_main_style']) && $this->options['mmps_ccss_main_style'] != '') {
     266                wp_register_style( 'mmps-ccss-add-custom-css', get_bloginfo('url') . '?display_mmps_ccss=css' );
     267                wp_enqueue_style( 'mmps-ccss-add-custom-css' );
     268            }
     269        }
     270
     271        public function single_mmps_css() {
     272            if ( is_single() || is_page() ) {
     273                global $post;
     274                $single_mmps_css = get_post_meta( $post->ID, '_single_add_mmps', true );
     275                if ( $single_mmps_css !== '' ) {
     276                    $single_mmps_css = str_replace ( array( '&gt;', '&lt;' ), array( '>', '<' ), $single_mmps_css );
     277                    $output = "<style type=\"text/css\">\n" . $single_mmps_css . "\n</style>\n";
     278                    echo $output;
     279                }
     280            }
     281        }
     282    }
     283}
     284
     285if(class_exists('MMPSccss')) {
     286    add_action('template_redirect', array('MMPSccss', 'display_mmps_ccss'));
     287    register_uninstall_hook(__FILE__, array('MMPSccss', 'uninstall'));
     288    $mmpsccss = new MMPSccss();
     289}
     290
     291if(isset($mmpsccss)) {
     292    function mmpsccss_settings_link($links) {
     293        $settings_link = '<a href="admin.php?page=mmps-ccss-add-custom-css_settings">' . __('Settings', 'mmps-ccss-add-custom-css') . '</a>';
     294        array_unshift($links, $settings_link);
     295        return $links;
     296    }
     297    add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'mmpsccss_settings_link');
     298}
     299
    74300?>
  • militant-moderates-css-parent-selector-mmps/trunk/readme.txt

    r1188967 r1189406  
    3434
    3535== Changelog ==
    36 = 1.1.4 (in development) =
     36= 1.2.0 (in process) =
     37* Optimizations in run-time performance greatly increase load speed
     38* Added the ability to save custom CSS rules for the entire site and on a per page/post basis
     39* Added options to ignore external CSS files and inline CSS Styles
     40* (more changes coming)
     41
     42= 1.1.4 (unreleased) =
    3743* Massive rework under the event handling hood; switching to bind/unbind instead of on/off
    3844* Handle <a> link elements differently because of the :link and :visited behavioral differences
    3945* Added error handling around calls into the DOM that might fail under older browsers
    40  * Changes in progress - Stay tuned for details
     46* *Version terminated - Rolled to 1.2.0*
    4147
    4248= 1.1.3 =
Note: See TracChangeset for help on using the changeset viewer.