public function executeJson(AgaviRequestDataHolder $rd) { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); $file = null; foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { $file = AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } if ($file === null) { $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), $rd->getParameter('template'), '.xml'); } $template = new CronkGridTemplateXmlParser($file->getRealPath()); $template->parseTemplate(); $user = $this->getContext()->getUser()->getNsmUser(); $data = $template->getTemplateData(); if ($user->hasTarget('IcingaCommandRestrictions')) { $template->removeRestrictedCommands(); } return json_encode(array('template' => $template->getTemplateData(), 'fields' => $template->getFields(), 'keys' => $template->getFieldKeys(), 'params' => $rd->getParameters(), 'connections' => IcingaDoctrineDatabase::$icingaConnections)); } catch (AppKitFileUtilException $e) { $msg = 'Could not find template for ' . $rd->getParameter('template'); AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); return $msg; } }
/** * retrieves content via model and returns it * @param AgaviRequestDataHolder $rd required by Agavi but not used here * @return string $content generated content * @author Christian Doebler <*****@*****.**> */ public function executeSimple(AgaviRequestDataHolder $rd) { if ($rd->getParameter('interface', false) == true) { return $this->executeHtml($rd); } try { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); $file = null; foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { $file = AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } if ($file === null) { $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.to'), $fileName, '.xml'); } $model = $this->getContext()->getModel('System.StaticContent', 'Cronks', array('rparam' => $rd->getParameter('p', array()))); $model->setTemplateFile($file->getRealPath()); $content = $model->renderTemplate($rd->getParameter('render', 'MAIN'), $rd->getParameters()); return sprintf('<div class="%s">%s</div>', 'static-content-container', $content); } catch (AppKitFileUtilException $e) { $msg = 'Could not find template for ' . $rd->getParameter('template'); AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); return $msg; } } catch (Exception $e) { return $e->getMessage(); } }
/** * Logs exceptions to the icinga-web logs. */ public static function logException(Exception $e) { AppKitAgaviUtil::log('Uncaught %s: %s (%s:%d)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), self::LOG_LEVEL); // Rethrow exception, so Agavi can handle and render it. // See AgaviController#dispatch(). throw $e; }
private function getTemplateFile(AgaviRequestDataHolder $rd) { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { return AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } return AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), $fileName, '.xml'); } catch (AppKitFileUtilException $e) { AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); throw $e; } }
/** * Shortcut method to log messages easier from action * @param mixed $arg1 * @see app/modules/AppKit/lib/AppKitAgaviUtil#log() */ protected function log($arg1) { $args = func_get_args(); return AppKitAgaviUtil::log($args); }
/** * Dump files minifying content on request * @return this * * @author Eric Lippmann <*****@*****.**> * @since 1.5.0 */ protected function readFiles() { $content = null; foreach ($this->getParameter('files') as $file) { if (false !== ($fcontent = @file_get_contents($file))) { if (!$this->getParameter('comments', true)) { $fcontent = preg_replace("!^\\s*//.*\$!m", "\n", $fcontent); $fcontent = preg_replace("!^\\s*/\\*.*?\\*/!s", "", $fcontent); } if (!$this->getParameter('indent', true)) { $fcontent = implode("\n", array_map('trim', explode("\n", $fcontent))); } if (!$this->getParameter('newlines', true)) { $fcontent = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", $fcontent); } $content .= $fcontent . "\n"; } else { AppKitAgaviUtil::log(sprintf('%s: Could not get contents of file %s.', get_class($this), $file), AgaviLogger::ERROR); } } $this->setParameter('content', $content); return $this; }