commit 256e4630e2d0f058de4df4f64913d201904308fd
parent f204911230929d680e502b33d2b33e27ed871be2
Author: Jan Dankert <devnull@localhost>
Date: Thu, 18 Oct 2012 23:54:42 +0200
JSON-Ausgabe wird über den Request-Parameter 'output' gesteuert. Die Ausgabevariablen sind von nun an im Array 'output' verschachtelt, damit die API lesbarer wird. Neu: API-Version ausgeben.
Diffstat:
3 files changed, 11 insertions(+), 217 deletions(-)
diff --git a/action/Action.class.php b/action/Action.class.php
@@ -49,7 +49,7 @@ define('OR_FILTER_ALL' ,'all' );
class Action
{
var $db;
- var $templateVars = Array();
+ private $templateVars = Array();
var $actionName;
var $subActionName;
var $actionClassName;
@@ -105,6 +105,7 @@ class Action
$this->templateVars['errors' ] = array();
$this->templateVars['notices'] = array();
$this->templateVars['control'] = array();
+ $this->templateVars['output' ] = array();
//Html::debug($this);
if ( !$this->isEditable() || isset($_COOKIE['or_always_edit']) )
@@ -261,7 +262,7 @@ class Action
*/
protected function setTemplateVar( $varName,$value )
{
- $this->templateVars[ $varName ] = $value;
+ $this->templateVars[ 'output' ][ $varName ] = $value;
}
@@ -352,7 +353,7 @@ class Action
* Ausgabe f�r den Browser, starten.<br>
* <br>
*/
- function forward()
+ public function forward()
{
$db = db_connection();
@@ -390,6 +391,7 @@ class Action
// Weitere Variablen anreichern.
$this->templateVars['session'] = array('name'=>session_name(),'id'=>session_id(),'token'=>token() );
$this->templateVars['version'] = OR_VERSION;
+ $this->templateVars['api' ] = '2';
if ( sizeof($types)==1 && in_array('application/php-array',$types) || $this->getRequestVar('output')=='php-array' )
{
@@ -456,7 +458,7 @@ class Action
// ?bertragen der Array-Variablen in den aktuellen Kontext
//
- extract( $this->templateVars );
+ extract( $this->templateVars['output'] );
// Falls Eingabefehler, dann Uebertragen der Request-Variablen in den aktuellen Kontext
if ( count($errors)>0 )
diff --git a/dispatcher.php b/dispatcher.php
@@ -293,20 +293,7 @@ $do->$subactionMethodName();
if ( isset($do->actionConfig[$do->subActionName]['direct']) )
exit;
-
-if ( isset($do->actionConfig[$do->subActionName]['async' ]) || $isAction )
-{
- $json = new JSON();
- header('Content-Type: application/json; charset=UTF-8');
-
- // Weitere Variablen anreichern.
- $do->templateVars['session'] = array('name'=>session_name(),'id'=>session_id(),'token'=>token() );
- $do->templateVars['version'] = OR_VERSION;
-
- echo $json->encode( $do->templateVars );
- exit;
-}
-
+
if ( $conf['interface']['redirect'] )
{
// Wenn Validierungsfehler aufgetrete sind, auf keinen Fall einen Redirect machen, da sonst
@@ -320,203 +307,7 @@ if ( $conf['interface']['redirect'] )
}
}
-
-
-/*
-// Schritt 2:
-// Alle Views durchlaufen
-foreach( $views as $view=>$viewConfig )
-{
- if ( $viewConfig == null )
- continue;
-
- $action = $viewConfig['action'];
- $subaction = $viewConfig['subaction'];
-
- if ( isset($viewCache[$view]) && $view != @$REQ[REQ_PARAM_TARGET] )
- {
- $viewCache[$view]['source'] = 'cache';
- continue;
- }
-
- $actionClassName = ucfirst($action).'Action';
-
- if ( !isset($conf['action'][$actionClassName]) )
- Http::serverError("Action '$action' is undefined.");
-
- require_once( OR_ACTIONCLASSES_DIR.'/'.$actionClassName.'.class.php' );
-
- // Erzeugen der Action-Klasse
- $do = new $actionClassName;
- $do->actionConfig = $conf['action'][$actionClassName];
- $do->actionClassName = $actionClassName;
- $do->actionName = $action;
- if ( $subaction == '' )
- $subaction = $do->actionConfig['default']['goto'];
-
- $do->subActionName = $subaction;
-
-
-
- if ( !isset($do->actionConfig[$subaction]) )
- {
- Logger::warn( "Action $action has no configured method named $subaction");
- Http::serverError("Action '$action' has no accessable method '$subaction'.");
- exit;
- }
-
-
-
- // Alias-Methode aufrufen.
- if ( isset($do->actionConfig[$do->subActionName]['alias']) )
- {
- $subaction = $do->actionConfig[$do->subActionName]['alias'];
- }
- // GOTO-Methode aufrufen.
- elseif ( isset($do->actionConfig[$do->subActionName]['goto']) )
- {
- $subaction = $do->actionConfig[$do->subActionName]['goto'];
- $do->subActionName = $subaction;
- }
-
- $do->init();
-
- if ( isset($actionTemplateVars))
- {
- //unset( $actionTemplateVars['mode'] );
- $do->templateVars = $actionTemplateVars;
- }
-
- $subactionConfig = $do->actionConfig[$subaction];
- //Logger::trace("controller is calling subaction '$subaction'");
-
- // Eine Subaktion ohne "guest=true" verlangt einen angemeldeten Benutzer.
- if ( !isset($subactionConfig['guest']) || !$subactionConfig['guest'] )
- if ( !is_object($do->currentUser) )
- {
- Logger::debug('No session and no guest action occured, maybe session expired');
- //Http::notAuthorized( lang('SESSION_EXPIRED') );
-
- $viewCache[$view] = array('error'=>'not logged in');
- continue;
- }
-
- // Eine Aktion mit "admin=true" verlangt einen Administrator als Benutzer.
- if ( isset($do->actionConfig['admin']) && $do->actionConfig['admin'] )
- if ( !$do->currentUser->isAdmin )
- {
- Logger::debug('Admin action, but user '.$do->currentUser->name.' is not an admin');
- //Http::notAuthorized( lang('SESSION_EXPIRED') );
- $viewCache[$view] = array('error'=>'no admin');
- continue;
- }
-
-
- // Aktuelle Subaction in Sitzung merken
- if ( isset($do->actionConfig[$subaction]['menu']) )
- {
- $sl = Session::getSubaction();
- if ( !is_array($sl))
- $sl = array();
- $sl[$action] = $subaction;
- Session::setSubaction( $sl );
- }
-
-
-
-
- if ( isset($do->actionConfig[$do->subActionName]['write']) )
- $subactionMethodName = $subaction.'View';
- else
- $subactionMethodName = $subaction;
-
- Logger::debug("Executing $actionClassName::$subactionMethodName");
-
- $do->$subactionMethodName(); // Aufruf der Subaction
-
- $views[$view]['subaction'] = $subaction;
-
-
- // Aufruf der n�chsten Subaction (falls vorhanden)
-
- if ( false && isset($do->actionConfig[$do->subActionName]['goto']) )
- {
- // Achtung: Redirect fuehrt zu Problemen beim Login sowie der Anzeige von Notices
- if ( $conf['interface']['redirect'] )
- {
- // Wenn Validierungsfehler aufgetrete sind, auf keinen Fall einen Redirect machen, da sonst
- // im naechsten Request die Eingabedaten fehlen.
- if ( empty($do->templateVars['errors']) )
- {
- $subActionName = $do->actionConfig[$do->subActionName]['goto'];
- header( 'HTTP/1.0 303 See other');
- // Absoluten Pfad kann auch der Client ergaenzen.
- header( 'Location: '.Html::url($action,$do->actionConfig[$do->subActionName]['goto'],$do->getRequestId()) );
- exit;
- }
- }
-
- $subActionName = $do->actionConfig[$do->subActionName]['goto'];
- $views[$view]['subaction'] = $subActionName;
-
- $do->subActionName = $subActionName;
- $subaction = $subActionName;
-
- // Auf Alias pr�fen.
- if ( isset($do->actionConfig[$do->subActionName]['alias']) )
- {
- $subaction = $do->actionConfig[$do->subActionName]['alias'];
- }
-
- Logger::debug("Executing $actionClassName::$subaction (following GOTO)");
- // Alias-Methode aufrufen.
- if ( isset($do->actionConfig[$subActionName]['write']) )
- {
- $subActionView = $subActionName.'View';
- $do->$subActionView();
- }
- else
- {
- $do->$subaction();
- }
- }
- $do->setMenu(); // Menue erzeugen
-
- // Anzeigedaten in den Cache schreiben.
- $viewCache[$view] = $do->templateVars;
- $viewCache[$view]['source'] = 'request';
-
- // $do->forward(); // Anzeige rendern
-}
-*/
-
-
-// Erst jetzt die Views wegschreiben (könnten sich durch ein "GOTO" verändert haben).
-
-//Html::debug($views,'VIEWS am Ende');
-
-// TODO: Globle Variablen für den Seitenkopf.
-/*
-$root_stylesheet = OR_THEMES_EXT_DIR.$conf['interface']['theme'].'/css/layout.css';
-$sessionStyle = Session::get('style');
-$user_stylesheet = OR_THEMES_EXT_DIR.$conf['interface']['theme'].'/css/user/'.(!empty($sessionStyle)?$sessionStyle:$conf['interface']['style']['default']).'.css';
-//$self = $HTTP_SERVER_VARS['PHP_SELF'];
-if ( !empty($conf['interface']['override_title']) )
- $cms_title = $conf['interface']['override_title'];
-else
- $cms_title = OR_TITLE.' '.OR_VERSION;
-$showDuration = $conf['interface']['show_duration'];
-*/
-
-/*
- *
- $viewConfig = $views[$view];
-
- if ( $viewConfig == null )
- return; // View ist leer.
- */
-
- $do->forward();
+$do->forward();
// fertig :)
?>
\ No newline at end of file
diff --git a/themes/default/js/openrat.js b/themes/default/js/openrat.js
@@ -485,11 +485,12 @@ function loadTree()
function loadBranch(li,type,id)
{
//alert("hier rein: "+$(li).html() );
- $.getJSON('./dispatcher.php?action=tree&subaction=loadBranch&id='+id+'&type='+type, function(json) {
+ $.getJSON('./dispatcher.php?action=tree&subaction=loadBranch&id='+id+'&type='+type+'&output=json', function(json) {
$(li).append('<ul class="tree" style="display:none;"/>');
//alert("öffne: "+$(li).html()+" neu: "+$(li).html());
var ul = $(li).children('ul').first();
- $.each(json['branch'],function(idx,line)
+ var output = json['output'];
+ $.each(output['branch'],function(idx,line)
{
//var img = (line.url!==undefined?'tree_plus':'tree_none');
$(ul).append( '<li><div class="tree"> </div><div class="entry" title="'+ line.description + '"><img src="'+OR_THEMES_EXT_DIR+'default/images/icon_'+line['icon']+'.png" />'+ line.text + '</div></li>' );