Changeset 622431
- Timestamp:
- 11/08/2012 04:30:10 AM (12 years ago)
- Location:
- shortbus/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
shortbus/trunk/admin-scripts.php
r419167 r622431 2 2 <script type="text/javascript"> 3 3 4 // @todo: encapsulate 5 //var Shortbus = function() {}(); 4 var Shortbus = {}; 6 5 7 var editor; 8 var shortcode_id; 6 (function($) { 7 $(function() { 8 // initialize codemirror 9 Shortbus.editor = CodeMirror.fromTextArea(document.getElementById("shortcode-content"), { 10 mode: "php", 11 theme: "neat", 12 indentUnit: 4, 13 tabMode: "shift", 14 lineNumbers: true 15 }); 9 16 10 jQuery(function() { 17 // load 18 $(".sb-option").live("click", function() { 19 Shortbus.shortcode_id = $(this).attr("rel"); 20 $("#shortcode-response").hide(); 21 $("#sb-select-value").html($(this).html()); 22 $("#sb-select-box").removeClass("active"); 23 $("#sb-select-popup").toggle(); 24 Shortbus.editor.setValue(""); 25 var data = { 26 method: "load", 27 action: "shortbus", 28 id: $(this).attr("rel") 29 }; 30 if ("" == data.id) { 31 $("#shortcode-area").hide(); 32 $("#shortcode-intro").show(); 33 } 34 else { 35 $("#save-area").hide(); 36 $("#loading-area").show(); 37 $.post(ajaxurl, data, function(response) { 38 Shortbus.editor.setValue(response.data); 39 $("#shortcode-intro").hide(); 40 $("#shortcode-area").show(); 41 $("#loading-area").hide(); 42 $("#save-area").show(); 43 }, "json"); 44 } 45 }); 11 46 12 // initialize codemirror 13 editor = CodeMirror.fromTextArea(document.getElementById("shortcode-content"), { 14 mode: "php", 15 theme: "neat", 16 indentUnit: 4, 17 tabMode: "shift", 18 lineNumbers: true 19 }); 47 // select box 48 $("#sb-select-box").click(function() { 49 $(this).toggleClass("active"); 50 $("#sb-select-popup").toggle(); 51 }); 20 52 21 // load 22 jQuery(".sb-option").live("click", function() { 23 shortcode_id = jQuery(this).attr("rel"); 24 jQuery("#shortcode-response").hide(); 25 jQuery("#sb-select-value").html(jQuery(this).html()); 26 jQuery("#sb-select-box").removeClass("active"); 27 jQuery("#sb-select-popup").toggle(); 28 editor.setValue(""); 29 var data = { 30 method: "load", 31 action: "shortbus", 32 id: jQuery(this).attr("rel") 33 }; 34 if ("" == data.id) { 35 jQuery("#shortcode-area").hide(); 36 jQuery("#shortcode-intro").show(); 37 } 38 else { 39 jQuery("#save-area").hide(); 40 jQuery("#loading-area").show(); 41 jQuery.post(ajaxurl, data, function(response) { 42 editor.setValue(response.data); 43 jQuery("#shortcode-intro").hide(); 44 jQuery("#shortcode-area").show(); 45 jQuery("#loading-area").hide(); 46 jQuery("#save-area").show(); 53 // filter select box options 54 $("#sb-filter-input").keyup(function() { 55 var keyword = $(this).val(); 56 if ("" == keyword) { 57 $(".sb-option").show(); 58 } 59 else { 60 $(".sb-option").each(function() { 61 var html = $(this).html(); 62 var regex = new RegExp(keyword, "i"); 63 if (0 <= html.search(regex)) { 64 $(this).show(); 65 } 66 else { 67 $(this).hide(); 68 } 69 }); 70 } 71 }); 72 73 // add 74 $("#add-shortcode").click(function() { 75 var data = { 76 method: "add", 77 action: "shortbus", 78 name: $("#shortcode-name").val() 79 }; 80 81 if ("" == data.name) return; 82 $.post(ajaxurl, data, function(response) { 83 if ("ok" == response.status) { 84 Shortbus.editor.setValue(""); 85 $("#shortcode-name").val(""); 86 $("#sb-select-options").append('<div class="sb-option" rel="'+response.data.id+'">'+data.name+'</div>'); 87 $("#sb-select-value").html(data.name); 88 $("#shortcode-intro").hide(); 89 $("#shortcode-area").show(); 90 Shortbus.shortcode_id = response.data.id; 91 } 92 $("#shortcode-response").html("<p>"+response.status_message+"</p>"); 93 $("#shortcode-response").show(); 47 94 }, "json"); 48 } 49 }); 95 }); 50 96 51 // select box 52 jQuery("#sb-select-box").click(function() { 53 jQuery(this).toggleClass("active"); 54 jQuery("#sb-select-popup").toggle(); 55 }); 97 // edit 98 $("#edit-shortcode").click(function() { 99 var data = { 100 method: "edit", 101 action: "shortbus", 102 id: Shortbus.shortcode_id, 103 content: Shortbus.editor.getValue() 104 }; 105 $.post(ajaxurl, data, function(response) { 106 $("#shortcode-response").html("<p>"+response.status_message+"</p>"); 107 $("#shortcode-response").show(); 108 }, "json"); 109 }); 56 110 57 // filter select box options 58 jQuery("#sb-filter-input").keyup(function() { 59 var keyword = jQuery(this).val(); 60 if ("" == keyword) { 61 jQuery(".sb-option").show(); 62 } 63 else { 64 jQuery(".sb-option").each(function() { 65 var html = jQuery(this).html(); 66 var regex = new RegExp(keyword, "i"); 67 if (0 <= html.search(regex)) { 68 jQuery(this).show(); 111 // delete 112 $("#delete-shortcode").click(function() { 113 if (confirm("Are you sure you want to delete this shortcode?")) { 114 var data = { 115 method: "delete", 116 action: "shortbus", 117 id: Shortbus.shortcode_id 118 }; 119 $.post(ajaxurl, data, function(response) { 120 $("#shortcode-area").hide(); 121 $("#shortcode-intro").show(); 122 $("#sb-select-value").html("Select one"); 123 $(".sb-option[rel="+Shortbus.shortcode_id+"]").remove(); 124 $("#shortcode-response").html("<p>"+response.status_message+"</p>"); 125 $("#shortcode-response").show(); 126 Shortbus.shortcode_id = null; 127 }, "json"); 128 } 129 }); 130 131 // export 132 $("#export").click(function() { 133 $("#import-area").hide(); 134 $("#export-area").toggle(); 135 }); 136 137 $("#do-export").click(function() { 138 $("#export-content").val(""); 139 var data = { method: "export", action: "shortbus" }; 140 $.post(ajaxurl, data, function(response) { 141 $("#export-content").val(response.data); 142 }, "json"); 143 }); 144 145 // import 146 $("#import").click(function() { 147 $("#export-area").hide(); 148 $("#import-area").toggle(); 149 }); 150 151 $("#do-import").click(function() { 152 var data = { 153 method: "import", 154 action: "shortbus", 155 content: $("#import-content").val(), 156 do_replace: $("#import-replace").is(":checked") ? 1 : 0 157 }; 158 $.post(ajaxurl, data, function(response) { 159 if ("error" == response.status) { 160 $("#shortcode-response").html("<p>"+response.status_message+"</p>"); 161 $("#shortcode-response").show(); 69 162 } 70 163 else { 71 jQuery(this).hide();164 ; 72 165 } 73 } );74 } 166 }); 167 } 75 168 }); 76 77 // add 78 jQuery("#add-shortcode").click(function() { 79 var data = { 80 method: "add", 81 action: "shortbus", 82 name: jQuery("#shortcode-name").val() 83 }; 84 85 if ("" == data.name) return; 86 jQuery.post(ajaxurl, data, function(response) { 87 if ("ok" == response.status) { 88 editor.setValue(""); 89 jQuery("#shortcode-name").val(""); 90 jQuery("#sb-select-options").append('<div class="sb-option" rel="'+response.data.id+'">'+data.name+'</div>'); 91 jQuery("#sb-select-value").html(data.name); 92 jQuery("#shortcode-intro").hide(); 93 jQuery("#shortcode-area").show(); 94 shortcode_id = response.data.id; 95 } 96 jQuery("#shortcode-response").html("<p>"+response.status_message+"</p>"); 97 jQuery("#shortcode-response").show(); 98 }, "json"); 99 }); 100 101 // edit 102 jQuery("#edit-shortcode").click(function() { 103 var data = { 104 method: "edit", 105 action: "shortbus", 106 id: shortcode_id, 107 content: editor.getValue() 108 }; 109 jQuery.post(ajaxurl, data, function(response) { 110 jQuery("#shortcode-response").html("<p>"+response.status_message+"</p>"); 111 jQuery("#shortcode-response").show(); 112 }, "json"); 113 }); 114 115 // delete 116 jQuery("#delete-shortcode").click(function() { 117 if (confirm("Are you sure you want to delete this shortcode?")) { 118 var data = { 119 method: "delete", 120 action: "shortbus", 121 id: shortcode_id 122 }; 123 jQuery.post(ajaxurl, data, function(response) { 124 jQuery("#shortcode-area").hide(); 125 jQuery("#shortcode-intro").show(); 126 jQuery("#sb-select-value").html("Select one"); 127 jQuery(".sb-option[rel="+shortcode_id+"]").remove(); 128 jQuery("#shortcode-response").html("<p>"+response.status_message+"</p>"); 129 jQuery("#shortcode-response").show(); 130 shortcode_id = null; 131 }, "json"); 132 } 133 }); 134 135 // export 136 jQuery("#export").click(function() { 137 jQuery("#import-area").hide(); 138 jQuery("#export-area").toggle(); 139 }); 140 141 jQuery("#do-export").click(function() { 142 jQuery("#export-content").val(""); 143 var data = { method: "export", action: "shortbus" }; 144 jQuery.post(ajaxurl, data, function(response) { 145 jQuery("#export-content").val(response.data); 146 }, "json"); 147 }); 148 149 // import 150 jQuery("#import").click(function() { 151 jQuery("#export-area").hide(); 152 jQuery("#import-area").toggle(); 153 }); 154 155 jQuery("#do-import").click(function() { 156 var data = { 157 method: "import", 158 action: "shortbus", 159 content: jQuery("#import-content").val(), 160 do_replace: jQuery("#import-replace").is(":checked") ? 1 : 0 161 }; 162 jQuery.post(ajaxurl, data, function(response) { 163 if ("error" == response.status) { 164 jQuery("#shortcode-response").html("<p>"+response.status_message+"</p>"); 165 jQuery("#shortcode-response").show(); 166 } 167 else { 168 window.location = ""; 169 } 170 }, "json"); 171 }); 172 }); 169 })(jQuery); 173 170 </script> -
shortbus/trunk/index.php
r487731 r622431 4 4 Plugin URI: http://wordpress.org/extend/plugins/shortbus/ 5 5 Description: Quickly and easily manage shortcodes. 6 Version: 1.2. 26 Version: 1.2. 7 7 Author: Matt Gibbs 8 8 Author URI: http://uproot.us/ … … 11 11 */ 12 12 13 define('SHORTBUS_VERSION', '1.2.2');14 15 13 $sb = new Shortbus(); 16 $sb->init();17 14 18 15 class Shortbus 19 16 { 20 /*--------------------------------------------------------------------------------------------- 21 * Verify the database, check plugin version, add necessary hooks 22 * 23 * @author Matt Gibbs 24 * @since 1.0 25 ---------------------------------------------------------------------------------------------*/ 17 public $version; 18 19 function __construct() { 20 $this->version = '1.2.5'; 21 $this->init(); 22 } 23 24 /*-------------------------------------------------------------------------------------- 25 * 26 * Verify the database, check plugin version, add necessary hooks 27 * 28 * @author Matt Gibbs 29 * @since 1.0.0 30 * 31 *-------------------------------------------------------------------------------------*/ 32 26 33 function init() { 27 34 global $wpdb; … … 31 38 32 39 if (false === $db_version) { 33 $wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}shortbus` ( 34 `id` int unsigned AUTO_INCREMENT PRIMARY KEY, 35 `name` varchar(128), 36 `content` mediumtext)"); 40 $wpdb->query(" 41 CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}shortbus` ( 42 `id` int unsigned AUTO_INCREMENT PRIMARY KEY, 43 `name` varchar(128), 44 `content` mediumtext)"); 37 45 38 46 // Add the version 39 add_option('shortbus_version', SHORTBUS_VERSION);40 } 41 elseif (version_compare($db_version, SHORTBUS_VERSION, '<')) {42 update_option('shortbus_version', SHORTBUS_VERSION);47 add_option('shortbus_version', ); 48 } 49 elseif (version_compare($db_version, , '<')) { 50 update_option('shortbus_version', ); 43 51 } 44 52 … … 53 61 } 54 62 55 /*--------------------------------------------------------------------------------------------- 56 * Retrieve the shortcode content 57 * 58 * @author Matt Gibbs 59 * @since 1.0 60 ---------------------------------------------------------------------------------------------*/ 63 /*-------------------------------------------------------------------------------------- 64 * 65 * Retrieve the shortcode content 66 * 67 * @author Matt Gibbs 68 * @since 1.0.0 69 * 70 *-------------------------------------------------------------------------------------*/ 71 61 72 function shortcode($atts) { 62 73 global $wpdb; … … 71 82 } 72 83 73 /*--------------------------------------------------------------------------------------------- 74 * Add the submenu under "Pages" 75 * 76 * @author Matt Gibbs 77 * @since 1.0 78 ---------------------------------------------------------------------------------------------*/ 84 /*-------------------------------------------------------------------------------------- 85 * 86 * Add the submenu under "Tools" 87 * 88 * @author Matt Gibbs 89 * @since 1.0.0 90 * 91 *-------------------------------------------------------------------------------------*/ 92 79 93 function admin_menu() { 80 94 add_submenu_page('tools.php', 'Shortcodes', 'Shortcodes', 'manage_options', 'shortbus', array($this, 'admin_page')); 81 95 } 82 96 83 /*--------------------------------------------------------------------------------------------- 84 * Standardize ajax responses 85 * 86 * @author Matt Gibbs 87 * @since 1.1.1 88 ---------------------------------------------------------------------------------------------*/ 97 /*-------------------------------------------------------------------------------------- 98 * 99 * Standardize ajax responses 100 * 101 * @author Matt Gibbs 102 * @since 1.0.0 103 * 104 *-------------------------------------------------------------------------------------*/ 105 89 106 function json_response($status = 'ok', $status_message = null, $data = null) { 90 107 if (empty($status_message)) { … … 100 117 } 101 118 102 /*--------------------------------------------------------------------------------------------- 103 * Save the shortcode data 104 * 105 * @author Matt Gibbs 106 * @since 1.0 107 ---------------------------------------------------------------------------------------------*/ 119 /*-------------------------------------------------------------------------------------- 120 * 121 * Save the shortcode data 122 * 123 * @author Matt Gibbs 124 * @since 1.0.0 125 * 126 *-------------------------------------------------------------------------------------*/ 127 108 128 function handle_ajax() { 109 129 include(WP_PLUGIN_DIR . '/shortbus/admin-ajax.php'); 110 130 } 111 131 112 /*--------------------------------------------------------------------------------------------- 113 * Add javascript to the admin header 114 * 115 * @author Matt Gibbs 116 * @since 1.0 117 ---------------------------------------------------------------------------------------------*/ 132 /*-------------------------------------------------------------------------------------- 133 * 134 * Add javascript to the admin header 135 * 136 * @author Matt Gibbs 137 * @since 1.0.0 138 * 139 *-------------------------------------------------------------------------------------*/ 140 118 141 function admin_scripts() { 119 142 if (isset($_GET['page']) && 'shortbus' == $_GET['page']) { … … 122 145 } 123 146 124 /*--------------------------------------------------------------------------------------------- 125 * Use the contextual help box 126 * 127 * @author Matt Gibbs 128 * @since 1.1.1 129 ---------------------------------------------------------------------------------------------*/ 147 /*-------------------------------------------------------------------------------------- 148 * 149 * Contextual help 150 * 151 * @author Matt Gibbs 152 * @since 1.0.0 153 * 154 *-------------------------------------------------------------------------------------*/ 155 130 156 function help_box() { 131 157 ob_start(); … … 142 168 } 143 169 144 /*--------------------------------------------------------------------------------------------- 145 * Build the shortcode management page 146 * 147 * @author Matt Gibbs 148 * @since 1.0 149 ---------------------------------------------------------------------------------------------*/ 170 /*-------------------------------------------------------------------------------------- 171 * 172 * Build the shortcode management page 173 * 174 * @author Matt Gibbs 175 * @since 1.0.0 176 * 177 *-------------------------------------------------------------------------------------*/ 178 150 179 function admin_page() { 151 180 global $wpdb; … … 170 199 <div id="sb-select-options"> 171 200 <div class="sb-option" rel="">Select one</div> 172 <?php 173 $results = $wpdb->get_results("SELECT id, name FROM `{$wpdb->prefix}shortbus` ORDER BY name ASC"); 174 foreach ($results as $result) { 175 ?> 201 <?php $results = $wpdb->get_results("SELECT id, name FROM `{$wpdb->prefix}shortbus` ORDER BY name ASC"); ?> 202 <?php foreach ($results as $result) : ?> 176 203 <div class="sb-option" rel="<?php echo $result->id; ?>"><?php echo $result->name; ?></div> 177 <?php 178 } 179 ?> 204 <?php endforeach; ?> 180 205 </div> 181 206 </div> -
shortbus/trunk/readme.txt
r487731 r622431 4 4 Tags: shortcode, shortcodes, shortcode manager, manager, posts, pages, content management 5 5 Requires at least: 3.0 6 Tested up to: 3. 3.16 Tested up to: 3. 7 7 Stable tag: trunk 8 8 9 Quickly and easily manage shortcodes. 9 Quickly and easily manage shortcodes. 10 10 11 11 == Description == … … 39 39 40 40 == Changelog == 41 42 43 44 45 41 46 42 47 = 1.2.2 =
Note: See TracChangeset
for help on using the changeset viewer.