Multi-site WordPress max. file upload gotcha

Posted in Uncategorized on July 30, 2014 by andkrup

If you’re setting up a wordpress installation as a multi-site installation, you will find that Multi-site WordPress begins to care about your user-uploads.

If you’ve set up your php.ini to not flash file size restrictions in the face of your users, you will have to change some settings from their default values.

Notice that the default threshold is set at a value that may restrict some high-res retina png files. Screen Shot 2014-07-30 at 10.17.57 AM

These settings are imposed on top of the post_max_sizeupload_max_filesize settings in your php.ini, so have this in mind when you’re working with multi-site installations.

Check this page for the settings available:

https://codex.wordpress.org/Network_Admin_Settings_Screen#Upload_Settings

Let your WordPress theme support gettext

Posted in Uncategorized on August 9, 2013 by andkrup

Has anyone tried translating your wordpress theme, using gettext?

I found I had to add a callback to the gettext filter in order to have wordpress recognize my *.mo files:


add_filter('gettext','patched_translate', 10, 3);

function patched_translate($translations, $text, $domain = 'default'){
  $translations = get_translations_for_domain( $domain );
  if($domain == 'default'){
    return $translations->translate($text);
  }
  $translation = $translations->translate( $domain.chr(4).$text );
  if($translation == $domain.chr(4).$text){
    return $text;
  }
  return $translation;
}

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.

https://developers.facebook.com/docs/reference/api/video/

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

$facebook = new Facebook(array('appId' => $appId, 'secret' => $appSecret));
$facebook->setAccessToken($accessToken);
$facebook->setFileUploadSupport(true);

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:

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

spl_autoload_register(__NAMESPACE__."\\load");
?>

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:

<?php
namespace supervillainhq{
    class SoundcloudPlayer extends WordPressPlugin{
        public function test(){
            return "test";
        }
    }
}
?>

Of course, this still needs testing

Commandline urlencoding/urldecoding alias

Posted in Uncategorized with tags , , , , on April 4, 2013 by andkrup

Here’s a clever bash alias for quick string url- encoding/decoding:

http://ruslanspivak.com/2010/06/02/urlencode-and-urldecode-from-a-command-line/

PhpTasks

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.

https://bitbucket.org/andkrup/phptasks

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 (https://bitbucket.org/andkrup/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 (http://bit.ly/y63Nz4) and tell me what you think.

Mxml

Posted in Uncategorized with tags , , on November 3, 2011 by andkrup

Here’s a little neat trick I didn’t know – actually I haven’t used mxml that much so I don’t really know if this is trivial…

<?xml version="1.0"?>
<fd:MovieClip xmlns:mx="http://ns.adobe.com/mxml/2009"
    xmlns:fd="flash.display.*">
</fd:MovieClip>

It looks like a custom component, but actually it’s just a bread’n’butter MovieClip (or it’s a componentized MovieClip).

It compiles as a swf with the mxml compiler, so flex applications doesn’t have to use <mx:Application/> as root element.

In other words, you don’t have to use the flex component framework in order to use mxml to mark up your application layout.

Obviously, you will then have to manage the layout yourself.

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:

<AS3ConfigConst>CONFIG::FLASH_AUTHORING=&quot;true&quot;;CONFIG::debug=&quot;false&quot;;CONFIG::production=&quot;true&quot;;</AS3ConfigConst>

with a text like this.

<AS3ConfigConst>CONFIG::FLASH_AUTHORING=&quot;true&quot;;CONFIG::debug=&quot;false&quot;;CONFIG::production=&quot;true&quot;;CONFIG::week34=&quot;false&quot;;CONFIG::week35=&quot;false&quot;;CONFIG::week36=&quot;false&quot;;CONFIG::week37=&quot;false&quot;;CONFIG::week38=&quot;false&quot;;CONFIG::week39=&quot;true&quot;;</AS3ConfigConst>

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}/${_flash.name}.fla" basedir="${dir.flash}/${_flash.name}" />
<delete dir="${dir.flash}/${_flash.name}" />
</target>

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


 

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

Java

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.

NetConnection.Connection.Failed

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: http://wiki.red5.org/wiki/AppServer/Plugins – 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: http://red5.googlecode.com/files/AdminPlugin-1.0.zip)
  3. download the admin.jsp into the webapp/root folder (from here: http://red5.googlecode.com/files/admin.jsp)
  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 http://red5.googlecode.com/files/AdminPlugin-1.0.zip
unzip AdminPlugin-1.0.zip

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

java.lang.ClassNotFoundException

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:

http://code.google.com/p/red5/issues/detail?id=41

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

Using jarfinder.com 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 http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/tomcat/jasper/6.0.18/jasper-6.0.18.jar
unzip jasper-6.0.18.jar
sudo wget http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/tomcat/jasper-jdt/6.0.18/jasper-jdt-6.0.18.jar
unzip jasper-jdt-6.0.18.jar
sudo wget http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/tomcat/jasper-el/6.0.18/jasper-el-6.0.18.jar
unzip jasper-el-6.0.18.jar

Hopefully this helps