Jun 29 2009

WordPress Shortcode To Generate A TinyURL For Any Post

TinyURLs can be very useful when you have a long url to type into something like an iphone or some other mobile device where the keyboard is rather tedious. On a few of my sites I was looking for a way to automatically generate a tinyURL with the least amount of effort. Since I use wordpress for most of them I decided to go with a shortcode.

Shortcodes seem to be gaining a fair amount of attention in the wordpress community and with good reason. The Shortcode API, which was new in wordpress 2.5, is a simple set of functions for creating macro codes for use in your posts. Shortcodes are written by providing a handler function and they accept parameters too. Here is a wordpress shortcode to generate a tinyURL for a post.


//Generate Tiny URLS For A Post 
function get_tiny_url($arguments)
{
  if(empty($arguments))
    $url = get_permalink($post->ID);
  else
    $url = urlencode($arguments['url']);
  if($url)
    {
      $tiny_url = 'http://tinyurl.com/api-create.php?url='.$url;
      $new_url = file_get_contents($tiny_url);
    }
    else
      $new_url = "Error";
    return $new_url;
}

add_shortcode('small_url', 'get_tiny_url');

If the url parameter is not defined then the function will attempt to use the wordpress function get_permalink($post->ID) which will return the current posts url. Also you can pass in a parameter if you want to show a tinyURL to another location. Using curl instead of file_get_contents would probably be faster but I didn’t want to make the example to long. The add_shortcode function is what tells the API to use the get_tiny_url function when it encounters the small_url shortcode. Note that this will call on the tinyurl api every page view so it would probably be prudent to set the tiny urls in the database so you only have to check once on a production site although I’m not sure if they expire or not.
This shortcode can be called in the post by typing :

[small_url]  // or
[small_url url='http://codytaylor.org']

Share

Jun 17 2009

Generate A Tiny URL On The Fly With PHP

Uniform resource locators (URL) are starting to get very long and I’m getting sick of typing ridiculously long strings into safari on my iphone. I don’t really care about the extra bandwidth, It’s just annoying when you’re on the phone telling someone to go check out a 67 character long url and they mistype it three times.

I’ve just started using the tiny url service and so far it’s been useful. On one of my sites I wanted to generate a tiny url for each of my pages to make them quicker to type in and also so people don’t know what get variables I’ve set until they get there. Here is the PHP function that I used to generate a tiny url for every page on the site.

There doesn’t seem to be any documentation at all on the Tiny URL website about this so I’m not sure if it’ll change in the future.
This function passes your desired url to the api-create.php script on the tinyurl domain which returns a nice short url that isn’t a pain to put into your iphone.


function get_tiny_url($url)
{
  $new_url = file_get_contents('http://tinyurl.com/api-create.php?url='.$url);
  return $new_url;
}

$tiny_url = get_tiny_url("http://codytaylor.org");

Not much to it but it made my life easier.

Share

May 24 2009

Stream Video To The Iphone Using Tversity

Stream Video to Iphone with Tversity

After using Tversity for quite some time to stream my media to my Xbox 360 over my local network, I decided I wanted the same functionality on my iphone.
This is how I did it:

Logged on to my wifi with my iphone and pointed safari to: 192.168.2.10:41952 which is the ip address of my tversity windows server.
41952 is the port that the tversity mediaserver listens on.

I was then shown a nice and easy to navigate web interface to browse through all my folders.

After locating a basic xvid tv show I selected “Play in Media Player”.

The iphone loaded the media player and seemed like it was going to load the movie but then this error popped up.
“This movie format is not supported”.

I searched and searched for a solution to this but found none so I transcoded a video file using one of the many ipod touch video converter programs and added it to my media in tversity.

When I browsed to this file in Tversity and clicked play it worked.
It’s kinda a pain that Tversity can’t handle converting these files on the fly but it’s still useful to watch videos on my mobile

Share

May 23 2009

Iphone Lag Fixes

I’ve been spending way to much time on my iphone lately and It’s been becoming a little unresponsive. When I scroll I notice the refresh rate is delayed and loading programs like phone, sms and safari are delayed. At first I thought that my theme was the cause but even after turning off all winterboard effects I still have the same problem. I decided to research the issue and here are my results.

  • The iphone is said to never shut a program down so the memory of the device is getting saturated. To cure this you need to reset the device.You would think that powering down and back up again would do this but apparently you need to hold the power button and the home button at the same time until the iphone shuts down.
  • Remove unused programs. As soon as I got rid of a few of the apps that I never use the phone started responding a lot quicker but still not quick enough.
  • Turn off ssh. Running the ssh daemon in the background is using resources. If you’re not scp’d or ssh’d into the phone at the moment then why do you have it running?
  • Turn off the GPS services. If you need it then turn it back on. In Settings => General click “Location Services” to off. This will also help with battery life on the iphone.
  • If you’re suffering from SMS lag I’ve read that opening and closing the app store solves the problem on the iphone.

Mostly straight forward but still useful. I’ve found that Winterboard does not cause any lag whatsoever. I’ve tried multiple themes and played around with each and they don’t seem to lag the phone out at all.

Share

May 15 2009

Read PDF’s Locally on the Iphone With Safari. No More Emails or URI Hacks

Read PDF’s Locally on the Iphone With Safari. No More Emails or URI Hacks

Essentially you can browse your entire iphone filesystem using this method but I just want to read PDF files as easily as possible.

I’ve been trying recently to find a proper PDF reader for the iphone that doesn’t really screw up the formatting or require very manual conversions and it seems that safari’s built in pdf reader is better than stanza and other readers.
Because safari on the iphone is not able to view files that are local on the device we need to do some quick work to make safari on the iphone read local files.
For this to work you will need to be able to access the iphone file system from a personal computer somehow. Check out how to get SCP on the iphone working.

First you will need to install the lighttpd program from cydia. It was under the networking section. Lighttpd is a tiny webserver for the iphone or ipod touch.
Once you’ve got lighttpd installed you will need to connect your iphone to your pc and open up SCP or a program similar over either wifi or through USB.

The version of lighttpd that I got from cydia didn’t have a default configuration file. So I created a file called lighttpd.conf which is extremely simple.
I chose not to put anything specific in the file because I never plan on accessing this iphone webserver from anywhere other than localhost.

server.document-root = “/var/www/”

server.port = 80

mimetype.assign = (
“.html” => “text/html”,
“.txt” => “text/plain”,
“.jpg” => “image/jpeg”,
“.png” => “image/png”
)

dir-listing.activate = “enable”

To check that your syntax is ok, log into the iphone with ssh or use a terminal app locally on the iphone and locate the lighttpd.conf file. I put mine in /etc.
Type this at the iphone prompt.

lighttpd -t -f lighttpd.conf

You should get “Syntax OK” after typing that into your iphone.

To start lighttpd:

lighttpd -D -f lighttpd.conf

Your document root on the iphone is now /var/www (if you used my configuration file) so start putting pdfs in there and you’ll now be able to read all those pirated ebooks that have been just sitting there taking up hard drive space for so long.
When you point safari to http://127.0.0.1/ you will now see a list of the pdfs (or whatever else you want to put in there).

Share

May 14 2009

Give Website a Custom Icon for the Iphone

To put a custom icon for a website on the home screen of your iphone or ipod touch you will need a PNG file which is 45×45 pixels.
Call this icon apple-touch-icon.png and store it in the root of the website. Not sure how to add a custom icon to other peoples websites yet.

Of course, to create the link, you will want to go the page in safari and select the ‘+’ button and then select the “add to home screen” option.

Check the icon at this iphone web application example.

If you want to add an icon image that is located somewhere else then use this

<link rel=”apple-touch-icon” href=”/images/iphone-icon.png” />

Share

May 14 2009

Iphone iwebkit Example

Create Custom Iphone or Ipod Touch Web Applications Using iWebKit

For the impatient people like myself, heres what it looks like. You want to point your iphone browser to this location and hit the ‘+’ button at the bottom and select add to the homescreen. This will get rid of the navigation bar on in safari and make the iwebkit example look like a native iphone app.

Here are the steps to take in order to get this working.
Get the frame work: iWebKit framework (I used 4.5.3 for this guide)
Extract the iwebkit and take a look at the manual. Iwebkit comes with a few examples of how to use the key framework elements.We’re going to make a very rudimentary application for the purpose of iphone iwebkit example. Ajax integration with iwebkit will come later.

First you will need to create a directory on your web server and extract the iwebkit files into it.
The webkit contains a few examples but most of them didn’t show up properly for me when I used the Iphone.
Most webapps are built with just really basic html. The custom elements that iwebkit provides are called by normal divs with certain ids.

First start with an extremely basic html skeleton page :

<html>
<head>
<meta content=”yes” name=”apple-mobile-web-app-capable” />
<meta content=”text/html; charset=iso-8859-1″ http-equiv=”Content-Type” />
<meta content=”minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no” name=”viewport” />
<title>iphone iwebkit example</title>
</head>
<body>

</body>
</html>

Hopefully no explanations are needed there. Notice the meta tags? So now we need to start adding the iphone javascript and css.
To get started with iwebkit for the iphone or iphone touch you only need to include two files into this basic html page but you will need to take all four folders from the Framework folder and put them into the directory where you want to host your web app.
Add these two lines to the head portion of the skeleton html file outlined above.

<link href=”css/style.css” rel=”stylesheet” type=”text/css” />
<script src=”javascript/functions.js” type=”text/javascript”></script>

Now to start putting the application together using iwebkits basic elements.

Top Bar
This section will outline the options for the navigation bar at the top of the page on the iphone or ipod touch.
Using iwebkit for the top bar we will normally put navagation buttons and a title like this.

<div id=’topbar’>
<div id=”leftnav”>
<a href=”index.html”><img alt=”home” src=”images/home.png”/></a>
</div>
<div id=’title’>
iphone iwebkit example
</div>
<div id=”rightnav”>
<a href=”index.html”>Next</a>
</div>
</div>

There are four div elements there that make up this top bar. The first is the bar itself and it encompasses the other three elements.
The second is the leftnav div. This specifies that the elements within this div are to appear at the left side of the bar (Big surprise).
The third is the title. The fourth is the rightnav which will appear on the right side. You’re probably going to want to put links and pictures in the leftnav and rightnav divs.
Instead of the rightnav div it is possible to put a rectangle button instead of the arrow button just by changing rightnav to rightbutton in the id.

Content
This section is for basically anything you want to put in your iwebkit page. I’m going to demonstrate a simple iphone-looking list here:

<div id=”content”>
<span class=”graytitle”>Iphone iwebkit example</span>
<ul class=”pageitem”>
<li class=”textbox”>
<p>Some Text for the iwebkit example</p>
<p>More text for the Iphone</p>
</li>
<li class=”textbox”>
<span class=”header”>Iphone iwebkit</span>
<p>Iphone Iphone</p><p>WebKit WebKit</p>
</li>
<li class=”menu”>
<a href=”index.php”>
<img alt=”Description” src=”thumbs/basics.png” />
<span class=”name”>Iphone iwebkit Example</span>
<span class=”comment”>Comment about iwebkit</span>
<span class=”arrow”></span>
</a>
</li>
<li class=”store”>
<a class=”noeffect” href=”index.php”>
<span class=”image” style=”background-image: url(‘image.jpg’)”></span>
<span class=”name”>Iphone Song</span>
<span class=”comment”>iWebKit Comment</span>
<img alt=”rating” class=”stars” src=”images/4stars.png” />
<span class=”starcomment”>13 Reviews</span>
<span class=”arrow”></span>
</a>
</li>

</ul>
</div>

There are a lot of options when using iwebkit. Most are pretty self explanatory, like the <ul> class and the <span> and <li> classes, but who wants to remember all that.
So go check the source of some feature or look that you want on your iwebkit page at <a href=’http://m.iwebkit.net/index.html’>this demo</a>.

The first issue I had when looking at my iwebkit example on the iphone was that the example iwebkit application wasn’t fullscreen in safari.
The only way that I’ve found so far to make this web application look like a native iphone application is to go to the page in safari and then hit the ‘+’ button at the bottom and select add to the homescreen.
This will get rid of the navigation bar on the iphone and make the iwebkit example look like a native iphone app.

This example and the full source for this iwebkit iphone example  can be looked at here.

Share

May 14 2009

10 best iPhone games for hardcore gamers

If you own an iPhone or iPod Touch, you’ve probably browsed or bought from the iTunes Store. With over 35,000 downloads currently available, finding the quality in all that quantity is growing increasingly difficult, frustrating and costly.


Share

May 14 2009

How Much Money Does a Billion iPhone Apps Get You? Not Much!

Recently, Apple proudly strutted its feathers, pointing at the one billion iPhone free and paid apps users have installed on their little bundles of electronic joy. Now, the folks at LSVP have done the math and calculated how much revenue, approximately, did that billion generate.Short version: not that much.


Share

May 14 2009

Steve Jobs Seen Returning Post-WWDC Brandishing New iPhones

While all eyes are on Apple’s annual developers conference as a likely forum for new iPhone hardware announcements, one Wall Street analyst is advising clients that better bets may be placed on an event a few weeks later that may also mark the return of Steve Jobs. In a note to clients, Piper Jaffray analyst Gene Munster said he believes a press…


Share