Posted (Updated ) in PHP

I had a bit of an issue with this and the documentation wasn’t of much help so I thought I’d post about the process. I currently have CampaignMonitor and MailChimp modules in the LemonStand marketplace and wanted to allow customers to create subscription forms on their sites that AJAX submit.

Firstly, here is the documentation page on custom events. The docs show that you need two things:

  • A subscribeEvents() method in your module’s setup class containing an addEvent() call.
  • A method containing the code you want to execute, which will be triggered by your event.

I attempted to do the above with the following backend code:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
class MyModule_Module extends Core_ModuleBase
{
	public function subscribeEvents()
	{
		Backend::$events->addEvent('MyModule_Module:onSubmit', $this, 'on_submit');
	}
 
	public function onSubmit()
	{
		//...
	}
}

And frontend code:

1
2
3
<form onsubmit="return $(this).sendRequest('MyModule_Module:onSubmit')" action="/" method="post">
	<input type='submit' name='submit' value='Submit' />
</form>

I submitted the form and was greeted with an error message:

An AJAX error occurred: AJAX handler not found.

After a little digging I came across the function excuted when you perform an AJAX query. Important lines are highlighted:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public static function execAjaxHandler($name, $controller)
{
	$parts = explode(':', $name);
	if (count($parts) != 2)
		throw new Phpr_ApplicationException("Invalid event handler identifier: $name");
 
	$className = ucfirst($parts[0]).'_Actions';	if (!Phpr::$classLoader->load($className))
		throw new Phpr_ApplicationException("Actions scope class is not found: $className");
 
	$method = $parts[1];
	$isEventHandler = preg_match('/^on_/', $method);	if (!$isEventHandler)
		throw new Phpr_ApplicationException("Specified method is not AJAX event handler: $method");
 
	$obj = new $className();
	if (!method_exists($obj, $method))
		throw new Phpr_ApplicationException("AJAX handler not found: $name");
 
	$obj->copy_context_from($controller);
	try
	{
		$result = $obj->$method();
		$controller->copy_context_from($obj);
		return $result;
	}
	catch (Exception $ex)
	{
		$controller->copy_context_from($obj);
		throw $ex;
	}
}

There’s a couple of things to note here.

  • Your second and third arguments in addEvent() are ignored.
  • _Actions is concatenated onto the end of your class name
  • Your method name must start with on_

With the above in mind, it’s time for some rewriting:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
 
class MyModule_Module extends Core_ModuleBase
{
	public function subscribeEvents()
	{
		Backend::$events->addEvent('MyModule:on_submit', $this, 'on_submit');
	}
}
 
class MyModule_Actions extends Cms_ActionScope
{
	public function on_submit()
	{
		//...
	}
}

That worked like a charm. Good luck to all the module developers for LS out there – I’ve found LemonStand a number of quirks like this and we’ll just have to tackle them one at a time 🙂

Read More »

Posted (Updated ) in Linux

Note: Also see the prequel to this post: Why I Hate Unity

As your typical Ubuntu user, I find Unity infuriating and have devoted countless hours towards bringing back the usability and functionality that came with Gnome 2. I’ve racked up quite a few tweaks so far that have gone a long way towards doing this and figured it was about time to share them. My aim was to make 11.10 look and feel exactly like 10.10. I’ve attached below a screenshot of the final result.

11.10 with Gnome Session Fallback
11.10 with Gnome Session Fallback

Read More »

Posted in Linux

I was receiving a 500 internal server error on one of my CPanel sites earlier tonight but the apache error logs in CPanel admin for that user showed nothing. Instead, I had to locate the global apache error logs. This information may help others so I’ve listed some of the most useful CPanel/WHM log file locations below:

Apache Logs

General Error and Auditing Logs:
Location : /usr/local/apache/logs/error_log
Description : All exceptions caught by httpd along with standard error output from CGI applications are logged here..
The first place you should look when httpd crashes or you incur errors when accessing website.

Domain Access Logs:
Location : /usr/local/apache/domlogs/domain.com
Description : General access log file for each domain configured with cPanel.

Apache Access Logs:
Location : /usr/local/apache/logs/access_log
Description : Complete web server access log records all requests processed by the server.

MySQL Logs

MySQL General Information and Errors:
Location : /var/lib/mysql/$(hostname).err
Description : This path could vary, but is generally located in /var/lib/mysql. Could also be located at /var/log/mysqld.log

 

For more log file locations, there are some great forum posts here and here.

Read More »

Posted (Updated ) in Linux, PHP

I’ve was playing with EasyApache in a WHM install recently and after the upgrade I came across a strange error:

SoftException in Application.cpp:357: UID of script "/home/mysite/public_html/index.php" is smaller than min_uid
Premature end of script headers: index.php

Turns out this error is caused by apache being unable to read files added by root to a users public_html folder. A simple fix for this problem is to

chown -R mysite:mysite /home/mysite/public_html

Thanks to user ronniev of eukhost forums for his solution here.

Read More »

Posted (Updated ) in Linux

One of my favourite plugins for GEdit2 was tabswitch. It made GEdit more consistant with browsers by allowing it to switch tabs with CTRL+Tab instead of CTRL+PgUp/Down. Ubuntu 11.10 comes with Gedit 3 and the plugin no longer worked – so I rewrote it!

This plugin will let you use CTRL+Tab to switch between tabs in GEdit 3. You can download a working implementation here.

Install it by copying the files into ~/.local/share/gedit/plugins directory (which doesn’t exist by default) or /usr/lib/gedit/plugins if you want it to work for all users. Remember to enable the plugin in Edit – Preferences – Plugins for it to work!

Read More »

Posted (Updated ) in Database, Linux

I’ve been using my Cloud Database Backup script for a few months now for weekly scheduled backups of my MySQL databases to Google Docs. Everything has been going smoothly, however I’m starting to run low on quota. For this reason I decided to look into splitting the SQL dumps into chunks small enough to be convertible and doing an upload-convert rather than a zip upload which will result in literally unlimited, quote free database backups as frequently as I like! The focus of this post though is the actual splitting script which splits a given MySQL dump into chunks of x characters.

As always, download it here.

Read More »

Posted (Updated ) in Linux

Ubuntu fans who like having Skype chats appearing in their Pidgin windows will know of 2 useful packages – skype4pidgin and pidgin-skype. These used to work great, however with the latest Skype update things broke. You could send messages from your Pidgin window but wouldn’t see any responses from your contacts. Frustrating!

Anyway, it looks like the guy behind skype4pidgin has come up with a solution which he’s layed out on his website.

You’ll need to download skype4pidgin.deb, libskype.so and libskype_dbus.so (or obviously the 64-bit equivalents of you’re on Ubuntu64). Drop the .so files into /usr/lib/purple-2 remembering to back up the existing equivalents first and install skype4pidgin.deb.

That should be all there is to it. Pidgin is back to working the way it should. *whew*

Read More »

Posted (Updated ) in Linux

This is an issue that plagues me constantly. For each PPA you add to Ubuntu, you also need to import a GPG key for it. This is all fine and well – until don’t have the key and are unsure how to get it (often happens after a reformat). Try doing an update without a valid key and you’ll get the following:

BSOD - Ubuntu Updates style
BSOD – Ubuntu Updates style
W: GPG error: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY

Well we finally have a solution: launchpad-getkeys! This handy little tool will automatically determine which PPA’s require GPG keys and import them for you.

Finally. Sweet relief!
Finally. Sweet relief!

Install with:

sudo apt-add-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install launchpad-getkeys

Run with:

sudo launchpad-getkeys

Images taken from this howtogeek article. For more information see here and here.

Read More »

Posted (Updated ) in Linux

This weekend I was trying to run a server on port 9000 but something was already on there. I had no idea what it was and needed to find and stop it. Here’s a super quick and easy way to do so:

You’ll need lsof:

sudo apt-get install lsof
lsof -iTCP:9000

The result I got was as follows:

COMMAND     PID      USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
komodo-bi 31713 myuser   51u  IPv4 1234567      0t0  TCP *:9000 (LISTEN)

From there it was as simple as going into komodo and turning turning off its listener 🙂

Thanks to Laran Evans for his useful tutorial.

Read More »

Posted (Updated ) in Javascript, PHP

If you’re reading this page (or my blog in general) it’s a pretty safe bet you already have Google+. If you’ve uploaded any photos to Google+ from Chrome or FF, you would also have noticed its snazzy HTML5 file uploader at work. This weekend I took it upon myself to whip up a quick and dirty version of that uploader and share its inner workings with the world.

Google+ Image Uploader
Google+ Image Uploader

Here’s a short video of my uploader at work:

https://www.youtube.com/watch?v=AXx8cu6rxV4

Requirements:

  • PHP4+
  • HTML5-enabled browser (File API – including drag and drop, XHR2)
  • Some images to upload

Disclaimer: Currently only Firefox and Webkit based browsers meet the requirements above. Opera supports the File API and probably XHR2 (I haven’t tested), however it doesn’t have drag and drop so this tutorial won’t work with it. If you’re curious about whether or not IE will work with this tutorial, I’m already laughing at you.

Download the finished script here.

Read More »

Page 9 of 16« First...7891011...Last »