Example #1
0
function _pluginExecute($params)
{
    $conf = $GLOBALS['_MAX']['CONF'];
    $paramParams = $params->getParam(0);
    $pluginParams = unserialize($paramParams->scalarval());
    // Instansiate the plugin and execute the method
    include_once MAX_PATH . '/lib/max/Plugin.php';
    $plugin = MAX_Plugin::factory($pluginParams['module'], strtolower($conf['database']['type']));
    if ($plugin) {
        $result = array();
        $result = $plugin->{$pluginParams}['method']($pluginParams['data']);
    }
    $response = new XML_RPC_Value(serialize($result), 'base64');
    return new XML_RPC_Response($response);
}
Example #2
0
 /**
  * A factory method, for including and instantiating a plugin, based on the
  * information in that plugin's configuration file(s), given a module (and
  * optional information about the plugin's configuration options).
  *
  * @static
  * @param string $module The plugin module name (i.e. /plugins/module directory).
  * @param string $configKey Optional configuration key name, which stores the
  *                          details of the plugin package name. Default is 'type'.
  * @param string $omit An optional setting, where if the value retrieved from the
  *                     configuration file for the $configKey is this, then it is
  *                     known that the plugin module is not been configured, or
  *                     is set to use no package. Default is 'none'.
  * @return mixed The instantiated plugin object, null if configured to return
  *               no plugin, or false on error.
  */
 function &factoryPluginByModuleConfig($module, $configKey = 'type', $omit = 'none')
 {
     // Read the module configuration file
     $conf = MAX_Plugin::getConfig($module);
     // Get the $configKey value from this configuration,
     // and convert into the package/plugin name
     if (!isset($conf[$configKey])) {
         return false;
     } else {
         $packageName = explode(':', $conf[$configKey]);
         if (count($packageName) > 1) {
             $package = $packageName[0];
             $name = $packageName[1];
         } else {
             $package = $conf[$configKey];
             $name = null;
         }
     }
     // Ensure that only real, valid packages/plugins are instantiated
     if ($package == $omit) {
         $r = null;
         return $r;
     }
     // Instantiate the plugin, if possible
     if (!empty($module) && !empty($package)) {
         return MAX_Plugin::factory($module, $package, $name);
     }
     // Error
     return false;
 }
 /**
  * A method to test the factory() method.
  */
 function testFactory()
 {
     // Set the error handling class' handleErrors() method as
     // the error handler for PHP for this test.
     $oTestErrorHandler = new TestErrorHandler();
     PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array(&$oTestErrorHandler, 'handleErrors'));
     // Test basic creation of a non-existant plugin fails
     $result = MAX_Plugin::factory('foo', 'bar');
     $this->assertEqual(count($oTestErrorHandler->aErrors), 1);
     $this->assertEqual($oTestErrorHandler->aErrors[0]->message, 'Unable to include the file ' . MAX_PATH . '/plugins/foo/bar/bar' . MAX_PLUGINS_EXTENSION . '.');
     $this->assertFalse($result);
     $oTestErrorHandler->reset();
     // Test plugin name creation of a non-existant plugin fails
     $result = MAX_Plugin::factory('foo', 'bar', 'baz');
     $this->assertEqual(count($oTestErrorHandler->aErrors), 1);
     $this->assertEqual($oTestErrorHandler->aErrors[0]->message, 'Unable to include the file ' . MAX_PATH . '/plugins/foo/bar/baz' . MAX_PLUGINS_EXTENSION . '.');
     $this->assertFalse($result);
     $oTestErrorHandler->reset();
     // Test correct creation of a plugin object
     $result = MAX_Plugin::factory('reports', 'standard', 'advertisingAnalysisReport');
     $this->assertEqual(count($oTestErrorHandler->aErrors), 0);
     $this->assertTrue(is_a($result, 'Plugins_Reports_Standard_AdvertisingAnalysisReport'));
     $this->assertEqual($result->module, 'reports');
     $this->assertEqual($result->package, 'standard');
     $this->assertEqual($result->name, 'advertisingAnalysisReport');
     $oTestErrorHandler->reset();
     // Unset the error handler
     PEAR::popErrorHandling();
 }