Author: Bennet Matschullat (hello@bennet-matschullat.com)
Author: Erik Torsner (erik@torgesta.com)
 public function testAddGlobal()
 {
     $obj = new Twig(['paths' => __DIR__ . '/../templates/']);
     $obj->addGlobal('sitename', 'Twig Test Site');
     $output = $obj->render('global');
     $this->assertEquals('<title>Twig Test Site</title>' . "\n", $output);
 }
Example #2
0
 /**
  * Create or update a table in a database.
  *
  * @param string $database The name of the database.
  * @param string $schema The name of the schema.
  * @param Table $table The Table object representing what the table should become.
  * @param bool $force If false, the driver should not perform possibly destructive changes.
  * @return bool True if operations were performed successfully.
  */
 public function setTable($database, $schema, Table $table, $force = false)
 {
     $success = true;
     foreach ($this->templates as $dest => $template) {
         $output = $this->twig->render($template, ['database' => $database, 'schema' => $schema, 'table' => $table]);
         $success = $success && file_put_contents($dest, $output);
     }
     return $success;
 }
Example #3
0
 /**
  * Translation functions
  *
  * @param Twig $twig
  */
 public function addTranslationFunctions($twig)
 {
     $twig->addFunction('_x', new Twig_SimpleFunction('_x', function ($text, $context, $domain = 'default') {
         return _x($text, $context, $domain);
     }));
     $twig->addFunction('_n', new Twig_SimpleFunction('_n', function ($single, $plural, $number, $domain = 'default') {
         return _n($single, $plural, $number, $domain);
     }));
     $twig->addFunction('_nx', new Twig_SimpleFunction('_nx', function ($single, $plural, $number, $context, $domain = 'default') {
         return _nx($single, $plural, $number, $context, $domain);
     }));
     return $twig;
 }
Example #4
0
 /**
  * Crea una unica instancia
  */
 public static function getInstance()
 {
     if (Twig::$instance == NULL) {
         Twig::$instance = new Twig();
     }
     return Twig::$instance;
 }
Example #5
0
 /**
  * Méthode qui crée l'unique instance de la classe
  * si elle n'existe pas encore puis la retourne.
  *
  * @param void
  * @return Singleton
  */
 public static function getInstance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new Twig();
     }
     return self::$_instance;
 }
 public function action_index()
 {
     $twig = Twig::factory('Public/login');
     if (Auth::instance()->logged_in()) {
         HTTP::redirect('admin/games');
     }
     if ($this->request->method() == 'POST') {
         $post = $this->request->post();
         $twig->post = $post;
         $success = Auth::instance()->login($post['username'], $post['password']);
         if ($success) {
             $user = Auth::instance()->get_user();
             if ($user->state == 2) {
                 Auth::instance()->logout();
                 $error = 'Your account has been locked. Please contact an administrator.';
             } else {
                 $login = ORM::factory('Login');
                 $login->user_id = $user->id;
                 $login->ip_address = Request::$client_ip;
                 $login->login_date = date('Y-m-d H:i:s');
                 $login->save();
                 Session::instance()->set('userData', $login->as_array());
                 HTTP::redirect('admin/games');
             }
         } else {
             $error = 'The user name or password is incorrect.';
         }
         $twig->error = $error;
     }
     $this->response->body($twig);
 }
 public function get_response()
 {
     $twig = Twig::factory('frontend/main');
     $response = $twig->render('Public/404');
     $response = Response::factory()->status(404)->body($response);
     return $response;
 }
 protected function registerTwigExtensions()
 {
     \Twig::addTokenParser(new ExtendsParent());
     $this->app->bindIf('lava83.twig.loader.filesystem', function () {
         return new Filesystem($this->app['config']['view.paths']);
     }, true);
     \Twig::getLoader()->addLoader($this->app['lava83.twig.loader.filesystem']);
 }
 /**
  * Setup view
  *
  * @return void
  */
 public function before()
 {
     if (empty($this->template)) {
         // Generate a template name if one wasn't set.
         $this->template = str_replace('_', DIRECTORY_SEPARATOR, $this->request->controller) . DIRECTORY_SEPARATOR . $this->request->action;
         if (!empty($this->request->directory)) {
             $this->template = $this->request->directory . DIRECTORY_SEPARATOR . $this->template;
         }
     }
     if ($this->auto_render) {
         // Load the twig template.
         $this->template = Twig::factory($this->template, $this->environment);
         // Return the twig environment
         $this->environment = $this->template->environment();
     }
     return parent::before();
 }
 public function action_index()
 {
     $twig = Twig::factory('Public/register');
     if (Auth::instance()->logged_in()) {
         HTTP::redirect('admin/dashboard');
     }
     $settings = ORM::factory('Setting')->where('id', '=', 1)->where('registration_status', '=', 1)->find();
     if ($settings->loaded()) {
         $registration = true;
         $twig->registrationStatus = null;
     } else {
         $registration = false;
         $twig->registrationStatus = 'Registration is currently off.';
     }
     if ($this->request->method() == 'POST') {
         $post = $this->request->post();
         $twig->post = $post;
         $errorMessages = array();
         $controllerValidation = Validation::factory($post)->rule('terms', 'not_empty')->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', 4))->rule('password', 'max_length', array(':value', 30));
         if ($registration) {
             if ($controllerValidation->check()) {
                 try {
                     $register = ORM::factory('User');
                     $register->username = $post['username'];
                     $register->email = $post['email'];
                     $register->password = $post['password'];
                     $register->save();
                     $adminRole = ORM::factory('Role', 1);
                     $register->add('roles', $adminRole);
                     $twig->success = 'You have successfully registered.';
                     $twig->post = null;
                 } catch (ORM_Validation_Exception $e) {
                     $errorMessages = $e->errors('models');
                 }
             } else {
                 $errors = $controllerValidation->errors();
                 foreach ($errors as $key => $value) {
                     if ($key == 'terms' and $value[0] == 'not_empty') {
                         $errorMessages[] = 'Please agree with terms and conditions to register.';
                     }
                     if ($key == 'password' and $value[0] == 'not_empty') {
                         $errorMessages[] = 'Please enter your password.';
                     }
                     if ($key == 'password' and $value[0] == 'min_length') {
                         $errorMessages[] = 'Password is too short.';
                     }
                     if ($key == 'password' and $value[0] == 'max_length') {
                         $errorMessages[] = 'Password is too long.';
                     }
                 }
             }
         } else {
             $errorMessages[] = 'Registration is currently off.';
         }
         $twig->errors = $errorMessages;
     }
     $this->response->body($twig);
 }
Example #11
0
 public static function get()
 {
     $loader = new Twig_Loader_Filesystem(BASE_PATH . '/views');
     self::$twig = new Twig_Environment($loader, array('cache' => BASE_PATH . '/cache', 'debug' => true));
     self::$twig->addGlobal("base_url", BASE_URL);
     self::$twig->addGlobal("assets_url", ASSETS_URL);
     self::$twig->addGlobal("flash", $_SESSION['slim.flash']);
     return self::$twig;
 }
Example #12
0
 /**
  * Setup view
  *
  * @return void
  */
 public function __construct(Request $request, Response $response)
 {
     parent::__construct($request, $response);
     if (empty($this->template)) {
         // Generate a template name if one wasn't set.
         $this->template = str_replace('_', DIRECTORY_SEPARATOR, $this->request->controller()) . DIRECTORY_SEPARATOR . $this->request->action();
         $directory = $this->request->directory();
         if (!empty($directory)) {
             $this->template = $this->request->directory() . DIRECTORY_SEPARATOR . $this->template;
         }
     }
     if ($this->auto_render) {
         // Load the twig template.
         $this->template = Twig::factory($this->template, $this->environment);
         // Return the twig environment
         $this->environment = $this->template->environment();
     }
 }
Example #13
0
 /**
  * Processes a template and returns the output.
  *
  * @param string $name The template to process.
  * @return string The output.
  */
 public function render($name)
 {
     $name = isset($this->_twig->custom_path)
         ? $this->_twig->custom_path . '/' . $name
         : $name
         ;
     $template = $this->_twig->loadTemplate($name);
     if(!is_array($this->_data)) $this->_data = array();
     return $template->render($this->_data);
 }
 public function action_index()
 {
     $twig = Twig::factory('Public/index');
     $games = ORM::factory('Game')->where('state', '=', 1)->order_by('name', 'ASC')->find_all();
     $data = array('games' => $games);
     $session = Session::instance();
     $session->delete('registrationState', 'registrationUsername', 'registrationClass', 'registrationHero');
     $twig->games = $games;
     $this->response->body($twig);
 }
Example #15
0
 /**
  * Назначить текущую тему оформления
  *
  * @param null $theme
  */
 static function setCurrent($theme = null)
 {
     //удалить все невостребованные классы тем оформления
     foreach (self::getThemes() as $t) {
         \LaraPage::body()->removeClass(self::getClassTheme($t));
     }
     //добавить класс текущей темы оформления
     \LaraPage::body()->addClass(self::getClassTheme($theme));
     self::$current = $theme;
     \Twig::addGlobal('current_theme', $theme);
 }
 public function action_index()
 {
     $slug = $this->request->param('slug');
     $game = ORM::factory('Game')->where('slug', '=', $slug)->find();
     if (!$game->loaded()) {
         throw new HTTP_Exception_404();
     }
     $twig = Twig::factory('Public/game');
     $twig->game = $game;
     $this->response->body($twig);
 }
Example #17
0
 public function testRender()
 {
     Kohana::$config->shouldReceive('load')->with('twig')->once()->andReturn(Kohana::$config);
     Kohana::$config->shouldReceive('get')->with('loader')->once()->andReturn(array('extension' => 'html', 'path' => ''));
     Kohana::$config->shouldReceive('get')->with('environment')->once()->andReturn(array('auto_reload' => Kohana::$environment == Kohana::DEVELOPMENT, 'autoescape' => TRUE, 'base_template_class' => 'Twig_Template', 'cache' => APPPATH . 'cache/twig', 'charset' => 'utf-8', 'optimizations' => -1, 'strict_variables' => FALSE));
     Kohana::$config->shouldReceive('get')->with('functions')->once()->andReturn(array());
     Kohana::$config->shouldReceive('get')->with('filters')->once()->andReturn(array());
     Kohana::$config->shouldReceive('get')->with('tests')->once()->andReturn(array());
     $twig = Twig::factory();
     $twig->hello = 'Hello World!';
     $view = $twig->render('tests/test');
     $this->assertEquals("Hello World!", trim($view));
 }
Example #18
0
function jBlockParsing($_type = "html", $_string = "", $_parameters = [])
{
    switch ($_type) {
        case "pug":
        case "jade":
            $Pug = new Pug();
            $_string = $Pug->drawText($_string, $_parameters);
            break;
        case "md":
        case "markdown":
        case "parsedown":
            $Parsedown = new Parsedown();
            $_string = $Parsedown->drawText($_string);
            break;
        case "twig":
            $Twig = new Twig();
            $_string = $Twig->drawText($_string, $_parameters);
            break;
        default:
            break;
    }
    return $_string;
}
 public function action_index()
 {
     $twig = Twig::factory('Admin/reports');
     $twig->totalGames = ORM::factory('Game')->where('state', '=', 1)->count_all();
     $twig->totalCompleted = ORM::factory('Game')->where('state', '=', 1)->where('status', '=', 'Completed')->or_where('status', '=', 'Played')->count_all();
     $twig->totalSpent = 0;
     $twig->editions = ORM::factory('Edition')->where('state', '=', 1)->order_by('edition', 'ASC')->find_all();
     $twig->sources = ORM::factory('Source')->where('state', '=', 1)->order_by('source', 'ASC')->find_all();
     $twig->genres = ORM::factory('Genre')->where('state', '=', 1)->order_by('genre', 'ASC')->find_all();
     $twig->platforms = ORM::factory('Platform')->where('state', '=', 1)->order_by('platform', 'ASC')->find_all();
     $twig->developers = ORM::factory('Game')->where('state', '=', 1)->order_by('developer', 'ASC')->group_by('developer')->find_all();
     $twig->publishers = ORM::factory('Game')->where('state', '=', 1)->order_by('publisher', 'ASC')->group_by('publisher')->find_all();
     $this->response->body($twig);
 }
Example #20
0
 public function before()
 {
     parent::before();
     $controller = $this->request->controller();
     $action = $this->request->action();
     $this->template = Twig::factory(strtolower($controller . '/' . $action));
     if ($this->auto_render === true) {
         /** @var Twig $engine */
         $engine = $this->engine;
         $engine::set_global('app', array('request' => $this->request, 'host_name' => $_SERVER['HTTP_HOST']));
         $engine::bind_global('styles', $this->_styles);
         $engine::bind_global('scripts', $this->_scripts);
     }
 }
 public function index()
 {
     /**
      * these are the basic values passed to Twig
      */
     $data = ["dir" => Config::get('DIRS'), "pageTitle" => 'Index Page', "feedback" => FlashAlert::renderFeedbackMessages()];
     /**
      * Static function to call Twig page
      */
     Twig::render('index/index', $data);
     /**
      * Or from the Controller method
      */
     $this->twig('index/index', $data);
 }
Example #22
0
File: GUI.php Project: XaBerr/JUICE
 protected function parsingFile($_file, $_type = "html")
 {
     switch ($_type) {
         case 'pug':
         case 'jade':
             $pug = new Pug();
             $page = $pug->drawFile($_file);
             break;
         case "md":
         case "markdown":
         case "parsedown":
             $Parsedown = new Parsedown();
             $page = $Parsedown->drawFile($_file);
             break;
         case 'twig':
             $twig = new Twig();
             $page = $twig->drawFile($_file);
             break;
         default:
             $page = file_get_contents($_file);
             break;
     }
     return $page;
 }
Example #23
0
File: view.php Project: jonlb/JxCMS
 public static function factory($controller, $format = null)
 {
     if (is_a($controller, 'Controller_Site')) {
         $format = $controller->request->param('format', 'html');
         switch ($format) {
             case 'html':
                 $template;
                 if (empty($controller->template)) {
                     // Generate a template name if one wasn't set.
                     $template = str_replace('_', '/', $controller->request->controller) . '/' . $controller->request->action;
                 } else {
                     $template = $controller->template;
                 }
                 if ($controller->auto_render) {
                     // Load the twig template.
                     $template = Twig::factory($template, 'default');
                     // Return the twig environment
                     $controller->environment = $template->environment();
                 }
                 return $template;
                 break;
             case 'json':
                 return new Jx_View_Json($controller->request);
                 break;
             case 'rss':
                 break;
             case 'xml':
                 break;
         }
     } elseif (is_string($controller)) {
         if (is_null($format)) {
             $format = 'html';
         }
         switch ($format) {
             case 'html':
                 $template = $controller;
                 return Twig::factory($template, 'default');
                 break;
             case 'json':
                 if (is_a($controller, 'Request')) {
                     return new Jx_View_Json($controller);
                 } else {
                     return new Jx_View_Json();
                 }
                 break;
         }
     }
 }
 public function action_index()
 {
     $twig = Twig::factory('Admin/sources');
     // Handling POST data from all forms on the page
     if ($this->request->method() == 'POST') {
         $post = $this->request->post();
         $twig->post = $post;
         if ($post['type'] == 'addSource') {
             $query = ORM::factory('Source')->where('source', '=', $post['source'])->where('state', '=', 1)->find();
             if ($query->loaded()) {
                 $twig->errorAdd = array('source' => 'Source name is already in use.');
             } else {
                 try {
                     $source = ORM::factory('Source');
                     $user = Auth::instance()->get_user();
                     $source->source = $post['source'];
                     $source->user_id = $user->id;
                     $source->save();
                     $twig->post = null;
                 } catch (ORM_Validation_Exception $e) {
                     $errors = $e->errors('models');
                     $twig->errorAdd = $errors;
                 }
             }
         }
         if ($post['type'] == 'deleteSource') {
             if (!isset($post['source'])) {
                 $post['source'] = null;
             }
             $source = ORM::factory('Source', $post['source']);
             if ($source->loaded()) {
                 $user = Auth::instance()->get_user();
                 $source->state = 2;
                 $source->user_id = $user->id;
                 $source->save();
                 $twig->post = null;
             } else {
                 $twig->errorDelete = 'Please select source to delete.';
             }
         }
     }
     // Getting data from the database
     $sources = ORM::factory('Source')->where('state', '=', 1)->order_by('id', 'ASC')->find_all();
     $twig->sources = $sources;
     $this->response->body($twig);
 }
 public function action_index()
 {
     $twig = Twig::factory('Admin/settings');
     if ($this->request->method() == 'POST') {
         $post = $this->request->post();
         $twig->post = $post;
         if ($post['type'] == 'registration') {
             $setting = ORM::factory('Setting', 1);
             if ($setting->loaded()) {
                 $user = Auth::instance()->get_user();
                 $setting->registration_status = $post['registrationStatus'];
                 $setting->user_id = $user->id;
                 $setting->save();
                 $twig->successRegistration = 'Settings have been saved.';
             }
         }
     }
     $twig->settings = ORM::factory('Setting')->where('id', '=', 1)->find();
     $this->response->body($twig);
 }
Example #26
0
 /**
  * @covers \phpDocumentor\Plugin\Scrybe\Template\Twig::getAssets
  */
 public function testGetAssets()
 {
     $fixture = new Twig('');
     $assets = $fixture->getAssets();
     $this->assertInternalType('array', $assets);
     $this->assertGreaterThan(0, count($assets));
     $this->assertInstanceOf('SplFileInfo', current($assets));
     $this->assertStringStartsWith($fixture->getPath(), key($assets));
     foreach (array_keys($assets) as $filename) {
         $this->assertStringEndsNotWith('.twig', $filename);
     }
 }
Example #27
0
 * Twig Module
 *
 * @author      Iván Molina Pavana <*****@*****.**>
 * @copyright   Copyright (c) 2015
 * @version     1.0.0
 */
// --------------------------------------------------------------------------------
/**
 * Initialize Twig Module
 *
 * @filesource
 */
/*
 * ------------------------------------------------------------
 * Module Directory
 * ------------------------------------------------------------
 */
define('MODULE_TWIG_PATH', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
/*
 * ------------------------------------------------------------
 * Register a Twig auto loader
 * ------------------------------------------------------------
 */
spl_autoload_register(array('Twig_Loader', 'auto_load'));
/*
 * ------------------------------------------------------------
 * Initialize module
 * ------------------------------------------------------------
 */
Twig::init();
Example #28
0
<?php

require_once "loginheader.php";
require_once "classes/twig.class.php";
require_once "classes/dogstore.class.php";
$dogstore = new DogStore($database);
//Om användaren har sökt på någoting
if (isset($_POST['breed'])) {
    // Anropa sökfunktionen med de parametrar användarens fyllt i på formuläret
    $result = $dogstore->SearchDogs($_POST['breed'], $_POST['country'], $_POST['city'], $_POST['gender']);
    // Skicka med en lista på hundar till twig och visa resultatsidan
    $page = new Twig(['result' => $result]);
    echo $page->render('searchresult.html');
} else {
    $page = new Twig(['dogstore' => $dogstore]);
    echo $page->render('buydog.html');
}
?>

Example #29
0
    if (isset($_GET['mode']) && $_SESSION['user']->GetUserId() == $owner->GetUserId()) {
        // I twig formuläret tittar vi på 'mode' för att se om vi ska visa redigeringsformuläret eller bara visa uppgifterna som en lista
        if ($_GET['mode'] == "edit") {
            $page->addData(['mode' => $owner]);
            $breeds = $dogstore->GetBreeds();
            $page->addData(['breeds' => $breeds]);
        } elseif ($_GET['mode'] == "delete") {
            $dog->DeleteDog();
            header("Location: dogprofile.php");
        } elseif ($_GET['mode'] == "deleteprofileimage") {
            $dog->DeleteProfileImage();
            header("Location: dogprofile.php?id=" . $dog->GetDogId() . "&mode=edit");
        }
    }
    // Visa profilsidan
    echo $page->render('dogprofile.html');
} else {
    // Hämta hundar i en array baserat på användarens(ägarens) id.
    $dogs = $dogstore->GetDogsByOwner($_SESSION['user']);
    // Skicka med en lista (en array) på hundobjekt till twig.
    $page = new Twig(['dogs' => $dogs]);
    // Hämta alla raser
    $breeds = $dogstore->GetBreeds();
    // Skicka med en lista (en key/value array där key är rasens id och value rasens namn) på raser till twig
    $page->addData(['breeds' => $breeds]);
    // Hämta de 6 senaste medlemmarna
    $latestmembers = $dogstore->GetLatestMembers(6);
    // Skicka in medlemmarna till twig
    $page->addData(['latestmembers' => $latestmembers]);
    echo $page->render('createdogprofile.html');
}
Example #30
0
<?php

$app->get('/managers/bets/', function () use($app) {
    // AUTHENTICATION FIRST
    if (!Sentry::check()) {
        // User is not logged in, or is not activated
        $app->flash('error', 'User is not logged in, or is not activated');
        $app->redirect('/managers/login');
    }
    $user = Sentry::getUser();
    if (!$user->isSuperUser()) {
        $app->flash('error', 'Your are not administrator.');
        $app->redirect('/managers/login');
    }
    $twig = Twig::get();
    $template = $twig->loadTemplate('managers-bets.html');
    echo $template->render(array());
});
$app->get('/managers/bets/request/', function () use($app) {
    // AUTHENTICATION FIRST
    if (!Sentry::check()) {
        // User is not logged in, or is not activated
        $app->status(401);
    }
    $user = Sentry::getUser();
    if (!$user->isSuperUser()) {
        $app->status(401);
    }
    $data = array();
    $counter = 0;
    $draws = Bet::orderBy('id', 'desc')->get()->toArray();