Short Tag – Web Development Blog

Entries for March, 2012

Make cPanel Api2 Requests with Jquery and Javascript

First, include jQuery in your page:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

Here is the API 2 of cPanel:
http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api2/WebHome
Find the modules and function names you need, and use them when calling the function below.
Copy the following function to your webpage:

function cpanel_call(module, fct, domain, user, password, secure, port, json, callback, return_as, async)
{
var protocol = secure ? "https" : "http";
var data_type = json [...]

Xul and XPCOM: Delete files

Here is a little handy function for removing files with Javascript on Mozzila platform:

function delete_file_by_path(path)
{
var file = Components.classes['@mozilla.org/file/local;1']
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(path);
if (file.exists())
file.remove(false);
}

Create a new instance of nsILocalFile, and the use the initWithPath function to initialize the file, and the delete the file is exists.

Php .Htaccess Set default timezone

When getting an error like this:
© Warning: date(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled [...]

Loop through a Combobox, Listbox in XUL/XPCOM

So, we have a XUL component, that looks like this:

<listbox id="listboxId">
<listitem label="1" />
<listitem label="2" />
<listitem label="3" />
</listbox>

We can loop through the elements of this componenet using XPCOM:

var lbox = document.getElementById(‘listboxId’);

for (var i =0; i<lbox.children.length; i++)
{
var child = lbox.children[i];
//do someting with child, like
alert(child.label)
}