Although I'm sure it's not recommended and if you don't mind making a small hack in the manager/includes/document.parser.class.inc.php file it is quire easy to add your own custom API.
Change at around line 50 of document.parser.class.inc.php :
// constructor
function DocumentParser() {
$this->loadExtension('DBAPI') or die('Could not load DBAPI class.'); // load DBAPI class
$this->loadExtension('CustomAPI') or die('Could not load CustomAPI class.'); // load CustomAPI class
$this->dbConfig= & $this->db->config; // alias for backward compatibility
$this->jscripts= array ();
$this->sjscripts= array ();
$this->loadedjscripts= array ();
// events
$this->event= new SystemEvent();
$this->Event= & $this->event; //alias for backward compatibility
$this->pluginEvent= array ();
// set track_errors ini variable
@ ini_set("track_errors", "1"); // enable error tracking in $php_errormsg
}
// loads an extension from the extenders folder
function loadExtension($extname) {
global $database_type;
switch ($extname) {
// Database API
case 'DBAPI' :
if (!include_once MODX_BASE_PATH . 'manager/includes/extenders/dbapi.' . $database_type . '.class.inc.php')
return false;
$this->db= new DBAPI;
return true;
break;
// Manager API
case 'ManagerAPI' :
if (!include_once MODX_BASE_PATH . 'manager/includes/extenders/manager.api.class.inc.php')
return false;
$this->manager= new ManagerAPI;
return true;
break;
// CustomAPI
case 'CustomAPI' :
if (!include_once MODX_BASE_PATH . 'manager/includes/extenders/custom.api.class.inc.php')
return false;
$this->custom= new CustomAPI;
return true;
break;
default :
return false;
}
}
So now we have our extension loading and being included, we need our manager/includes/extenders/custom.api.class.inc.php
The one below is just a demo and has no particularly useful functions :
<?php
class CustomAPI {
var $customId;
var $customClass;
var $customLink;
var $customQuery;
var $customQueryValue;
function setCustomClass($customClass) {
$this->customClass = $customClass ? $customClass : 'my-class';
return ' class="'.$this->customClass.'" ';
}
function setCustomQuery($customQuery) {
$this->customQuery = $customQuery ? $customQuery : 'searching';
return $this->customQuery;
}
function setCustomQueryValue($customQueryValue) {
$this->customQueryValue = $customQueryValue ? $customQueryValue : 'something';
return '='.$this->customQueryValue;
}
function setCustomId($customId,$customQuery,$customQueryValue){
global $modx;
$this->customId = $customId ? $customId : 1;
$url = $modx->makeUrl($this->customId,'',$this->setCustomQuery($customQuery) . $this->setCustomQueryValue($customQueryValue), 'full');
return ' href="'.$url.'"';
}
function setCustomLink($customLink){
$this->customLink = $customLink ? $customLink : 'link text here';
return $this->customLink;
}
function setCustomOutput($customClass,$customId,$customLink,$customQuery,$customQueryValue) {
$o .= '<a';
$o .= $this->setCustomId($customId,$customQuery,$customQueryValue);
$o .= $this->setCustomClass($customClass);
$o .= '>';
$o .= $this->setCustomLink($customLink);
$o .= '</a>';
return $o;
}
}
?>
Finally a snippet to do something with the newly extended API :
<?php
/*
$text = $modx->custom->setCustomOutput('link class name', 'document id', 'link text', 'querystring name', 'querystring value');
defaults set in cusom api class are => ('my-class', '1', 'link text here', 'searching', 'something');
gives output of <a href="http://localhost/development/index.html?searching=something" class="my-class">link text here</a>
*/
$text = $modx->custom->setCustomOutput('','' ,'','','');
return $text;
?>
More of a proof of concept than something instantly usable, but it seems to work okay.
Obviously you'd loose the edits in the document.parser.class.inc.php in an upgrade so a backup needs to be made.
There may be some impact on performance, particularly if your own custom API is large or demanding.