Fork me on GitHub

[solved] style.php & $imagepath  Bottom

  • I'm trying to develop a theme that uses a dynamic stylesheet: style.php

    In it, I would like to references some background-images ala:{code]' background: URL('.$imagepath.'/lr.gif) no-repeat bottom right;'."\n".
    [/code]The problem is that $imagepath seems to be completely empty.

    for that matter, so do $pagewidth, $lcolwidth and $rcolwidth.

    the $colors arrays seems to be available however.

    Any idea how to solve this issue?
  • OK, I've corrected this problem.

    The $pagewidth, etc vars seem to work now, but I'm not sure what has changed, so I can't explain it.

    In order for the $imagepath to be available, I inserted the following at the top of style.php

    Code

    <?php
    global $imagepath;
  • Please note that $imagepath is not available unless the theme is selected as your theme (or the default site theme). It cannot be accessed upon theme init or viewing from the theme listing in Xanthia. :(

    Here's how I got around it: (this in style.php)

    Code

    function ch_getimagepath($skin)
    {
        $path = pnGetBaseURI();
        $directory = 'themes/'.pnVarPrepForOS($skin).'/images';
        if($path!='') $path.='/';
        $imagepath=$path.$directory;
        return $imagepath;
    }
    global $imagepath;
    if ($imagepath == "") $imagepath = ch_getimagepath($skin); // imagepath not available on themeinit
    if (substr($imagepath,0,1) <> "/") $imagepath = "/".$imagepath;

    $stylesheet =
    '   background: url('.$imagepath.'/ur.gif) no-repeat top right;'."\n";
  • I had to modify it a little more because the $imagepath is sometimes returned as the *current* imagepath and not the one for the theme being installed... so the bottom part of the code there should look like:

    Code

    global $imagepath;
    if (!strpos($imagepath,$skin)) $imagepath = ch_getimagepath($skin); // imagepath doesn't contain theme name
    if ($imagepath == "") $imagepath = ch_getimagepath($skin); // imagepath not available on themeinit
    if (substr($imagepath,0,1) <> "/") $imagepath = "/".$imagepath;

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