/**
  * Gibt den Text mit den ersetzten Links zurück
  * @return string
  */
 public function getText()
 {
     $this->text = html_entity_decode($this->text);
     $matches = [];
     // Suchen nach allem, dass in [[ ]] eingeschlossen ist
     preg_match_all('/\\[\\[([\\w\\.\\säöüÄÖÜß]+)\\]\\]/', $this->text, $matches);
     Logging::debug(print_r($matches, true));
     foreach ($matches[1] as $match) {
         $artikel = CmsArtikel::loadByBezeichnung($match, $this->kategorieId);
         if ($artikel == null) {
             Logging::info('Lege Artikel neu an: ' . $match);
             $artikel = new CmsArtikel();
             $artikel->ca_kategorie = $this->kategorieId;
             $artikel->ca_bezeichnung = $match;
             $artikel->ca_aktiv = 1;
             $artikel->ca_autor = Security::getUserId();
             $artikel->save();
             $titel = Text::get($artikel->getElementId() . '.titel');
             $titel->te_text = $match;
             $titel->save();
         }
         $link = EntityLinks::show($artikel);
         $tag = "<a href=\"{$link}\">{$match}</a>";
         $this->text = str_replace('[[' . $match . ']]', $tag, $this->text);
     }
     return $this->text;
 }
 public function get($key, $default = '')
 {
     if (!isset($this->cache[$key])) {
         Logging::debug("{$key} nicht gefunden");
         Logging::info(print_r(array_keys($this->cache), true));
         return $default;
     } else {
         return $this->cache[$key];
     }
 }
 public function get($key, $default = '')
 {
     if (!$this->enabled) {
         return $default;
     }
     if (!isset($_SESSION['cache'][$key])) {
         Logging::debug('Cache-Miss für ' . $key);
         return $default;
     } else {
         Logging::debug('Cache-Hit für ' . $key);
         return $this->decode($_SESSION['cache'][$key]);
     }
 }
 public function getConnection($host, $database, $user, $password)
 {
     $connString = static::getConnectionString($host, $database);
     Logging::debug("Datenbankverbindung aufbauen {$connString}");
     // Persistente Verbindung erzeugen
     try {
         $result = new PDO($connString, $user, $password);
         $result->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (Exception $e) {
         throw new \RuntimeException("Fehler beim Verbinden mit der Datenbank " . $e->getMessage());
     }
     return $result;
 }
 public function getConnection($host, $database, $user, $password)
 {
     $connString = $this->getConnectionString($host, $database);
     Logging::debug("Datenbankverbindung aufbauen {$connString}");
     // Persistente Verbindung erzeugen
     try {
         $result = new PDO($connString, $user, $password, [PDO::ATTR_PERSISTENT => true]);
         $statement = $result->prepare('set names utf8;');
         $statement->execute();
         $statement->closeCursor();
     } catch (Exception $e) {
         throw new Exception("Fehler beim Verbinden mit der Datenbank " . $e->getMessage());
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * Erzeugt die <link> Tags für die benötigten CSS Bibliotheken
  *
  * @return string
  */
 public static function getLinkTags()
 {
     Logging::debug('Binde CSS-Bibliotheken ein: ' . count(static::$requiredLibraries) . ' / ' . count(static::$registeredLibraries));
     $result = '';
     foreach (static::$requiredLibraries as $lib) {
         if (array_key_exists($lib, static::$registeredLibraries)) {
             $filesToInclude = static::$registeredLibraries[$lib];
             foreach ($filesToInclude as $file) {
                 $result .= "\n<link href=\"{$file}\" rel=\"stylesheet\" type=\"text/css\" />";
             }
         } else {
             Logging::error('CSS-Bibliothek nicht gefunden: ' . $lib);
         }
     }
     return $result;
 }
 public function getConnection($host, $database, $user, $password)
 {
     if (FirebirdDatabaseProvider::$instance === null) {
         FirebirdDatabaseProvider::$instance = new FirebirdDatabaseProvider();
     }
     $connString = FirebirdDatabaseProvider::getConnectionString($host, $database);
     Logging::debug("Datenbankverbindung aufbauen {$connString}");
     // Persistente Verbindung erzeugen
     try {
         $result = new PDO($connString, $user, $password, array());
         $result->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         // Set Names um den CharacterSet zu setzen..
     } catch (Exception $e) {
         throw new \RuntimeException("Fehler beim Verbinden mit der Datenbank {$connString} " . $e->getMessage());
     }
     return $result;
 }
 /**
  * Sendet eine Mail über den in der Konfiguration hinterlegten SMTP Account.
  * @param string $empfaenger Empfängeradresse / Wird automatisch von UTF-8 nach ANSI gewandelt
  * @param string $betreff Empfängeradresse / Wird automatisch von UTF-8 nach ANSI gewandelt
  * @param string $nachricht Nachricht als Plaintext
  * @param string $html Nachricht als HTML
  * @param string $attachment Pfad und Dateiname eines Anhangs
  * @return boolean
  */
 public function sendMail($empfaenger, $betreff, $nachricht, $html = null, $attachment = null)
 {
     if (Configuration::get('mail.from') === '') {
         Logging::warning('Kein Absender in der Konfiguration eingetragen. E-Mail wird nicht versendet');
         return false;
     }
     if ($empfaenger === '') {
         Logging::warning('Keine E-Mail Adresse übergeben');
         return false;
     }
     $empfaenger = trim($empfaenger);
     Profiler::startSection('Mailer::sendMail');
     try {
         $message = Swift_Message::newInstance();
         $message->setSubject($betreff);
         $message->setFrom(array(Configuration::get('mail.from')));
         $message->setTo(array(utf8_decode($empfaenger)));
         $message->setBody(strip_tags($nachricht));
         if ($html !== null) {
             $templatePath = Environment::get()->srcDir . '/site/mails/template.html';
             if (file_exists($templatePath)) {
                 $html = str_replace('{mail}', $html, file_get_contents($templatePath));
             }
             $message->addPart($html, 'text/html');
         }
         if ($attachment !== null) {
             $message->attach(Swift_Attachment::fromPath($attachment));
         }
         if ($this->transport === null) {
             $this->transport = Swift_SmtpTransport::newInstance(Configuration::get('mail.smtp_host'), Configuration::get('mail.smtp_port'))->setUsername(Configuration::get('mail.smtp_user'))->setPassword(Configuration::get('mail.smtp_pass'));
             $this->mailer = Swift_Mailer::newInstance($this->transport);
         }
         Logging::debug('Versende Mail per SMTP an ' . $empfaenger . ' über ' . Configuration::get('mail.smtp_host') . ':' . Configuration::get('mail.smtp_port') . ' / ' . Configuration::get('mail.smtp_user') . ' / ' . Configuration::get('mail.smtp_pass'));
         $result = $this->mailer->send($message);
         Logging::debug('Result des Mails ' . print_r($result, true));
         Profiler::endSection('Mailer::sendMail');
         return $result;
     } catch (Exception $ex) {
         Logging::error('Exception beim Senden einer Mail ' . $ex->getMessage());
         Profiler::endSection('Mailer::sendMail');
         return false;
     }
 }
 /**
  * Lädt das Modul mit dem übergebenen Namen
  * @param $name
  * @return Module|null
  */
 public function getModule($name)
 {
     if ($name === '') {
         Logging::warning('Leeres Modul sollte geladen werden.');
         return null;
     }
     $name = ucfirst($name);
     // Aus dem Cache holen
     $cacheId = 'module.' . $name;
     if (array_key_exists($cacheId, $this->internalCache)) {
         return $this->internalCache[$cacheId];
     }
     $result = Cache::get($cacheId, null);
     if ($result !== null) {
         $this->internalCache[$cacheId] = $result;
         return $result;
     }
     Profiler::startSection('module.load', $name);
     Logging::debug("Modul '{$name}' wird geladen");
     // Generieren der Klassendefinition für den Controller um dann via
     // Reflection die Datei und damit das Verzeichnis herauszubekommen.
     $naming = new ModuleNaming();
     $classOfController = $naming->getControllerClassFromCamelCase($name);
     if (class_exists($classOfController)) {
         $reflector = new ReflectionClass($classOfController);
         $directory = dirname($reflector->getFileName());
         $filename = $directory . '/Module.xml';
         if (file_exists($filename)) {
             $file = simplexml_load_file($filename);
             $result = $this->createByXml($file, $directory);
             unset($file);
         } else {
             Logging::error("Modul [{$name}] konnte in Pfad {$directory} nicht gefunden werden");
         }
     } else {
         Logging::warning("Controller für Modul [{$name}] konnte nicht gefunden werden [{$classOfController}]");
     }
     Cache::set($cacheId, $result);
     $this->internalCache[$cacheId] = $result;
     Profiler::endSection('module.load');
     return $result;
 }
 /**
  * Führt einen Request per Reflection auf dem Controller aus
  *
  * @param ReflectionMethod $method
  * @return mixed
  */
 private function executeViaReflection(ReflectionMethod $method)
 {
     Logging::debug('Ausführen via Reflection ' . (string) $method);
     $parameters = $method->getParameters();
     if (count($parameters) === 0) {
         $result = $method->invoke($this);
     } elseif (count($parameters) === 1) {
         $resource = $parameters[0]->getClass()->newInstance($this->request->id);
         $result = $method->invoke($this, $resource);
     } else {
         throw new \RuntimeException('Mehr als ein Argument wird aktuell nicht unterstützt');
     }
     return $result;
 }
 /**
  * Die Init-Funktion wird aufgerufen, wenn der Benutzer zum ersten Mal
  * die Seite betritt und die Session daher noch leer ist. Setzen der
  * benötigten Ifnormationen in der Session
  */
 private function init()
 {
     Logging::debug('Session wird initialisiert');
     Events::dispatch(FrameworkEvents::SESSION_INIT, new FrameworkEvent());
     Security::initApplication();
     $_SESSION['initialized'] = true;
 }
 /**
  * Bearbeitet einen Request. Ist diese Instanz zuständig, so wir der Request
  * ausgeführt. Wenn nicht, dann wird false zuurückgegen.
  *
  * @param Request $request
  * @param Response $response
  * @return bool
  */
 public function handleResourceRequest(Request $request, Response $response)
 {
     if ($this->isResourceRequest($request->action)) {
         // TODO: Für die Berechtigungsprüfung braucht man die Action noch.
         // TODO: Ggf. als Resource erfassen um das loszuwerden?
         Logging::debug('Handling Request via ' . (string) $this);
         if ($request->present('id')) {
             $this->resource = $this->loadOrCreateResource($request->id);
         } else {
             $this->resource = $this->loadOrCreateResource();
         }
         $callable = $this->possibleActions[$request->action];
         $callable($request, $response);
         if ($response->getContent() instanceof View) {
             $response->getContent()->setResource($this->resource);
         }
         return true;
     }
     return false;
 }
 /**
  * Daten anzeigen
  * @return string HTML-String der Datenzeilen
  */
 private function getDaten()
 {
     $tbody = Html::create('tbody');
     $i = 0;
     $groupValue = null;
     $addedRow = false;
     $summe = 0;
     Logging::debug('Verwende DB-Service: ' . $this->entity->getDatabaseServiceName());
     $db = Application::resolve($this->entity->getDatabaseServiceName());
     while ($row = $db->fetch()) {
         $addedRow = true;
         // Daten in Entität laden, damit die formatierten Feldwerte zur Verfügung stehen
         $this->entity->loadFromRow($row);
         // Gruppieren
         if ($this->groupColumn > -1 && $groupValue != $this->columns[$this->groupColumn]->getData($row)) {
             $colcount = count($this->columns);
             if (!$this->renderGrouped) {
                 $colcount--;
             }
             $i = 0;
             $groupValue = $this->columns[$this->groupColumn]->getData($row);
             $th = Html::create('th')->addAttribute('colspan', $colcount)->text($groupValue);
             $tr = Html::create('tr')->css('groupHeader')->text($th);
             $tbody->text($tr);
         }
         if ($this->sum > -1) {
             $summe += $this->columns[$this->sum]->getRawData($row);
         }
         $tr = Html::create('tr')->addAttribute('data-id', $this->entity->id);
         // Callable aufrufen um Klasse der Zeile zu ermitteln
         if (isset($this->rowClassCallable)) {
             $callable = $this->rowClassCallable;
             $tr->css($callable($this->entity));
         }
         $j = 0;
         foreach ($this->columns as $column) {
             if ($this->renderGrouped || $j != $this->groupColumn) {
                 $td = Html::create('td')->css($column->getCssClass())->text($column->getData($row));
                 if ($column->getNoWrap()) {
                     $td->css('nowrap');
                 }
                 $tr->text($td);
             }
             $j++;
         }
         // spalten
         $tbody->text($tr);
         $i++;
     }
     // zeilen
     // Summe rendern
     if ($this->sum > -1) {
         $tr = Html::create('tr');
         $j = 0;
         foreach ($this->columns as $column) {
             if ($this->renderGrouped || $j != $this->groupColumn) {
                 if ($j == $this->sum) {
                     $td = Html::create('td')->css($column->getCssClass())->text('<strong>' . number_format($summe, 2, ',', '.') . '</strong>');
                 } else {
                     $td = Html::create('td')->css($column->getCssClass())->text('&nbsp;');
                 }
                 if ($column->getNoWrap()) {
                     $td->css('nowrap');
                 }
                 $tr->create($td);
             }
             $j++;
         }
         // spalten
         $tbody->text($tr);
     }
     if ($addedRow) {
         return $tbody;
     } else {
         return null;
     }
 }
 /**
  * Erzeugt das Markup für ein horizontales Bootstrap Form
  * @return string
  */
 public function toHorizontalBootstrapHtml()
 {
     $div = Html::create('div')->css('editControl')->css('form-horizontal');
     $i = 0;
     $colwidth = 1;
     $labelwidth = $this->labelWidth;
     $controlwidth = $this->controlWidth;
     if ($this->columns > 1) {
         $div->css('row');
         $colwidth = round(12 / $this->columns);
         Logging::debug('Zeige ' . $this->columns . ' Spalten mit Breite ' . $colwidth);
         $labelwidth = 3;
         $controlwidth = 9;
     }
     foreach ($this->rows as $row) {
         $container = $div;
         if ($this->columns > 1 && $i % $this->columns == 0) {
             $container = Html::create('div')->css('col-sm-' . $colwidth);
             $container->addTo($div);
         }
         $firstChar = substr($row['field'], 0, 1);
         switch ($firstChar) {
             case "-":
                 Html::create('p')->addInnerHtml('&nbsp;')->css('form-empty')->addTo($container);
                 break;
             case "*":
                 Html::create('h4')->addInnerHtml(substr($row['field'], 1))->addTo($container);
                 break;
             default:
                 $formGroup = Html::create('div')->css('form-group')->addTo($container);
                 if (!$row['control'] instanceof Control) {
                     continue;
                 }
                 Html::create('label')->addTo($formGroup)->css('control-label')->css('col-sm-' . $labelwidth)->attr('for', $row['control']->getId())->text($row['header']);
                 $inner = Html::create('div')->css('col-sm-' . $controlwidth)->addTo($formGroup);
                 $control = $row['control'];
                 $inner->addInnerHtml($control);
                 break;
         }
     }
     return $div->render();
 }
Esempio n. 15
0
 /**
  * Prüft, ob der aktuell angemeldete Benutzer berechtigt für diese Aktion ist
  * @return bool
  */
 public function isBerechtigt()
 {
     Logging::debug("Prüfe Berechtigung für {$this->name} : {$this->securityLevel}");
     if ($this->securityLevel === Action::LEVEL_ALL) {
         return true;
     } elseif ($this->securityLevel === Action::LEVEL_LOGGEDIN) {
         return Security::isAuthenticated();
     } elseif ($this->securityLevel === Action::LEVEL_CONFIG) {
         return Security::hatBerechtigung($this->getSecurityToken());
     } else {
         // TODO: Hier könnte man jetzt auch den Rückgriff auf
         // andere Module einbauen. Wäre kein Problem
         $module = $this->module;
         $action = $module->getAction($this->securityLevel);
         if ($action !== null) {
             return $action->isBerechtigt();
         }
     }
     return false;
 }