[pmwiki-users] CSS for one (or all) tag in _a single_ page (inline or in head)

Patrick R. Michaud pmichaud at pobox.com
Fri Aug 25 14:33:57 CDT 2006

On Fri, Aug 25, 2006 at 08:15:42AM +0100, Hans wrote:
> Pm wrote earlier:
> > Another possibility is for the (:stylesheet:) markup to generate
> > tags like
> > 
> >     <link rel='stylesheet' href='{$PubDirUrl}/cache/{$FullName}.css' type='text/css' />
> > 
> > and have the stylesheet data copied from the referenced page into a
> > public cache file that is automatically updated whenever we
> > detect that the stylesheet page has changed.  This could reduce 
> > bandwidth a lot.
> This looks very interesting and promising.
> But how can one achieve the copy and automatic update?

I started to write out the code to do this, and then realized
it could introduce a security hole whereby a malicious author 
could then use (:stylepage:) to eventually be able to see 
the contents of read-protected pages.  

Essentially, the code to handle the caching would look something
like the following:

    ## $stylepagename holds the name of the page to be included

    ## find the name and url of the css file in pub/cache/
    SDV($PubCacheDir, "pub/cache");
    SDV($PubCacheUrl, "$PubDirUrl/cache");
    $cssfile = FmtPageName("$PubCacheDir/{\$FullName}.css", $stylepagename);
    $cssurl = FmtPageName("$PubCacheUrl/{\$FullName}.css", $stylepagename);

    ## if the cached .css file doesn't exist or is older than the
    ## latest site modification, we need to re-generate it
    if (@filemtime($cssfile) < $LastModTime) {

      ## remove the outdated cache file

      ## read the stylepage, if we can
      $stylepage = 
        RetrieveAuthPage($stylepagename, 'read', false, READPAGE_CURRENT);

      ## if we couldn't read it, we're done
      if (!$stylepage) return '';

      ## if we could read it but it's read-protected, we can't cache it.
      ## so, put its contents into $HTMLStylesFmt[] and return
      if ($stylepage['=auth']['read']) {
        $HTMLStylesFmt[] = $stylepage['text'];
        return '';

      ## save a copy of the text to the cached css file
      $fp = fopen($cssfile, "w");
      fputs($fp, $stylepage['text']);

    ## okay, the cache file is up-to-date, so put a link to it into
    ## $HTMLHeaderFmt[]
    $HTMLHeaderFmt[] = 
      "<link rel='stylesheet' href='$cssurl' type='text/css' />";

    ## we're done
    return '';

More information about the pmwiki-users mailing list