Tags: PHP
Disqus Plugin
2008/10/29 @ 15:03
The first version of the Disqus plugin has been released!
The Disqus plugin allows you to use comments from the social commenting website Disqus. It embeds javascript to show comments when viewing a particular blog post and shows how many comments a post has when viewing a blog post list. Find out more about what Disqus does here. Read more about the plugin here.
Download: disqus_plugin-0.1.zip
New Sweetcron Homepage
2008/09/03 @ 22:02![]()
I just finished implementing sweetcron on my homepage. It's a pretty architecturally bare-bones but slick feed aggregator that makes a page containing all the most current information about you or what your are interested in. This page is called a "lifestream" and I liked the concept because I'm a busy person and I want to make publishing to my homepage easier so that it doesn't become dusty and so I don't have to create blog posts on anything and everything just to get a blurb on my homepage.
It basically aggregates feeds and puts the entries in your lifestream. Your twitter, digg links, blog entries can all end up in the same place. nice. It includes some basic blogging functionality but it's pretty lame and I have too much invested in b2evo to give it up so I stuck with that for my blogging. I just simply import my blog RSS feeds into sweetcron.
Sweetcron is made by Yongfook, a local web consultant here in Tokyo. I find him a bit pretentious but he seems quite popular. He has a habit of singing in video blog posts and speaking in a voice that feels to outlandish to be real. But for any faults he might have he seems to be successful and competent at consulting.
His programming could be better though. I'm glad he made Sweetcron because it allowed me to do something I had been wanting to do for a while, but it required a bit of programming to get working properly. It has a few bugs and the default install is pretty unusable. It's written using codeigniter which is ok but sweetcron doesn't support some of it's features properly. For instance, using the database table prefix causes sweetcron to throw SQL errors. His codeigniter templates are simply PHP code files which I don't like because they end up being programs themselves and don't separate logic and presentation very well. Codeigniter has it's own templates but they're lame so I kind of wish he used Smarty which I've had good experience with.
That said it was still pretty easy to implement and get integrated with the b2evolution site and I'm pleased with the results.
Google Analytics for Mobile Sites
2008/05/23 @ 20:13I implemented tracking using Google Analytics for my company's mobile sites using a technique described by Peter van der Graff on his site. The technique involves performing a GET to to an image on Google's server and passing it a bunch of options. Incidentally this is because Javascript can perform gets of images but not gets for any other kinds of content (as an aside, this kind of protection seems usless since the server could return any kind of content in wants to the javascript even though the GET has an image in the url. Maybe someone could enlighten me).
Peter originally came up with the idea because he wanted to track hits to a RSS xml url (which also seemed strange to me since the rss aggregator could read it as many times as it wants and doesn't give much insight into the number of readers, but I digress), or to another type of file download (image, pdf, etc) which wouldn't trigger the javascript that Google uses for Analytics.
One important difference between his motives and mine were that I'm tracking hits to a mobile site. Doing analytics on the server side are important since most phones (in Japan at least) don't support javascript. I also, because of the differences in what I was doing, needed to make some changes to how his script worked. Since I'm not tracking downloads or rss hits, I care about things like sessions, language, and user agent (why Peter didn't also care about this I'm not sure).
So I modified his code as follows. I forward the language and user agent of the client to Google Analytics so that I can track these things properly. I also pass my own cookie number so that Google Analytics can aggregate page hits from the same user into a session. I also make use of the user var to track hits to different customer's web pages. The example is in PHP but it could be easily translated into another language.
Note that, because of the use of stream contexts, this code will require a version of PHP >= 4.3.0.
| $var_utmac=MOBILE_GOOGLE_ANALYTICS_CODE; //enter the new urchin code | |
| $var_utmhn=WEB_DOMAIN; //enter your domain | |
| $var_utmn=rand(1000000000,9999999999);//random request number | |
| $var_cookie=$session; //cookie number | |
| $var_random=rand(1000000000,2147483647); //number under 2147483647 | |
| $var_today=time(); //today | |
| $var_referer=$_SERVER['HTTP_REFERER']; //referer url | |
| $var_uservar=$storeinfo['storeid']; //enter your own user defined variable | |
| $var_utmp=$_SERVER['REQUEST_URI']; // request uri | |
| $urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=1&utmn='.$var_utmn.'&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn='.$var_utmhn.'&utmr='.$var_referer.'&utmp='.$var_utmp.'&utmac='.$var_utmac.'&utmcc=__utma%3D'.$var_cookie.'.'.$var_random.'.'.$var_today.'.'.$var_today.'.'.$var_today.'.2%3B%2B__utmb%3D'.$var_cookie.'%3B%2B__utmc%3D'.$var_cookie.'%3B%2B__utmz%3D'.$var_cookie.'.'.$var_today.'.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D'.$var_cookie.'.'.$var_uservar.'%3B'; | |
| $header = ''; | |
| //Set the language to that of the client so analytics can track it. | |
| if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { | |
| $header = 'Accept-language: '.$_SERVER['HTTP_ACCEPT_LANGUAGE'].'\r\n'; | |
| } | |
| //Set the user agent to that of the client so analytics can track it. | |
| if (!empty($_SERVER['HTTP_USER_AGENT'])) { | |
| $header = 'User-Agent: '.$_SERVER['HTTP_USER_AGENT'].'\r\n'; | |
| } | |
| $opts = array( | |
| 'http'=>array( | |
| 'method'=>'GET', | |
| 'header'=>$header | |
| ) | |
| ); | |
| $handle = fopen($urchinUrl, 'r', false, stream_context_create($opts)); | |
| $test = fgets($handle); | |
| fclose($handle); |
MDB2 transaction bug
2007/11/12 @ 11:52There is currently a bug in the current stable release of MDB2 (2.4.1) that breaks transaction support with MySQL databases. It seems to occur anytime the server cababilities are checked twice (This basically means that it occurs when creating multiple connections to the database).
After running into this bug I took a dive into the code for MDB2 and found that was caused by the use of a static variable that is used to determine if the capabilites were already checked or not, including whether transactions are supported or not. Basically you make one connection to the database and everything is fine, it checks the capabilities and finds that transactions are supported and sets a class member variable indicating this. However, when making the second connection, the server capabilities are checked in the new object. The member variable of the new object that specifies if transactions are supported defaults to false, but the function that actually checks the capabilities checks the static variable to see if they were already checked and skips checking again leaving the new connection object with transaction support set to false.
Seems like a silly oversight to me, but one that caused me a headache for a couple hours. I looked to see if I needed to submit a bug report and/or patch but it seems that someone has already done so. The change should be in the next stable version but I need to patch my currently running servers so that transaction support is enabled in the mean time.









