JW Player and Shadowbox integration not working

I recently had some trouble getting JW Player to work in IE7/IE8 with Flash 10.3.183 using Shadowbox to pull it up in a pop up box. I did a ton of digging and when the dust settled I found this page on the JW Player help forums to be of the most help. One of the other posters suggested passing the parameters directly to the the player.swf file in this manner:

You can also pass in the preview image and any other variable in this manner.

Posted: October, 30 2011

register_activation_hook not working?

For a while I had some trouble getting the register_activation_hook() hook to work for a plugin. After some debugging and comparing with a plugin I had made in the past I realized that the hook for this plugin was not in the same file as that of the plugin description.

After I moved the register_activation_hook() call to the file I had placed that description in, everything worked as I expected it to.

Posted: April, 3 2011

First time using Smarty Template Engine - where to put the template directory?

I decided to give the Smarty Template Engine a go tonight. I downloaded it pretty easily and moved it to my htdocs folder to try out. My initial impression of the code was that it was pretty powerful and I was going to enjoy working with it. When I loaded it up on the browser though I was faced with some error messages. Not one likes to see errors when they haven't even started writing their own code!

So I started down the "winging it" road and decided I would learn from doing and reading the demo code (even though it wasn't working yet).

The first step is to create a test directory. My path was to C:\xampp\htdocs\smarty\test\ (I left the /lib/ directory that contains the core Smarty code in the parent directory, /smarty/. Now the thing to note is that for all intensive purposes, your web site or application is going to live inside this /test/. So when a tutorial says to create a /templates/ folder, it should be at C:\xampp\htdocs\smarty\test\templates\. It will become a bit more evident as you start using Smarty more and more, but essentially that is the standard. When you go to include a template file you are able to call just the file name. If you had put the template directory in a parent or sibling folder, you would need to use relative or absolute paths to prepend the file name.

Posted: March, 25 2011

Loading AddThis widget after the page loads

I have been working with AddThis for the past 3 days on and off. I have been trying to get it to load in the Javascript after the rest of the page loads. My reasoning for doing this is because I was looking to tie into an existing Javascript file that was included on all of the pages of a site to add the AddThis widget in. I was looking to load AddThis inside of an external Javascript file and I was so close! Here is what I was trying to inject into the code.

]]>

My initial approach was to try and load everything inside of a div element that I created inside the Javascript file.

'; menuPlaceholder.parentNode.insertBefore(newNode,menuPlaceholder.nextSibling); ]]>

The above worked excellent for embedding the code, but for some reason it wasn't executing the AddThis Javascript file at the right time. I believed that using the #domready parameter it would pause on executing the code until after the new elements had been injected.

After a little bit of thinking and debating the issue, I decided it was probably an order of operating. Normally when you include the AddThis widget the html is rendered, and then the Javascript works in on it. However, the way I have it above the html AND Javascript are injected and rendered at the same time.

So I decided to try and load the script separately. My plan was to inject it as the last item on the page, right before the closing body tag.

Lo-and-behold, the AddThis widget loaded up like a champ! So if you are having trouble loading your AddThis widget from a Javascript file, chances are it has to do with the order it is executing.

Posted: March, 23 2011

Simple Tumblr project

I recently did some work making a pretty simple Tumblr app.

I used the Tumblr API to authenticate a user login, retrieve their avatar, number of posts, username, and the last 10 posts made by them. The other option I give is to search for a Tumblr site by name, for instance, searching for 'levijackson' will pull in the two posts I have ever made on the site :) Right now there isn't much validation of input, so it may be wise to add in some for the login form and the search box.

Local storage

Something that I had been dying to play with was local storage! I finally got a chance to do so with this and I must say, pretty snazzy. I enjoyed being able to access the data using methods/object notation instead of needing to use a third party or home brewed Javascript cookie function.

Graceful degradation

Having used local storage, I didn't want to exclude any browser that does not have local storage capabilities, and so I stored some of the information as a cookie as well for the browsers that do not use local storage. In addition to both of these methods, I cached the content I retrieve from Tumblr in text files so as to not pound their servers with the tons of traffic I get daily.

The end

Anyway, you can test it out or download the code and modify it all you want.

Download

Demo

If you spot anything glaringly broken on it or have any suggestions of where to go next with it, let me know! I realize it is far from perfect, but when used right it does work well.

Posted: March, 21 2011

Posting with cURL

I like to browse Stackoverflow in my spare time to learn new things. I came upon this post about posting with cURL recently and though it was worth sharing.

The question was about whether you needed to urlencode parameters being posted. I can't say I had ever run into any problems posting with cURL before, but I was still curious of the answer.

The top answer referenced the PHP manual:

This parameter can either be passed as a urlencoded string like 'para1=val1&2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data.

I realized the reason I had never run into any problems was that I use an array to pass my values about 90% of the time. So PHP had been processing and encoding the parameters for me this whole time, which is what I figured it had been doing. What I didn't know was that had I been passing one value as a string, PHP would NOT be encoding that value for me. So make a mental note that when posting using cURL either use an array to store the parameters or else you need to urlencode() your value!

Posted: March, 13 2011

Installing memcache on xampp 1.7.4

Open up the php.ini file located at C:/xampp/php/php.ini. Add the following to the file after all of the other extension declcarations:

Believe it or not the next step took me the longest to get done. All of the instructions I read online for doing this pointed me to http://downloads.php.net/pierre/ to download the memcache dll file. Unfortunately you can only find the VC9 download on that site, xampp 1.7.4 on the other hand uses VC6. According to http://windows.php.net/:

If you are using PHP with Apache 1 or Apache2 from apache.org you need to use the VC6 versions of PHP If you are using PHP with IIS you should use the VC9 versions of PHP

I was able to find the VC6 dll after some searching and if you also require it you can download it right here. http://www.levijackson.net/public/files/downloads/php_memcache-cvs-20090703-5.3-VC6-x86.zip

Once you download the proper memcache dll you need to unzip it and place it in C:/xampp/php/ext/

The final step is to restart xampp. After that give it a go, try out some of the memcache functions found on the php manual web site.

Posted: March, 7 2011

Yet another "that is so cool" moment with Ruby on Rails

I've been focusing on areas such as migration, config, and paths lately while learning Rails. Today I made a discovery that I probably should have made earlier!

Say you have a mysql table, books, and a second table, authors. The tables would be built roughly like the following.

Based on that relationship I would add Authors model, has_many :books. To the Books model I would add belongs_to :authors. Using this relationship allows for us to easily display the relevant information. For instance, consider that you want to find all of the books a particular author wrote.

This is very convenient and eliminates the need to write methods for the model to join the two tables together. Once again RoR, you have made me wish everything was as easy to do.

Posted: March, 2 2011

SimpleXMLElement instead of a string being returned

I've been working on integrating http://square-a-day.tumblr.com for my girlfriend, Lindsay Webster's site. One road block I ran into was that Tumblr has a cap on the number of items you can pull from their XML feed set at 50. That isn't a terribly big problem though because within the XML feed there is an attribute 'total' that will come in handy.

The difficulty in retrieving the total attribute

I haven't full on worked with the PHP5 SimpleXML class in about a year so I was a bit rusty to start with. I quickly put together the following code to garner the first 50 posts and also to retrieve the total number made on the Tumblr account (although for debugging purposes I only retrieve 2).

So the above should print out the total number of squares. Instead I get the following:

SimpleXMLElement Object ( [0] => 98 ) 

I had never seen such a thing before and I wasn't even sure how to access it. I tried reading through the docs and finally I hit on something in the SimpleXML examples page. Juan Herrera wrote, "When using simplexml to access a element the returned object may be a SimpleXMLElement instead of a string." He also linked to a bug report where it was declared this was intentionally done. I can't find any further information on it was done this way, but they did thankfully give a helpful method of fixing it, type casting. If you remember that foreach statement I had, I only had to make one minor adjustment to it to make things work.

Posted: March, 1 2011

Parsing an e-mail message with PHP's IMAP functions

First you need to setup the connection to the mailbox, Google has a pretty good intro on finding the hostname for a Gmail mailbox.

The biggest trouble I had when trying to parse the messages was that if I simply called for the message in part 1 (like on line 16 above), it would return the plain text version of the e-mail... which includes MIME type headings and so forth. Very hard to anticipate for and to parse out.

After doing some reading online, which included the PHP docs, I came across these two useful pages. PHP doc on the imap_fetchbody function and I found this article on Tux Radar about Dealing with MIME-encoded messages. The parts of a message vary depending on what is being sent. An e-mail with an attachment, for example, has a different part 1 than an e-mail with no attachment.

With an email message that only has a text body and does not have any mime 
attachments, imap-fetchbody() will return the following for each requested 
part number:

(empty) - Entire message
0 - Message header
1 - Body text

With an email message that is a multi-part message in MIME format, and contains
the message text in plain text and HTML, and has a file.ext attachment, 
imap-fetchbody() will return something like the following for each requested 
part number:

(empty) - Entire message
0 - Message header
1 - MULTIPART/ALTERNATIVE
1.1 - TEXT/PLAIN
1.2 - TEXT/HTML
2 - file.ext

Now if you attach the above email to an email with the message text in plain 
text and HTML, imap_fetchbody() will use this type of part number system:

(empty) - Entire message
0 - Message header
1 - MULTIPART/ALTERNATIVE
1.1 - TEXT/PLAIN
1.2 - TEXT/HTML
2 - MESSAGE/RFC822 (entire attached message)
2.0 - Attached message header
2.1 - TEXT/PLAIN
2.2 - TEXT/HTML
2.3 - file.ext

- Courtesy of the PHP docs

Hopefully my code above starts to make more sense now that you see a chart of the different parts of an e-mail. I first check for part 1.1 as that included the plain text e-mail (the message being sent), if there is nothing there I revert to checking part 1. I found that most of the time if 1.1 was empty it was because there was no attachment with the e-mail.

Posted: February, 27 2011

Next Page