Youtube uploader – wordpress plugin

I needed a plugin for uploading videos to youtube, directly from wordpress administration area using youtube upload API. Since none of the plugins i searched suited my needs i decided to write my own plugin. Read more

Ffmpeg 0.6 release – now with html5 support

On 15 June 2010  Ffmpeg announced their new release : Ffmpeg 0.6 , whose main feature is support for libvpx library for the vp8 codec, which means it will now support html5 video conversion.

This is a major step in the process of adopting html5 as a standard for video sharing sites, and in my opinion, in about a year we will see all the major video sharing sites, switching from flash to html5.

You can download the new ffmpeg 0.6 from here

Common php errors and how to debug them

A lot of questions asked by beginners are about errors errors that occur when running a PHP script. In the following article, I will try to summarize these errors, hoping to be useful to those who, like me when I’ve started coding in PHP,met with such problems. Read more

Getting statistics by period using mysql

One of the most common client request is to display statistics per day/week/month or other periods of time. This statistics might mean clicks, article views, user registered etc.

Let’s see how can we display statistics of article views by day, week and month using php and mysql.
Read more

Making ajax content availble to search engines

Nowadays, more and more sites are developed using ajax because of its interactivity, ease of use, and speed.
Although it has obvious advantages there are some drawbacks:

  • Ajax pages don’t register themselves in browser history, so the back button become useless
  • Because the url remains the same through different requests, the bookmarking doesn’t work as expected
  • The same origin policy prevents Ajax to make requests across domains
  • Content retrieved with ajax is not accessible to non-javascript browsers, or web crawlers, making the ajax pages not indexable by search engines.

Today i will talk about how can you overcome the problem of the content not available to search engines and users with javascript disabled:

You need to  generate the same content to the search engine as you do for the regular user, just presented in a different way.

So if you have a link

<a onClick="showAjaxContent('about');return false;" href="about.php">About</a>

where showAjaxContent() is used to load some ajax content in a <div> box, you can just create a page to display the page, as if it was loaded directly from the browser (using headers, footers and all other elements from your page).

How safe strip_tags is?

Many developers rely on strip_tags to validate user input, and, although the function does a good job when removing all the html tags, there are some security issues when you want to leave some of them (like <a> or <img>).
That is because, although you removed all the <script> tags from the input, that doesn’t mean that a malicious user cannot enter javascript code embeded into <a> tag using html events.
Read more

OEmbed – transforming video links to embeds

Since the video sharing phenomenon began, many web developers struggle with the problem of embeding the videos without knowing anything but the url where the video page is. Many users didn’t know anything about embed code, how to put videos on their blog or other tehnical stuff like that, so developers tried to find ways of getting the video embed code from url.

The solution was to parse the html of that page, to look for the <embed> tag. However this solution was not very reliable, because any change to the html of the video website, would mess the parsing, making this method to not work anymore. Read more

10 things you should know when switching from Mysql to PostgreSQL

1) Vacuum frequently

You must do that especially after adding or deleting a large number of rows in a table.

2) || means concatenation in PosgreSql

(as opossed to Mysql where it ment OR)

3) PostgreSQL doesn’t know unsigned.

SMALLINT, INTEGER, BIGINT types doesn’t have an unsigned option, as it is in mysql

4) PostgreSQL is case-sensitive for string comparasions

So if in mysql making:

SELECT * FROM articles WHERE title='postgresql'

would find a record with title field: “PostgreSQL”

In PostgreSQL the same query will not find that record

The solution is to use lower(title)=’postgresql’ if you want to make the query case insensitive

Read more

How to change your site url structure

Most of us had this problem:

We found a link with an interesting title, click on it and all it showed was a “This page cannot be found message”

So why does this happen?

Well, the link most probably was valid some time ago, but site owners decided to change the site arhitecture. So, what was once http://www.example.com/article.php?id=243 is now http://www.example.com/article/243-some-cool-title. All seems ok, if you browse through the site,  but maybe hundreds of backlinks from other sites that are now broken, annoying users who thought they found something interesting.
Read more

Running multiple processes in PHP

Sometimes you need multiple commands to run in parallel to save up script processing time for repetitive tasks.
In the “Building a Video sharing site” project that i will present here soon, I needed a script to run multiple video processing jobs. PHP wasn’t meant to support multitasking, but with a few tricks we can emulate a multitasking environment.

On my research there were a couple of solutions that, althought they might seemed viable, had some weakness:

  • Using curl to open multiple instances of the script at once
    The problem was that the script was supposed to be accessible via the Web, and when trying to access external commands, this is a big security issue.
  • Using pcntl functions
    This could have been the best approach, but it required recompiling the PHP version with –enable-pcntl option, and many of us don’t have access to recompile PHP on the server. Beside that, it only works on linux systems, so it’s platform dependent.
  • Finally i found a nice class that simulates multi-threading and after some customisation i managed to set the multi tasking the way i wanted: Read more