Local WordPress shows empty page

I thought it’ll be easy to pull my WP site down to local and make some theme changes. Just install XAMPPLite, export/import my database, backup the site files and go.

It kept showing an empty site, with no errors reported in the log, so I ended up tracing through the code to find out the what was not working. Below were the other changes I had to make.

The siteurl and home attributes in the wp_options table of the database had to be updated. I opted to change it in wp-config.ini using the following 2 lines:

define('WP_HOME', 'http://localhost/wp' );
define('WP_SITEURL', 'http://localhost/wp');

I realize some PHP was not parsed when the shorter tag is used. This option needs to be explicitly enabled in php.ini.

short_open_tag = On

The OpenID plugin requires the GMP extension, which needs to be enabled in php.ini. The comments on the PHP documentation site helped.

extension=php_gmp.dll

PHP XML XPath

The problem with the simple XML-RPC wordpress solution was that it did not have feedback whether the post was successful. I knew I could get the response from curl_exec, but I have to figure out the XPath part. Similarly I was hoping for some ready-made function to do that, but it seems things were not so straightforward. Furthermore, being on PHP4 means I didn’t have the luxury of the newer XML functions such as SimpleXML.

After some fiddling, this was the simplest I could go:


$dom = domxml_open_mem($response);
$faultString = xpath_eval(xpath_new_context($dom), 
	  "/methodResponse/fault/value/struct/member[name='faultString']/value/string/text()");
return $faultString->nodeset[0]->content;

The XPath expression was also a level-up: I had to select a node based on the child data of its sibling.

WordPress XML-RPC

I wanted a stripped-down “mobile” version of the WP admin interface for posting, but I couldn’t find a suitable one. So while I thought about writing my own, I looked for ready made XML RPC solutions.

Indeed, as I expected, one function is all it takes.


function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1)){
	$categories = implode(",", $categories);
	$XML = "$title".
	"$categories".
	$body;
	$params = array('','',$username,$password,$XML,1);
	$request = xmlrpc_encode_request('blogger.newPost',$params);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
	curl_setopt($ch, CURLOPT_URL, $rpcurl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 1);
	curl_exec($ch);
	curl_close($ch);
}

I made a small HTML form and submitted it to this PHP function, and that’s it! 15 minutes worth of work.

VirtualBox remote access

VirtualBox supports RDP (Remote Desktop Protocol), which can be enabled by the following steps.

  1. Power off the Guest machine (doesn’t work in saved state).
  2. Click “Settings” to configure the settings for the VM.
  3. Select the Remote Display tab, check “Enable VRDP Server”.
  4. If you’re on Windows you might need to change the server port because it may conflict with the Remote Desktop for Windows.
  5. Click “OK”.

Start the VM, and run “mstsc /v:hostname:port” from another box to Remote Desktop into the VM.

What I’ve experienced is that the mouse speed is not synchronized, so it becomes difficult to navigate even when I change the mouse sensitivity to be approximately the same. I also haven’t figure out how to have authentication with this method.

Another possible way I’ve yet to succeed is to use Ubuntu’s built in vnc server.

Oracle lightweight client

I needed an Oracle client to do some quick tests on a database server (see the next post), something like SQL Plus. But it felt too heavy for me to install the official client. So I went out looking for an alternative, something that’s standalone, very light to install and use. Of course it should be free.

http://www.sqlpal.com/

SQLPal is a perfect match – it’s free (for use), it’s standalone, just unzip and use (no install), works just like SQLPlus. In addition it has a schema browser to dig into the database easily, supports command history, and happens to be implemented in Java. The Java part has no added advantage though, it wouldn’t make a difference if it were in C++ or Python.

EDIT: I just realized the last update to the program was in 2004, evident from the website as well as the files extracted from the zip. Is it bad that there are no updates? Or it’s just a good program that needs no updates?

insert into (select) with oracle sequence

Colleague needed some SQL today for an upgrade script. Needed to add default data to entities that didn’t have a specific parameter.

As usual I reduced the problem to a snippet. Although he was trying to squeeze it into a single command with INSERT INTO (SELECT…), due to time constraints I felt a stored proc was faster to get over it. Maybe someone can post the single command here.

In this case the TestTable already had some data, with refids 1, 2, and 3. Ref 2 already had the xyz param, but the others don’t. So the task is to add the field to all other refids, using the given TestSeq.


CREATE SEQUENCE TestSeq START WITH 7;

CREATE TABLE TestTable (
	id NUMBER PRIMARY KEY,
	refid NUMBER,
	param VARCHAR2(64),
	other NUMBER
);

INSERT INTO TestTable VALUES(1, 1, 'abc', 0);
INSERT INTO TestTable VALUES(2, 1, 'def', 0);
INSERT INTO TestTable VALUES(3, 2, 'abc', 0);
INSERT INTO TestTable VALUES(4, 2, 'xyz', 0);
INSERT INTO TestTable VALUES(5, 3, 'abc', 0);
INSERT INTO TestTable VALUES(6, 3, 'def', 0);

DECLARE
	newid TestTable.id%type;
	CURSOR dataCursor IS
		SELECT UNIQUE refid, other FROM TestTable WHERE refid NOT IN 
		(SELECT refid FROM TestTable WHERE param = 'xyz');
BEGIN
	FOR dataRow IN dataCursor
	LOOP
		SELECT TestSeq.nextval INTO newid FROM DUAL;
		INSERT INTO TestTable VALUES(newid, dataRow.refid, 'xyz', dataRow.other);
	END LOOP;
END;
/

inconvertible types when casting

I was unlucky enough to hit a compiler bug, such that Eclipse IDE passes compilation, but it failed on my server using ant with Sun’s compiler. From the bug report it happens to JDK6 and will only be fixed in JDK7, so in the meantime I read of 2 workarounds that work.

1. Up-cast to an Object so that the down-cast become compiler-legal.

(ChildType)(Object)getParentType();

2. Use the Class.cast() method.

ChildType.class.cast( getParentType() );