Agile Toolkit JavaScript Digest

The purpose of JS chains in Agile Toolkit is to provide a glue between JavaScript and PHP. It is NOT to completely replace native JavaScript.

Agile Toolkit offers a better way to organise your JavaScript code. It is by putting it inside a jQuery namespace. The way you call your function will be slightly different:

// Before
myfunc(123);

// After
$.univ().myfunc(123);

// From PHP
$view->js(true)->univ()->myfunc(123);

 

Extending The Universal library

make a .js file in templates/js and put these codes:

$.each({
    myfunc: function(a){
        alert('myfunc: '+a);
    },
    mysum: function(foo,bar){
        return foo+bar+1;
    },
},$.univ._import);

now you can call js like this:

$page->add('Button')->set('Click Me')
    ->js('click')->_load('secret')
    ->univ()->myfunc('hello world');
/////////////////////////
$page->js(true)->_load('j')->univ()->myfunc(123);

Static Includes

If you are including some 3rd party code, they sometimes might not like dynamic loading. Third party code might assume that the on-ready is not yet triggered or do some other kind of magic. Google Maps code, for example, wants to be loaded along with your page.

If this happens, you can specifically instruct Agile Toolkit to put the include inside the HTML.

$this->api->jui->addStaticInclude('myfile');
// or
$this->api->jui->addStaticInclude('http://pathto/cdn/file.js');

You must be mindful to include this on the page, which is loaded directly, and can potentially open other pages through AJAX, requiring this include. If unsure, add this code to your API’s init() method.

If you want to go even more ‘hardcore’ with the include you can do this:

$this->api->template->append('js_include',
    '<script type="text/javascript" src="http://..."></script>'."\n");

Executing any JS code

One of the goals of JS Chains is security. JavaScript injection is a common problem and by having a nice interface between your JavaScript and server backend you become immune to it.

If you think that you know better, you can execute a string of JavaScript code from anywhere like this:

// DANGER: Contains JavaScript injection vulnerability
$view->js(true,"alert('$my_message')");

// SAFE: $my_message is escaped
$view->js(true)->univ()->alert($my_message);

.

 

Automatic Database and file Backup with PHP

phpMyBackup Pro is a very easy to use, free, web-based MySQL backup application, licensed under the GNU GPL.
You can create scheduled backups, manage and restore them, download or email them and a lot more!

Major features:

– backup of one or several databases with or without data, table structure, …
– three types of compression (no compression, gzip or zip)
– scheduled backups (by a small PHP script which must be included in an existing PHP script)
– interface for managment of the backups (viewing, restoring, downloading, deleting)
– backup directly onto FTP server and sending of backups by email
– platform independent – only webserver and PHP needed to run e.g. on MS Windows, Linux or Mac
– shell mode (to use manually or by cron script)
– backup of whole file directories (on a FTP server).
– backup databases from different accounts on several MySQL servers
– one installation can be used for all MySQL users of one MySQL server (used by webhosters)
– highest security through two alternative login methods (HTTP or HTML authentication)
– easy to use interface and very easy to install
– several language packages available
– online help (included in pMBP) and FAQ on this website

========

to automate it, you must set cron like this:

wget -O /dev/null http://domain.com/script_dirr/auto_name.php