public function get($msg = null) { $data = []; if (!is_null($msg)) { $data['message'] = $msg; } $this->slim->render('login.twig', $data); }
protected function render($template, $data = array(), $status = null) { try { $this->application->render($template, $data, $status); } catch (Twig_Error_Runtime $e) { $this->application->render('Error/app_load_error.html.twig', array('message' => sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e)); } }
public static function registrationRoute(\Slim\Slim $app) { $app->get('/', function () use($app) { $app->render('index.php'); }); $app->post('/form/', function () use($app) { $app->render('index.php', ['nickname' => $_POST['nickname']]); }); }
public function delete($key) { $config = new Config(); if ($config->readKey($key)) { $id = $config->id; $this->app->render($config->delete() ? 200 : 500, ['response' => $id]); } else { $this->app->render(404); } }
/** * GET /export/feed/:id/atom * * @param int $id */ public function getFeedItemsAtom($id) { $feed = new Feed(); if (!$feed->read($id)) { $this->app->render(404); return; } $items = (new Item())->readList('id_feed = ?', [$feed->id]); $this->xmlOutput(new Atom($feed, $items)); }
protected function render($template, $data = array(), $status = array()) { try { $this->app->render($template, $data, $status); } catch (Twig_Error_Runtime $twigException) { $errorData = array(); $errorData['errorMessage'] = sprintf("An error was thrown while rendering view template from class %s. (%s)", get_class($this), $twigException->getMessage()); if ($this->app->getMode() == self::DEV_MODE) { $errorData['stackTrace'] = $twigException->getTraceAsString(); } $this->app->render(self::ERROR_TEMPLATE, $errorData, self::ERROR_CODE); } }
public function cleanupOldFiles() { $_SESSION['DB_DONE'] = true; $cleanupList = array_merge($this->pluginFinder->getDummyPlugins(), $this->filesFinder->getCleanupFiles()); $this->cleanupMedia(); if (count($cleanupList) == 0) { $_SESSION['CLEANUP_DONE'] = true; $this->response->redirect($this->app->urlFor('done')); } if ($this->request->isPost()) { $result = []; foreach ($cleanupList as $path) { $result = array_merge($result, Utils::cleanPath($path)); } if (count($result) == 0) { $_SESSION['CLEANUP_DONE'] = true; $this->response->redirect($this->app->urlFor('done')); } else { $result = array_map(function ($path) { return substr($path, strlen(SW_PATH) + 1); }, $result); $this->app->render('cleanup.php', ['cleanupList' => $result, 'error' => true]); } } else { $cleanupList = array_map(function ($path) { return substr($path, strlen(SW_PATH) + 1); }, $cleanupList); $this->app->render('cleanup.php', ['cleanupList' => $cleanupList, 'error' => false]); } }
/** * Override \Slim\Slim::render method on controller * * @param string $tpl * @param array $data [] * @param string $suffix * @return void */ protected function render($tpl, array $data = []) { $suffix = $this->app->config('template.suffix'); $suffix = empty($suffix) ? $this->viewSuffix : $suffix; $tpl .= $suffix; $this->app->render($tpl, $data); }
public function render($name, $data = array(), $status = null) { if (strpos($name, ".php") === false) { $name = $name . ".php"; } parent::render($name, $data, $status); }
/** * */ public function printMenu() { $result = []; $complete = true; $entries = $this->entries; foreach ($entries as $entry) { $active = $entry == current($this->entries); if ($active) { $complete = false; } $key = 'menuitem_' . $entry; $label = $this->translations->translate($key); $result[] = ['label' => $label, 'complete' => $complete, 'active' => $active]; } $this->slim->render('/_menu.php', ['entries' => $result]); }
/** * Returns the form HTML to create a new setup. * @param Slim $app */ public function action_quickAddDialog(Slim $app) { if (!$app->user->isLoggedin()) { return false; } $tour = $app->rulechecker->getTournament(); $app->render('setup/quickAddDialog.twig', array('tournament' => $tour)); }
/** * Call this class as a function. * * @return void */ public function __invoke() { $request = MessageBridge::newOAuth2Request($this->slim->request()); $response = new OAuth2\Response(); $isValid = $this->server->validateAuthorizeRequest($request, $response); if (!$isValid) { MessageBridge::mapResponse($response, $this->slim->response()); return; } $authorized = $this->slim->request()->params('authorized'); if (empty($authorized)) { $this->slim->render($this->template, ['client_id' => $request->query('client_id', false)]); return; } //@TODO implement user_id $this->server->handleAuthorizeRequest($request, $response, $authorized === 'yes'); MessageBridge::mapResponse($response, $this->slim->response()); }
/** * DELETE /password/:key/:id * * @param string $key * @param int $id */ public function delete($key, $id) { $container = new Container(); if ($container->read($id) && $this->crypto->decrypt($container->getContainer(), $key) !== false) { $this->app->render($container->delete() ? 200 : 500, ['response' => $id]); } else { $this->app->render(404); } }
public function action_exportDialog(Slim $app, $setupId, $fitId) { if (!$app->user->isLoggedin()) { return false; } $setup = $app->evefit->getSetup($setupId); $fit = $setup->getFit($fitId); $app->render('fit/exportDialog.twig', array('setupId' => $setupId, 'fit' => $fit)); }
/** * GET /feed/item/queue */ public function dequeueItem() { $itemQueue = new ItemQueue(); if ($itemQueue->dequeue()) { $this->getItem($itemQueue->id_item); } else { $this->app->render(404); } }
/** * Returns partialHTML of a list of fits. * * @param \Slim\Slim $app */ public function action_fitList(Slim $app, $setupId, $fitId) { if (!$app->user->isLoggedin()) { return false; } $setup = $app->evefit->getSetup($setupId); $fit = $setup->getFit($fitId); $tour = $app->rulechecker->getTournament(); $app->render('fit/fit.twig', array('setup' => $setup, 'fit' => $fit, 'tournament' => $tour)); }
/** * @proxy app->render * * @param string $template The name of the template passed into the view's render() method * @param array $data Associative array of data made available to the view * @param int $status The HTTP response status code to use (optional) * @param string $controller The controller name that acts as root for the template - default = current controller */ protected function render($template, $data = array(), $status = null, $controller = null) { if (!is_null($controller)) { $tpl = "{$controller}/{$template}"; } else { $ctrl = $this->controllerName(); $tpl = "{$ctrl}/{$template}"; } $this->app->render($tpl, $data, $status); }
public function RenderPreview($files, \Slim\Slim &$app, $preview) { $obj = new Files(); $obj->parseFile($files); $obj->path = $preview; $user_id = $obj->user_id; // $cookieDB = $obj->cookie; $cookie = $app->getCookie('username'); $public = $obj->public; $db = $app->db; $logged = new Logged(); $id = $logged->getLogged($db, $cookie); //checking of the user is registered in Users table as the user or anonymous which added this file and getting his id if ($id == $user_id) { $app->render('Preview.php', ['files' => $files]); } elseif ($public == 0) { $app->render('Preview.php', ['files' => $files]); } else { $this->app->redirect('/TwigBlog/'); } }
public function render($name, $data = array(), $status = null) { if (strpos($name, ".php") === false) { $name = $name . ".php"; } if (isset($_SESSION['slim.flash'])) { $data['flash'] = $_SESSION['slim.flash']; $_SESSION['slim.flash'] = null; } $data['path'] = $_SESSION['path']; parent::render($name, $data, $status); }
/** * Returns partialHTML for a given setup by setupId * * @param \Slim\Slim $app * @param String $setupId */ public function action_list(Slim $app, $setupId) { if (!$app->user->isLoggedin()) { return false; } $setups = $app->evefit->getSetups(); $tour = $app->rulechecker->getTournament(); foreach ($setups as $setup) { if ($setup->getId() == $setupId) { $app->render('setup/setup.twig', array('setup' => $setup, 'tournament' => $tour)); } } }
public function action_admin(\Slim\Slim $app) { if (!$app->user->isLoggedin()) { return false; } if (!$app->user->isAdmin()) { return false; } $userId = $app->request()->get('user', null); if ($userId != null) { $app->model->getModel('user')->toggleValid($userId); } $users = $app->model->getModel('user')->getAll(); $app->render('user/admin.twig', array('users' => $users, 'user' => $app->user)); }
/** * * {@inheritDoc} * * @see \Slim\Slim::render() */ public function render($template, $data = array(), $status = null) { // Allowed Extensions $allowed = ['twig', 'php']; if (!preg_match('/' . preg_quote(implode('|', array_map(function ($ext) { return "." . $ext; }, $allowed))) . '/i', $template)) { foreach ($allowed as $ext) { if (file_exists('../View/' . $template . '.' . $ext)) { $template = $template . '.' . $ext; break; } } } parent::render($template, $data, $status); }
/** * Apply settings to the Slim application. * * @param \Slim\Slim $slim Application */ protected function configureSlim(\Slim\Slim $slim) { $slim->config(['parsoid.url' => Config::getStr('PARSOID_URL', 'http://parsoid-lb.eqiad.wikimedia.org/enwiki/'), 'parsoid.cache' => Config::getStr('CACHE_DIR', "{$this->deployDir}/data/cache"), 'es.url' => Config::getStr('ES_URL', 'http://127.0.0.1:9200/')]); $slim->configureMode('production', function () use($slim) { $slim->config(['debug' => false, 'log.level' => Config::getStr('LOG_LEVEL', 'INFO')]); // Install a custom error handler $slim->error(function (\Exception $e) use($slim) { $errorId = substr(session_id(), 0, 8) . '-' . substr(uniqid(), -8); $slim->log->critical($e->getMessage(), ['exception' => $e, 'errorId' => $errorId]); $slim->view->set('errorId', $errorId); $slim->render('error.html'); }); }); $slim->configureMode('development', function () use($slim) { $slim->config(['debug' => true, 'log.level' => Config::getStr('LOG_LEVEL', 'DEBUG'), 'view.cache' => false]); }); }
/** * Apply settings to the Slim application. * * @param \Slim\Slim $slim Application */ protected function configureSlim(\Slim\Slim $slim) { $slim->config(array('parsoid.url' => Config::getStr('PARSOID_URL', 'http://parsoid-lb.eqiad.wikimedia.org/enwiki/'), 'parsoid.cache' => Config::getStr('CACHE_DIR', "{$this->deployDir}/data/cache"), 'es.url' => Config::getStr('ES_URL', 'http://127.0.0.1:9200/'), 'es.user' => Config::getStr('ES_USER', ''), 'es.password' => Config::getStr('ES_PASSWORD', ''), 'can.edit' => Config::getBool('CAN_EDIT', false), 'can.vote' => Config::getBool('CAN_VOTE', false), 'oauth.enable' => Config::getBool('USE_OAUTH', false), 'oauth.consumer_token' => Config::getStr('OAUTH_CONSUMER_TOKEN', ''), 'oauth.secret_token' => Config::getStr('OAUTH_SECRET_TOKEN', ''), 'oauth.endpoint' => Config::getStr('OAUTH_ENDPOINT', ''), 'oauth.redir' => Config::getStr('OAUTH_REDIR', ''), 'oauth.callback' => Config::getStr('OAUTH_CALLBACK', ''))); $slim->configureMode('production', function () use($slim) { $slim->config(array('debug' => false, 'log.level' => Config::getStr('LOG_LEVEL', 'INFO'))); // Install a custom error handler $slim->error(function (\Exception $e) use($slim) { $errorId = substr(session_id(), 0, 8) . '-' . substr(uniqid(), -8); $slim->log->critical($e->getMessage(), array('exception' => $e, 'errorId' => $errorId)); $slim->view->set('errorId', $errorId); $slim->render('error.html'); }); }); $slim->configureMode('development', function () use($slim) { $slim->config(array('debug' => true, 'log.level' => Config::getStr('LOG_LEVEL', 'DEBUG'), 'view.cache' => false)); }); }
public function checkRequirements() { $paths = Utils::getPaths(SW_PATH . "/engine/Shopware/Components/Check/Data/Path.xml"); clearstatcache(); $systemCheckPathResults = Utils::checkPaths($paths, SW_PATH); foreach ($systemCheckPathResults as $value) { if (!$value['result']) { $fileName = SW_PATH . '/' . $value['name']; @mkdir($fileName, 0777, true); @chmod($fileName, 0777); } } clearstatcache(); $systemCheckPathResults = Utils::checkPaths($paths, SW_PATH); $hasErrors = false; foreach ($systemCheckPathResults as $value) { if (!$value['result']) { $hasErrors = true; } } $directoriesToDelete = ['engine/Library/Mpdf/tmp' => false, 'engine/Library/Mpdf/ttfontdata' => false]; CommonUtils::clearOpcodeCache(); $results = []; foreach ($directoriesToDelete as $directory => $deleteDirecory) { $result = true; $filePath = SW_PATH . '/' . $directory; Utils::deleteDir($filePath, $deleteDirecory); if ($deleteDirecory && is_dir($filePath)) { $result = false; $hasErrors = true; } if ($deleteDirecory) { $results[$directory] = $result; } } if (!$hasErrors && $this->app->request()->get("force") !== "1") { // No errors, skip page except if force parameter is set $this->app->redirect($this->app->urlFor("dbmigration")); } $isSkippableCheck = $this->app->config('skippable.check'); if ($isSkippableCheck && $this->app->request()->get("force") !== "1") { // No errors, skip page except if force parameter is set $this->app->redirect($this->app->urlFor("dbmigration")); } $this->app->render('checks.php', ['systemCheckResultsWritePermissions' => $systemCheckPathResults, 'filesToDelete' => $results, 'error' => $hasErrors]); }
public function render($template, $data = array(), $status = null) { if ($this->role) { if (strpos($template, '@') === false) { $template = '@' . $this->role . '/' . $template; } } parent::render($template, $data, $status); }
/** * Output tabular data, in the most appropriate MIME type * * @param array $data The rows to output * @param array $headers Column headers * * @throws \SameAsLite\Exception\ContentTypeException An exception may be thrown if the requested MIME type * is not supported */ protected function outputTable(array $data, array $headers = array()) { // pagination check if (empty($data)) { $this->app->view()->set('pagination', false); } elseif ($this->stores[$this->store]->isPaginated()) { $current_page = $this->stores[$this->store]->getCurrentPage(); // add pagination buttons to the template $this->app->view()->set('currentPage', $current_page); // $this->app->view()->set('numResults', count($data)); $max_page_num = (int) ceil($this->stores[$this->store]->getMaxResults() / $this->appOptions['num_per_page']); $this->app->view()->set('maxPageNum', $max_page_num); // // build pages array $pages = []; if (!isset($this->appOptions['num_page_links'])) { $num_page_links = 5; } else { $num_page_links = intval($this->appOptions['num_page_links']); } $pcounter = 0; $p = $current_page; while ($pcounter < $num_page_links) { $page = $p - ceil($num_page_links / 2); if ($page > 0) { $pages[] = $page; $pcounter++; } $p++; if ($page >= $max_page_num) { break; } } $this->app->view()->set('pages', $pages); } switch ($this->mimeBest) { case 'text/csv': case 'text/tab-separated-values': if ($this->mimeBest === 'text/tab-separated-values') { $delimiter = "\t"; } else { $delimiter = ","; } ob_start(); $out = fopen('php://output', 'w'); fputcsv($out, $headers, $delimiter); foreach ($data as $i) { fputcsv($out, $i, $delimiter); } fclose($out); $out = ob_get_contents(); ob_end_clean(); $this->app->response->setBody($out); break; case 'text/plain': ob_start(); $out = fopen('php://output', 'w'); // fwrite($out, implode(' => ', $headers) . PHP_EOL); foreach ($data as $i) { fwrite($out, implode(' => ', $i) . PHP_EOL); } fclose($out); $out = ob_get_contents(); ob_end_clean(); $this->app->response->setBody($out); break; case 'application/rdf+xml': case 'text/turtle': case 'application/x-turtle': $this->outputRDF(array_merge([$headers], $data), 'table', 'eg:predicate'); // TODO break; case 'application/json': $op = array(); foreach ($data as $row) { $op[] = array_combine($headers, $row); } $this->app->response->setBody(json_encode($op, JSON_PRETTY_PRINT)); // PHP 5.4+ break; // full webpage output // full webpage output case 'text/html': case 'application/xhtml+xml': // add the alternate formats for ajax query and pagination buttons $this->prepareWebResultView(); // escaping for output array_walk($headers, '\\SameAsLite\\Helper::escapeInputArray'); array_walk($data, '\\SameAsLite\\Helper::escapeInputArray'); $tables = array(); // no headers were given // turn the array keys into table headlines // use the sub-keys in the first column // and the array values in the second column if (!$headers && \SameAsLite\Helper::countdim($data) === 2) { foreach ($data as $hdr => $dat) { // reset the table $subtabledata = array(); if (is_array($dat)) { foreach ($dat as $k => $v) { if (is_array($v)) { $hdr = $k; // TODO //add a new data row with key and value foreach ($v as $uk => $uv) { $subtabledata[] = array($uk, $uv); } } else { //add a new data row with key and value $subtabledata[] = array($k, $v); } } } else { $subtabledata[] = array($hdr, $dat); } $tables[] = array('title' => $hdr, 'headers' => array(), "data" => $subtabledata); } // var_dump($tables);die; } else { $tables[] = array('headers' => $headers, "data" => $data); foreach ($data as &$d) { if (!is_array($d)) { $d = array_map('\\SameAsLite\\Helper::linkify', $d); // $d = \SameAsLite\Helper::linkify($d); } } } $this->app->render('page/table.twig', array('tables' => $tables)); break; default: throw new Exception\ContentTypeException('Could not render tabular output as ' . $this->mimeBest); } $this->app->stop(); }
global $log4php_config; \Logger::configure($log4php_config); $logger = \Logger::getLogger('index.php'); // INIT SLIM APP $app = new Slim(array('debug' => $debug, 'view' => new Twig())); $view = $app->view(); $view->parserExtensions = array(new \Twig_Extension_Debug()); $view->parserOptions = array('debug' => $debug); $env = $app->environment(); $env['basepath'] = __DIR__; // DEFINE SLIM-ERROR HANDLING $app->error(function (\Exception $e) use($app, $logger) { $logger->error($e->getMessage()); $data = array(); HeaderViewHelper::parseCurrentUser($data); $app->render('error.twig', $data); }); $app->notFound(function () use($app) { $data = array(); HeaderViewHelper::parseCurrentUser($data); $app->render('404.twig', $data); }); // INIT DB-CONNECTION try { Model\DataBase\SQLCommands::init(); } catch (Exceptions\DataSourceException $e) { $logger->fatal($e->getMessage()); $app->render('error.twig'); die; } // DEFINE GET ROUTES
$app->container->singleton('log', function () { $log = new Logger('Echolink CRON System'); $log->pushHandler(new StreamHandler('./logs/app.log', Logger::DEBUG)); return $log; }); // Prepare view $app->view(new Twig()); $app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('./templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true); $app->view->parserExtensions = array(new TwigExtension()); // dashboard $app->get('/', function () use($app) { $app->log->info("Echolink CRON System - '/' route"); $echolinksys = new System("mysql:host=" . host . ";dbname=" . database, username, password); $dataHistory = $echolinksys->getHistoryLog(); $dataEcholinkRep = $echolinksys->getRepeaterInArray(); $app->render('index.twig', array('dataHistory' => $dataHistory, 'dataEcholinkRepeater' => $dataEcholinkRep)); })->name('list'); // updating data $app->get('/check', function () use($app) { $app->log->info("Echolink CRON System - '/check' route"); $echolinksys = new System("mysql:host=" . host . ";dbname=" . database, username, password); $echolinksys->dataFromTheServer(); $app->log->info("Echolink CRON System - Update was performed from a remote server echolink.org"); if ($echolinksys->responseStat != System::RESPONSE_OK) { $app->log->info("Echolink CRON System - Server problem ! (CODE: " . $echolinksys->responseStat . ")"); $echolinksys->addHistoryLog("Server response problem! (CODE: " . $echolinksys->responseStat . ")"); } else { $body = "Byl změněn stav převaděče.\r\n" . "Call: "; foreach ($echolinksys->messageEmail as $email) { //set template for email! $body = "Byl změněn stav převaděče.\r\n" . "Call: " . $email["callname"] . "\r\n" . "Nyní stav: " . ($email["newStatus"] == 1 ? "true" : "false") . "\r\n" . "Datum poslední změny: " . $email["oldCheckDate"] . "\r\n" . "Datum nynější změny: " . $email["checkDate"] . "\r\n";
protected function renderHtml($htmlFile, $data = [], $status = 200) { $this->app->render($htmlFile, $data, $status); }