示例#1
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']);
			}
		}
示例#2
0
文件: Router.php 项目: fuzzy76/sire
 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);
         }
     }
 }
示例#3
0
function view($name, array $data = [])
{
    static $engine = null;
    if ($engine === null) {
        $engine = new League\Plates\Engine(__DIR__ . "/templates");
    }
    return $engine->render($name, $data);
}
示例#4
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;
 }
示例#5
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;
 }
示例#6
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();
示例#7
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;
 }
示例#8
0
// 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 = "Status";
// 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;
// $all_submits will be a 2D array containing all the submit information
// row keys: submit_id, date, username, problem, language, status
$all_submits = get_all_submits($dbc);
// if the user is logged in, get his submits too
// keys same as $all_submits
$user_submits = $user_logged_in == true ? get_users_submits($_COOKIE['username'], $dbc) : array();
// array with all the data that will be passed to the template
$data = array('all_submits' => $all_submits, 'user_submits' => $user_submits, 'username' => $user_logged_in == true ? $_COOKIE['username'] : null, 'user_logged_in' => $user_logged_in, 'admin' => $admin, 'title' => $title);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('judge', $data);
示例#9
0
    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);
示例#10
0
<?php

//$scheme = $_SERVER['HTTPS'] ? 'https' : 'http';
//$host = $_SERVER['HTTP_HOST'];
//$basedir = dirname($_SERVER['SCRIPT_NAME']);
//header("Location: {$scheme}://{$host}{$basedir}/www.matthewhouse.ca/index.html");
// exit();
$loader = (require __DIR__ . '/vendor/autoload.php');
$templates = new League\Plates\Engine('templates');
$current_file_path = dirname(__FILE__);
$page = $_GET['p'];
$subpage = $_GET['s'];
$templates->addFolder($page, $current_file_path . '/templates/' . $page);
// Render a template
echo $templates->render($page . '::' . $subpage);
示例#11
0
文件: router.php 项目: AmbreB/Senny
 public function makeView($page)
 {
     $templates = new League\Plates\Engine($this->template);
     echo $templates->render($page, ['name' => 'dkqhflfmagic']);
 }
示例#12
0
    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);
示例#13
0
<?php

//$scheme = $_SERVER['HTTPS'] ? 'https' : 'http';
//$host = $_SERVER['HTTP_HOST'];
//$basedir = dirname($_SERVER['SCRIPT_NAME']);
//header("Location: {$scheme}://{$host}{$basedir}/www.matthewhouse.ca/index.html");
// exit();
$loader = (require __DIR__ . '/vendor/autoload.php');
$templates = new League\Plates\Engine('templates');
// Render a template
echo $templates->render('main', ['name' => 'Jonathan']);
示例#14
0
<?php

/*---------------------------------------------------------------------------*/
// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
// markdown parser
require 'lib/Parsedown.php';
$title = "Help Page";
// path to markdown of the help page
$path = "data/help.md";
$text = file_get_contents($path);
$Parsedown = new Parsedown();
$text = $Parsedown->text($text);
$data = array('title' => $title, 'text' => $text);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('help', $data);
示例#15
0
    if ($page == '') {
        $page = 'Home';
    }
    $filename = Config::$sourceDir . $page . '.md';
    if (!file_exists($filename)) {
        not_found();
        die;
    }
    $source = file_get_contents($filename);
    // Pre-process source file
    $source = Parser::preProcess($source);
    // Parse markdown
    $html = Markdown::defaultTransform($source);
    // If there is a sidebar, parse the links from it
    $sidebarFilename = Config::$sourceDir . '_Sidebar.md';
    if (file_exists($sidebarFilename)) {
        $sidebar = file_get_contents($sidebarFilename);
        $sidebar = Parser::preProcess($sidebar);
        $sidebar = Markdown::defaultTransform($sidebar);
    } else {
        $sidebar = false;
    }
    echo $templates->render('page', ['title' => $page, 'html' => $html, 'sidebar' => $sidebar]);
} else {
    not_found();
}
function not_found()
{
    header('HTTP/1.1 404 Not Found');
    echo '404 Not Found';
}
 protected function generateTex($data)
 {
     $templates = new \League\Plates\Engine('phar://invoicer.phar/src/templates');
     $output = $templates->render('invoice', ['data' => $data]);
     file_put_contents('./invoice-' . date('Y-m-d') . '.html', $output);
 }
示例#17
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);
示例#18
0
文件: Helpers.php 项目: RDuuke/Newbie
/**
 *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);
}
示例#19
0
<?php

require 'vendor/autoload.php';
// Create new Plates instance
$templates = new League\Plates\Engine('./templates');
// Render a template
echo $templates->render('profile', ['name' => 'Jonathan']);
示例#20
0
function view($tpl, $data = [])
{
    $templates = new League\Plates\Engine(__DIR__ . '/Views/');
    return $templates->render($tpl, $data);
}
示例#21
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);
示例#22
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
session_start();
$templates = new League\Plates\Engine('templates/site');
echo $templates->render('user-registration-details');
示例#23
0
<?php

$template = new \League\Plates\Engine("../views");
echo $template->render("index/error");
示例#24
0
文件: main.php 项目: bafs/parvula
<?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');
示例#25
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);
示例#26
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 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);
示例#27
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);
示例#28
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;
示例#29
0
文件: index.php 项目: OppHack/Blinx
<?php

require_once __DIR__ . '/vendor/autoload.php';
session_start();
$templates = new League\Plates\Engine('templates/site');
echo $templates->render('home');