echo $phpscript

Dear friends,

at this point I’ll switch writing from german to english. I hope it may be more useful for our friends in china and other countries that aren’t that familiar with german language to follow my blog, anyway all other parts of my website are already in english so it’ll just be consistent.

What about this entry?
Last days I discovered a nice webwidget created by netvibes. It daily displays a different chinese propaganda poster from www.maopost.com on e.g. dashboard of iGoogle, on your pc/mac desktop/dashboard or on your website. It looks like this.




So I thought it’ll be nice to implement it onto my site, but as I tried I had to realize it wouldn’t work out the way I wanted to. It couldn’t be customized for my preferences, e.g. transparent background color or size of the picture etc. So I thought, why don’t you create a “widget” by yourself?

As I’m until now almost only familiar with html web-“programming” I thought of php to begin with. I had to figure out several problems, e.g. about how to concat strings, which actually is deadeasy as well as how to implement a function to format a random number into a certain fixed length format. Long story short, here is my very first php code snippet.


01 <?php
02 echo "<a href=http://www.maopost.com><img src=http://www.maopost.com/widget/logo_en_h.gif width=250></a><br><br>;
03 $maopost = rand(1,1671);
04 $isomaopost = sprintf("%04d", $maopost);
05 $link1="http://www.maopost.com/postl/";
06 $link2="-001M.jpg";
07 $maourl= "$link1$isomaopost$link2";
08 echo "<a href=" . $maourl . "><img src=" . $maourl . " width=250></a><br>";
09 ?>



Offtopic
It took me quite a while to find an acceptable solution to display php code within rapidweaver blog. Until now its handcoded and very time consuming. Appreaciate any advices to simplify this step.



It displays a random chinese propaganda poster (per siteload) from maopost.com as long as they don’t change their poster url format.

Until now I haven’t parsed the corresponding website so that it’ll not display the title and published year as the netvibes widget does. But my widget is not tagged with any labels or links, you can adjust its size on line 08 and it shows you a new poster every time you load the site instead of only one new picture / day. Please leave the maopost banner and link as the contributors ask for if you put it on your own site. As it is free for everyone to use and ”created by two enthusiastic collectors, Pierre Lavigne and Pierre Budestschu I think its fair to contribute to the authors and let the people know who did this work.

From my side you are free to use it on your own site if you like to but I suggest you ask the authors for permission in advance, esp. you want to be commercial with it. Have fun.

Here it is in
action.

@rapidweaver user: You can download this snippet (esp. for the sidebar)
here