Plugin Directory

Changeset 479547


Ignore:
Timestamp:
12/22/2011 09:32:36 PM (14 years ago)
Author:
marquex
Message:

Added some ajax methods - wpnonce and createsidebar - to the cs interface

Location:
custom-sidebars/branches/nightly
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • custom-sidebars/branches/nightly/cs.js

    r478228 r479547  
    176176       var ajaxdata = {
    177177           action: 'cs-wpnonce',
    178            nonce: 'show-create-sidebar'
     178           nonce_action: 'cs-create-sidebar',
     179           nonce_nonce: $('#_nonce_nonce').val()
    179180       };
    180        if(!$('.new-sidebar-holder').is(':visible')){
    181            $('#new-sidebar').append($('#new-sidebar-form'));
    182            $('.new-sidebar-holder').hide().detach().insertAfter('#cs-title-options').slideDown().children(".sidebar-name").click(function(){var h=$(this).siblings(".widgets-sortables"),g=$(this).parent();if(!g.hasClass("closed")){h.sortable("disable");g.addClass("closed")}else{g.removeClass("closed");h.sortable("enable").sortable("refresh")}});
    183        }
     181       $.post(ajaxurl, ajaxdata, function(response){
     182           if(!$('.new-sidebar-holder').is(':visible')){
     183               $('#_nonce_nonce').val(response.nonce_nonce);
     184               $('#_create_nonce').val(response.nonce);
     185               $('#new-sidebar').append($('#new-sidebar-form'));
     186               $('.new-sidebar-holder').hide().detach().insertAfter('#cs-title-options').slideDown().children(".sidebar-name").click(function(){var h=$(this).siblings(".widgets-sortables"),g=$(this).parent();if(!g.hasClass("closed")){h.sortable("disable");g.addClass("closed")}else{g.removeClass("closed");h.sortable("enable").sortable("refresh")}});
     187           }
     188       }, 'json');
    184189       return false;
    185190    });
     191}
     192
     193setCreateSidebar = function($){
     194   $('#cs-create-sidebar').click(function(){
     195      var ajaxdata = {
     196           action: 'cs-create-sidebar',
     197           nonce: $('#_create_nonce').val(),
     198           name: $('#sidebar_name').val(),
     199           description: $('#sidebar_description').val()
     200       };
     201       
     202       $.post(ajaxurl, ajaxdata, function(response){
     203           
     204       }, 'json');
     205     
     206      return false;
     207   });
    186208}
    187209
     
    191213    addCSControls($);
    192214    showCreateSidebar($);
     215    setCreateSidebar($);
    193216});
  • custom-sidebars/branches/nightly/customsidebars.php

    r478228 r479547  
    874874        return 1 + $this->getCategoryLevel($cat->category_parent);
    875875    }
     876       
     877        function jsonResponse($obj){
     878            header('Content-Type: application/json');
     879            echo json_encode($obj);
     880            die();
     881        }
     882       
     883        function ajaxCreateNonce(){
     884            $nonce = $_POST['nonce_nonce'];
     885            $action = $_POST['nonce_action'];
     886            if(! wp_verify_nonce($nonce, 'cs-wpnonce'))
     887                die('malo');
     888           
     889            $this->jsonResponse(array(
     890                nonce_nonce => wp_create_nonce('cs-wpnonce'),
     891                nonce => wp_create_nonce($action)
     892            ));
     893        }
     894       
     895        function ajaxCreateSidebar(){
     896            $nonce = $_POST['nonce'];
     897            if(! wp_verify_nonce($nonce, 'cs-create-sidebar'))
     898                $this->jsonResponse (array(
     899                   success => false,
     900                   message => __('The operation is not secure and it cannot be completed.','custom-sidebars')
     901                ));
     902           
     903            $this->storeSidebar();
     904           
     905            if($this->message_class == 'error')
     906                $this->jsonResponse (array(
     907                   success => false,
     908                   message => $this->message
     909                ));
     910           
     911            $this->jsonResponse (array(
     912                success => true,
     913                message => __('The sidebar has been created successfully.','custom-sidebars'),
     914                name => trim($_POST['sidebar_name']),
     915                description => trim($_POST['sidebar_description']),
     916                id => $this->sidebar_prefix . sanitize_title_with_dashes($name)
     917            ));
     918        }
    876919}
    877920endif; //exists class
     
    888931    add_action( 'init', array($plugin_sidebars,'loadTextDomain'));
    889932    add_action( 'admin_enqueue_scripts', array($plugin_sidebars,'addStyles'));
     933        //AJAX actions
     934        add_action( 'wp_ajax_cs-wpnonce', array($plugin_sidebars, 'ajaxCreateNonce'));
     935        add_action( 'wp_ajax_cs-create-sidebar', array($plugin_sidebars, 'ajaxCreateSidebar'));
     936       
    890937}
    891938if(! class_exists('CustomSidebarsEmptyPlugin')){
  • custom-sidebars/branches/nightly/view-widgets-sidebar.php

    r478228 r479547  
    2525    <div id="new-sidebar-form">
    2626        <form action="themes.php?page=customsidebars" method="post">
    27         <?php wp_nonce_field( 'custom-sidebars-new');?>
     27        <?php wp_nonce_field( 'cs-create-sidebar', '_create_nonce');?>
     28        <?php wp_nonce_field( 'cs-wpnonce', '_nonce_nonce');?>
    2829        <div id="namediv">
    2930            <label for="sidebar_name"><?php _e('Name','custom-sidebars'); ?></label>
    30             <input type="text" name="sidebar_name" size="30" tabindex="1" value="" id="link_name" />
     31            <input type="text" name="sidebar_name" size="30" tabindex="1" value="" id="sidebar_name" />
    3132            <p class="description"><?php _e('The name has to be unique.','custom-sidebars')?></p>
    3233        </div>
     
    3435        <div id="addressdiv">           
    3536            <label for="sidebar_description"><?php echo _e('Description','custom-sidebars'); ?></label>
    36             <input type="text" name="sidebar_description" size="30" class="code" tabindex="1" value="" id="link_url" />
     37            <input type="text" name="sidebar_description" size="30" class="code" tabindex="1" value="" id="sidebar_description" />
    3738        </div>
    38         <p class="submit"><input type="submit" class="button-primary" name="create-sidebars" value="<?php _e('Create Sidebar','custom-sidebars'); ?>" /></p>
     39        <p class="submit"><input type="submit" class="button-primary" id="cs-create-sidebar" name="cs-create-sidebar" value="<?php _e('Create Sidebar','custom-sidebars'); ?>" /></p>
    3940    </form>       
    4041    </div>
Note: See TracChangeset for help on using the changeset viewer.