\CJAX\Plugin\ExamplePluginExamplePlugin

The Plugin class that represents a basic unit of CJAX's plugin system.

Since CJAX 6.0, Plugin class is lightweight and only contains information of one specific plugin object.

Summary

Methods
Properties
Constants
__construct()
init()
isAborted()
abort()
xmlObject()
xml()
output()
delete()
import()
imports()
waitFor()
get()
set()
setVars()
save()
deleteEntry()
callback()
prevent()
__get()
__set()
__call()
autoload()
PageAutoload()
AjaxAutoload()
___construct()
waitfor()
onLoad()
onAjaxLoad()
onEvent()
rightHandler()
callbackHandler()
$ajaxFile
$id
$name
$dir
$file
$controllersDir
$controllerFile
$init
$xml
$params
$class
$elementId
$entryIds
$exclude
No constants found
No protected methods found
$coreEvents
$cookie
$aborted
N/A
setVar()
No private properties found
N/A

Properties

$ajaxFile

$ajaxFile : boolean

The ajaxFile property, it will replace any string starting with ajax.php to full url if true.

Type

boolean

$id

$id : integer

The id property, assigns an id if the plugin is used for more than once on a page.

This id will be useful to do modifications in later execution.

Type

integer

$name

$name : string

The name property, defines the plugin name and the identity key for a plugin.

Type

string

$dir

$dir : string

The dir property, specifies the main directory for a given plugin.

Type

string

$file

$file : string

The file property, defines the name of javascript file name for plugin.

By default it is the plugin's name, but can be different.

Type

string

$controllersDir

$controllersDir : \CJAX\Plugin\ExamplePlugin\unknown_type

For ajax request use the plugin name in place of the controller in the url, it will automatically point to your plugin.

eg. ajax.php?ExamplePlugin/docs

Cjax will add the plugin controller on top of the list, if a controller is not found it will continue its normal process and see for a controller in the default controller process.

would seek for: plugins/ExamplePlugin/cntrollers/ExamplePlugin.php:docs();

Type

\CJAX\Plugin\ExamplePlugin\unknown_type

$controllerFile

$controllerFile : string

The controllersFile property, defines the controllers file name for this plugin.

Type

string

$init

$init : string

The init property, which is an executable string runs before plugin is created.

Type

string

$xml

$xml : \CJAX\Core\XmlItem

The xml property, stores an instance of XmlItem object for this plugin.

Type

\CJAX\Core\XmlItem

$params

$params : array

The params property, specifies the plugin arguments.

Type

array

$class

$class : string

The class property, defines a class pertaining to an addon.

Type

string

$elementId

$elementId : string

The elementId property, stores the element Id associated with plugin event.

Type

string

$entryIds

$entryIds : array

The entryIds property, stores an array of entry ids for this plugin.

Type

array

$exclude

$exclude : \CJAX\Plugin\ExamplePlugin\unknown_type

This excludes this plugins from being processed

Type

\CJAX\Plugin\ExamplePlugin\unknown_type

$coreEvents

$coreEvents : \CJAX\Core\CoreEvents

The coreEvents property, stores an instance of injected CoreEvents object.

Type

\CJAX\Core\CoreEvents

$cookie

$cookie : boolean

The cookie property, it will use cookie instead of session if true.

Type

boolean

$aborted

$aborted : boolean

The aborted property, specifes if the plugin is aborted.

Type

boolean

Methods

__construct()

__construct(\CJAX\Core\CoreEvents  $coreEvents, array  $array = array()) : \CJAX\Core\Plugin

The constructor for Plugin class, creates an instance of Plugin object.

Parameters

\CJAX\Core\CoreEvents $coreEvents
array $array

Returns

\CJAX\Core\Plugin

init()

init() : string

The init method, fetches the executable string for $init.

Returns

string

isAborted()

isAborted() : boolean

The isAborted method, checks if this plugin has been aborted.

Returns

boolean

abort()

abort() : void

The abort method, terminates plugin executation and deletes plugin entry ids.

xmlObject()

xmlObject() : \CJAX\Core\XmlItem

The xmlObject method, gets the XmlItem object associated with this plugin.

Returns

\CJAX\Core\XmlItem

xml()

xml() : integer

The xml method, mirrors XmlItem's xml() method.

Returns

integer

output()

output() : object

The output method, mirrors XmlItem's output() method.

Returns

object

delete()

delete() : object

The delete method, mirrors XmlItem's delete() method.

Returns

object

import()

import(string  $file, integer  $loadTime, boolean  $onInit = false) : void

The import method, imports and caches a JavaScript or CSS file.

Parameters

string $file
integer $loadTime
boolean $onInit

imports()

imports(array  $files = array(), array  $data = array()) : void

like import() - imports allows you to import files into the page, the difference is

Parameters

array $files
array $data

waitFor()

waitFor(string  $file) : void

The waitFor method, wait for javascript file to be loaded before firing plugin.

Parameters

string $file

get()

get(string  $setting, string  $prefix = null) : mixed

Get plugin setting saved with save();

Parameters

string $setting
string $prefix

Returns

mixed

set()

set(string  $setting, mixed  $value, integer  $instanceId = null) : void

Update parameters You may use a,b,c,d,e,f etc.

. as $setting.

if the setting is called other than the alphabeth, you may still access these settings eg:

Instead of updating parameters you would be updating variables

Lets say you set variable testing:

$this->set('testing','Hello!');

in your plugin you can access it as: this.testing (if it is inside the scope) or ExamplePlugin.testing outside the scope of your plugin.

if you use __get() magic function, you should be able to intercept.

Parameters

string $setting
mixed $value
integer $instanceId

setVars()

setVars(string  $setting, mixed  $value) : void

The setVars method, set variables that can be accessed as this.var in javascript for all instance ids.

Parameters

string $setting
mixed $value

save()

save(string  $setting, mixed  $value, string  $prefix = null) : void

Save plugin settings globally in a session or cookie variable

Parameters

string $setting
mixed $value
string $prefix

deleteEntry()

deleteEntry(integer  $entryId) : void

The deleteEntry method, deletes an entry id for plugin.

Parameters

integer $entryId

callback()

callback(object  $apiObj) : void

The callback method, assigns an API as javascript callback function.

Parameters

object $apiObj

prevent()

prevent(object  $apiObj) : void

The prevent method, intercepts an API and prevent it from being fired.

Parameters

object $apiObj

__get()

__get(string  $setting) : mixed

The magic method __get, dynamically gets a setting/parameter for plugin.

Parameters

string $setting

Returns

mixed

__set()

__set(string  $setting, mixed  $value) : void

The magic method __set, dynamically sets a parameter/setting for plugin.

Parameters

string $setting
mixed $value

__call()

__call(string  $api, array  $args) : void

The magic method __call, carries out right handlers chain APIs.

Parameters

string $api
array $args

autoload()

autoload() 

Autoload - is fired regardless of if the plugin is called or not, in page load and during ajax requests

PageAutoload()

PageAutoload() 

Autoload - is fired regardless of if the plugin is called or not while the page first load ( not in ajax requests)

AjaxAutoload()

AjaxAutoload() 

Autoload - is fired during an ajax request regardless of if the plugin is called or not

___construct()

___construct(\CJAX\Plugin\ExamplePlugin\unknown_type  $arg, \CJAX\Plugin\ExamplePlugin\unknown_type  $arg2) 

Constructor

This function is ran when the plugin is initialized as $ajax->ExamplePlugin();

Paramaters: through the plugin contructor eg. $ajax->ExamplePlugin('test1','test2');

This function is ran on contruction - for both page load and ajax.

Parameters

\CJAX\Plugin\ExamplePlugin\unknown_type $arg
\CJAX\Plugin\ExamplePlugin\unknown_type $arg2

waitfor()

waitfor(\CJAX\Plugin\ExamplePlugin\unknown_type  $file) 

$this->waitFor('Some-js-file-loaded-throgh-import.js');

Lets say that you loaded a javascritp file usin:

$ajax->import('some_file.js');

Javascript loads scripts acrimoniously so some times even if you load script #1 before #2, it is posibble that script #2 loads before script #1, so this would prevent some times the plugin to work. Here is where waitFor comes in.

$ajax->waitFor() - allows #1 to fully load before loading script #2.

Also there is another approach to this, see: $this->callback();

Parameters

\CJAX\Plugin\ExamplePlugin\unknown_type $file

onLoad()

onLoad(\CJAX\Plugin\ExamplePlugin\unknown_type  $arg = null, \CJAX\Plugin\ExamplePlugin\unknown_type  $ar2 = array()) 

Semi-Constructor function

This function is automatically fired on page load when the loading is invoqued. Is similar to the constructor, except this one won't be fired on ajax requests, just on page load.

The parameters of the contructor will be passed.

Parameters

\CJAX\Plugin\ExamplePlugin\unknown_type $arg
\CJAX\Plugin\ExamplePlugin\unknown_type $ar2

onAjaxLoad()

onAjaxLoad(  $arg = null,   $ar2 = null) 

Semi-Constructor function

This function is ran only when is an ajax request or a requests approved by $ajax->isAjaxRequest() That may include others type of requests.

The parameters of the contructor will be passed.

Parameters

$arg
$ar2

onEvent()

onEvent(  $elementId) 

This function is ran within exec when plugin passed as paramenter.

Serves mainly to obtain the elementId being used.

As of 5.3 +

Parameters

$elementId

rightHandler()

rightHandler(string  $api, array  $args,   $xmlObj) 

Handles right api assignments eg:

$ajax->overlay()->[plugin](); $ajax->call()->[plugin](); etc...

Parameters

string $api
  • internal API name
array $args
$xmlObj

callbackHandler()

callbackHandler(  $xmlObjFrom,   $xmlObjTo,   $setting) 

Advanced Callback Handler

Pushes an API to be a part of another API or Plugin instead of running on its own, then you may access that other callback in plugins through this.callback

If your rightHandler is a callback, you may create a custom handler for that callback, mainly micmic the functionality in core/classes/xmlItem.php on function __set() case 'callback'

Parameters

$xmlObjFrom
$xmlObjTo
$setting

setVar()

setVar(string  $setting, mixed  $value, integer  $instanceId) : void

The setVar method, set variables that can be accessed as this.var in javascript.

Parameters

string $setting
mixed $value
integer $instanceId