Dynamic CSS files

I had always wished CSS files weren’t so static so you could do different things at runtime. It turns out you can do it, but exercise common sense. The exact plan you take depends on how often the CSS “variables” change value. If it’s not too often you might want to “precompile” the style files into static and just use them the old style way.

Here is how you can use PHP to do ‘on-the-fly’ CSS files.

  1. Instead of including a static css file include a file with the php suffix as below:
    <link rel='stylesheet' type='text/css' href='css/style.php' />
    
  2. Make sure your style.php file returns the appropriate headers for a text/css mime type as below:
        header("Content-type: text/css; charset: UTF-8");
    
  3. Now set up variables in your style.php very much like you would for a view template:
     $mainUrl = "http://dorkage.net";
     $mainHeaderColor = "#FE0EDE";
    
  4. Refer to your variables using echo
    #header {
       background: url("<?php echo $mainUrl; ?>/images/header-bg.png") no-repeat;
    }
    a {
      color: <?php echo $mainHeaderColor; ?>;
    }
    

CSS Tricks.com reported a different way to do this: This match rule in htaccess matches any file with style in it’s name and gets parsed as PHP thusly:

<FilesMatch "^.*?style.*?$">
SetHandler php5-script
</FilesMatch>

They speculate that you wouldn’t be able to take advantage of the automatic cacheing that is normally provided for style files. However, you could precompile your style.php by running it through CLI php each time you update the “variables” thusly:

php style.php > style.css

and just include the resulting css file the normal way

Listen to this post Listen to this post

PHP Elephant Plarn Geek Backpack

PHP Elephant Plarn BackpackPHP bag back viewphp-backpack action shot Here is my latest geeky plarn project. It’s been a long time in the making. I’m very proud of how long it took me to get enough bags to do this project, and I have to say I didn’t even get all of them myself. I fashioned the bag as a backpack rather than a shopping bag so I could operate it hands-free. I got the straps too long, so I just tucked up the extra strappage. I can always undo that if a larger person ever uses the backpack. My try at doing the PHP elephant was a limited by the resolution of this large needle knitting. Also he had to be vertical, and he had to be across the short way so that he would have the right orientation and so that he wouldn’t be covered up when the top is closed. I have the pattern I created for the elephant if anyone really wants it. You could probably improve it with a slightly finer resolution–I only had 30 st of width to work with.

Listen to this post Listen to this post

Lingering reservations about ORM

I have always had reservations about locking myself into a strict Object Relational Model scheme for the same reason I have been allergic to Windows. I was never able to articulate exactly why but my friend Juozas Kaziukėnas has brought it into sharp focus in his latest blog post on Doctrine.

Here’s the deal: I played with and studied Doctrine and I found it to be the most flexible and powerful of all the data mapping systems I have seen. Plus, Zend Framework is moving to it, so eventually I think it will be completely integrated with Zend Framework whether I like it or not. I had some concern due to alarming memory usage statistics reported when using Doctrine. But it seems that (as is often the case) the bad performance is the result of programmer ignorance, and not inefficiency of Doctrine itself.
Continue Reading…

Listen to this post Listen to this post

Zend Framework and Doctrine

doctrine_iconWell it’s looking like Doctrine is the heavy weight data mapping solution of the lot. Zend Framework was often criticized for having no serious Model methods. Models was just sort of where you put your nuts and bolts database code. Some folks like the structure of the Active Record model that you see in Rails some other PHP frameworks. Sure it makes it dead easy when your tables map pretty straightforwardly onto your objects but makes it harder to have complex objects involving many tables. Zend was working on their own Zend_Entity package to remedy this, but they have abandoned it in favor of integrating Doctrine. The Zend Roadmap for the future calls for tight integration of Doctrine with the framework, so there will probably be some additional automatic linkage, with the view to the framework user’s code being smaller. But both ZF 2.0 and Doctrine 2.? are for PHP5.3, which is some time down the pike for ordinary folks. On the ZF Wiki there is a proposal to integrate current versions, at least to some extent. The symfony camp are hollering that Doctrine automatically “just works” in symfony, and that’s great. But for now you do have to do a little work to integrate it with ZF.
Continue Reading…

Listen to this post Listen to this post

How to integrate a jQuery plugin into Yii Framework

I have been studying up on Yii framework as a potential alternative to Zend. It has its pluses and minuses. Yii framework comes with jQuery included at the core. It was ridiculously easy to download a jQuery plugin, drop it in as a black box, follow the instructions for the front end, and it just works. I used the star-rating plugin. If you have a rating for a piece of content represented as a number such as 3.642/4 on a scale of 0-4, it is much more Web 2.0 friendly if you represent that graphically. Star-rating uses pimped up radio buttons to represent this number as five fractional stars. It also does the front end of dynamic interactive ratings, and as soon as I get my ajax back-end working on that I’ll post that too. Since the actual code being typed in is illegible in the video, I have included it in this article.

Continue Reading…

Listen to this post Listen to this post

Twitter list apps

They couldn’t be too long in coming! The best thing about Twitter is its API. I was told by someone in the know that 90% of Twitter’s traffic comes through its API, not through people directly surfing it. Anyway, the new lists are GREAT. They should have been there from the get-go but oh well. Here is Twitter’s widget to track lists. This is my geek list. Since I don’t know any cool automated listing management tools yet, these geeks I put on here by hand. If you want to be on it and you’re not, just ask.

Listen to this post Listen to this post

Twibbons for Toonlet


Here’s a little Twitter app for you while we all wait for some serious list apps: This one is called twibbon, and what it does is overlays a little icon over your twitter avatar to show you support something. First I placed the zend framework one, then I created my own for toonlet, of which I am a rabid fan. Then it tweets it and invites all your followers to place one as well. The little widget keeps track of how many supporters it has. You can also do Twibbons for facebook.

Listen to this post Listen to this post

Toonlet with Audio


I just clipped each individual frame of one of my toonlets and put them in an open office presentation. Then I fired up Berio and ran the slideshow fullscreen while I read the lines. Then I imported the whole thing into IMovie, clipped the beginning and end, compressed it a little and uploaded it to Youtube.

Listen to this post Listen to this post

Berio Free Video Screen Capture for Leopard

Camtasia is awesome, but pricey. For the likes of me, who doesn’t do video screen capture for a living, the price just isn’t justified. Leopard comes with an app to do capture, but it requires a hookup to a MacOSX server. Out of luck again. Enter Berio. Simple Straightforward, and does the job. You can talk while you’re mousing as well. Downside: Five minute limit.

Free download from http://www.juniortan.com

Listen to this post Listen to this post

Scary Facebook Hackage

Paul Fenwick graced us with the following presentation at Barcamp Melbourne. Armed with only the documentation from Facebook’s API he proceded to submit queries to their query engine and it is amazing what he dug up on the volunteers who agreed to let him “hack” their accounts.

Bottom line: Facebook apps are scary because they open your info veins via the back door of applications shared with your “friends.” I don’t know about you but I have quite a few non savvy friends who are nowhere as paranoid as I am. I like using Facebook to keep up to date with my friends, but I don’t want people dredging up stuff on me via my friends’ lack of savvy. So your only hope is to disable *ALL* facebook apps.

Listen to this post Listen to this post