Plugin Directory

Changeset 622431

Timestamp:
11/08/2012 04:30:10 AM (12 years ago)
Author:
logikal16
Message:

Shortcode Manager 1.2.5

Location:
shortbus/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • shortbus/trunk/admin-scripts.php

    r419167 r622431  
    22<script type="text/javascript">
    33
    4 // @todo: encapsulate
    5 //var Shortbus = function() {}();
     4var Shortbus = {};
    65
    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        });
    916
    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        });
    1146
    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        });
    2052
    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();
    4794            }, "json");
    48         }
    49     });
     95        });
    5096
    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        });
    56110
    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();
    69162                }
    70163                else {
    71                     jQuery(this).hide();
     164                    ;
    72165                }
    73             });
    74         }
     166            });
     167        }
    75168    });
    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);
    173170</script>
  • shortbus/trunk/index.php

    r487731 r622431  
    44Plugin URI: http://wordpress.org/extend/plugins/shortbus/
    55Description: Quickly and easily manage shortcodes.
    6 Version: 1.2.2
     6Version: 1.2.
    77Author: Matt Gibbs
    88Author URI: http://uproot.us/
     
    1111*/
    1212
    13 define('SHORTBUS_VERSION', '1.2.2');
    14 
    1513$sb = new Shortbus();
    16 $sb->init();
    1714
    1815class Shortbus
    1916{
    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
    2633    function init() {
    2734        global $wpdb;
     
    3138
    3239        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)");
    3745
    3846            // 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', );
    4351        }
    4452
     
    5361    }
    5462
    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
    6172    function shortcode($atts) {
    6273        global $wpdb;
     
    7182    }
    7283
    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
    7993    function admin_menu() {
    8094        add_submenu_page('tools.php', 'Shortcodes', 'Shortcodes', 'manage_options', 'shortbus', array($this, 'admin_page'));
    8195    }
    8296
    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
    89106    function json_response($status = 'ok', $status_message = null, $data = null) {
    90107        if (empty($status_message)) {
     
    100117    }
    101118
    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
    108128    function handle_ajax() {
    109129        include(WP_PLUGIN_DIR . '/shortbus/admin-ajax.php');
    110130    }
    111131
    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
    118141    function admin_scripts() {
    119142        if (isset($_GET['page']) && 'shortbus' == $_GET['page']) {
     
    122145    }
    123146
    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
    130156    function help_box() {
    131157        ob_start();
     
    142168    }
    143169
    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
    150179    function admin_page() {
    151180        global $wpdb;
     
    170199                <div id="sb-select-options">
    171200                    <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) : ?>
    176203                    <div class="sb-option" rel="<?php echo $result->id; ?>"><?php echo $result->name; ?></div>
    177 <?php
    178         }
    179 ?>
     204                    <?php endforeach; ?>
    180205                </div>
    181206            </div>
  • shortbus/trunk/readme.txt

    r487731 r622431  
    44Tags: shortcode, shortcodes, shortcode manager, manager, posts, pages, content management
    55Requires at least: 3.0
    6 Tested up to: 3.3.1
     6Tested up to: 3.
    77Stable tag: trunk
    88
    9 Quickly and easily manage shortcodes.
     9Quickly and easily manage shortcodes.
    1010
    1111== Description ==
     
    3939
    4040== Changelog ==
     41
     42
     43
     44
     45
    4146
    4247= 1.2.2 =
Note: See TracChangeset for help on using the changeset viewer.