* #84 test data dump from CREST login * updated "credits" dialog (Google+ link) fixed login form layout * updated Cortex Data-Mapper * - #84 CREST Login (WIP) - New CREST controller - Database restructuring - improved type-casting for some controller functions - New login process - Fixed some bugs during the setup process (/setup root) - Added CREST request caching by response headers * pathfinder-84 [Feature Request] CREST Pilot Tracking, many smaller Bugfixes * pathfinder-84 [Feature Request] added develop JS files * closed #121 fixed wormhole signature type caching * closed #120 removed map-loading animation for larger maps (same behaviour as IGB) * closed #119 fixed wormhole signature id count * closed #114 Added check for already existing system when adding a new one. (fixed PDO 'duplicate entry' error) * closed #112 fixed DataTables error for missing "status" data (signature table) * closed #111 fixed convertDataToUTC(); client side date transformation * closed #109 fixed system TrueSec rounding * closed #103 fixed system updated timestamp in getData() * fixed CSS class for secStatus in Routes module * closed #121 fixed wormhole signature type caching * changed dateTime format from German to US format fixed some minor bugs in signatureTable module * closed #81 fixed "signature type" overwriting by "signature reader" update * closed #106 added new signature_types form C5/6 wormholes (gas/ore) * closed #129 fixed parameter hinting * closed #131 new "route search" algorithm, added current map systems to live search, added refresh/update functionality for each found route, added bulk route refresh function, added "meta map" route search (search on multiple maps), added route "filters" (restrict search on "stargates", "wormholes", "jumpbridges"), added route "filter" for wormholes (reduced/critical wormholes) closed #89 fixed "loop connections" on same system #84 added error messages for "invalid" CREST "Client ID" added "bootboxjs" (customized styled checkboxes/radio buttons) CSS only "Font Awesome" version upgrade 4.4.0 -> 4.61 "Bootbox.js" version upgrade 4.3.0 -> 4.4.0 fixed "system dialog" (added responsive layout) * closed #134 fixed db column type DT_INT (8 bytes) to DT_BIGINT * closed #138 added new cookie based login * closed #137 fixed javascript errors on trying to establish an "invalid" connection * - #84, #138 improved "character selection" on login page (expired cookies are deleted, character panel layout improvements) - added new "Server info panel" to the login page - added new cronjob to delete expired cookie authentication data * #138 enables character switching between characters which have same user * - PHP Framework upgrade 3.5.0 -> 3.5.1 (fixes some issues with CREST cURL caching, and SESSION management) - #138 added "cookie logout" to "logout" menu entry * - updated "feature page" with new feature descriptions and label - added some new images to the "feature gallery" - removed "beta" status from "magnetizing" feature on map menu - hide "server status" panel on "mobile" breakpoint * - #138 clear character authentication data on sold characters * closed #142 added custom "onsuspect()" session handler * #142 do not log suspect if no file is defined in pathfinder.ini * #142 added NullSec Data/Relic sites to C1/2/3 wormholes as signature option * #144 fixed "Character not found" warning * #144 fixed "Character not found" warning * closed #144 fixed broken routes panel in IGB * updated README.md for upcoming release * #147 response header validation * #149 changed comment for 'BASE' framework var * fixed map import * - added minimal SDE dump (EVE Online: Citadel) - #147 improved CREST API error logging (WIP) - improved SSO controller (removed access_token from public endpoints) * closed #154 added alliance maps to CREST API * - updated Gulp build dependencies - increased CREST timeout from 3s -> 4s - added "Accept" Headers for some CREST endpoints * cloased #147 * - closed #153 added character verification check for getAll(); Signatures Ajax endpoint * - updated README.md (added Slack developer chat information) * Bugfix frig holes (#159) * added missing frigate wormholes and fixed Q003 destination in shattered wormholes * changed C7 to 0.0 for Q003 * - fixed broken "graph" data for system * added a "failover" system for bad crest requests (HTTP status 5xx,.. ) * Red Gaint => Red Giant (#161) * closed #163 added CREST endpoint support for "waypoints" * fixed typo * closed #160 fixed tooltip container * - added new features to login page * closes #154 added alliance map support * fixed XML path for cronjobs * fixed a bug with inactive "private" maps * closes #175 added alternative environment configuration * - v1.0.0 build
351 lines
8.4 KiB
PHP
351 lines
8.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
|
|
Copyright (c) 2009-2015 F3::Factory/Bong Cosca, All rights reserved.
|
|
|
|
This file is part of the Fat-Free Framework (http://fatfreeframework.com).
|
|
|
|
This 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 3 of the License, or later.
|
|
|
|
Fat-Free Framework 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 Fat-Free Framework. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
//! XML-style template engine
|
|
class Template extends Preview {
|
|
|
|
//@{ Error messages
|
|
const
|
|
E_Method='Call to undefined method %s()';
|
|
//@}
|
|
|
|
protected
|
|
//! Template tags
|
|
$tags,
|
|
//! Custom tag handlers
|
|
$custom=array();
|
|
|
|
/**
|
|
* Template -set- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _set(array $node) {
|
|
$out='';
|
|
foreach ($node['@attrib'] as $key=>$val)
|
|
$out.='$'.$key.'='.
|
|
(preg_match('/\{\{(.+?)\}\}/',$val)?
|
|
$this->token($val):
|
|
Base::instance()->stringify($val)).'; ';
|
|
return '<?php '.$out.'?>';
|
|
}
|
|
|
|
/**
|
|
* Template -include- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _include(array $node) {
|
|
$attrib=$node['@attrib'];
|
|
$hive=isset($attrib['with']) &&
|
|
($attrib['with']=$this->token($attrib['with'])) &&
|
|
preg_match_all('/(\w+)\h*=\h*(.+?)(?=,|$)/',
|
|
$attrib['with'],$pairs,PREG_SET_ORDER)?
|
|
'array('.implode(',',
|
|
array_map(function($pair) {
|
|
return '\''.$pair[1].'\'=>'.
|
|
(preg_match('/^\'.*\'$/',$pair[2]) ||
|
|
preg_match('/\$/',$pair[2])?
|
|
$pair[2]:
|
|
\Base::instance()->stringify($pair[2]));
|
|
},$pairs)).')+get_defined_vars()':
|
|
'get_defined_vars()';
|
|
$ttl=isset($attrib['ttl'])?(int)$attrib['ttl']:0;
|
|
return
|
|
'<?php '.(isset($attrib['if'])?
|
|
('if ('.$this->token($attrib['if']).') '):'').
|
|
('echo $this->render('.
|
|
(preg_match('/^\{\{(.+?)\}\}$/',$attrib['href'])?
|
|
$this->token($attrib['href']):
|
|
Base::instance()->stringify($attrib['href'])).','.
|
|
'$this->mime,'.$hive.','.$ttl.'); ?>');
|
|
}
|
|
|
|
/**
|
|
* Template -exclude- tag handler
|
|
* @return string
|
|
**/
|
|
protected function _exclude() {
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Template -ignore- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _ignore(array $node) {
|
|
return $node[0];
|
|
}
|
|
|
|
/**
|
|
* Template -loop- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _loop(array $node) {
|
|
$attrib=$node['@attrib'];
|
|
unset($node['@attrib']);
|
|
return
|
|
'<?php for ('.
|
|
$this->token($attrib['from']).';'.
|
|
$this->token($attrib['to']).';'.
|
|
$this->token($attrib['step']).'): ?>'.
|
|
$this->build($node).
|
|
'<?php endfor; ?>';
|
|
}
|
|
|
|
/**
|
|
* Template -repeat- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _repeat(array $node) {
|
|
$attrib=$node['@attrib'];
|
|
unset($node['@attrib']);
|
|
return
|
|
'<?php '.
|
|
(isset($attrib['counter'])?
|
|
(($ctr=$this->token($attrib['counter'])).'=0; '):'').
|
|
'foreach (('.
|
|
$this->token($attrib['group']).'?:array()) as '.
|
|
(isset($attrib['key'])?
|
|
($this->token($attrib['key']).'=>'):'').
|
|
$this->token($attrib['value']).'):'.
|
|
(isset($ctr)?(' '.$ctr.'++;'):'').' ?>'.
|
|
$this->build($node).
|
|
'<?php endforeach; ?>';
|
|
}
|
|
|
|
/**
|
|
* Template -check- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _check(array $node) {
|
|
$attrib=$node['@attrib'];
|
|
unset($node['@attrib']);
|
|
// Grab <true> and <false> blocks
|
|
foreach ($node as $pos=>$block)
|
|
if (isset($block['true']))
|
|
$true=array($pos,$block);
|
|
elseif (isset($block['false']))
|
|
$false=array($pos,$block);
|
|
if (isset($true,$false) && $true[0]>$false[0])
|
|
// Reverse <true> and <false> blocks
|
|
list($node[$true[0]],$node[$false[0]])=array($false[1],$true[1]);
|
|
return
|
|
'<?php if ('.$this->token($attrib['if']).'): ?>'.
|
|
$this->build($node).
|
|
'<?php endif; ?>';
|
|
}
|
|
|
|
/**
|
|
* Template -true- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _true(array $node) {
|
|
return $this->build($node);
|
|
}
|
|
|
|
/**
|
|
* Template -false- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _false(array $node) {
|
|
return '<?php else: ?>'.$this->build($node);
|
|
}
|
|
|
|
/**
|
|
* Template -switch- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _switch(array $node) {
|
|
$attrib=$node['@attrib'];
|
|
unset($node['@attrib']);
|
|
foreach ($node as $pos=>$block)
|
|
if (is_string($block) && !preg_replace('/\s+/','',$block))
|
|
unset($node[$pos]);
|
|
return
|
|
'<?php switch ('.$this->token($attrib['expr']).'): ?>'.
|
|
$this->build($node).
|
|
'<?php endswitch; ?>';
|
|
}
|
|
|
|
/**
|
|
* Template -case- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _case(array $node) {
|
|
$attrib=$node['@attrib'];
|
|
unset($node['@attrib']);
|
|
return
|
|
'<?php case '.(preg_match('/\{\{(.+?)\}\}/',$attrib['value'])?
|
|
$this->token($attrib['value']):
|
|
Base::instance()->stringify($attrib['value'])).': ?>'.
|
|
$this->build($node).
|
|
'<?php '.(isset($attrib['break'])?
|
|
'if ('.$this->token($attrib['break']).') ':'').
|
|
'break; ?>';
|
|
}
|
|
|
|
/**
|
|
* Template -default- tag handler
|
|
* @return string
|
|
* @param $node array
|
|
**/
|
|
protected function _default(array $node) {
|
|
return
|
|
'<?php default: ?>'.
|
|
$this->build($node).
|
|
'<?php break; ?>';
|
|
}
|
|
|
|
/**
|
|
* Assemble markup
|
|
* @return string
|
|
* @param $node array|string
|
|
**/
|
|
protected function build($node) {
|
|
if (is_string($node))
|
|
return parent::build($node);
|
|
$out='';
|
|
foreach ($node as $key=>$val)
|
|
$out.=is_int($key)?$this->build($val):$this->{'_'.$key}($val);
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Extend template with custom tag
|
|
* @return NULL
|
|
* @param $tag string
|
|
* @param $func callback
|
|
**/
|
|
function extend($tag,$func) {
|
|
$this->tags.='|'.$tag;
|
|
$this->custom['_'.$tag]=$func;
|
|
}
|
|
|
|
/**
|
|
* Call custom tag handler
|
|
* @return string|FALSE
|
|
* @param $func callback
|
|
* @param $args array
|
|
**/
|
|
function __call($func,array $args) {
|
|
if ($func[0]=='_')
|
|
return call_user_func_array($this->custom[$func],$args);
|
|
if (method_exists($this,$func))
|
|
return call_user_func_array(array($this,$func),$args);
|
|
user_error(sprintf(self::E_Method,$func),E_USER_ERROR);
|
|
}
|
|
|
|
/**
|
|
* Parse string for template directives and tokens
|
|
* @return string|array
|
|
* @param $text string
|
|
**/
|
|
function parse($text) {
|
|
// Build tree structure
|
|
for ($ptr=0,$w=5,$len=strlen($text),$tree=array(),$tmp='';$ptr<$len;)
|
|
if (preg_match('/^(.{0,'.$w.'}?)<(\/?)(?:F3:)?'.
|
|
'('.$this->tags.')\b((?:\h+[\w-]+'.
|
|
'(?:\h*=\h*(?:"(?:.*?)"|\'(?:.*?)\'))?|'.
|
|
'\h*\{\{.+?\}\})*)\h*(\/?)>/is',
|
|
substr($text,$ptr),$match)) {
|
|
if (strlen($tmp)||$match[1])
|
|
$tree[]=$tmp.$match[1];
|
|
// Element node
|
|
if ($match[2]) {
|
|
// Find matching start tag
|
|
$stack=array();
|
|
for($i=count($tree)-1;$i>=0;$i--) {
|
|
$item = $tree[$i];
|
|
if (is_array($item) && array_key_exists($match[3],$item)
|
|
&& !isset($item[$match[3]][0])) {
|
|
// Start tag found
|
|
$tree[$i][$match[3]]+=array_reverse($stack);
|
|
$tree=array_slice($tree,0,$i+1);
|
|
break;
|
|
} else $stack[]=$item;
|
|
}
|
|
}
|
|
else {
|
|
// Start tag
|
|
$node=&$tree[][$match[3]];
|
|
$node=array();
|
|
if ($match[4]) {
|
|
// Process attributes
|
|
preg_match_all(
|
|
'/(?:\b([\w-]+)\h*'.
|
|
'(?:=\h*(?:"(.*?)"|\'(.*?)\'))?|'.
|
|
'(\{\{.+?\}\}))/s',
|
|
$match[4],$attr,PREG_SET_ORDER);
|
|
foreach ($attr as $kv)
|
|
if (isset($kv[4]))
|
|
$node['@attrib'][]=$kv[4];
|
|
else
|
|
$node['@attrib'][$kv[1]]=
|
|
(isset($kv[2]) && $kv[2]!==''?
|
|
$kv[2]:
|
|
(isset($kv[3]) && $kv[3]!==''?
|
|
$kv[3]:NULL));
|
|
}
|
|
}
|
|
$tmp='';
|
|
$ptr+=strlen($match[0]);
|
|
$w=5;
|
|
}
|
|
else {
|
|
// Text node
|
|
$tmp.=substr($text,$ptr,$w);
|
|
$ptr+=$w;
|
|
if ($w<50)
|
|
$w++;
|
|
}
|
|
if (strlen($tmp))
|
|
// Append trailing text
|
|
$tree[]=$tmp;
|
|
// Break references
|
|
unset($node);
|
|
return $tree;
|
|
}
|
|
|
|
/**
|
|
* Class constructor
|
|
* return object
|
|
**/
|
|
function __construct() {
|
|
$ref=new ReflectionClass(__CLASS__);
|
|
$this->tags='';
|
|
foreach ($ref->getmethods() as $method)
|
|
if (preg_match('/^_(?=[[:alpha:]])/',$method->name))
|
|
$this->tags.=(strlen($this->tags)?'|':'').
|
|
substr($method->name,1);
|
|
}
|
|
|
|
}
|