[pLog-svn] r746 - in plog/trunk: . class/action class/net/http
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Sun Jan 16 19:14:06 GMT 2005
Author: oscar
Date: 2005-01-16 19:14:06 +0000 (Sun, 16 Jan 2005)
New Revision: 746
Added:
plog/trunk/class/net/http/subdomains.class.php
Modified:
plog/trunk/class/action/blogaction.class.php
plog/trunk/summary.php
Log:
when the summary.php is set as the default page, subdomains are not checked. I've added the class Subdomains so that we can check whether the incoming request belongs to a subdomain or not... I've also moved some of the subdomain logic from BlogAction to Subdomains::getSubdomainInfo()
Modified: plog/trunk/class/action/blogaction.class.php
===================================================================
--- plog/trunk/class/action/blogaction.class.php 2005-01-16 10:00:50 UTC (rev 745)
+++ plog/trunk/class/action/blogaction.class.php 2005-01-16 19:14:06 UTC (rev 746)
@@ -11,7 +11,7 @@
include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
include_once( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
- include_once( PLOG_CLASS_PATH."class/net/linkparser.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
@@ -128,18 +128,14 @@
// see if we're using subdomains
$config =& Config::getConfig();
if( $config->getValue( "subdomains_enabled" )) {
- $url = new Url( $config->getValue( "subdomains_base_url"));
- $lp = new LinkParser( $url->getHost());
- $server = HttpVars::getServer();
- $httpHost = $server["HTTP_HOST"];
- $result = $lp->parseLink( $httpHost );
+ $subdomainInfo = Subdomains::getSubdomainInfoFromRequest();
+
+ if( $subdomainInfo["username"] != "" && $this->_request->getValue( 'user' ) == "" )
+ $this->_request->setValue( 'user', $subdomainInfo["username"] );
+ if( $subdomainInfo["blogname"] != "" && $this->_request->getValue( 'blogName' ) == "" )
+ $this->_request->setValue( 'blogName', $subdomainInfo["blogname"] );
- if( $result["username"] != "" && $this->_request->getValue( 'user' ) == "" )
- $this->_request->setValue( 'user', $result["username"] );
- if( $result["blogname"] != "" && $this->_request->getValue( 'blogId' ) == "" )
- $this->_request->setValue( 'blogId', $result["blogname"] );
-
- $this->log->debug($result);
+ $this->log->debug($subdomainInfo);
}
$blogId = $this->_request->getValue( 'blogId' );
Added: plog/trunk/class/net/http/subdomains.class.php
===================================================================
--- plog/trunk/class/net/http/subdomains.class.php 2005-01-16 10:00:50 UTC (rev 745)
+++ plog/trunk/class/net/http/subdomains.class.php 2005-01-16 19:14:06 UTC (rev 746)
@@ -0,0 +1,66 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/linkparser.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/url.class.php" );
+
+ /**
+ * encapsulates most of the logic needed to extract info about
+ * the subdomain given a subdomain url
+ */
+ class Subdomains extends Object
+ {
+ /**
+ * returns an array with two positions: $array["username"] and $array["blogname"] as
+ * extracted from the request. This method is static
+ *
+ * @static
+ * @return an associative array
+ */
+ function getSubdomainInfoFromRequest()
+ {
+ $config =& Config::getConfig();
+ $url = new Url( $config->getValue( "subdomains_base_url"));
+ $lp = new LinkParser( $url->getHost());
+ $server = HttpVars::getServer();
+ $httpHost = $server["HTTP_HOST"];
+ $result = $lp->parseLink( $httpHost );
+
+ return( $result );
+ }
+
+ /**
+ * returns true if a given url is using a subdomain or not. It works by comparing
+ * the url with "base_url" from the plog_config table. If they match, then the incoming
+ * url is *not* using subdomains. Otherwise, it will return true
+ *
+ * @param url If null, use $_SERVER["HTTP_HOST"]
+ * @return true if the given url is subdomained or not
+ * @static
+ */
+ function isSubdomainUrl( $url = null )
+ {
+ // prepare the url
+ if( $url == null ) {
+ $server = HttpVars::getServer();
+ $urlObject = new Url( "http://".$server["HTTP_HOST"] );
+ }
+ else
+ $urlObject = new Url( $url );
+
+ // and now get the base_url
+ $config =& Config::getConfig();
+ $baseUrlObject = new Url( $config->getValue( "base_url" ));
+
+ // and finally check if whether they match or not
+ if( $urlObject->getHost() == $baseUrlObject->getHost())
+ $isSubdomain = false;
+ else
+ $isSubdomain = true;
+
+ // return it...
+ return( $isSubdomain );
+ }
+ }
+?>
\ No newline at end of file
Modified: plog/trunk/summary.php
===================================================================
--- plog/trunk/summary.php 2005-01-16 10:00:50 UTC (rev 745)
+++ plog/trunk/summary.php 2005-01-16 19:14:06 UTC (rev 746)
@@ -13,9 +13,18 @@
include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
include_once( PLOG_CLASS_PATH."class/misc/version.class.php" );
include_once( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
define( "SUMMARY_DEFAULT_BLOGS_PER_PAGE", 25 );
+ // check if the url is coming for a subdomain because if it is... we should
+ // redirect to index.php because it is not coming to us!
+ $config =& Config::getConfig();
+ if( $config->getValue( "subdomains_enabled") && Subdomains::isSubdomainUrl()) {
+ include_once( PLOG_CLASS_PATH."index.php" );
+ die();
+ }
+
/**
* our very own controller class... overwrite a few methods for our convenience!
*/
More information about the pLog-svn
mailing list