Skip to:
Content

BuddyPress.org

Changeset 102


Ignore:
Timestamp:
05/13/2008 04:15:35 PM (18 years ago)
Author:
jbasdf
Message:

added drag and drop ordering to xprofile fields

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-friends.php

    r57 r102  
    11<?php
    2 
    3 add_site_option('bp-friends-version', '0.1');
    4 
     2$bp_friends_table_name = $wpdb->base_prefix . 'bp_friends';
     3define('BP_FRIENDS_VERSION', '0.2');
     4       
    55/**************************************************************************
    66 friends_install()
     
    99 **************************************************************************/
    1010
    11 function friends_install() {
    12         global $wpdb, $table_name;
    13 
    14         $sql = "CREATE TABLE ". $table_name ." (
    15                                 id mediumint(9) NOT NULL AUTO_INCREMENT,
    16                                 initiator_user_id mediumint(9) NOT NULL,
    17                                 friend_user_id mediumint(9) NOT NULL,
    18                                 is_confirmed bool DEFAULT 0,
    19                                 date_created int(11) NOT NULL,
    20                     UNIQUE KEY id (id)
     11function friends_install( $version ) {
     12        global $wpdb, $bp_friends_table_name;
     13
     14        $sql = array();                 
     15                       
     16        $sql[] = "CREATE TABLE `". $bp_friends_table_name ."` (
     17                                `id` mediumint(9) NOT NULL AUTO_INCREMENT,
     18                                `initiator_user_id` mediumint(9) NOT NULL,
     19                                `friend_user_id` mediumint(9) NOT NULL,
     20                                `is_confirmed` bool DEFAULT 0,
     21                                `date_created` int(11) NOT NULL,
     22                    UNIQUE KEY id (`id`)
    2123                 );";
    2224
    2325        require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    2426        dbDelta($sql);
     27       
     28        add_site_option('bp-friends-version', $version);
    2529}
    2630
     
    3438
    3539function friends_add_menu() {   
    36         global $wpdb, $table_name, $bp_friends, $userdata;
    37         $table_name = $wpdb->base_prefix . "bp_friends";
     40        global $wpdb, $bp_friends_table_name, $bp_friends, $userdata;
    3841       
    3942        if ( $wpdb->blogid == $userdata->primary_blog ) {
     43                add_menu_page( __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_list" );
     44                add_submenu_page( basename(__FILE__), __("My Friends"), __("My Friends"), 1, basename(__FILE__), "friends_list" );
     45                add_submenu_page( basename(__FILE__), __("Friend Finder"), __("Friend Finder"), 1, "friend_finder", "friends_find" );   
     46
    4047                /* Instantiate bp_Friends class to do the real work. */
    4148                $bp_friends = new BP_Friends;
    4249                $bp_friends->bp_friends();
    43        
    44                 add_menu_page( __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_list" );
    45                 add_submenu_page( basename(__FILE__), __("My Friends"), __("My Friends"), 1, basename(__FILE__), "friends_list" );
    46                 add_submenu_page( basename(__FILE__), __("Friend Finder"), __("Friend Finder"), 1, "friend_finder", "friends_find" );   
    47 
     50               
    4851                /* Add the administration tab under the "Site Admin" tab for site administrators */
    4952                add_submenu_page( 'wpmu-admin.php', __("Friends"), __("Friends"), 1, basename(__FILE__), "friends_settings" );
    5053        }
    51        
     54
    5255        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    53         if ( $wpdb->get_var("show tables like '%" . $table_name . "%'") == false )
    54                 friends_install();
     56        if ( ( $wpdb->get_var("show tables like '%" . $bp_friends_table_name . "%'") == false ) || ( get_site_option('bp-friends-version') < BP_FRIENDS_VERSION )  )
     57                friends_install(BP_FRIENDS_VERSION);
     58               
    5559}
    5660add_action( 'admin_menu','friends_add_menu' );
     
    9397        function bp_friends()
    9498        {
    95                 global $wpdb, $userdata, $table_name;
     99                global $wpdb, $userdata, $bp_friends_table_name;
    96100                 
    97101                $this->wpdb = &$wpdb;
    98102                $this->userdata = &$userdata;
    99103                $this->basePrefix = $wpdb->base_prefix;
    100                 $this->tableName = $table_name; // need a root prefix, not a wp_X_ prefix.
    101104                $this->imageBase = get_option('siteurl') . '/wp-content/mu-plugins/bp_friends/images/';
    102105               
     
    220223         get_friends()
    221224         
     225         Get a list of friends for the current user using the current, internal
     226         user id.
     227         **************************************************************************/   
     228         
     229        function get_friend_list()
     230        {
     231                return $this->get_friends($this->userdata->ID);
     232        }
     233       
     234       
     235        /**************************************************************************
     236         get_friends()
     237         
    222238         Get a list of friends for the current user.
    223239         **************************************************************************/   
     
    225241        function get_friends($id)
    226242        {
     243                global $bp_friends_table_name;
     244               
    227245                if(bp_core_validate($id))
    228246                {
    229247                        $sql = "SELECT initiator_user_id, friend_user_id
    230                                         FROM " . $this->tableName . "
     248                                        FROM " . $bp_friends_table_name . "
    231249                                        WHERE initiator_user_id = " . $id . "
    232250                                        OR friend_user_id = " . $id . "
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r101 r102  
    4949                <?php }
    5050               
    51                 if ( $groups ) {
     51                if ( $groups ) { ?>
     52                        <script type="text/javascript" charset="utf-8">
     53                                jQuery(document).ready(function(){ <?php
     54                                for ( $i = 0; $i < count($groups); $i++ ) { ?>
     55                                        jQuery('#group_<?php echo $groups[$i]->id;?>').tableDnD( {
     56                                                        onDrop: function(table, row) {
     57                                        var field_ids = jQuery.tableDnD.serialize();
     58                                                                reorderFields(table, row, field_ids);
     59                                            }
     60                                  });
     61                                <?php } ?>
     62                                });                                     
     63                        </script>
     64                       
     65                        <?php if ( function_exists('wp_nonce_field') )
     66                                wp_nonce_field('xprofile_reorder_fields');
     67                       
    5268                        for ( $i = 0; $i < count($groups); $i++ ) {
    5369                        ?>
    54                                 <script type="text/javascript" charset="utf-8">
    55                                         jQuery(document).ready(function(){
    56                                                 jQuery('#<?php echo $groups[$i]->name;?>').tableDnD({
    57                                                         onDrop: function(table, row) {
    58                                         var order = jQuery.tableDnD.serialize();
    59                                             }
    60                                     });
    61                                         });                                     
    62                                 </script>
    63                                 <p>
    64                                 <table id="<?php echo $groups[$i]->name; ?>" class="widefat">
     70                                <p>
     71                                <table id="group_<?php echo $groups[$i]->id;?>" class="widefat">
    6572                                        <thead>
    6673                                            <tr class="nodrag">
     
    8693                                                            <?php if ( !$field->can_delete ) { $class .= ' core'; } ?>
    8794                                                       
    88                                                                         <tr<?php echo ' class="' . $class . '"'; ?>>
     95                                                                        <tr id="field_<?php echo $field->id; ?>" <?php if ( $class ) { echo 'class="' . $class . '"'; } ?>>
    8996                                                                <td><span title="<?php echo $field->desc; ?>"><?php echo $field->name; ?> <?php if(!$field->can_delete) { ?>(Core)<?php } ?></span></td>
    9097                                                                <td><?php echo $field->type; ?></td>
     
    100107                                                        </tr>
    101108                                                <?php } ?>
    102                                                         <tr>
     109                                                        <tr class="nodrag">
    103110                                                                <td colspan="6"><a href="admin.php?page=xprofile_settings&amp;group_id=<?php echo $groups[$i]->id; ?>&amp;mode=add_field">Add New Field</a></td>
    104111                                                        </tr>
  • trunk/bp-xprofile/bp-xprofile-cssjs.php

    r101 r102  
    366366                                jQuery('#v2_h').val(dimensions.height);
    367367                        }
     368                       
     369                        function reorderFields(table, row, field_ids) {
     370                                var ajaxurl = '<?php echo get_option('siteurl') . "/wp-admin/admin-ajax.php"; ?>';
     371                                jQuery.post( ajaxurl, {
     372                                        action: 'xprofile_reorder_fields',
     373                                        'cookie': encodeURIComponent(document.cookie),
     374                                        '_wpnonce': jQuery("input#_wpnonce").val(),
     375                                        'group': table.id.split('_')[1],
     376                                        'row': row,
     377                                        'field_ids': field_ids
     378                                        },
     379                                        function(response) {
     380                                                alert(response);
     381                                        },
     382                                        1250
     383                                );
     384                        }
     385                       
    368386                        <?php } ?>
    369387                </script>
Note: See TracChangeset for help on using the changeset viewer.