Request - 'Dynamic Extension'

Discuss PivotX 2.0.x extensions here, and view extensions that are available for download.

Request - 'Dynamic Extension'

Postby phigmov » Mon Oct 06, 2008 7:45 pm

Hi all,

I realise there are more pressing priorities for the team but I thought this idea for an extension had some merit and might not be to hard to whip up if someone had the skills.

Basically what I had in mind was a an extension that altered the look of the site based on a particular condition.

A specific (and simple) example would be - update the header (or theme) based on a rss weather feed.

Like this - ... p-and-css/

So a form would take a postcode and then allow you to select four header images (or themes) based on the output of the feed.
If for some reason the feed is inaccessible then the header would remain the same so you don't end up with a situation whereby your site is blank.

The extension would be generic enough that people could come up with whatever feed and conditions they like through recoding it themselves (ie using a weather feed is probably a common scenario).

Posts: 6
Joined: Sat May 17, 2008 10:15 pm

Re: Request - 'Dynamic Extension'

Postby Bob » Mon Oct 06, 2008 7:58 pm

That's a nice trick, but rather specific for one purpose. However, the example there should be really easy to use in PivotX..
Code: Select all

   /* get xml, find match */

   /* get the weather from Yahoo */
   $data = get_data("");

   $weather_class = format_result(get_match('/<yweather:condition  text="(.*)"/isU',$data));
   $this->assign("weather_class", $weather_class);

   /* debug to see what we got back */
   //echo '<pre style="background:#fff;font-size:12px;">['; print_r($weather_class); echo ']</pre>';

   /* format the result */
   function format_result($input)
      return strtolower(str_replace(array(' ', '(', ')'), array('-', '-', ''), $input));

   /* helper:  does regex */
   function get_match($regex,$content)
      return $matches[1];

   /* gets the xml data from Alexa */
   function get_data($url)
      $ch = curl_init();
      $timeout = 5;
      $xml = curl_exec($ch);
      return $xml;


The only changes i made, are that i used [[php]]..[[/php]] to use PHP inside Smarty code, and i used $this->assign() to set the variable to use later on:

Code: Select all
<div class="header header-[[ $weather_class ]]">

I did this for two reasons: First, it looks cleaner, i think.. Secondly, for security purposes, every [[php]] block has it's own local scope, in which you can't just use global variables. So, i set it as a Smarty variable to use later on.

The other steps should work as-is.. Let me know if this is helpful!
Lead Developer
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: Request - 'Dynamic Extension'

Postby phigmov » Wed Oct 08, 2008 1:19 am

Cheers Bob - I'll give this a crack and let you know how I get along.
Posts: 6
Joined: Sat May 17, 2008 10:15 pm

Re: Request - 'Dynamic Extension'

Postby phigmov » Tue Oct 14, 2008 4:55 am

OK I gave this a go.

Basically I inserted the initial chunk of code into _sub_header.html and if I put this into the head section

<div class="header header-[[ $weather_class ]]">

it returns

<div class="header header-partly-cloudy">

Which is cool

Unfortunately the header image disappeared - I've tried a few variations in terms of defining the header in the pivot_default.css to return an image but had no luck.

I tried this

.header .header-partly-cloudy {
height: 180px;
background: url(images/header_dark.jpg);

and also seperating out the .header and .header-partly-cloud bits but no joy.

I'm sure theres something simple I'm missing but not being much of a css guru I'm unsure how the div class needs to relate to the actual css to present an image based on the feed result.

Any tips ?

Thanks in advance,
Posts: 6
Joined: Sat May 17, 2008 10:15 pm

Return to 2.x Extensions

Who is online

Users browsing this forum: No registered users and 2 guests