Fork me on GitHub

Host-Specific Themes, Templates, Overrides  Bottom

  • Does anybody know if there is an existing method to allow different hosts on a given domain to use different templates in pnRender?

    The concept is as follows (think of a setup like typepad, webex, or other site where users or organizations get their own "hostname" on top of the service's domain name). ClientA uses a service on example.com. Example.com wants to provide a "nice" URL for ClientA to give out to their own customers like clienta.example.com. This could possibly go a step further and select a completely different theme based on the hostname, so now, example.com can allow a custom theme/skin for their clientA.

    I think that multisites could handle this situation, but it might be a little overkill. After looking at the pnRender code, I think it's possible to extract the hostname and add a host-specific (or hostname-specific) search path for templates inside pnRender. Something like themes/mytheme/pntemplates/hosts/hostname/ should work and would allow a simple way to offer the functionality I describe here in addition to other more standard situations like mobile.example.com, wap.example.com, etc...

    My other option is to build a simple module called during pnRender or pnUserGetTheme which would do a lookup on themepath for a given hostname, uri, or URL parameter. This might make for less hacking on the core, but I would have to create hidden themes for each of my clients and that still does not cover mobile/pda/wap setups and would still have to fall back to the site's current/default theme.

    For completeness, a wildcard DNS entry is required to point all hostnames not otherwise specified to the webserver of your choice. If you have multiple webservers and need to manually load balance, you could copy your default PN codebase to the other servers and point some of your client hostnames to the new server.

    Any prior experience with something like this would be greatly appreciated. I have to come up with something, so I'll report back with the results later.

    Chris

    --
    Chris Stevens, CEO
    OpenTaxi Systems LLC
    866.OPENTAXI
    www.opentaxi.com
    On-Demand Air Taxi Reservations Platform, Flight Reservations, Consulting.
  • hack function _load_config() in pnTheme.class.php like below.

    the else part is different from elseif part only at


    Code

    $server = pnServerGetVar('SERVER_NAME');
    $customargs = $server/$this->module.'/'.$this->type.'/'.$this->func.$customargs;


    Here is the code

    Code

    // code hacked
    } else {
        $server = pnServerGetVar('SERVER_NAME');
        $customargs = $server/$this->module.'/'.$this->type.'/'.$this->func.$customargs;
        // find any page configurations that match in a sub string comparison
        $match = '';
        $matchlength = 0;
        foreach ($pageconfigurations as $pageconfiguration => $pageconfigurationarray) {
            if (stristr($customargs, $pageconfiguration) && $matchlengh < strlen($pageconfiguration)) {
                $match = $pageconfiguration;
                $matchlengh = strlen($match);
            }
        }
        if (!empty($match)) {
            $file = $pageconfigurations[$match]['file'];
        }
    }
    } elseif {
        $customargs = $this->module.'/'.$this->type.'/'.$this->func.$customargs;
        // find any page configurations that match in a sub string comparison
        $match = '';
        $matchlength = 0;
        foreach ($pageconfigurations as $pageconfiguration => $pageconfigurationarray) {
            if (stristr($customargs, $pageconfiguration) && $matchlengh < strlen($pageconfiguration)) {
                $match = $pageconfiguration;
                $matchlengh = strlen($match);
            }
        }
        if (!empty($match)) {
            $file = $pageconfigurations[$match]['file'];
        }
    }


    thanks

    s. moon
  • I was out of town, but wanted to say thanks for the input! I'll try it out the first chance I get.

    --
    Chris Stevens, CEO
    OpenTaxi Systems LLC
    866.OPENTAXI
    www.opentaxi.com
    On-Demand Air Taxi Reservations Platform, Flight Reservations, Consulting.
  • IMoon's code in this thread will work great for PN 0.800.

    Here's a solution to the host-specific theme issue for PN 0.764. This has not been fully tested, but seems to work for me.

    Insert the following code into includes/pnUser.php just after the "User theme" logic and just before the "default site theme" logic in the function pnUserGetTheme.

    Code

    // Custom theme selection based on hostname
        $server = pnServerGetVar('SERVER_NAME');

        // grab the hostname from the servername
        $server = explode('.',$server);
        $servertheme = $server[0];

        // try to match the server name with an active
        // Xanthia theme
        if (!empty($servertheme))
        {
          $themeinfo = pnThemeInfo($servertheme);
          if ($themeinfo && $themeinfo['active'])
          {
            $theme = $servertheme;
            return $servertheme;
          }
          else
          {
            // hostnames in urls will be all lowercase, so
            // try uppercasing the first letter to match our
            // normal theme naming schemes
            $servertheme = ucwords($servertheme);
            $themeinfo = pnThemeInfo($servertheme);
            if ($themeinfo && $themeinfo['active'])
            {
              $theme = $servertheme;
              return $servertheme;
            }
          }
        }


    Create a standard Xanthia theme named after the hostname you want to use (ex. "mobile").

    Upload and activate it.

    If your webserver is configured to point all hostnames for your domain at your Postnuke installation, you should see your site rendered with the new theme when you go to mobile.yourdomain.com.

    This works because pnUserGetTheme handles most of the include path sourcing for templates and plugins between Xanthia, pnRender, and the Core.

    Any improvements or extensions on this are certainly welcome.

    Standard disclaimers apply about altering the PN Core and upgrade-compatibility.

    Chris

This list is based on users active over the last 60 minutes.