示例#1
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();
示例#2
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);
     }
 }
示例#3
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;
 }
示例#4
0
文件: services.php 项目: bafs/parvula
    $view->registerFunction('dateFormat', function (DateTime $date) use($config) {
        return $date->format($config->get('dateFormat'));
    });
    // System date format
    $view->registerFunction('pageDateFormat', function (Parvula\Models\Page $page) use($config) {
        return $page->getDateTime()->format($config->get('dateFormat'));
    });
    // Excerpt strings
    $view->registerFunction('excerpt', function ($text, $length = 275) {
        $text = strip_tags($text);
        $excerpt = substr($text, 0, $length);
        if ($excerpt !== $text) {
            $lastDot = strrpos($excerpt, '. ');
            if ($lastDot === false) {
                $lastDot = strrpos($excerpt, ' ');
            }
            $excerpt = substr($excerpt, 0, $lastDot);
        }
        return $excerpt;
    });
    // Register folder begining with a '_' as Plates folder
    // (Plates will resolve `this->fetch('myFolder::file')` as `_myFolder/file.html`)
    $filter = function ($current) {
        // Must be a dir begining with _
        return $current->isDir() && $current->getFilename()[0] === '_';
    };
    (new Files($path))->index('', function (\SplFileInfo $file, $dir) use($path, $view) {
        $view->addFolder(substr($file->getFileName(), 1), $path . $dir . '/' . $file->getFileName());
    }, $filter);
    return $view;
};
示例#5
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);
示例#6
0
<?php

class Template
{
    private $_Templates;
    public function __construct(League\Plates\Engine $_Templates)
    {
        $this->_Templates = $_Templates;
    }
    public function TemplateRender($template)
    {
        return $this->_Templates->render($template);
    }
}
$Templates = new League\Plates\Engine('Controllers');
$Templates->addFolder('Controllers', 'Controllers');
$Templates->addFolder('Views', 'Views');
/* 1. Frontend templates */
/* no frontend at the moment */
/* 2. Backend templates */
$Templates->addFolder('Office_Controllers', 'Controllers/Office');
$Templates->addFolder('Office_Views', 'Views/Office');
$Templates->setFileExtension('php');