Dec 04, 2008, 02:54 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1] 2 3 ... 5   Go Down
  Print  
Author Topic: [Plugin] Subsites/Subdomains  (Read 24341 times)
0 Members and 1 Guest are viewing this topic.
xwisdom
Foundation
*
Posts: 1,732



« on: Nov 17, 2005, 11:25 AM »

Hell everyone,

Sometime I created this little plugin to allow subsites under modx.

To install create an new plugin called Subsites and enable the 'OnWebPageInit' event then copy and paste the following code. Be sure to make the necessary modifications to the source:

Code:
$e = &$modx->event;
$subdomain = 'subdomain.yourdomain.com'; // your subdomain name here
if($e->name=='OnWebPageInit') {
   $s = $_SERVER['HTTP_HOST'];
   if($s==$subdomain && $modx->documentIdentifier==$modx->config['site_start']){
      header('Location: index.php?id=6');
      exit;
   }
   else if($s==$subdomain){
       $modx->config['site_start'] = 6; // your start page here
       $modx->config['error_page'] = 6; // your error page here
   }
}

Once the plugin is installed your next step is to make subdomain.yourdomain.com an alias of www.yourdomain.com.
« Last Edit: Nov 17, 2005, 11:26 AM by xwisdom » Logged

xWisdom
www.xwisdomhtml.com
The fear of the Lord is the beginning of wisdom:
MODx Co-Founder - Create and do more with less.
zi
MODx Special Forces /
Administrator
*
Posts: 3,020


May Peace Be On You


WWW
« Reply #1 on: Nov 17, 2005, 11:38 AM »

Great work Raymond !!  Kiss

Many people asked for this, and now they will be happy  Roll Eyes

Best regards,

zi
Logged

“Internet Explorer’s CSS rendering: WYSIWTF”. — someone genius
--------------------------------------------------
banzai
Testers
*
Posts: 857


MODx Italia


WWW
« Reply #2 on: Nov 17, 2005, 04:40 PM »

Great!!
I think it's a nice feature to include in next release
Logged

MODx Websites Showcase 
Add your site to www.modx.it!
-----------------------------------------------------
FREE MODx Templates
www.tattoocms.it
-----------------------------------------------------
VIDEO: whats new in MODx 0.9.5   | VIDEO: MODx PHP Application Framework  |  bubuna.com - Web & Multimedia Design
davidm
Marketing & Design Team
*
Posts: 6,779


The best way to predict the future is to invent it


WWW
« Reply #3 on: Nov 18, 2005, 08:22 AM »

+1 this is really cool, even if I don't need it (yet Grin)
Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
Djamoer
Testers
*
Posts: 1,492

No one can limit a man other than the man himself.


WWW
« Reply #4 on: Nov 18, 2005, 10:32 PM »

Nice one!

I just posted yesterday, and I received the complete solution in a day.

Thanks xwisdom.

Do you mind if I ask a little detailed about the code?

Code:
&$modx->event
That will fetch the current event by reference right?

Code:
if($e->name=='OnWebPageInit') {
Why do we need to check the current event again? I thought it will only be called when event is OnWebPageInit?

Code:
   if($s==$subdomain && $modx->documentIdentifier==$modx->config['site_start']){
      header('Location: index.php?id=6');
      exit;
   }
   else if($s==$subdomain){
       $modx->config['site_start'] = 6; // your start page here
       $modx->config['error_page'] = 6; // your error page here
   }
What is the first if conditional did? Checking the default page start?


Hope I can start learning the current API in modX further, by starting from smaller plugin, and getting used to some other resources, which later lead to modules. Is there anyway to start understanding module better?

Thank you

Sincerely,
Wendy Novianto
Logged

The Man Can!
Testers
*
Posts: 296



WWW
« Reply #5 on: Nov 19, 2005, 02:39 AM »

Hi all.  Great plugin Raymond!
I've spent some time playing with it, and combining it with a modified version of Susan's UltimateParent to make a sort of UltimateParentSubdomain.  The idea is roughly:
  • set the subdomains' "root"/landing page,
  • determine the subdomain,
  • find the ultimate parent using the subdomain root ID instead of 0.

The problem is that links aren't rendered with the subdomain. If I go to subdomain.boopaloo.com, the links on the page are for boopaloo.com/subdomain/item1.html, so once the visitor navigates away from the subdomain landing page, they're no longer in the subdomain, which often isn't what's desired, and makes my snippet not work Wink

I'm guessing the solution might be in a plugin that loads on event OnFriendlyURLSettingsRender?, but I can't get anything going.  The plugin could check each link's "ultimate subdomain parent" and apply the appropriate subdomain prefix to the link.

So, if doc2 = subdomain2, then any link to content that is under doc2 gets its link rewritten.  (When using alias paths, it'd also be nice to strip the first alias as well, so instead of subdomain2.boopaloo.com/doc2/folder/content it'd just be subdomain.boopaloo.com/folder/content.  This isn't quite as important but it'd be nice.)

Does that make sense?  Any ideas if OnFriendlyURLSettingsRender is the right thing to focus on, or any tips on how MODx makes the friendly URLs in the first place?  I think this could be relatively simple, but I'm still new and don't know where to look.

Having subdomians function like this would be amazing, and would open the door to some pretty cool stuff kind of like WordPress Multi User.  It would also allow an UltimateParent for subdomains, which would make menus within a subdomian much easier, and even stuff like having a simple snippet to display a different header/logo depending on the current subdomain.  Smiley
Thanks all!
Brett
Logged

Need MODx Ecommerce? Try FoxyCart!
xwisdom
Foundation
*
Posts: 1,732



« Reply #6 on: Nov 20, 2005, 12:20 AM »

Code:
&$modx->event
That will fetch the current event by reference right?
That's correct
Quote
Code:
if($e->name=='OnWebPageInit') {
Why do we need to check the current event again? I thought it will only be called when event is OnWebPageInit?

Note here that we are checking for the name of the even by using $e->name. The plugin is only executed when anyone of the events it is listening to is invoked.

Quote
Code:
   if($s==$subdomain && $modx->documentIdentifier==$modx->config['site_start']){
      header('Location: index.php?id=6');
      exit;
   }
   else if($s==$subdomain){
       $modx->config['site_start'] = 6; // your start page here
       $modx->config['error_page'] = 6; // your error page here
   }
What is the first if conditional did? Checking the default page start?

This will cause the plugin to redirect site_start request to the subdomain site_start page.

Quote
Is there anyway to start understanding module better?

You can have a look at our documentation:
http://modxcms.com/developers-guide.html
Logged

xWisdom
www.xwisdomhtml.com
The fear of the Lord is the beginning of wisdom:
MODx Co-Founder - Create and do more with less.
xwisdom
Foundation
*
Posts: 1,732



« Reply #7 on: Nov 20, 2005, 12:31 AM »

The problem is that links aren't rendered with the subdomain. If I go to subdomain.boopaloo.com, the links on the page are for boopaloo.com/subdomain/item1.html, so once the visitor navigates away from the subdomain landing page, they're no longer in the subdomain, which often isn't what's desired, and makes my snippet not work Wink


Hi Brett,

Are u usng firendly url paths?
Logged

xWisdom
www.xwisdomhtml.com
The fear of the Lord is the beginning of wisdom:
MODx Co-Founder - Create and do more with less.
The Man Can!
Testers
*
Posts: 296



WWW
« Reply #8 on: Nov 20, 2005, 12:48 AM »

Hi Raymond.  Yes I am.  I'm using alias paths as well.  ...
EDIT: Something goofy is happening with my DNS (or I *really* need some sleep Wink ), but as of 10 minutes ago (and after hours of testing/banging my head against my desk) it does indeed rewrite the URLs to include the subdomain.  Sorry to be stupid on this one.

EDIT again:  I think I figured it out.  Seems like once a page is loaded that is "unfriendly" (ie. /index.php?id=6), the subdomains no longer get attached to the links on the page.  I have a weblink that points to one of its children, and I made that link "unfriendly"; so once that link like was clicked, the subdomain stopped appearing in the links.  Changing the weblink to the appropriate friendly link works perfectly.  Hopefully this helps somebody.  Took me long enough to figure out.

Now I can focus on trying to get it to abstain from including the subdomain in links to content that's "outside the subdomain" (as described above)... don't hold your breath Smiley
Thanks again Raymond.  -Brett
« Last Edit: Nov 20, 2005, 08:47 PM by The Man Can! » Logged

Need MODx Ecommerce? Try FoxyCart!
Djamoer
Testers
*
Posts: 1,492

No one can limit a man other than the man himself.


WWW
« Reply #9 on: Nov 20, 2005, 11:59 PM »


Quote
Code:
   if($s==$subdomain && $modx->documentIdentifier==$modx->config['site_start']){
      header('Location: index.php?id=6');
      exit;
   }
   else if($s==$subdomain){
       $modx->config['site_start'] = 6; // your start page here
       $modx->config['error_page'] = 6; // your error page here
   }
What is the first if conditional did? Checking the default page start?

This will cause the plugin to redirect site_start request to the subdomain site_start page.


I still don't get it.

What I can interpret, if domain requested equal to $subdomain, then set the header to the desired doc id, and exit; else, if the the requested domain equal to $subdomain, then it will set the config vars of site start and error page into desired doc id.

From what I assume, the else if statement is the one that do the job, by changing the config site start and page error doc id, then what is the use of the first if statement? Why don't we just move the header() into else if statement, and remove the if statement.

Sorry, if I ask something stupid.

Is there any possibility to include array support as the subdoain vars, and the plugin will loop throught the array of subdomain to determine whether the requested subdomain to be directed to the appropriate doc id that was assigned in the array. In fact, we can set the array key as the subdomain string, and let the value of array as the doc id for start page and error page, but I'm not to for sure whether php allowed an array key with a dot.

Thanks again for the help and reply.

PS: The developers docs is imrpoved from the one that I read a few weeks ago. Awesome! It helps me understand the way MODx work more than I know previously. Thank you guys!

regards,
Wendy Novianto
Logged

Djamoer
Testers
*
Posts: 1,492

No one can limit a man other than the man himself.


WWW
« Reply #10 on: Nov 21, 2005, 08:23 PM »

Bump!!

Just wanna know, whether someone can help me clarify things up.

Thank you...
Logged

xwisdom
Foundation
*
Posts: 1,732



« Reply #11 on: Nov 21, 2005, 08:48 PM »

Bump!!

Just wanna know, whether someone can help me clarify things up.

Thank you...

Hi wendy,

What is it that you need to be clarify?

Logged

xWisdom
www.xwisdomhtml.com
The fear of the Lord is the beginning of wisdom:
MODx Co-Founder - Create and do more with less.
Djamoer
Testers
*
Posts: 1,492

No one can limit a man other than the man himself.


WWW
« Reply #12 on: Nov 22, 2005, 11:29 PM »

xwisdom...

I tried to modified your code, and it ended up not doing what I want it to be. With the Location header, it will only redirect the user, and it will change the url to the user.

Here is the code:
Code:
$e = &$modx->event;
// Main Site Domain
$mainSiteDomain = 'main.domain.com';
// Sub Sites Configuration Array
$subSites[0]['domain'] = 'subdsite.domain.com'; // SubSite Domain (Mirrored to MODx installation domain)
$subSites[0]['alias'] = 'subdsite'; // SubSite Folder Document Alias
$subSites[0]['id'] = 6; // SubSite Folder Document ID
$subSites[0]['error'] = 7; // Error Page ID

if($e->name=='OnWebPageInit') {
  // Extract Domain and URI
  $incomingDomain = $_SERVER['HTTP_HOST'];
  $incomingPath = $_SERVER['SCRIPT_NAME'];
  $incomingQueryString = $_SERVER['QUERY_STRING'];;
  // Checking subSites Array and directing users to the right start page
  for($i = 0; $i < count($subSites); $i) {
    if($incomingDomain==$subSites[$i]['domain'] && !isset($domainRedirectSign)) {
      //$modx->config['site_start'] = $subSites[$i]['id']; // start page here
      //$modx->config['error_page'] = $subSites[$i]['error']; // error page here
      header('Location: http://'.$mainSiteDomain.'/'.$subSites[$i]['alias'].$incomingPath.'?'.$incomingQueryString.'&domainRedirectSign=1');
      exit;
    }
  }
}

Basically I'm trying to change all the address into the main.domain.com/subsite/URI_REMAINING_ADDRESS. I assume that each subsite will be aliased and using all the SEO tools provided by MODx.
The current solution that doesn't fit me is the appearance of subsite on the subdomain. Instead of having subsite.domain.com/home, it will show up as subsite.domain.com/subsite/home.

Is there anyway to use mod rewrite engine to determin the requested domain and rewrite it to the maindomain/subsitefolder?


Sincerely,
Wendy Novianto
Logged

Djamoer
Testers
*
Posts: 1,492

No one can limit a man other than the man himself.


WWW
« Reply #13 on: Nov 23, 2005, 12:46 AM »

I've been researching about mod-rewrite, and here is what I come up with, I just make a subfolder under my main modx folder, and create a new subfolder again for my other subdomain/domain. In each subfolder, I will have .htaccess file to control the redirection for that subdomain/domain.

Here is what the folders looks like
modx/
  assets/
  manager/
  subsites/
    subdomain1.domain.com/
      .htaccess
    domain2.com/
      .htaccess
  index.php
  .htaccess

Inside the .htaccess of each sub sites I paste this code: (ex: subdomain1.domain.com)
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain1.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain1.domain.com$
RewriteRule ^(.*)$ http://main.domain.com/subdomain1.domain.com/$1 [L,QSA]

I'm assuming that all the SEF options are being activated. The way how the subsites was organized inside the MODx is by seperating them in different directories and aliased the main directory of the subsites into its domain name, for example "subdomain1.domain.com".

So far it works just fine, but I'm having the same problem with the previous one, which is url address on the web browser is changing, from "http://subdomain1.domain.com/home.html" into "http://main.domain.com/subdomain1.domain.com/home.html".

Any other idea or solution? This is areally hacky solution, if xwisdome or somebody else able to handle this in more MODx way, please do so. The one that xwisdome came up with is a really good solution, except, the "subdomain1.domain.com" is being included on every subsites. So in my example above, the result will look like this, from "http://subdomain1.domain.com/home.html" into "http://subdomain1.domain.com/subdomain1.domain.com/home.html".

If the middle part of "subdomain1.domain.com" can be removed, than it will be awesome....

Thank you guys


Sincerely,
Wendy Novianto

Btw, don't use the code given above, it's not working correctly.

Logged

xwisdom
Foundation
*
Posts: 1,732



« Reply #14 on: Nov 23, 2005, 09:24 AM »

xwisdom...

I tried to modified your code, and it ended up not doing what I want it to be. With the Location header, it will only redirect the user, and it will change the url to the user.

Hi Wendy,

You code aboves does exactly what it was coded to do. It will only redirect the user the the address specified.

What I think you're trying to do is have the system "Transfer" all request for a subdomain to subdomain/subsite folder, correct? This solution (I think) can only be accomplished via mod_rewrite.
Logged

xWisdom
www.xwisdomhtml.com
The fear of the Lord is the beginning of wisdom:
MODx Co-Founder - Create and do more with less.
Pages: [1] 2 3 ... 5   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!