Archive for the Php Category

Upload and tag a video to facebook via php

Posted in Development, Instructional, Php with tags , , , , , on May 14, 2013 by andkrup

Currently the facebook API documentation doesn’t mention that you can upload a video file to your facebook wall and tag your friends in it. This may be a feature yet to be announced or just hidden.

The code for connecting to facebook is well-known, here

$facebook = new Facebook(array('appId' => $appId, 'secret' => $appSecret));

Uploading a video to your feed is done like this:

$args = array();
$args['description'] = $videoDescription;
$args['title'] = $videoTitle;
$args['privacy'] = json_encode(array('value' => 'ALL_FRIENDS'));
$args['file'] = "@$videoPath";
$data = $facebook->api('/me/videos', 'post', $args);

Then after the api() function returns the video-id, you can tag the video object, using the undocumented field tags, like so:

$args = array();
$args['tag_uid'] = "$userId";
$data = $facebook->api("/{$videoId}/tags", 'post', $args);

That’s it


Autoloader for WordPress

Posted in Php with tags , , , on April 10, 2013 by andkrup

The process of creating an autoloader for WordPress is a bit problematic. The WordPress core doesn’t use autoloaders, so when you register one via spl_autoload_register(), the autoloader you define in your plugin or theme, will take control of how the WordPress core loads its internal classes.

Other 3rd-party plugins may also break if your autoloader function tries to load their classes in your namespace/source-path.

However, if you put all your classes into your own unique namespace (as is best practice in most other languages), you shouldn’t have any problems in avoiding invocations where your autoload function tries to load classes not from your distribution.

Here I put all my own classes in a namespace called ‘supervillain’, using a plugin structure as pictured here:

Screen Shot 2013-04-10 at 11.42.38

The SoundcloudPlayer-plugin.php file will be included by WordPress. In there I require_once the bootstrap.php, containing this code:

function load($className){
    if(false!==stripos($className, 'supervillainhq')){
        require str_replace("\\", '/', dirname(__FILE__) .'/'. __NAMESPACE__ . $className . '.php');


Further down in Soundcloudplayer-plugin.php I can create an instance of the SoundcloudPlayer class, defined in SoundcloudPlayer.php like this:

$scplayer = new supervillainhq\SoundcloudPlayer();

The SoundcloudPlayer class is defined like this:

namespace supervillainhq{
    class SoundcloudPlayer extends WordPressPlugin{
        public function test(){
            return "test";

Of course, this still needs testing


Posted in Ant, Development, Php with tags , , , , on February 26, 2013 by andkrup

I am currently writing a batch of ant tasks for Php-development in Eclipse, using PDT.

The low-level nature of php makes the workflow of php-development highly indiviual, and any non-framework based workflow which works for one developer, is probably not going to work for the next dveloper. Each developer has his or her own set of (bad) habits. On the other hand, most of us develop a set of routines and our experiences enable us to know which patterns work in what situations.

This collection of tasks help me in my daily work.

It should be noted that some tasks takes for granted some idioms and coding, conventions if you will, that has proven helpful during my php developing experiences. A lot of these tasks will probably work great in conjunction with the code library PhpBasics (, and in the future both of these projects will probably merge into a set framework, god forbid