WordPress.org

Plugin Directory

Changeset 160829


Ignore:
Timestamp:
10/06/09 03:21:58 (5 years ago)
Author:
ikailo
Message:
 
Location:
wp-hive/tags/0.5
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • wp-hive/tags/0.5/admin/edit.php

    r156140 r160829  
    108108                               value="<?php echo stripslashes($current_site->host); ?>" 
    109109                               name="site_host" /></td> 
     110                    <td>Eg: <strong>example.com</strong></td> 
    110111                </tr> 
    111112                <tr valign="top"> 
     
    113114                    <td><input id="site_path" class="regular-text" type="text" 
    114115                               value="<?php echo stripslashes($current_site->path); ?>" name="site_path" /></td> 
     116                    <td>Eg: <strong>/subdirectory</strong><br/>Use <strong>/</strong> for none</td> 
    115117                </tr> 
    116118                <tr valign="top"> 
     
    119121                               value="<?php echo stripslashes($current_site->prefix); ?>" 
    120122                               name="site_prefix" /></td> 
     123                    <td>A short unique identifier, usually ends with underscore. Eg: <strong>wp_</strong></td> 
    121124                </tr> 
    122125            </tbody> 
    123126        </table> 
    124         <p class="submit"><input class="button-primary" type="submit" 
     127        <p class="submit"> 
     128            <input class="button-primary" type="submit" 
    125129                                 value="Save Changes" name="wphive_save_site" id="wphive_save_site" /> 
    126130                                     <?php if ('edit' == $action) {?> 
     
    134138                   value="Install Site" name="wphive_install_site" id="wphive_install_site" onclick="window.location='<?php echo 'http://'.$current_site->host.$current_site->path ?>';return false;"/> 
    135139                           <?php } 
    136                        } ?> 
     140                       } 
     141                       do_action('wphive_edit_buttons'); 
     142                       ?> 
    137143        </p> 
    138144    </form> 
  • wp-hive/tags/0.5/do-prefix.php

    r156140 r160829  
    77 
    88define('WPHIVE_PATH', dirname(__FILE__)); 
     9define('WPHIVE_ADDON_PATH', WPHIVE_PATH.'/add-ons'); 
    910 
    1011require_once ('includes/functions.php'); 
    1112require_once ('includes/class.wphive.php'); 
    12  
    13  
    1413 
    1514$wphive = new wphive(); 
     
    1716// Get and clean up the hostname 
    1817if (!$hostname) { 
    19     $orig_hostname = addslashes($_SERVER['HTTP_HOST']); 
     18    $orig_hostname = strtolower(addslashes($_SERVER['HTTP_HOST'])); 
    2019    $hostname = $wphive->clean_hostname($orig_hostname); 
    2120} 
    2221 
    23 // Check if the pathname has been previously defined 
    24 // If we are in wp-admin, wp-install, wp-login 
    25 // TODO: Probably need to fix for non-admin wp-logins on subdirectory sites. 
    26 if (defined('WP_ADMIN') || defined('WP_INSTALLING') || stristr($_SERVER['REQUEST_URI'], 'wp-login.php')) { 
    27     $pathname = isset ($_COOKIE['wphive_pathname']) ? addslashes($_COOKIE['wphive_pathname']) : '/'; 
     22// Get and clean up the pathname 
     23$orig_pathname = strtolower(addslashes($_SERVER['REQUEST_URI'])); 
     24$pathname = $wphive->clean_pathname($orig_pathname); 
     25 
     26// Root-Redirect Triggers 
     27if ( strpos($orig_pathname, $pathname . '/wp-admin') !== false || 
     28    strpos($orig_pathname, $pathname . '/wp-login.php') !== false ) { 
     29 
     30    wphive_set_cookie('wphive_pathname', $pathname); 
     31    $redirect = 'http://' . $orig_hostname . substr($orig_pathname, strlen($pathname)); // Strip path for redirect 
     32    wphive_redirect($redirect); 
     33    exit (0); 
    2834} 
    29 // Get and clean up the pathname 
    30 else { 
    31     $orig_pathname = addslashes($_SERVER['REQUEST_URI']); 
    32     $pathname = $wphive->clean_pathname($orig_pathname); 
    3335 
    34     // Handle wp-admin, wp-install, wp-login requests for subdirectory sites 
    35     if (stristr($orig_pathname, $pathname . '/wp-admin') || stristr($orig_pathname, $pathname . '/wp-login.php')) { 
    36         wphive_set_cookie('wphive_pathname', $pathname); // Use cookies to keep track of the site we are administering 
    37         $redirect = 'http://' . $orig_hostname . substr($orig_pathname, strlen($pathname)); 
    38         wphive_redirect($redirect); 
    39         exit (0); 
     36// Root-Redirect Passthrough 
     37if ( isset ($_COOKIE['wphive_pathname']) ) { 
     38    if( defined('WP_ADMIN') || 
     39        defined('WP_INSTALLING') || 
     40        strpos( $orig_pathname, '/wp-login.php') !== false ) { 
     41 
     42        $pathname =  addslashes($_COOKIE['wphive_pathname']); 
     43    } 
     44    else { 
     45        wphive_delete_cookie('wphive_pathname'); 
    4046    } 
    4147} 
     48 
    4249// Check if WP Hive is installed, run installation or upgrade as required. 
    4350$installed_version = $wphive->get_installed_version(); 
     
    5360    // None? Try to add one. 
    5461    if (!$possible_sites) { 
     62    // TODO: Premium Feature - Redirect to alternate site. 
    5563        wp_die("Unknown Host"); 
    5664    } else { 
     
    6674            } 
    6775        } 
    68         // if it doesn't match, assume they want the root site 
    6976        if (empty ($prefix)) { 
    70             $prefix = $root_prefix; 
    71             $pathname = '/'; 
    72             unset($orig_pathname); 
     77            if( !empty( $root_prefix ) ) { 
     78            // Assume root site 
     79                $prefix = $root_prefix; 
     80                $pathname = '/'; 
     81                unset($orig_pathname); 
     82            } 
     83            else { 
     84            // TODO: Call properly through add-on functionality 
     85                if (file_exists(WPHIVE_ADDON_PATH.'/unknown-root.php')) { 
     86                    require(WPHIVE_ADDON_PATH.'/unknown-root.php'); 
     87                } 
     88                else { 
     89                    wp_die("Unknown Host"); 
     90                } 
     91            } 
    7392        } 
    7493    } 
     
    82101 
    83102/* WP Install Override */ 
    84 // Don't clear .htaccess on subdirectory install 
     103// Prevents clearing of .htaccess on subdirectory install 
    85104if ( defined('WP_INSTALLING') && WP_INSTALLING === true && $wphive->current_site->path != '/' ) { 
    86105    function wp_install($blog_title, $user_name, $user_email, $public, $deprecated='') { 
  • wp-hive/tags/0.5/includes/class.wphive.php

    r156140 r160829  
    3232class wphive { 
    3333 
     34/** 
     35 * The version of the WP Hive package 
     36 * "PHP-standardized" version number string 
     37 * 
     38 * @package WP Hive 
     39 * @since 0.5 
     40 * @var string 
     41 */ 
     42    var $version = '0.5'; 
     43 
     44    /** 
     45     * Holds the current site object 
     46     * 
     47     * @since 0.5 
     48     * @var object 
     49     */ 
    3450    var $current_site; 
    35     var $version = '0.5'; 
     51 
    3652    /** 
    3753     * Constructor. 
     
    4965     * @package WP Hive 
    5066     * @since 0.5 
    51      * 
    5267     * @return The version of WP Hive that is installed 
    5368     */ 
     
    6378    } 
    6479 
     80    /** 
     81     * Determines if a site has subdirectories 
     82     * @package WP Hive 
     83     * @since 0.5 
     84     * 
     85     * @global $wpdb 
     86     * 
     87     * @param object $site The site to check 
     88     * 
     89     * @return boolean True if the site has subdirectories 
     90     */ 
    6591    public function site_has_subdirs( $site ) { 
    6692        global $wpdb; 
     
    159185    } 
    160186 
    161  
    162187    /** 
    163188     * Gets an array containing the site prefixes in the WP Hive database 
     
    241266        } 
    242267    } 
    243  
    244  
    245268 
    246269    /** 
     
    390413    } 
    391414 
     415    /** 
     416     * Sanitizes hostname and removes unnecessary characters 
     417     * 
     418     * @package WP Hive 
     419     * @since 0.5 
     420     * 
     421     * @param string $hostname The value to sanitize 
     422     * 
     423     * @return string Sanitized hostname 
     424     */ 
    392425    public function clean_hostname( $hostname ) { 
     426        if (substr($hostname, 0, 8) == "https://") { $hostname = substr($hostname, 8); } // Strip https:// 
    393427        if (substr($hostname, 0, 7) == "http://") { $hostname = substr($hostname, 7); } // Strip http:// 
    394428        if (substr($hostname, 0, 4) == "www.") { $hostname = substr($hostname, 4); } // Strip www 
     
    398432    } 
    399433 
     434    /** 
     435     * Sanitizes pathname and removes unnecessary characters 
     436     * 
     437     * @package WP Hive 
     438     * @since 0.5 
     439     * 
     440     * @param string $patname The value to sanitize 
     441     * 
     442     * @return string Sanitized pathname 
     443     */ 
    400444    public function clean_pathname( $pathname ) { 
    401445        $pathname = preg_replace('|([a-z0-9-]+.php.*)|', '', $pathname); // Ignore calling php file (eg: index.php) 
    402         if (substr($pathname, 0, 9) == "/wp-admin") 
    403             $pathname = '/'; // Ignore wp-admin, assume root path 
     446        if (substr($pathname, 0, 9) == "/wp-admin") { $pathname = '/'; } // Ignore wp-admin, assume root path 
    404447        $pathname = preg_replace('|(/[a-z0-9-]+?/).*|', '$1', $pathname); // Get the first subdirectory 
    405448        $pathname = "/" . trim($pathname, "/"); // Fix slashes 
     449 
    406450        return $pathname; 
    407451    } 
    408452} 
    409  
    410453?> 
  • wp-hive/tags/0.5/includes/functions.php

    r156140 r160829  
    22 
    33function wphive_force_plugin_active() { 
    4     global $wpdb, $table_prefix; 
    5     if (function_exists('apply_filters')){ 
    6         $active_plugins = get_option('active_plugins'); 
    7         $plugin_name = 'wp-hive/wp-hive.php'; 
    8         if ( !in_array($plugin_name, $active_plugins) ) { 
    9             $active_plugins[] = $plugin_name; 
    10             sort($active_plugins); 
    11             update_option('active_plugins', $active_plugins); 
    12         } 
    13     } 
    14     else { 
    15         // Too early. Gotta hack it. 
    16         // TODO: Slow. Need to use cache / better algorithm 
    17         $active_plugins = $wpdb->get_var("SELECT option_value FROM ".$table_prefix."options WHERE option_name = 'active_plugins' LIMIT 1"); 
    18         $active_plugins = unserialize($active_plugins); 
    19         if ( empty($active_plugins) ) {$active_plugins = array();} 
    20         $plugin_name = 'wp-hive/wp-hive.php'; 
    21         if ( !in_array($plugin_name, $active_plugins) ) { 
    22             $active_plugins[] = $plugin_name; 
    23             sort($active_plugins); 
    24             $active_plugins = serialize($active_plugins); 
    25             $wpdb->query( $wpdb->prepare( "UPDATE ".$table_prefix."options SET option_value = %s WHERE option_name = %s", $active_plugins, 'active_plugins' ) ); 
    26         } 
    27     } 
     4    global $wpdb, $table_prefix; 
     5    if (function_exists('apply_filters')) { 
     6        $active_plugins = get_option('active_plugins'); 
     7        $plugin_name = 'wp-hive/wp-hive.php'; 
     8        if ( !in_array($plugin_name, $active_plugins) ) { 
     9            $active_plugins[] = $plugin_name; 
     10            sort($active_plugins); 
     11            update_option('active_plugins', $active_plugins); 
     12        } 
     13    } 
     14    else { 
     15    // Too early. Gotta hack it. 
     16    // TODO: Slow. Need to use cache / better algorithm 
     17        $active_plugins = $wpdb->get_var("SELECT option_value FROM ".$table_prefix."options WHERE option_name = 'active_plugins' LIMIT 1"); 
     18        $active_plugins = unserialize($active_plugins); 
     19        if ( empty($active_plugins) ) {$active_plugins = array();} 
     20        $plugin_name = 'wp-hive/wp-hive.php'; 
     21        if ( !in_array($plugin_name, $active_plugins) ) { 
     22            $active_plugins[] = $plugin_name; 
     23            sort($active_plugins); 
     24            $active_plugins = serialize($active_plugins); 
     25            $wpdb->query( $wpdb->prepare( "UPDATE ".$table_prefix."options SET option_value = %s WHERE option_name = %s", $active_plugins, 'active_plugins' ) ); 
     26        } 
     27    } 
    2828} 
    2929 
    30 function wphive_set_cookie($name, $value, $expire = 0, $path = '/') {    
    31     setcookie($name, $value, $expire, $path); 
     30function wphive_set_cookie($name, $value, $expire = 0, $path = '/') { 
     31    setcookie($name, $value, $expire, $path); 
    3232} 
    3333 
    34 function wphive_delete_cookie($name){ 
    35     setcookie($name, ' ', time() - 31536000); 
     34function wphive_delete_cookie($name) { 
     35    setcookie($name, ' ', time() - 31536000, '/'); 
    3636} 
    3737 
    3838function wphive_redirect($location, $status = 302) { 
    39     $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location); 
    40     $strip = array('%0d', '%0a'); 
    41     $found = true; 
    42     while($found) { 
    43         $found = false; 
    44         foreach($strip as $val) { 
    45             while(strpos($location, $val) !== false) { 
    46                 $found = true; 
    47                 $location = str_replace($val, '', $location); 
    48             } 
    49         } 
    50     } 
    51      
    52     $is_IIS = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false) ? true : false; 
    53     if ( $is_IIS ) { 
     39    $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location); 
     40    $strip = array('%0d', '%0a'); 
     41    $found = true; 
     42    while($found) { 
     43        $found = false; 
     44        foreach($strip as $val) { 
     45            while(strpos($location, $val) !== false) { 
     46                $found = true; 
     47                $location = str_replace($val, '', $location); 
     48            } 
     49        } 
     50    } 
    5451 
    55         header("Refresh: 0;url=$location"); 
    56     } else { 
    57         if ( php_sapi_name() != 'cgi-fcgi' ) { 
    58             status_header($status); // This causes problems on IIS and some FastCGI setups 
    59         } 
    60         header("Location: $location"); 
    61     } 
     52    $is_IIS = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false) ? true : false; 
     53    if ( $is_IIS ) { 
     54 
     55        header("Refresh: 0;url=$location"); 
     56    } else { 
     57        if ( php_sapi_name() != 'cgi-fcgi' ) { 
     58            status_header($status); // This causes problems on IIS and some FastCGI setups 
     59        } 
     60        header("Location: $location"); 
     61    } 
    6262} 
    6363 
     
    7474        $wpdb->suppress_errors($suppress); 
    7575        if (empty ($home)) { 
     76        //FIXME: orig_hostname not defined 
    7677            $siteurl = substr($orig_hostname, 0, 4) == "www." ? 'http://www.' . $hostname : 'http://' . $hostname; 
    7778            $siteurl .= $pathname == "/" ? '' : $pathname; 
     
    136137    return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password, 'password_message' => $message); 
    137138} 
    138  
    139139?> 
  • wp-hive/tags/0.5/wp-hive.php

    r156140 r160829  
    99 Author URI: http://wp-hive.com 
    1010 */ 
     11 
     12do_action('wphive_loading_plugin'); 
    1113 
    1214/* 
     
    5254 
    5355 
    54 /* Trying to sort out wp-admin confusion, when logging into subdirectories. */ 
    55 // Probably doesn't work 
    56 if ( isset($_COOKIE['wphive_pathname']) ) { 
    57     if ( isset($_REQUEST['clearwphive']) && $_REQUEST['clearwphive'] == 'true') { 
    58         function wphive_return_login_root() { 
    59             wphive_remove_site_cookie(); 
    60             wp_redirect('http://'.$_SERVER['HTTP_HOST'].'/wp-login.php'); // TODO: Parse target url 
    61         } 
    62         add_action('init', 'wphive_return_login_root'); 
    63     } 
    64     else { 
     56function wphive_login_notices() { 
     57/* Trying to sort out wp-admin confusion, when logging into subdirectories, because path is not in browser url. */ 
     58    if ( isset($_COOKIE['wphive_pathname']) ) { 
     59         
    6560        function wphive_login_name($message) { 
    66             return '<p class="message">' . sprintf('Logging into %s', get_bloginfo('title', 'display' )) . ' | <a href="wp-login.php?clearwphive=true">Login to root site</a></p>'; 
    67         // TODO: Redirect with GET url 
     61            return '<p class="message">' . sprintf('Logging into %s', get_bloginfo('title', 'display' )). '</p>'; 
    6862        } 
    6963        add_filter('login_message', 'wphive_login_name' ); 
     64 
    7065        function wphive_admin_name() { 
    71             echo "<div id='wphive-warning' class='updated fade'><p>".sprintf('WP Hive Notice: Administrating %s', get_bloginfo('title', 'display' )).". <a href='".wp_logout_url()."'>Log out</a> to administer root site.</a></p></div>"; 
     66            echo "<div id='wphive-warning' class='updated fade'><p>".sprintf('Administrating %s', get_bloginfo('title', 'display' )).".</p></div>"; 
    7267        } 
    7368        add_action('admin_notices', 'wphive_admin_name'); 
     69 
    7470    } 
    7571} 
     72wphive_login_notices(); 
    7673 
    77 /* Cookies */ 
     74/* Fix Meta URLs */ 
     75function wphive_meta_url($meta_url) { 
     76    global $wphive; 
     77    $pathname = $wphive->current_site->path; 
     78    if ('/' != $pathname) { 
     79        $link = str_replace(get_option('siteurl'), get_option('home'), $meta_url); 
     80        return str_replace($pathname.$pathname, $pathname, $link); 
     81    } 
     82    return $meta_url; 
     83} 
     84add_filter('login_url', 'wphive_meta_url'); 
     85add_filter('logout_url', 'wphive_meta_url'); 
     86add_filter('register', 'wphive_meta_url'); 
     87add_filter('wp_admin', 'wphive_meta_url'); 
    7888 
    79 function wphive_remove_site_cookie() { 
     89/* Log Out */ 
     90 
     91function wphive_logout() { 
    8092    wphive_delete_cookie('wphive_pathname'); 
     93    wp_redirect(get_bloginfo('home')); 
     94    exit(0); 
    8195} 
    82 add_action('wp_logout', 'wphive_remove_site_cookie'); 
     96add_action('wp_logout', 'wphive_logout'); 
    8397 
    8498/* 
     
    87101 
    88102include ('add-ons/root-files-rewriter.php'); 
     103 
     104do_action('wphive_plugin_loaded'); 
    89105?> 
Note: See TracChangeset for help on using the changeset viewer.