0

I have a social content publishing site maintained in Drupal 7. I want to show content only specific to a user when everyone visits the site using the user's user name as the subdomain.

For example when the mail site is www.example.com

And the user is john

When people visit the site using URL john.example.com

I want to show only the content created by John, like that is his own site or book.

When people visit the site www.example.com they shall see all content including John's content also. This may mean Drupal 7 content shall be as usual , only the subdomain shall show content created by John.

It is not clear whether this can be achieved by Domain Access module, hence asking here to get more targetted answer from any one who may have done something like this.

2
  • Subdomains are considered as separate sites by Google, for simplicity avoid creating sub domains based on user names. – AgA Jan 24 '14 at 5:14
  • I want the user to have a unique URL so they can share it with all to showcase their own content, and also have a way to let people know that there is a bigger site having more of such users having their content. Even if that subdomain gets identified as a separate site logically it will be the exact concept about it in the users mind. – Tushar Joshi Jan 24 '14 at 7:34
1

You're really just passing an argument ("john") to a view (or multiple views, view blocks, etc.) to control what content is being displayed. I'm sure there is a way to do this in domain access but you can bypass that overhead by adding the logic in the view itself as a contextual filter. In rough detail:

  • Create your view listing the content you would want to show
  • Add a contextual filter based on Content: Author uid, and select 'provide default value'
  • I would recommend using 'PHP Code' to provide your default value and having it return value from a custom function which you can place in a module for better maintainability, ex: return _my_custom_function();

Your custom function should be returning the UID of the user you are looking for and could look something like this:

function _my_custom_function() { 

  $domain = $_SERVER['server_name']; //reserved php variable
  $host = explode('.', $domain);
  $subdomain = $host[0]; // probably a more elegant regex to use here.. 

  // your code here that takes the subdomain 'john', sanitizes it, runs security checks, then pulls the uid for this username from the user table or wherever

  return $uid;
}
0

I've worked on Subdomain module in D6 so I can tell only about D6 version. Using it you can easily show users on each subdomain.

Here is what Subdomain page says:

OVERVIEW:

Automatically creates subdomains and places content on them. There are 4 modes:

User: e.g. "Mary" and content at http://mary.example.com

You can create a View which lists user posts based on url or you can write a simple module which should be simple enough.

After you've done this, use Content Access module to decide what to show on which domain. You may not even need the Content Access module for what you want to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.