WordPress.org

Plugin Directory

Changeset 151196


Ignore:
Timestamp:
09/01/09 19:26:47 (5 years ago)
Author:
ikailo
Message:
 
Location:
wp-hive/tags/0.5
Files:
15 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • wp-hive/tags/0.5/do-prefix.php

    r138684 r151196  
    11<?php 
     2 
    23// WP Hive Plugin 
    3 // Version 0.4.2 
     4// Version 0.5 
    45 
    5 global $wpdb, $table_prefix, $hostname, $path; 
     6global $wpdb, $table_prefix, $hostname, $pathname, $wphive; 
     7 
     8define('WPHIVE_PATH', dirname(__FILE__)); 
     9 
     10require_once ('includes/functions.php'); 
     11require_once ('includes/class.wphive.php'); 
     12 
     13$wphive = new wphive(); 
    614 
    715// Get and clean up the hostname 
    8 $hostname = addslashes( $_SERVER['HTTP_HOST'] ); 
    9 if ( substr($hostname, 0, 4) == "www." ) $hostname = substr($hostname,4); // Strip www 
    10 $hostname = preg_replace('/:.*$/', '', $hostname); // Strip port 
    11 $hostname = trim($hostname, "."); // Strip trailing dots 
    12  
    13 // Get and clean up the path 
    14 $path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] ); // Ignore calling php file (eg: index.php) 
    15 $path = str_replace ( '/wp-admin/', '/', $path ); // Ignore wp-admin for base site 
    16 $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path ); // Get the actual path 
    17 if( substr( $path, -1 ) == '/' ) $path = substr( $path, 0, -1 ); // Remove trailing slash 
    18 if ( '' == $path ) $path == '/'; // Path is root, make it so 
    19 // $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); 
    20  
    21 // Check if WP Hive is installed, run installation if not. 
    22 $installed = $wpdb->get_var("SELECT val FROM wphive_config WHERE item = 'installed'"); 
    23 if ( empty($installed) )    { 
    24  
    25     // Create the config table 
    26     $wpdb->query ("CREATE TABLE `wphive_config` ( 
    27         `item` varchar (255) NOT NULL, 
    28         `val` varchar (255), 
    29         PRIMARY KEY ( `item` ))"); 
    30  
    31     // Create the host table 
    32     $wpdb->query ("CREATE TABLE `wphive_hosts` ( 
    33         `host` varchar (255) NOT NULL, 
    34         `prefix` varchar (255) NOT NULL,  
    35         `path` varchar (255) NOT NULL )"); 
    36  
    37     // Create common directory 
    38     if (! file_exists(WP_CONTENT_DIR . '/wp-hive/') ) { 
    39         mkdir(WP_CONTENT_DIR . '/wp-hive'); 
    40     } 
    41     // Set intitial prefix to existing $table_prefix (assume the prefix is an existing WP installation) 
    42     if ($table_prefix != false) { 
    43         $prefix = $table_prefix; 
    44         $wpdb->query($wpdb->prepare("INSERT INTO wphive_hosts (host, prefix) values ( %s, %s )", $hostname, $prefix)); 
    45  
    46         // Create storage directory for the domain 
    47         if ( ! file_exists(WP_CONTENT_DIR . '/wp-hive/' . $hostname . '/' ) ) { 
    48             mkdir(WP_CONTENT_DIR . '/wp-hive/' . $hostname . '/'); 
    49         } 
    50         // Clean up special files in the root 
    51         // Note: Users should ensure the files are accessed by Plugins in their new location 
    52         $specialfiles = array("robots.txt", "favicon.ico", "sitemap.xml", "sitemap.xml.gz"); 
    53         foreach ($specialfiles as $file) { 
    54             if (file_exists(ABSPATH . '/' . $file) ) { 
    55                 rename(ABSPATH . '/' . $file, WP_CONTENT_DIR . '/wp-hive/' . $hostname . '/' . $file); 
    56             } 
    57         } 
    58  
    59         // Insert some config values 
    60         $wpdb->query ($wpdb->prepare("INSERT INTO wphive_config (item, val) values ( %s, %s )", "allow_new_hosts", 1)); 
    61         $wpdb->query ($wpdb->prepare("INSERT INTO wphive_config (item, val) values ( %s, %s )", "installed", 1)); 
    62  
    63         // TODO: Check if WP Hive plugin is installed / active 
    64     } 
     16if (!$hostname) { 
     17    $orig_hostname = addslashes($_SERVER['HTTP_HOST']); 
     18    $hostname = $wphive->clean_hostname($orig_hostname); 
    6519} 
    6620 
    67 function wphive_try_add_prefix() { 
    68     global $wpdb, $hostname, $prefix, $path; 
    69     // Check if we are allowed to add a new site 
    70     if ($wpdb->get_var("SELECT val FROM wphive_config WHERE item = 'allow_new_hosts'") == 1){ 
    71         $prefix = substr($hostname, 0, 3) . "_"; 
     21// Check if the pathname has been previously defined 
     22// If we are in wp-admin, wp-install, wp-login 
     23// TODO: Probably need to fix for non-admin wp-logins on subdirectory sites. 
     24if (defined('WP_ADMIN') || defined('WP_INSTALLING') || stristr($_SERVER['REQUEST_URI'], 'wp-login.php')) { 
     25    $pathname = isset ($_COOKIE['wphive_pathname']) ? addslashes($_COOKIE['wphive_pathname']) : '/'; 
     26} 
     27// Get and clean up the pathname 
     28else { 
     29    $orig_pathname = addslashes($_SERVER['REQUEST_URI']); 
     30    $pathname = $wphive->clean_pathname($orig_pathname); 
    7231 
    73         // fix small subdomain prefixes by removing the "." and ensure they are 3 characters long 
    74         if (strpos($prefix,".")) { 
    75             $prefix = substr($prefix,0, strpos($prefix, ".", 1)); 
    76             while ( strlen($prefix) < 4 ) { 
    77                 $prefix .= "_";          
    78             } 
    79         } 
    80         // Ensure prefix is unique 
    81         $i = 1; 
    82         while ($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM wphive_hosts WHERE prefix = %s", $prefix)) > 0) {             
    83             $prefix = substr($prefix, 0, 2) . $i . "_"; 
    84             $i += 1; 
    85         } 
    86         $wpdb->query($wpdb->prepare("INSERT INTO wphive_hosts (host, prefix) values ( %s, %s )", $hostname, $prefix)); 
    87         // Create storage directory for the domain 
    88         if ( ! file_exists(WP_CONTENT_DIR . '/wp-hive/' . $hostname . '/') ) { 
    89             mkdir(WP_CONTENT_DIR . '/wp-hive/' . $hostname); 
    90         } 
    91     } 
    92     else    { 
    93         wp_die("Hostname: $hostname<br/>Path: $path<br/>Host not found."); 
    94     } 
     32    // Handle wp-admin, wp-install, wp-login requests for subdirectory sites 
     33    // TODO: use preg_replace? 
     34    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        $redirect = 'http://' . $orig_hostname . substr($orig_pathname, strlen($pathname)); 
     37        //$redirect = str_replace($pathname, '', $redirect); 
     38        wphive_redirect($redirect); 
     39        exit (0); 
     40    } 
     41} 
     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); 
     46if (empty ($installed)) { 
     47    require_once ('includes/install.php'); 
     48    $prefix = wphive_install(); 
    9549} 
    9650 
    9751// Get the corresponding prefix from the db 
    98 if (empty($prefix)) { 
    99     // get all the sites possible for the hostname 
    100     $possible_sites = $wpdb->get_results($wpdb->prepare("SELECT prefix, path FROM wphive_hosts WHERE host = %s", $hostname)); 
    101     // None? Try to add one. 
    102     if ( !$possible_sites ) {        
    103         wphive_try_add_prefix(); 
    104     } 
    105     else { 
    106         foreach ($possible_sites as $site)  { 
    107             if ($site->path == "/") { 
    108                 // root path, save this prefix 
    109                 $root_prefix = $site->prefix; 
    110             } 
    111              // If it matches, serve that site 
    112             if ($site->path == $path) { 
    113                 $prefix = $site->prefix; 
    114                 break; 
    115             } 
    116         } 
    117         // if it doesn't match, assume they want the root site 
    118         if ( empty($prefix) ) { 
    119             $prefix = $root_prefix; 
    120         } 
    121     } 
     52if (empty ($prefix)) { 
     53// get all the sites possible for the hostname 
     54    $possible_sites = $wpdb->get_results($wpdb->prepare("SELECT prefix, path FROM wphive_hosts WHERE host = %s", $hostname)); 
     55    // None? Try to add one. 
     56    if (!$possible_sites) { 
     57        wp_die("Unknown Host"); 
     58    } else { 
     59        foreach ($possible_sites as $site) { 
     60            if ($site->path == "/") { 
     61            // root path, save this prefix 
     62                $root_prefix = $site->prefix; 
     63            } 
     64            // If it matches, serve that site 
     65            if ($site->path == $pathname) { 
     66                $prefix = $site->prefix; 
     67                break; 
     68            } 
     69        } 
     70        // if it doesn't match, assume they want the root site 
     71        if (empty ($prefix)) { 
     72            $prefix = $root_prefix; 
     73            $pathname = '/'; 
     74            unset($orig_pathname); 
     75        } 
     76    } 
    12277} 
     78 
     79// This is what it all boils down to: 
    12380$table_prefix = $prefix; 
    12481 
     82// Setting up for success - It's a plugin. Of course you want it active. 
     83// Just remember that you need to delete db.php if you want to deactivate the plugin. 
     84wphive_force_plugin_active(); 
     85 
     86// Check if this is a fresh install and fix Siteurl for proper redirect 
     87wphive_siteurl_for_install($pathname, $table_prefix, $orig_hostname); 
     88 
    12589?> 
  • wp-hive/tags/0.5/readme.txt

    r138681 r151196  
    55Tags: multiple blog, single installation 
    66Requires at least: 2.5 
    7 Tested up to: 2.8 
     7Tested up to: 2.8.4 
    88Stable tag: 0.4.2 
    99 
     
    1515 
    1616This plugin is currently intended to be used in a multi-blog, single administrator environment.  It is built with ease of use and resource sharing at the forefront. WP Hive is for the blogger who manages many blogs and is looking for a simple way to synchronize the plugins, themes, and files for all their blogs at once. If you are looking to run a blog network where you (or a group of trusted individuals) administer and control all the blogs' content, then WP Hive is perfect for you. 
    17  
    18 WP Hive currently allows users to create new blogs on separate domains and on subdomains.  Having a separate blog on a subdirectory is currently in the works and is expected to be supported within the next few releases. 
    1917 
    2018Be sure to read the installation instructions, since the procedure is a little different than for most plugins. 
  • wp-hive/tags/0.5/wp-hive.php

    r138681 r151196  
    11<?php 
     2 
    23/* 
    34 Plugin Name: WP Hive 
    45 Plugin URI: http://wp-hive.com/overview/ 
    5  Description: Hive manager for multiple blogs with a single WP installation. 
     6 Description: Hive manager for multiple blogs with a single WP installation. **NOTE** To deactivate this plugin, you must delete the file 'wp-content/db.php' first! 
    67 Version: 0.5 
    78 Author: ikailo 
     
    910 */ 
    1011 
    11 /* -------- 
    12  * Robots.txt Manager 
    13  * Don't forget to save the robots file as /robottxt/[db_prefix]robot.txt. 
    14  * Also, you MUST ensure that no robot.txt file exists in the root directory. 
     12/* 
     13 * Permalinks 
    1514 */ 
    16 function hive_robots_check() { 
    17     global $wpdb, $hostname; 
    1815 
    19     $robotsfile = WP_CONTENT_DIR . '/wp-hive/'. $hostname . '/robots.txt'; 
    20     if ( file_exists ( $robotsfile ) ) { 
    21         readfile( $robotsfile ); 
    22         exit(0); 
    23     } 
     16function 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(); 
     22    } 
    2423} 
    25 add_action('do_robotstxt', 'hive_robots_check'); 
     24add_action('init', 'wphive_force_permalinks', 1); 
     25 
     26/* 
     27 * Admin 
     28 */ 
     29 
     30function wphive_admin_hook() { 
     31    if ( current_user_can('manage_options') ) { 
     32        add_menu_page('WP Hive', 'WP Hive', 8, WPHIVE_PATH.'/admin/settings.php', null, get_option('siteurl').'/wp-content/plugins/wp-hive/images/wphive.png'); 
     33        add_submenu_page(WPHIVE_PATH.'/admin/settings.php', 'WP Hive > Settings', 'Settings', 8, WPHIVE_PATH.'/admin/settings.php'); 
     34        add_submenu_page(WPHIVE_PATH.'/admin/settings.php', 'WP Hive > Edit', 'Edit', 8, WPHIVE_PATH.'/admin/edit.php'); 
     35        add_submenu_page(WPHIVE_PATH.'/admin/settings.php', 'WP Hive > Add New', 'Add New', 8, WPHIVE_PATH.'/admin/add.php'); 
     36        define('WPHIVE_ADMIN_REL', 'admin.php?page=wp-hive/admin'); 
     37    } 
     38} 
     39add_action('admin_menu', 'wphive_admin_hook'); 
     40 
     41/* Cookies */ 
     42 
     43function wphive_remove_site_cookie() { 
     44    wphive_delete_cookie('wphive_pathname'); 
     45} 
     46add_action('wp_logout', 'wphive_remove_site_cookie'); 
    2647 
    2748 
    28 /* -------- 
    29  * Sitemap.xml Manager 
    30  * Don't forget to set the sitemap generator to save the file as /sitemaps/[db_prefix]sitemap.xml. 
    31  * Also, you MUST ensure that no sitemap.xml file exists in the root directory. 
     49/* 
     50 * Add-ons 
    3251 */ 
    33 function hive_sitemap_check() { 
    34     global $wpdb, $wp_query, $hostname; 
    3552 
    36     if ( $wp_query->get('sitemap') == '1') { 
    37         $sitemapfile = WP_CONTENT_DIR . '/wp-hive/'. $hostname . '/sitemap.xml'; 
    38         if ( file_exists ( $sitemapfile ) ) { 
    39             header('Content-type: application/xml; charset="utf-8"'); 
    40             readfile( $sitemapfile ); 
    41             exit(0); 
    42         } 
    43         else { 
    44             status_header('404'); 
    45             include ( TEMPLATEPATH . '/404.php' ); 
    46             exit(0); 
    47         } 
    48     } 
    49     elseif ( $wp_query->get('sitemapgz') == '1' ) { 
    50         $sitemapgzfile = WP_CONTENT_DIR . '/wp-hive/'. $hostname . '/sitemap.xml.gz'; 
    51         if ( file_exists ( $sitemapgzfile ) ) { 
    52             header('Content-type: application/x-gzip'); 
    53             readfile( $sitemapgzfile ); 
    54             exit(0); 
    55         } 
    56         else { 
    57             status_header('404'); 
    58             include ( TEMPLATEPATH . '/404.php' ); 
    59             exit(0); 
    60         } 
    61     } 
    62 } 
    63 add_action('template_redirect', 'hive_sitemap_check'); 
    64  
    65 // add sitemap as an allowed query var 
    66 function hive_sitemap_query_var($vars){ 
    67     array_push($vars, 'sitemap', 'sitemapgz'); 
    68     return $vars; 
    69 } 
    70 add_filter('query_vars','hive_sitemap_query_var'); 
    71  
    72 // add sitemap rewrite rules 
    73 function hive_sitemap_intercept($rewrite_rules) { 
    74  
    75     $sitemap_rules = array ( 
    76         'sitemap.xml$' => 'index.php?sitemap=1', 
    77         'sitemap.xml.gz$' => 'index.php?sitemapgz=1' 
    78         ); 
    79  
    80         return ( $rewrite_rules + $sitemap_rules ); 
    81 } 
    82 add_filter( 'root_rewrite_rules', 'hive_sitemap_intercept' ); 
    83  
    84  
    85 /* -------- 
    86  * Favicon.ico Manager 
    87  * Don't forget to save your favicon.ico file as /favicons/[db_prefix]favicons.ico. 
    88  * Also, you MUST ensure that no favicon.ico file exists in the root directory. 
    89  */ 
    90 function hive_favicon_check() { 
    91     global $wpdb, $wp_query, $hostname; 
    92  
    93     if ( $wp_query->get('favicon') == '1') { 
    94         $faviconfile = WP_CONTENT_DIR . '/wp-hive/'. $hostname . '/favicon.ico'; 
    95         if ( file_exists ( $faviconfile ) ) { 
    96             if (function_exists('finfo_open')) { 
    97                 $finfo = finfo_open(FILEINFO_MIME); 
    98                 $fmime = finfo_file($finfo, $faviconfile); 
    99                 finfo_close($finfo); 
    100             } 
    101             else { 
    102                 require_once( 'mime-content-type.php' ); 
    103                 $fmime = mime_content_type($faviconfile); 
    104             } 
    105             header('Content-type: ' . $fmime); // Send the actual MIME type 
    106             readfile( $faviconfile ); 
    107             exit(0); 
    108         } 
    109         else { 
    110             status_header('404'); 
    111             echo "File Does Not Exist"; 
    112             exit(0); 
    113         } 
    114     } 
    115 } 
    116 add_action('template_redirect', 'hive_favicon_check'); 
    117  
    118 // add favicon as an allowed query var 
    119 function hive_favicon_query_var($vars){ 
    120     array_push($vars, 'favicon'); 
    121     return $vars; 
    122 } 
    123 add_filter('query_vars','hive_favicon_query_var'); 
    124  
    125 // add favicon rewrite rules 
    126 function hive_favicon_intercept($rewrite_rules) { 
    127  
    128     $favicon_rules = array ( 
    129         'favicon.ico$' => 'index.php?favicon=1' 
    130         ); 
    131  
    132         return ( $rewrite_rules + $favicon_rules ); 
    133 } 
    134 add_filter( 'root_rewrite_rules', 'hive_favicon_intercept' ); 
     53include ('add-ons/root-files-rewriter.php'); 
    13554?> 
Note: See TracChangeset for help on using the changeset viewer.