$this->search = Horde::loadConfiguration('search.php', 'search');
}
- public static function dispatch($koward)
+ public static function dispatch($koward, $request_class = 'Horde_Controller_Request_Http',
+ $webroot = null)
{
global $registry, $notification, $browser;
$notification = Notification::singleton();
$notification->attach('status');
- $registry = Registry::singleton();
+ $registry = Registry::singleton();
/* Browser detection object. */
if (class_exists('Horde_Browser')) {
$browser = Horde_Browser::singleton();
}
- $webroot = Koward::_detectWebroot($koward);
+ if ($webroot === null) {
+ $webroot = Koward::_detectWebroot($koward);
+ }
// Set up our request and routing objects
- $request = new Horde_Controller_Request_Http();
+ $request = new $request_class();
$mapper = new Horde_Routes_Mapper();
// Application routes are relative only to the application. Let the mapper know
$session = Horde_Kolab_Session::singleton();
if (!empty($session->user_uid)) {
$user = $this->getObject($session->user_uid);
+ if (get_class($user) == $this->conf['koward']['cli_admin']
+ && Horde_CLI::runningFromCLI()) {
+ return true;
+ }
$type = $this->getType($user);
if (isset($this->objects[$type]['permission'])) {
return $this->_hasPermission($this->objects[$type]['permission'],
);
list($this->_argv, $args) = $parser->parseArgs();
if (!count($args)) {
- throw new Horde_Controller_Exception('unknown command: ' . implode(' ', $args));
+ throw new Koward_Exception('unknown command: ' . implode(' ', $args));
}
/**
}
}
+ if (is_a(($pushed = $registry->pushApp('koward',
+ empty($this->auth_handler)
+ || $this->auth_handler != $this->params[':action'])), 'PEAR_Error')) {
+ if ($pushed->getCode() == 'permission_denied') {
+ header('Location: ' . $this->urlFor(array('controller' => 'index', 'action' => 'login')));
+ exit;
+ }
+ }
+
/**
* A rough command line handler that allows us to map CLI requests into
* the web view of the system.
*/
switch ($args[0]) {
- case 'object/edit':
+ case 'object/add':
$this->_cmd_argv['formname'] = 'koward_form_object';
/** Has the object type been set? */
* to use the standard form mechanisms via CLI. Think of some
* alternatives here.
*/
- $koward = &Koward_Koward::singleton();
+ $koward = &Koward::singleton();
$token = $koward->getRequestToken('cli');
$this->_cmd_argv['koward_form_object_formToken'] = $token;
/**
* Provide a token for immediate deletion.
*/
- $koward = &Koward_Koward::singleton();
+ $koward = &Koward::singleton();
$this->_cmd_argv['token'] = $koward->getRequestToken('object.delete');
break;
$cli->init();
/**
- * Hm, the fact that we need the registry at this point for identifying the
- * location where we installed the application is not really satisfying. The
- * whole "app" dir should probably be in "lib", too. That way we can install it
- * in a defined location via PEAR.
+ * Hm, the fact that we need the registry at this point for
+ * identifying the location where we installed the application is not
+ * really satisfying. We need it to know the location of the
+ * configuration though.
*/
-require_once $opts->base . '/lib/base.php';
-
-/** Configure the Autoloader */
-$app = 'koward';
-Horde_Autoloader::addClassPattern('/^Koward_/', $registry->get('fileroot', $app) . '/lib/');
-Horde_Autoloader::addClassPattern('/^Koward_/', $registry->get('fileroot', $app) . '/app/controllers/');
+require_once $opts->base . '/koward/config/base.php';
/**
* FIXME END
*/
-/** Initialize the command line handler */
-$request = new Koward_Cli();
-
-/**
- * The following is an extract from rampage.php and only a rough draft. Calling
- * Controller actions this way is still rather complicated on the command line
- * this way. For one thing you need to provide the application installation base
- * which is knowledge we'd rather hide from the user and the full path to the
- * Controller action (including the path to the app identified by the registry)
- * has to be provided. This should be handled via other CLI parameters.
- */
-$mapper = new Horde_Routes_Mapper();
-
-$routeFile = $registry->get('fileroot', $app) . '/config/routes.php';
-if (!file_exists($routeFile)) {
- throw new Horde_Controller_Exception('Not routable');
-}
-$mapper->prefix = $registry->get('webroot', 'horde') . '/' . $app;
-include $routeFile;
-
-$context = array(
- 'mapper' => $mapper,
- 'controllerDir' => $registry->get('fileroot', $app) . '/app/controllers',
- 'viewsDir' => $registry->get('fileroot', $app) . '/app/views',
- // 'logger' => '',
-);
+/** Configure the Autoloader to handle the "Koward" pattern */
+Horde_Autoloader::addClassPattern('/^Koward_/', 'Koward/');
+/** Dispatch the request. */
try {
- $dispatcher = Horde_Controller_Dispatcher::singleton($context);
- $dispatcher->dispatch($request);
+ Koward::dispatch($opts->base . '/htdocs/koward/koward.php', 'Koward_Cli', '/koward');
} catch (Exception $e) {
// @TODO Make nicer
echo '<h1>' . $e->getMessage() . '</h1>';
echo '<pre>'; var_dump($e); echo '</pre>';
}
-
-exit(0);
/** Dispatch the request. */
try {
- Koward::dispatch(__FILE__);
+ Koward::dispatch(__FILE__, 'Horde_Controller_Request_Http');
} catch (Exception $e) {
// @TODO Make nicer
echo '<h1>' . $e->getMessage() . '</h1>';