[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Forums Deprecated Functions. 4 * 5 * This file contains all the deprecated functions for BuddyPress forums since 6 * version 1.7. This was a major update for the forums component, moving from 7 * bbPress 1.x to bbPress 2.x. 8 * 9 * @package BuddyPress 10 * @subpackage Forums 11 */ 12 13 // Exit if accessed directly. 14 defined( 'ABSPATH' ) || exit; 15 16 function bp_forums_add_admin_menu() { 17 18 if ( !is_super_admin() ) 19 return false; 20 21 $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php'; 22 23 // Add the administration tab under the "Site Admin" tab for site administrators. 24 $hook = add_submenu_page( $page, __( 'Forums (Legacy)', 'buddypress' ), __( 'Forums (Legacy)', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" ); 25 26 // Fudge the highlighted subnav item when on the BuddyPress Forums admin page. 27 add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' ); 28 } 29 add_action( bp_core_admin_hook(), 'bp_forums_add_admin_menu' ); 30 31 function bp_forums_configure_existing_install() { 32 global $wpdb, $bbdb; 33 34 check_admin_referer( 'bp_forums_existing_install_init' ); 35 36 // Sanitize $_REQUEST['bbconfigloc']. 37 $_REQUEST['bbconfigloc'] = apply_filters( 'bp_forums_bbconfig_location', $_REQUEST['bbconfigloc'] ); 38 39 if ( false === strpos( $_REQUEST['bbconfigloc'], 'bb-config.php' ) ) { 40 if ( '/' != substr( $_REQUEST['bbconfigloc'], -1, 1 ) ) 41 $_REQUEST['bbconfigloc'] .= '/'; 42 43 $_REQUEST['bbconfigloc'] .= 'bb-config.php'; 44 } 45 46 bp_update_option( 'bb-config-location', $_REQUEST['bbconfigloc'] ); 47 48 if ( !file_exists( $_REQUEST['bbconfigloc'] ) ) { 49 return false; 50 } 51 52 return true; 53 } 54 55 function bp_forums_bbpress_install( $location = '' ) { 56 global $wpdb, $bbdb; 57 58 check_admin_referer( 'bp_forums_new_install_init' ); 59 60 if ( empty( $location ) ) { 61 $location = ABSPATH . 'bb-config.php'; 62 } 63 64 $bp = buddypress(); 65 66 // Create the bb-config.php file. 67 $initial_write = bp_forums_bbpress_write( 68 $bp->plugin_dir . '/bp-forums/bbpress/bb-config-sample.php', 69 $location, 70 array( 71 "define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ), 72 "define( 'BBDB_USER'," => array( "'username'", "'" . DB_USER . "'" ), 73 "define( 'BBDB_PASSWO" => array( "'password'", "'" . DB_PASSWORD . "'" ), 74 "define( 'BBDB_HOST'," => array( "'localhost'", "'" . DB_HOST . "'" ), 75 "define( 'BBDB_CHARSE" => array( "'utf8'", "'" . DB_CHARSET . "'" ), 76 "define( 'BBDB_COLLAT" => array( "''", "'" . DB_COLLATE . "'" ), 77 "define( 'BB_AUTH_KEY" => array( "'put your unique phrase here'", "'" . addslashes( AUTH_KEY ) . "'" ), 78 "define( 'BB_SECURE_A" => array( "'put your unique phrase here'", "'" . addslashes( SECURE_AUTH_KEY ) . "'" ), 79 "define( 'BB_LOGGED_I" => array( "'put your unique phrase here'", "'" . addslashes( LOGGED_IN_KEY ) . "'" ), 80 "define( 'BB_NONCE_KE" => array( "'put your unique phrase here'", "'" . addslashes( NONCE_KEY ) . "'" ), 81 "\$bb_table_prefix = '" => array( "'bb_'", "'" . $bp->table_prefix . "bb_'" ), 82 "define( 'BB_LANG', '" => array( "''", "'" . get_locale() . "'" ) 83 ) 84 ); 85 86 // Add the custom user and usermeta entries to the config file. 87 if ( $initial_write == 1 ) { 88 $file = file_get_contents( $location ); 89 } else { 90 $file = &$initial_write; 91 } 92 93 $file = trim( $file ); 94 if ( '?>' == substr( $file, -2, 2 ) ) { 95 $file = substr( $file, 0, -2 ); 96 } 97 98 $file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';'; 99 $file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';'; 100 $file .= "\n\n" . '$bb->uri = \'' . $bp->plugin_url . '/bp-forums/bbpress/\';'; 101 $file .= "\n" . '$bb->name = \'' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';'; 102 103 if ( is_multisite() ) { 104 $file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . bp_get_root_blog_id() . ';'; 105 } 106 107 if ( defined( 'AUTH_SALT' ) ) { 108 $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');'; 109 } 110 111 if ( defined( 'LOGGED_IN_SALT' ) ) { 112 $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');'; 113 } 114 115 if ( defined( 'SECURE_AUTH_SALT' ) ) { 116 $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');'; 117 } 118 119 $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);'; 120 $file .= "\n\n" . '?>'; 121 122 if ( $initial_write == 1 ) { 123 $file_handle = fopen( $location, 'w' ); 124 fwrite( $file_handle, $file ); 125 fclose( $file_handle ); 126 } else { 127 $initial_write = $file; 128 } 129 130 bp_update_option( 'bb-config-location', $location ); 131 return $initial_write; 132 } 133 134 function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) { 135 136 if ( empty( $file_source ) || !file_exists( $file_source ) || !is_file( $file_source ) ) { 137 return -1; 138 } 139 140 if ( empty( $file_target ) ) { 141 $file_target = $file_source; 142 } 143 144 if ( empty( $alterations ) || !is_array( $alterations ) ) { 145 return -2; 146 } 147 148 // Get the existing lines in the file. 149 $lines = file( $file_source ); 150 151 // Initialise an array to store the modified lines. 152 $modified_lines = array(); 153 154 // Loop through the lines and modify them. 155 foreach ( (array) $lines as $line ) { 156 if ( isset( $alterations[substr( $line, 0, 20 )] ) ) { 157 $alteration = $alterations[substr( $line, 0, 20 )]; 158 $modified_lines[] = str_replace( $alteration[0], $alteration[1], $line ); 159 } else { 160 $modified_lines[] = $line; 161 } 162 } 163 164 $writable = true; 165 if ( file_exists( $file_target ) ) { 166 if ( !is_writable( $file_target ) ) { 167 $writable = false; 168 } 169 } else { 170 $dir_target = dirname( $file_target ); 171 172 if ( file_exists( $dir_target ) ) { 173 if ( !is_writable( $dir_target ) || !is_dir( $dir_target ) ) { 174 $writable = false; 175 } 176 } else { 177 $writable = false; 178 } 179 } 180 181 if ( empty( $writable ) ) { 182 return trim( join( null, $modified_lines ) ); 183 } 184 185 // Open the file for writing - rewrites the whole file. 186 $file_handle = fopen( $file_target, 'w' ); 187 188 // Write lines one by one to avoid OS specific newline hassles. 189 foreach ( (array) $modified_lines as $modified_line ) { 190 if ( strlen( $modified_line ) - 2 === strrpos( $modified_line, '?>' ) ) { 191 $modified_line = '?>'; 192 } 193 194 fwrite( $file_handle, $modified_line ); 195 if ( $modified_line == '?>' ) { 196 break; 197 } 198 } 199 200 // Close the config file. 201 fclose( $file_handle ); 202 203 @chmod( $file_target, 0666 ); 204 205 return 1; 206 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Dec 7 01:01:35 2017 | Cross-referenced by PHPXref 0.7.1 |