My jQuery YouTube API plugin, jTube, has now been ported to a PHP class. The two work similar in the fact that you set a query type (user uploads, feed, playlist, etc.) and set some options. Below is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?phpinclude("jTube.Query.php");$oVideos=new jTubeQuery;$oVideos->setQuery("user","defvayne23","uploads");$oVideos->setOption("limit",5);
try {$aVideos=$oVideos->runQuery();} catch(Exception $e){die($e->getMessage());}// Use $aVideos
With the PHP class jTube can now make use of authentication and with that the entire YouTube API. The YouTube API allows for anything from uploading a video to supplying feedback on a video (rate, comment, flag). The PHP class already can make use of authentication tokens to retrieve private info for the user that belongs to the token. The first new functionality coming to the PHP class is video managing and upload.
When creating an image with PHP per call, why should the server have to create the image every time. In part two of using GD I’ll show how to use the 304 Not Modified header, and storing the image as cache.
To start we need to pass more info about the image from the previous post. Need to pass the last modified date and time, tell the browser that it can cache it and for how long, when the image would expire and an ID for the file.
41
42
43
44
45
header("Last-Modified: ".gmdate("D, d M Y H:i:s",filemtime($sFile))." GMT");header("Pragma: public");header("Cache-Control: maxage=".(60*60*24*2));header("Expires: ".gmdate("D, d M Y H:i:s",strtotime("+2 days"))." GMT");header("ETag: ".md5($sFile));
This is the first in a series of accepting a users image, selecting the area, and cropping it. First we will start with the guts of the process and build on top of that.
When letting users upload images for a site, you normally would like the images to be the same ratio and size. To do this we need to crop the image. To get things started lets select the image.
Now that we have the image we need to load the image into GD before we can do anything with it. You can find all the GD functions we use here. (more…)
Memcache can be great to store variables, but beware of Memcache::flush. The function actually requires about 1 second to finish. Below is the best way to handle it:
1
2
3
4
5
6
7
$oMemcache->flush();// Wait for memcache to finish flushing$time=time()+1;//one second futurewhile(time()<$time){//sleep}
DISCLAIMER: I would like to say I do not condone doing this. Better ways, more legal, ways to get content from someone. But sometimes this is asked of you by your boss. DO NOT STEAL CONTENT.
For this weeks Thursday Code Tip I will show how to use PHP to crawl a website to gather content. First we start by selecting the URL to crawl:
1
$sURL="http://www.defvayne23.com/";
Next we get the content of the page:
2
$sContent=file_get_contents($sURL);
Now to use REGEX to get what we want. You can learn patterns here. Below we search for the text within a H1 tag.