Archive for the Development 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

A3Tasks update

Posted in Actionscript, Ant, Java with tags , , , , on January 5, 2012 by andkrup

Finally had some time to work on the A3Tasks!

A3Tasks is a little set of Ant tasks for Flash development, made by me (hence the 3 A’s; Andkrups Ant tasks for Actionscript).

Have a look at the repository at bitbucket ( and tell me what you think.

Converting fla files to xfl and vice versa to simplify copying publish settings

Posted in Ant, Flash with tags , , , on August 23, 2011 by andkrup

A really nice feature of the xfl flash file format is that (mostly) everything is text-based.

Today I was working on a small landing page project with 1 fla file that is supposed to display small variations each week for the next 6 weeks. Some of the variations are changes in graphics, and the easiest solution was to create 7 different publish settings each with different compiler constants.

Copying a publish setting will copy all the current settings, bit for some reason, the library settings pointing to the swc files used, was not copied into the new publish setting.

Instead of tediously selecting and copying every compiler constants back and forth in 7 publish settings, it was much easier and faster to convert the fla file to xfl, and edit the PublishSettings.xml with a simple search and replace.

This way you can replace a text like this:


with a text like this.


in the PublishSettings.xml instead of risking carpal tunnel syndrome by copying each constant and clicking a lot of gui components in the gui.

Converting a fla file into a xfl file is as easy as unzipping the fla file – it’s a zip file with the *.fla extension. Converting back is rather obvious.

I use some ant tasks to streamline the process:

<target name="Convert Xfl to Fla">
<zip destfile="${dir.flash}/${}.fla" basedir="${dir.flash}/${}" />
<delete dir="${dir.flash}/${}" />

<target name="Convert Fla to Xfl">
<mkdir dir="${dir.flash}/${}" />
<unzip src="${dir.flash}/${}.fla" dest="${dir.flash}/${}" />
<delete file="${dir.flash}/${}.fla" />


Problems & Errors encountered during Red5 installation on Ubuntu 11.04

Posted in Development, Java, red5, ubuntu with tags , , , , , on August 10, 2011 by andkrup

During a Red5 installation on Ubuntu 11.04 I encountered some problems and errors.

The Red5 documentation does not really include the common problems that you may encounter while installing it.

This can be attributed to Red5 previously requiring java, ant and subversion.

Target System

Ubuntu 11.04


Look up resources on how to install java on ubuntu 11.04. The short version is that java isn’t included in Natty and Natty doesn’t know where to look for it, so you need to add a line in a file with an url so Natty can look up a java distribution and install it.

Anyway, this is how it went:

Problems while installing Red5

Problems while testing Red5

After creating the start-up scripts (can be found on the bottom of this page ) Red5 hopefully starts up like we want it, and we want to test it.

But first we need to get acquainted with Red5 terminology in order to be able to google properly.

The Red5 version 1.0 installation contains client-side demo samples that require a server-side counterpart. Clients connect to a Red5 server application which you must install in the Red5 webapp folder.


Most of the time this status message was popping up because Red5 couldn’t install the server application correctly. Somehow I got this to work when:

  1. Red5 was started with sudo (see below), so file permissions is out of the picture
  2. Connecting to the correct url

Starting the Red5 server manually:

sudo /etc/init.d/red5 start &gt; dev/null &amp;

Problems with the admin part

In order to run the admin demo, you need to do this first:

  1. find the documentation about how to install the required parts (it’s here: – the page is aptly named so it’s easy to find) so you know what to do.
  2. download the admin plugin (it’s here:
  3. download the admin.jsp into the webapp/root folder (from here:
  4. use the admin.jsp to create a new admin user.
  5. input the correct text in the server input field (only the server name, like in an apache config without stating protocol and port)

Installing on Natty can be done like so (assuming that you installed red5 in (/opt/red5):

cd /opt/red5/webapps/root
sudo wget

The documentation assumes that all required jar files are included in the zip file, but atm, they’re not…


The name says it all – you need some classes, because either the Red5 team assumes you already have them installed or they just didn’t bother including them in the distribution.

This support ticket describesthe problem:

While the ticket status is set to fixed, you would assume that the has been re-packaged, but at the time of writing you need to fetch the missing jar files from somewhere else:

Using I found these compatible files:

that you can download directly into the plugins folder like so (assuming that you installed red5 in (/opt/red5):

cd /opt/red5/plugins
sudo wget
unzip jasper-6.0.18.jar
sudo wget
unzip jasper-jdt-6.0.18.jar
sudo wget
unzip jasper-el-6.0.18.jar

Hopefully this helps

AS2 History class: The construct function

Posted in Actionscript, Development, oop with tags , , , , , , on July 3, 2011 by andkrup

Here’s a little nugget of information that may or may not come in handy. If javascript is to get the revival that everybody is hoping for (with html5 and ajax), this kind of code could prove useful, especially since we’re touching on some common concepts (mostly prototype manipulation).

Also, if you are being forced to develop something for the flash museum, you might need this snippet of code.

But first, some history lecture…

The problem

Most of the time a flash developer is to develop a larger flash application, he wants to have control of the main timeline. As3 developers have it easy with the possibility of creating a Document class and flex coders extends the Application class all the time.

In flash 8 we typically added scripts in the top-most timeline in_level0 but there where always some problems with this approach, especially in modular applications where you could only cast a loaded swf file as a MovieClip and hope that that instance had had some function references added to it, with execution scope being addressed correctly.

Normal MovieClip symbols from the library could map to external as2 classes fine, but the _level0 timeline was out of reach, even though it behaves just like any other normal MovieClip symbol, when loaded into another swf file.

In as3 this architectural problem was addressed with the advent of the Document class, but you can actually do the same in as2:

The Solution

class Main extends MovieClip{
static var instance:Main;
public static function construct(timeline):Void{
timeline.__proto__ = Main.prototype;
Function(Main).apply(timeline, arguments.slice(1));
instance = (Main)(timeline);

public function Main(){

Invoke the static construct method in _level0 in your 2004-tech flash file, with ‘this’ as the first argument like so:



What this method does, is that it replaces the _level0 hidden property __proto__ with the one from your external as2 class, invokes your external as2 classes constructor and in practicality casts _level0 (with the new prototype inheritance chain) as an instance of your external as2 class.

This means that whenever we need to develop modular flash in yesterdays technology, we can stay comfortably in the OO-zone (especially if we also create and implement some interfaces to establish an api), and use _level0 as an instance of your ‘Document’ class

Very nice.