WordPress.org

Plugin Directory

Changeset 156140


Ignore:
Timestamp:
09/19/09 02:28:03 (5 years ago)
Author:
ikailo
Message:
 
Location:
wp-hive/tags/0.5
Files:
7 edited

Legend:

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

    r151196 r156140  
    5555        $message = "There was an error saving the site."; 
    5656    } 
    57  
     57    do_action('wphive_site_added'); 
    5858    ?> 
    5959<div id="message" class="updated fade"><p><strong><?php echo $message; ?></strong></div> 
     
    7272        $message = "There was a problem removing the site from WP Hive."; 
    7373    } 
     74    do_action('wphive_site_removed'); 
    7475    ?> 
    7576<div id="message" class="updated fade"><p><strong><?php echo $message; ?></strong></div> 
  • wp-hive/tags/0.5/admin/settings.php

    r151196 r156140  
    3131        Except sites: <a href="<?php echo WPHIVE_ADMIN_REL.'/add.php'; ?>">add</a> 
    3232        and <a href="<?php echo WPHIVE_ADMIN_REL.'/edit.php'; ?>">edit</a>.<br/> 
    33         Better still, <a href="http://wp-hive.com/donate">donate</a>!</p> 
     33        Better still, <a href="http://wp-hive.com/donate">donate</a></p> 
    3434</div> 
  • wp-hive/tags/0.5/do-prefix.php

    r151196 r156140  
    1010require_once ('includes/functions.php'); 
    1111require_once ('includes/class.wphive.php'); 
     12 
     13 
    1214 
    1315$wphive = new wphive(); 
     
    3133 
    3234    // Handle wp-admin, wp-install, wp-login requests for subdirectory sites 
    33     // TODO: use preg_replace? 
    3435    if (stristr($orig_pathname, $pathname . '/wp-admin') || stristr($orig_pathname, $pathname . '/wp-login.php')) { 
    35         wphive_set_cookie('wphive_pathname', $pathname); // Use cookies to keep track of the site we are editing 
     36        wphive_set_cookie('wphive_pathname', $pathname); // Use cookies to keep track of the site we are administering 
    3637        $redirect = 'http://' . $orig_hostname . substr($orig_pathname, strlen($pathname)); 
    37         //$redirect = str_replace($pathname, '', $redirect); 
    3838        wphive_redirect($redirect); 
    3939        exit (0); 
    4040    } 
    4141} 
    42 // Check if WP Hive is installed, run installation if not. 
    43 $suppress = $wpdb->suppress_errors(); 
    44 $installed = $wpdb->get_var("SELECT val FROM wphive_config WHERE item = 'installed'"); 
    45 $wpdb->suppress_errors($suppress); 
    46 if (empty ($installed)) { 
     42// Check if WP Hive is installed, run installation or upgrade as required. 
     43$installed_version = $wphive->get_installed_version(); 
     44if ( $installed_version != $wphive->version ) { 
    4745    require_once ('includes/install.php'); 
    48     $prefix = wphive_install(); 
     46    $prefix = wphive_maybe_install($installed_version, $wphive->version); 
    4947} 
    5048 
     
    8078$table_prefix = $prefix; 
    8179 
    82 // Setting up for success - It's a plugin. Of course you want it active. 
     80// TODO: Inefficient - should be in class. Need to rework wphive class. 
     81$wphive->current_site = $wphive->get_site_by_prefix($prefix); 
     82 
     83/* WP Install Override */ 
     84// Don't clear .htaccess on subdirectory install 
     85if ( defined('WP_INSTALLING') && WP_INSTALLING === true && $wphive->current_site->path != '/' ) { 
     86    function wp_install($blog_title, $user_name, $user_email, $public, $deprecated='') { 
     87        return wphive_override_install($blog_title, $user_name, $user_email, $public, $deprecated=''); 
     88    } 
     89} 
     90 
     91// Setting up for success - force plugin active. Will be changed in a future version. 
    8392// Just remember that you need to delete db.php if you want to deactivate the plugin. 
    8493wphive_force_plugin_active(); 
  • wp-hive/tags/0.5/includes/class.wphive.php

    r151196 r156140  
    3232class wphive { 
    3333 
    34 /** 
    35  * Constructor. 
    36  * 
    37  * @package WP Hive 
    38  * @since 0.5 
    39  * 
    40  */ 
     34    var $current_site; 
     35    var $version = '0.5'; 
     36    /** 
     37     * Constructor. 
     38     * 
     39     * @package WP Hive 
     40     * @since 0.5 
     41     * 
     42     */ 
    4143    public function wphive ( ) { 
    4244 
     45    } 
     46 
     47    /** 
     48     * Gets the installed version of WP Hive 
     49     * @package WP Hive 
     50     * @since 0.5 
     51     * 
     52     * @return The version of WP Hive that is installed 
     53     */ 
     54    public function get_installed_version() { 
     55        global $wpdb; 
     56        $suppress = $wpdb->suppress_errors(); 
     57        $version = $this->get_option('version'); 
     58        if (empty($version)) { 
     59            $version = $this->get_option('installed') ? '0.4' : null; 
     60        } 
     61        $wpdb->suppress_errors($suppress); 
     62        return $version; 
     63    } 
     64 
     65    public function site_has_subdirs( $site ) { 
     66        global $wpdb; 
     67        if ($site->path == '/') { 
     68            return $wpdb->get_var($wpdb->prepare("SELECT Count(*) FROM wphive_hosts WHERE host = %s AND NOT path = %s", $site->host, "/")) > 0; 
     69        } 
     70        return false; 
    4371    } 
    4472 
     
    113141    } 
    114142 
    115         /** 
     143    /** 
    116144     * Get a site Prefix 
    117145     * 
  • wp-hive/tags/0.5/includes/functions.php

    r151196 r156140  
    8686} 
    8787 
     88// Override, fix permalink issue 
     89function wphive_override_install($blog_title, $user_name, $user_email, $public, $deprecated='') { 
     90    global $wp_rewrite; 
     91 
     92    wp_check_mysql_version(); 
     93    wp_cache_flush(); 
     94    make_db_current_silent(); 
     95    populate_options(); 
     96    populate_roles(); 
     97 
     98    update_option('blogname', $blog_title); 
     99    update_option('admin_email', $user_email); 
     100    update_option('blog_public', $public); 
     101 
     102    $guessurl = wp_guess_url(); 
     103 
     104    update_option('siteurl', $guessurl); 
     105 
     106    // If not a public blog, don't ping. 
     107    if ( ! $public ) 
     108        update_option('default_pingback_flag', 0); 
     109 
     110    // Create default user.  If the user already exists, the user tables are 
     111    // being shared among blogs.  Just set the role in that case. 
     112    $user_id = username_exists($user_name); 
     113    if ( !$user_id ) { 
     114        $random_password = wp_generate_password(); 
     115        $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.'); 
     116        $user_id = wp_create_user($user_name, $random_password, $user_email); 
     117        update_usermeta($user_id, 'default_password_nag', true); 
     118    } else { 
     119        $random_password = ''; 
     120        $message =  __('User already exists.  Password inherited.'); 
     121    } 
     122 
     123    $user = new WP_User($user_id); 
     124    $user->set_role('administrator'); 
     125 
     126    wp_install_defaults($user_id); 
     127 
     128    if (!isset($_COOKIE['wphive_pathname'])) { 
     129        $wp_rewrite->flush_rules(); 
     130    } 
     131 
     132    wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password); 
     133 
     134    wp_cache_flush(); 
     135 
     136    return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password, 'password_message' => $message); 
     137} 
    88138 
    89139?> 
  • wp-hive/tags/0.5/includes/install.php

    r151196 r156140  
    11<?php 
     2 
     3function wphive_maybe_install($from_version, $to_version) { 
     4    switch ($from_version) { 
     5        case '': 
     6            return wphive_install(); 
     7            break; 
     8        case '0.4': 
     9            wphive_upgrade_0_4($to_version); 
     10    } 
     11} 
     12 
    213function wphive_install () { 
    3     global $wpdb, $table_prefix, $hostname; 
     14    global $wpdb, $wphive, $table_prefix, $hostname; 
    415    // Create the config table 
    516    $wpdb->query ("CREATE TABLE `wphive_config` ( 
     
    3748        } 
    3849 
    39         // Inseret some config values 
    40         $wpdb->insert('wphive_config', array('item'=>'installed', 'val'=>true)); 
    41         $wpdb->insert('wphive_config', array('item'=>'version', 'val'=>'0.5')); 
    42         $wpdb->insert('wphive_config', array('item'=>'default_permalinks', 'val'=>'/archives/%post_id%')); 
     50        // Insert some config values 
     51        $wphive->add_option('version', '0.5'); 
     52        $wphive->add_option('default_permalinks', '/archives/%post_id%'); 
    4353        return $prefix; 
    4454    } 
    4555} 
     56 
     57function wphive_upgrade_0_4($to_version) { 
     58    global $wpdb, $wphive; 
     59 
     60    // Update the Hosts Table 
     61    $wpdb->query ("ALTER TABLE `wphive_hosts` 
     62                    ADD COLUMN `id` int NOT NULL AUTO_INCREMENT FIRST, 
     63                    ADD COLUMN `path` varchar (255) NOT NULL AFTER `prefix`, 
     64                    CHANGE `host` `host` varchar (255) NOT NULL, 
     65                    CHANGE `prefix` `prefix` varchar (255) NOT NULL, 
     66                    ADD PRIMARY KEY(`id` )"); 
     67 
     68    // Fix the path values 
     69    $wpdb->update ('wphive_hosts', array('path'=>'/'), array('path' => '') ); 
     70 
     71    // Add new options 
     72    $wphive->add_option('version', '0.5'); 
     73    $wphive->add_option('default_permalinks', '/archives/%post_id%'); 
     74 
     75    // Remove unused options 
     76    $wphive->delete_option('installed'); 
     77    $wphive->delete_option('allow_new_hosts'); 
     78} 
     79 
     80 
    4681?> 
  • wp-hive/tags/0.5/wp-hive.php

    r151196 r156140  
    1414 */ 
    1515 
    16 function wphive_force_permalinks() { 
    17     global $wp_rewrite, $wpdb; 
    18     if (!$wp_rewrite->using_permalinks()) { 
    19         $permalink_structure = $wpdb->get_var("SELECT val FROM wphive_config WHERE item = 'default_permalinks'"); 
    20         $wp_rewrite->set_permalink_structure($permalink_structure); 
    21         $wp_rewrite->flush_rules(); 
     16function wphive_check_permalinks() { 
     17    global $wp_rewrite, $wphive; 
     18    if (!$wp_rewrite->using_permalinks() && $wphive->site_has_subdirs($wphive->current_site)) { 
     19        echo "<div id='wphive-warning' class='updated fade'><p><strong>WP Hive Warning:</strong><br/>A 
     20subdirectory site is installed using WP Hive, but you are not using pretty permalinks.<br/>Fix the problem now by 
     21<a href='/wp-admin/options-permalink.php'>configuring this site to use pretty permalinks</a>. 
     22</p></div>"; 
    2223    } 
    2324} 
    24 add_action('init', 'wphive_force_permalinks', 1); 
     25if ( isset($_REQUEST['wphive_save_site'])) { 
     26    add_action('wphive_site_added', 'wphive_check_permalinks'); 
     27} 
     28elseif ( isset($_REQUEST['wphive_remove_site']) ) { 
     29    add_action('wphive_site_removed', 'wphive_check_permalinks'); 
     30} 
     31elseif ( version_compare(get_bloginfo('version'), '2.8', '>=') &&  isset($_REQUEST['permalink_structure']) ) { 
     32    add_action('permalink_structure_changed', 'wphive_check_permalinks'); 
     33} 
     34else { 
     35    add_action('admin_notices', 'wphive_check_permalinks'); 
     36} 
    2537 
    2638/* 
     
    3951add_action('admin_menu', 'wphive_admin_hook'); 
    4052 
     53 
     54/* Trying to sort out wp-admin confusion, when logging into subdirectories. */ 
     55// Probably doesn't work 
     56if ( 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 { 
     65        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 
     68        } 
     69        add_filter('login_message', 'wphive_login_name' ); 
     70        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>"; 
     72        } 
     73        add_action('admin_notices', 'wphive_admin_name'); 
     74    } 
     75} 
     76 
    4177/* Cookies */ 
    4278 
     
    4682add_action('wp_logout', 'wphive_remove_site_cookie'); 
    4783 
    48  
    4984/* 
    5085 * Add-ons 
Note: See TracChangeset for help on using the changeset viewer.