Skip to content
This repository
Browse code

changed usage of OntoWiki_Application, remove require_once

  • Loading branch information...
commit bf81e76fca4e1ad589a9127dc783f0e9459a220d 1 parent efc8f87
Norman Heino 0xfeedface authored

Showing 23 changed files with 459 additions and 386 deletions. Show diff stats Hide diff stats

  1. +167 23 application/Bootstrap.php
  2. +119 7 application/classes/OntoWiki.php
  3. +0 148 application/classes/OntoWiki/Application.php
  4. +19 30 application/classes/OntoWiki/Controller/Plugin/SetupHelper.php
  5. +19 1 application/classes/OntoWiki/Dispatcher.php
  6. +1 3 application/classes/OntoWiki/Message.php
  7. +0 12 application/classes/OntoWiki/Model.php
  8. +1 13 application/classes/OntoWiki/Model/Hierarchy.php
  9. +30 41 application/classes/OntoWiki/Model/Instances.php
  10. +1 12 application/classes/OntoWiki/Model/Resource.php
  11. +1 8 application/classes/OntoWiki/Model/TitleHelper.php
  12. +2 1  application/classes/OntoWiki/Module/Manager.php
  13. +26 13 application/classes/OntoWiki/Module/Registry.php
  14. +3 3 application/classes/OntoWiki/Plugin.php
  15. +34 10 application/classes/OntoWiki/Toolbar.php
  16. +1 11 application/classes/OntoWiki/Url.php
  17. +19 23 application/classes/OntoWiki/View.php
  18. +5 5 application/config/application.ini
  19. +2 3 application/controllers/ErrorController.php
  20. +1 1  application/controllers/ModelController.php
  21. +5 9 extensions/modules/modellist/modellist.php
  22. +1 4 extensions/plugins/linkeddata/linkeddata.php
  23. +2 5 index.php
190 application/Bootstrap.php
@@ -28,14 +28,14 @@ public function _initConfig()
28 28 {
29 29 // load default application configuration file
30 30 try {
31   - $config = new Zend_Config_Ini(_OWROOT . 'application/config/default.ini', 'default', true);
  31 + $config = new Zend_Config_Ini(ONTOWIKI_ROOT . 'application/config/default.ini', 'default', true);
32 32 } catch (Zend_Config_Exception $e) {
33 33 exit($e->getMessage());
34 34 }
35 35
36 36 // load user application configuration files
37 37 try {
38   - $privateConfig = new Zend_Config_Ini(_OWROOT . 'config.ini', 'private', true);
  38 + $privateConfig = new Zend_Config_Ini(ONTOWIKI_ROOT . 'config.ini', 'private', true);
39 39 $config->merge($privateConfig);
40 40 } catch (Zend_Config_Exception $e) {
41 41 exit($e->getMessage());
@@ -60,14 +60,20 @@ public function _initConfig()
60 60 // support absolute path
61 61 $matches = array();
62 62 if (!(preg_match('/^(\w:[\/|\\\\]|\/)/', $config->cache->path, $matches) === 1)) {
63   - $config->cache->path = _OWROOT . $config->cache->path;
  63 + $config->cache->path = ONTOWIKI_ROOT . $config->cache->path;
64 64 }
65 65
  66 + // set path variables
  67 + $rewriteBase = substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], BOOTSTRAP_FILE));
  68 + $protocol = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? 'https' : 'http';
  69 + $port = $_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '';
  70 + $urlBase = sprintf('%s://%s%s%s', $protocol, $_SERVER['SERVER_NAME'], $port, $rewriteBase);
  71 +
66 72 // construct URL variables
67   - $config->host = parse_url($this->urlBase, PHP_URL_HOST);
68   - $config->urlBase = rtrim($this->urlBase, '/\\') . '/';
69   - $config->staticUrlBase = rtrim($this->staticUrlBase, '/\\') . '/';
70   - $config->themeUrlBase = $this->staticUrlBase
  73 + $config->host = parse_url($urlBase, PHP_URL_HOST);
  74 + $config->urlBase = rtrim($urlBase . (ONTOWIKI_REWRITE ? '' : BOOTSTRAP_FILE), '/\\') . '/';
  75 + $config->staticUrlBase = rtrim($urlBase, '/\\') . '/';
  76 + $config->themeUrlBase = $config->staticUrlBase
71 77 . $config->themes->path
72 78 . $config->themes->default;
73 79
@@ -96,7 +102,12 @@ public function _initDispatcher()
96 102 $this->bootstrap('frontController');
97 103 $frontController = $this->getResource('frontController');
98 104
99   - $dispatcher = new OntoWiki_Dispatcher();
  105 + // require Config
  106 + $this->bootstrap('Config');
  107 + $config = $this->getResource('Config');
  108 +
  109 + $dispatcher = new OntoWiki_Dispatcher(array('url_base' => $config->urlBase));
  110 + $dispatcher->setControllerDirectory(APPLICATION_PATH . 'controllers');
100 111 $frontController->setDispatcher($dispatcher);
101 112
102 113 return $dispatcher;
@@ -141,7 +152,7 @@ public function _initEventDispatcher()
141 152 *
142 153 * @since 0.9.5
143 154 */
144   - public function _initLog()
  155 + public function _initLogger()
145 156 {
146 157 // require config
147 158 $this->bootstrap('Config');
@@ -157,17 +168,31 @@ public function _initLog()
157 168 $levelFilter = new Zend_Log_Filter_Priority((int)$config->log->level, '<=');
158 169
159 170 $writer = new Zend_Log_Writer_Stream($config->log->path . 'ontowiki.log');
160   - $log = new Zend_Log($writer);
161   - $log->addFilter($levelFilter);
  171 + $logger = new Zend_Log($writer);
  172 + $logger->addFilter($levelFilter);
162 173
163   - return $log;
  174 + return $logger;
164 175 }
165 176
166 177 // fallback to NULL logger
167 178 $writer = new Zend_Log_Writer_Null();
168   - $log = new Zend_Log($writer);
  179 + $logger = new Zend_Log($writer);
169 180
170   - return $log;
  181 + return $logger;
  182 + }
  183 +
  184 + public function _initModuleManager()
  185 + {
  186 + // require config
  187 + $this->bootstrap('Config');
  188 + $config = $this->getResource('Config');
  189 +
  190 + // TODO: make session requirement explicit
  191 + $this->bootstrap('Session');
  192 +
  193 + $moduleManager = new OntoWiki_Module_Manager(ONTOWIKI_ROOT . $config->extensions->modules);
  194 +
  195 + return $moduleManager;
171 196 }
172 197
173 198 /**
@@ -216,12 +241,17 @@ public function _initPlugins()
216 241 */
217 242 public function _initRequest()
218 243 {
219   - $this->bootstrap('frontController');
220   - $frontController = $this->getResource('frontController');
  244 + $this->bootstrap('FrontController');
  245 + $frontController = $this->getResource('FrontController');
  246 +
  247 + $this->bootstrap('Router');
  248 + $router = $this->getResource('Router');
221 249
222 250 $request = new OntoWiki_Request();
223 251 $frontController->setRequest($request);
224 252
  253 + $router->route($request);
  254 +
225 255 return $request;
226 256 }
227 257
@@ -247,6 +277,101 @@ public function _initRouter()
247 277 }
248 278
249 279 /**
  280 + * Initializes the selected resource from the request or session
  281 + */
  282 + // public function _initSelectedModel()
  283 + // {
  284 + // // require Config
  285 + // $this->bootstrap('Config');
  286 + // $config = $this->getResource('Config');
  287 + //
  288 + // // require request
  289 + // $this->bootstrap('Request');
  290 + // $request = $this->getResource('Request');
  291 + //
  292 + // // require Session
  293 + // $this->bootstrap('Session');
  294 + // $session = $this->getResource('Session');
  295 + //
  296 + // // require Erfurt
  297 + // $this->bootstrap('Erfurt');
  298 + // $erfurt = $this->getResource('Erfurt');
  299 + // $store = $erfurt->getStore();
  300 + //
  301 + // // instantiate model if parameter passed
  302 + // if (isset($request->m)) {
  303 + // try {
  304 + // $selectedModel = $store->getModel($request->getParam('m', null, false));
  305 + // $session->selectedModel = $selectedModel;
  306 + // return $selectedModel;
  307 + // } catch (Erfurt_Store_Exception $e) {
  308 + // // if no user is given (Anoymous) give the requesting party a chance to authenticate
  309 + // if (Erfurt_App::getInstance()->getAuth()->getIdentity()->isAnonymousUser()) {
  310 + // $response = $frontController->getResponse();
  311 + //
  312 + // // request authorization
  313 + // $response->setRawHeader('HTTP/1.1 401 Unauthorized');
  314 + // $response->setHeader('WWW-Authenticate', 'FOAF+SSL');
  315 + // $response->sendResponse();
  316 + // exit;
  317 + // }
  318 + //
  319 + // // post error message
  320 + // $owApp->prependMessage(new OntoWiki_Message(
  321 + // '<p>Could not instantiate graph: ' . $e->getMessage() . '</p>' .
  322 + // '<a href="' . $owApp->config->urlBase . '">Return to index page</a>',
  323 + // OntoWiki_Message::ERROR, array('escape' => false)));
  324 + // // hard redirect since finishing the dispatch cycle will lead to errors
  325 + // header('Location:' . $owApp->config->urlBase . 'error/error');
  326 + // exit;
  327 + // }
  328 + // } else if (isset($session->selectedModel)) {
  329 + // return $session->selectedModel;
  330 + // }
  331 + // }
  332 +
  333 + /**
  334 + * Initializes the selected resource from the request
  335 + */
  336 + // public function _initSelectedResource()
  337 + // {
  338 + // // require Config
  339 + // $this->bootstrap('Config');
  340 + // $config = $this->getResource('Config');
  341 + //
  342 + // // require request
  343 + // $this->bootstrap('Request');
  344 + // $request = $this->getResource('Request');
  345 + //
  346 + // // require Session
  347 + // $this->bootstrap('Session');
  348 + // $session = $this->getResource('Session');
  349 + //
  350 + // // require model
  351 + // $this->bootstrap('SelectedModel');
  352 + // $selectedModel = $this->getResource('SelectedModel');
  353 + //
  354 + // if (isset($request->r)) {
  355 + // if ($selectedModel instanceof Erfurt_Rdf_Model) {
  356 + // $selectedResource = new OntoWiki_Resource($request->getParam('r', null, true), $selectedModel);
  357 + // $session->selectedResource = $selectedResource;
  358 + // return $selectedResource;
  359 + // } else {
  360 + // // post error message
  361 + // OntoWiki::getInstance()->prependMessage(new OntoWiki_Message(
  362 + // '<p>Could not instantiate resource. No model selected.</p>' .
  363 + // '<a href="' . $config->urlBase . '">Return to index page</a>',
  364 + // OntoWiki_Message::ERROR, array('escape' => false)));
  365 + // // hard redirect since finishing the dispatch cycle will lead to errors
  366 + // header('Location:' . $config->urlBase . 'error/error');
  367 + // exit;
  368 + // }
  369 + // } else if (isset($session->selectedResource)) {
  370 + // return $session->selectedResource;
  371 + // }
  372 + // }
  373 +
  374 + /**
250 375 * Initializes the session and loads session variables
251 376 *
252 377 * @since 0.9.5
@@ -274,8 +399,16 @@ public function _initSession()
274 399 */
275 400 public function _initToolbar()
276 401 {
277   - // init toolbar
  402 + $this->bootstrap('Config');
  403 + $config = $this->getResource('Config');
  404 +
  405 + $this->bootstrap('Translate');
  406 + $translate = $this->getResource('Translate');
  407 +
  408 + // configure toolbar
278 409 $toolbar = OntoWiki_Toolbar::getInstance();
  410 + $toolbar->setThemeUrlBase($config->themeUrlBase)
  411 + ->setTranslate($translate);
279 412
280 413 return $toolbar;
281 414 }
@@ -285,7 +418,7 @@ public function _initToolbar()
285 418 *
286 419 * @since 0.9.5
287 420 */
288   - public function _initTranslation()
  421 + public function _initTranslate()
289 422 {
290 423 $this->bootstrap('Config');
291 424 $config = $this->getResource('Config');
@@ -318,15 +451,15 @@ public function _initTranslation()
318 451 // don't emit notices
319 452 'disableNotices' => true
320 453 );
321   - $translation = new Zend_Translate('csv', _OWROOT . $config->languages->path, null, $options);
  454 + $translate = new Zend_Translate('csv', _OWROOT . $config->languages->path, null, $options);
322 455 try {
323   - $translation->setLocale($config->languages->locale);
  456 + $translate->setLocale($config->languages->locale);
324 457 } catch (Zend_Translate_Exception $e) {
325 458 $config->languages->locale = 'en';
326   - $translation->setLocale('en');
  459 + $translate->setLocale('en');
327 460 }
328 461
329   - return $translation;
  462 + return $translate;
330 463 }
331 464
332 465 /**
@@ -364,6 +497,10 @@ public function _initView()
364 497 $this->bootstrap('Config');
365 498 $config = $this->getResource('Config');
366 499
  500 + // require Config
  501 + $this->bootstrap('Translate');
  502 + $translate = $this->getResource('Translate');
  503 +
367 504 // standard template path
368 505 $defaultTemplatePath = _OWROOT
369 506 . 'application/views/templates';
@@ -374,8 +511,15 @@ public function _initView()
374 511 . $config->themes->default
375 512 . 'templates';
376 513
  514 + $viewOptions = array(
  515 + 'use_module_cachce' => (bool)$config->cache->modules,
  516 + 'cache_path' => $config->cache->path,
  517 + 'lang' => $config->languages->locale
  518 +
  519 + );
  520 +
377 521 // init view
378   - $view = new OntoWiki_View();
  522 + $view = new OntoWiki_View($viewOptions, $translate);
379 523 $view->addScriptPath($defaultTemplatePath) // default templates
380 524 ->addScriptPath($themeTemplatePath) // theme templates override default ones
381 525 ->setEncoding($config->encoding)
126 application/classes/OntoWiki.php
@@ -61,14 +61,14 @@ class OntoWiki
61 61 */
62 62 private function __construct()
63 63 {
64   - $frontController = Zend_Controller_Front::getInstance();
65   - $this->_bootstrap = $frontController->getParam('bootstrap');
66 64 }
67 65
68 66 /**
69 67 * Disallow cloning
70 68 */
71   - private function __clone() {}
  69 + private function __clone()
  70 + {
  71 + }
72 72
73 73 /**
74 74 * Returns a property value
@@ -83,12 +83,13 @@ public function __get($propertyName)
83 83 $this->_properties[$propertyName] = $this->session->$propertyName;
84 84 }
85 85
86   - if (isset($this->$propertyName)) {
87   - return $this->_properties[$propertyName];
  86 + $bootstrap = $this->getBootstrap();
  87 + if ($bootstrap and $bootstrap->hasResource($propertyName)) {
  88 + return $bootstrap->getResource($propertyName);
88 89 }
89 90
90   - if ($this->_bootstrap->hasResource($propertyName)) {
91   - return $this->_bootstrap->getResource($propertyName);
  91 + if (isset($this->$propertyName)) {
  92 + return $this->_properties[$propertyName];
92 93 }
93 94 }
94 95
@@ -140,6 +141,100 @@ public function __unset($propertyName)
140 141 // ------------------------------------------------------------------------
141 142
142 143 /**
  144 + * Returns the current message stack and empties it.
  145 + *
  146 + * @since 0.9.5
  147 + * @return array
  148 + */
  149 + public function drawMessages()
  150 + {
  151 + return $this->getMessages(true);
  152 + }
  153 +
  154 + /**
  155 + * Returns whether OntoWiki currently has messages for the user
  156 + *
  157 + * @return boolean
  158 + */
  159 + public function hasMessages()
  160 + {
  161 + $messages = $this->getMessages();
  162 +
  163 + return (!empty($messages));
  164 + }
  165 +
  166 + /**
  167 + * Returns the current message stack and empties it.
  168 + *
  169 + * @param boolean $clearMessages Clears the message stack after retrieval
  170 + * @return array
  171 + */
  172 + public function getMessages($clearMessages = false)
  173 + {
  174 + $session = $this->getBootstrap()->getResource('Session');
  175 +
  176 + // store temporarily
  177 + $messageStack = (array)$this->session->messageStack;
  178 +
  179 + if ($clearMessages) {
  180 + // empty message stack
  181 + unset($session->messageStack);
  182 + }
  183 +
  184 + // return temp
  185 + return $messageStack;
  186 + }
  187 +
  188 + /**
  189 + * Appends a message to the message stack
  190 + *
  191 + * @param OntoWiki_Message $message The message to be added.
  192 + * @return OntoWiki_Application
  193 + */
  194 + public function appendMessage(OntoWiki_Message $message)
  195 + {
  196 + $session = $this->getBootstrap()->getResource('Session');
  197 +
  198 + $messageStack = (array)$session->messageStack;
  199 + array_push($messageStack, $message);
  200 +
  201 + $session->messageStack = $messageStack;
  202 +
  203 + return $this;
  204 + }
  205 +
  206 + /**
  207 + * Prepends a message to the message stack
  208 + *
  209 + * @param OntoWiki_Message $message The message to be added.
  210 + * @return OntoWiki_Application
  211 + */
  212 + public function prependMessage(OntoWiki_Message $message)
  213 + {
  214 + $session = $this->getBootstrap()->getResource('Session');
  215 +
  216 + $messageStack = (array)$session->messageStack;
  217 + array_unshift($session->messageStack, $message);
  218 +
  219 + $session->messageStack = $messageStack;
  220 +
  221 + return $this;
  222 + }
  223 +
  224 + /**
  225 + * Returns the application bootstrap object
  226 + */
  227 + public function getBootstrap()
  228 + {
  229 + if (null === $this->_bootstrap) {
  230 + $frontController = Zend_Controller_Front::getInstance();
  231 + $this->_bootstrap = $frontController->getParam('bootstrap');
  232 + }
  233 +
  234 + return $this->_bootstrap;
  235 + }
  236 +
  237 + /**
143 238 * Singleton instance
144 239 *
145 240 * @return OntoWiki
@@ -152,5 +247,22 @@ public static function getInstance()
152 247
153 248 return self::$_instance;
154 249 }
  250 +
  251 + /**
  252 + * Loads variables stored in the session.
  253 + */
  254 + private function _loadSessionVars()
  255 + {
  256 + foreach ($this->_sessionVars as $varName) {
  257 + if (isset($this->session->$varName)) {
  258 + $this->$varName = $this->session->$varName;
  259 + }
  260 + }
  261 +
  262 + // init empty message stack
  263 + if (!isset($this->session->messageStack)) {
  264 + $this->session->messageStack = array();
  265 + }
  266 + }
155 267 }
156 268
148 application/classes/OntoWiki/Application.php
@@ -53,134 +53,6 @@ public function __get($propertyName)
53 53 }
54 54
55 55 /**
56   - * Sets a property
57   - *
58   - * @param string $propertyName
59   - * @param mixed $propertyValue
60   - */
61   - public function __set($propertyName, $propertyValue)
62   - {
63   - if (in_array($propertyName, $this->_sessionVars)) {
64   - $this->session->$propertyName = $propertyValue;
65   - }
66   -
67   - $this->_properties[$propertyName] = $propertyValue;
68   - }
69   -
70   - /**
71   - * Returns whether a property is set
72   - *
73   - * @param string $propertyName
74   - * @return boolean
75   - */
76   - public function __isset($propertyName)
77   - {
78   - return array_key_exists($propertyName, $this->_properties);
79   - }
80   -
81   - /**
82   - * Unsets a property
83   - *
84   - * @param string $propertyName
85   - */
86   - public function __unset($propertyName)
87   - {
88   - if (in_array($propertyName, $this->_sessionVars)) {
89   - unset($this->session->$propertyName);
90   - }
91   -
92   - unset($this->_properties[$propertyName]);
93   - }
94   -
95   - /**
96   - * Appends a message to the message stack
97   - *
98   - * @param OntoWiki_Message $message The message to be added.
99   - * @return OntoWiki_Application
100   - */
101   - public function appendMessage(OntoWiki_Message $message)
102   - {
103   - $messageStack = $this->session->messageStack;
104   - array_push($messageStack, $message);
105   -
106   - $this->session->messageStack = $messageStack;
107   -
108   - return $this;
109   - }
110   -
111   -
112   -
113   - /**
114   - * Returns the current message stack and empties it.
115   - *
116   - * @return array
117   - */
118   - public function getMessages()
119   - {
120   - // store temporarily
121   - $messages = (array) $this->session->messageStack;
122   - // empty message stack
123   - unset($this->session->messageStack);
124   -
125   - // return temp
126   - return $messages;
127   - }
128   -
129   - /**
130   - * Returns the current agent
131   - *
132   - * @return Erfurt_Auth_Identity
133   - */
134   - public function getUser()
135   - {
136   - require_once 'Erfurt/Auth.php';
137   - return Erfurt_Auth::getInstance()->getIdentity();
138   - }
139   -
140   - /**
141   - * Returns whether OntoWiki currently has messages for the user
142   - *
143   - * @return boolean
144   - */
145   - public function hasMessages()
146   - {
147   - return (!empty($this->session->messageStack));
148   - }
149   -
150   - /**
151   - * Prepends a message to the message stack
152   - *
153   - * @param OntoWiki_Message $message The message to be added.
154   - * @return OntoWiki_Application
155   - */
156   - public function prependMessage(OntoWiki_Message $message)
157   - {
158   - array_unshift($this->session->messageStack, $message);
159   -
160   - return $this;
161   - }
162   -
163   - /**
164   - * Sets the base URL under which this OntoWiki application operates
165   - *
166   - * @param string $urlBase
167   - * @return OntoWiki_Application
168   - */
169   - public function setUrlBase($urlBase, $rewriteEngineOn)
170   - {
171   - // dynamic URL base for controller actions
172   - $this->urlBase = $urlBase . ($rewriteEngineOn ? '' : _OWBOOT);
173   -
174   - // static URL base for file access (css, js, png etc.)
175   - $this->staticUrlBase = $urlBase;
176   -
177   - // set rewriting state
178   - $this->rewriting = $rewriteEngineOn;
179   -
180   - return $this;
181   - }
182   -
183   - /**
184 56 * Starts the OntoWiki application and returnes a reference to it.
185 57 *
186 58 * @return OntoWiki_Application
@@ -199,9 +71,6 @@ public static function start($urlBase, $rewriteEngineOn = false)
199 71 */
200 72 public function init()
201 73 {
202   - define('OW_SHOW_MAX', 5);
203   -
204   -
205 74 $this->logger->info('Request start: ' . microtime(true));
206 75
207 76 // initialize Erfurt
@@ -241,22 +110,5 @@ public function init()
241 110
242 111 return $this;
243 112 }
244   -
245   - /**
246   - * Loads variables stored in the session.
247   - */
248   - private function _loadSessionVars()
249   - {
250   - foreach ($this->_sessionVars as $varName) {
251   - if (isset($this->session->$varName)) {
252   - $this->$varName = $this->session->$varName;
253   - }
254   - }
255   -
256   - // init empty message stack
257   - if (!isset($this->session->messageStack)) {
258   - $this->session->messageStack = array();
259   - }
260   - }
261 113 }
262 114
49 application/classes/OntoWiki/Controller/Plugin/SetupHelper.php
@@ -10,8 +10,6 @@
10 10 * @version $Id: SetupHelper.php 4095 2009-08-19 23:00:19Z christian.wuerker $
11 11 */
12 12
13   -require_once 'Zend/Controller/Plugin/Abstract.php';
14   -
15 13 /**
16 14 * OntoWiki Setup Helper Zend plug-in.
17 15 *
@@ -31,18 +29,16 @@ class OntoWiki_Controller_Plugin_SetupHelper extends Zend_Controller_Plugin_Abst
31 29 public function routeShutdown(Zend_Controller_Request_Abstract $request)
32 30 {
33 31 if (!$this->_isSetup) {
34   - require_once 'Zend/Controller/Front.php';
35 32 $frontController = Zend_Controller_Front::getInstance();
36 33
37   - require_once 'OntoWiki/Application.php';
38   - $owApp = OntoWiki_Application::getInstance();
39   - $store = $owApp->erfurt->getStore();
  34 + $ontowiki = OntoWiki::getInstance();
  35 + $store = $ontowiki->erfurt->getStore();
40 36
41 37 // instantiate model if parameter passed
42 38 if (isset($request->m)) {
43 39 try {
44 40 $model = $store->getModel($request->getParam('m', null, false));
45   - $owApp->selectedModel = $model;
  41 + $ontowiki->selectedModel = $model;
46 42 } catch (Erfurt_Store_Exception $e) {
47 43 // When no user is given (Anoymous) give the requesting party a chance to authenticate.
48 44 if (Erfurt_App::getInstance()->getAuth()->getIdentity()->isAnonymousUser()) {
@@ -56,50 +52,43 @@ public function routeShutdown(Zend_Controller_Request_Abstract $request)
56 52 }
57 53
58 54 // post error message
59   - require_once 'OntoWiki/Message.php';
60   - $owApp->prependMessage(new OntoWiki_Message(
  55 + $ontowiki->prependMessage(new OntoWiki_Message(
61 56 '<p>Could not instantiate graph: ' . $e->getMessage() . '</p>' .
62   - '<a href="' . $owApp->config->urlBase . '">Return to index page</a>',
  57 + '<a href="' . $ontowiki->config->urlBase . '">Return to index page</a>',
63 58 OntoWiki_Message::ERROR, array('escape' => false)));
64 59 // hard redirect since finishing the dispatch cycle will lead to errors
65   - header('Location:' . $owApp->config->urlBase . 'error/error');
  60 + header('Location:' . $ontowiki->config->urlBase . 'error/error');
66 61 exit;
67 62 }
68 63 }
69 64
70 65 // instantiate resource if parameter passed
71 66 if (isset($request->r)) {
72   - $graph = $owApp->selectedModel;
  67 + $graph = $ontowiki->selectedModel;
73 68 if ($graph instanceof Erfurt_Rdf_Model) {
74   - require_once 'OntoWiki/Resource.php';
75 69 $resource = new OntoWiki_Resource($request->getParam('r', null, true), $graph);
76   - $owApp->selectedResource = $resource;
  70 + $ontowiki->selectedResource = $resource;
77 71 } else {
78 72 // post error message
79   - require_once 'OntoWiki/Message.php';
80   - $owApp->prependMessage(new OntoWiki_Message(
  73 + $ontowiki->prependMessage(new OntoWiki_Message(
81 74 '<p>Could not instantiate resource. No model selected.</p>' .
82   - '<a href="' . $owApp->config->urlBase . '">Return to index page</a>',
  75 + '<a href="' . $ontowiki->config->urlBase . '">Return to index page</a>',
83 76 OntoWiki_Message::ERROR, array('escape' => false)));
84 77 // hard redirect since finishing the dispatch cycle will lead to errors
85   - header('Location:' . $owApp->config->urlBase . 'error/error');
  78 + header('Location:' . $ontowiki->config->urlBase . 'error/error');
86 79 exit;
87 80 }
88 81 }
89 82
90 83 // initialize components
91   - require_once 'OntoWiki/Component/Manager.php';
92   - $owApp->componentManager = new OntoWiki_Component_Manager(_OWROOT . $owApp->config->extensions->components);
93   -
94   - foreach ($owApp->componentManager->getComponents() as $componentName => $componentConfig) {
95   - $frontController->addControllerDirectory($componentConfig['path'], '_component_' . $componentName);
96   - }
97   -
98   - require_once 'OntoWiki/Module/Manager.php';
99   - $moduleManager = new OntoWiki_Module_Manager(_OWROOT . $owApp->config->extensions->modules);
100   -
101   - $dispatcher = $frontController->getDispatcher();
102   - $dispatcher->setComponentManager($owApp->componentManager);
  84 + // $owApp->componentManager = new OntoWiki_Component_Manager(_OWROOT . $owApp->config->extensions->components);
  85 + //
  86 + // foreach ($owApp->componentManager->getComponents() as $componentName => $componentConfig) {
  87 + // $frontController->addControllerDirectory($componentConfig['path'], '_component_' . $componentName);
  88 + // }
  89 + //
  90 + // $dispatcher = $frontController->getDispatcher();
  91 + // $dispatcher->setComponentManager($owApp->componentManager);
103 92
104 93 // avoid setting up twice
105 94 $this->_isSetup = true;
20 application/classes/OntoWiki/Dispatcher.php
@@ -40,6 +40,24 @@ class OntoWiki_Dispatcher extends Zend_Controller_Dispatcher_Standard
40 40 protected $_componentManager = null;
41 41
42 42 /**
  43 + * Base for building URLs
  44 + * @var string
  45 + */
  46 + protected $_urlBase = '';
  47 +
  48 + public function __construct($params = array())
  49 + {
  50 + if (array_key_exists('url_base', $params)) {
  51 + $urlBase = (string)$params['url_base'];
  52 + unset($params['url_base']);
  53 + }
  54 +
  55 + parent::__construct($params);
  56 +
  57 + $this->urlBase = $urlBase;
  58 + }
  59 +
  60 + /**
43 61 * Sets the component manager
44 62 */
45 63 public function setComponentManager(OntoWiki_Component_Manager $componentManager)
@@ -131,7 +149,7 @@ public function isDispatchable(Zend_Controller_Request_Abstract $request)
131 149 */
132 150 require_once 'Erfurt/Event.php';
133 151 $event = new Erfurt_Event('onIsDispatchable');
134   - $event->uri = OntoWiki_Application::getInstance()->config->urlBase . ltrim($request->getPathInfo(), '/');
  152 + $event->uri = $this->urlBase . ltrim($request->getPathInfo(), '/');
135 153 $event->request = $request;
136 154
137 155 // We need to make sure that registered plugins return a boolean value!
4 application/classes/OntoWiki/Message.php
@@ -88,12 +88,10 @@ public function __construct($text, $type = self::INFO, $options = array())
88 88 $this->_type = $type;
89 89 $this->_text = $text;
90 90
91   - require_once 'OntoWiki/Application.php';
92   - $this->_translate = OntoWiki_Application::getInstance()->translate;
  91 + $this->_translate = OntoWiki::getInstance()->translate;
93 92
94 93 // init view
95 94 if (null === $this->_view) {
96   - require_once 'Zend/Controller/Action/HelperBroker.php';
97 95 $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
98 96 if (null === $viewRenderer->view) {
99 97 $viewRenderer->initView();
12 application/classes/OntoWiki/Model.php
@@ -10,17 +10,6 @@
10 10 * @version $Id: Model.php 4095 2009-08-19 23:00:19Z christian.wuerker $
11 11 */
12 12
13   -/**
14   - * Required Zend classes
15   - */
16   -require_once 'Erfurt/Event/Dispatcher.php';
17   -
18   -/**
19   - * Required OntoWiki API classes
20   - */
21   -require_once 'OntoWiki/Application.php';
22   -require_once 'OntoWiki/Utils.php';
23   -
24 13 /**
25 14 * OntoWiki model base class.
26 15 *
@@ -101,7 +90,6 @@ public function __construct(Erfurt_Store $store, $graph)
101 90 $this->_graph = $graph->getModelIri();
102 91 $this->_model = $graph;
103 92
104   - require_once 'OntoWiki/Model/TitleHelper.php';
105 93 $this->_titleHelper = new OntoWiki_Model_TitleHelper($this->_model);
106 94
107 95 // $this->_titleProperties = array_flip($this->_config->properties->title->toArray());
14 application/classes/OntoWiki/Model/Hierarchy.php
@@ -10,17 +10,6 @@
10 10 * @version $Id: Hierarchy.php 4095 2009-08-19 23:00:19Z christian.wuerker $
11 11 */
12 12
13   -/**
14   - * Required Erfurt classes
15   - */
16   -require_once 'Erfurt/Sparql/SimpleQuery.php';
17   -
18   -/**
19   - * Required OntoWiki API classes
20   - */
21   -require_once 'OntoWiki/Model.php';
22   -require_once 'OntoWiki/Utils.php';
23   -
24 13 /**
25 14 * OntoWiki resource hierarchy model class.
26 15 *
@@ -128,7 +117,6 @@ public function getHierarchy()
128 117 if (!$this->_hierarchyResults) {
129 118 $query = $this->_buildQuery();
130 119
131   - require_once 'OntoWiki/Url.php';
132 120 $this->_url = new OntoWiki_Url(array('route' => 'instances'), array('r'));
133 121
134 122 if ($result = $this->_model->sparqlQuery($query)) {
@@ -179,7 +167,7 @@ protected function _getEntry($resultUri, $hasChildren = false)
179 167
180 168 $entry = array(
181 169 'uri' => $resultUri,
182   - 'url' => (string) $this->_url,
  170 + 'url' => (string)$this->_url,
183 171 'classes' => trim($classes),
184 172 'title' => $this->_titleHelper->getTitle($resultUri, $this->_config->languages->locale),
185 173 'children' => array(),
71 application/classes/OntoWiki/Model/Instances.php
@@ -10,10 +10,6 @@
10 10 * @version $Id: Instances.php 4309 2009-10-14 15:36:22Z sebastian.dietzold $
11 11 */
12 12
13   -require_once 'OntoWiki/Model.php';
14   -require_once 'OntoWiki/Url.php';
15   -require_once 'OntoWiki/Utils.php';
16   -
17 13 /**
18 14 * OntoWiki resource list model class.
19 15 *
@@ -99,8 +95,6 @@ public function __construct(Erfurt_Store $store, $graph, $options = array())
99 95 {
100 96 parent::__construct($store, $graph);
101 97
102   - require_once 'OntoWiki/Application.php';
103   -
104 98 $type = isset($options['type']) ? $options['type'] : OntoWiki_Application::getInstance()->selectedClass;
105 99 $withChilds = isset($options['withChilds']) ? $options['withChilds'] : true;
106 100 $member_predicate = isset($options['memberPredicate']) ? $options['memberPredicate'] : EF_RDF_TYPE;
@@ -110,7 +104,6 @@ public function __construct(Erfurt_Store $store, $graph, $options = array())
110 104 $shownInverseProperties = isset($options['shownInverseProperties']) ? $options['shownInverseProperties'] : array();
111 105 $sessionfilter = isset($options['filter']) ? $options['filter'] : array();
112 106
113   - require_once 'Erfurt/Sparql/Query2.php';
114 107 $this->_resourceQuery = new Erfurt_Sparql_Query2();
115 108
116 109 if(is_string($member_predicate))
@@ -368,8 +361,7 @@ public function getValues()
368 361 $this->getResults();
369 362
370 363 $result = $this->_results['bindings'];
371   - //echo 'results:<pre>'; print_r($result); echo '</pre>';
372   - require_once 'OntoWiki/Model/TitleHelper.php';
  364 +
373 365 $titleHelper = new OntoWiki_Model_TitleHelper($this->_model);
374 366
375 367 foreach ($result as $row) {
@@ -413,7 +405,6 @@ public function getValues()
413 405
414 406
415 407 // set up event
416   - require_once 'Erfurt/Event.php';
417 408 $event = new Erfurt_Event('onDisplayObjectPropertyValue');
418 409
419 410 //find uri
@@ -436,7 +427,6 @@ public function getValues()
436 427 $object = $data['value'];
437 428
438 429 // set up event
439   - require_once 'Erfurt/Event.php';
440 430 $event = new Erfurt_Event('onDisplayLiteralPropertyValue');
441 431 $event->property = $propertyUri;
442 432 $event->value = $object;
@@ -565,38 +555,37 @@ public function getSubjects($property, $distinct = true){
565 555
566 556 protected function convertProperties($properties)
567 557 {
568   - require_once 'OntoWiki/Model/TitleHelper.php';
569   - $titleHelper = new OntoWiki_Model_TitleHelper($this->_model);
570   -
571   - $uris = array();
572   - foreach($properties as $property){
573   - $uris[] = $property['uri'];
  558 + $titleHelper = new OntoWiki_Model_TitleHelper($this->_model);
  559 +
  560 + $uris = array();
  561 + foreach($properties as $property){
  562 + $uris[] = $property['uri'];
  563 + }
  564 +
  565 + $titleHelper->addResources($uris);
  566 +
  567 + $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
  568 +
  569 + $propertyResults = array();
  570 + $i = 0;
  571 + foreach ($properties as $property) {
  572 + if(in_array($property['uri'], $this->_ignoredShownProperties)){
  573 + continue;
574 574 }
575   -
576   - $titleHelper->addResources($uris);
577   -
578   - $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
579   -
580   - $propertyResults = array();
581   - $i = 0;
582   - foreach ($properties as $property) {
583   - if(in_array($property['uri'], $this->_ignoredShownProperties)){
584   - continue;
585   - }
586 575
587   - // set URL
588   - $url->setParam('r', $property['uri'], true);
589   -
590   - $property['url'] = (string) $url;
591   -
592   - $property['curi'] = OntoWiki_Utils::contractNamespace($property['uri']);
593   -
594   - $property['title'] = $titleHelper->getTitle($property['uri'], $this->_lang);
595   -
596   - $propertyResults[] = $property;
597   - }
598   -
599   - return $propertyResults;
  576 + // set URL
  577 + $url->setParam('r', $property['uri'], true);
  578 +
  579 + $property['url'] = (string) $url;
  580 +
  581 + $property['curi'] = OntoWiki_Utils::contractNamespace($property['uri']);
  582 +
  583 + $property['title'] = $titleHelper->getTitle($property['uri'], $this->_lang);
  584 +
  585 + $propertyResults[] = $property;
  586 + }
  587 +
  588 + return $propertyResults;
600 589 }
601 590
602 591 /**
13 application/classes/OntoWiki/Model/Resource.php
@@ -10,8 +10,6 @@
10 10 * @version $Id: Resource.php 4311 2009-10-14 17:14:10Z jonas.brekle@gmail.com $
11 11 */
12 12
13   -require_once 'OntoWiki/Model.php';
14   -
15 13 /**
16 14 * OntoWiki resource model class.
17 15 *
@@ -63,7 +61,6 @@ public function __construct(Erfurt_Store $store, $graph, $uri, $options = array(
63 61 parent::__construct($store, $graph);
64 62 $this->_uri = (string)$uri;
65 63
66   - require_once 'OntoWiki/Model/TitleHelper.php';
67 64 $this->_titleHelper = new OntoWiki_Model_TitleHelper($this->_model);
68 65 }
69 66
@@ -81,7 +78,6 @@ public function getPredicates()
81 78 $results = $this->getQueryResults();
82 79
83 80 // url object to build URLs
84   - require_once 'OntoWiki/Url.php';
85 81 $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
86 82
87 83 foreach ($results as $graph => $resultsForGraph) {
@@ -101,8 +97,7 @@ public function getPredicates()
101 97 $predicateTitle = $this->_titleHelper->getTitle($predicateUri, $this->_lang);
102 98 // url
103 99 $url->setParam('r', $predicateUri, true);
104   -
105   - require_once 'OntoWiki/Utils.php';
  100 +
106 101 $this->_predicateResults[$graph][$predicateUri] = array(
107 102 'uri' => $predicateUri,
108 103 'curi' => OntoWiki_Utils::compactUri($predicateUri),
@@ -166,7 +161,6 @@ public function getValues()
166 161 $this->getPredicates();
167 162
168 163 // URL object to build URLs
169   - require_once 'OntoWiki/Url.php';
170 164 $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
171 165
172 166 // keep track of URI objects already used
@@ -222,7 +216,6 @@ public function getValues()
222 216 * Event payload: value, property, title and link
223 217 */
224 218 // set up event
225   - require_once 'Erfurt/Event.php';
226 219 $event = new Erfurt_Event('onDisplayObjectPropertyValue');
227 220 $event->value = $row['object']['value'];
228 221 $event->property = $predicateUri;
@@ -242,7 +235,6 @@ public function getValues()
242 235 break;
243 236
244 237 case 'typed-literal':
245   - require_once 'OntoWiki/Utils.php';
246 238 $value['datatype'] = OntoWiki_Utils::compactUri($row['object']['datatype']);
247 239 /* fallthrough */
248 240
@@ -255,7 +247,6 @@ public function getValues()
255 247 * property is returned. Plugins can attach to this trigger in order to modify
256 248 * the value that gets displayed.
257 249 */
258   - require_once 'Erfurt/Event.php';
259 250 $event = new Erfurt_Event('onDisplayLiteralPropertyValue');
260 251 $event->value = $row['object']['value'];
261 252 $event->property = $predicateUri;
@@ -283,7 +274,6 @@ public function getValues()
283 274 $this->_predicateResults[$graph][$predicateUri]['has_more'] = true;
284 275
285 276 if (!isset($this->_predicateResults[$graph][$predicateUri]['has_more_link'])) {
286   - require_once 'OntoWiki/Url.php';
287 277 $hasMoreUrl = new OntoWiki_Url(array('controller' => 'model', 'action' => 'query'));
288 278 $query = <<<EOT
289 279 SELECT ?value
@@ -311,7 +301,6 @@ public function getValues()
311 301 */
312 302 private function _buildQueries()
313 303 {
314   - require_once "Erfurt/Sparql/Query2.php";
315 304 $query = new Erfurt_Sparql_Query2();
316 305
317 306 $uri = new Erfurt_Sparql_Query2_IriRef($this->_uri);
9 application/classes/OntoWiki/Model/TitleHelper.php
@@ -122,10 +122,8 @@ public function __construct(Erfurt_Rdf_Model $model = null)
122 122 $this->_model = $model;
123 123 }
124 124
125   - require_once 'Erfurt/App.php';
126 125 $this->_store = Erfurt_App::getInstance()->getStore();
127 126
128   - require_once 'OntoWiki/Application.php';
129 127 $config = OntoWiki_Application::getInstance()->config;
130 128
131 129 // naming properties for resources
@@ -254,7 +252,6 @@ public function getResources()
254 252 public function getResourceQuery()
255 253 {
256 254 if (null === $this->_resourceQuery) {
257   - require_once 'Erfurt/Sparql/SimpleQuery.php';
258 255 $this->_resourceQuery = new Erfurt_Sparql_SimpleQuery();
259 256 $this->_resourceQuery->setProloguePart('SELECT DISTINCT ?' . self::RESOURCE_VARIABLE)
260 257 ->setWherePart('WHERE {?' . self::RESOURCE_VARIABLE . ' ' . $this->_resourcePattern . '}')
@@ -325,7 +322,6 @@ public function getTitle($resourceUri, $language = null)
325 322
326 323 // still not found?
327 324 if (null === $title) {
328   - require_once 'OntoWiki/Utils.php';
329 325 $title = OntoWiki_Utils::contractNamespace($resourceUri);
330 326 }
331 327
@@ -355,7 +351,6 @@ public function getTitleQueryResult()
355 351 }
356 352
357 353 if (defined('_OWDEBUG')) {
358   - require_once 'OntoWiki/Application.php';
359 354 $logger = OntoWiki_Application::getInstance()->logger;
360 355 $logger->info('TitleHelper: ' . $numQueries . ' queries with ' . count($this->_resources) . ' resources.');
361 356 }
@@ -372,9 +367,7 @@ public function getTitleQueryResult()
372 367 * @return Erfurt_Sparql_SimpleQuery
373 368 */
374 369 public function getTitleQueries($numQueries)
375   - {
376   - require_once 'Erfurt/Sparql/SimpleQuery.php';
377   -
  370 + {
378 371 $currentQuery = null;
379 372 $queries = array();
380 373 $select = 'SELECT DISTINCT ?'
3  application/classes/OntoWiki/Module/Manager.php
@@ -65,8 +65,9 @@ class OntoWiki_Module_Manager
65 65 */
66 66 public function __construct($modulePath)
67 67 {
68   - $this->_modulePath = (string) $modulePath;
  68 + $this->_modulePath = (string)$modulePath;
69 69 $this->_moduleRegistry = OntoWiki_Module_Registry::getInstance();
  70 + $this->_moduleRegistry->setModuleDir($modulePath);
70 71
71 72 // scan for modules