Archive for the ‘Web Design’ Category

Sitemeter works by inserting an image and iframe into your page, so that when the browser retrieves it, sitemeter can look at the referer and know what page was visited. But you can't include image links in an XML or GIF file, so I can't tell which of the bililite webservices are being visited. But behind the scenes, all the files are PHP files, so I can use cURL to get the image file as long as I can spoof the parameters so sitemeter thinks it knows where the request came from. A little experimentation came up with this:

function getSitemeterImage(){
	// the sitemeter image parameters; obtained by inspection
	$opts = array(
		'site' => 's48bililite',
		'refer' => urlencode ($_SERVER['HTTP_REFERER']),
		'pg' => urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']),
		'rnd' => rand()/getrandmax()
	);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, 'http://s48.sitemeter.com/meter.asp?'.http_build_query($opts));
	curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_REFERER']);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	// be nice to the server (http://inanimatt.com/php-curl.php)
	curl_setopt($ch, CURLOPT_USERAGENT, 'Bililite Webservices (http://bililite.com/webservices)');
	curl_exec($ch); // get the image to tell sitemeter that we were here
}

We don't actually use the image; all we want is to let sitemeter know that we want it.

I just started using Sitemeter for tracking page visits (everyone seems to use Google Analytics, but I've used Sitemeter before and am satisfied with what I've got). Sort of depressing seeing a "1" for the visit count, but it's new as of today. Creating a widget to put in the sidebar was straightforward, since I've already created one widget:

/*
Plugin Name: Sitemeter Widget
Plugin URI: http://bililite.nfshost.com/blog/2010/12/26/simple-sitemeter-widget/
Description: Display the sitemeter.com badge in the sidebar
Author: Daniel Wachsstock
Version: 1.0
Author URI: http://bililite.nfshost.com/blog
*/ 

// WordPress 2.8 Widget code based on http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/
// and http://justcoded.com/article/wordpress-28-multi-widgets/

class Sitemeter_Widget extends WP_Widget{
  function Sitemeter_Widget(){
    $this->WP_Widget ('sitemeter', __('Sitemeter'), array(
     'description' => 'Display the Sitemeter Badge'
    ));
  } // constructor
  function widget ($args, $instance){
    extract ($args, EXTR_SKIP);
    extract ($instance, EXTR_SKIP);
    echo $before_widget.$before_title.$title.$after_title;
		echo "<!-- Site Meter -->
<script type=\"text/javascript\" src=\"http://$server.sitemeter.com/js/counter.js?site=$account\">
</script>
<noscript>
<a href=\"http://$server.sitemeter.com/stats.asp?site=$account\" target=\"_top\">
<img src=\"http://$server.sitemeter.com/meter.asp?site=$account\" alt=\"Site Meter\" border=\"0\"/></a>
</noscript>
<!-- Copyright (c)2009 Site Meter -->";
    echo $after_widget;
  } // widget display code
  function update ($new, $old){
    return array_merge ($old, $new);
  } // options update
  function form ($instance){
    extract ($instance, EXTR_SKIP);
    $this->textElement ('title', 'Title', $title);
    $this->textElement ('server', 'Server', $server);
    $this->textElement ('account', 'Account', $account);
  } // control form
  function textElement ($index, $text, $value){
    $id = $this->get_field_id($index);
    $name = $this->get_field_name ($index);
    $text = __($text); // localize
    echo "<p><label for=\"$id\">$text <input name=\"$name\" class=\"widefat\" value=\"$value\" id=\"$id\" /></label></p>";
  } // textElement
} // class Sitemeter_Widget

add_action ('widgets_init', create_function('', 'return register_widget("Sitemeter_Widget");'));

Short and sweet

I've been using Peter van der Does's AVH Amazon plugin to display my Amazon wish list (more as an "about my interests" than a "buy things and make me money") and it's worked well, allowing a random selection of books I would like to be shown in the sidebar. Now it's dead, killed by Amazon's deprecating the API to get the wish list items. It seems short sighted, especially since Amazon's wish list widget is so limited and poorly formatted (it's on the sidebar now). I may look into creating my own, if I ever have free time again.

Eternal vigilance is the price of liberty. Last month, the Young Israel site was hacked and destroyed. A little talking with my ISP's tech support reminded me that I had an old version of WordPress on the site, in a folder called "wordpress," and that it contained a vulnerability that make the vandalism possible.

When I moved this blog, I kept it updated, so I don't think it is vulnerable, but I completely forgot to remove the old one. I just changed the links to refer to the new one. Stupid! And now I've paid the price.

Well, we got just about everything restored from backups (missing some old announcements that I don't think anyone will miss), and I think I've removed any vulnerable code. I also am now the proud owner of some cool-looking hacking software that was installed on the site that I want to try to take apart and experiment with. Just more tuition paid to the school of hard knocks.

All I wanted was to get a better 404 page for the bililite.com site and to use mod_rewrite to standardize my pages. Of course, nothing is ever simple and mod_rewrite is voodoo. So it took a week of experimenting, pulling my hair and staring at a lot of 500 errors, but I think I got things where I wanted them (still don't have a very elegant 404 page, though!). To make sure I didn't have to go through this again, and to help anyone else out there, here are the things I wish I had known:

Continue reading ‘Things I Learned About .htaccess’ »

See the updated version.

I needed a date/time picker and spend a couple of hours making a simple one:

Obviously, I didn't spend a couple of hours putting this together. I wrote it quickly, then spend the hours getting it to work even remotely correctly in Internet Explorer.

Continue reading ‘Don’t Reinvent the Wheel’ »

Just added a new widget to the sidebar: the AVH Amazon Wishlist. It randomly picks items from my Amazon wishlist. Anyone reading this can feel free to buy me something, though I don't expect that (except from Stanley; you know who you are). I think it's more interesting as an indicator of the sorts of things that interest me. It's mostly all there: judaica, programming, woodworking, cooking gadgets. Interestingly, virtually no medical books. All my medical references are online or on my PDA (uptodate, epocrates, Riley Kidometer, Pediatrics, Contemporary Pediatrics). The actual books I've used in years are the picture books (Hurwitz's Clinical Pediatric Dermatology, Smith's Recognizable Patterns of Human Malformation). Almost by definition, texts are obsolete by the time they reach the editor, let only when they are published. The doctors I know still have impressive bookcases filled with medical textbooks, but they're the ones they bought in medical school and haven't opened since.

Speaking of which, there's a new edition of Hurwitz out. Hint!

I decided that this blog is mine, rather than Young Israel's, so I wanted to move it to a domain that I personally own. Thus, it is no longer at youngisrael-stl.org/wordpress, but at bililite.com/blog. Moving the blog intact was non-trivial, so I'm recording how I did it, based on mydigitallife's instructions:

  1. Create the new folder, bililite.com/blog/
  2. Create a new mySQL database on bililite.com
  3. Copy all of youngisrael-stl.org/wordpress/ into bililite.com/blog/
  4. Edit the wp-config.php file to reflect the new database name/user/password
  5. Backup the youngisrael-stl.org database into an SQL file with phpMyAdmin or some other tool
  6. In a text editor, change all the "http://youngisrael-stl.org/wordpress" to "http://bililite.nfshost.com/blog" and "/wordpress" to "/blog". note that there are both absolute and relative URL's in there, and I was changing both the domain and the subdirectory, so I had to do two replacements. I couldn't just change "http://youngisrael-stl.org" because I didn't want to change links to the actual site.
  7. Run the edited SQL file on the bililite.com database
  8. In the youngisrael-stl.org/.htaccess , add the line "Redirect permanent /wordpress http://bililite.nfshost.com/blog" to let browsers know I've moved
  9. Actually announce the change on mailing lists of people who actually read the site
Finally, jQuery UI 1.6 final is out, renamed 1.7, and it's on google ajax libraries, so it's minimized (45K for the whole thing; .27 sec to download for me, which is nothing, especially if you're loading at the end of your code so the user is busy reading the content of your site). The contributors list doesn't include me ($.widget uses $.metadata); so much for my fame and fortune. This release still has the droppable bug; looks like that's to be fixed in 1.7.1.

All I wanted to do was back up the Young Israel databases, some way more amenable to automation than phpMyAdmin. There are lots of PHP-based solutions on the web, but all seem based on mysqldump. I implemented one and found myself faced with an eyeful of אריאל מאיר יעקב בן דוד אברהם where the Hebrew names should be. Turns out this a known bug; mysqldump can't handle Unicode. There are reports of workarounds, but I spent 8 hours not getting anything to work.

So I had to write my own backup, going through each database on a server then each table in the database, writing the appropriate INSERT INTO commands (thank goodness the SHOW CREATE DATABASE and SHOW CREATE TABLE commands work correctly). It wasn't terribly miserable (not nearly as miserable it was trying to use someone else's tool that doesn't work), and now I get my  אריאל מאיר יעקב בן דוד אברהם just fine, and the backup works. I import the generated file into my local copy of mySQL and it regenerates the databases.

Continue reading ‘The Agony of Unicode (and backing up mySQL)’ »