Example #1
0
 function process()
 {
     global $config;
     $backend = Backend::createBackend($config['backend']);
     if (substr($this->getPath(), 0, 5) == 'sire/') {
         // Sire internal page
         $code = $this->internal(substr($this->getPath(), 5), $backend);
         $this->handleStatus($code);
         return;
     }
     // Regular request handling
     $file = File::createFile($backend, $this->getPath());
     if ($file instanceof File) {
         $templates = new \League\Plates\Engine('template');
         echo $templates->render('content', ['file' => $file]);
     } else {
         if ($file == 200) {
             // Asset fallback
             $backend->serveRaw($this->getPath());
         } else {
             // Error handling
             $this->handleStatus($file);
         }
     }
 }
Example #2
0
 public function testActionMethodExists()
 {
     $engine = new \League\Plates\Engine();
     $ext = new \werx\Url\Extensions\Plates();
     $engine->loadExtension($ext);
     $template = new \League\Plates\Template($engine);
     $this->assertTrue(method_exists($template->url(), 'action'), 'The action method from werx\\Url\\Builder should be available');
 }
Example #3
0
		public function __construct(){
			$templates = new League\Plates\Engine('views/templates');
			if (isset($_GET['page']) && array_key_exists($_GET['page'], $this->nav)){
				echo $templates->render($this->nav[$_GET['page']][1], ['name' => 'Benjamin']);
			} else {
				echo $templates->render('index.part', ['name' => 'Benjamin']);
			}
		}
Example #4
0
function view($name, array $data = [])
{
    static $engine = null;
    if ($engine === null) {
        $engine = new League\Plates\Engine(__DIR__ . "/templates");
    }
    return $engine->render($name, $data);
}
Example #5
0
 public function register(Application $app)
 {
     $app->set("View", function ($baseDir = null) use($app) {
         $baseDir = $baseDir ?: APP_PATH . 'views';
         $plates = new \League\Plates\Engine();
         $plates->loadExtension(new URI($app->Request->getPathInfo()));
         $plates->setDirectory($baseDir);
         return $plates;
     });
 }
Example #6
0
 /**
  * Affiche un template
  * 
  * @param  string $file Chemin vers le template, relatif à app/templates/
  * @param  array  $data Données à rendre disponibles à la vue
  */
 public function show($file, array $data = array())
 {
     //incluant le chemin vers nos templates
     $engine = new \League\Plates\Engine('../app/templates');
     //charge nos extensions (nos fonctions personnalisées)
     $engine->loadExtension(new \W\View\Plates\PlatesExtensions());
     //rend certaines données disponibles à tous les templates
     //accessible avec $w_user dans les fichiers de vue
     $engine->addData(array("w_user" => $this->getUser()));
     //retire l'éventuelle extension .php
     $file = str_replace(".php", "", $file);
     // Affiche le template
     echo $engine->render($file, $data);
     die;
 }
Example #7
0
 /**
  * Affiche un template
  * @param string $file Chemin vers le template, relatif à app/Views/
  * @param array  $data Données à rendre disponibles à la vue
  */
 public function show($file, array $data = array())
 {
     //incluant le chemin vers nos vues
     $engine = new \League\Plates\Engine(self::PATH_VIEWS);
     //charge nos extensions (nos fonctions personnalisées)
     $engine->loadExtension(new \W\View\Plates\PlatesExtensions());
     $app = getApp();
     // Rend certaines données disponibles à tous les vues
     // accessible avec $w_user & $w_current_route dans les fichiers de vue
     $engine->addData(['w_user' => $this->getUser(), 'w_current_route' => $app->getCurrentRoute()]);
     // Retire l'éventuelle extension .php
     $file = str_replace('.php', '', $file);
     // Affiche le template
     echo $engine->render($file, $data);
     die;
 }
Example #8
0
 /**
  * process the request so we can work out
  * what view we need to process and serve
  *
  * @access public
  * @return object   DocMark\System\View Object
  */
 public function process()
 {
     $query = $this->request->query->keys();
     // setup the root for all the doc files
     $docRoot = ROOT . $this->config['docs']['root'];
     if (isset($query['0']) && !empty($query['0'])) {
         $this->url = $query['0'] = rtrim($query['0'], '/');
         $query['0'] = ltrim($query['0'], '/');
         $queryBits = explode('/', $query['0']);
     } else {
         // homepage
         $queryBits = array();
         $isHome = true;
     }
     $path = $this->findFile($queryBits, $docRoot);
     // set the template engine and set fallback theme
     $templates = new \League\Plates\Engine(ROOT . 'themes' . DS . 'fallback');
     // set the defined user theme
     if (file_exists(ROOT . 'themes' . DS . $this->config['themeName']) && is_dir(ROOT . 'themes' . DS . $this->config['themeName'])) {
         $templates->addFolder($this->config['themeName'], ROOT . 'themes' . DS . $this->config['themeName'], true);
     }
     // set the path to the assets to run through plates
     $templates->loadExtension(new \Snscripts\AdvancedAssets\Assets(ROOT, new \Symfony\Component\Filesystem\Filesystem()));
     // load the converter
     $converter = new \Michelf\MarkdownExtra();
     if ($path !== false && isset($isHome) && $isHome) {
         return new \DocMark\System\View\Home($this, $converter, $templates, $path);
     } elseif ($path !== false && (!isset($isHome) || $isHome === false)) {
         return new \DocMark\System\View\Page($this, $converter, $templates, $path);
     } else {
         return new \DocMark\System\View\Error($this, $converter, $templates, $path);
     }
 }
Example #9
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
session_start();
$templates = new League\Plates\Engine('templates/site');
echo $templates->render('user-registration-details');
Example #10
0
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Data.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Directory.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/FileExtension.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Folder.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Folders.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Func.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Functions.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Name.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Template.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Extension/ExtensionInterface.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Extension/Asset.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Extension/URI.php';
/*************************************
 * Init Plates Tpl Engine
 */
$platesTpl = new League\Plates\Engine(GSPLUGINPATH . OGM_SUB_FOLDER . '/templates');
/*************************************
 * Register Tpl Helper Function
 */
$platesTpl->registerFunction('imageExists', function ($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($code == 200) {
        $status = true;
    } else {
        $status = false;
    }
    curl_close($ch);
    return $status;
Example #11
0
<?php

function get_user_info($username, $dbc)
{
    if (!isset($username)) {
        return array('name' => "Error", 'mail_address' => "Error", 'mail_subscription' => 0);
    }
    $stmt = $dbc->prepare("SELECT name, mail_address, mail_subscription FROM users\n          WHERE username=:username");
    $stmt->execute(array(':username' => $username));
    // get the data from the result query
    return $stmt->fetch(PDO::FETCH_ASSOC);
}
/*---------------------------------------------------------------------------*/
require 'database.php';
// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
$title = "Account management";
$user_logged_in = isset($_COOKIE['username']);
$user_data = get_user_info($_COOKIE['username'], $dbc);
$data = array('title' => $title, 'user_logged_in' => $user_logged_in, 'user_data' => $user_data);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('manage-account', $data);
Example #12
0
if (!isset($_GET['problem'], $_GET['language'])) {
    die("No solution chosen.");
}
require 'database.php';
// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
// markdown parser
require 'lib/Parsedown.php';
$title = "Example Solution";
$problem = $_GET['problem'];
$lang = $_GET['language'];
$user_logged_in = isset($_COOKIE['username']);
// check whether the user is an admin
$admin = $user_logged_in == true ? is_admin($_COOKIE['username'], $_COOKIE['huehuehue']) : false;
// check if the user solved the problem
$solved = $user_logged_in == true ? check_if_solved($_COOKIE['username'], $problem, $lang, $dbc) : false;
// load the .ini file where the paths are stored
$settings = parse_ini_file("settings.ini", true);
// construct paths to solution files
$paths = get_solution_paths($settings['web']['solutions'], $problem, $lang);
// load the source code
$source_code = file_exists($paths['source']) ? htmlentities(file_get_contents($paths['source'])) : "Error: Source code file not found";
// get the solution text
$text = file_exists($paths['text']) ? file_get_contents($paths['text']) : "Error: Source code file not found";
// parse the markdown from the text
$Parsedown = new Parsedown();
$text = $Parsedown->text($text);
$data = array('title' => $title, 'admin' => $admin, 'solved' => $solved, 'problem' => $problem, 'source_code' => $source_code, 'text' => $text);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('view-solution', $data);
Example #13
0
    return $problems;
}
// checks if the user has admin privileges
// magic cookie contains hash of the username and either "is_an_admin" or
// "just_a_user" appended based on the privileges
function check_if_admin($username, $magic_cookie)
{
    // check if the user that is logged in has admin privileges
    if (strcmp($magic_cookie, md5($username . "is_an_admin")) == 0) {
        return true;
    }
    return false;
}
/*---------------------------------------------------------------------------*/
require 'database.php';
// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
$title = "Problemset";
// check if the user is logged in
$user_logged_in = isset($_COOKIE['username']);
// check whether the user is an admin
$admin = $user_logged_in == true ? check_if_admin($_COOKIE['username'], $_COOKIE['huehuehue']) : false;
// 1D array of problems which user already solved
$solved_problems = $user_logged_in == true ? get_solved_problems($_COOKIE['username'], $dbc) : array();
// 2D array of problems as it is passed to the template
// row keys: problem_id, problem_name, published, solved
$all_problems = get_problems($solved_problems, $dbc);
$data = array('title' => $title, 'problems' => $all_problems, 'admin' => $admin);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('problemset', $data);
Example #14
0
<?php

use Parvula\Parvula;
use Parvula\Parvula\Core\Config;
use Parvula\Parvula\Core\Models\Pages;
$templates = new League\Plates\Engine(__DIR__ . '/view', 'html');
$templates->addData(['baseUrl' => Parvula::getRelativeURIToRoot(), 'pluginUrl' => Parvula::getRelativeURIToRoot($that->getPluginPath()), 'templateUrl' => Parvula::getRelativeURIToRoot(_THEMES_ . $that->app['config']->get('theme'))]);
$pages = $that->app['pages'];
$pagesList = $pages->index(true);
$templates->addData(['pagesList' => $pagesList, '_page' => 'admin']);
return $templates->render('base');
Example #15
0
 * along with RuneAudio; see the file COPYING.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.txt>.
 *
 *  file: index.php
 *  version: 1.3
 *  coder: Simone De Gregori
 *
 */
// load configuration
include $_SERVER['HOME'] . '/app/config/config.php';
// main include
include $_SERVER['HOME'] . '/app/libs/vendor/autoload.php';
// open session
session_start();
// plates: create new engine
$engine = new \League\Plates\Engine('/srv/http/app/templates');
// plates: load asset extension
$engine->loadExtension(new \League\Plates\Extension\Asset('/srv/http/assets', true));
// plates: load URI extension
$engine->loadExtension(new \League\Plates\Extension\URI($_SERVER['REQUEST_URI']));
// plates: create a new template
$template = new \League\Plates\Template($engine);
// set devmode
$template->dev = $devmode;
// activePlayer
$activePlayer = $redis->get('activePlayer');
// TODO: rework needed
$template->activePlayer = $activePlayer;
// allowed controllers
$controllers = array('credits', 'coverart', 'dev', 'debug', 'help', 'index', 'login', 'mpd', 'network', 'playback', 'settings', 'sources', 'tun');
// check page
Example #16
0
/**
 *function view, renders a view and the layout select.
 *
 * @param array $parameters
 */
function view($template, $parameters = [])
{
    $tmpl = new \League\Plates\Engine('..\\resource\\views', 'tpl.php');
    echo $tmpl->render($template, $parameters);
}
Example #17
0
 public function __construct()
 {
     $this->_CI =& get_instance();
     $this->_CI->load->config('plates');
     parent::__construct(config_item("directory_tempalte"), config_item("file_extension"));
 }
Example #18
0
<?php

// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
$title = "Registration";
$data = array('title' => $title);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('register-form', $data);
Example #19
0
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Data.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Directory.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/FileExtension.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Folder.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Folders.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Func.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Functions.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Name.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Template/Template.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Extension/ExtensionInterface.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Extension/Asset.php';
require_once GSPLUGINPATH . OGM_SUB_FOLDER . '/plates/Extension/URI.php';
/*************************************
 * Init Plates Tpl Engine
 */
$platesTpl = new League\Plates\Engine(GSPLUGINPATH . OGM_SUB_FOLDER . '/templates');
/*************************************
 * Register Tpl Helper Function
 */
$platesTpl->registerFunction('isTab', function ($string) {
    if (@$_POST['tab'] == $string) {
        return true;
    }
    return false;
});
/*************************************
 * Get & save data
 */
$params = $_REQUEST;
$allowedXmlVars = array("general_author", "general_publisher", "general_image_path", "twitter_site", "twitter_creator", "facebook_page_id", "facebook_admins");
foreach ($params as $key => $value) {
Example #20
0
<?php

use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\Server;
use League\Plates\Extension\URI as PlatesUri;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server') {
    $path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
    if (__FILE__ !== $path && is_file($path)) {
        return false;
    }
    unset($path);
}
$app = new MiddlewarePipe();
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$routes = (require 'config/routes.php');
// Routing system
$app->pipe('/', function ($req, $res, $next) use($routes) {
    $path = $req->getUri()->getPath();
    $template = new League\Plates\Engine(__DIR__ . '/../views');
    $template->loadExtension(new PlatesUri($req->getUri()->getPath()));
    // 404 error
    if (!in_array($path, array_keys($routes))) {
        return $res->withStatus('404')->end($template->render('404'));
    }
    $route = new $routes[$path]($template);
    return $res->end($route($req, $res, $next));
});
$server->listen();
Example #21
0
 public function renderpage($po_page)
 {
     // Get view folder and file
     $ls_viewfolder = $this->getviewfolder($po_page);
     $ls_viewfile = $this->getviewfile($po_page);
     $ls_templatefolder = $this->gettemplatefolder($po_page);
     $ls_partialfolder = $this->getpartialfolder($po_page);
     $ls_assetsfolder = $this->getasstesfolder($po_page);
     // Get the data
     $la_viewdata = $this->getviewdata();
     $la_templatedata = $this->gettemplatedata();
     // Has view ?
     $lb_hasview = $this->hasview($po_page);
     // If no view is defined and view data is set throw error
     if (!$lb_hasview && !empty($la_viewdata)) {
         trigger_error('View not defined: ' . $ls_viewfolder . '/' . $ls_viewfile, E_USER_ERROR);
     }
     // Dont show anything if no view is defined
     if (!$lb_hasview) {
         return false;
     }
     // Create new Plates instance
     $lo_templates = new \League\Plates\Engine($ls_viewfolder);
     // Load URI extension
     $lo_templates->loadExtension(new \League\Plates\Extension\URI($this->getcurrenturl()));
     // Load asset extension
     $lo_templates->loadExtension(new AssetExtension($ls_assetsfolder, true));
     // Prepate the HTML extension for the template engine
     $lo_htmlextension = new HtmlExtension();
     // Inject any validation errors that we accumulated
     $lo_htmlextension->setformerrors($this->getformerrors());
     // Load html extension
     $lo_templates->loadExtension($lo_htmlextension);
     // Get the view details from db if non admin
     if (strcasecmp($po_page->module, 'admin') === 0) {
         // Configure the template
         $la_viewdata['gs_template'] = 'templates::admin';
         $la_viewdata['ga_templatedata'] = ['gs_title' => 'Mercury PHP', 'gs_currentpage' => $this->getcurrenturl(), 'gi_copyrightyear' => date('Y'), 'gs_version' => $this->getversion()];
     } else {
         // Load any additional custom extensions
         $la_extensions = $this->pagemodel->getpages('VIEWEXTENSION');
         foreach ($la_extensions as $lo_extension) {
             // Prepare the class
             $ls_extension = "\\Mercury\\App\\Extensions\\{$lo_extension->name}";
             if (class_exists($ls_extension)) {
                 $lo_templates->loadExtension(new $ls_extension());
             }
         }
         // Get more details about template
         $lo_search = new \stdClass();
         $lo_search->name = $ls_viewfile;
         $lo_search->controllerid = $po_page->controllerid;
         $lo_search->moduleid = $po_page->moduleid;
         $lo_viewdetail = $this->pagemodel->getviewdetails($lo_search);
         //Standard values
         $la_standardvals = ['gs_title' => $po_page->pagetitle, 'gs_currentpage' => $this->getcurrenturl(), 'gs_viewname' => $lo_viewdetail->name, 'gi_copyrightyear' => date('Y'), 'gs_version' => $this->getversion()];
         // Configure the template
         $la_viewdata['gs_template'] = is_object($lo_viewdetail) && !empty($lo_viewdetail->template) ? 'templates::' . strtolower($lo_viewdetail->template) : 'defaults::blank';
         $la_viewdata['ga_templatedata'] = array_merge($la_templatedata, $la_standardvals);
     }
     // Add folders used for the engine
     $lo_templates->addFolder('templates', $ls_templatefolder);
     $lo_templates->addFolder('defaults', $this->defaulttemplate);
     if (file_exists($ls_partialfolder)) {
         $lo_templates->addFolder('partials', $ls_partialfolder);
     }
     // Render the view if exists
     $ls_pagecontent = $lo_templates->render($ls_viewfile, $la_viewdata);
     // Output the page
     echo $ls_pagecontent;
     return true;
 }
Example #22
0
function view($tpl, $data = [])
{
    $templates = new League\Plates\Engine(__DIR__ . '/Views/');
    return $templates->render($tpl, $data);
}
<?php

require 'vendor/autoload.php';
// Create new Plates instance
$templates = new League\Plates\Engine('./templates');
// Render a template
echo $templates->render('profile', ['name' => 'Jonathan']);
Example #24
0
    $path = sprintf("data/submits/%d/%d-compiler.log", $id, $id);
    if (file_exists($path)) {
        return htmlentities(file_get_contents($path));
    } else {
        return "Compiler log not found";
    }
}
/*---------------------------------------------------------------------------*/
// if the link is malformed, die
if (!isset($_GET['submit']) || intval($_GET['submit']) == 0 || intval($_GET['submit']) < 1 || !isset($_COOKIE['username'])) {
    die("No submit chosen.");
}
require 'database.php';
// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
$title = "Submission Details";
$user_logged_in = isset($_COOKIE['username']);
// check whether the user is an admin
$admin = $user_logged_in == true ? is_admin($_COOKIE['username'], $_COOKIE['huehuehue']) : false;
// submit data
// keys: submit_id, site, timestamp, username, problem, language, status
$submit = get_submit($_GET['submit'], $dbc);
// source code of the submission
// error string will be stored here if the source is not found
$source_code = get_source_code($_GET['submit'], $submit['language']);
$compiler_log = get_compiler_log($_GET['submit']);
$test_log = get_test_log($_GET['submit']);
$data = array('title' => $title, 'admin' => $admin, 'submit' => $submit, 'source_code' => $source_code, 'compiler_log' => $compiler_log, 'test_log' => $test_log);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('view-submit', $data);
Example #25
0
<?php

// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
$title = "Home";
$data = array('title' => $title);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('index', $data);
Example #26
0
 public function makeView($page)
 {
     $templates = new League\Plates\Engine($this->template);
     echo $templates->render($page, ['name' => 'dkqhflfmagic']);
 }
Example #27
0
    public function call()
    {
        $app = $this->app;
        // Get request path and media type
        // Run inner middleware and application
        $this->next->call();
        $reqMediaType = $app->request->getMediaType();
        $reqIsAPI = (bool) preg_match('|^/api/.*$|', $app->request->getPath());
        if ($reqMediaType === 'application/json' || $reqIsAPI) {
            $app->response->headers->set('Content-Type', 'application/json');
            $app->response->headers->set('Access-Control-Allow-Methods', '*');
            $app->response->headers->set('Access-Control-Allow-Origin', '*');
        } else {
            $app->response->headers->set('Content-Type', 'text/html');
        }
    }
}
/* General functions */
// Create new Plates instance and map template folders
$templates = new League\Plates\Engine('templates');
$templates->addFolder('partials', 'templates/partials');
// Initalize Slim instance
$app = new \Slim\Slim(array('debug' => defined('GENERAL_DEBUG') && GENERAL_DEBUG === true ? true : false));
$app->add(new \APIheaderMiddleware());
// Set routes
$app->get('/', 'dashboard');
$app->get('/api', 'routeGetOverview');
$app->get('/api/warranties', 'routeGetWarranties');
$app->get('/api/warranties/:id', 'routeGetWarranty');
// Run application
$app->run();
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program;  If not, see <http://www.gnu.org/licenses/>.
 */
require __DIR__ . '/install_lang.php';
require __DIR__ . '/../vendor/autoload.php';
$template = new \League\Plates\Engine(__DIR__ . '/../templates/builtin/html');
$template->registerFunction('_', 'lng');
error_reporting(0);
// E_ERROR | E_WARNING | E_PARSE
function create_tables(PDO $pdo, $delete_existing)
{
    static $migrations = [];
    if (empty($migrations)) {
        $migrations[] = (include 'updates/ThWboardMigration.0.php');
        $migrations[] = (include 'updates/ThWboardMigration.1.php');
        $migrations[] = (include 'updates/ThWboardMigration.2.php');
        $migrations[] = (include 'updates/ThWboardMigration.3.php');
        $migrations[] = (include 'updates/ThWboardMigration.4.php');
        $migrations[] = (include 'updates/ThWboardMigration.5.php');
    }
    if ($delete_existing) {
Example #29
0
<?php

require 'vendor/autoload.php';
$templates = new League\Plates\Engine(__DIR__);
$html = $templates->render('content');
$css = file_get_contents('style.css');
$emogrifier = new \Pelago\Emogrifier($html, $css);
$mergedHtml = $emogrifier->emogrify();
echo $mergedHtml;
Example #30
0
}
// checks if the user has admin privileges
// magic cookie contains hash of the username and either "is_an_admin" or
// "just_a_user" appended based on the privileges
function is_admin($username, $magic_cookie)
{
    // check if the user that is logged in has admin privileges
    if (strcmp($magic_cookie, md5($username . "is_an_admin")) == 0) {
        return true;
    }
    return false;
}
/*---------------------------------------------------------------------------*/
require 'database.php';
// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
$title = "Admin dashboard";
// check if the user is logged in
$user_logged_in = isset($_COOKIE['username']);
// check whether the user is an admin
$admin = $user_logged_in == true ? is_admin($_COOKIE['username'], $_COOKIE['huehuehue']) : false;
// array of problem ids
$problems = get_problems($dbc);
// array of usernames
$users = get_users($dbc);
// array of possible languages for solution submission
$langs = array('C++' => "cpp", 'C' => "c", 'Pascal' => "pas", 'Java' => "java", 'Python' => "py");
$data = array('title' => $title, 'problems' => $problems, 'users' => $users, 'admin' => $admin, 'langs' => $langs);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('admin', $data);