Sync plugins from current page

Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
2019-09-11 19:08:46 +02:00
parent 85d41e4216
commit 8515ff9587
1847 changed files with 505469 additions and 0 deletions

View File

@@ -0,0 +1,204 @@
=== Scripts n Styles ===
Contributors: WraithKenny, CaptainN
Tags: admin, CSS, javascript, code, custom, Style
Requires at least: 5.0
Tested up to: 5.1
Requires PHP: 5.4
Stable tag: 3.5.1
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
This plugin allows Admin users to individually add HTML, custom CSS, Classes and JavaScript directly to Post, Pages or any other custom post types.
== Description ==
This plugin allows Admin users the ability to add custom CSS and JavaScript directly into individual Post, Pages or any other registered custom post types. You can also add classes to the body tag and the post container. There is a Global settings page for which you can write Scripts n Styles for the entire blog.
Admin's can also add classes to the TinyMCE "Formats" dropdown which users can use to style posts and pages directly. As of Scripts n Styles 3+ styles are reflected in the post editor.
Because only well trusted users should ever be allowed to insert JavaScript directly into the pages of your site, this plugin restricts usage to admin type users. Admin's have access to even more sensitive areas by definition, so that should be relatively safe ;)
= Notes about the implementation: =
* Admin users, or more specifically, *any user with the `manage_options` and `unfiltered_html` capabilities* (which by default is *only* the admin type user) can use this plugin's functionality. Some plugins extend user rolls, and so this plugin would naturally extend include rolls that have the appropriate capability.
* CSS Styles are embeded, not linked, at the bottom of the `head` element with `style` tags by using `wp-head`. If your theme doesn't have this hook, this plugin (as well as most others) won't work.
* JavaScript is embeded, not linked, at the bottom of the `body` (or `head`) element with `script` tags by using `wp-footer` (or `wp-head`). If your theme doesn't have this hook, this plugin (as well as most others) won't work.
* **There is no input validation.** This plugin puts exactly what you type in the meta box directly into the `html` with no error checking. You are an Admin, and we trust you to be carefull. Try not to break anything.
* Do to the licensing of the libraries used, this plugin is released "GPL 3.0 or later" if you care about those things.
= Contact: =
You'll have better luck contacting me if you try me on [Twitter](http://twitter.com/WraithKenny1) and [Github](https://github.com/unFocus/Scripts-n-Styles/issues). I also have a day job at [Ashworth Creative](https://ashworthcreative.com/); check us out!
== Installation ==
This plugin does not require any special activation or template tags. Just get it from wordpress.org/extend, install and activate like normal.
== Frequently Asked Questions ==
= Will I lose all of my custom Styles and Scripts if I uninstall the plugin? =
Yes, absolutely. **YOU WLL LOSE ALL CUSTOMIZATIONS.** Be sure that you do not want these customizations before you uninstall.
= Why would you do that to me? =
Well, because plugins are supposed to, and should be expected to clean up after themselves. If you disable and uninstall the plugin, as a developer, I am supposed to assume that you no longer want me to store all of that now useless data in your database.
= Can I get around that somehow? =
Sure, if you are an Admin, just go to the plugin editor and wipe out the uninstall.php and then WordPress will not delete the meta data on uninstall.
== Screenshots ==
1. Settings Page for Writing Scripts n Styles that apply to the whole blog.
2. The Scripts panel of the Meta Box.
3. The Styles panel of the Meta Box.
4. The Classes panel. Add classes to the Style dropdown!
5. Enqueue panel. You can enqueue jQuery from here if you need!
6. Your styles are reflected in the Editor.
== Changelog ==
= 3.5.1 =
* Fix JS error in Classic mode
= 3.5 =
* Fix some functionality for Gutenberg
* Add arbitrary HTML fields
= 3.4.4 =
* Rename codemirror handle for compatibility
= 3.4.3 =
* No newline at end of file
* Remove closing php tags
* More guards against PHP 7.1 array conversion breaking change
= 3.4.2 =
* Silence alert debug message.
= 3.4.1 =
* Fix meta box saving.
= 3.4 =
* Add option to not delete data on uninstall
* Version 4.0 will drop php support under 5.4
* This version disables updates for installs with php < 5.4
* 4.0 will launch when most have updated to 3.4 :) (and when it's done.)
= 3.3 =
* See the github repo commits
= 3.2.1 =
* metabox add shortcode bugfix
= 3.2 =
* Add AJAX to Shortcode Tab
* Add "Chosen" for selects
* General UI Improvements
* Add CoffeeScript Support
* Add Hoops Widget
* Add Global Hoops Shortcodes
* Add Markdown mode to code editor
* Add (fix) code editor themes
* Theme Support (Beta Feature)
= 3.1.1 =
* Add (fix) CodeMirror Themes
= 3.1 =
* Feature: Dynamic Shortcodes.
* Feature: LESS.js support.
* Bug Fix: Proper output escaping.
= 3.0.3 =
* Bug Fix: wpautop formatting.
= 3.0.2 =
* Bug Fix: Fatal Error on post save
= 3.0.1 =
* Option to show Metabox by default
* Check upgrade in more places
* Fix double Settings Message on general-options
* Fix empty post showing on usage
* Cleaned up constants (internal)
= 3 =
* AJAX Saving of Meta-box
* Dynamically populate the Styles Dropdown for TinyMCE
* Styles preview in Post Editor
* Enqueue dependant scripts if you need (like jQuery)
* Adjustable menu placement
* CodeMirror Themes
= 2.0.3 =
* fixed some bugs
= 2.0.1 =
* Better selection of `post_types` to add Scripts-n-Styles
* micro-optimization for storage of class names.
* Adds option page for globally adding Scripts and Styles.
* Defined a later priority for Scripts n Styles to print after other scripts and styles.
* Added a box for Scripts to be included in the `head`.
* Better adherence to coding standards.
* Tabbed interface on metabox
* added CodeMirror
* began contextual help
= 1.0.2 =
* Added fields for `body_clas`s and `post_class`
* Merged meta boxes
* Cleaned up code
* Improved compatibility
* Added Screenshot
= 1.0.1 =
* Some small plugin meta data updates.
= 1.0 =
* Initial Release.
== Upgrade Notice ==
= 3.3 =
Bug fixes and lib upgrades
= 3.2.1 =
Bug fix (add shortcode)
= 3.2 =
New Major Features
= 3.1.1 =
Add (fix) CodeMirror Themes
= 3.1 =
New Features and Bug fixes
= 3.0.3 =
Bug fix (wpauto issue)
= 3.0.2 =
Bug fix
= 3.0.1 =
Bug fixes
= 3 =
Adds new features.
= 2 =
Adds new features.
= 1.0.3 =
Adds a few new features.
= 1.0.2 =
Minor update. Adds a few new features.
= 1.0.1 =
Some small plugin meta data updates.
= 1.0 =
Initial Release, there is nothing to upgrade from.

View File

@@ -0,0 +1,3 @@
#newcontent{display:block;}
.CodeMirror{border:1px solid #DFDFDF;background-color:white;margin:8px 0;}
#template .CodeMirror{margin-right:30px;}#template .CodeMirror div{margin-right:0;}

View File

@@ -0,0 +1,42 @@
#editorcontainer #content{font-family:"Courier New",Courier,monospace;}
.CodeMirror{height:200px;border:1px solid #DFDFDF;}
.autoheight .CodeMirror{height:auto;}
.autoheight .CodeMirror-scroll{overflow-x:auto;overflow-y:hidden;}
.style,.script,.less,.coffee{background-color:white;margin:8px 0;background-clip:padding-box;font-family:"Courier New",Courier,monospace;}.style:before,.script:before,.less:before,.coffee:before,.style:after,.script:after,.less:after,.coffee:after{border:1px solid #dfdfdf;position:relative;z-index:3;display:block;padding:.5em;background-color:#f5f5f5;color:#333;font-family:"Courier New",Courier,monospace;line-height:1em;text-shadow:none;}
.style:before,.script:before,.less:before,.coffee:before{border-bottom:0 none;border-radius:5px 5px 0px 0px;}
.style:after,.script:after,.less:after,.coffee:after{border-top:0 none;border-radius:0px 0px 5px 5px;}
.style:before{content:'<style type="text/css">';}
.style:after{content:'</style>';}
.script:before{content:'<script type="text/javascript">';}
.script:after{content:'</script>';}
.less:before{content:'<style type="text/less">';}
.less:after{content:'</style>';}
.coffee:before{content:'<script type="text/coffeescript">';}
.coffee:after{content:'</script>';}
.sns-shortcode p{margin:0;}
.sns-collapsed-shortcode{overflow:hidden;}.sns-collapsed-shortcode .sns-collapsed-shortcode-btn{background-position:1px -107px;}
.sns-collapsed-shortcode .CodeMirror,.sns-collapsed-shortcode .sns-ajax-wrap{visibility:hidden;position:absolute;}
.sns-collapsed-shortcode-btn{cursor:pointer;float:left;height:1.4em;width:1.4em;background-image:url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%0F%00%00%00%7B%08%06%00%00%00%ABe%DA%9D%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%01%90IDATx%DA%EC%991N%C3%40%10E%D7%40%1D%A4(G%A0%A2%A0%E2%06Q%90%DB%5C%02%09%AA%F4%A1%8C%7BW%20%E5%10P%DA%22%E2%06%AERP%E5%08%08)%F4%D6%F2G%FA%C5j%E5%F5%AEM%81%10%B3%D2%D7%EC%3A~%1E%7Bci%BE%C6%99%B5%D6%8C%1D'%E6%07%E3%8F%C2g%FE%81%BA%AE%1B%84%0B.'%D0%17%E7%87%3C%CF%AFc%99%0B%E8%9C%CA%9Cy%E1%9F%98u%FDU%C8%FE%8A%B0p%0E%ED%90%F5%26%F5%99WP%CBy%CBu%DA%86!%CB%3B%C2%96%CB-%D7%83v%FB%01%B2%8C%DDC%9E9%A4%AA%AA%E6%7D%BFg%FAn%2B%AC%B0%C2%0A%2B%FC%CB0%EA%F4%BC%EF%F7%60%AD%028E%F8%80f(%B1%9FC3oh%2B6%832%23%EB%25%C2%1E%3A%A53%B8%EA*%F0%A1%CC%25A%C3X%26%DD6%B2.%3D3%23c%C1%E3%D1%CCk%E8HYg%BEN%DEm%7D%B7%15VXa%85%15V8v%82%D4e%B6%3F%E2%7D%12%CFZ%94%2C%F4%C7%D4%26%CB%94%26%E6%D6%B1%16%F1%0E%0D%7D%D7%8E.%C8%1D%93%E83%C3%F1%BC%89%EF%82%9E%9C%3E%89qZ%3C%FD%1B%26%86%0D%BA%17%FB%C4%BB0%A3Z%1Dlw%2C%A1F%5B%1D%0A%2B%AC%B0%C2%0A%2B%CC%22%DFt%F5%08R3%CB%B7%9Bg%F9%92Bo2%EA%B6%C5%CC%ECq%81Gz%95%24%D8%F5%20bj%EE%A4%D5%E3%F7%8AB%B0%EBAZz%94%19%3DK%DC%87q%88'Y%85%BE%DD%84%E0%03T%00z%E9%BB%F2%7F%F4%24%DF%02%0C%00%C9H%D9%18%7B.%E6%93%00%00%00%00IEND%AEB%60%82");background-attachment:scroll;background-repeat:no-repeat;background-position:1px 1px;margin-right:.5em;}
#add-mce-dropdown-names label{width:50px;display:inline-block;}
.sns-ajax-loading{display:none;vertical-align:top;}.sns-ajax-loading .spinner{float:none;}
.sns-ajax-wrap{height:23px;height:auto;}
#sns-classes{overflow:hidden;width:100%;}
#SnS_classes_mce_wrapper{margin:6px 0;}
#mce-dropdown-names{display:none;}body.js #mce-dropdown-names{display:block;}
#delete-mce-dropdown-names .sns-ajax-delete{cursor:pointer;display:inline-block;height:10px;overflow:hidden;text-indent:-9999px;width:10px;background:url("/wp-admin/images/xit.gif") no-repeat scroll 0 0 transparent;}#delete-mce-dropdown-names .sns-ajax-delete:hover{background:url("/wp-admin/images/xit.gif") no-repeat scroll -10px 0 transparent;}
body.js #SnS_meta_box .title{display:none;}
body.js #SnS_meta_box>.inside{height:auto;padding:0 10px;margin:6px 0 8px;}
body.js #SnS_meta_box .wp-tab-panel{display:none;margin-bottom:0;}
body.js #SnS_meta_box .wp-tabs-panel-active{display:block;}
body.no-js #SnS_meta_box .wp-tab-bar{position:absolute;top:36px;}
body.no-js #SnS_meta_box .wp-tab-panel{margin-bottom:1em;}
body.no-js #side-sortables #SnS_meta_box>.inside{margin-top:33px;padding-top:0;}
#SnS_meta_box>.inside{height:300px;overflow:auto;padding:6px 10px 8px;margin:0;position:static;}
#SnS_meta_box .wp-tab-bar{text-align:right;overflow:auto;width:100%;padding:0;margin-top:3px;margin-bottom:-1px;}#SnS_meta_box .wp-tab-bar li{float:left;background-color:inherit;border:0 none;margin:0;padding:0;display:inline;}
#SnS_meta_box .wp-tab-bar a{display:block;border-radius:3px 3px 0 0;border-style:none;border-width:1px 1px 0 1px;padding:3px 5px 5px;margin-right:3px;text-decoration:none;}
#SnS_meta_box .wp-tab-active a{background-color:#FFFFFF;border-color:#DFDFDF;border-style:solid;margin-bottom:-1px;}
#SnS_meta_box .wp-tab-panel{border-style:solid;border-width:1px;overflow:auto;padding:0.5em 0.9em;min-height:200px;height:auto;}
#normal-sortables #SnS_meta_box .wp-tab-bar,#advanced-sortables #SnS_meta_box .wp-tab-bar{float:left;margin:0 -1px 0 5px;width:121px;overflow:visible;}#normal-sortables #SnS_meta_box .wp-tab-bar a,#advanced-sortables #SnS_meta_box .wp-tab-bar a{padding:8px;width:104px;}
#normal-sortables #SnS_meta_box .wp-tab-panel,#advanced-sortables #SnS_meta_box .wp-tab-panel{margin-left:125px;margin-right:5px;max-height:none;}
#normal-sortables #SnS_meta_box .wp-tab-active a,#advanced-sortables #SnS_meta_box .wp-tab-active a{border-radius:3px 0 0 3px;border-style:solid none solid solid;border-width:1px 0 1px 1px;margin-right:-1px;font-weight:bold;}
@media only screen and (max-width:1050px){body.no-js #SnS_meta_box>.inside{margin-top:33px;padding-top:0;} body.js #normal-sortables #SnS_meta_box .wp-tab-panel,body.js #advanced-sortables #SnS_meta_box .wp-tab-panel{margin:0;} #normal-sortables #SnS_meta_box .wp-tab-bar,#advanced-sortables #SnS_meta_box .wp-tab-bar{float:none;margin:3px 0 -1px;width:100%;overflow:hidden;} #normal-sortables #SnS_meta_box .wp-tab-panel,#advanced-sortables #SnS_meta_box .wp-tab-panel{margin:0 0 1em;} #normal-sortables #SnS_meta_box .wp-tab-bar a,#advanced-sortables #SnS_meta_box .wp-tab-bar a{padding:3px 5px 5px;width:auto;} #normal-sortables #SnS_meta_box .wp-tab-active a,#advanced-sortables #SnS_meta_box .wp-tab-active a{border-radius:3px 3px 0 0;border-style:solid solid none solid;border-width:1px 1px 0 1px;margin-right:3px;font-weight:normal;}}

View File

@@ -0,0 +1,26 @@
textarea.code{display:block;}
.CodeMirror{height:200px;border:1px solid #DFDFDF;}
.autoheight .CodeMirror{height:auto;}
.autoheight .CodeMirror-scroll{overflow-x:auto;overflow-y:hidden;}
.style,.script,.less,.coffee{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;background-color:white;margin:8px 0 6px;background-clip:padding-box;font-family:"Courier New",Courier,monospace;}.style:before,.script:before,.less:before,.coffee:before,.style:after,.script:after,.less:after,.coffee:after{border:1px solid #dfdfdf;position:relative;z-index:3;display:block;padding:.5em;background-color:#f5f5f5;color:#333;font-family:"Courier New",Courier,monospace;line-height:1em;text-shadow:none;}
.style:before,.script:before,.less:before,.coffee:before{border-bottom:0 none;border-radius:5px 5px 0px 0px;}
.style:after,.script:after,.less:after,.coffee:after{border-top:0 none;border-radius:0px 0px 5px 5px;}
.style>label,.script>label,.less>label,.coffee>label{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:block;padding:3px 6px;border:1px solid #dfdfdf;border-top:0 none;}
.style:before{content:'<style type="text/css">';}
.style:after{content:'</style>';}
.script:before{content:'<script type="text/javascript">';}
.script:after{content:'</script>';}
.less:before{content:'<style type="text/less">';}
.less:after{content:'</style>';}
.coffee:before{content:'<script type="text/coffeescript">';}
.coffee:after{content:'</script>';}
.scripts-n-styles_page_sns_theme .CodeMirror-scroll{max-height:none;}
#icon-sns{background:no-repeat center url('../images/icon32.png');}
.sns-less-ide .disabled{cursor:default;}
.sns-less-ide .inside{margin:6px 0;padding:0 10px;line-height:1.4em;}
.sns-collapsed-btn{cursor:pointer;float:left;height:1.4em;width:1.4em;background-image:url("data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%0F%00%00%00%7B%08%06%00%00%00%ABe%DA%9D%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%01%90IDATx%DA%EC%991N%C3%40%10E%D7%40%1D%A4(G%A0%A2%A0%E2%06Q%90%DB%5C%02%09%AA%F4%A1%8C%7BW%20%E5%10P%DA%22%E2%06%AERP%E5%08%08)%F4%D6%F2G%FA%C5j%E5%F5%AEM%81%10%B3%D2%D7%EC%3A~%1E%7Bci%BE%C6%99%B5%D6%8C%1D'%E6%07%E3%8F%C2g%FE%81%BA%AE%1B%84%0B.'%D0%17%E7%87%3C%CF%AFc%99%0B%E8%9C%CA%9Cy%E1%9F%98u%FDU%C8%FE%8A%B0p%0E%ED%90%F5%26%F5%99WP%CBy%CBu%DA%86!%CB%3B%C2%96%CB-%D7%83v%FB%01%B2%8C%DDC%9E9%A4%AA%AA%E6%7D%BFg%FAn%2B%AC%B0%C2%0A%2B%FC%CB0%EA%F4%BC%EF%F7%60%AD%028E%F8%80f(%B1%9FC3oh%2B6%832%23%EB%25%C2%1E%3A%A53%B8%EA*%F0%A1%CC%25A%C3X%26%DD6%B2.%3D3%23c%C1%E3%D1%CCk%E8HYg%BEN%DEm%7D%B7%15VXa%85%15V8v%82%D4e%B6%3F%E2%7D%12%CFZ%94%2C%F4%C7%D4%26%CB%94%26%E6%D6%B1%16%F1%0E%0D%7D%D7%8E.%C8%1D%93%E83%C3%F1%BC%89%EF%82%9E%9C%3E%89qZ%3C%FD%1B%26%86%0D%BA%17%FB%C4%BB0%A3Z%1Dlw%2C%A1F%5B%1D%0A%2B%AC%B0%C2%0A%2B%CC%22%DFt%F5%08R3%CB%B7%9Bg%F9%92Bo2%EA%B6%C5%CC%ECq%81Gz%95%24%D8%F5%20bj%EE%A4%D5%E3%F7%8AB%B0%EBAZz%94%19%3DK%DC%87q%88'Y%85%BE%DD%84%E0%03T%00z%E9%BB%F2%7F%F4%24%DF%02%0C%00%C9H%D9%18%7B.%E6%93%00%00%00%00IEND%AEB%60%82");background-attachment:scroll;background-repeat:no-repeat;background-position:1px 1px;margin-right:.5em;}.sns-collapsed-btn+label,.sns-collapsed-btn+p{height:1.4em;display:block;margin:0;}
.sns-collapsed{overflow:hidden;}.sns-collapsed .sns-collapsed-btn{background-position:1px -107px;}
.sns-collapsed .CodeMirror,.sns-collapsed .code,.sns-collapsed .sns-ajax-wrap,.sns-collapsed textarea{visibility:hidden;position:absolute;}
.sns-ajax-loading{display:none;vertical-align:top;}.sns-ajax-loading .spinner{float:none;}
.sns-ajax-wrap{height:23px;}.sns-ajax-wrap .single-status{display:inline-block;vertical-align:middle;}.sns-ajax-wrap .single-status .settings-error{margin:0;}
.sns-shortcode{background-color:#F5F5F5;background-image:-moz-linear-gradient(center top, #f9f9f9, #f5f5f5);border-color:#DFDFDF;border-radius:3px 3px 3px 3px;box-shadow:0 1px 0 #FFFFFF inset;border-style:solid;border-width:1px;line-height:1;margin-bottom:20px;padding:0;}.sns-shortcode .inside{margin:6px 0 8px;position:relative;line-height:1.4em;padding:0 10px;}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,202 @@
<?php
/**
* Scripts n Styles Admin Class
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
require_once( 'class-sns-meta-box.php' );
// require_once( 'class-sns-code-editor.php' );
require_once( 'class-sns-settings-page.php' );
require_once( 'class-sns-usage-page.php' );
require_once( 'class-sns-global-page.php' );
require_once( 'class-sns-hoops-page.php' );
require_once( 'class-sns-theme-page.php' );
require_once( 'class-sns-ajax.php' );
require_once( 'class-sns-form.php' );
class SnS_Admin
{
/**#@+
* Constants
*/
const OPTION_GROUP = 'scripts_n_styles';
const MENU_SLUG = 'sns';
static $parent_slug = '';
/**#@-*/
/**
* Initializing method.
* @static
*/
static function init() {
add_action( 'admin_menu', array( 'SnS_Admin_Meta_Box', 'init' ) );
// add_action( 'admin_menu', array( 'SnS_Admin_Code_Editor', 'init' ) );
// add_action( 'network_admin_menu', array( 'SnS_Admin_Code_Editor', 'init' ) );
add_action( 'admin_menu', array( __CLASS__, 'menu' ) );
add_action( 'admin_init', array( 'SnS_AJAX', 'init' ) );
add_action( 'admin_init', array( __CLASS__, 'load_plugin_textdomain' ) );
$plugin_file = plugin_basename( Scripts_n_Styles::$file );
add_filter( "plugin_action_links_$plugin_file", array( __CLASS__, 'plugin_action_links') );
register_activation_hook( Scripts_n_Styles::$file, array( __CLASS__, 'upgrade' ) );
}
static function load_plugin_textdomain() {
load_plugin_textdomain( 'scripts-n-styles', false, dirname( plugin_basename( Scripts_n_Styles::$file ) ) . '/languages/' );
}
static function menu() {
if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'unfiltered_html' ) ) return;
$options = get_option( 'SnS_options' );
$menu_spot = isset( $options[ 'menu_position' ] ) ? $options[ 'menu_position' ]: '';
$top_spots = array( 'menu', 'object', 'utility' );
$sub_spots = array( 'tools.php', 'options-general.php', 'themes.php' );
if ( in_array( $menu_spot, $top_spots ) ) $parent_slug = SnS_Admin::MENU_SLUG;
else if ( in_array( $menu_spot, $sub_spots ) ) $parent_slug = $menu_spot;
else $parent_slug = 'tools.php';
self::$parent_slug = $parent_slug;
switch( $menu_spot ) {
case 'menu':
add_menu_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
break;
case 'object':
add_object_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
break;
case 'utility':
add_utility_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
break;
}
SnS_Global_Page::init();
SnS_Hoops_Page::init();
if ( current_theme_supports( 'scripts-n-styles' ) )
SnS_Theme_Page::init();
SnS_Settings_Page::init();
SnS_Usage_Page::init();
}
/**
* Nav Tabs
*/
static function nav() {
$options = get_option( 'SnS_options' );
$page = $_REQUEST[ 'page' ];
?>
<h2>Scripts n Styles</h2>
<?php if ( ! isset( $options[ 'menu_position' ] ) || 'options-general.php' != $options[ 'menu_position' ] ) settings_errors(); ?>
<h3 class="nav-tab-wrapper">
<a class="nav-tab<?php echo ( self::MENU_SLUG == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG ); ?>"><?php _e( 'Global', 'scripts-n-styles' ); ?></a>
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_hoops' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_hoops' ); ?>"><?php _e( 'Hoops', 'scripts-n-styles' ); ?></a>
<?php if ( current_theme_supports( 'scripts-n-styles' ) ) { ?>
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_theme' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_theme' ); ?>"><?php _e( 'Theme', 'scripts-n-styles' ); ?></a>
<?php } ?>
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_settings' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_settings' ); ?>"><?php _e( 'Settings', 'scripts-n-styles' ); ?></a>
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_usage' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_usage' ); ?>"><?php _e( 'Usage', 'scripts-n-styles' ); ?></a>
</h3>
<?php
}
/**
* Settings Page help
*/
static function help() {
$help = '<p>' . __( 'In default (non MultiSite) WordPress installs, both <em>Administrators</em> and <em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens. Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only <em>"Super Admin"</em> users can access either <em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change capabilities (specifically "unfiltered_html"), other users can be granted access.', 'scripts-n-styles' ) . '</p>';
$help .= '<p><strong>' . __( 'Reference: jQuery Wrappers', 'scripts-n-styles' ) . '</strong></p>' .
'<pre><code>jQuery(document).ready(function($) {
// $() will work as an alias for jQuery() inside of this function
});</code></pre>';
$help .= '<pre><code>(function($) {
// $() will work as an alias for jQuery() inside of this function
})(jQuery);</code></pre>';
$sidebar = '<p><strong>' . __( 'For more information:', 'scripts-n-styles' ) . '</strong></p>' .
'<p>' . __( '<a href="http://wordpress.org/extend/plugins/scripts-n-styles/faq/" target="_blank">Frequently Asked Questions</a>', 'scripts-n-styles' ) . '</p>' .
'<p>' . __( '<a href="https://github.com/unFocus/Scripts-n-Styles" target="_blank">Source on github</a>', 'scripts-n-styles' ) . '</p>' .
'<p>' . __( '<a href="http://wordpress.org/tags/scripts-n-styles" target="_blank">Support Forums</a>', 'scripts-n-styles' ) . '</p>';
$screen = get_current_screen();
if ( method_exists( $screen, 'add_help_tab' ) ) {
$screen->add_help_tab( array(
'title' => __( 'Scripts n Styles', 'scripts-n-styles' ),
'id' => 'scripts-n-styles',
'content' => $help
)
);
if ( 'post' != $screen->id )
$screen->set_help_sidebar( $sidebar );
} else {
add_contextual_help( $screen, $help . $sidebar );
}
}
/**
* Utility Method: Sets defaults if not previously set. Sets stored 'version' to VERSION.
*/
static function upgrade() {
$options = get_option( 'SnS_options' );
if ( ! $options ) $options = array();
$options[ 'version' ] = Scripts_n_Styles::VERSION;
update_option( 'SnS_options', $options );
/*
* upgrade proceedure
*/
$posts = get_posts(
array(
'numberposts' => -1,
'post_type' => 'any',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'OR',
array( 'key' => '_SnS_scripts' ),
array( 'key' => '_SnS_styles' ),
array( 'key' => 'uFp_scripts' ),
array( 'key' => 'uFp_styles' )
)
)
);
foreach( $posts as $post) {
$styles = get_post_meta( $post->ID, '_SnS_styles', true );
if ( empty( $styles ) )
$styles = get_post_meta( $post->ID, 'uFp_styles', true );
$scripts = get_post_meta( $post->ID, '_SnS_scripts', true );
if ( empty( $scripts ) )
$scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
$SnS = array();
if ( ! empty( $styles ) )
$SnS[ 'styles' ] = $styles;
if ( ! empty( $scripts ) )
$SnS[ 'scripts' ] = $scripts;
if ( ! empty( $SnS ) )
update_post_meta( $post->ID, '_SnS', $SnS );
delete_post_meta( $post->ID, 'uFp_styles' );
delete_post_meta( $post->ID, 'uFp_scripts' );
delete_post_meta( $post->ID, '_SnS_styles' );
delete_post_meta( $post->ID, '_SnS_scripts' );
}
}
/**
* Adds link to the Settings Page in the WordPress "Plugin Action Links" array.
* @param array $actions
* @return array
*/
static function plugin_action_links( $actions ) {
$actions[ 'settings' ] = '<a href="' . menu_page_url( SnS_Settings_Page::MENU_SLUG, false ) . '"/>' . __( 'Settings' ) . '</a>';
return $actions;
}
}

View File

@@ -0,0 +1,452 @@
<?php
class SnS_AJAX
{
static function init() {
// Keep track of current tab.
add_action( 'wp_ajax_sns_update_tab', array( __CLASS__, 'update_tab' ) );
// TinyMCE requests a css file.
add_action( 'wp_ajax_sns_tinymce_styles', array( __CLASS__, 'tinymce_styles' ) );
add_action( 'wp_ajax_nopriv_sns_tinymce_styles', array( __CLASS__, 'tinymce_styles' ) );
// Ajax Saves.
add_action( 'wp_ajax_sns_classes', array( __CLASS__, 'classes' ) );
add_action( 'wp_ajax_sns_scripts', array( __CLASS__, 'scripts' ) );
add_action( 'wp_ajax_sns_styles', array( __CLASS__, 'styles' ) );
add_action( 'wp_ajax_sns_html', array( __CLASS__, 'html' ) );
add_action( 'wp_ajax_sns_dropdown', array( __CLASS__, 'dropdown' ) );
add_action( 'wp_ajax_sns_delete_class', array( __CLASS__, 'delete_class' ) );
add_action( 'wp_ajax_sns_shortcodes', array( __CLASS__, 'shortcodes' ) );
add_action( 'wp_ajax_sns_open_theme_panels', array( __CLASS__, 'open_theme_panels' ) );
add_action( 'wp_ajax_sns_plugin_editor', array( __CLASS__, 'plugin_editor' ) );
}
static function plugin_editor() {
check_ajax_referer( 'sns_plugin_editor' );
if ( ! current_user_can( 'edit_plugins' ) ) exit( 'Insufficient Privileges.' );
$active = false;
$plugin = '';
$debug = array();
$need_update = false;
$plugins = array_keys( get_plugins() );
$file = $_REQUEST[ 'file' ];
$short = substr( $file, 0, strpos( $file, '/' ) );
if ( ! in_array( $file, $plugins ) ) {
$need_update = true;
if ( in_array( $_REQUEST[ 'plugin' ], $plugins ) ) {
$plugin = $_REQUEST[ 'plugin' ];
} else {
foreach ( $plugins as $maybe ) {
if ( false !== strpos( $maybe, $short ) ) {
$plugin = $maybe;
break;
}
}
}
} else {
$plugin = $file;
while ( 1 < substr_count( $plugin, "/" ) ) {
$plugin = dirname( $plugin );
}
}
$active = is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin );
$files = get_plugin_files( $plugin );
add_filter( 'editable_extensions', array( 'SnS_Admin_Code_Editor', 'extend' ) );
$editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
$editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
$ul = '';
foreach ( $files as $plugin_file ) {
// Get the extension of the file
if ( preg_match( '/\.([^.]+)$/', $plugin_file, $matches ) ) {
$ext = strtolower( $matches[1] );
// If extension is not in the acceptable list, skip it
if ( ! in_array( $ext, $editable_extensions ) )
continue;
} else {
// No extension found
continue;
}
$ul .= '<li';
$ul .= $file == $plugin_file ? ' class="highlight">' : '>';
$ul .= '<a href="plugin-editor.php?file=' . urlencode( $plugin_file ) . '&amp;plugin=' . urlencode( $plugin ) . '">';
$ul .= str_replace( $short . '/', '', $plugin_file );
$ul .= '</a>';
$ul .= '</li>';
}
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"plugin" => $plugin,
"active" => $active,
"files" => $files,
"need_update" => $need_update,
"ul" => $ul,
) );
exit();
}
static function open_theme_panels() {
check_ajax_referer( SnS_Admin::OPTION_GROUP . "-options" );
$name = isset( $_POST[ 'file-name' ] ) ? $_POST[ 'file-name' ] : '';
if ( empty( $name ) ) exit( 'empty name');
$collapsed = isset( $_POST[ 'collapsed' ] ) ? $_POST[ 'collapsed' ] : '';
if ( empty( $collapsed ) ) exit( 'empty value');
if ( ! $user = get_current_user_id() ) exit( 'Bad User' );
$open_theme_panels = json_decode( get_user_option( 'sns_open_theme_panels', $user ), true );
$open_theme_panels = is_array( $open_theme_panels ) ? $open_theme_panels : array();
$open_theme_panels[ $name ] = $collapsed;
$open_theme_panels = json_encode( $open_theme_panels );
update_user_option( $user, 'sns_open_theme_panels', $open_theme_panels );
exit();
}
static function update_tab() {
check_ajax_referer( Scripts_n_Styles::$file );
$active_tab = isset( $_POST[ 'active_tab' ] ) ? 's'.$_POST[ 'active_tab' ] : 's0';
if ( ! $user = wp_get_current_user() ) exit( 'Bad User' );
$success = update_user_option( $user->ID, 'current_sns_tab', $active_tab, true);
exit();
}
static function tinymce_styles() {
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$options = get_option( 'SnS_options' );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
header('Content-Type: text/css; charset=UTF-8');
if ( ! empty( $options[ 'styles' ] ) ) echo $options[ 'styles' ];
if ( ! empty( $styles[ 'styles' ] ) ) echo $styles[ 'styles' ];
exit();
}
// AJAX handlers
static function classes() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( ! isset( $_REQUEST[ 'classes_body' ], $_REQUEST[ 'classes_post' ] ) ) exit( 'Data missing.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
$styles = self::maybe_set( $styles, 'classes_body' );
$styles = self::maybe_set( $styles, 'classes_post' );
if ( empty( $styles ) ) {
if ( isset( $SnS['styles'] ) )
unset( $SnS['styles'] );
} else {
$SnS[ 'styles' ] = $styles;
}
self::maybe_update( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"classes_post" => $_REQUEST[ 'classes_post' ]
, "classes_body" => $_REQUEST[ 'classes_body' ]
) );
exit();
}
static function scripts() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( ! isset( $_REQUEST[ 'scripts' ], $_REQUEST[ 'scripts_in_head' ] ) ) exit( 'Data incorrectly sent.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
$scripts = self::maybe_set( $scripts, 'scripts_in_head' );
$scripts = self::maybe_set( $scripts, 'scripts' );
if ( empty( $scripts ) ) {
if ( isset( $SnS['scripts'] ) )
unset( $SnS['scripts'] );
} else {
$SnS[ 'scripts' ] = $scripts;
}
self::maybe_update( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"scripts" => $_REQUEST[ 'scripts' ]
, "scripts_in_head" => $_REQUEST[ 'scripts_in_head' ]
) );
exit();
}
static function html() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( ! isset( $_REQUEST[ 'html_in_footer' ], $_REQUEST[ 'html_in_head' ] ) ) exit( 'Data incorrectly sent.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$html = isset( $SnS['html'] ) ? $SnS[ 'html' ]: array();
$html = self::maybe_set( $html, 'html_in_head' );
$html = self::maybe_set( $html, 'html_in_footer' );
if ( empty( $html ) ) {
if ( isset( $SnS['html'] ) )
unset( $SnS['html'] );
} else {
$SnS[ 'html' ] = $html;
}
self::maybe_update( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"html_in_footer" => $_REQUEST[ 'html_in_footer' ]
, "html_in_head" => $_REQUEST[ 'html_in_head' ]
) );
exit();
}
static function styles() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( ! isset( $_REQUEST[ 'styles' ] ) ) exit( 'Data incorrectly sent.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
$styles = self::maybe_set( $styles, 'styles' );
if ( empty( $styles ) ) {
if ( isset( $SnS['styles'] ) )
unset( $SnS['styles'] );
} else {
$SnS[ 'styles' ] = $styles;
}
self::maybe_update( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"styles" => $_REQUEST[ 'styles' ],
) );
exit();
}
static function dropdown() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'format' ] ) ) exit( 'Missing Format.' );
if ( empty( $_REQUEST[ 'format' ][ 'title' ] ) ) exit( 'Title is required.' );
if ( empty( $_REQUEST[ 'format' ][ 'classes' ] ) ) exit( 'Classes is required.' );
if (
empty( $_REQUEST[ 'format' ][ 'inline' ] ) &&
empty( $_REQUEST[ 'format' ][ 'block' ] ) &&
empty( $_REQUEST[ 'format' ][ 'selector' ] )
) exit( 'A type is required.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
if ( ! isset( $styles[ 'classes_mce' ] ) ) $styles[ 'classes_mce' ] = array();
// pass title as key to be able to delete.
$styles[ 'classes_mce' ][ $_REQUEST[ 'format' ][ 'title' ] ] = $_REQUEST[ 'format' ];
$SnS[ 'styles' ] = $styles;
update_post_meta( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"classes_mce" => array_values( $styles[ 'classes_mce' ] )
) );
exit();
}
static function delete_class() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
$title = $_REQUEST[ 'delete' ];
if ( isset( $styles[ 'classes_mce' ][ $title ] ) ) unset( $styles[ 'classes_mce' ][ $title ] );
else exit ( 'No Format of that name.' );
if ( empty( $styles[ 'classes_mce' ] ) ) unset( $styles[ 'classes_mce' ] );
if ( empty( $styles ) ) {
if ( isset( $SnS['styles'] ) )
unset( $SnS['styles'] );
} else {
$SnS[ 'styles' ] = $styles;
}
self::maybe_update( $post_id, '_SnS', $SnS );
if ( ! isset( $styles[ 'classes_mce' ] ) ) $styles[ 'classes_mce' ] = array( 'Empty' );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"classes_mce" => array_values( $styles[ 'classes_mce' ] )
) );
exit();
}
static function shortcodes() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( empty( $_REQUEST[ 'subaction' ] ) ) exit( 'missing directive' );
if ( in_array( $_REQUEST[ 'subaction' ], array( 'add', 'update', 'delete' ) ) )
$subaction = $_REQUEST[ 'subaction' ];
else
exit( 'unknown directive' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$shortcodes = isset( $SnS[ 'shortcodes' ] ) ? $SnS[ 'shortcodes' ]: array();
$message = '';
$code = 0;
$key = '';
$value = '';
if ( isset( $_REQUEST[ 'name' ] ) )
$key = $_REQUEST[ 'name' ];
else
exit( 'bad directive.' );
if ( '' == $key ) {
$key = count( $shortcodes );
while ( isset( $shortcodes[ $key ] ) )
$key++;
}
switch ( $subaction ) {
case 'add':
if ( empty( $_REQUEST[ 'shortcode' ] ) )
exit( 'empty value.' );
else
$value = $_REQUEST[ 'shortcode' ];
if ( isset( $shortcodes[ $key ] ) ) {
$countr = 1;
while ( isset( $shortcodes[ $key . '_' . $countr ] ) )
$countr++;
$key .= '_' . $countr;
}
$code = 1;
$shortcodes[ $key ] = $value;
break;
case 'update':
if ( empty( $_REQUEST[ 'shortcode' ] ) ) {
if ( isset( $shortcodes[ $key ] ) )
unset( $shortcodes[ $key ] );
$code = 3;
$message = $key;
} else {
$value = $_REQUEST[ 'shortcode' ];
if ( isset( $shortcodes[ $key ] ) )
$shortcodes[ $key ] = $value;
else
exit( 'wrong key.' );
$code = 2;
$message = 'updated ' . $key;
}
break;
case 'delete':
if ( isset( $shortcodes[ $key ] ) )
unset( $shortcodes[ $key ] );
else
exit( 'bad key.' );
$code = 3;
$message = $key;
break;
}
if ( empty( $shortcodes ) ) {
if ( isset( $SnS[ 'shortcodes' ] ) )
unset( $SnS[ 'shortcodes' ] );
} else {
$SnS[ 'shortcodes' ] = $shortcodes;
}
self::maybe_update( $post_id, '_SnS', $SnS );
if ( 1 < $code ) {
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"message" => $message
, "code" => $code
) );
} else {
header('Content-Type: text/html; charset=' . get_option('blog_charset'));
?><div class="sns-shortcode widget">
<div class="inside">
<p>[hoops name="<?php echo esc_attr( $key ) ?>"]</p>
<textarea style="width: 98%;" cols="40" rows="5" name="SnS_shortcodes[existing][<?php echo esc_attr( $key ) ?>]"
data-sns-shortcode-key="<?php echo esc_attr( $key ) ?>" class="codemirror-new htmlmixed"><?php echo esc_textarea( stripslashes( $value ) ) ?></textarea>
<div class="sns-ajax-wrap"><a href="#" class="sns-ajax-delete-shortcode button">Delete</a> &nbsp; <a href="#" class="sns-ajax-update-shortcode button">Update</a> <span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span></div>
</div>
</div><?php
}
exit();
}
// Differs from SnS_Admin_Meta_Box::maybe_set() in that this needs no prefix.
static function maybe_set( $o, $i ) {
if ( ! is_array( $o ) ) return array();
if ( empty( $_REQUEST[ $i ] ) ) {
if ( isset( $o[ $i ] ) ) unset( $o[ $i ] );
} else $o[ $i ] = $_REQUEST[ $i ];
return $o;
}
static function maybe_update( $id, $name, $meta ) {
if ( empty( $meta ) ) {
delete_post_meta( $id, $name );
} else {
update_post_meta( $id, $name, $meta );
}
}
}

View File

@@ -0,0 +1,185 @@
<?php
/**
* SnS_Global_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Form
{
/**
* Settings Page
* Outputs a textarea for setting 'scripts_in_head'.
*/
static function textarea( $args ) {
extract( $args );
$options = get_option( $setting );
$value = isset( $options[ $label_for ] ) ? $options[ $label_for ] : '';
$output = '';
if ( isset( $wrap_class ) ) $output .= '<div class="'. $wrap_class . '">';
$output .= '<textarea';
$output .= ( $style ) ? ' style="' . $style . '"': '';
$output .= ( $class ) ? ' class="' . $class . '"': '';
$output .= ( $rows ) ? ' rows="' . $rows . '"': '';
$output .= ( $cols ) ? ' cols="' . $cols . '"': '';
$output .= ' name="' . $setting . '[' . $label_for . ']"';
$output .= ' id="' . $label_for . '">';
$output .= esc_textarea( $value ) . '</textarea>';
if ( isset( $wrap_class ) ) $output .= '</div>';
if ( $description ) {
$output .= $description;
}
echo $output;
}
static function radio( $args ) {
extract( $args );
$options = get_option( $setting );
$default = isset( $default ) ? $default : '';
$value = isset( $options[ $label_for ] ) ? $options[ $label_for ] : $default;
$output = '<fieldset>';
if ( $legend ) {
$output .= '<legend class="screen-reader-text"><span>';
$output .= $legend;
$output .= '</span></legend>';
}
$output .= '<p>';
foreach ( $choices as $choice ) {
$output .= '<label style="white-space: pre;">';
$output .= '<input type="radio"';
$output .= checked( $value, $choice, false );
$output .= ' value="' . $choice . '" name="' . $setting . '[' . $label_for . ']"> ' . $choice;
$output .= '</label>';
$output .= ( ! isset( $layout ) || 'horizontal' != $layout ) ? '<br>' : ' &nbsp; ';
}
$output .= '</p></fieldset>';
if ( $description ) {
$output .= $description;
}
echo $output;
}
/**
* Settings Page
* Outputs a select element for selecting options to set scripts for including.
*/
static function select( $args ) {
extract( $args );
$options = get_option( $setting );
$selected = isset( $options[ $label_for ] ) ? $options[ $label_for ] : array();
$output = '<select';
$output .= ' id="' . $label_for . '"';
$output .= ' name="' . $setting . '[' . $label_for . ']';
if ( isset( $multiple ) && $multiple )
$output .= '[]" multiple="multiple"';
else
$output .= '"';
$output .= ( $size ) ? ' size="' . $size . '"': '';
$output .= ( $style ) ? ' style="' . $style . '"': '';
$output .= '>';
foreach ( $choices as $choice ) {
$output .= '<option value="' . $choice . '"';
if ( isset( $multiple ) && $multiple )
foreach ( $selected as $handle ) $output .= selected( $handle, $choice, false );
else
$output .= selected( $selected, $choice, false );
$output .= '>' . $choice . '</option> ';
}
$output .= '</select>';
if ( ! empty( $show_current ) && ! empty( $selected ) ) {
$output .= '<p>' . $show_current;
foreach ( $selected as $handle ) $output .= '<code>' . $handle . '</code> ';
$output .= '</p>';
}
echo $output;
}
/**
* Settings Page
* Outputs the Admin Page and calls the Settings registered with the Settings API.
*/
static function take_action() {
global $action, $option_page, $page, $new_whitelist_options;
if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'unfiltered_html' ) || ( is_multisite() && ! is_super_admin() ) )
wp_die( __( 'Cheatin&#8217; uh?' ) );
// Handle menu-redirected update message.
if ( isset( $_REQUEST[ 'message' ] ) && $_REQUEST[ 'message' ] )
add_settings_error( $page, 'settings_updated', __( 'Settings saved.' ), 'updated' );
if ( ! isset( $_REQUEST[ 'action' ], $_REQUEST[ 'option_page' ], $_REQUEST[ 'page' ] ) )
return;
wp_reset_vars( array( 'action', 'option_page', 'page' ) );
check_admin_referer( $option_page . '-options' );
if ( ! isset( $new_whitelist_options[ $option_page ] ) )
return;
$options = $new_whitelist_options[ $option_page ];
foreach ( (array) $options as $option ) {
$old = get_option( $option );
$option = trim( $option );
$new = null;
if ( isset($_POST[ $option ]) )
$new = $_POST[ $option ];
if ( !is_array( $new ) )
$new = trim( $new );
$new = stripslashes_deep( $new );
$value = array_merge( $old, $new );
// Allow modification of $value
$value = apply_filters( 'sns_options_pre_update_option', $value, $page, $action, $new, $old );
update_option( $option, $value );
}
if ( ! count( get_settings_errors() ) )
add_settings_error( $page, 'settings_updated', __( 'Settings saved.' ), 'updated' );
if ( isset( $_REQUEST[ 'ajaxsubmit' ] ) && $_REQUEST[ 'ajaxsubmit' ] ) {
ob_start();
settings_errors( $page );
$output = ob_get_contents();
ob_end_clean();
exit( $output );
}
// Redirect to new page if changed.
if ( isset( $_POST[ $option ][ 'menu_position' ] ) && ( $value[ 'menu_position' ] != SnS_Admin::$parent_slug ) ) {
switch( $value[ 'menu_position' ] ) {
case 'menu':
case 'object':
case 'utility':
wp_redirect( add_query_arg( array( 'message' => 1, 'page' => 'sns_settings' ), admin_url( 'admin.php' ) ) );
break;
default:
wp_redirect( add_query_arg( array( 'message' => 1, 'page' => 'sns_settings' ), admin_url( $value[ 'menu_position' ] ) ) );
break;
}
}
return;
}
/**
* Settings Page
* Outputs the Admin Page and calls the Settings registered with the Settings API in init_options_page().
*/
static function page() {
?>
<div class="wrap">
<?php SnS_Admin::nav(); ?>
<form action="" method="post" autocomplete="off">
<?php settings_fields( SnS_Admin::OPTION_GROUP ); ?>
<?php do_settings_sections( SnS_Admin::MENU_SLUG ); ?>
<?php if ( apply_filters( 'sns_show_submit_button', true ) ) submit_button(); ?>
</form>
</div>
<?php
}
}

View File

@@ -0,0 +1,252 @@
<?php
/**
* SnS_Global_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Global_Page
{
/**
* Initializing method.
* @static
*/
static function init() {
if ( SnS_Admin::$parent_slug == SnS_Admin::MENU_SLUG ) $menu_title = __( 'Global', 'scripts-n-styles' );
else $menu_title = __( 'Scripts n Styles', 'scripts-n-styles' );
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), $menu_title, 'unfiltered_html', SnS_Admin::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
}
static function admin_enqueue_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
wp_enqueue_style( 'chosen' );
wp_enqueue_style( 'sns-options' );
wp_enqueue_script( 'sns-global-page' );
wp_localize_script( 'sns-global-page', '_SnS_options', array( 'theme' => $cm_theme ) );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
register_setting(
SnS_Admin::OPTION_GROUP,
'SnS_options' );
add_settings_section(
'global_html',
__( 'Blog Wide HTML', 'scripts-n-styles' ),
array( __CLASS__, 'global_html_section' ),
SnS_Admin::MENU_SLUG );
add_settings_section(
'global_styles',
__( 'Blog Wide CSS Styles', 'scripts-n-styles' ),
array( __CLASS__, 'global_styles_section' ),
SnS_Admin::MENU_SLUG );
add_settings_section(
'global_scripts',
__( 'Blog Wide JavaScript', 'scripts-n-styles' ),
array( __CLASS__, 'global_scripts_section' ),
SnS_Admin::MENU_SLUG );
add_settings_field(
'less',
__( '<strong>LESS:</strong> ', 'scripts-n-styles' ),
array( __CLASS__, 'less_fields' ),
SnS_Admin::MENU_SLUG,
'global_styles',
array( 'label_for' => 'less' ) );
add_settings_field(
'coffee',
__( '<strong>CoffeeScript:</strong> ', 'scripts-n-styles' ),
array( __CLASS__, 'coffee_fields' ),
SnS_Admin::MENU_SLUG,
'global_scripts',
array( 'label_for' => 'coffee' ) );
add_settings_field(
'html_in_head',
__( '<strong>HTML<br>(<code>head</code> tag):</strong> ', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_html',
array(
'label_for' => 'html_in_head',
'setting' => 'SnS_options',
'class' => 'code html',
'wrap_class' => 'html',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The HTML will be included in <code>&lt;head></code> element of your pages.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'html_in_footer',
__( '<strong>HTML<br>(end of the <code>body</code> tag):</strong> ', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_html',
array(
'label_for' => 'html_in_footer',
'setting' => 'SnS_options',
'class' => 'code html',
'wrap_class' => 'html',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The HTML will be included at the bottom of the <code>&lt;body></code> element of your pages.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'styles',
__( '<strong>CSS Styles:</strong> ', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_styles',
array(
'label_for' => 'styles',
'setting' => 'SnS_options',
'class' => 'code css',
'wrap_class' => 'style',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Styles" will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> element of your html.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'scripts_in_head',
__( '<strong>Scripts</strong><br />(for the <code>head</code> element): ', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_scripts',
array(
'label_for' => 'scripts_in_head',
'setting' => 'SnS_options',
'class' => 'code js',
'wrap_class' => 'script',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts (in head)" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags in the <code>&lt;head></code> element of your html.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'scripts',
__( '<strong>Scripts</strong><br />(end of the <code>body</code> tag):', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_scripts',
array(
'label_for' => 'scripts',
'setting' => 'SnS_options',
'class' => 'code js',
'wrap_class' => 'script',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the bottom of the <code>&lt;body></code> element of your html.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'enqueue_scripts',
__( '<strong>Enqueue Scripts</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'select' ),
SnS_Admin::MENU_SLUG,
'global_scripts',
array(
'label_for' => 'enqueue_scripts',
'setting' => 'SnS_options',
'choices' => Scripts_n_Styles::get_wp_registered(),
'size' => 5,
'style' => 'height: auto;',
'multiple' => true,
'show_current' => __( 'Currently Enqueued Scripts: ', 'scripts-n-styles' )
) );
add_filter( 'sns_options_pre_update_option', array( __CLASS__, 'enqueue_scripts'), 10, 5 );
}
static function enqueue_scripts( $value, $page, $action, $new, $old ) {
if ( empty( $new['enqueue_scripts'] ) && ! empty( $old['enqueue_scripts'] ) )
unset( $value['enqueue_scripts'] );
return $value;
}
static function less_fields() {
$options = get_option( 'SnS_options' );
$less = isset( $options[ 'less' ] ) ? $options[ 'less' ] : '';
$compiled = isset( $options[ 'compiled' ] ) ? $options[ 'compiled' ] : '';
?>
<div style="overflow: hidden;">
<div style="width: 49%; float: left; overflow: hidden; margin-right: 2%;" class="less">
<textarea id="less" name="SnS_options[less]" style="min-width: 250px; width:47%; float: left" class="code less" rows="5" cols="40"><?php echo esc_textarea( $less ) ?></textarea>
</div>
<div style="width: 49%; float: left; overflow: hidden;" class="style">
<textarea id="compiled" name="SnS_options[compiled]" style="min-width: 250px; width:47%;" class="code css" rows="5" cols="40"><?php echo esc_textarea( $compiled ) ?></textarea>
<div id="compiled_error" style="display: none" class="error settings-error below-h2"></div>
</div>
</div>
<?php
}
static function coffee_fields() {
$options = get_option( 'SnS_options' );
$coffee = isset( $options[ 'coffee' ] ) ? $options[ 'coffee' ] : '';
$compiled = isset( $options[ 'coffee_compiled' ] ) ? $options[ 'coffee_compiled' ] : '';
?>
<div style="overflow: hidden;">
<div style="width: 49%; float: left; overflow: hidden; margin-right: 2%;" class="coffee">
<textarea id="coffee" name="SnS_options[coffee]" style="min-width: 250px; width:47%; float: left" class="code coffee" rows="5" cols="40"><?php echo esc_textarea( $coffee ) ?></textarea>
</div>
<div style="width: 49%; float: left; overflow: hidden;" class="script">
<textarea id="coffee_compiled" name="SnS_options[coffee_compiled]" style="min-width: 250px; width:47%;" class="code js" rows="5" cols="40"><?php echo esc_textarea( $compiled ) ?></textarea>
<div id="coffee_compiled_error" style="display: none" class="error settings-error below-h2"></div>
</div>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function global_scripts_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Scripts that were registered individually.', 'scripts-n-styles' )?></p>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function global_styles_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Styles that were registered individually.', 'scripts-n-styles' )?></p>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function global_html_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'HTML entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> HTML added to individual posts and pages.', 'scripts-n-styles' )?></p>
<p><?php _e( 'You can place <strong>any</strong> HTML here. In the <code>head</code> tag, please stick to appropriate elements, like <code>script</code>, <code>style</code>, <code>link</code>, and <code>meta</code> html tags.' ); ?></p>
</div>
<?php
}
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* SnS_Hoops_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Hoops_Page
{
/**
* Constants
*/
const MENU_SLUG = 'sns_hoops';
/**
* Initializing method.
* @static
*/
static function init() {
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Hoops' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
// Make the page into a tab.
if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
}
}
static function parent_file( $parent_file ) {
global $plugin_page, $submenu_file;
if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
return $parent_file;
}
static function admin_enqueue_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
wp_enqueue_style( 'sns-options' );
wp_enqueue_style( 'codemirror-theme' );
wp_enqueue_script( 'sns-hoops-page' );
wp_localize_script( 'sns-hoops-page', '_SnS_options', array( 'theme' => $cm_theme ) );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
// added here to not effect other pages.
add_filter( 'sns_options_pre_update_option', array( __CLASS__, 'new_hoops') );
register_setting(
SnS_Admin::OPTION_GROUP,
'SnS_options' );
add_settings_section(
'hoops_section',
__( 'The Hoops Shortcodes', 'scripts-n-styles' ),
array( __CLASS__, 'hoops_section' ),
SnS_Admin::MENU_SLUG );
}
static function new_hoops( $options ) {
// Get Hoops. (Shouldn't be empty.)
$hoops = $options[ 'hoops' ];
/*
add_settings_error( 'sns_hoops', 'settings_updated', '<pre>'
. '$hoops '
. print_r(
$hoops, true ) . '</pre>', 'updated' );
*/
// take out new. (Also shouldn't be empty.)
$new = $hoops[ 'new' ];
unset( $hoops[ 'new' ] );
// Get Shortcodes. (Could be empty.)
$shortcodes = empty( $hoops[ 'shortcodes' ] ) ? array() : $hoops[ 'shortcodes' ];
// prune shortcodes with blank values.
foreach( $shortcodes as $key => $value ){
if ( empty( $value ) )
unset( $shortcodes[ $key ] );
}
// Add new (if not empty).
if ( ! empty( $new[ 'code' ] ) ) {
$name = empty( $new[ 'name' ] ) ? '' : $new[ 'name' ];
if ( '' == $name ) {
// If blank, find next index..
$name = 0;
while ( isset( $shortcodes[ $name ] ) )
$name++;
} else if ( isset( $shortcodes[ $name ] ) ) {
// To make sure not to overwrite.
$countr = 1;
while ( isset( $shortcodes[ $name . '_' . $countr ] ) )
$countr++;
$name .= '_' . $countr;
}
// Add new to shortcodes.
$shortcodes[ $name ] = $new[ 'code' ];
}
// Put in Shortcodes... if not empty.
if ( empty( $shortcodes ) ) {
if ( isset( $hoops[ 'shortcodes' ] ) )
unset( $hoops[ 'shortcodes' ] );
} else {
$hoops[ 'shortcodes' ] = $shortcodes;
}
// Put in Hoops... if not empty.
if ( empty( $hoops ) ) {
if ( isset( $options[ 'hoops' ] ) )
unset( $options[ 'hoops' ] );
} else {
$options[ 'hoops' ] = $hoops;
}
return $options; // Finish Filter.
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function hoops_section() {
echo '<div style="max-width: 55em;">';
_e( '<p>"Hoops" are shortcodes invented to get around some limitations of vanilla WordPress.</p>'
. '<p> Normally, certain HTML is very problematic to use in the Post Editor, because it either gets '
. 'jumbled during Switching between HTML and Visual Tabs, stripped out by WPAutoP (rare) or stripped '
. 'out because the User doesn&#8217;t have the proper Permissions.</p>'
. '<p>With Hoops, an Admin user (who has `unfiltered_html` and `manage_options` capablilities) can '
. 'write and approve snippets of HTML for other users to use via Shortcodes.</p>', 'scripts-n-styles' );
echo '</div>';
$options = get_option( 'SnS_options' );
$meta_name = 'SnS_options[hoops]';
$hoops = isset( $options[ 'hoops' ] ) ? $options[ 'hoops' ] : array();
$shortcodes = isset( $hoops[ 'shortcodes' ] ) ? $hoops[ 'shortcodes' ] : array();
?>
<div id="sns-shortcodes">
<h4>Add New: </h4>
<div class="sns-less-ide" style="overflow: hidden">
<div class="widget sns-shortcodes"><div class="inside">
<label style="display:inline" for="<?php echo $meta_name; ?>">Name: </label>
<input id="<?php echo $meta_name; ?>" name="<?php echo $meta_name . '[new][name]'; ?>" type="text" />
<?php /** / ?>
<a class="button" href="#" id="sns-ajax-add-shortcode">Add New</a>
<?php /**/ ?>
<textarea id="<?php echo $meta_name; ?>_new" class="code htmlmixed" name="<?php echo $meta_name . '[new][code]'; ?>" rows="5" cols="40" style="width: 98%;"></textarea>
</div></div>
</div>
<?php if ( ! empty( $shortcodes ) ) { ?>
<h4>Existing Codes: </h4>
<div id="sns-shortcodes-wrap">
<?php if ( ! empty( $shortcodes ) ) { ?>
<?php foreach ( $shortcodes as $key => $value ) { ?>
<div class="sns-less-ide" style="overflow: hidden">
<div class="widget sns-shortcodes"><div class="sns-collapsed inside">
<span class="sns-collapsed-btn"></span>
<p style="margin-bottom: 0;">[hoops name="<?php echo $key ?>"]</p>
<textarea class="code htmlmixed" data-sns-shortcode-key="<?php echo $key ?>" name="<?php echo $meta_name . '[shortcodes][' . $key . ']'; ?>" rows="5" cols="40" style="width: 98%;"><?php echo esc_textarea( $value ); ?></textarea>
<?php /** / ?>
<div class="sns-ajax-wrap">
<a class="sns-ajax-delete-shortcode button" href="#">Delete</a> &nbsp;
<a class="sns-ajax-update-shortcode button" href="#">Update</a>
<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>
</div>
<?php /**/ ?>
</div></div>
</div>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
</div>
<?php
}
}

View File

@@ -0,0 +1,176 @@
<?php
if ( ! class_exists( 'WP_List_Table' ) ) require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
class SnS_List_Usage extends WP_List_Table {
function ajax_user_can() {
return current_user_can( 'unfiltered_html' ) && current_user_can( 'manage_options' );
}
function column_default( $post, $column_name ) {
$return = '';
switch( $column_name ){
case 'status':
return $post->post_status;
case 'ID':
case 'post_type':
return $post->$column_name;
case 'script_data':
if ( isset( $post->sns_scripts[ 'scripts_in_head' ] ) ) {
$return .= '<div>' . __( 'Scripts (head)', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_scripts[ 'scripts' ] ) ) {
$return .= '<div>' . __( 'Scripts', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_scripts[ 'enqueue_scripts' ] ) ) {
$return .= '<div>' . __( 'Enqueued Scripts', 'scripts-n-styles' ) . '</div>';
}
return $return;
case 'style_data':
if ( isset( $post->sns_styles[ 'classes_mce' ] ) ) {
$return .= '<div>' . __( 'TinyMCE Formats', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_styles[ 'styles' ] ) ) {
$return .= '<div>' . __( 'Styles', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_styles[ 'classes_post' ] ) ) {
$return .= '<div>' . __( 'Post Classes', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_styles[ 'classes_body' ] ) ) {
$return .= '<div>' . __( 'Body Classes', 'scripts-n-styles' ) . '</div>';
}
return $return;
default:
return print_r( $post, true );
}
}
function column_title( $post ) {
$edit_link = esc_url( get_edit_post_link( $post->ID ) );
$edit_title = esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $post->post_title ) );
$actions = array(
'edit' => sprintf( '<a title="%s" href="%s">%s</a>', $edit_title, $edit_link, __( 'Edit' ) ),
);
$return = '<strong>';
if ( $this->ajax_user_can() && $post->post_status != 'trash' ) {
$return .= '<a class="row-title"';
$return .= ' href="'. $edit_link .'"';
$return .= ' title="'. $edit_title .'">';
$return .= $post->post_title;
$return .= '</a>';
} else {
$return .= $post->post_title;
}
$this->_post_states( $post );
$return .= '</strong>';
$return .= $this->row_actions( $actions );
return $return;
}
function get_columns() {
$columns = array(
'title' => __( 'Title' ),
'ID' => __( 'ID' ),
'status' => __( 'Status' ),
'post_type' => __( 'Post Type', 'scripts-n-styles' ),
'script_data' => __( 'Script Data', 'scripts-n-styles' ),
'style_data' => __( 'Style Data', 'scripts-n-styles' )
);
return $columns;
}
function prepare_items() {
$screen_id = get_current_screen()->id;
$per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen_id}_per_page" ) );
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns()
);
/**
* Get Relavent Posts.
*/
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => 'any',
'post_status' => 'any',
'orderby' => 'ID',
'order' => 'ASC',
'meta_key' => '_SnS'
) );
$items = $this->_add_meta_data( $posts );
$total_items = count( $items );
/**
* Reduce items to current page's posts.
*/
$this->items = array_slice(
$items,
( ( $this->get_pagenum() - 1 ) * $per_page ),
$per_page
);
$this->set_pagination_args( compact( 'total_items', 'per_page' ) );
}
function _post_states( $post ) {
$post_states = array();
$return = '';
if ( isset($_GET[ 'post_status' ]) )
$post_status = $_GET[ 'post_status' ];
else
$post_status = '';
if ( ! empty( $post->post_password ) )
$post_states[ 'protected' ] = __( 'Password protected' );
if ( 'private' == $post->post_status && 'private' != $post_status )
$post_states[ 'private' ] = __( 'Private' );
if ( 'draft' == $post->post_status && 'draft' != $post_status )
$post_states[ 'draft' ] = __( 'Draft' );
if ( 'pending' == $post->post_status && 'pending' != $post_status )
/* translators: post state */
$post_states[ 'pending' ] = _x( 'Pending', 'post state' );
if ( is_sticky($post->ID) )
$post_states[ 'sticky' ] = __( 'Sticky' );
$post_states = apply_filters( 'display_post_states', $post_states );
if ( ! empty( $post_states ) ) {
$state_count = count( $post_states );
$i = 0;
$return .= ' - ';
foreach ( $post_states as $state ) {
++$i;
( $i == $state_count ) ? $sep = '' : $sep = ', ';
$return .= "<span class='post-state'>$state$sep</span>";
}
}
if ( get_post_format( $post->ID ) )
$return .= ' - <span class="post-state-format">' . get_post_format_string( get_post_format( $post->ID ) ) . '</span>';
return $return;
}
function _add_meta_data( $posts ) {
foreach( $posts as $post) {
$SnS = get_post_meta( $post->ID, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS[ 'styles' ] ) ? $SnS[ 'styles' ]: array();
$scripts = isset( $SnS[ 'scripts' ] ) ? $SnS[ 'scripts' ]: array();
if ( ! empty( $styles ) )
$post->sns_styles = $styles;
if ( ! empty( $scripts ) )
$post->sns_scripts = $scripts;
}
return $posts;
}
}

View File

@@ -0,0 +1,451 @@
<?php
/**
* SnS_Admin_Meta_Box
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Admin_Meta_Box
{
/*
* Constants
*/
const NONCE_NAME = 'scripts_n_styles_noncename';
static $post_types;
/**
* Initializing method.
*/
static function init() {
add_action( 'current_screen', array( __CLASS__, 'add_meta_boxes' ) );
add_action( 'save_post', array( __CLASS__, 'save_post' ) );
}
static function mce_buttons_2( $buttons ) {
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
if ( ! empty( $styles[ 'classes_mce' ] ) )
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
static function tiny_mce_before_init( $initArray ) {
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
// Add div as a format option, should probably use a string replace thing here.
// Better yet, a setting for adding these. Postpone for now.
//$initArray['theme_advanced_blockformats'] = "p,address,pre,h1,h2,h3,h4,h5,h6,div";
if ( ( ! empty( $styles[ 'classes_body' ] ) || ! empty( $styles[ 'classes_post' ] ) ) && ! isset( $initArray['body_class'] ) )
$initArray['body_class'] = '';
// Add body_class (and/or maybe post_class) values... somewhat problematic.
if ( ! empty( $styles[ 'classes_body' ] ) )
$initArray['body_class'] .= ' ' . $styles[ 'classes_body' ];
if ( ! empty( $styles[ 'classes_post' ] ) )
$initArray['body_class'] .= ' ' . $styles[ 'classes_post' ];
// In case Themes or plugins have added style_formats, not tested.
if ( isset( $initArray['style_formats'] ) )
$style_formats = json_decode( $initArray['style_formats'], true );
else
$style_formats = array();
if ( ! empty( $styles[ 'classes_mce' ] ) )
foreach ( $styles[ 'classes_mce' ] as $format )
$style_formats[] = $format;
if ( ! empty( $style_formats ) )
$initArray['style_formats'] = json_encode( $style_formats );
return $initArray;
}
/**
* Admin Action: 'mce_css'
* Adds a styles sheet to TinyMCE via ajax that contains the current styles data.
*/
static function mce_css( $mce_css ) {
$url = admin_url( 'admin-ajax.php' );
$url = wp_nonce_url( $url, 'sns_tinymce_styles' );
$url = add_query_arg( 'post_id', get_the_ID(), $url );
$url = add_query_arg( 'action', 'sns_tinymce_styles', $url );
add_theme_support( 'editor-styles' );
add_editor_style( $url );
return $mce_css;
}
/**
* Admin Action: 'add_meta_boxes'
* Main Meta Box function. Checks restriction options and display options, calls add_meta_box() and adds actions for adding admin CSS and JavaScript.
*/
static function add_meta_boxes() {
if ( current_user_can( 'unfiltered_html' ) ) {
$post_type = get_current_screen()->post_type;
if ( in_array( $post_type, get_post_types( array('show_ui' => true, 'public' => true ) ) ) ) {
add_meta_box( 'SnS_meta_box', __( 'Scripts n Styles', 'scripts-n-styles' ), array( __CLASS__, 'admin_meta_box' ), $post_type, 'normal', 'high' );
add_filter( 'default_hidden_meta_boxes', array( __CLASS__, 'default_hidden_meta_boxes' ) );
add_action( "admin_print_styles", array( __CLASS__, 'meta_box_styles'));
add_action( "admin_print_scripts", array( __CLASS__, 'meta_box_scripts'));
add_filter( 'contextual_help', array( 'SnS_Admin', 'help' ) );
add_filter( 'mce_buttons_2', array( __CLASS__, 'mce_buttons_2' ) );
add_filter( 'tiny_mce_before_init', array( __CLASS__, 'tiny_mce_before_init' ) );
add_filter( 'replace_editor', array( __CLASS__, 'mce_css' ) );
}
}
}
static function default_hidden_meta_boxes( $hidden ) {
$options = get_option( 'SnS_options' );
if ( ! ( isset( $options[ 'metabox' ] ) && 'yes' == $options[ 'metabox' ] ) ) {
$hidden[] = 'SnS_meta_box';
$hidden[] = 'SnS_shortcode';
}
return $hidden;
}
/**
* Admin Action: 'add_meta_boxes'
* Outputs the Meta Box. Only called on callback from add_meta_box() during the add_meta_boxes action.
* @param unknown_type WordPress Post object.
*/
static function admin_meta_box( $post ) {
$registered_handles = Scripts_n_Styles::get_wp_registered();
$SnS = get_post_meta( $post->ID, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
$html = isset( $SnS['html'] ) ? $SnS[ 'html' ]: array();
$position = get_user_option( "current_sns_tab" );
if ( ! in_array( $position, array( 's0', 's1', 's2', 's3', 's4', 's5', 's6' ) ) ) $position = 's0';
wp_nonce_field( Scripts_n_Styles::$file, self::NONCE_NAME );
?>
<ul class="wp-tab-bar">
<li<?php echo ( 's0' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_scripts-tab"><?php _e( 'Scripts', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's1' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_styles-tab"><?php _e( 'Styles', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's2' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_classes_body-tab"><?php _e( 'Classes', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's3' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_enqueue_scripts-tab"><?php _e( 'Include Scripts', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's4' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_shortcodes-tab"><?php _e( 'Shortcodes', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's5' == $position ) ? ' class="wp-tab-active"': ''; ?> style="display:none"><a href="#SnS_post_styles-tab"><?php _e( 'Dropdown', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's6' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_html-tab"><?php _e( 'HTML', 'scripts-n-styles' ) ?></a></li>
</ul>
<div class="wp-tab-panel" id="SnS_scripts-tab">
<p><em><?php _e( "This code will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the end of your page's (or post's)", 'scripts-n-styles' ) ?> ...</em></p>
<label for="SnS_scripts_in_head" class="title"><?php _e( '<strong>Scripts</strong> (for the <code>head</code> element):', 'scripts-n-styles' ) ?> </label>
<div class="script">
<textarea class="codemirror js" name="SnS_scripts_in_head" id="SnS_scripts_in_head" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts_in_head' ] ) ? esc_textarea( $scripts[ 'scripts_in_head' ] ) : ''; ?></textarea>
</div>
<p><em>... <code>&lt;/head></code> <?php _e( 'tag', 'scripts-n-styles' ) ?>.</em></p>
<label for="SnS_scripts" class="title"><strong>Scripts</strong>: </label>
<div class="script">
<textarea class="codemirror js" name="SnS_scripts" id="SnS_scripts" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts' ] ) ? esc_textarea( $scripts[ 'scripts' ] ) : ''; ?></textarea>
</div>
<p><em>... <code>&lt;/body></code> <?php _e( 'tag', 'scripts-n-styles' ) ?>.</em></p>
</div>
<div class="wp-tab-panel" id="SnS_styles-tab">
<label for="SnS_styles" class="title"><?php _e( '<strong>Styles</strong>:', 'scripts-n-styles' ) ?> </label>
<div class="style">
<textarea class="codemirror css" name="SnS_styles" id="SnS_styles" rows="5" cols="40" style="width: 98%;"><?php echo isset( $styles[ 'styles' ] ) ? esc_textarea( $styles[ 'styles' ] ) : ''; ?></textarea>
</div>
<p><em><?php _e( 'This code will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> tag of your page (or post).', 'scripts-n-styles' ) ?></em></p>
</div>
<div class="wp-tab-panel" id="SnS_classes_body-tab">
<strong class="title"><?php _e( 'Classes', 'scripts-n-styles' ) ?></strong>
<div id="sns-classes">
<p>
<label for="SnS_classes_body"><?php _e( '<strong>Body Classes</strong>:', 'scripts-n-styles' ) ?> </label>
<input name="SnS_classes_body" id="SnS_classes_body" type="text" class="code" style="width: 99%;"
value="<?php echo isset( $styles[ 'classes_body' ] ) ? esc_attr( $styles[ 'classes_body' ] ) : ''; ?>" />
</p>
<p>
<label for="SnS_classes_post"><strong>Post Classes</strong>: </label>
<input name="SnS_classes_post" id="SnS_classes_post" type="text" class="code" style="width: 99%;"
value="<?php echo isset( $styles[ 'classes_post' ] ) ? esc_attr( $styles[ 'classes_post' ] ) : ''; ?>" />
</p>
<p><em><?php _e( 'These <strong>space separated</strong> class names will be added to the <code>body_class()</code> or <code>post_class()</code> function (provided your theme uses these functions).', 'scripts-n-styles' ) ?></em></p>
</div>
</div>
<?php
/*
* Note: Styles Dropdown section only makes sense when Javascript is enabled. (Otherwise, no TinyMCE.)
*/
?>
<div class="wp-tab-panel" id="SnS_post_styles-tab" style="display: none;">
<strong class="title"><?php _e( 'Post Styles', 'scripts-n-styles' ) ?></strong>
<div id="mce-dropdown-names">
<h4><?php _e( 'The Styles Dropdown', 'scripts-n-styles' ) ?></h4>
<div id="add-mce-dropdown-names">
<p><?php _e( 'Add (or update) a class for the "Styles" drop-down:', 'scripts-n-styles' ) ?></p>
<p class="sns-mce-title">
<label for="SnS_classes_mce_title"><?php _e( 'Title:', 'scripts-n-styles' ) ?></label>
<input name="SnS_classes_mce_title" id="SnS_classes_mce_title"
value="" type="text" class="code" style="width: 80px;" />
</p>
<p class="sns-mce-type">
<label for="SnS_classes_mce_type"><?php _e( 'Type:', 'scripts-n-styles' ) ?></label>
<select name="SnS_classes_mce_type" id="SnS_classes_mce_type" style="width: 80px;">
<option value="inline"><?php _ex( 'Inline', 'css type', 'scripts-n-styles' ) ?></option>
<option value="block"><?php _ex( 'Block', 'css type', 'scripts-n-styles' ) ?></option>
<option value="selector"><?php _ex( 'Selector:', 'css type', 'scripts-n-styles' ) ?></option>
</select>
</p>
<p class="sns-mce-element">
<label for="SnS_classes_mce_element"><?php _e( 'Element:', 'scripts-n-styles' ) ?></label>
<input name="SnS_classes_mce_element" id="SnS_classes_mce_element"
value="" type="text" class="code" style="width: 80px;" />
</p>
<p class="sns-mce-classes">
<label for="SnS_classes_mce_classes"><?php _e( 'Classes:', 'scripts-n-styles' ) ?></label>
<input name="SnS_classes_mce_classes" id="SnS_classes_mce_classes"
value="" type="text" class="code" style="width: 80px;" />
</p>
<p class="sns-mce-wrapper" style="display: none;">
<label for="SnS_classes_mce_wrapper"><?php _e( 'Wrapper:', 'scripts-n-styles' ) ?></label>
<input name="SnS_classes_mce_wrapper" id="SnS_classes_mce_wrapper" type="checkbox" value="true" />
</p>
</div>
<div id="delete-mce-dropdown-names" style="display: none;">
<p id="instructions-mce-dropdown-names"><?php _e( 'Classes currently in the dropdown:', 'scripts-n-styles' ) ?></p>
</div>
</div>
</div>
<div class="wp-tab-panel" id="SnS_enqueue_scripts-tab">
<strong class="title">Include Scripts</strong>
<select name="SnS_enqueue_scripts[]" id="SnS_enqueue_scripts" size="5" multiple="multiple" style="height: auto; float: left; margin: 6px 10px 8px 0;">
<?php
if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
foreach ( $registered_handles as $value ) { ?>
<option value="<?php echo esc_attr( $value ) ?>"<?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) selected( $handle, $value ); ?>><?php echo esc_html( $value ) ?></option>
<?php }
} else {
foreach ( $registered_handles as $value ) { ?>
<option value="<?php echo esc_attr( $value ) ?>"><?php echo esc_html( $value ) ?></option>
<?php }
} ?>
</select>
<?php if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) { ?>
<p><?php _e( 'Currently Enqueued Scripts:', 'scripts-n-styles' ) ?>
<?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) echo '<code>' . esc_html( $handle ) . '</code> '; ?>
</p>
<?php } ?>
<p><em><?php _e( 'The chosen scripts will be enqueued and placed before your codes if your code is dependant on certain scripts (like jQuery).', 'scripts-n-styles' ) ?></em></p>
</div>
<div class="wp-tab-panel" id="SnS_shortcodes-tab">
<strong class="title">Shortcodes</strong>
<div id="sns-add-shortcode">
<?php
$meta_name = 'SnS_shortcodes';
$SnS = get_post_meta( $post->ID, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$shortcodes = isset( $SnS['shortcodes'] ) ? $SnS[ 'shortcodes' ] : array();
?>
<label for="<?php echo $meta_name; ?>">Name: </label>
<input id="<?php echo $meta_name; ?>" name="<?php echo $meta_name . '[new][name]'; ?>" type="text" />
<textarea id="<?php echo $meta_name; ?>_new" class="codemirror htmlmixed" name="<?php echo $meta_name . '[new][value]'; ?>" rows="5" cols="40" style="width: 98%;"></textarea>
</div>
<div id="sns-shortcodes">
<h4>Existing Codes: </h4>
<div id="sns-shortcodes-wrap">
<?php if ( ! empty( $shortcodes ) ) { ?>
<?php foreach ( $shortcodes as $key => $value ) { ?>
<div class="sns-shortcode widget"><div class="inside">
<p>[hoops name="<?php echo $key ?>"]</p>
<textarea class="codemirror htmlmixed" data-sns-shortcode-key="<?php echo $key ?>" name="<?php echo $meta_name . '[existing][' . $key . ']'; ?>" rows="5" cols="40" style="width: 98%;"><?php echo esc_textarea( $value ); ?></textarea>
</div></div>
<?php } ?>
<?php } ?>
</div>
</div>
</div>
<div class="wp-tab-panel" id="SnS_html-tab">
<p><em><?php _e( "<strong>HTML</strong> for the <code>head</code> element", 'scripts-n-styles' ) ?> ...</em></p>
<label for="SnS_html_in_head" class="title"><?php _e( '<strong>HTML</strong> (for the <code>head</code> element):', 'scripts-n-styles' ) ?> </label>
<div class="html">
<textarea class="codemirror html" name="SnS_html_in_head" id="SnS_html_in_head" rows="5" cols="40" style="width: 98%;"><?php echo isset( $html[ 'html_in_head' ] ) ? esc_textarea( $html[ 'html_in_head' ] ) : ''; ?></textarea>
</div>
<p>&nbsp;</p>
<p><em><?php _e( "<strong>HTML</strong> for the <code>bottom of the body</code> element", 'scripts-n-styles' ) ?> ...</em></p>
<label for="SnS_html_in_footer" class="title"><strong><?php _e( '<strong>HTML</strong> (for the <code>bottom of the body</code>):', 'scripts-n-styles' ) ?></strong>: </label>
<div class="html">
<textarea class="codemirror html" name="SnS_html_in_footer" id="SnS_html_in_footer" rows="5" cols="40" style="width: 98%;"><?php echo isset( $html[ 'html_in_footer' ] ) ? esc_textarea( $html[ 'html_in_footer' ] ) : ''; ?></textarea>
</div>
</div>
<?php
}
static function current_classes( $type, $post_id ) {
if ( 'body' == $type ) {
global $wp_query, $pagenow;
if ( 'post-new.php' == $pagenow ) {
echo join( ' ', get_body_class( '', $post_id ) );
echo ' ' . __( '(plus others once saved.)', 'scripts-n-styles' );
return;
}
// This returns more of what actually get used on the theme side.
$save = $wp_query;
$param = ( 'page' == get_post_type( $post_id ) ) ? 'page_id': 'p';
$wp_query = new WP_Query( "$param=$post_id" );
echo join( ' ', get_body_class( '', $post_id ) );
$wp_query = $save;
} else {
echo join( ' ', get_post_class( '', $post_id ) );
}
}
/**
* Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
* Enqueues the CSS for admin styling of the Meta Box.
*/
static function meta_box_styles() {
wp_enqueue_style( 'chosen' );
wp_enqueue_style( 'sns-meta-box' );
}
/**
* Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
* Enqueues the JavaScript for the admin Meta Box.
*/
static function meta_box_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
wp_enqueue_script( 'sns-meta-box' );
wp_localize_script( 'sns-meta-box', 'codemirror_options', array( 'theme' => $cm_theme ) );
}
/**
* Admin Action: 'save_post'
* Saves the values entered in the Meta Box when a post is saved (on the Edit Screen only, excluding autosaves) if the user has permission.
* @param int $post_id ID value of the WordPress post.
*/
static function save_post( $post_id ) {
if ( ! isset( $_POST[ self::NONCE_NAME ] ) || ! wp_verify_nonce( $_POST[ self::NONCE_NAME ], Scripts_n_Styles::$file )
|| ! current_user_can( 'unfiltered_html' )
|| wp_is_post_revision( $post_id ) // is needed for get_post_meta compatibility.
|| ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
) return;
/*
NOTE: There is no current_user_can( 'edit_post' ) check here, because as far as I
can tell, in /wp-admin/post.php the calls edit_post(), write_post(), post_preview(),
wp_untrash_post(), etc., the check is already done prior to the 'save_post' action,
which is where this function is called. Other calls are from other pages so the
NONCE covers those cases, and that leaves autosave, which is also checked here.
*/
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array(); // automatic array conversion became an error in PHP 7.1
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
$html = isset( $SnS['html'] ) ? $SnS[ 'html' ]: array();
$scripts = self::maybe_set( $scripts, 'scripts_in_head' );
$scripts = self::maybe_set( $scripts, 'scripts' );
$scripts = self::maybe_set( $scripts, 'enqueue_scripts' );
$styles = self::maybe_set( $styles, 'styles' );
$styles = self::maybe_set( $styles, 'classes_body' );
$styles = self::maybe_set( $styles, 'classes_post' );
$html = self::maybe_set( $html, 'html_in_head' );
$html = self::maybe_set( $html, 'html_in_footer' );
$shortcodes = array();
$SnS_shortcodes = isset( $_REQUEST[ 'SnS_shortcodes' ] ) ? $_REQUEST[ 'SnS_shortcodes' ]: array();
$existing_shortcodes = isset( $SnS_shortcodes[ 'existing' ] ) ? $SnS_shortcodes[ 'existing' ]: array();
foreach ( $existing_shortcodes as $key => $value )
if ( ! empty( $value ) )
$shortcodes[ $key ] = $value;
$new_shortcode = isset( $SnS_shortcodes[ 'new' ] ) ? $SnS_shortcodes[ 'new' ]: array();
if ( ! empty( $new_shortcode[ 'value' ] ) ) {
$key = ( isset( $new_shortcode[ 'name' ] ) ) ? $new_shortcode[ 'name' ] : '';
if ( '' == $key ) {
$key = count( $shortcodes );
while ( isset( $shortcodes[ $key ] ) )
$key++;
}
if ( isset( $shortcodes[ $key ] ) ) {
$countr = 1;
while ( isset( $shortcodes[ $key . '_' . $countr ] ) )
$countr++;
$key .= '_' . $countr;
}
$shortcodes[ $key ] = $new_shortcode[ 'value' ];
}
// This one isn't posted, it's ajax only. Cleanup anyway.
if ( isset( $styles[ 'classes_mce' ] ) && empty( $styles[ 'classes_mce' ] ) )
unset( $styles[ 'classes_mce' ] );
if ( empty( $scripts ) ) {
if ( isset( $SnS['scripts'] ) )
unset( $SnS['scripts'] );
} else {
$SnS['scripts'] = $scripts;
}
if ( empty( $styles ) ) {
if ( isset( $SnS['styles'] ) )
unset( $SnS['styles'] );
} else {
$SnS['styles'] = $styles;
}
if ( empty( $html ) ) {
if ( isset( $SnS['html'] ) )
unset( $SnS['html'] );
} else {
$SnS['html'] = $html;
}
if ( empty( $shortcodes ) ) {
if ( isset( $SnS['shortcodes'] ) )
unset( $SnS['shortcodes'] );
} else {
$SnS['shortcodes'] = $shortcodes;
}
if ( empty( $SnS ) )
delete_post_meta( $post_id, '_SnS' );
else
update_post_meta( $post_id, '_SnS', $SnS );
}
/**
* maybe_set()
* Filters $o and Checks if the sent data $i is empty (intended to clear). If not, updates.
*/
static function maybe_set( $o, $i, $p = 'SnS_' ) {
if ( ! is_array( $o ) ) return array();
if ( empty( $_REQUEST[ $p . $i ] ) ) {
if ( isset( $o[ $i ] ) ) unset( $o[ $i ] );
} else {
$o[ $i ] = $_REQUEST[ $p . $i ];
}
return $o;
}
}

View File

@@ -0,0 +1,186 @@
<?php
/**
* SnS_Settings_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Settings_Page
{
/**
* Constants
*/
const MENU_SLUG = 'sns_settings';
/**
* Initializing method.
* @static
*/
static function init() {
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Settings' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
// Make the page into a tab.
if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
}
}
static function parent_file( $parent_file ) {
global $plugin_page, $submenu_file;
if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
return $parent_file;
}
static function admin_enqueue_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : '';
wp_enqueue_style( 'sns-options' );
wp_enqueue_script( 'sns-settings-page' );
wp_localize_script( 'sns-settings-page', 'codemirror_options', array( 'theme' => $cm_theme ) );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
wp_enqueue_style( 'sns-options' );
register_setting(
SnS_Admin::OPTION_GROUP,
'SnS_options' );
add_settings_section(
'settings',
__( 'Scripts n Styles Settings', 'scripts-n-styles' ),
array( __CLASS__, 'settings_section' ),
SnS_Admin::MENU_SLUG );
add_settings_field(
'metabox',
__( '<strong>Hide Metabox by default</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'settings',
array(
'label_for' => 'metabox',
'setting' => 'SnS_options',
'choices' => array( 'yes', 'no' ),
'layout' => 'horizontal',
'default' => 'yes',
'legend' => __( 'Hide Metabox by default', 'scripts-n-styles' ),
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">This is overridable via Screen Options on each edit screen.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'menu_position',
__( '<strong>Menu Position</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'settings',
array(
'label_for' => 'menu_position',
'setting' => 'SnS_options',
'choices' => array( 'menu', 'object', 'utility', 'tools.php', 'options-general.php', 'themes.php' ),
'default' => 'tools.php',
'legend' => __( 'Theme', 'scripts-n-styles' ),
'layout' => 'vertical',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">Some people are fussy about where the menu goes, so I made an option.</span>', 'scripts-n-styles' ),
) );
add_settings_section(
'demo',
__( 'Code Mirror Demo', 'scripts-n-styles' ),
array( __CLASS__, 'demo_section' ),
SnS_Admin::MENU_SLUG );
add_settings_field(
'cm_theme',
__( '<strong>Theme</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'demo',
array(
'label_for' => 'cm_theme',
'setting' => 'SnS_options',
'choices' => Scripts_n_Styles::$cm_themes,
'default' => 'default',
'legend' => __( 'Theme', 'scripts-n-styles' ),
'layout' => 'horizontal',
'description' => '',
) );
add_settings_field(
'hoops_widget',
__( '<strong>Hoops Widgets</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'settings',
array(
'label_for' => 'hoops_widget',
'setting' => 'SnS_options',
'choices' => array( 'yes', 'no' ),
'layout' => 'horizontal',
'default' => 'no',
'legend' => __( 'Shortcode Widgets', 'scripts-n-styles' ),
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">This enables Hoops shortcodes to be used via a "Hoops" Text Widget.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'delete_data_uninstall',
__( '<strong>Delete Data When Uninstalling</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'settings',
array(
'label_for' => 'delete_data_uninstall',
'setting' => 'SnS_options',
'choices' => array( 'yes', 'no' ),
'layout' => 'horizontal',
'default' => 'no',
'legend' => __( 'Delete Data When Uninstalling', 'scripts-n-styles' ),
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">Should the plugin clean up after itself and delete all of its saved data.</span>', 'scripts-n-styles' )
) );
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function settings_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'Control how and where Scripts n Styles menus and metaboxes appear. These options are here because sometimes users really care about this stuff. Feel free to adjust to your liking. :-)', 'scripts-n-styles' ) ?></p>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function demo_section() {
?>
<div style="max-width: 55em;">
<textarea id="codemirror_demo" name="code" style="min-width: 500px; width:97%;" rows="5" cols="40">
<?php echo esc_textarea( '<?php
function hello($who) {
return "Hello " . $who;
}
?>
<p>The program says <?= hello("World") ?>.</p>
<script>
alert("And here is some JS code"); // also colored
</script>' ); ?>
</textarea>
</div>
<?php
}
}

View File

@@ -0,0 +1,170 @@
<?php
/**
* SnS_Theme_Page
*
* Allows WordPress admin users the ability to edit theme CSS
* and LESS directly in the admin via CodeMirror.
*
* On the `wp_enqueue_scripts` action, use `wp_enqueue_style( 'theme_style', get_stylesheet_uri() );` to add your style.css instead of inline.
* On the `after_setup_theme` action, use `add_theme_support( 'scripts-n-styles', array( '/less/variables.less', '/less/mixins.less' ) );` but use the appropriate file locations.
*
*/
class SnS_Theme_Page
{
/**
* Constants
*/
const MENU_SLUG = 'sns_theme';
static $files = array();
/**
* Initializing method.
* @static
*/
static function init() {
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Theme' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
// Make the page into a tab.
if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
}
}
static function parent_file( $parent_file ) {
global $plugin_page, $submenu_file;
if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
return $parent_file;
}
static function admin_enqueue_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
wp_enqueue_style( 'sns-options' );
wp_enqueue_style( 'codemirror-theme' );
wp_enqueue_script( 'sns-theme-page' );
wp_localize_script( 'sns-theme-page', '_SnS_options', array( 'theme' => $cm_theme ) );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
// added here to not effect other pages. Theme page requires JavaScript (less.js) or it doesn't make sense to save.
add_filter( 'sns_show_submit_button', '__return_false' );
register_setting(
SnS_Admin::OPTION_GROUP,
'SnS_options' );
add_settings_section(
'theme',
__( 'Scripts n Styles Theme Files', 'scripts-n-styles' ),
array( __CLASS__, 'less_fields' ),
SnS_Admin::MENU_SLUG );
}
static function less_fields() {
$files = array();
$support_files = get_theme_support( 'scripts-n-styles' );
if ( is_child_theme() )
$root = get_stylesheet_directory();
else
$root = get_template_directory();
foreach( $support_files[0] as $file ) {
if ( is_file( $root . $file ) )
$files[] = $root . $file;
}
$slug = get_stylesheet();
$options = get_option( 'SnS_options' );
// Stores data on a theme by theme basis.
$theme = isset( $options[ 'themes' ][ $slug ] ) ? $options[ 'themes' ][ $slug ] : array();
$stored = isset( $theme[ 'less' ] ) ? $theme[ 'less' ] : array(); // is an array of stored imported less file data
$compiled = isset( $theme[ 'compiled' ] ) ? $theme[ 'compiled' ] : ''; // the complete compiled down css
$slug = esc_attr( $slug );
$open_theme_panels = json_decode( get_user_option( 'sns_open_theme_panels', get_current_user_id() ), true );
?>
<div style="overflow: hidden">
<div id="less_area" style="width: 49%; float: left; overflow: hidden; margin-right: 2%;">
<?php
foreach ( $files as $file ) {
$name = basename( $file );
$raw = file_get_contents( $file );
if ( isset( $stored[ $name ] ) ) {
$source = $stored[ $name ];
$less = isset( $source ) ? $source : '';
$compiled = isset( $compiled ) ? $compiled : '';
} else {
$less = $raw;
$compiled = '';
}
$name = esc_attr( $name );
$lead_break = 0 == strpos( $less, PHP_EOL ) ? PHP_EOL : '';
if ( isset( $open_theme_panels[ $name ] ) )
$collapse = $open_theme_panels[ $name ] == 'yes' ? 'sns-collapsed ' : '';
else
$collapse = $less == $raw ? 'sns-collapsed ': '';
?>
<div class="sns-less-ide" style="overflow: hidden">
<div class="widget"><div class="<?php echo $collapse; ?>inside">
<span class="sns-collapsed-btn"></span>
<label style="margin-bottom: 0;"><?php echo $name ?></label>
<textarea data-file-name="<?php echo $name ?>" data-raw="<?php echo esc_attr( $raw ) ?>"
name="SnS_options[themes][<?php echo $slug ?>][less][<?php echo $name ?>]"
style="min-width: 250px; width:47%;"
class="code less" rows="5" cols="40"><?php echo $lead_break . esc_textarea( $less ) ?></textarea>
<div class="sns-ajax-wrap">
<a class="sns-ajax-load button" href="#">Load Source File</a>
<a class="sns-ajax-save button" href="#">Save All Changes</a>
<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>
<div class="single-status"><div class="updated settings-error below-h2"></div></div>
</div>
</div></div>
</div>
<?php
}
?>
</div>
<div id="css_area" class="sns-less-ide" style="width: 49%; float: left; overflow: hidden;">
<div id="compile_status" style="display: none" class="updated settings-error below-h2">
<p><span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>
<span class="status-text">Keystokes detected. 1 second delay, then compiling...</span></p>
</div>
<div class="widget"><div class="sns-collapsed inside">
<span class="sns-collapsed-btn"></span>
<label style="margin-bottom: 0;">Preview Window</label>
<textarea
name="SnS_options[themes][<?php echo $slug ?>][compiled]"
style="min-width: 250px; width:47%;"
class="code css" rows="5" cols="40"><?php echo esc_textarea( $compiled ) ?></textarea>
</div></div>
<div id="compiled_error" class="error settings-error below-h2"></div>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function global_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Scripts and Styles registered individually.', 'scripts-n-styles' )?></p>
</div>
<?php
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* SnS_Settings_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Usage_Page
{
/**
* Constants
*/
const MENU_SLUG = 'sns_usage';
/**
* Initializing method.
* @static
*/
static function init() {
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Usage', 'scripts-n-styles' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
// Make the page into a tab.
if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
}
}
static function parent_file( $parent_file ) {
global $plugin_page, $submenu_file;
if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
return $parent_file;
}
static function admin_enqueue_scripts() {
wp_enqueue_style( 'sns-options' );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
add_screen_option( 'per_page', array( 'label' => __( 'Per Page' ), 'default' => 20 ) );
add_filter( 'set-screen-option', array( __CLASS__, 'set_screen_option' ), 10, 3 );
// hack for core limitation: see http://core.trac.wordpress.org/ticket/18954
set_screen_options();
add_settings_section(
'usage',
__( 'Scripts n Styles Usage', 'scripts-n-styles' ),
array( __CLASS__, 'usage_section' ),
SnS_Admin::MENU_SLUG );
}
static function set_screen_option( $false, $option, $value ) {
$screen_id = get_current_screen()->id;
$this_option = str_replace( '-', '_', "{$screen_id}_per_page" );
if ( $this_option != $option )
return false;
$value = (int) $value;
if ( $value < 1 || $value > 999 )
return false;
return $value;
}
/**
* Settings Page
* Outputs the Usage Section.
*/
static function usage_section() { ?>
<div style="max-width: 55em;">
<p><?php _e( 'The following table shows content that utilizes Scripts n Styles.', 'scripts-n-styles' ) ?></p>
</div>
<?php
require_once( 'class-sns-list-usage.php' );
$usageTable = new SnS_List_Usage();
$usageTable->prepare_items();
$usageTable->display();
}
}

View File

@@ -0,0 +1,114 @@
// Options JavaScript
jQuery( document ).ready( function( $ ) {
if ( 'plugin-editor' == pagenow )
$.ajax({
type: "POST",
url: ajaxurl,
data: {
_ajax_nonce: sns_plugin_editor_options.nonce,
action: sns_plugin_editor_options.action,
file: $('input[name="file"]').val(),
plugin: $('input[name="plugin"]').val()
},
success: function( data ) {
$('#templateside > ul').html( data.ul );
if ( ! data.need_update ) return;
var warning = "<p><strong>Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.</p>";
if ( data.active ) {
$('p.submit').before(warning);
$('.fileedit-sub .alignleft big').html( 'Editing <strong>' + $('.fileedit-sub .alignleft big strong').html() + '</strong> (active)' );
}
$('#plugin').val( data.plugin );
console.dir( data );
}
});
});
jQuery( document ).ready( function( $ ) {
var theme = codemirror_options.theme ? codemirror_options.theme: 'default',
file = $( 'input[name="file"]' ).val(),
$new = $( '#newcontent' ),
$template = $( '#template' ),
$wpbody = $( '#wpbody-content' ),
$documentation = $( '#documentation' ),
$submit = $( 'p.submit' ).first(),
$warning = $( '#documentation + p:not(.submit)' ).first(),
$templateside = $( '#templateside' ),
templateOffset, bottomPadding, docHeight, submitHeight, resizeTimer, fileType, cmheight;
fileType = file.slice( file.lastIndexOf(".")+1 );
templateOffset = parseInt( jQuery('#template').offset().top ),
bottomPadding = parseInt( $('#wpbody-content').css('padding-bottom') );
docHeight = ( $documentation.length ) ? parseInt( $documentation.height() )
+ parseInt( $documentation.css('padding-top') )
+ parseInt( $documentation.css('padding-bottom') )
+ parseInt( $documentation.css('margin-top') )
+ parseInt( $documentation.css('margin-bottom') )
: 0;
warningHeight = ( $warning.length ) ? parseInt( $warning.height() )
+ parseInt( $warning.css('padding-top') )
+ parseInt( $warning.css('padding-bottom') )
+ parseInt( $warning.css('margin-top') )
+ parseInt( $warning.css('margin-bottom') )
: 0;
submitHeight = parseInt( $submit.height() )
+ parseInt( $submit.css('padding-top') )
+ parseInt( $submit.css('padding-bottom') )
+ parseInt( $submit.css('margin-top') )
+ parseInt( $submit.css('margin-bottom') );
templateside = parseInt( $templateside.height() );
var config = {
lineNumbers: true,
theme: theme,
//viewportMargin: Infinity
};
switch ( fileType ) {
case "md":
config.mode = "gfm";
break;
case "js":
config.mode = "javascript";
break;
case "css":
config.mode = "css";
break;
case "less":
config.mode = "less";
break;
case "coffee":
config.mode = "coffeescript";
break;
case "html":
case "htm":
config.mode = "html";
break;
case "php":
config.mode = "php";
break;
default:
config.mode = "markdown";
break;
}
CodeMirror.commands.save = function (){ jQuery('#submit').click(); };
var cmeditor = CodeMirror.fromTextArea( $new.get(0), config );
$(window).resize(function(){
clearTimeout(resizeTimer);
resizeTimer = setTimeout( cmresizer, 100 );
});
function cmresizer() {
cmheight = Math.max( 300, $(window).height() - ( templateOffset + bottomPadding + docHeight + warningHeight + submitHeight + 40 ) );
if ( cmheight > templateside )
cmeditor.setSize( null, cmheight );
else
cmeditor.setSize( null, $(window).height() - ( templateOffset + docHeight + warningHeight + submitHeight ) );
}
cmresizer();
});

View File

@@ -0,0 +1,134 @@
// Options JavaScript
jQuery( document ).ready( function( $ ) {
var compiled, source;
var theme = _SnS_options.theme ? _SnS_options.theme: 'default';
var lessMirror, lessOutput, errorLine, errorText, errors, loaded,
coffeeMirror, coffeeOutput, coffee_errorLine, coffee_errorText, coffee_errors, coffee_loaded,
lessMirrorConfig = { gutters: ["note-gutter", "CodeMirror-linenumbers"],
lineNumbers: true, mode: "text/x-less", theme: theme, indentWithTabs: true },
coffeeMirrorConfig = { lineNumbers: true, mode: "text/x-coffeescript", theme: theme };
var parser = new( less.Parser )({});
$("#enqueue_scripts").data( 'placeholder', 'Enqueue Registered Scripts...' ).width(350).chosen();
$(".chosen-container-multi .chosen-choices .search-field input").height('26px');
$(".chosen-container .chosen-results").css( 'max-height', '176px');
//CodeMirror.commands.save = saveLessMirror;
$( "textarea.js" ).not( '#coffee_compiled' ).each( function() {
CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "javascript", theme: theme } );
});
$( "textarea.css" ).not( '#compiled' ).each( function() {
CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "css", theme: theme } );
});
$( "textarea.html" ).each( function() {
CodeMirror.fromTextArea( this, { lineNumbers: true, mode: "text/html", theme: theme } );
});
lessOutput = CodeMirror.fromTextArea( $( '#compiled' ).get(0), { lineNumbers: true, mode: "css", theme: theme, readOnly: true } );
coffeeOutput = CodeMirror.fromTextArea( $( '#coffee_compiled' ).get(0), { lineNumbers: true, mode: "javascript", theme: theme, readOnly: true } );
$( "textarea.less" ).each( function() {
lessMirror = CodeMirror.fromTextArea( this, lessMirrorConfig );
lessMirror.on( "change", compile );
});
$( "textarea.coffee" ).each( function() {
coffeeMirror = CodeMirror.fromTextArea( this, coffeeMirrorConfig );
coffeeMirror.on( "change", coffee_compile );
});
$('#coffee').parent().append('<label><input type="checkbox" id="coffee_spacing"> Double Spaced</label>');
$('#coffee_spacing').change( coffee_compile );
compile();
coffee_compile();
loaded = true;
coffee_loaded = true;
$( "#less" ).closest('form').submit( compile );
$( "#coffee" ).closest('form').submit( coffee_compile );
//function saveLessMirror(){
// Ajax Save.
//}
function compile() {
lessMirror.save();
parser.parse( lessMirror.getValue(), function ( err, tree ) {
if ( err ){
doError( err );
} else {
try {
$( '#compiled_error' ).hide();
lessOutput.setValue( tree.toCSS() );
lessOutput.save();
$( '#compiled' ).next( '.CodeMirror' ).show();
lessOutput.refresh();
clearCompileError();
}
catch ( err ) {
doError( err );
}
}
});
}
function coffee_compile() {
coffeeMirror.save();
try {
$( '#coffee_compiled_error' ).hide();
source = $('#coffee').val();
if ( '' == source || ' ' == source ) {
coffeeOutput.setValue( '' );
} else {
compiled = CoffeeScript.compile( source );
trimmed = $('#coffee_spacing').is(':checked') ? compiled : compiled.replace(/(\n\n)/gm,"\n");
coffeeOutput.setValue( trimmed );
}
coffeeOutput.save();
$( '#coffee_compiled' ).next( '.CodeMirror' ).show();
}
catch ( err ) {
console.dir( err );
$( '#coffee_compiled' ).next( '.CodeMirror' ).hide();
if ( coffee_loaded ) {
$( '#coffee_compiled_error' ).removeClass( 'error' ).addClass( 'updated' );
$( '#coffee_compiled_error' ).show().html( "<p><strong>Warning: &nbsp; </strong>" + err.message + "</p>" );
} else {
$( '#coffee_compiled_error' ).show().html( "<p><strong>Error: &nbsp; </strong>" + err.message + "</p>" );
}
}
}
function doError( err ) {
//console.dir( err );
$( '#compiled' ).next( '.CodeMirror' ).hide();
if ( loaded ) {
$( '#compiled_error' ).removeClass( 'error' ).addClass( 'updated' );
$( '#compiled_error' ).show().html( "<p><strong>Warning: &nbsp; </strong>" + err.message + "</p>" );
} else {
$( '#compiled_error' ).show().html( "<p><strong>Error: &nbsp; </strong>" + err.message + "</p>" );
}
clearCompileError();
errorLine = lessMirror.setGutterMarker( err.line - 1, 'note-gutter', document.createTextNode("*") );
//lessMirror.setLineClass( errorLine, "cm-error");
var pos = lessMirror.posFromIndex( err.index + 1 );
var token = lessMirror.getTokenAt( pos );
var start = lessMirror.posFromIndex( err.index );
var end = lessMirror.posFromIndex( err.index + token.string.length )
errorText = lessMirror.markText( start, end, { className: "cm-error" } );
lessOutput.setValue( "" );
lessOutput.save();
}
function clearCompileError() {
if ( errorLine ) {
lessMirror.clearGutter( 'note-gutter' );
//lessMirror.setLineClass( errorLine, null );
errorLine = false;
}
if ( errorText ) errorText.clear();
errorText = false;
}
});

View File

@@ -0,0 +1,105 @@
// Options JavaScript
jQuery( document ).ready( function( $ ) { "use strict"
var collection = []
, context = "#sns-shortcodes"
, theme = _SnS_options.theme ? _SnS_options.theme: 'default'
, $form
, config;
config = {
mode: "text/html",
theme: theme,
lineNumbers: true,
tabMode: "shift",
indentUnit: 4,
indentWithTabs: true,
enterMode: "keep",
matchBrackets: true
};
CodeMirror.commands.save = function() {
$form.submit();
};
// Each "IDE"
$( ".sns-less-ide", context ).each( function() {
var $text = $('.code',this);
var ide = {
data : $text.val(),
name : $text.data('sns-shortcode-key'),
$text : $text,
cm : CodeMirror.fromTextArea( $text.get(0), config )
};
if ( $text.parent().hasClass( 'sns-collapsed' ) )
ide.cm.toTextArea();
collection.push( ide );
});
// Collapsable
$( context ).on( "click", '.sns-collapsed-btn, .sns-collapsed-btn + label', function( event ){
var $this = $( this )
, collapsed
, fileName
, thisIDE;
$this.parent().toggleClass( 'sns-collapsed' );
fileName = $this.siblings( '.code' ).data( 'sns-shortcode-key' );
collapsed = $this.parent().hasClass( 'sns-collapsed' );
$(collection).each(function(index, element) {
if ( element.name == fileName )
thisIDE = element;
});
if ( collapsed ) {
thisIDE.cm.toTextArea();
} else {
thisIDE.cm = CodeMirror.fromTextArea( thisIDE.$text.get(0), config );
}
});
$( '.sns-ajax-loading' ).hide();
/*
$form = $( context ).closest( 'form' );
$form.submit( function( event ){
event.preventDefault();
$.ajax({
type: "POST",
url: window.location,
data: $(this).serialize()+'&ajaxsubmit=1',
cache: false,
success: saved
});
});
// Save
$( context ).on( "click", ".sns-ajax-save", function( event ){
event.preventDefault();
$( this ).nextAll( '.sns-ajax-loading' ).show();
$form.submit();
});*/
/*
function saved( data ) {
$(data).insertAfter( '#icon-sns + h2' ).delay(3000).fadeOut();
$( '.sns-ajax-loading' ).hide();
}
* Expects return data.
$('#sns-ajax-add-shortcode').click(function( event ){
event.preventDefault();
$(this).next().show();
$(collection).each(function (){ this.save(); });
var args = { _ajax_nonce: nonce };
args.action = 'sns_hoops';
args.subaction = 'add';
args.name = $( '#SnS_shortcodes' ).val();
args.shortcode = $( '#SnS_shortcodes_new' ).val();
$.post( ajaxurl, args, function( data ) { refreshShortcodes( data ); } );
});
$('#SnS_shortcodes').keypress(function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
$("#sns-ajax-add-shortcode").click();
}
});
*/
});

View File

@@ -0,0 +1,666 @@
jQuery( document ).ready( function( $ ) {
var context = '#SnS_meta_box',
currentCodeMirror = [], keys = [],
gutenMCE = false,
nonce = $( '#scripts_n_styles_noncename' ).val(),
theme = codemirror_options.theme ? codemirror_options.theme: 'default';
if ( window.wpEditorL10n && wpEditorL10n.tinymce && wpEditorL10n.tinymce.settings ) {
gutenMCE = wpEditorL10n.tinymce.settings;
}
// For CPTs that don't have an editor, prevent "tinyMCEPreInit is 'undefined'"
var initDatas = ( typeof tinyMCEPreInit !== 'undefined' && tinyMCEPreInit.mceInit ) ? tinyMCEPreInit.mceInit: false;
for ( var prop in initDatas ) {
keys.push( prop );
}
var mceBodyClass = getMCEBodyClasses();
$("#SnS_enqueue_scripts").data( 'placeholder', 'Enqueue Registered Scripts...' ).chosen({ width: "356px" });
$(".chosen-container-multi .chosen-choices .search-field input").height('26px');
$(".chosen-container .chosen-results").css( 'max-height', '176px');
//$('textarea', context).attr('autocomplete','off');
// Refresh when panel becomes unhidden
$( '#adv-settings' ).on( 'click', context + '-hide', refreshCodeMirrors );
$( context ).on( 'click', '.hndle, .handlediv', refreshCodeMirrors );
// add tab-switch handler
$( context ).on( 'click', '.wp-tab-bar a', onTabSwitch );
// activate first run
$( '.wp-tab-active a', context ).click();
// must run before ajax click handlers are added.
setupAjaxUI();
refreshDeleteBtns();
if ( gutenMCE && wp.data && wp.data.select ) {
var editPost = wp.data.select( 'core/edit-post' );
wp.data.subscribe( function() {
if ( editPost.isSavingMetaBoxes() ) {
$( currentCodeMirror ).each( function() {
this.save();
});
} else {
$( currentCodeMirror ).each( function() {
this.refresh();
});
}
});
}
$('#sns-ajax-update-scripts').click(function( event ){
event.preventDefault();
$(this).next().show();
$(currentCodeMirror).each(function (){ this.save(); });
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_scripts';
args.scripts = $( '#SnS_scripts' ).val();
args.scripts_in_head = $( '#SnS_scripts_in_head' ).val();
$.post( ajaxurl, args, function() { refreshMCE(); } );
});
$('#sns-ajax-update-html').click(function( event ){
event.preventDefault();
$(this).next().show();
$(currentCodeMirror).each(function (){ this.save(); });
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_html';
args.html_in_footer = $( '#SnS_html_in_footer' ).val();
args.html_in_head = $( '#SnS_html_in_head' ).val();
$.post( ajaxurl, args, function(res) { console.log('post sent'); refreshMCE(); } );
});
$('#sns-ajax-update-styles').click(function( event ){
event.preventDefault();
$(this).next().show();
$(currentCodeMirror).each(function (){ this.save(); });
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_styles';
args.styles = $( '#SnS_styles' ).val();
$.post( ajaxurl, args, function() { refreshMCE(); } );
});
/*
* Expects return data.
*/
$('#sns-ajax-update-classes').click(function( event ){
event.preventDefault();
$(this).next().show();
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_classes';
args.classes_body = $( '#SnS_classes_body' ).val();
args.classes_post = $( '#SnS_classes_post' ).val();
$.post( ajaxurl, args, function( data ) { refreshBodyClass( data ); } );
});
$('#SnS_classes_body, #SnS_classes_body').keypress(function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
$("#sns-ajax-update-classes").click();
}
});
/*
* Expects return data.
*/
$('#sns-ajax-update-dropdown').click(function( event ){
event.preventDefault();
$(this).next().show();
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_dropdown';
var format = {};
format.title = $( '#SnS_classes_mce_title' ).val();
format.classes = $( '#SnS_classes_mce_classes' ).val();
switch ( $( '#SnS_classes_mce_type' ).val() ) {
case 'inline':
format.inline = $( '#SnS_classes_mce_element' ).val();
break;
case 'block':
format.block = $( '#SnS_classes_mce_element' ).val();
if ( $( '#SnS_classes_mce_wrapper' ).prop('checked') )
format.wrapper = true;
break;
case 'selector':
format.selector = $( '#SnS_classes_mce_element' ).val();
break;
default:
return;
}
args.format = format;
$.post( ajaxurl, args, function( data ) { refreshStyleFormats( data ); } );
});
$('#SnS_classes_mce_classes, #SnS_classes_mce_element, #SnS_classes_mce_title').keypress(function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
$("#sns-ajax-update-dropdown").click();
}
});
/*
* Expects return data.
*/
$('#delete-mce-dropdown-names').on( "click", ".sns-ajax-delete", function( event ){
event.preventDefault();
$(this).next().show();
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_delete_class';
args.delete = $( this ).attr( 'id' );
$.post( ajaxurl, args, function( data ) { refreshStyleFormats( data ); } );
});
/*
* Expects return data.
*/
$('#sns-ajax-add-shortcode').click(function( event ){
event.preventDefault();
$(this).next().show();
$(currentCodeMirror).each(function (){ this.save(); });
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_shortcodes';
args.subaction = 'add';
args.name = $( '#SnS_shortcodes' ).val();
args.shortcode = $( '#SnS_shortcodes_new' ).val();
$.post( ajaxurl, args, function( data ) { refreshShortcodes( data ); } );
});
$('#SnS_shortcodes').keypress(function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
$("#sns-ajax-add-shortcode").click();
}
});
$('#sns-shortcodes').on( "click", ".sns-ajax-delete-shortcode", function( event ){
event.preventDefault();
if($(this).data('lock'))return;else $(this).data('lock',true);
$(this).next().show();
$(currentCodeMirror).each(function (){ this.save(); });
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_shortcodes';
args.subaction = 'delete';
args.name = $( this ).parent().siblings('textarea').attr( 'data-sns-shortcode-key' );
$.post( ajaxurl, args, function( data ) { refreshShortcodes( data ); } );
});
$('#sns-shortcodes').on( "click", ".sns-ajax-update-shortcode", function( event ){
event.preventDefault();
$(this).next().show();
$(currentCodeMirror).each(function (){ this.save(); });
var args = { _ajax_nonce: nonce, post_id: $( '#post_ID' ).val(), };
args.action = 'sns_shortcodes';
args.subaction = 'update';
args.name = $( this ).parent().siblings('textarea').attr( 'data-sns-shortcode-key' );
args.shortcode = $( this ).parent().siblings('textarea').val();
$.post( ajaxurl, args, function( data ) { refreshShortcodes( data ); } );
});
/*
* Returns the body_class of TinyMCE minus the Scripts n Styles values.
*/
function getMCEBodyClasses() {
var t = [],
a = [],
b = [],
c = [];
if ( gutenMCE.body_class ) {
b = gutenMCE.body_class.trim().split( ' ' );
}
$( keys ).each( function( index, element ) {
var data = initDatas[element];
if ( data.body_class ) {
t = data.body_class.split( ' ' );
}
var bc = $( '#SnS_classes_body' ).val().split( ' ' ),
pc = $( '#SnS_classes_post' ).val().split( ' ' ),
p;
for ( var i = 0; i < t.length; i++ ) {
p = $.inArray( bc[i], t );
if ( -1 != p ) {
t.splice( p, 1 );
}
}
for ( var i = 0; i < t.length; i++ ) {
p = $.inArray( pc[i], t );
if ( -1 != p ) {
t.splice( p, 1 );
}
}
t = t.join( ' ' );
a[element] = t;
});
c = a.concat( b );
return c;
}
/*
* Builds and Adds the DOM for AJAX functionality.
*/
function setupAjaxUI() {
// set up ajax ui. (need to come up with a better ID naming scheme.)
$('#SnS_scripts-tab').append(
'<div class="sns-ajax-wrap">'
+ '<a id="sns-ajax-update-scripts" href="#" class="button">Update Scripts</a>'
+ ' '
+ '<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>'
+ '</div>'
);
$('#SnS_html-tab').append(
'<div class="sns-ajax-wrap">'
+ '<a id="sns-ajax-update-html" href="#" class="button">Update HTML</a>'
+ ' '
+ '<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>'
+ '</div>'
);
$('#SnS_styles-tab').append(
'<div class="sns-ajax-wrap">'
+ '<a id="sns-ajax-update-styles" href="#" class="button">Update Styles</a>'
+ ' '
+ '<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>'
+ '</div>'
);
$('#sns-classes').append(
'<div class="sns-ajax-wrap">'
+ '<a id="sns-ajax-update-classes" href="#" class="button">Update Classes</a>'
+ ' '
+ '<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>'
+ '</div>'
);
$('#add-mce-dropdown-names').append(
'<div class="sns-ajax-wrap">'
+ '<a id="sns-ajax-update-dropdown" href="#" class="button">Add Class</a>'
+ ' '
+ '<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>'
+ '</div>'
);
$('#SnS_shortcodes').after(
' &nbsp; '
+ '<a id="sns-ajax-add-shortcode" href="#" class="button">Add New</a>'
+ ' '
+ '<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>'
);
$('#sns-shortcodes .sns-shortcode .inside').append(
'<div class="sns-ajax-wrap">'
+ '<a class="sns-ajax-delete-shortcode button" href="#">Delete</a>'
+ ' &nbsp; '
+ '<a class="sns-ajax-update-shortcode button" href="#">Update</a>'
+ ' '
+ '<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>'
+ '</div>'
);
$( '.sns-ajax-loading' ).hide();
if ( $( '#SnS_classes_mce_type').val() == 'block' ) {
$('#add-mce-dropdown-names .sns-mce-wrapper').show();
} else {
$('#add-mce-dropdown-names .sns-mce-wrapper').hide();
}
$( '#SnS_classes_mce_type' ).change(function() {
if ( $(this).val() == 'block' ) {
$('#add-mce-dropdown-names .sns-mce-wrapper').show();
} else {
$('#add-mce-dropdown-names .sns-mce-wrapper').hide();
}
});
$( '.wp-tab-bar li', context ).show();
}
/*
* Main Tab Switch Handler.
*/
function onTabSwitch( event ) {
event.preventDefault();
clearCodeMirrors();
/*
* There is a weird bug where if clearCodeMirrors() is called right before
* loadCodeMirrors(), loading the page with the Styles tab active, and
* then switching to the Script tab, you can lose data from the second
* CodeMirror if leaving and returning to that tab. I've no idea what's
* going on there. Leaving code inbetween them is a fraggle, but working,
* workaround. Maybe has to do with execution time? No idea.
*/
// switch active classes
$( '.wp-tab-active', context ).removeClass( 'wp-tab-active' );
$( this ).parent( 'li' ).addClass( 'wp-tab-active' );
$( '.wp-tabs-panel-active', context ).hide().removeClass( 'wp-tabs-panel-active' );
$( $( this ).attr( 'href' ) ).show().addClass( 'wp-tabs-panel-active' );
loadCodeMirrors();
$.post( ajaxurl, {
action: 'sns_update_tab',
_ajax_nonce: nonce,
active_tab: $( '.wp-tab-bar li', context ).index( $( this ).parent( 'li' ).get(0) )
}
);
}
/*
* CodeMirror Utilities.
*/
function clearCodeMirrors() {
$(currentCodeMirror).each(function (){
this.toTextArea();
});
currentCodeMirror = [];
}
function refreshCodeMirrors() {
$(currentCodeMirror).each( function(){
this.refresh();
});
}
function loadCodeMirrors() {
// collect codemirrors
var settings;
// loop codemirrors
$( '.wp-tabs-panel-active textarea.codemirror', context ).each(function (){
if ( $(this).hasClass( 'js' ) )
settings = {
mode: "text/javascript",
theme: theme,
lineNumbers: true,
tabMode: "shift",
indentUnit: 4,
indentWithTabs: true
};
else if ( $(this).hasClass( 'html' ) )
settings = {
mode: "text/html",
theme: theme,
lineNumbers: true,
tabMode: "shift",
indentUnit: 4,
indentWithTabs: true
};
else if ( $(this).hasClass( 'css' ) )
settings = {
mode: "text/css",
theme: theme,
lineNumbers: true,
tabMode: "shift",
indentUnit: 4,
indentWithTabs: true
};
else if ( $(this).hasClass( 'less' ) )
settings = {
mode: "text/x-less",
theme: theme,
lineNumbers: true,
tabMode: "shift",
indentUnit: 4,
indentWithTabs: true,
};
else if ( $(this).hasClass( 'htmlmixed' ) )
settings = {
mode: "text/html",
theme: theme,
lineNumbers: true,
tabMode: "shift",
indentUnit: 4,
indentWithTabs: true,
enterMode: "keep",
matchBrackets: true
};
/*else if ( $(this).hasClass( 'php' ) )
settings = {
mode: "application/x-httpd-php",
lineNumbers: true,
tabMode: "shift",
indentUnit: 4,
indentWithTabs: true,
enterMode: "keep",
matchBrackets: true
};*/
else
return;
// initialize and store active codemirrors
currentCodeMirror.push( CodeMirror.fromTextArea( this, settings ) );
});
}
/*
* Refresh after AJAX.
*/
function refreshDeleteBtns() {
// responsible for clearing out Delete Buttons, and Adding new ones.
// initData should always contain the latest settings.
var formats = [];
$(keys).each(function(index, key) {
var initData = initDatas[key]
if ( initData.style_formats && initData.style_formats.length ) {
formats = initData.style_formats;
}
});
if ( gutenMCE.style_formats && gutenMCE.style_formats.length ) {
formats = gutenMCE.style_formats;
}
if ( ! formats.length ) {
$( '#delete-mce-dropdown-names', context ).hide();
return;
}
$( '#delete-mce-dropdown-names .sns-ajax-delete-p' ).remove();
$( '#delete-mce-dropdown-names', context ).show();
for ( var i = 0; i < formats.length; i++ ) {
var deleteBtn = {};
if ( formats[i].inline ) {
deleteBtn.element = formats[i].inline;
deleteBtn.wrapper = '';
} else if ( formats[i].block ) {
deleteBtn.element = formats[i].block;
if ( formats[i].wrapper )
deleteBtn.wrapper = ' (wrapper)';
else
deleteBtn.wrapper = '';
} else if ( formats[i].selector ) {
deleteBtn.element = formats[i].selector;
deleteBtn.wrapper = '';
} else {
console.log( 'ERROR!' );
}
deleteBtn.title = formats[i].title;
deleteBtn.classes = formats[i].classes;
$( '#instructions-mce-dropdown-names', context ).after(
'<p class="sns-ajax-delete-p"><a title="delete" class="sns-ajax-delete" id="'
+ deleteBtn.title + '">X</a> "'
+ deleteBtn.title + '" <code>&lt;'
+ deleteBtn.element + ' class="'
+ deleteBtn.classes + '"&gt;</code>'
+ deleteBtn.wrapper + '</p>'
);
}
}
function refreshBodyClass( data ) {
$(keys).each(function(index, key) {
initDatas[key].body_class = mceBodyClass[key] + ' ' + data.classes_body + ' ' + data.classes_post;
});
refreshMCE();
}
function refreshStyleFormats( data ) {
var initData = false;
$(keys).each(function(index, key) {
initData = initDatas[key];
});
if ( ! initData && gutenMCE ) {
initData = gutenMCE;
}
// error check
//console.log(data.classes_mce);
if ( typeof data.classes_mce === 'undefined' ) {
console.log( data );
/*$( '.sns-ajax-loading' ).hide();
return;*/ // Don't block
} else if ( data.classes_mce.length && data.classes_mce != 'Empty' ) {
var style_formats = [];
for ( var i = 0; i < data.classes_mce.length; i++ ) { // loop returned classes_mce
var format = {};
format.title = data.classes_mce[i].title;
if ( data.classes_mce[i].inline )
format.inline = data.classes_mce[i].inline;
else if ( data.classes_mce[i].block ) {
format.block = data.classes_mce[i].block;
if (data.classes_mce[i].wrapper)
format.wrapper = true;
} else if ( data.classes_mce[i].selector )
format.selector = data.classes_mce[i].selector;
else
console.log('dropdown format has bad type.');
format.classes = data.classes_mce[i].classes;
style_formats.push( format );
}
if ( initData ) {
initData.style_formats = style_formats;
if ( initData.toolbar2.indexOf( "styleselect" ) == -1 ) {
var tempString = "styleselect,";
initData.toolbar2 = tempString.concat(initData.toolbar2);
}
}
$( '#delete-mce-dropdown-names', context ).show();
} else {
if ( initData ) {
delete initData.style_formats;
initData.toolbar2 = initData.toolbar2.replace("styleselect,", "");
}
$( '#delete-mce-dropdown-names', context ).hide();
}
refreshDeleteBtns();
refreshMCE();
}
if ( 0 == $( '.sns-shortcode', '#sns-shortcodes' ).length )
$( 'h4', '#sns-shortcodes' ).hide();
function refreshShortcodes( data ) {
if ( data.code ) {
switch ( data.code ) {
case 2:
console.log( data.message );
break;
case 3:
$( 'textarea[data-sns-shortcode-key=' + data.message + ']', '#sns-shortcodes' ).closest('.sns-shortcode').slideUp(function(){
$(this).remove();
if ( 0 == $( '.sns-shortcode', '#sns-shortcodes' ).length )
$( 'h4', '#sns-shortcodes' ).slideUp();
});
break;
}
} else {
if ( 0 == data.indexOf( "<" ) ) {
$('#sns-shortcodes-wrap').prepend( data ).find( '.widget' ).hide().slideDown();
$( '.codemirror-new' ).parent().prepend( '<span class="sns-collapsed-shortcode-btn"></span>' );
var codemirrorNew = $( '.codemirror-new' ).removeClass('codemirror-new').addClass('codemirror').get(0);
currentCodeMirror.push( CodeMirror.fromTextArea( codemirrorNew, {
mode: "text/html",
theme: theme,
lineNumbers: true,
tabMode: "shift",
indentUnit: 4,
indentWithTabs: true,
enterMode: "keep",
matchBrackets: true
} ) );
if ( 0 == $( 'h4', '#sns-shortcodes' ).length )
$( '#sns-shortcodes' ).prepend('<h4>Existing Codes: </h4>');
if ( ! $( 'h4', '#sns-shortcodes' ).is( ":visible" ) )
$( 'h4', '#sns-shortcodes' ).slideDown();
clearCodeMirrors();
$('#SnS_shortcodes').val('');
$('#SnS_shortcodes_new').val('');
loadCodeMirrors();
} else if ( 0 == data.indexOf( "empty value." ) ) {
console.log('empty value');
} else if ( 0 == data.indexOf( "Use delete instead." ) ) {
console.log('Use delete instead');
} else {
console.log( 'Scripts n Styles: ' + '\n\n' + 'Sorry, there was an AJAX error: (' + data + ')' + '\n\n' + 'Please use the post update button instead.' );
}
}
$( '.sns-ajax-loading' ).hide();
}
addShortcodeBtns();
function addShortcodeBtns() {
$( '.sns-shortcode > .inside > p' ).before('<span class="sns-collapsed-shortcode-btn"></span>');
$('#sns-shortcodes-wrap').on("click",'.sns-collapsed-shortcode-btn', function(event){
$(this).parent().toggleClass('sns-collapsed-shortcode');
});
$('.sns-collapsed-shortcode-btn').click();
}
function refreshMCE() {
$( tinyMCE.editors ).each( function( index, ed ){
// If Visual has been activated.
if ( ed ) {
if ( ed.isHidden() ) {
refreshMCEhelper( ed );
} else {
$('#'+ed.id+'-html').click(); // 3.3
refreshMCEhelper( ed );
$('#'+ed.id+'-tmce').click(); // 3.3
}
}
});
$( '.sns-ajax-loading' ).hide();
}
function refreshMCEhelper( ed ) {
if ( gutenMCE ) {
return;
}
ed.save();
ed.destroy();
ed.remove();
if ( initDatas[ed.id] && initDatas[ed.id].wpautop )
$('#'+ed.id).val( switchEditors.wpautop( $('#'+ed.id).val() ) );
ed = new tinymce.Editor( ed.id, initDatas[ed.id], tinymce.EditorManager );
ed.render();
ed.hide();
}
});

View File

@@ -0,0 +1,18 @@
// Options JavaScript
jQuery( document ).ready( function( $ ) {
var theme = codemirror_options.theme ? codemirror_options.theme: 'default';
var editor = CodeMirror.fromTextArea(document.getElementById("codemirror_demo"), {
lineNumbers: true,
matchBrackets: true,
mode: "application/x-httpd-php",
indentUnit: 4,
indentWithTabs: true,
enterMode: "keep",
tabMode: "shift",
theme: theme
});
$('input[name="SnS_options[cm_theme]"]').change( function(){
editor.setOption("theme", $(this).val());
});
});

View File

@@ -0,0 +1,276 @@
// Options JavaScript
jQuery( document ).ready( function( $ ) { "use strict"
var collection = []
, context = "#less_area"
, theme = _SnS_options.theme ? _SnS_options.theme: 'default'
, timeout = _SnS_options.timeout || 1000
, loaded = false
, preview = false
, compiled
, $error, $status, $form, $css
, onChange
, errorMarker, errorText, errorMirror
, config;
// Prevent keystoke compile buildup
onChange = function onChange( cm ){
$status.show();
cm.save();
if ( timeout ) {
clearTimeout( _SnS_options.theme_compiler_timer );
_SnS_options.theme_compiler_timer = setTimeout( _SnS_options.theme_compiler, timeout );
} else {
compile();
}
}
config = {
gutters: ["note-gutter", "CodeMirror-linenumbers"],
lineNumbers: true,
mode: "text/x-less",
theme: theme,
indentWithTabs: true,
tabSize: 4,
indentUnit: 4
};
CodeMirror.commands.save = function() {
$form.submit();
};
// Each "IDE"
$( ".sns-less-ide", context ).each( function() {
var $text = $('.code',this);
var ide = {
name : $text.data('file-name'),
raw : $text.data('raw'),
data : $text.val(),
$text : $text,
lines : 0,
startLine : 0,
endLine : 0,
startChars : 0,
endChars : 0,
errorLine : null,
errorText : null,
cm : CodeMirror.fromTextArea( $text.get(0), config )
};
ide.cm.on( "change", onChange );
if ( $text.parent().hasClass( 'sns-collapsed' ) )
ide.cm.toTextArea();
collection.push( ide );
});
// Collapsable
$( context ).on( "click", '.sns-collapsed-btn, .sns-collapsed-btn + label', function( event ){
var $this = $( this )
, collapsed
, fileName
, thisIDE;
$this.parent().toggleClass( 'sns-collapsed' );
fileName = $this.siblings( '.code' ).data( 'file-name' );
collapsed = $this.parent().hasClass( 'sns-collapsed' );
$(collection).each(function(index, element) {
if ( element.name == fileName )
thisIDE = element;
});
if ( collapsed ) {
thisIDE.cm.toTextArea();
} else {
thisIDE.cm = CodeMirror.fromTextArea( thisIDE.$text.get(0), config );
thisIDE.cm.on( "change", onChange );
}
$.post( ajaxurl,
{ action: 'sns_open_theme_panels'
, _ajax_nonce: $( '#_wpnonce' ).val()
, 'file-name': fileName
, 'collapsed': collapsed ? 'yes' : 'no'
}
);
});
$( '#css_area' ).on( "click", '.sns-collapsed-btn, .sns-collapsed-btn + label', function( event ){
var $this = $( this ).parent();
$this.toggleClass( 'sns-collapsed' );
preview = ! $this.hasClass( 'sns-collapsed' );
if ( preview )
compiled = createCSSEditor();
else
compiled.toTextArea();
});
$( '.single-status' ).hide();
$( '.sns-ajax-loading' ).hide();
// Load
$( context ).on( "click", ".sns-ajax-load", function( event ){
event.preventDefault();
$( this ).nextAll( '.sns-ajax-loading' ).show();
var name = $( this ).parent().prevAll( '.code' ).data( 'file-name' );
$( collection ).each( function( index, element ){
if ( element.name == name ) {
element.cm.setValue( element.raw );
return;
}
});
compile();
$( '.sns-ajax-loading' ).hide();
$( this ).nextAll( '.single-status' )
.show().delay(3000).fadeOut()
.children('.settings-error').text( 'Original Source File Loaded.' );
});
// Save
$( context ).on( "click", ".sns-ajax-save", function( event ){
event.preventDefault();
$( this ).nextAll( '.sns-ajax-loading' ).show();
$form.submit();
});
function saved( data ) {
$(data).insertAfter( '#icon-sns + h2' ).delay(3000).fadeOut();
$( '.sns-ajax-loading' ).hide();
}
// The CSS output side.
$css = $( '.css', "#css_area" );
if ( preview ) {
compiled = createCSSEditor();
}
$error = $( "#compiled_error" );
$status = $( "#compile_status" );
// Start.
compile();
loaded = true;
$form = $( "#less_area" ).closest( 'form' );
$form.submit( function( event ){
event.preventDefault();
compile();
$.ajax({
type: "POST",
url: window.location,
data: $(this).serialize()+'&ajaxsubmit=1',
cache: false,
success: saved
});
});
function createCSSEditor() {
return CodeMirror.fromTextArea(
$css.get(0),
{ lineNumbers: true, mode: "css", theme: theme, indentWithTabs: true, tabSize: 4, indentUnit: 4 }
);
}
function compile() {
var lessValue = '';
var totalLines = 0;
var totalChars = 0;
var compiledValue;
$( collection ).each(function(){
//this.cm.save();
lessValue += "\n" + this.$text.val();
this.lines = this.cm.lineCount();
this.startLine = totalLines;
totalLines += this.lines;
this.endLine = totalLines;
this.chars = this.$text.val().length + 1;
this.startChars = totalChars;
totalChars += this.chars;
this.endChars = totalChars;
});
var parser = new( less.Parser )({});
parser.parse( lessValue, function ( err, tree ) {
if ( err ){
doError( err );
} else {
try {
$error.hide();
if ( preview ) {
$( compiled.getWrapperElement() ).show();
compiledValue = tree.toCSS();
compiled.setValue( compiledValue );
compiled.save();
compiled.refresh();
} else {
compiledValue = tree.toCSS({ compress: true });
$css.val( compiledValue );
}
clearCompileError();
}
catch ( err ) {
doError( err );
}
}
});
clearTimeout( _SnS_options.theme_compiler_timer );
$status.hide();
}
function doError( err ) {
var pos, token, start, end, errLine, fileName, errMessage, errIndex;
errLine = err.line-1;
errorMirror = null;
$( collection ).each(function( i ){
if ( this.startLine <= errLine && errLine < this.endLine ) {
errorMirror = this.cm;
errLine = errLine - this.startLine -1;
fileName = this.name;
errIndex = err.index - this.startChars;
return;
}
});
if ( preview )
$( compiled.getWrapperElement()).hide();
var errMessage = '';
errMessage = " &nbsp; <em>LESS " + err.type +" Error</em> on line " + ( errLine + 1 ) + " of " + fileName + ". <br />" + err.message + "</p>";
if ( loaded ) {
$error
.removeClass( 'error' )
.addClass( 'updated' )
.show()
.html( "<p><strong>Warning:</strong>" + errMessage + "</p>" );
} else {
$error
.show()
.html( "<p><strong>Error: &nbsp; </strong>" + errMessage + "</p>" );
}
clearCompileError();
if (!errorMirror) return;
errorMarker = errorMirror.setGutterMarker( errLine, 'note-gutter', $('<span></span>').addClass('cm-error').css('marginLeft','4px').text('✖').get(0) );
//errorMirror.addLineClass( errLine, "wrap", cm-error" );
pos = errorMirror.posFromIndex( errIndex );
token = errorMirror.getTokenAt( pos );
start = errorMirror.posFromIndex( errIndex - 1 );
end = errorMirror.posFromIndex( errIndex + token.string.length - 1 );
errorText = errorMirror.markText( start, end, { className: "cm-error" } );
if ( preview ) {
//compiled.setValue( "" );
//compiled.save();
//compiled.refresh();
}
}
function clearCompileError() {
if ( errorMarker ) {
$( collection ).each(function( i ){
this.cm.clearGutter( 'note-gutter' );
});
//errorMirror.removeLineClass( errLine, "wrap", "cm-error" );
errorMarker = false;
}
if ( errorText ) {
errorText.clear();
errorText = false;
}
}
_SnS_options.theme_compiler = compile;
});

View File

@@ -0,0 +1,398 @@
# Copyright (C) 2010 Scripts n Styles
# This file is distributed under the same license as the Scripts n Styles package.
msgid ""
msgstr ""
"Project-Id-Version: Scripts n Styles 3.0\n"
"Report-Msgid-Bugs-To: http://wordpress.org/tag/scripts-n-styles\n"
"POT-Creation-Date: 2011-12-09 20:46:53+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
#. #-#-#-#-# plugin.pot (Scripts n Styles 3.0) #-#-#-#-#
#. Plugin Name of the plugin/theme
#: includes/class.SnS_Admin_Meta_Box.php:97
#: includes/class.SnS_Settings_Page.php:22
#: includes/class.SnS_Usage_Page.php:22 includes/class.SnS_Global_Page.php:18
#: includes/class.SnS_Global_Page.php:20 includes/class.SnS_Admin.php:64
#: includes/class.SnS_Admin.php:67 includes/class.SnS_Admin.php:70
#: includes/class.SnS_Admin.php:106 includes/class.SnS_Admin.php:126
msgid "Scripts n Styles"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:133
#: includes/class.SnS_List_Usage.php:23
msgid "Scripts"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:134
#: includes/class.SnS_List_Usage.php:34
msgid "Styles"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:135
#: includes/class.SnS_Admin_Meta_Box.php:156
msgid "Classes"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:136
msgid "Include Scripts"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:140
msgid ""
"This code will be included <strong>verbatim</strong> in <code>&lt;script></"
"code> tags at the end of your page's (or post's)"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:141
msgid "<strong>Scripts</strong> (for the <code>head</code> element):"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:143
#: includes/class.SnS_Admin_Meta_Box.php:146
msgid "tag"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:150
msgid "<strong>Styles</strong>:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:152
msgid ""
"This code will be included <strong>verbatim</strong> in <code>&lt;style></"
"code> tags in the <code>&lt;head></code> tag of your page (or post)."
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:159
msgid "<strong>Body Classes</strong>:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:162
#: includes/class.SnS_Admin_Meta_Box.php:168
msgid "Standard:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:170
msgid ""
"These <strong>space separated</strong> class names will be added to the "
"<code>body_class()</code> or <code>post_class()</code> function (provided "
"your theme uses these functions)."
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:179
msgid "The Styles Dropdown"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:181
msgid "Add (or update) a class for the \"Styles\" drop-down:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:183
msgid "Title:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:188
msgid "Type:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:190
msgctxt "css type"
msgid "Inline"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:191
msgctxt "css type"
msgid "Block"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:192
msgctxt "css type"
msgid "Selector:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:196
msgid "Element:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:201
msgid "Classes:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:206
msgid "Wrapper:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:212
msgid "Classes currently in the dropdown:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:232
msgid "Currently Enqueued Scripts:"
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:236
msgid ""
"The chosen scripts will be enqueued and placed before your codes if your "
"code is dependant on certain scripts (like jQuery)."
msgstr ""
#: includes/class.SnS_Admin_Meta_Box.php:247
msgid "(plus others once saved.)"
msgstr ""
#: includes/class.SnS_Settings_Page.php:22 includes/class.SnS_Admin.php:91
#: includes/class.SnS_Admin.php:202
msgid "Settings"
msgstr ""
#: includes/class.SnS_Settings_Page.php:77
msgid "Scripts n Styles Settings"
msgstr ""
#: includes/class.SnS_Settings_Page.php:83
msgid "<strong>Menu Position</strong>: "
msgstr ""
#: includes/class.SnS_Settings_Page.php:97
msgid "<strong>CodeMirror Theme</strong>: "
msgstr ""
#: includes/class.SnS_Settings_Page.php:111
msgid "<strong>Hide Metabox by default</strong>: "
msgstr ""
#: includes/class.SnS_Settings_Page.php:120
msgid "Hide Metabox by default"
msgstr ""
#: includes/class.SnS_Settings_Page.php:121
msgid ""
"<span class=\"description\" style=\"max-width: 500px; display: inline-block;"
"\">This is overridable via Screen Options on each edit screen.</span>"
msgstr ""
#: includes/class.SnS_Settings_Page.php:126
msgid "Code Mirror Demo"
msgstr ""
#: includes/class.SnS_Settings_Page.php:138
msgid ""
"Control how and where Scripts n Styles menus and metaboxes appear. These "
"options are here because sometimes users really care about this stuff. Feel "
"free to adjust to your liking. :-)"
msgstr ""
#: includes/class.SnS_List_Usage.php:20
msgid "Scripts (head)"
msgstr ""
#: includes/class.SnS_List_Usage.php:26
msgid "Enqueued Scripts"
msgstr ""
#: includes/class.SnS_List_Usage.php:31
msgid "TinyMCE Formats"
msgstr ""
#: includes/class.SnS_List_Usage.php:37
msgid "Post Classes"
msgstr ""
#: includes/class.SnS_List_Usage.php:40
msgid "Body Classes"
msgstr ""
#: includes/class.SnS_List_Usage.php:50
msgid "Edit &#8220;%s&#8221;"
msgstr ""
#: includes/class.SnS_List_Usage.php:53
msgid "Edit"
msgstr ""
#: includes/class.SnS_List_Usage.php:75
msgid "Title"
msgstr ""
#: includes/class.SnS_List_Usage.php:76
msgid "ID"
msgstr ""
#: includes/class.SnS_List_Usage.php:77
msgid "Status"
msgstr ""
#: includes/class.SnS_List_Usage.php:78
msgid "Post Type"
msgstr ""
#: includes/class.SnS_List_Usage.php:79
msgid "Script Data"
msgstr ""
#: includes/class.SnS_List_Usage.php:80
msgid "Style Data"
msgstr ""
#: includes/class.SnS_List_Usage.php:133
msgid "Password protected"
msgstr ""
#: includes/class.SnS_List_Usage.php:135
msgid "Private"
msgstr ""
#: includes/class.SnS_List_Usage.php:137
msgid "Draft"
msgstr ""
#. translators: post state
#: includes/class.SnS_List_Usage.php:140
msgctxt "post state"
msgid "Pending"
msgstr ""
#: includes/class.SnS_List_Usage.php:142
msgid "Sticky"
msgstr ""
#: includes/class.SnS_Usage_Page.php:22 includes/class.SnS_Admin.php:92
msgid "Usage"
msgstr ""
#: includes/class.SnS_Usage_Page.php:47
msgid "Per Page"
msgstr ""
#: includes/class.SnS_Usage_Page.php:54
msgid "Scripts n Styles Usage"
msgstr ""
#: includes/class.SnS_Usage_Page.php:78
msgid "The following table shows content that utilizes Scripts n Styles."
msgstr ""
#: includes/class.SnS_Global_Page.php:17 includes/class.SnS_Admin.php:90
msgid "Global"
msgstr ""
#: includes/class.SnS_Global_Page.php:53
msgid "Global Scripts n Styles"
msgstr ""
#: includes/class.SnS_Global_Page.php:59
msgid "<strong>Scripts:</strong> "
msgstr ""
#: includes/class.SnS_Global_Page.php:70
msgid ""
"<span class=\"description\" style=\"max-width: 500px; display: inline-block;"
"\">The \"Scripts\" will be included <strong>verbatim</strong> in <code>&lt;"
"script></code> tags at the bottom of the <code>&lt;body></code> element of "
"your html.</span>"
msgstr ""
#: includes/class.SnS_Global_Page.php:74
msgid "<strong>Styles:</strong> "
msgstr ""
#: includes/class.SnS_Global_Page.php:85
msgid ""
"<span class=\"description\" style=\"max-width: 500px; display: inline-block;"
"\">The \"Styles\" will be included <strong>verbatim</strong> in <code>&lt;"
"style></code> tags in the <code>&lt;head></code> element of your html.</span>"
msgstr ""
#: includes/class.SnS_Global_Page.php:89
msgid "<strong>Scripts</strong><br />(for the <code>head</code> element): "
msgstr ""
#: includes/class.SnS_Global_Page.php:100
msgid ""
"<span class=\"description\" style=\"max-width: 500px; display: inline-block;"
"\">The \"Scripts (in head)\" will be included <strong>verbatim</strong> in "
"<code>&lt;script></code> tags in the <code>&lt;head></code> element of your "
"html.</span>"
msgstr ""
#: includes/class.SnS_Global_Page.php:104
msgid "<strong>Enqueue Scripts</strong>: "
msgstr ""
#: includes/class.SnS_Global_Page.php:115
msgid "Currently Enqueued Scripts: "
msgstr ""
#: includes/class.SnS_Global_Page.php:126
msgid ""
"Code entered here will be included in <em>every page (and post) of your "
"site</em>, including the homepage and archives. The code will appear "
"<strong>before</strong> Scripts and Styles registered individually."
msgstr ""
#: includes/class.SnS_Form.php:105
msgid "Cheatin&#8217; uh?"
msgstr ""
#: includes/class.SnS_Form.php:108 includes/class.SnS_Form.php:135
msgid "Settings saved."
msgstr ""
#: includes/class.SnS_Admin.php:109 includes/class.SnS_Admin.php:129
msgid ""
"<p>In default (non MultiSite) WordPress installs, both <em>Administrators</"
"em> and \r\n"
"\t\t\t\t\t\t<em>Editors</em> can access <em>Scripts-n-Styles</em> on "
"individual edit screens. \r\n"
"\t\t\t\t\t\tOnly <em>Administrators</em> can access this Options Page. In "
"MultiSite WordPress installs, only \r\n"
"\t\t\t\t\t\t<em>\"Super Admin\"</em> users can access either\r\n"
"\t\t\t\t\t\t<em>Scripts-n-Styles</em> on individual edit screens or this "
"Options Page. If other plugins change \r\n"
"\t\t\t\t\t\tcapabilities (specifically \"unfiltered_html\"), \r\n"
"\t\t\t\t\t\tother users can be granted access.</p>"
msgstr ""
#: includes/class.SnS_Admin.php:119
msgid "For more information:"
msgstr ""
#: includes/class.SnS_Admin.php:120
msgid ""
"<a href=\"http://wordpress.org/extend/plugins/scripts-n-styles/faq/\" target="
"\"_blank\">Frequently Asked Questions</a>"
msgstr ""
#: includes/class.SnS_Admin.php:121
msgid ""
"<a href=\"https://github.com/unFocus/Scripts-n-Styles\" target=\"_blank"
"\">Source on github</a>"
msgstr ""
#: includes/class.SnS_Admin.php:122
msgid ""
"<a href=\"http://wordpress.org/tags/scripts-n-styles\" target=\"_blank"
"\">Support Forums</a>"
msgstr ""
#. Plugin URI of the plugin/theme
msgid "http://www.unfocus.com/projects/scripts-n-styles/"
msgstr ""
#. Description of the plugin/theme
msgid ""
"Allows WordPress admin users the ability to add custom CSS and JavaScript "
"directly to individual Post, Pages or custom post types."
msgstr ""
#. Author of the plugin/theme
msgid "unFocus Projects"
msgstr ""
#. Author URI of the plugin/theme
msgid "http://www.unfocus.com/"
msgstr ""

View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@@ -0,0 +1,527 @@
<?php
/*
Plugin Name: Scripts n Styles
Plugin URI: http://www.unfocus.com/projects/scripts-n-styles/
Description: Allows WordPress admin users the ability to add custom CSS and JavaScript directly to individual Post, Pages or custom post types.
Author: unFocus Projects
Author URI: http://www.unfocus.com/
Version: 3.5.1
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Text Domain: scripts-n-styles
Domain Path: /languages
*/
/* The Scripts n Styles WordPress Plugin
Copyright (c) 2010-2019 Kenneth Newman <http://www.unfocus.com/>
Copyright (c) 2012 Kevin Newman <http://www.unfocus.com/>
Copyright (c) 2012-2013 adcSTUDIO LLC <http://www.adcstudio.com/>
Scripts n Styles is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
Scripts n Styles is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This file incorporates work covered by other licenses and permissions.
*/
if ( version_compare( PHP_VERSION, '5.4', '<' ) ) :
function sns_disable_update( $value ) {
if( isset( $value->response[plugin_basename( __FILE__ )] ) ) {
unset( $value->response[plugin_basename( __FILE__ )] );
}
return $value;
}
add_filter( 'site_transient_update_plugins', 'sns_disable_update' );
endif;
/**
* Scripts n Styles
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*
* NOTE: No user except the "Super Admin" can use this plugin in MultiSite. I'll add features for MultiSite later, perhaps the ones below...
* The "Super Admin" user has exclusive 'unfiltered_html' capabilities in MultiSite. Also, options.php checks for is_super_admin()
* so the 'manage_options' capability for blog admins is insufficient to pass the check to manage options directly.
*
* The Tentative plan is for Super Admins to create Snippets or Shortcodes approved for use by users with certain capabilities
* ('unfiltered_html' and/or 'manage_options'). The 'unfiltered_html' capability can be granted via another plugin. This plugin will
* not deal with granting any capabilities.
*
* @package Scripts_n_Styles
* @link http://www.unfocus.com/projects/scripts-n-styles/ Plugin URI
* @author unFocus Projects
* @link http://www.unfocus.com/ Author URI
* @version 3.5.1
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright Copyright (c) 2010 - 2019, Kenneth Newman
* @copyright Copyright (c) 2012, Kevin Newman
* @copyright Copyright (c) 2012 - 2013, adcSTUDIO LLC
*
* @todo Create ability to add and register scripts and styles for enqueueing (via Options page).
* @todo Create selection on Option page of which to pick registered scripts to make available on edit screens.
* @todo Create shortcode registration on Options page to make those snippets available on edit screens.
* @todo Add Error messaging.
* @todo Clean up tiny_mce_before_init in SnS_Admin_Meta_Box.
*/
class Scripts_n_Styles
{
/**#@+
* @static
*/
const VERSION = '3.5.1';
static $file = __FILE__;
static $cm_themes = array( 'default', '3024-day', '3024-night', 'ambiance',
'base16-dark', 'base16-light',
'blackboard', 'cobalt', 'eclipse',
'elegant', 'erlang-dark', 'lesser-dark', 'midnight', 'monokai',
'neat', 'night', 'paraiso-dark', 'paraiso-light', 'rubyblue',
'solarized', 'the-matrix', 'tomorrow-night-eighties', 'twilight', 'vibrant-ink',
'xq-dark', 'xq-light' );
/**#@-*/
/**
* Initializing method. Checks if is_admin() and registers action hooks for admin if true. Sets filters and actions for Theme side functions.
* @static
*/
static function init() {
if ( is_admin() && ! ( defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML ) ) {
/* NOTE: Setting the DISALLOW_UNFILTERED_HTML constant to
true in the wp-config.php would effectively disable this
plugin's admin because no user would have the capability.
*/
include_once( 'includes/class-sns-admin.php' );
SnS_Admin::init();
}
//register_theme_directory( WP_PLUGIN_DIR . "/" . basename( dirname( __FILE__ ) ) . '/theme/' );
add_action( 'plugins_loaded', array( __CLASS__, 'upgrade_check' ) );
add_filter( 'body_class', array( __CLASS__, 'body_classes' ) );
add_filter( 'post_class', array( __CLASS__, 'post_classes' ) );
add_action( 'wp_head', array( __CLASS__, 'styles' ), 11 );
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 11 );
add_action( 'wp_head', array( __CLASS__, 'scripts_in_head' ), 11 );
add_action( 'wp_footer', array( __CLASS__, 'scripts' ), 11 );
add_action( 'wp_head', array( __CLASS__, 'html_in_head' ), 11 );
add_action( 'wp_footer', array( __CLASS__, 'html_in_footer' ), 11 );
add_action( 'plugins_loaded', array( __CLASS__, 'add_shortcodes' ) );
add_action( 'widgets_init', array( __CLASS__, 'add_widget' ) );
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register' ) );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'register' ) );
add_action( 'wp_print_styles', array( __CLASS__, 'theme_style' ) );
add_action( 'wp_ajax_sns_theme_css', array( __CLASS__, 'theme_css' ) );
add_action( 'wp_ajax_nopriv_sns_theme_css', array( __CLASS__, 'theme_css' ) );
}
static function theme_style() {
if ( current_theme_supports( 'scripts-n-styles' ) ) {
$options = get_option( 'SnS_options' );
$slug = get_stylesheet();
if ( ! empty( $options[ 'themes' ][ $slug ][ 'compiled' ] ) ) {
wp_deregister_style( 'theme_style' );
wp_enqueue_style( 'theme_style', add_query_arg( array( 'action' => 'sns_theme_css' ), admin_url( "admin-ajax.php" ) ) );
}
}
}
static function theme_css() {
$options = get_option( 'SnS_options' );
$slug = get_stylesheet();
$compiled = $options[ 'themes' ][ $slug ][ 'compiled' ];
header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + 864000 ) . ' GMT');
header("Cache-Control: public, max-age=864000");
header('Content-Type: text/css; charset=UTF-8');
echo $compiled;
die();
}
static function add_widget() {
$options = get_option( 'SnS_options' );
if ( isset( $options[ 'hoops_widget' ] ) && 'yes' == $options[ 'hoops_widget' ] )
register_widget( 'SnS_Widget' );
}
static function add_shortcodes() {
add_shortcode( 'sns_shortcode', array( __CLASS__, 'shortcode' ) );
add_shortcode( 'hoops', array( __CLASS__, 'shortcode' ) );
}
static function shortcode( $atts, $content = null, $tag ) {
global $post;
extract( shortcode_atts( array( 'name' => 0, ), $atts ) );
$output = '';
$options = get_option( 'SnS_options' );
$hoops = isset( $options['hoops']['shortcodes'] ) ? $options['hoops']['shortcodes'] : array();
if ( isset( $post->ID ) ) {
$SnS = get_post_meta( $post->ID, '_SnS', true );
$shortcodes = isset( $SnS['shortcodes'] ) ? $SnS[ 'shortcodes' ]: array();
}
if ( isset( $shortcodes[ $name ] ) )
$output .= $shortcodes[ $name ];
else if ( isset( $hoops[ $name ] ) )
$output .= $hoops[ $name ];
if ( ! empty( $content ) && empty( $output ) )
$output = $content;
$output = do_shortcode( $output );
return $output;
}
static function hoops_widget( $atts, $content = null, $tag ) {
$options = get_option( 'SnS_options' );
$hoops = $options['hoops']['shortcodes'];
extract( shortcode_atts( array( 'name' => 0, ), $atts ) );
$output = '';
$shortcodes = isset( $SnS['shortcodes'] ) ? $SnS[ 'shortcodes' ]: array();
if ( isset( $hoops[ $name ] ) )
$output .= $hoops[ $name ];
if ( ! empty( $content ) && empty( $output ) )
$output = $content;
$output = do_shortcode( $output );
return $output;
}
/**
* Utility Method
*/
static function get_wp_registered() {
/* This is a collection of scripts that are listed as registered after running `wp_head` and `wp_footer` actions on the theme side. */
return array(
'utils', 'common', 'sack', 'quicktags', 'colorpicker', 'editor', 'wp-fullscreen', 'wp-ajax-response', 'wp-pointer', 'autosave',
'heartbeat', 'wp-auth-check', 'wp-lists', 'prototype', 'scriptaculous-root', 'scriptaculous-builder', 'scriptaculous-dragdrop',
'scriptaculous-effects', 'scriptaculous-slider', 'scriptaculous-sound', 'scriptaculous-controls', 'scriptaculous', 'cropper',
'jquery', 'jquery-core', 'jquery-migrate', 'jquery-ui-core', 'jquery-effects-core', 'jquery-effects-blind', 'jquery-effects-bounce',
'jquery-effects-clip', 'jquery-effects-drop', 'jquery-effects-explode', 'jquery-effects-fade', 'jquery-effects-fold',
'jquery-effects-highlight', 'jquery-effects-pulsate', 'jquery-effects-scale', 'jquery-effects-shake', 'jquery-effects-slide',
'jquery-effects-transfer', 'jquery-ui-accordion', 'jquery-ui-autocomplete', 'jquery-ui-button', 'jquery-ui-datepicker',
'jquery-ui-dialog', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-menu', 'jquery-ui-mouse', 'jquery-ui-position',
'jquery-ui-progressbar', 'jquery-ui-resizable', 'jquery-ui-selectable', 'jquery-ui-slider', 'jquery-ui-sortable',
'jquery-ui-spinner', 'jquery-ui-tabs', 'jquery-ui-tooltip', 'jquery-ui-widget', 'jquery-form', 'jquery-color', 'suggest',
'schedule', 'jquery-query', 'jquery-serialize-object', 'jquery-hotkeys', 'jquery-table-hotkeys', 'jquery-touch-punch',
'jquery-masonry', 'thickbox', 'jcrop', 'swfobject', 'plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight',
'plupload-html4', 'plupload-all', 'plupload-handlers', 'wp-plupload', 'swfupload', 'swfupload-swfobject', 'swfupload-queue',
'swfupload-speed', 'swfupload-all', 'swfupload-handlers', 'comment-reply', 'json2', 'underscore', 'backbone', 'wp-util',
'wp-backbone', 'revisions', 'imgareaselect', 'mediaelement', 'wp-mediaelement', 'password-strength-meter', 'user-profile',
'user-suggest', 'admin-bar', 'wplink', 'wpdialogs', 'wpdialogs-popup', 'word-count', 'media-upload', 'hoverIntent', 'customize-base',
'customize-loader', 'customize-preview', 'customize-controls', 'accordion', 'shortcode', 'media-models', 'media-views',
'media-editor', 'mce-view', 'less.js', 'coffeescript', 'chosen', 'coffeelint', 'mustache', 'html5shiv', 'html5shiv-printshiv',
'google-diff-match-patch', 'sns-codemirror'
);
}
static function register() {
$dir = plugins_url( '/', __FILE__);
$vendor = $dir . 'vendor/';
wp_register_script( 'less.js', $vendor . 'less.min.js', array(), '1.4.2-min' );
wp_register_script( 'coffeescript', $vendor . 'coffee-script.js', array(), '1.6.3-min' );
wp_register_script( 'chosen', $vendor . 'chosen/chosen.jquery.min.js', array( 'jquery' ), '1.0.0', true );
wp_register_style( 'chosen', $vendor . 'chosen/chosen.min.css', array(), '1.0.0' );
//wp_register_script( 'coffeelint', $vendor . 'coffeelint.js', array(), '0.5.6' );
//wp_register_script( 'mustache', $vendor . 'chosen/jquery.mustache.min.js', array( 'jquery' ), '0.7.2', true );
//wp_register_script( 'html5shiv', $vendor . 'html5shiv.js', array(), '3.6.2' );
//wp_register_script( 'html5shiv-printshiv', $vendor . 'html5shiv-printshiv.js', array(), '3.6.2' );
//wp_register_script( 'google-diff-match-patch', $vendor . 'codemirror/diff_match_patch.js', array() );
wp_register_script( 'sns-codemirror', $vendor . 'codemirror/codemirror-compressed.js', array( /*'google-diff-match-patch'*/ ), '3.16' );
wp_register_style( 'sns-codemirror', $vendor . 'codemirror/codemirror-compressed.css', array(), '3.16' );
$js = $dir . 'js/';
wp_register_script( 'sns-global-page', $js . 'global-page.js', array( 'jquery', 'sns-codemirror', 'less.js', 'coffeescript', 'chosen' ), self::VERSION, true );
wp_register_script( 'sns-theme-page', $js . 'theme-page.js', array( 'jquery', 'sns-codemirror', 'less.js', ), self::VERSION, true );
wp_register_script( 'sns-hoops-page', $js . 'hoops-page.js', array( 'jquery', 'sns-codemirror' ), self::VERSION, true );
wp_register_script( 'sns-settings-page', $js . 'settings-page.js', array( 'jquery', 'sns-codemirror' ), self::VERSION, true );
wp_register_script( 'sns-meta-box', $js . 'meta-box.js', array( 'editor', 'jquery-ui-tabs', 'sns-codemirror', 'chosen' ), self::VERSION, true );
wp_register_script( 'sns-code-editor', $js . 'code-editor.js', array( 'editor', 'jquery-ui-tabs', 'sns-codemirror' ), self::VERSION, true );
$css = $dir . 'css/';
wp_register_style( 'sns-options', $css . 'options-styles.css', array( 'sns-codemirror' ), self::VERSION );
wp_register_style( 'sns-meta-box', $css . 'meta-box.css', array( 'sns-codemirror' ), self::VERSION );
wp_register_style( 'sns-code-editor', $css . 'code-editor.css', array( 'sns-codemirror' ), self::VERSION );
}
/**
* Theme Action: 'wp_head()'
* Outputs the globally and individually set Styles in the Theme's head element.
*/
static function styles() {
// Global
$options = get_option( 'SnS_options' );
if ( ! empty( $options ) && ! empty( $options[ 'styles' ] ) ) {
echo '<style type="text/css" id="sns_global_styles">';
echo $options[ 'styles' ];
echo '</style>';
}
if ( ! empty( $options ) && ! empty( $options[ 'compiled' ] ) ) {
echo '<style type="text/css" id="sns_global_less_compiled">';
echo $options[ 'compiled' ];
echo '</style>';
}
if ( ! is_singular() ) return;
// Individual
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
if ( ! empty( $styles ) && ! empty( $styles[ 'styles' ] ) ) {
echo '<style type="text/css" id="sns_styles">';
echo $styles[ 'styles' ];
echo '</style>';
}
}
/**
* Theme Action: 'wp_footer()'
* Outputs the globally and individually set Scripts at the end of the Theme's body element.
*/
static function scripts() {
// Global
$options = get_option( 'SnS_options' );
if ( ! empty( $options ) && ! empty( $options[ 'scripts' ] ) ) {
echo '<script type="text/javascript" id="sns_global_scripts">';
echo $options[ 'scripts' ];
echo '</script>';
}
if ( ! empty( $options ) && ! empty( $options[ 'coffee_compiled' ] ) ) {
echo '<script type="text/javascript" id="sns_global_coffee_compiled">';
echo $options[ 'coffee_compiled' ];
echo '</script>';
}
if ( ! is_singular() ) return;
// Individual
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts' ] ) ) {
echo '<script type="text/javascript" id="sns_scripts">';
echo $scripts[ 'scripts' ];
echo '</script>';
}
}
/**
* Theme Action: 'wp_head()'
* Outputs the globally and individually set Scripts in the Theme's head element.
*/
static function scripts_in_head() {
// Global
$options = get_option( 'SnS_options' );
if ( ! empty( $options ) && ! empty( $options[ 'scripts_in_head' ] ) ) {
echo '<script type="text/javascript" id="sns_global_scripts_in_head">';
echo $options[ 'scripts_in_head' ];
echo '</script>';
}
if ( ! is_singular() ) return;
// Individual
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
if ( ! empty( $scripts ) && ! empty( $scripts[ 'scripts_in_head' ] ) ) {
echo '<script type="text/javascript" id="sns_scripts_in_head">';
echo $scripts[ 'scripts_in_head' ];
echo '</script>';
}
}
/**
* Theme Action: 'wp_head()'
* Outputs the globally and individually set HTML in the Theme's head element.
*/
static function html_in_head() {
// Global
$options = get_option( 'SnS_options' );
if ( ! empty( $options ) && ! empty( $options[ 'html_in_head' ] ) ) {
echo $options[ 'html_in_head' ];
}
if ( ! is_singular() ) return;
// Individual
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$html = isset( $SnS['html'] ) ? $SnS[ 'html' ]: array();
if ( ! empty( $html ) && ! empty( $html[ 'html_in_head' ] ) ) {
echo $html[ 'html_in_head' ];
}
}
/**
* Theme Action: 'wp_footer()'
* Outputs the globally and individually set Scripts at the end of the Theme's body element.
*/
static function html_in_footer() {
// Global
$options = get_option( 'SnS_options' );
if ( ! empty( $options ) && ! empty( $options[ 'html_in_footer' ] ) ) {
echo $options[ 'html_in_footer' ];
}
if ( ! is_singular() ) return;
// Individual
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$html = isset( $SnS['html'] ) ? $SnS[ 'html' ]: array();
if ( ! empty( $html ) && ! empty( $html[ 'html_in_footer' ] ) ) {
echo $html[ 'html_in_footer' ];
}
}
/**
* Theme Filter: 'body_class()'
* Adds classes to the Theme's body tag.
* @uses self::get_styles()
* @param array $classes
* @return array $classes
*/
static function body_classes( $classes ) {
if ( ! is_singular() || is_admin() ) return $classes;
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
if ( ! empty( $styles ) && ! empty( $styles[ 'classes_body' ] ) )
$classes = array_merge( $classes, explode( " ", $styles[ 'classes_body' ] ) );
return $classes;
}
/**
* Theme Filter: 'post_class()'
* Adds classes to the Theme's post container.
* @param array $classes
* @return array $classes
*/
static function post_classes( $classes ) {
if ( ! is_singular() || is_admin() ) return $classes;
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
if ( ! empty( $styles ) && ! empty( $styles[ 'classes_post' ] ) )
$classes = array_merge( $classes, explode( " ", $styles[ 'classes_post' ] ) );
return $classes;
}
/**
* Theme Action: 'wp_enqueue_scripts'
* Enqueues chosen Scripts.
*/
static function enqueue_scripts() {
// Global
$options = get_option( 'SnS_options' );
if ( ! isset( $options[ 'enqueue_scripts' ] ) )
$enqueue_scripts = array();
else
$enqueue_scripts = $options[ 'enqueue_scripts' ];
foreach ( $enqueue_scripts as $handle )
wp_enqueue_script( $handle );
if ( ! is_singular() ) return;
// Individual
global $post;
$SnS = get_post_meta( $post->ID, '_SnS', true );
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
foreach ( $scripts[ 'enqueue_scripts' ] as $handle )
wp_enqueue_script( $handle );
}
}
/**
* Utility Method: Compares VERSION to stored 'version' value.
*/
static function upgrade_check() {
$options = get_option( 'SnS_options' );
if ( ! isset( $options[ 'version' ] ) || version_compare( self::VERSION, $options[ 'version' ], '>' ) ) {
include_once( 'includes/class-sns-admin.php' );
SnS_Admin::upgrade();
}
}
}
Scripts_n_Styles::init();
class SnS_Widget extends WP_Widget
{
function __construct() {
$widget_ops = array( 'classname' => 'sns_widget_text', 'description' => __( 'Arbitrary text or HTML (including "hoops" shortcodes)', 'scripts-n-styles' ) );
$control_ops = array( 'width' => 400, 'height' => 350 );
parent::__construct( 'sns_hoops', __( 'Hoops', 'scripts-n-styles' ), $widget_ops, $control_ops );
}
function widget( $args, $instance ) {
global $shortcode_tags;
extract( $args );
$title = apply_filters( 'widget_title', empty( $instance[ 'title' ] ) ? '' : $instance[ 'title' ], $instance, $this->id_base );
$text = apply_filters( 'widget_text', empty( $instance[ 'text' ] ) ? '' : $instance[ 'text' ], $instance );
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
echo '<div class="hoopstextwidget">';
$content = ! empty( $instance[ 'filter' ] ) ? wpautop( $text ) : $text;
$backup = $shortcode_tags;
remove_all_shortcodes();
add_shortcode( 'sns_shortcode', array( 'Scripts_n_Styles', 'hoops_widget' ) );
add_shortcode( 'hoops', array( 'Scripts_n_Styles', 'hoops_widget' ) );
$content = do_shortcode( $content );
$shortcode_tags = $backup;
echo $content;
echo '</div>';
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
if ( current_user_can( 'unfiltered_html' ) )
$instance[ 'text' ] = $new_instance[ 'text' ];
else
$instance[ 'text' ] = stripslashes( wp_filter_post_kses( addslashes( $new_instance[ 'text' ] ) ) ); // wp_filter_post_kses() expects slashed
$instance[ 'filter' ] = isset( $new_instance[ 'filter' ] );
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
$title = strip_tags( $instance[ 'title' ] );
$text = esc_textarea( $instance[ 'text' ] );
?>
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p>
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>"><?php echo $text; ?></textarea>
<p><input id="<?php echo $this->get_field_id( 'filter' ); ?>" name="<?php echo $this->get_field_name( 'filter' ); ?>" type="checkbox" <?php checked( isset( $instance[ 'filter' ] ) ? $instance[ 'filter' ] : 0 ); ?> />&nbsp;<label for="<?php echo $this->get_field_id( 'filter' ); ?>"><?php _e( 'Automatically add paragraphs' ); ?></label></p>
<?php
}
}

View File

@@ -0,0 +1,26 @@
<?php
if( ! defined( 'ABSPATH' ) || ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit();
$options = get_option( 'SnS_options' );
if ( empty($options['delete_data_uninstall']) || 'yes' !== $options['delete_data_uninstall'] ) {
return;
}
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => 'any',
'post_status' => 'any',
'orderby' => 'ID',
'meta_key' => '_SnS'
) );
foreach( $posts as $post)
delete_post_meta( $post->ID, '_SnS' );
delete_option( 'SnS_options' );
$users = get_users( 'meta_key=current_sns_tab' );
foreach( $users as $user ) delete_user_option( $user->ID, 'current_sns_tab', true );
$users = get_users( 'meta_key=scripts_n_styles_page_sns_usage_per_page' );
foreach( $users as $user ) delete_user_option( $user->ID, 'scripts_n_styles_page_sns_usage_per_page', true );
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 B

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long