/** Handle some event * * Call this function to make TSunic do some job. This method will search * for the requested module and function and run it providing the given * parameters * * @param string $event * If running internally, enter the event here * @param array|string $parameters * Parameters for event function (internal-run only!) * * @return bool|mix */ public function run($event = NULL, $parameters = NULL) { $this->internal_run = false; // is internal run? if (!empty($event)) { // internal $this->internal_run = true; // get parameter-string $parameter_string = ''; if (!($parameters === false)) { // put values in array if (!is_array($parameters)) { $parameters = array($parameters); } // create parameter-string for function foreach ($parameters as $index => $value) { // use nowdoc to define string (TRICKY!) $parameters[$index] = '<<<\'EOD\'' . chr(10) . $value . chr(10) . 'EOD' . chr(10); } $parameter_string = implode(',', $parameters); } } else { // external // delete old activated templates $this->Tmpl->clearActivatedTemplates(); // redirect, if back-link if ($this->isIndex() and isset($_GET['back'])) { $this->redirect('this'); } // get event $event = $this->Input->get('event'); if (empty($event)) { if ($this->isAjax()) { return false; } $this->redirect('default'); exit; } } $this->Log->log(6, "Run: {$event}"); // get path and file-object $path = '#runtime#functions/' . $event . '.func.php'; $File = $this->get('$$$File', array($path)); // does file exists? if (!$File->isFile()) { // function doesn't exist if ($this->internal_run or $this->isAjax()) { return false; } // page not found! $this->Log->alert('error', '{CLASS__TSUNIC__PAGE_NOT_FOUND}'); $this->redirect('back'); } // include function $File->includeFile(); // run function if (!$this->internal_run or empty($parameter_string)) { $return = $event(); } else { $to_eval = '$return = ' . $event . '(' . $parameter_string . ');'; try { @eval($to_eval); } catch (Exception $e) { // invalid function $this->throwError('Fatale error: Requested function is invalid! (' . $this->Input->get('event') . ')'); } } if (!$this->internal_run or $return === NULL) { return true; } return $return; }