Posts tagged PHP

Quick Self-Exam of Writing Syntax

I was writing my update to my Perl uploader project for today when it dawned on me that my writing syntax has evolved.  I saw that in place of the usual -- I began to use almost a year ago has been replaced by // which isn’t just present in my Tweets and blog posts, but also my SMS’.  Also looking at my old (PHP) code I’ve noticed that my variable names have progressively gotten shorter; for example, in my first (fully functional) PHP project, a simple URL shortener, a typical variable had a name like

$urls_database_connection_handler

, whereas in my latest incarnation of it (it’s somewhat integrated into the Uploader), it’s simply

$qh_urls

(for query handle for urls database).  Two factors are at play: 1) The names are now much shorter and 2) I’m using caps instead of underscores to delimit words for my readability (it makes me think of Obj-C best practices, but I don’t know). Just a thought.

Code: Add sites to Social Links [UPDATE]

[UPDATE] Changed base URLs for yFrog and TwitPic in the code. And edited the name of the yFrog image.

Since I’ve launched the redesigned BradArsenault dot com, I’ve been using a WordPress plugin called Social Links to show my social links (such as to Last.fm, Digg, Flickr, etc.) and this is how to add services that aren’t included by default.

First off, I’ll walk you through adding yFrog, however this will work with any site (that is publicly accessible with a user-specific URL)

First you have to get an image for the site you want to add. This could be from the favicon.ico file from the site (look for a link to that in the site’s source code) or from an image search. You then have to dress the icon up by cropping it, giving it a transparent background (if it has empty space in the icon), and resizing it to 16×16 pixels.

This was my design process in Pixelmator

Pixelmator designing yFrog favicon

Pixelmator designing yFrog favicon

You now have to upload this to the /images of this plugin’s folder with an easy name, like yfrog.php. The next step is to add the right code to the php file.

I use Espresso by MacRabbit for my code, however any raw text editor will work (Smultron, SubEthaEdit, Coda, the Transmit built-in editor, and many others will work for this). Open the sociallinks.php in the main plugin folder.

Look down the code for the

$definitions array

and add another definition at the end (so that you would be at

array(22

if you are starting from the stock code). Add this code.

 /sociallinks/sociallinks.php
array(22,'yfrog.jpg','http://yfrog.com/%userid%','Enter your Twitter handle','yFrog'),

If you’re not familiar with PHP then you may need this help: The first quoted block (that’s an apostrophe there, it’s the non-shifted quotation mark) is the location of the image relating to that service, in this case yFrog.png. This is what we just edited and put in the /images folder of the plugin. The next portion is the link that this will go to when clicked to bring you to your user page, excluding the feature that uniquely identifies your account. Where you see %userid% is where your user name will be inserted by this script in the management page.
The next block gives you instruction as to what to enter, in this case yFrog uses your Twitter handle for your page. Finally, you have to state what this service is called.
Save. Now rename the old version of the script (sociallinks-1.php?) and upload the new script with the name sociallinks.php. Now you can go to the administrative page and select your new service. If there are errors, it’s most likely because you forgot a comma after each entry except for the last, forgot to close a quote, used the mismatched quotes, or didn’t use quotes at all.

fwiw here is what I have: (starting at line 67 of the PHP file)

 /sociallinks/sociallinks.php
array(20,'technorati.jpg','http://technorati.com/people/technorati/%userid%/','Enter your Technorati username.','Technorati'),
array(21,'friendfeed.png','http://friendfeed.com/%userid%','Enter your FriendFeed username.','FriendFeed'),

/*I added the rest of theses --BradArsenault (Nov 28/09)*/
/*Note the changes I made to TwitPic and yFrog -- these are the correct base URLs*/

array(20,'technorati.jpg','http://technorati.com/people/technorati/%userid%/','Enter your Technorati username.','Technorati'),
array(21,'friendfeed.png','http://friendfeed.com/%userid%','Enter your FriendFeed username.','FriendFeed'),
array(22,'yfrog.png','http://www.yfrog.com/froggy.php?username=','Enter your Twitter handle','yFrog'),
array(23,'twitpic.png','http://twitpic.com/photos/%userid%','Enter your Twitter handle','TwitPic'),
array(24,'qik.jpg','http://qik.com/%userid%','Enter your Qik user account','Qik'),
array(25,'wakoopa.png','http://wakoopa.com/%userid%','Enter your Wakoopa user account','Wakoopa')
);

If you want to use the icons that I used you can download them here (icons.zip)

Track My Snow Leopard Shipment!

If you remember back earlier thi year I had a post about tracking a classic Mac keyboard and mouse from eBay… well I’ve since shipped a few items on Canada Post, Fedex, and Purolator and have come up with a few PHP pages to make these pages viewable on non-secure connections and to eliminate almost all scripting (at the very least make these viewable on cell phones).  I will be releasing the source code to these pages for you to use, but in the meantime you can wait and watching with me as my copy of Snow Leopard ships across the country to me: [bradarsenault.com/track.php].