First commit, version 0.1 beta base nibiru framework

This commit is contained in:
Stephan Kasdorf
2017-06-16 12:21:19 +02:00
parent 7d475ceb6b
commit 4bfe207b78
556 changed files with 113905 additions and 26 deletions

46
LICENSE
View File

@@ -1,29 +1,29 @@
BSD 3-Clause License BSD 4 License
Copyright (c) 2017, alllinux Copyright (c) 2016/2017, Stephan Kasdorf
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by the alllinux.de.
4. Neither the name of the alllinux.de nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
* Redistributions of source code must retain the above copyright notice, this THIS SOFTWARE IS PROVIDED BY Stephan Kasdorf ''AS IS'' AND ANY
list of conditions and the following disclaimer. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* Redistributions in binary form must reproduce the above copyright notice, DISCLAIMED. IN NO EVENT SHALL Stephan Kasdorf BE LIABLE FOR ANY
this list of conditions and the following disclaimer in the documentation DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
and/or other materials provided with the distribution. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* Neither the name of the copyright holder nor the names of its ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
contributors may be used to endorse or promote products derived from (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
this software without specific prior written permission. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,7 +1,46 @@
# Nibiru # Nibiru
#####Version 0.1 beta
## Introduction
Nibiru is a rapid prototyping framework written in PHP and based on the MVC design pattern. Now one may say that writing another framework is not cool because there are so many, such as Symphony, ZendFramework ( where as I have prefered the first version of that framework ), Laravel, etc.. But let's be honest they are complete overkill for smaller projects and are not fit to quick start your "own" development. <div style="word-spacing: 2px; letter-spacing: 0.1px; font-size: 12px; margin-bottom: 15px;">Nibiru is a rapid prototyping framework written in PHP and based on the MVC design pattern. Now one may say that writing <br>
another framework is not cool because there are so many, such as Symphony, ZendFramework ( where as I have prefered the<br>
first version of that framework ), Laravel, etc.. But let's be honest they are complete overkill for smaller projects and<br>
are not fit to quick start your "own" development.</div>
That is why I have started my own little framework and am happy to provide the first version of Nibiru, in the version 0.1, there is still a lot of work to be done in refactoring the core features for the View, Controller and the main Template Engine Implementation. <div style="word-spacing: 2px; letter-spacing: 0.1px; font-size: 12px; margin-bottom: 15px;">That is why I have started my own little framework and am happy to provide the first version of Nibiru, in the version 0.1,<br>
there is still a lot of work to be done in refactoring the core features for the View, Controller and the main Template<br>
Engine Implementation.</div>
But for now the start is done. And always remember, have fun! <div style="word-spacing: 2px; letter-spacing: 0.1px; font-size: 12px; margin-bottom: 15px;">
<h1>Currently supported features</h1><br>
<ul>
<li>Controller, Model, View ( already tested )</li>
<li>Smarty template engine ( already tested )</li>
<li>Dwoo template engine ( untested )</li>
<li>Twig template engine ( untested )</li>
<li>PDO adapter to the MySQL database</li>
<ol>
<li>read datasets from a complete table</li>
<li>read datasets by selection from a table</li>
<li>write datasets by array into a table</li>
</ol>
<li>Bootstrap template of a dashboard</li>
<li>Example page, on how to setup a View and Controller</li>
<li>Example page, on how to setup a navigation with a json file</li>
<li>Debugbar access through the configuration, sould be set to true in order to use it</li>
</ul>
<h1>In progress for the next version</h1>
<ul>
<li>framework documentation</li>
<li>class documentation</li>
<li>soap interface to a given SOAP server</li>
<li>Dwoo tempalte eninge tests</li>
<li>Twig tempalte eninge tests</li>
<li>Improved routing</li>
</ul>
</div>
<div style="word-spacing: 2px; letter-spacing: 0.1px; font-size: 15px; margin-bottom: 15px;">The start is done, have success with PHP prototyping, and always remember to have fun!</div>
######Author: Stephan Kasdorf<br><br>

View File

@@ -0,0 +1,6 @@
{
"navigation" :
{
"Home": { "link": "/", "tooltip": "Home", "icon": "icon-home" }
}
}

View File

@@ -0,0 +1,27 @@
[SETTINGS]
debugbar = true
navigation = "navigation.json"
background.img[] = "public/img/nibiru3.jpg"
smarty[cache] = "application/view/cache/"
smarty[templates] = "application/view/templates/"
smarty[templates_c] = "application/view/templates_c/"
smarty[config_dir] = "application/view/configs/"
smarty[class_file] = "core/l/Smarty.class.php"
smarty.css[] = "public/css/roboto.css"
smarty.css[] = "public/css/toolkit-inverse.css"
smarty.css[] = "public/css/application.css"
smarty.css[] = "public/css/jquery-ui.css"
smarty.css[] = "public/css/nibiru-debug.css"
smarty.css[] = "public/css/tiamat-form.css"
smarty.js[] = "public/js/jquery.min.js"
smarty.js[] = "public/js/tether.min.js"
smarty.js[] = "public/js/jquery-ui.js"
smarty.js[] = "public/js/chart.js"
smarty.js[] = "public/js/tablesorter.min.js"
smarty.js[] = "public/js/toolkit.js"
smarty.js[] = "public/js/application.js"
smarty.js[] = "public/js/nibiru-debug.js"
[ROUTING]
route[index] = "/"
route[example] = "/example"

View File

@@ -0,0 +1,43 @@
[ENGINE]
;;name = "Dwoo"
name = "Smarty"
;;name = "Twig"
cache = "application/view/cache/"
templates = "application/view/templates/"
templates_c = "application/view/templates_c/"
config_dir = "application/view/configs/"
class_file = "core/l/Smarty/Smarty.class.php"
debugbar = false
[SETTINGS]
navigation = "navigation.json"
background.img[] = "public/img/nibiru3.jpg"
smarty.css[] = "public/css/v3/roboto.css"
smarty.css[] = "public/css/v3/toolkit-inverse.css"
smarty.css[] = "public/css/v3/application.css"
smarty.css[] = "public/css/v3/jquery-ui.css"
smarty.css[] = "public/css/v3/nibiru-debug.css"
smarty.css[] = "public/css/v3/tiamat-form.css"
smarty.js[] = "public/js/v3/jquery.min.js"
smarty.js[] = "public/js/v3/tether.min.js"
smarty.js[] = "public/js/v3/jquery-ui.js"
smarty.js[] = "public/js/v3/chart.js"
smarty.js[] = "public/js/v3/tablesorter.min.js"
smarty.js[] = "public/js/v3/toolkit.js"
smarty.js[] = "public/js/v3/application.js"
smarty.js[] = "public/js/v3/nibiru-debug.js"
[ROUTING]
route[index] = "/"
route[example] = "/example"
[DATABASE]
username = "YOURUSER"
password = "YOURPASSWORD"
hostname = "SERVERHOST"
basename = "DATABASENAME"
driver = "mysql"
port = "3306"
[SECURITY]
password_hash = "YOURPWHASH"

View File

@@ -0,0 +1,132 @@
{if $debuging==true}
<script>
$( function() {
$( "#tabs" ).tabs();
} );
</script>
<div id="nibiru-bar-open" class="closed">
<span class="nibiru-bar-logo"></span>
<p>{$ndbinfo}</p>
</div>
<div id="nibiru-debug" class="down">
<div id="tabs">
<ul>
<li><a href="#tabs-1">$_POST</a></li>
<li><a href="#tabs-2">$_GET</a></li>
<li><a href="#tabs-3">$_REQUEST</a></li>
<li><a href="#tabs-4">$_SERVER</a></li>
<li><a href="#tabs-5">$_ENV</a></li>
<li><a href="#tabs-6">$_FILES</a></li>
<li><a href="#tabs-7">$_COOKIE</a></li>
<li><a href="#tabs-8">$_SESSION</a></li>
<li><a href="#tabs-9">$GLOBALS</a></li>
<li><a href="#tabs-10">SMARTY Engine</a></li>
<li><a href="#tabs-11">Messages</a></li>
</ul>
{assign var="message" value="ERROR: no message defined!"}
<div id="tabs-1">
<p>
<!-- Smarty $_POST output -->
{if isset($ndbpost)}
{$ndbpost}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-2">
<p>
<!-- Smarty $_GET output -->
{if isset($ndbget)}
{$ndbget}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-3">
<p>
<!-- Smarty $_REQUEST output -->
{if isset($ndbrequest)}
{$ndbrequest}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-4">
<p>
<!-- Smarty $_SERVER output -->
{if isset($ndbserver)}
{$ndbserver}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-5">
<p>
<!-- Smarty $_ENV output -->
{if isset($ndbenv)}
{$ndbenv}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-6">
<p>
<!-- Smarty $_FILES output -->
{if isset($ndbfiles)}
{$ndbfiles}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-7">
<p>
<!-- Smarty $_COOKIE output -->
{if isset($ndbcookie)}
{$ndbcookie}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-8">
<p>
<!-- Smarty $_SESSION output -->
{if isset($ndbsession)}
{$ndbsession}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-9">
<p>
<!-- Smarty $GLOBALS output -->
{if isset($ndbglobals)}
{$ndbglobals}
{else}
{$message}
{/if}
</p>
</div>
<div id="tabs-10">
{debug}
</div>
<div id="tabs-11">
<p>
<!-- Smarty $raw output -->
{if isset($ndbraw_output)}
{$ndbraw_output}
{else}
{$message}
{/if}
</p>
</div>
</div>
</div>
{/if}

View File

@@ -0,0 +1,300 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<title>
{$title}
</title>
{foreach item=style from=$css}
<link href="{$style}" rel="stylesheet">
{/foreach}
<style>
/* note: this is a hack for ios iframe for bootstrap themes shopify page */
/* this chunk of css is not part of the toolkit :) */
body {
width: 1px;
min-width: 100%;
*width: 100%;
}
</style>
</head>
<body>
<div class="container">
<div class="with-iconav">
{include file="navigation.tpl"}
</div>
<div class="col-sm-12 content">
<div class="dashhead">
<div class="dashhead-titles">
<h6 class="dashhead-subtitle">Dashboards</h6>
<h2 class="dashhead-title">Order history</h2>
</div>
<div class="btn-toolbar dashhead-toolbar">
<div class="btn-toolbar-item input-with-icon">
<input type="text" value="01/01/15 - 01/08/15" class="form-control" data-provide="datepicker">
<span class="icon icon-calendar"></span>
</div>
</div>
</div>
<div class="flextable table-actions">
<div class="flextable-item flextable-primary">
<div class="btn-toolbar-item input-with-icon">
<input type="text" class="form-control input-block" placeholder="Search orders">
<span class="icon icon-magnifying-glass"></span>
</div>
</div>
<div class="flextable-item">
<div class="btn-group">
<button type="button" class="btn btn-primary-outline">
<span class="icon icon-pencil"></span>
</button>
<button type="button" class="btn btn-primary-outline">
<span class="icon icon-erase"></span>
</button>
</div>
</div>
</div>
<div class="table-full">
<div class="table-responsive">
<table class="table" data-sort="table">
<thead>
<tr>
<th><input type="checkbox" class="select-all" id="selectAll"></th>
<th>Order</th>
<th>Customer name</th>
<th>Description</th>
<th>Date</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10001</a></td>
<td>First Last</td>
<td>Admin theme, marketing theme</td>
<td>01/01/2015</td>
<td>$200.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10002</a></td>
<td>Firstname Lastname</td>
<td>Admin theme</td>
<td>01/01/2015</td>
<td>$100.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10003</a></td>
<td>Name Another</td>
<td>Personal blog theme</td>
<td>01/01/2015</td>
<td>$100.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10004</a></td>
<td>One More</td>
<td>Marketing theme, personal blog theme, admin theme</td>
<td>01/01/2015</td>
<td>$300.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10005</a></td>
<td>Name Right Here</td>
<td>Personal blog theme, admin theme</td>
<td>01/02/2015</td>
<td>$200.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10006</a></td>
<td>First Last</td>
<td>Admin theme, marketing theme</td>
<td>01/01/2015</td>
<td>$200.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10007</a></td>
<td>Firstname Lastname</td>
<td>Admin theme</td>
<td>01/01/2015</td>
<td>$100.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10008</a></td>
<td>Name Another</td>
<td>Personal blog theme</td>
<td>01/01/2015</td>
<td>$100.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10009</a></td>
<td>One More</td>
<td>Marketing theme, personal blog theme, admin theme</td>
<td>01/01/2015</td>
<td>$300.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10010</a></td>
<td>Name Right Here</td>
<td>Personal blog theme, admin theme</td>
<td>01/02/2015</td>
<td>$200.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10011</a></td>
<td>First Last</td>
<td>Admin theme, marketing theme</td>
<td>01/01/2015</td>
<td>$200.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10012</a></td>
<td>Firstname Lastname</td>
<td>Admin theme</td>
<td>01/01/2015</td>
<td>$100.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10013</a></td>
<td>Name Another</td>
<td>Personal blog theme</td>
<td>01/01/2015</td>
<td>$100.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10014</a></td>
<td>One More</td>
<td>Marketing theme, personal blog theme, admin theme</td>
<td>01/01/2015</td>
<td>$300.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10015</a></td>
<td>Name Right Here</td>
<td>Personal blog theme, admin theme</td>
<td>01/02/2015</td>
<td>$200.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10016</a></td>
<td>First Last</td>
<td>Admin theme, marketing theme</td>
<td>01/01/2015</td>
<td>$200.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10017</a></td>
<td>Firstname Lastname</td>
<td>Admin theme</td>
<td>01/01/2015</td>
<td>$100.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10018</a></td>
<td>Name Another</td>
<td>Personal blog theme</td>
<td>01/01/2015</td>
<td>$100.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10019</a></td>
<td>One More</td>
<td>Marketing theme, personal blog theme, admin theme</td>
<td>01/01/2015</td>
<td>$300.00</td>
</tr>
<tr>
<td><input type="checkbox" class="select-row"></td>
<td><a href="#">#10020</a></td>
<td>Name Right Here</td>
<td>Personal blog theme, admin theme</td>
<td>01/02/2015</td>
<td>$200.00</td>
</tbody>
</table>
</div>
</div>
<div class="text-center">
<ul class="pagination">
<li>
<a href="#" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li class="active"><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</div>
</div>
</div>
<div id="docsModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Example modal</h4>
</div>
<div class="modal-body">
<p>You're looking at an example modal in the dashboard theme.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Cool, got it!</button>
</div>
</div>
</div>
</div>
{foreach item=script from=$js}
<script src="{$script}"></script>
{/foreach}
<script>
// execute/clear BS loaders for docs
$(function(){
while( window.BS&&window.BS.loader&&window.BS.loader.length )
{
(window.BS.loader.pop())()
}
})
</script>
{include file="debugbar.tpl"}
</body>
</html>

View File

@@ -0,0 +1,17 @@
<nav class="iconav">
<a class="iconav-brand" href="/">
<span class="icon icon-leaf iconav-brand-icon"></span>
</a>
<div class="iconav-slider">
<ul class="nav nav-pills iconav-nav">
{foreach $json as $naventry}
<li >
<a href="{$naventry.link}" title="{$naventry.tooltip}" data-toggle="tooltip" data-placement="right" data-container="body">
<span class="icon {$naventry.icon}"></span>
<small class="iconav-nav-label visible-xs-block">{$naventry.title}</small>
</a>
</li>
{/foreach}
</ul>
</div>
</nav>

96
core/c/auth.php Normal file
View File

@@ -0,0 +1,96 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 01.02.17
* Time - 17:20
* @author - alllinux.de GbR
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class Auth extends Controller implements IAuth
{
private static $_instance;
private $_password_salt = "";
private $_username = "";
private $_password = "";
protected function __construct()
{
parent::__construct();
$this->_setPasswordSalt();
}
public static function getInstance()
{
$className = get_called_class();
if( self::$_instance == null )
{
self::$_instance = new $className();
}
return self::$_instance;
}
public function auth( $username, $password )
{
// TODO: Implement auth($username, $password) method.
$this->_setPassword($password);
$this->_setUsername($username);
echo "<pre>";
print_r(pdo::query("SELECT DES_DECRYPT(user_pass, '".Config::getInstance()->getConfig()["SECURITY"]["password_hash"]."') FROM user;"));
echo "</pre>";
die();
}
/**
* @return string
*/
protected function getPasswordSalt()
{
return $this->_password_salt;
}
/**
* @param string $password_salt
*/
private function _setPasswordSalt( )
{
$this->_password_salt = $this->getConfig()[self::NIBIRU_SECURITY];
}
/**
* @return string
*/
protected function getUsername()
{
return $this->_username;
}
/**
* @param string $username
*/
private function _setUsername( $username )
{
$this->_username = $username;
}
/**
* @return string
*/
protected function getPassword()
{
return $this->_password;
}
/**
* @param string $password
*/
private function _setPassword( $password )
{
$this->_password = $password;
}
}

52
core/c/config.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 19:24
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class Config extends Settings
{
const STAGING_SYSTEM = "staging";
const PRODUCTION_SYSTEM = "production";
const DEVELOPMENT_SYSTEM = "development";
const CLI_SYSTEM = "cli";
private static $_env;
public static function getInstance()
{
self::setEnv();
parent::setConfig(self::getEnv());
return parent::getInstance();
}
/**
* @return mixed
*/
public static function getEnv()
{
return self::$_env;
}
/**
* @param mixed $env
*/
private static function setEnv( )
{
if(getenv("APPLICATION_ENV"))
{
self::$_env = getenv("APPLICATION_ENV");
}
else
{
self::$_env = self::CLI_SYSTEM;
}
}
}

128
core/c/controller.php Normal file
View File

@@ -0,0 +1,128 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 22:01
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class Controller
{
private static $_instance;
private $_config = array();
protected $_request = array();
protected $_get = array();
protected $_post = array();
private $_current = array();
private $_next = array();
protected function __construct()
{
$this->_setConfig(Config::getInstance()->getConfig());
}
public static function getInstance()
{
$className = get_called_class();
if( self::$_instance == null )
{
self::$_instance = new $className();
}
return self::$_instance;
}
/**
* @return array
*/
protected function getConfig()
{
return $this->_config;
}
/**
* @param array $config
*/
protected function _setConfig( $config )
{
$this->_config = $config;
}
/**
* @param $template
* @param $page
*/
public function action( $template, $page )
{
$this->_setCurrent( $this->getNext() );
$this->_setNext( $page );
$template->display( $this->getNext() );
}
public function varname( $template, $varname = array() )
{
if(is_array($varname))
{
$template->assign($varname);
}
}
/**
* @return array
*/
protected function getCurrent()
{
return $this->_current;
}
/**
* @param array $current
*/
private function _setCurrent( $current )
{
$this->_current = $current;
}
/**
* @return array
*/
protected function getNext()
{
return $this->_next;
}
/**
* @param array $next
*/
public function _setNext( $next )
{
$this->_next = $next;
}
/**
* @return array
*/
public function getPost()
{
return $_POST;
}
/**
* @return array
*/
public function getGet()
{
return $_GET;
}
/**
* @return array
*/
public function getRequest()
{
return $_REQUEST;
}
}

304
core/c/debug.php Normal file
View File

@@ -0,0 +1,304 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: stephan
* Date: 24.01.17
* Time: 12:31
*
*/
final class Debug
{
/**
* class wide constances
*/
use Messages;
/**
* @var debug variables currently only super globals
*
*/
private $_raw_output;
private $_request_data;
private $_server_data;
private $_post_data;
private $_get_data;
private $_files_data;
private $_cookie_data;
private $_session_data;
private $_env_data;
private $_globals_data;
public function __construct()
{
Controller::getInstance()->varname(View::getInstance()->getEngine(), array('ndbinfo' => Messages::msg_bottom_bar()));
$this->_setRequestData();
$this->_setPostData();
$this->_setGetData();
$this->_setCookieData();
$this->_setEnvData();
$this->_setGlobalsData();
$this->_setSessionData();
$this->_setFilesData();
$this->_setServerData();
}
/**
* Call this method to get singleton
* @return Debug
*/
public static function getInstance()
{
static $instance = null;
if ($instance === null)
{
$instance = new Debug();
}
return $instance;
}
public function toDebug( $data )
{
try {
$this->_setRawOutput( $data );
} catch(Exception $e)
{
throw new Exception("ERROR: No data for debugging handled!");
}
}
/**
* @return mixed
*/
protected function getRawOutput()
{
return $this->_raw_output;
}
/**
* @param mixed $raw_output
*/
private function _setRawOutput($raw_output=false)
{
if(sizeof($raw_output)>0)
{
$this->_raw_output = $raw_output;
}
else
{
$this->_raw_output = Messages::msg_raw_output();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbraw_output' => $this->getRawOutput()) );
}
/**
* @return mixed
*/
private function getGetData()
{
return $this->_get_data;
}
/**
* @param mixed $get_data
*/
private function _setGetData()
{
if(sizeof($_GET)>0)
{
$this->_get_data = '<pre>' . print_r($_GET, true) . '</pre>';
}
else
{
$this->_get_data = Messages::msg_get();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbget' => $this->getGetData()) );
}
/**
* @return mixed
*/
private function getFilesData()
{
return $this->_files_data;
}
/**
* @param mixed $files_data
*/
private function _setFilesData()
{
if(sizeof($_FILES)>0)
{
$this->_files_data = '<pre>' . print_r($_FILES, true) . '</pre>';
}
else
{
$this->_files_data = Messages::msg_files();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbfiles' => $this->getFilesData()) );
}
/**
* @return mixed
*/
private function getCookieData()
{
return $this->_cookie_data;
}
/**
* @param mixed $cookie_data
*/
private function _setCookieData()
{
if(sizeof($_COOKIE)>0)
{
$this->_cookie_data = '<pre>' . print_r($_COOKIE, true) . '</pre>';
}
else
{
$this->_cookie_data = Messages::msg_cookie();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbcookie' => $this->getCookieData()) );
}
/**
* @return mixed
*/
private function getSessionData()
{
return $this->_session_data;
}
/**
* @param mixed $session_data
*/
private function _setSessionData()
{
if(sizeof($_SESSION)>0)
{
$this->_session_data = '<pre>' . print_r($_SESSION, true) . '</pre>';
}
else
{
$this->_session_data = Messages::msg_cookie();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbsession' => $this->getSessionData()) );
}
/**
* @return mixed
*/
private function getEnvData()
{
return $this->_env_data;
}
/**
* @param mixed $env_data
*/
private function _setEnvData()
{
if(sizeof($_ENV)>0)
{
$this->_env_data = '<pre>' . print_r($_ENV, true) . '</pre>';
}
else
{
$this->_env_data = Messages::msg_env();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbenv' => $this->getEnvData()) );
}
/**
* @return mixed
*/
private function getGlobalsData()
{
return $this->_globals_data;
}
/**
* @param mixed $globals_data
*/
private function _setGlobalsData()
{
if(sizeof($GLOBALS)>0)
{
$this->_globals_data = '<pre>' . print_r($GLOBALS, true) . '</pre>';
}
else
{
$this->_globals_data = Messages::msg_globals();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbglobals' => $this->getGlobalsData()) );
}
/**
* @return mixed
*/
private function getPostData()
{
return $this->_post_data;
}
/**
* @param mixed $post_data
*/
private function _setPostData()
{
if(sizeof($_POST)>0)
{
$this->_post_data = '<pre>' . print_r($_POST, true) . '</pre>';
}
else
{
$this->_post_data = Messages::msg_post();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbpost' => $this->getPostData()) );
}
/**
* @desc loads the request data to the
* debugbar
*/
private function _setRequestData()
{
if(sizeof($_REQUEST)>0)
{
$this->_request_data = '<pre>' . print_r($_REQUEST, true) . '</pre>';
}
else
{
$this->_request_data = Messages::msg_request();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbrequest' => $this->getRequestData()) );
}
private function getRequestData()
{
return $this->_request_data;
}
/**
* @desc loads the server data array to the
* debugbar
*/
private function _setServerData()
{
if(sizeof($_SERVER)>0)
{
$this->_server_data = '<pre>' . print_r($_SERVER, true) . '</pre>';
}
else
{
$this->_server_data = Messages::msg_server();
}
Controller::getInstance()->varname( View::getInstance()->getEngine(), array('ndbserver' => $this->getServerData() ));
}
private function getServerData()
{
return $this->_server_data;
}
}

38
core/c/display.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: stephan
* Date: 24.01.17
* Time: 11:19
*/
class Display
{
/**
* Call this method to get singleton
* @return Display
*/
public static function getInstance()
{
static $instance = null;
if ($instance === null)
{
$instance = new Display();
}
return $instance;
}
/**
* Display constructor.
*/
protected function __construct()
{
}
public function display()
{
View::getInstance()->display(Router::getInstance()->tplName(true));
}
}

100
core/c/engine.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: skasdorf
* Date: 10.05.17
* Time: 10:45
*/
class Engine implements IEngine
{
private static $_instance;
private $_config = array();
private $_template_engine;
protected function __construct()
{
$this->_setConfig(Config::getInstance()->getConfig());
$this->_setTemplateEngine();
}
public static function getInstance()
{
$className = get_called_class();
if( self::$_instance == null )
{
self::$_instance = new $className();
}
return self::$_instance;
}
/**
* @return array
*/
protected function getConfig()
{
return $this->_config;
}
/**
* @param array $config
*/
protected function _setConfig( $config )
{
$this->_config = $config;
}
/**
* @return mixed
*/
public function getTemplateEngine()
{
return self::$_template_engine;
}
/**
* @desc set the template engine implementation and make it
* known class wide
* @param mixed $template_engine
*/
protected function _setTemplateEngine( )
{
switch(self::getConfig()[self::T_ENGINE][self::T_ENGINE_NAME])
{
case self::T_ENGINE_DWOO:
$this->_template_engine = self::T_ENGINE_DWOO;
require_once __DIR__ . '/../l/Dwoo/IDataProvider.php';
require_once __DIR__ . '/../l/Dwoo/Data.php';
require_once __DIR__ . '/../l/Dwoo/ICompiler.php';
require_once __DIR__ . '/../l/Dwoo/Compiler.php';
require_once __DIR__ . '/../l/Dwoo/ITemplate.php';
require_once __DIR__ . '/../l/Dwoo/Template/Str.php';
require_once __DIR__ . '/../l/Dwoo/Template/File.php';
require_once __DIR__ . '/../l/Dwoo/Exception.php';
require_once __DIR__ . '/../l/Dwoo/Plugin.php';
require_once __DIR__ . '/../l/Dwoo/ICompilable.php';
require_once __DIR__ . '/../l/Dwoo/ICompilable/Block.php';
require_once __DIR__ . '/../l/Dwoo/IElseable.php';
require_once __DIR__ . '/../l/Dwoo/Plugins/';
require_once __DIR__ . '/../l/Dwoo/Block/Plugin.php';
require_once __DIR__ . '/../l/Dwoo/Plugins/Blocks/PluginTopLevelBlock.php';
require_once __DIR__ . '/../l/Dwoo/Exception.php';
require_once __DIR__ . '/../l/Dwoo/ILoader.php';
require_once __DIR__ . '/../l/Dwoo/Loader.php';
require_once __DIR__ . '/../l/Dwoo/Core.php';
require_once __DIR__ . '/../l/Dwoo/Smarty/Adapter.php';
break;
case self::T_ENGINE_TWIG:
$this->_template_engine = self::T_ENGINE_TWIG;
require_once __DIR__ . '/../l/Twig/Autoloader.php';
break;
case self::T_ENGINE_SMARTY:
default:
$this->_template_engine = self::T_ENGINE_SMARTY;
require_once __DIR__ . '/../l/Smarty/Smarty.class.php';
break;
}
}
}
Engine::getInstance();

169
core/c/form.php Normal file
View File

@@ -0,0 +1,169 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: stephan
* Date: 24.01.17
* Time: 15:48
*/
class Form implements IForm
{
use Messages;
/**
* @desc class wide parameters
* @var
*/
protected static $_instance;
private static $fieldset_name;
private static $action;
private static $name;
private static $type;
private static $fields = array();
private static $form = self::TYPE_FORM;
protected function __construct($action, $name, $type)
{
try {
if($action != "")
{
self::setFormAction($action);
}
if($name != "")
{
self::setFormName($name);
}
if($type != "")
{
self::setFormType($type);
}
} catch (\Exception $e)
{
Debug::getInstance()->toDebug($e->getMessage());
}
}
private static function setCurrentForm($form = self::TYPE_FORM)
{
if(self::getFieldsetName())
{
self::$form = self::TYPE_FORM_FIELDSET;
}
else
{
self::$form = $form;
}
}
protected static function getCurrentForm()
{
return self::$form;
}
/**
* Call this method to get singleton
*
* @return Form
*/
public static function getInstance($action, $name, $type)
{
static $instance = null;
if ($instance === null)
{
$instance = new Form($action, $name, $type);
}
return $instance;
}
public static function setFormAction($action)
{
try{
if(is_string($action))
{
self::setCurrentForm(str_replace("{action}", $action, self::getCurrentForm()));
}
else
{
throw new \Exception(Messages::msg_error_string());
}
} catch (\Exception $e)
{
Debug::getInstance()->toDebug($e->getMessage());
}
}
private static function getFormAction()
{
return self::$action;
}
public static function setFormName($name)
{
try{
if(is_string($name))
{
self::setCurrentForm(str_replace("{name}", $name, self::getCurrentForm()));
}
else
{
throw new \Exception(Messages::msg_error_string());
}
} catch (\Exception $e)
{
Debug::getInstance()->toDebug($e->getMessage());
}
}
/**
* @desc set the form type corresponding to the HTML5 standard
*
* @param $type
*/
public static function setFormType($type)
{
try{
if(is_string($type))
{
self::setCurrentForm(str_replace("{type}", $type, self::getCurrentForm()));
}
else
{
throw new \Exception(Messages::msg_error_string());
}
} catch (\Exception $e)
{
Debug::getInstance()->toDebug($e->getMessage());
}
}
/**
* @return mixed
*/
protected static function getFieldsetName()
{
return self::$fieldset_name;
}
/**
* @param mixed $fieldset_name
*/
private static function setFieldsetName( $fieldset_name )
{
self::$fieldset_name = $fieldset_name;
}
/**
* @desc output the form with all current fields and values
*/
public function displayForm()
{
// TODO: Implement displayForm() method.
}
public function addFieldset($name)
{
self::setFieldsetName($name);
}
}

16
core/c/formfromtable.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: mithril
* Date: 17.03.2017
* Time: 14:27
*/
class Formfromtable implements IFormfromtable
{
use Messages;
//TODO: Buld form from table
}

293
core/c/input.php Normal file
View File

@@ -0,0 +1,293 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: stephan
* Date: 24.01.17
* Time: 11:18
*/
class Input extends Form implements IInput
{
use Messages;
/**
* @desc class wide parameters
* @var string
*/
private static $_currentInput = self::INPUT;
private static $_inputFields = array();
private static $_labeled = false;
protected function __construct($action, $name, $type, $labeled)
{
parent::getInstance($action, $name, $type);
}
public static function load($action = false, $name, $type, $labeled=false)
{
self::setLabeled($labeled);
if( self::$_instance == null )
{
self::$_instance = new Input($action, $name, $type, $labeled);
}
return self::$_instance;
}
/**
* @return bool
*/
protected static function isLabeled()
{
return self::$_labeled;
}
/**
* @param bool $labeled
*/
protected function setLabeled($labeled=false)
{
self::$_labeled = $labeled;
}
/**
* @desc accesor method for building the input fields
* @param $fields
* @throws \Exception
*/
public function setInputFields($fields)
{
try {
if(is_array($fields))
{
if(self::isLabeled())
{
self::$_currentInput = self::INPUT_LABELED;
}
if(sizeof($fields)==5) {
$keys = array_keys($fields);
for ($i = 0; sizeof($keys)>$i; $i++) {
if ($keys[$i] == "fieldnames") {
try {
if (is_array($fields[$keys[$i]])) {
for ($a = 0; sizeof($fields[$keys[$i]]) > $a; $a++) {
if($fields["fieldtypes"][$a]=="submit")
{
if(self::isLabeled())
{
$submit = str_replace("<label for=\"{name}\">{labelname}</label>", "", self::getCurrentInput());
$submit = str_replace("name=\"{name}\"", "", $submit);
}
else
{
$submit = str_replace("name=\"{name}\"", "", self::getCurrentInput());
}
self::$_inputFields[] = str_replace("{value}", $fields[$keys[$i]][$a], $submit);
}
else
{
if($fields["fieldtypes"][$a]===self::TYPE_HIDDEN)
{
self::$_inputFields[] = str_replace("{name}", $fields[$keys[$i]][$a], self::INPUT);
}
else
{
$inputname = str_replace("{name}", $fields[$keys[$i]][$a], self::getCurrentInput());
self::$_inputFields[] = str_replace("{labelname}", $fields[$keys[$i]][$a], $inputname);
}
}
}
}
} catch (\Exception $e) {
throw new \Exception(Messages::msg_error_field_names());
}
}
if ($keys[$i] == "fieldvalues") {
try {
if (is_array($fields[$keys[$i]])) {
try {
if (is_array($fields[$keys[$i]])) {
for ($j = 0; sizeof($fields[$keys[$i]]) > $j; $j++) {
if($fields[$keys[$i]][$j]==false)
{
self::$_inputFields[$j] = str_replace("value=\"{value}\"", "", self::$_inputFields[$j]);
}
else
{
self::$_inputFields[$j] = str_replace("{value}", $fields[$keys[$i]][$j], self::$_inputFields[$j]);
}
}
}
} catch (\Exception $e) {
throw new \Exception(Messages::msg_error_input_values());
}
}
} catch (\Exception $e) {
throw new \Exception(Messages::msg_error_input_values());
}
}
if ($keys[$i] == "fieldtypes") {
try {
if (is_array($fields[$keys[$i]])) {
for ($b = 0; sizeof($fields[$keys[$i]]) > $b; $b++) {
switch ($fields[$keys[$i]][$b]) {
case self::TYPE_BUTTON:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_BUTTON, self::$_inputFields[$b]);
break;
case self::TYPE_CHECKBOX:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_CHECKBOX, self::$_inputFields[$b]);
break;
case self::TYPE_DATE:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_DATE, self::$_inputFields[$b]);
break;
case self::TYPE_EMAIL:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_EMAIL, self::$_inputFields[$b]);
break;
case self::TYPE_HIDDEN:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_HIDDEN, self::$_inputFields[$b]);
break;
case self::TYPE_IMAGE:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_IMAGE, self::$_inputFields[$b]);
break;
case self::TYPE_TEL:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_TEL, self::$_inputFields[$b]);
break;
case self::TYPE_RADIO:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_RADIO, self::$_inputFields[$b]);
break;
case self::TYPE_PASSWORD:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_PASSWORD, self::$_inputFields[$b]);
break;
case self::TYPE_SUBMIT:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_SUBMIT, self::$_inputFields[$b]);
break;
case self::TYPE_TIME:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_TIME, self::$_inputFields[$b]);
break;
case self::TYPE_WEEK:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_WEEK, self::$_inputFields[$b]);
break;
case self::TYPE_URL:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_URL, self::$_inputFields[$b]);
break;
case self::TYPE_TEXT:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_TEXT, self::$_inputFields[$b]);
break;
case self::TYPE_COLOR:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_COLOR, self::$_inputFields[$b]);
break;
case self::TYPE_DATETIME_LOCAL:
self::$_inputFields[$b] = str_replace("{type}", self::TYPE_DATETIME_LOCAL, self::$_inputFields[$b]);
break;
}
}
}
} catch (\Exception $e) {
throw new \Exception(Messages::msg_error_field_types());
}
}
if ($keys[$i] == "min") {
try {
if (is_array($fields[$keys[$i]])) {
try {
if (is_array($fields[$keys[$i]])) {
for ($c = 0; sizeof($fields[$keys[$i]]) > $c; $c++) {
if($fields[$keys[$i]][$c]==false)
{
self::$_inputFields[$c] = str_replace("min=\"{min}\"", "", self::$_inputFields[$c]);
}
else
{
self::$_inputFields[$c] = str_replace("{min}", $fields[$keys[$i]][$c], self::$_inputFields[$c]);
}
}
}
} catch (\Exception $e) {
throw new \Exception(Messages::msg_error_field_min());
}
}
} catch (\Exception $e) {
throw new \Exception(Messages::msg_error_field_min());
}
}
if ($keys[$i] == "max") {
try {
if (is_array($fields[$keys[$i]])) {
try {
if (is_array($fields[$keys[$i]])) {
for ($d = 0; sizeof($fields[$keys[$i]]) > $d; $d++) {
if($fields[$keys[$i]][$d]==false)
{
self::$_inputFields[$d] = str_replace("max=\"{max}\"", "", self::$_inputFields[$d]);
}
else
{
self::$_inputFields[$d] = str_replace("{max}", $fields[$keys[$i]][$d], self::$_inputFields[$d]);
}
}
}
} catch (\Exception $e) {
throw new \Exception(Messages::msg_error_field_max());
}
}
} catch (\Exception $e) {
throw new \Exception(Messages::msg_error_field_max());
}
}
}
self::setCurrentInput();
$fields = self::$_inputFields;
self::$_inputFields = "";
for($i=0;sizeof($fields)>$i;$i++)
{
self::$_inputFields .= $fields[$i];
}
}
}
else
{
throw new \Exception(Messages::msg_error_input_array_size());
}
} catch (\Exception $e)
{
throw new \Exception(Messages::msg_error_array());
}
}
/**
* @desc get all input fields for the display
* @return array
*/
private static function getInputFields()
{
return self::$_inputFields;
}
/**
* @desc set the current replacement for the input field
* @param string $input
*/
private static function setCurrentInput($input = self::INPUT)
{
self::$_currentInput = $input;
}
/**
* @desc transfer method for the Template replacement
* @return string
*/
private static function getCurrentInput()
{
return self::$_currentInput;
}
/**
* @desc diplay the current form with the input fields
*/
public function displayForm()
{
return str_replace("{fields}", self::getInputFields(), self::getCurrentForm());
}
}

130
core/c/json-navigation.php Normal file
View File

@@ -0,0 +1,130 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 15:26
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class JsonNavigation extends Config
{
const NAVIGATION = "navigation";
private static $_navigation;
private static $_navigation_array = array();
private static $_instance;
private static $_file_content_string = NULL;
private static $_file_content_array = array();
public static function getInstance()
{
parent::getInstance();
self::setFileContentString();
self::setFileContentArray();
self::setNavigation();
$className = get_called_class();
if(self::$_instance==null) self::$_instance = new $className();
return self::$_instance;
}
/**
* @return null
*/
protected static function getFileContentString( )
{
return self::$_file_content_string;
}
/**
* @param null $file_content
*/
private static function setFileContentString( )
{
self::$_file_content_string = file_get_contents( Settings::SETTINGS_PATH . self::getConfig()["SETTINGS"]["navigation"] );
}
/**
* @return array
*/
protected static function getFileContentArray( )
{
return self::$_file_content_array;
}
/**
* @param array $file_content_array
*/
private static function setFileContentArray( )
{
self::$_file_content_array = file( Settings::SETTINGS_PATH . self::getConfig()["SETTINGS"]["navigation"] );
}
/**
* @return array
*/
protected static function getNavigation( )
{
return self::$_navigation;
}
/**
* @param array $navigation
*/
private static function setNavigation( )
{
self::$_navigation = new \RecursiveIteratorIterator(
new \RecursiveArrayIterator(
json_decode( self::getFileContentString() , TRUE )
), \RecursiveIteratorIterator::SELF_FIRST
);
}
/**
* Displays the content of the file line by line on the
* screen if it is in json format
*/
public function displayRawJsonNavigation( )
{
foreach (self::getNavigation() as $key => $val)
{
if(is_array($val))
{
echo "$key:<br>\n";
}
else
{
echo "$key => $val<br>\n";
}
}
}
/**
* Loads the navigation from a json file into
* the view, making the variables available
*/
public function loadJsonNavigationArray( )
{
$nav = self::getNavigation();
foreach ( $nav as $item => $value)
{
if($item == self::NAVIGATION)
{
$keys = array_keys($value);
for($i=0; sizeof($keys)>$i;$i++)
{
self::$_navigation_array[] = array(
'title' => $keys[$i],
'icon' => $value[$keys[$i]]["icon"],
'link' => $value[$keys[$i]]["link"],
'tooltip' => $value[$keys[$i]]["tooltip"],
);
}
}
}
View::getInstance()->getEngine()->assignGlobal("navigationJson", self::$_navigation_array);
}
}

176
core/c/mysql.php Normal file
View File

@@ -0,0 +1,176 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 01.02.17
* Time - 17:36
* @author - alllinux.de GbR
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class Mysql implements IMysql
{
use Messages;
private static $_instance;
private $_dsn = self::PLACE_DSN;
private $_username = self::PLACE_USERNAME;
private $_password = self::PLACE_PASSWORD;
private $_diver = self::PLACE_DRIVER;
private $_hostname = self::PLACE_HOSTNAME;
private $_dbname = self::PLACE_DATABASE;
private $_port = self::PLACE_PORT;
private $_conn = self::PLACE_CONNECTION;
protected function __construct( )
{
$settings = Config::getInstance()->getConfig()[self::SETTINGS_DATABASE];
$this->_setUsername($settings[self::PLACE_USERNAME]);
$this->_setPassword($settings[self::PLACE_PASSWORD]);
$this->_setDbname($settings[self::PLACE_DATABASE]);
$this->_setDiver($settings[self::PLACE_DRIVER]);
$this->_setHostname($settings[self::PLACE_HOSTNAME]);
$this->_setPort($settings[self::PLACE_PORT]);
$this->_setDsn();
$this->_setConn();
}
public static function getInstance()
{
$className = get_called_class();
if(self::$_instance==null) self::$_instance = new $className();
return self::$_instance;
}
/**
* @return string
*/
protected function getDsn()
{
return $this->_dsn;
}
/**
* @param string $dsn
*/
private function _setDsn( )
{
$this->_dsn = $this->getDiver() . ':host=' . $this->getHostname() . ';port=' . $this->getPort() . ';dbname=' . $this->getDbname();
}
/**
* @return string
*/
protected function getUsername()
{
return $this->_username;
}
/**
* @param string $username
*/
private function _setUsername( $username )
{
$this->_username = $username;
}
/**
* @return string
*/
protected function getPassword()
{
return $this->_password;
}
/**
* @param string $password
*/
private function _setPassword( $password )
{
$this->_password = $password;
}
/**
* @return mixed
*/
protected function getDiver()
{
return $this->_diver;
}
/**
* @param mixed $diver
*/
private function _setDiver( $diver )
{
$this->_diver = $diver;
}
/**
* @return string
*/
protected function getHostname()
{
return $this->_hostname;
}
/**
* @param string $hostname
*/
private function _setHostname( $hostname )
{
$this->_hostname = $hostname;
}
/**
* @return string
*/
protected function getDbname()
{
return $this->_dbname;
}
/**
* @param string $dbname
*/
private function _setDbname( $dbname )
{
$this->_dbname = $dbname;
}
/**
* @return string
*/
protected function getConn()
{
return $this->_conn;
}
/**
* @param string $conn
*/
private function _setConn( )
{
$this->_conn = new \PDO($this->getDsn(), $this->getUsername(), $this->getPassword());
}
/**
* @return string
*/
protected function getPort()
{
return $this->_port;
}
/**
* @param string $port
*/
private function _setPort( $port )
{
$this->_port = $port;
}
}

175
core/c/pdo.php Normal file
View File

@@ -0,0 +1,175 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 01.02.17
* Time - 18:55
* @author - alllinux.de GbR
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
final class Pdo extends Mysql implements IPdo
{
/**
* @param string $string
*
* @return array
*/
public static function query( $string = self::PLACE_NO_QUERY )
{
$query = parent::getInstance()->getConn()->query( $string );
while($row = $query->fetch())
{
$keys = array_keys($row);
for($i=0;sizeof($keys)>$i;$i += 2)
{
$row_values[] = $row[$keys[$i]];
$key_values[] = $keys[$i];
}
$result = array_combine($key_values, $row_values);
}
return $result;
}
public static function fetchRowInArrayById($tablename = self::PLACE_TABLE_NAME, $id = self::NO_ID )
{
$statement = parent::getInstance()->getConn();
$describe = $statement->query('DESC ' . $tablename);
$describe->execute();
$tableInformation = $describe->fetchAll( \PDO::FETCH_ASSOC );
foreach ( $tableInformation as $entry )
{
if( $entry["Key"] == IMysql::PLACE_PRIMARY_KEY )
{
$id_name = $entry["Field"];
}
}
$prepare = $statement->prepare("SELECT * FROM " . $tablename . " WHERE " . $id_name . " = :" . $id_name . ";");
$prepare->execute($id);
$rowset = array_shift($prepare->fetchAll());
foreach(array_keys($rowset) as $entry)
{
if(is_string($entry))
{
$result[$entry] = $rowset[$entry];
}
}
return $result;
}
public static function fetchRowInArrayByWhere($tablename = IMysql::PLACE_TABLE_NAME,
$column_name = IMysql::PLACE_COLUMN_NAME,
$parameter_name = IMysql::PLACE_SEARCH_TERM)
{
$statement = parent::getInstance()->getConn();
$prepare = $statement->prepare("SELECT * FROM " . $tablename . " WHERE " . $column_name . " = :" . $parameter_name . ";");
$prepare->execute();
$rowset = array_shift($prepare->fetchAll());
foreach(array_keys($rowset) as $entry)
{
if(is_string($entry))
{
$result[$entry] = $rowset[$entry];
}
}
return $result;
}
public static function getLastInsertedID()
{
// TODO: Implement getLastInsertedID() method.
}
public static function fetchTableAsArray( $tablename = self::PLACE_TABLE_NAME )
{
$statement = parent::getInstance()->getConn()->query('SElECT * FROM ' . $tablename);
$statement->execute();
$result = $statement->fetchAll( \PDO::FETCH_ASSOC );
return $result;
}
public static function insertArrayIntoTable( $tablename = IMysql::PLACE_TABLE_NAME, $array_name = IMysql::PLACE_ARRAY_NAME, $encrypted = IMysql::PLACE_DES_ENCRYPT )
{
$statement = parent::getInstance()->getConn();
if(is_array($array_name))
{
if(array_key_exists(0, $array_name))
{
foreach( $array_name as $entry )
{
$field_names = array_keys( $entry );
$numItems = sizeof( $field_names );
$i = 0;
$row = " ( ";
foreach( $field_names as $field )
{
if( ++$i === $numItems )
{
$row .= $field;
}
else
{
$row .= $field . ", ";
}
}
$i = 0;
$row .= " ) VALUES ( ";
foreach ( $field_names as $field )
{
if( ++$i === $numItems )
{
$row .= ":" . $field ;
}
else
{
$row .= ":" . $field . ", ";
}
}
$row .= " )";
$query = $statement->prepare('INSERT INTO ' . $tablename . $row);
$query->execute( $entry );
}
}
else
{
$field_names = array_keys($array_name);
$numItems = sizeof($field_names);
$i = 0;
$row = " ( ";
foreach( $field_names as $field )
{
if( ++$i === $numItems )
{
$row .= $field;
}
else
{
$row .= $field . ", ";
}
}
$row .= " ) VALUES ( ";
$i = 0;
foreach ( $field_names as $field )
{
if( ++$i === $numItems )
{
$row .= ":" . $field ;
}
else
{
$row .= ":" . $field . ", ";
}
}
$row .= " )";
$query = $statement->prepare('INSERT INTO ' . $tablename . $row);
$query->execute( $array_name );
}
}
}
}

140
core/c/router.php Normal file
View File

@@ -0,0 +1,140 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 23:10
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class Router extends Config
{
private static $_routing;
private static $_cur_route;
private static $_instance;
private static $_cur_page;
private static $_routes = array();
protected function __construct()
{
}
public static function getInstance()
{
self::loadRouting();
$className = get_called_class();
if(self::$_instance==null) self::$_instance = new $className();
return self::$_instance;
}
private static function loadRouting()
{
Config::setConfig(Config::getInstance()->getEnv());
self::$_routing = Config::getInstance()->getConfig()[View::ATM_ROUTING];
self::setRoutes(self::$_routing);
}
/**
* @return mixed
*/
public function getRoutes()
{
return self::$_routes;
}
/**
* @param mixed $routes
*/
private static function setRoutes( $routes )
{
self::$_routes = $routes;
}
public function route()
{
self::setCurPage();
$route_keys = array_keys(self::$_routing["route"]);
$size_route_keys = sizeof($route_keys);
for($i=0; $size_route_keys>$i; $i++)
{
if(self::$_routing["route"][$route_keys[$i]] == self::getCurPage())
{
return self::getCurPage();
}
}
}
public function tplName($ending = false)
{
self::setCurPage();
if($ending)
{
return self::getCurPage() . ".tpl";
}
else
{
return self::getCurPage();
}
}
/**
* @return mixed
*/
protected static function getCurPage()
{
return self::$_cur_page;
}
/**
* @param mixed $cur_page
*/
private static function setCurPage( )
{
$uri_parts = explode('/', $_SERVER["REQUEST_URI"]);
if(is_array($uri_parts))
{
if($uri_parts[1] == "")
{
self::$_cur_page = "index";
}
else
{
self::$_cur_page = $uri_parts[1];
}
}
}
/**
* Returns an array with all the information about the current page
* post, get, request, current route, current page, current parameters
* @return array
*/
public function currentPage()
{
//self::RouterDebug(self::$_cur_page);
return self::$_cur_page;
}
public static function RouterDebug($value)
{
if(is_array($value))
{
echo "<pre>";
print_r($value);
echo "</pre>";
}
elseif(is_string($value))
{
echo '<br />' . $value;
}
die("DEBUG END ----->");
}
}

94
core/c/settings.php Normal file
View File

@@ -0,0 +1,94 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 20:16
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class Settings
{
const SETTINGS_FILE = "settings.ENV.ini";
const SETTINGS_PATH = "application/settings/config/";
private static $_config;
private static $_instance;
private static $_is_db_connection = false;
protected function __construct()
{
}
public static function getInstance()
{
$className = get_called_class();
if(self::$_instance==null) self::$_instance = new $className();
return self::$_instance;
}
/**
* @return mixed
*/
public function getConfig( )
{
return self::$_config;
}
/**
* in order to have the class serve connection
* details switch to db connection
*/
public static function setToDbConnection()
{
self::$_is_db_connection = true;
}
/**
* in order to switch back from a database
* connection
*/
public static function unsetFromDbConnection()
{
self::$_is_db_connection = false;
}
/**
* @param mixed $config
*/
public static function setConfig( $env )
{
if($env)
{
$current_settings_file = str_replace('.ENV.', '.'.$env.'.', self::SETTINGS_FILE);
if(file_exists(self::SETTINGS_PATH . $current_settings_file))
{
self::$_config = parse_ini_file(self::SETTINGS_PATH . $current_settings_file, "SETTINGS");
}
elseif(file_exists('../' . self::SETTINGS_PATH . $current_settings_file))
{
if($env==config::CLI_SYSTEM)
{
if(self::$_is_db_connection)
{
self::$_config = parse_ini_file('../' . self::SETTINGS_PATH . $current_settings_file, "SETTINGS");
}
else
{
self::$_config = parse_ini_file('../' . self::SETTINGS_PATH . $current_settings_file, "EMAIL");
}
}
else
{
self::$_config = parse_ini_file('../' . self::SETTINGS_PATH . $current_settings_file, View::ATM_SETTINGS);
}
}
}
else
{
throw new Exception("ERROR: The environment is unknown, please check with the server Administrator!");
}
}
}

15
core/c/soap.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: skasdorf
* Date: 16.06.17
* Time: 10:52
*/
namespace Nibiru;
class Soap implements ISoap
{
}

103
core/c/view.php Normal file
View File

@@ -0,0 +1,103 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 22:28
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
class View extends Controller implements IView
{
private static $_instance;
const ATM_SETTINGS = "SETTINGS";
const ATM_ROUTING = "ROUTING";
const ATM_FILE_END = ".tpl";
private static $smarty = array();
private static $engine = array();
protected function __construct()
{
Controller::getInstance();
self::_setEngine();
}
public static function getInstance()
{
$className = get_called_class();
if( self::$_instance == null )
{
self::$_instance = new $className();
}
return self::$_instance;
}
/**
* @return array
*/
public function getEngine()
{
return self::$engine;
}
/**
* @param array $engine
*/
public static function _setEngine( )
{
switch(Config::getInstance()->getConfig()[Engine::T_ENGINE][Engine::T_ENGINE_NAME])
{
case Engine::T_ENGINE_SMARTY:
self::$engine = new \Smarty();
self::$engine->setTemplateDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates"]);
self::$engine->setCompileDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates_c"]);
self::$engine->setCacheDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["cache"]);
self::$engine->setConfigDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["config_dir"]);
self::$engine->assign('debuging', Config::getInstance()->getConfig()[Engine::T_ENGINE]["debugbar"]);
break;
case Engine::T_ENGINE_TWIG:
$twig = new \Twig_Autoloader();
$twig::register();
self::$engine = new \Twig_Environment(new \Twig_Loader_Filesystem(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates"]), array(
'cache' => Config::getInstance()->getConfig()[Engine::T_ENGINE]["cache"],
));
break;
case Engine::T_ENGINE_DWOO:
// Implement Dwoo Template Engine
self::$engine = new \Dwoo\Core();
self::$engine->setCacheDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["cache"]);
self::$engine->setCompileDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates_c"]);
self::$engine->setTemplateDir(Config::getInstance()->getConfig()[Engine::T_ENGINE]["templates"]);
self::$engine->get('debugbar.tpl', array('debuging' => Config::getInstance()->getConfig()[Engine::T_ENGINE]["debugbar"]));
break;
}
}
public function assign( $varname = array() )
{
if(is_array($varname))
{
Controller::getInstance()->varname( $this->getEngine(), $varname );
}
}
public static function forwardTo( $page )
{
header('Location: ' . $page);
exit();
}
public function display( $page )
{
preg_match_all("/".self::ATM_FILE_END."/", $page, $matches);
if(!array_key_exists(self::ATM_FILE_END, array_flip(array_shift($matches))))
{
$page = str_replace("/", "", $page) . self::ATM_FILE_END;
}
Controller::getInstance()->action( $this->getEngine(), $page );
}
}

15
core/dispatch.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
/**
* User - stephan
* Date - 24.01.17
* Time - 20:22
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
Nibiru\Router::getInstance();
Nibiru\Router::getInstance()->route();
require_once __DIR__ . '/../application/controller/' . Nibiru\Router::getInstance()->tplName() . 'Controller.php';
eval("new Nibiru\\".Nibiru\Router::getInstance()->tplName()."Controller();");
Nibiru\Debug::getInstance();
Nibiru\Display::getInstance()->display();

38
core/framework.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
/**
* User - stephan
* Date - 24.01.17
* Time - 20:28
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
session_start();
require_once __DIR__ . '/t/messages.php';
require_once __DIR__ . '/c/settings.php';
require_once __DIR__ . '/c/config.php';
require_once __DIR__ . '/c/router.php';
require_once __DIR__ . '/i/engine.php';
require_once __DIR__ . '/c/engine.php';
require_once __DIR__ . '/i/form.php';
require_once __DIR__ . '/c/form.php';
require_once __DIR__ . '/i/input.php';
require_once __DIR__ . '/c/input.php';
require_once __DIR__ . '/i/formfromtable.php';
require_once __DIR__ . '/c/formfromtable.php';
require_once __DIR__ . '/i/controller.php';
require_once __DIR__ . '/c/controller.php';
require_once __DIR__ . '/i/view.php';
require_once __DIR__ . '/c/view.php';
require_once __DIR__ . '/c/json-navigation.php';
require_once __DIR__ . '/i/mysql.php';
require_once __DIR__ . '/c/mysql.php';
require_once __DIR__ . '/i/pdo.php';
require_once __DIR__ . '/c/pdo.php';
require_once __DIR__ . '/i/soap.php';
require_once __DIR__ . '/c/soap.php';
require_once __DIR__ . '/i/auth.php';
require_once __DIR__ . '/c/auth.php';
require_once __DIR__ . '/c/debug.php';
require_once __DIR__ . '/c/display.php';
require_once __DIR__ . '/dispatch.php';

17
core/i/auth.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 01.02.17
* Time - 17:18
* @author - alllinux.de GbR
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
interface IAuth
{
const NIBIRU_SECURITY = "SECURITY";
public function auth( $username, $password );
}

47
core/i/controller.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 22:36
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
interface IController
{
/**
* This should be part of any extended controller
* class in order to implement a page structure
* @return array
*/
public function pageAction();
/**
* This is the part where you can add titles to
* your page navigation.
*/
public function navigationAction();
/**
* Here you can add any form data for handling in your
* controller
*
* @param bool $action
* @param string $name
* @param string $type
* @param bool $labeled
* @param array $data
*
* @return array
*/
public function formAction( $action = false, $name = <<<NAME
NAME
, $type = <<<METHOD
METHOD
, $labeled = false , $data = array()
);
}

16
core/i/engine.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: skasdorf
* Date: 10.05.17
* Time: 10:46
*/
interface IEngine
{
const T_ENGINE = "ENGINE";
const T_ENGINE_NAME = "name";
const T_ENGINE_TWIG = "Twig";
const T_ENGINE_SMARTY = "Smarty";
const T_ENGINE_DWOO = "Dwoo";
}

44
core/i/form.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: stephan
* Date: 24.01.17
* Time: 10:20
*/
interface IForm
{
/**
* @desc Basic Form template
*/
const TYPE_FORM = "<form action=\"{action}\" method=\"{type}\" name=\"{name}\">" . "\n" . "{fields}" . "\n" . "<input type='submit' value='speichern'>\t\t" . "</form>" . "\n";
const TYPE_FORM_FIELDSET = "<form action=\"{action}\" method=\"{type}\" name=\"{name}\">"."\n"."<fieldset><label>{flname}</label>" . "\n" . "{fields}" . "\n" . "<input type='submit' value='speichern'>" . "\t\t" . "</fieldset>"."\n"."</form>" . "\n";
/**
* @desc add the form action in order to set the path
* for the controller
* @param $action
* @return mixed
*/
public static function setFormAction($action);
/**
* @desc set the form type, two types (post, get)
* @param $type
* @return mixed
*/
public static function setFormType($type);
/**
* @desc set the name for the form
* @param $name
* @return mixed
*/
public static function setFormName($name);
/**
* @desc display the form data on the html layout
* @return mixed
*/
public function displayForm();
}

20
core/i/formaction.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 14:39
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
interface IFormaction
{
public function getPostData();
public function getGetData();
public function getRequestData();
public function saveData();
}

14
core/i/formfromtable.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: mithril
* Date: 17.03.2017
* Time: 14:27
*/
interface IFormfromtable
{
//TODO: Buld form from table
}

71
core/i/input.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: stephan
* Date: 24.01.17
* Time: 11:16
*/
interface IInput
{
/**
* @desc constant form types for this class
*/
const TYPE_CHECKBOX = "checkbox";
const TYPE_RADIO = "radio";
const TYPE_EMAIL = "email";
const TYPE_TEXT = "text";
const TYPE_HIDDEN = "hidden";
const TYPE_DATE = "date";
const TYPE_IMAGE = "image";
const TYPE_PASSWORD = "password";
const TYPE_WEEK = "week";
const TYPE_TIME = "time";
const TYPE_TEL = "tel";
const TYPE_SUBMIT = "submit";
const TYPE_BUTTON = "button";
const TYPE_URL = "url";
const TYPE_COLOR = "color";
const TYPE_DATETIME_LOCAL = "datetime-local";
/**
* TODO: Implement onClick for javascript form validation
*@desc Build Templates for the input form field
*/
const INPUT = "\t\t\t" . "<input name=\"{name}\" type=\"{type}\" value=\"{value}\" min=\"{min}\" max=\"{max}\">" . "\n";
const INPUT_LABELED = "\t\t\t" . "<label for=\"{name}\">{labelname}</label>"."<input name=\"{name}\" type=\"{type}\" value=\"{value}\" min=\"{min}\" max=\"{max}\">" . "\n";
/**
* @desc set the form fields, they must be passed within an
* array: array(
* 'fieldnames' => array('name', 'name' ...),
* 'fieldtypes' => 'array(text, radio ...)',
* 'min' => array(number, number ...),
* 'max' => array(number, nunber ...)
* );
* @param $fields
* @return mixed
*/
public function setInputFields($fields);
/**
* @desc offer the main types for an input field
* e.g. type="checkbox",
* type="radio",
* type="email",
* type="text",
* type="hidden",
* type="date",
* type="image"
* type="password"
* type="week"
* type="time"
* type="tel"
* type="submit"
* type="button"
* type="url"
* @param (string) $type
* @return (string)
*/
}

31
core/i/mysql.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 01.02.17
* Time - 17:27
* @author - alllinux.de GbR
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
interface IMysql
{
const SETTINGS_DATABASE = "DATABASE";
const PLACE_NO_QUERY = "NO QUERY";
const NO_ID = false;
const PLACE_TABLE_NAME = "NO TABLENAME";
const PLACE_DSN = "NO CONNECTION STRING";
const PLACE_USERNAME = "username";
const PLACE_PASSWORD = "password";
const PLACE_HOSTNAME = "hostname";
const PLACE_DRIVER = "driver";
const PLACE_DATABASE = "basename";
const PLACE_PORT = "port";
const PLACE_CONNECTION = "NO CONNECTION";
const PLACE_PRIMARY_KEY = "PRI";
const PLACE_COLUMN_NAME = "NO COLUMN NAME";
const PLACE_SEARCH_TERM = "NO SEARCH PARAMETER";
const PLACE_DES_ENCRYPT = false;
}

63
core/i/pdo.php Normal file
View File

@@ -0,0 +1,63 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 01.02.17
* Time - 19:03
* @author - alllinux.de GbR
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
interface IPdo
{
/**
* @desc returns the query by ressult
* @param string $string
*
* @return array()
*/
public static function query( $string = IMysql::PLACE_NO_QUERY );
/**
* @desc returns the row by id
* @param bool $id
*
* @return array()
*/
public static function fetchRowInArrayById( $tablename = IMysql::PLACE_TABLE_NAME, $id = IMysql::NO_ID );
/**
* @desc returns row by column name and search parameter
* @param string $tablename
* @param string $column_name
* @param IMysql $
* @return mixed
*/
public static function fetchRowInArrayByWhere( $tablename = IMysql::PLACE_TABLE_NAME,
$column_name = IMysql::PLACE_COLUMN_NAME,
$parameter_name = IMysql::PLACE_SEARCH_TERM );
/**
* @desc will return the last inserted ID
* @return integer
*/
public static function getLastInsertedID();
/**
* @desc will return all entries from the selected tablename
*
* @param string $tablename
*
* @return mixed
*/
public static function fetchTableAsArray( $tablename = IMysql::PLACE_TABLE_NAME );
/**
* @desc insert array content into database
* @param string $tablename
* @param string $array_name
* @return mixed
*/
public static function insertArrayIntoTable( $tablename = IMysql::PLACE_TABLE_NAME, $array_name = IMysql::PLACE_ARRAY_NAME, $encrypted = IMysql::PLACE_DES_ENCRYPT );
}

44
core/i/select.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: stephan
* Date: 24.01.17
* Time: 11:16
* TODO: Write the corresponding class for the select dropdown of the form
*/
interface ISelect
{
/**
* @desc set the name for the select box
* @param $selectName
* @return mixed
*/
public static function setSelectName($selectName);
/**
* @desc set the options array in the current form if present
* e.g.: array(
'names' => array('name1', 'name2'),
* 'value' => array('value1', 'value2')
* )
* @param $optionNames
* @return mixed
*/
public static function setOptionNames($optionNames);
/**
* @desc set the select type possible parameter values
* multiple, single
* @param $selectType
* @return mixed
*/
public static function setSelectType($selectType);
/**
* @desc set the size of the select type if it is multiple
* @param $selectTypeSize
* @return mixed
*/
public static function setSelectTypeSize($selectTypeSize);
}

15
core/i/soap.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: skasdorf
* Date: 16.06.17
* Time: 10:44
*/
namespace Nibiru;
interface ISoap
{
}

33
core/i/textarea.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace Nibiru;
/**
* Created by PhpStorm.
* User: stephan
* Date: 24.01.17
* Time: 11:22
* TODO: Write the class for the textareas
*/
interface ITextarea
{
/**
* @desc set the name of the text area
* @param (string) $textareaName
* @return (string)
*/
public static function setTextareaName($textareaName);
/**
* @desc set the size of the text area
* @param (int) $textareaSize
* @return (int)
*/
public static function setTextareaSize($textareaSize);
/**
* @desc set the textarea form name given by the father class
* e.g.:
* @param (string) $textareaFormname
* @return (string)
*/
public static function setTextareaFormname($textareaFormname);
}

14
core/i/view.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
namespace Nibiru;
/**
* User - stephan
* Date - 24.01.17
* Time - 22:41
* @author - Stephan Kasdorf
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
interface IView
{
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Block
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-23
* @link http://dwoo.org/
*/
namespace Dwoo\Block;
use Dwoo\Plugin as DwooPlugin;
use Dwoo\Compiler as DwooCompiler;
/**
* Base class for block plugins.
* you have to implement the <em>init()</em> method, it will receive the parameters that
* are in the template code and is called when the block starts
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
abstract class Plugin extends DwooPlugin
{
/**
* Stores the contents of the block while it runs.
*
* @var string
*/
protected $buffer = '';
/**
* Buffers input, override only if necessary.
*
* @var string the content that must be buffered
*/
public function buffer($input)
{
$this->buffer .= $input;
}
// initialization code, receives the parameters from {block param1 param2}
// public function init($arg, $arg, ...);
/**
* Called when the block ends, this is most of the time followed right away by a call
* of <em>process()</em> but not always, so this should be used to do any shutdown operations on the
* block object, if required.
*/
public function end()
{
}
/**
* Called when the block output is required by a parent block.
* this must read $this->buffer and return it processed
*
* @return string
*/
public function process()
{
return $this->buffer;
}
/**
* Called at compile time to define what the block should output in the compiled template code, happens when the
* block is declared basically this will replace the {block arg arg arg} tag in the template.
*
* @param DwooCompiler $compiler the compiler instance that calls this function
* @param array $params an array containing original and compiled parameters
* @param string $prepend that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, "foo();") to add a command before the
* default commands are executed parent::postProcessing($compiler, $params, "foo();")
* to add a command before the default commands are executed
* @param string $append that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, null, "foo();") to add a command after
* the default commands are executed parent::postProcessing($compiler, $params, null,
* "foo();") to add a command after the default commands are executed
* @param string $type the type is the plugin class name used
*
* @return string
*/
public static function preProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $type)
{
return DwooCompiler::PHP_OPEN . $prepend . '$this->addStack("' . $type . '", array(' . DwooCompiler::implode_r($compiler->getCompiledParams($params)) . '));' . $append . DwooCompiler::PHP_CLOSE;
}
/**
* Called at compile time to define what the block should output in the compiled template code, happens when the
* block is ended basically this will replace the {/block} tag in the template.
*
* @see preProcessing
*
* @param DwooCompiler $compiler the compiler instance that calls this function
* @param array $params an array containing original and compiled parameters, see preProcessing() for more
* details more details
* @param string $prepend that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, "foo();") to add a command before the
* default commands are executed parent::postProcessing($compiler, $params, "foo();")
* to add a command before the default commands are executed
* @param string $append that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, null, "foo();") to add a command after
* the default commands are executed parent::postProcessing($compiler, $params, null,
* "foo();") to add a command after the default commands are executed
* @param string $content the entire content of the block being closed
*
* @return string
*/
public static function postProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $content)
{
return $content . DwooCompiler::PHP_OPEN . $prepend . '$this->delStack();' . $append . DwooCompiler::PHP_CLOSE;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Compilation
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE LGPLv3
* @version 1.3.6
* @date 2017-03-21
* @link http://dwoo.org/
*/
namespace Dwoo\Compilation;
use Dwoo\Exception as DwooException;
use Dwoo\Compiler as DwooCompiler;
/**
* Dwoo compilation exception class.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class Exception extends DwooException
{
protected $compiler;
protected $template;
/**
* Exception constructor.
*
* @param DwooCompiler $compiler
* @param int $message
*/
public function __construct(DwooCompiler $compiler, $message)
{
$this->compiler = $compiler;
$this->template = $compiler->getCore()->getTemplate();
parent::__construct('Compilation error at line ' . $compiler->getLine() . ' in "' . $this->template->getResourceName() . ':' . $this->template->getResourceIdentifier() . '" : ' . $message);
}
/**
* @return DwooCompiler
*/
public function getCompiler()
{
return $this->compiler;
}
/**
* @return \Dwoo\ITemplate|null
*/
public function getTemplate()
{
return $this->template;
}
}

3671
core/l/Dwoo/Compiler.php Normal file

File diff suppressed because it is too large Load Diff

1792
core/l/Dwoo/Core.php Normal file

File diff suppressed because it is too large Load Diff

264
core/l/Dwoo/Data.php Normal file
View File

@@ -0,0 +1,264 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.4
* @date 2017-03-01
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Dwoo data object, use it for complex data assignments or if you want to easily pass it
* around multiple functions to avoid passing an array by reference.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class Data implements IDataProvider
{
/**
* Data array.
*
* @var array
*/
protected $data = array();
/**
* Returns the data array.
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* Clears a the entire data or only the given key.
*
* @param array|string $name clears only one value if you give a name, multiple values if
* you give an array of names, or the entire data if left null
*/
public function clear($name = null)
{
if ($name === null) {
$this->data = array();
} elseif (is_array($name)) {
foreach ($name as $index) {
unset($this->data[$index]);
}
} else {
unset($this->data[$name]);
}
}
/**
* Overwrites the entire data with the given array.
*
* @param array $data the new data array to use
*/
public function setData(array $data)
{
$this->data = $data;
}
/**
* merges the given array(s) with the current data with array_merge.
*
* @param array $data the array to merge
*/
public function mergeData(array $data)
{
$args = func_get_args();
foreach ($args as $key => $v) {
if (is_array($v)) {
$this->data = array_merge($this->data, $v);
}
}
}
/**
* Assigns a value or an array of values to the data object.
*
* @param array|string $name an associative array of multiple (index=>value) or a string
* that is the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign, or null if $name was an array
*/
public function assign($name, $val = null)
{
if (is_array($name)) {
reset($name);
foreach ($name as $k => $v){
$this->data[$k] = $v;
}
} else {
$this->data[$name] = $val;
}
}
/**
* Allows to assign variables using the object syntax.
*
* @param string $name the variable name
* @param string $value the value to assign to it
*/
public function __set($name, $value)
{
$this->assign($name, $value);
}
/**
* Assigns a value by reference to the data object.
*
* @param string $name the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign by reference
*/
public function assignByRef($name, &$val)
{
$this->data[$name] = &$val;
}
/**
* Appends values or an array of values to the data object.
*
* @param array|string $name an associative array of multiple (index=>value) or a string
* that is the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to assign, or null if $name was an array
* @param bool $merge true to merge data or false to append, defaults to false
*/
public function append($name, $val = null, $merge = false)
{
if (is_array($name)) {
foreach ($name as $key => $val) {
if (isset($this->data[$key]) && !is_array($this->data[$key])) {
settype($this->data[$key], 'array');
}
if ($merge === true && is_array($val)) {
$this->data[$key] = $val + $this->data[$key];
} else {
$this->data[$key][] = $val;
}
}
} elseif ($val !== null) {
if (isset($this->data[$name]) && !is_array($this->data[$name])) {
settype($this->data[$name], 'array');
} elseif (!isset($this->data[$name])) {
$this->data[$name] = array();
}
if ($merge === true && is_array($val)) {
$this->data[$name] = $val + $this->data[$name];
} else {
$this->data[$name][] = $val;
}
}
}
/**
* Appends a value by reference to the data object.
*
* @param string $name the index to use, i.e. a value assigned to "foo" will be
* accessible in the template through {$foo}
* @param mixed $val the value to append by reference
* @param bool $merge true to merge data or false to append, defaults to false
*/
public function appendByRef($name, &$val, $merge = false)
{
if (isset($this->data[$name]) && !is_array($this->data[$name])) {
settype($this->data[$name], 'array');
}
if ($merge === true && is_array($val)) {
foreach ($val as $key => &$value) {
$this->data[$name][$key] = &$value;
}
} else {
$this->data[$name][] = &$val;
}
}
/**
* Returns true if the variable has been assigned already, false otherwise.
*
* @param string $name the variable name
*
* @return bool
*/
public function isAssigned($name)
{
return isset($this->data[$name]);
}
/**
* Supports calls to isset($dwoo->var).
*
* @param string $name the variable name
*
* @return bool
*/
public function __isset($name)
{
return isset($this->data[$name]);
}
/**
* Unassigns/removes a variable.
*
* @param string $name the variable name
*/
public function unassign($name)
{
unset($this->data[$name]);
}
/**
* Supports unsetting variables using the object syntax.
*
* @param string $name the variable name
*/
public function __unset($name)
{
unset($this->data[$name]);
}
/**
* Returns a variable if it was assigned.
*
* @param string $name the variable name
*
* @return mixed
*/
public function get($name)
{
return $this->__get($name);
}
/**
* Allows to read variables using the object syntax.
*
* @param string $name the variable name
*
* @return mixed
* @throws Exception
*/
public function __get($name)
{
if (isset($this->data[$name])) {
return $this->data[$name];
} else {
throw new Exception('Tried to read a value that was not assigned yet : "' . $name . '"');
}
}
}

26
core/l/Dwoo/Exception.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Main dwoo exception class.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class Exception extends \Exception
{
}

52
core/l/Dwoo/Filter.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Base class for filters.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
abstract class Filter
{
/**
* The dwoo instance that runs this filter.
*
* @var Core
*/
protected $dwoo;
/**
* Constructor, if you override it, call parent::__construct($dwoo); or assign
* the dwoo instance yourself if you need it.
*
* @param Core $dwoo the dwoo instance that runs this plugin
*/
public function __construct(Core $dwoo)
{
$this->dwoo = $dwoo;
}
/**
* Processes the input and returns it filtered.
*
* @param string $input the template to process
*
* @return string
*/
abstract public function process($input);
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-23
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Interface that represents a compilable plugin.
* implement this to notify the compiler that this plugin does not need to be loaded at runtime.
* to implement it right, you must implement <em>public static function compile(Compiler $compiler, $arg, $arg,
* ...)</em>, which replaces the <em>process()</em> method (that means <em>compile()</em> should have all arguments it
* requires). This software is provided 'as-is', without any express or implied warranty. In no event will the authors
* be held liable for any damages arising from the use of this software.
*/
interface ICompilable
{
// this replaces the process function
//public static function compile(Compiler $compiler, $arg, $arg, ...);
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\ICompilable
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\ICompilable;
/**
* Interface that represents a compilable block plugin.
* implement this to notify the compiler that this plugin does not need to be loaded at runtime.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
interface Block
{
}

59
core/l/Dwoo/ICompiler.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE LGPLv3
* @version 1.3.6
* @date 2017-03-21
* @link http://dwoo.org/
*/
namespace Dwoo;
use Dwoo\Security\Policy as SecurityPolicy;
/**
* Interface that represents a dwoo compiler.
* while implementing this is enough to interact with Dwoo/Templates, it is not
* sufficient to interact with Dwoo/Plugins, however the main purpose of creating a
* new compiler would be to interact with other/different plugins, that is why this
* interface has been left with the minimum requirements.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
interface ICompiler
{
/**
* Compiles the provided string down to php code.
*
* @param Core $core
* @param ITemplate $template the template to compile
*
* @return string a compiled php code string
*/
public function compile(Core $core, ITemplate $template);
/**
* Adds the custom plugins loaded into Dwoo to the compiler so it can load them.
*
* @see Core::addPlugin
*
* @param array $customPlugins an array of custom plugins
*/
public function setCustomPlugins(array $customPlugins);
/**
* Sets the security policy object to enforce some php security settings.
* use this if untrusted persons can modify templates,
* set it on the Dwoo object as it will be passed onto the compiler automatically
*
* @param SecurityPolicy $policy the security policy object
*/
public function setSecurityPolicy(SecurityPolicy $policy = null);
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-23
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Interface that represents a dwoo data object.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
interface IDataProvider
{
/**
* Returns the data as an associative array that will be used in the template.
*
* @return array
*/
public function getData();
}

30
core/l/Dwoo/IElseable.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Interface that represents a block plugin that supports the else functionality.
* the else block will enter an "hasElse" parameter inside the parameters array
* of the closest parent implementing this interface, the hasElse parameter contains
* the else output that should be appended to the block's content (see foreach or other
* block for examples)
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
interface IElseable
{
}

37
core/l/Dwoo/ILoader.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-23
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Interface for dwoo plugin loaders.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
interface ILoader
{
/**
* Loads a plugin file.
* the second parameter is used to avoid permanent rehashing when using php functions,
* however this means that if you have add a plugin that overrides a php function you have
* to delete the classpath.cache file(s) by hand to force a rehash of the plugins
*
* @param string $class the plugin name, without the `Plugin` prefix
* @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it
* has just been added, defaults to true
*/
public function loadPlugin($class, $forceRehash = true);
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-23
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Interface that represents a dwoo plugin proxy.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
interface IPluginProxy
{
/**
* Returns true or false to say whether the given plugin is handled by this proxy or not.
*
* @param string $name the plugin name
*
* @return bool true if the plugin is known and usable, otherwise false
*/
public function handles($name);
/**
* Returns the code (as a string) to call the plugin
* (this will be executed at runtime inside the Dwoo class).
*
* @param string $name the plugin name
* @param array $params a parameter array, array key "*" is the rest array
*
* @return string
*/
public function getCode($name, $params);
/**
* Returns a callback to the plugin, this is used with the reflection API to
* find out about the plugin's parameter names etc.
* should you need a rest array without the possibility to edit the
* plugin's code, you can provide a callback to some
* other function with the correct parameter signature, i.e. :
* <code>
* return array($this, "callbackHelper");
* // and callbackHelper would be as such:
* public function callbackHelper(array $rest=array()){}
* </code>
*
* @param string $name the plugin name
*
* @return callback
*/
public function getCallback($name);
/**
* Returns some code that will check if the plugin is loaded and if not load it
* this is optional, if your plugins are autoloaded or whatever, just return an
* empty string.
*
* @param string $name the plugin name
*
* @return string
*/
public function getLoader($name);
}

161
core/l/Dwoo/ITemplate.php Normal file
View File

@@ -0,0 +1,161 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.4
* @date 2017-03-07
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Interface that represents a dwoo template.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
interface ITemplate
{
/**
* Returns the cache duration for this template.
* defaults to null if it was not provided
*
* @return int|null
*/
public function getCacheTime();
/**
* Sets the cache duration for this template.
* can be used to set it after the object is created if you did not provide
* it in the constructor
*
* @param int $seconds duration of the cache validity for this template, if
* null it defaults to the Dwoo instance's cache time. 0 = disable and
* -1 = infinite cache
*/
public function setCacheTime($seconds = null);
/**
* Returns the cached template output file name, true if it's cache-able but not cached
* or false if it's not cached.
*
* @param Core $core the dwoo instance that requests it
*
* @return string|bool
*/
public function getCachedTemplate(Core $core);
/**
* Caches the provided output into the cache file.
*
* @param Core $core the dwoo instance that requests it
* @param string $output the template output
*
* @return mixed full path of the cached file or false upon failure
*/
public function cache(Core $core, $output);
/**
* Clears the cached template if it's older than the given time.
*
* @param Core $core the dwoo instance that was used to cache that template
* @param int $olderThan minimum time (in seconds) required for the cache to be cleared
*
* @return bool true if the cache was not present or if it was deleted, false if it remains there
*/
public function clearCache(Core $core, $olderThan = - 1);
/**
* Returns the compiled template file name.
*
* @param Core $core the dwoo instance that requests it
* @param ICompiler $compiler the compiler that must be used
*
* @return string
*/
public function getCompiledTemplate(Core $core, ICompiler $compiler = null);
/**
* Returns the template name.
*
* @return string
*/
public function getName();
/**
* Returns the resource name for this template class.
*
* @return string
*/
public function getResourceName();
/**
* Returns the resource identifier for this template or false if it has no identifier.
*
* @return string|false
*/
public function getResourceIdentifier();
/**
* Returns the template source of this template.
*
* @return string
*/
public function getSource();
/**
* Returns an unique string identifying the current version of this template,
* for example a timestamp of the last modified date or a hash of the template source.
*
* @return string
*/
public function getUid();
/**
* Returns the compiler used by this template, if it was just compiled, or null.
*
* @return ICompiler
*/
public function getCompiler();
/**
* Returns some php code that will check if this template has been modified or not.
* if the function returns null, the template will be instanciated and then the Uid checked
*
* @return string
*/
public function getIsModifiedCode();
/**
* Returns a new template object from the given resource identifier, null if no include is
* possible (resource not found), or false if include is not permitted by this resource type.
* this method should also check if $dwoo->getSecurityPolicy() is null or not and do the
* necessary permission checks if required, if the security policy prevents the template
* generation it should throw a new Security\Exception with a relevant message
*
* @param Core $core
* @param mixed $resourceId the resource identifier
* @param int $cacheTime duration of the cache validity for this template, if null it defaults to the
* Dwoo instance that will render this template if null it defaults to the Dwoo
* instance that will render this template
* @param string $cacheId the unique cache identifier of this page or anything else that makes this
* template's content unique, if null it defaults to the current url makes this
* template's content unique, if null it defaults to the current url
* @param string $compileId the unique compiled identifier, which is used to distinguish this template from
* others, if null it defaults to the filename+bits of the path template from
* others, if null it defaults to the filename+bits of the path
* @param ITemplate $parentTemplate the template that is requesting a new template object (through an include,
* extends or any other plugin) an include, extends or any other plugin)
*
* @return ITemplate|false|null
*/
public static function templateFactory(Core $core, $resourceId, $cacheTime = null, $cacheId = null,
$compileId = null, ITemplate $parentTemplate = null);
}

181
core/l/Dwoo/Loader.php Normal file
View File

@@ -0,0 +1,181 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE LGPLv3
* @version 1.4.0
* @date 2017-03-16
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Handles plugin loading and caching of plugins names/paths relationships.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class Loader implements ILoader
{
/**
* Stores the plugin directories.
*
* @see addDirectory
* @var array
*/
protected $paths = array();
/**
* Stores the plugins names/paths relationships
* don't edit this on your own, use addDirectory.
*
* @see addDirectory
* @var array
*/
protected $classPath = array();
/**
* Path where class paths cache files are written.
*
* @var string
*/
protected $cacheDir;
/**
* Path where builtin plugins are stored.
*
* @var string
*/
protected $corePluginDir;
/**
* Loader constructor.
*
* @param $cacheDir
*/
public function __construct($cacheDir)
{
$this->corePluginDir = __DIR__ . DIRECTORY_SEPARATOR;
$this->cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
// include class paths or rebuild paths if the cache file isn't there
$cacheFile = $this->cacheDir . 'classpath.cache.d' . Core::RELEASE_TAG . '.php';
if (file_exists($cacheFile)) {
$classpath = file_get_contents($cacheFile);
$this->classPath = unserialize($classpath) + $this->classPath;
} else {
$this->rebuildClassPathCache($this->corePluginDir, $cacheFile);
}
}
/**
* Rebuilds class paths, scans the given directory recursively and saves all paths in the given file.
*
* @param string $path the plugin path to scan
* @param string|boolean $cacheFile the file where to store the plugin paths cache, it will be overwritten
*
* @throws Exception
*/
protected function rebuildClassPathCache($path, $cacheFile)
{
$tmp = array();
if ($cacheFile !== false) {
$tmp = $this->classPath;
$this->classPath = array();
}
// iterates over all files/folders
foreach (new \DirectoryIterator($path) as $fileInfo) {
if (!$fileInfo->isDot()) {
if ($fileInfo->isDir()) {
$this->rebuildClassPathCache($fileInfo->getPathname(), false);
} else {
$this->classPath[$fileInfo->getBasename('.php')] = $fileInfo->getPathname();
}
}
}
// save in file if it's the first call (not recursed)
if ($cacheFile !== false) {
if (!file_put_contents($cacheFile, serialize($this->classPath))) {
throw new Exception('Could not write into ' . $cacheFile . ', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()');
}
$this->classPath += $tmp;
}
}
/**
* Loads a plugin file.
*
* @param string $class the plugin name, without the `Plugin` prefix
* @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it
* has just been added, defaults to true
*
* @throws Exception
*/
public function loadPlugin($class, $forceRehash = true)
{
/**
* An unknown class was requested (maybe newly added) or the
* include failed so we rebuild the cache. include() will fail
* with an uncatchable error if the file doesn't exist, which
* usually means that the cache is stale and must be rebuilt,
* so we check for that before trying to include() the plugin.
*/
if ((!isset($this->classPath[$class]) || !is_readable($this->classPath[$class])) || (!isset
($this->classPath[$class . 'Compile']) || !is_readable($this->classPath[$class . 'Compile']))) {
if ($forceRehash) {
$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d' .
Core::RELEASE_TAG . '.php');
foreach ($this->paths as $path => $file) {
$this->rebuildClassPathCache($path, $file);
}
if (isset($this->classPath[$class])) {
include_once $this->classPath[$class];
} elseif (isset($this->classPath[$class . 'Compile'])) {
include_once $this->classPath[$class . 'Compile'];
} else {
throw new Exception('Plugin "' . $class . '" can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
}
} else {
throw new Exception('Plugin "' . $class . '" can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
}
}
}
/**
* Adds a plugin directory, the plugins found in the new plugin directory
* will take precedence over the other directories (including the default
* dwoo plugin directory), you can use this for example to override plugins
* in a specific directory for a specific application while keeping all your
* usual plugins in the same place for all applications.
* TOCOM don't forget that php functions overrides are not rehashed so you
* need to clear the classpath caches by hand when adding those.
*
* @param string $pluginDirectory the plugin path to scan
*
* @throws Exception
*/
public function addDirectory($pluginDirectory)
{
$pluginDir = realpath($pluginDirectory);
if (!$pluginDir) {
throw new Exception('Plugin directory does not exist or can not be read : ' . $pluginDirectory);
}
$cacheFile = $this->cacheDir . 'classpath-' . substr(strtr($pluginDir, '/\\:' . PATH_SEPARATOR, '----'),
strlen($pluginDir) > 80 ? - 80 : 0) . '.d' . Core::RELEASE_TAG . '.php';
$this->paths[$pluginDir] = $cacheFile;
if (file_exists($cacheFile)) {
$classpath = file_get_contents($cacheFile);
$this->classPath = unserialize($classpath) + $this->classPath;
} else {
$this->rebuildClassPathCache($pluginDir, $cacheFile);
}
}
}

105
core/l/Dwoo/Plugin.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-23
* @link http://dwoo.org/
*/
namespace Dwoo;
/**
* Base plugin class.
* you have to implement the <em>process()</em> method, it will receive the parameters that
* are in the template code
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
abstract class Plugin
{
/**
* The dwoo instance that runs this plugin.
*
* @var Core
*/
protected $core;
/**
* Constructor, if you override it, call parent::__construct($core); or assign
* the dwoo instance yourself if you need it.
*
* @param Core $core the dwoo instance that runs this plugin
*/
public function __construct(Core $core)
{
$this->core = $core;
}
// plugins should always implement :
// public function process($arg, $arg, ...)
// or for block plugins :
// public function init($arg, $arg, ...)
// this could be enforced with :
// abstract public function process(...);
// if my feature request gets enough interest one day
// see => http://bugs.php.net/bug.php?id=44043
/**
* Utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag
* attributes. this is to be used in preProcessing or postProcessing functions, example :
* $p = $compiler->getCompiledParams($params);
* // get only the rest array as attributes
* $attributes = Plugin::paramsToAttributes($p['*']);
* // get all the parameters as attributes (if there is a rest array, it will be included)
* $attributes = Plugin::paramsToAttributes($p);
*
* @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string
* inclusion in a php string
* @param string $delim the string delimiter you want to use (defaults to ')
* @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior)
* escaping behavior)
*
* @return string
*/
public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null)
{
if (isset($params['*'])) {
$params = array_merge($params, $params['*']);
unset($params['*']);
}
$out = '';
foreach ($params as $attr => $val) {
$out .= ' ' . $attr . '=';
if (trim($val, '"\'') == '' || $val == 'null') {
$out .= str_replace($delim, '\\' . $delim, '""');
} elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) {
$out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"');
} else {
if (!$compiler) {
// disable double encoding since it can not be determined if it was encoded
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).';
} elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) {
// escape if auto escaping is disabled, or there was no variable in the string
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).';
} else {
// print as is
$escapedVal = '.' . $val . '.';
}
$out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"');
}
}
return ltrim($out);
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Outputs a html &lt;a&gt; tag
* <pre>
* * href : the target URI where the link must point
* * rest : any other attributes you want to add to the tag can be added as named parameters
* </pre>.
* Example :
* <code>
* {* Create a simple link out of an url variable and add a special class attribute: *}
* {a $url class="external" /}
* {* Mark a link as active depending on some other variable : *}
* {a $link.url class=tif($link.active "active"); $link.title /}
* {* This is similar to: <a href="{$link.url}" class="{if $link.active}active{/if}">{$link.title}</a> *}
* </code>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginA extends BlockPlugin implements ICompilableBlock
{
/**
* @param $href
* @param array $rest
*/
public function init($href, array $rest = array())
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$p = $compiler->getCompiledParams($params);
$out = Compiler::PHP_OPEN . 'echo \'<a ' . self::paramsToAttributes($p, "'", $compiler);
return $out . '>\';' . Compiler::PHP_CLOSE;
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$p = $compiler->getCompiledParams($params);
// no content was provided so use the url as display text
if ($content == '') {
// merge </a> into the href if href is a string
if (substr($p['href'], - 1) === '"' || substr($p['href'], - 1) === '\'') {
return Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, - 1) . '</a>' . substr($p['href'], - 1) . ';' . Compiler::PHP_CLOSE;
}
// otherwise append
return Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Compiler::PHP_CLOSE;
}
// return content
return $content . '</a>';
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
use Dwoo\Compilation\Exception as CompilationException;
/**
* Overrides the compiler auto-escape setting within the block
* <pre>
* * enabled : if set to "on", "enable", true or 1 then the compiler autoescaping is enabled inside this block. set to
* "off", "disable", false or 0 to disable it
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginAutoEscape extends BlockPlugin implements ICompilableBlock
{
protected static $stack = array();
/**
* @param $enabled
*/
public function init($enabled)
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
* @throws CompilationException
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$params = $compiler->getCompiledParams($params);
switch (strtolower(trim((string)$params['enabled'], '"\''))) {
case 'on':
case 'true':
case 'enabled':
case 'enable':
case '1':
$enable = true;
break;
case 'off':
case 'false':
case 'disabled':
case 'disable':
case '0':
$enable = false;
break;
default:
throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false');
}
self::$stack[] = $compiler->getAutoEscape();
$compiler->setAutoEscape($enable);
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$compiler->setAutoEscape(array_pop(self::$stack));
return $content;
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* This is used only when rendering a template that has blocks but is not extending anything,
* it doesn't do anything by itself and should not be used outside of template inheritance context,
* see {@link http://wiki.dwoo.org/index.php/TemplateInheritance} to read more about it.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginBlock extends BlockPlugin implements ICompilableBlock
{
/**
* @param string $name
*/
public function init($name = '')
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
return $content;
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Captures all the output within this block and saves it into {$.capture.default} by default,
* or {$.capture.name} if you provide another name.
* <pre>
* * name : capture name, used to read the value afterwards
* * assign : if set, the value is also saved in the given variable
* * cat : if true, the value is appended to the previous one (if any) instead of overwriting it
* </pre>
* If the cat parameter is true, the content
* will be appended to the existing content.
* Example :
* <code>
* {capture "foo"}
* Anything in here won't show, it will be saved for later use..
* {/capture}
* Output was : {$.capture.foo}
* </code>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCapture extends BlockPlugin implements ICompilableBlock
{
/**
* @param string $name
* @param null $assign
* @param bool $cat
* @param bool $trim
*/
public function init($name = 'default', $assign = null, $cat = false, $trim = false)
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
return Compiler::PHP_OPEN . $prepend . 'ob_start();' . $append . Compiler::PHP_CLOSE;
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$params = $compiler->getCompiledParams($params);
$out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();';
if ($params['trim'] !== 'false' && $params['trim'] !== 0) {
$out .= "\n" . '$tmp = trim($tmp);';
}
if ($params['cat'] === 'true' || $params['cat'] === 1) {
$out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;';
}
if ($params['assign'] !== 'null') {
$out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;';
}
return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Compiler::PHP_CLOSE;
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
use Dwoo\Compilation\Exception as CompilationException;
/**
* Marks the contents of the block as dynamic. Which means that it will not be cached.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginDynamic extends BlockPlugin implements ICompilableBlock
{
/**
*
*/
public function init()
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
try {
$compiler->findBlock('dynamic');
return $content;
}
catch (CompilationException $e) {
}
$output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t";
if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) {
$output .= substr($content, strlen(Compiler::PHP_OPEN));
} else {
$output .= Compiler::PHP_CLOSE . $content;
}
if (substr($output, - strlen(Compiler::PHP_CLOSE)) == Compiler::PHP_CLOSE) {
$output = substr($output, 0, - strlen(Compiler::PHP_CLOSE));
} else {
$output .= Compiler::PHP_OPEN;
}
$output .= "\n}" . Compiler::PHP_CLOSE;
return $output;
}
/**
* @param $output
* @param $dynamicId
* @param $compiledFile
*
* @return mixed|string
*/
public static function unescape($output, $dynamicId, $compiledFile)
{
$output = preg_replace_callback('/<dwoo:dynamic_(' . $dynamicId . ')>(.+?)<\/dwoo:dynamic_' . $dynamicId . '>/s', array(
'self',
'unescapePhp'
), $output, - 1, $count);
// re-add the includes on top of the file
if ($count && preg_match('#/\* template head \*/(.+?)/\* end template head \*/#s', file_get_contents($compiledFile), $m)) {
$output = '<?php ' . $m[1] . ' ?>' . $output;
}
return $output;
}
/**
* @param $match
*
* @return mixed
*/
public static function unescapePhp($match)
{
return preg_replace('{<\?php /\*' . $match[1] . '\*/ echo \'(.+?)\'; \?>}s', '$1', $match[2]);
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
use Dwoo\Compilation\Exception as CompilationException;
/**
* Generic else block, it supports all builtin optional-display blocks which are if/for/foreach/loop/with.
* If any of those block contains an else statement, the content between {else} and {/block} (you do not
* need to close the else block) will be shown if the block's condition has no been met
* Example :
* <code>
* {foreach $array val}
* $array is not empty so we display it's values : {$val}
* {else}
* if this shows, it means that $array is empty or doesn't exist.
* {/foreach}
* </code>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginElse extends BlockPlugin implements ICompilableBlock
{
public function init()
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
* @throws CompilationException
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$preContent = '';
while (true) {
$preContent .= $compiler->removeTopBlock();
$block = &$compiler->getCurrentBlock();
if (!$block) {
throw new CompilationException($compiler, 'An else block was found but it was not preceded by an if or other else-able construct');
}
$interfaces = class_implements($block['class']);
if (in_array('Dwoo\IElseable', $interfaces) !== false) {
break;
}
}
$params['initialized'] = true;
$compiler->injectBlock($type, $params);
return $preContent;
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
if (!isset($params['initialized'])) {
return '';
}
$block = &$compiler->getCurrentBlock();
$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
return '';
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\IElseable;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Acts as a php elseif block, allowing you to add one more condition
* if the previous one(s) didn't match. See the {if} plugin for syntax details.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginElseif extends PluginIf implements ICompilableBlock, IElseable
{
/**
* @param array $rest
*/
public function init(array $rest)
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$preContent = '';
while (true) {
$preContent .= $compiler->removeTopBlock();
$block = &$compiler->getCurrentBlock();
$interfaces = class_implements($block['class']);
if (in_array('Dwoo\IElseable', $interfaces) !== false) {
break;
}
}
$params['initialized'] = true;
$compiler->injectBlock($type, $params);
return $preContent;
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
if (!isset($params['initialized'])) {
return '';
}
$tokens = $compiler->getParamTokens($params);
$params = $compiler->getCompiledParams($params);
$pre = Compiler::PHP_OPEN . 'elseif (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE;
$post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$post .= $params['hasElse'];
}
$block = &$compiler->getCurrentBlock();
$block['params']['hasElse'] = $pre . $content . $post;
return '';
}
}

View File

@@ -0,0 +1,192 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\IElseable;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Similar to the php for block
* <pre>
* * name : for name to access it's iterator variables through {$.for.name.var} see {@link
* http://wiki.dwoo.org/index.php/IteratorVariables} for details
* * from : array to iterate from (which equals 0) or a number as a start value
* * to : value to stop iterating at (equals count($array) by default if you set an array in from)
* * step : defines the incrementation of the pointer at each iteration
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginFor extends BlockPlugin implements ICompilableBlock, IElseable
{
public static $cnt = 0;
/**
* @param $name
* @param $from
* @param null $to
* @param int $step
* @param int $skip
*/
public function init($name, $from, $to = null, $step = 1, $skip = 0)
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
// get block params and save the current template pointer to use it in the postProcessing method
$currentBlock = &$compiler->getCurrentBlock();
$currentBlock['params']['tplPointer'] = $compiler->getPointer();
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$params = $compiler->getCompiledParams($params);
$tpl = $compiler->getTemplateSource($params['tplPointer']);
// assigns params
$from = $params['from'];
$name = $params['name'];
$step = $params['step'];
$to = $params['to'];
// evaluates which global variables have to be computed
$varName = '$dwoo.for.' . trim($name, '"\'') . '.';
$shortVarName = '$.for.' . trim($name, '"\'') . '.';
$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
$usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
$usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
$usesIndex = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
$usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
$usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
$usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
if (strpos($name, '$this->scope[') !== false) {
$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
}
// gets foreach id
$cnt = self::$cnt ++;
// builds pre processing output for
$out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\n" . 'if (is_numeric($_for' . $cnt . '_from) && !is_numeric($_for' . $cnt . '_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }' . "\n" . '$tmp_shows = $this->isArray($_for' . $cnt . '_from, true) || (is_numeric($_for' . $cnt . '_from) && (abs(($_for' . $cnt . '_from - $_for' . $cnt . '_to)/$_for' . $cnt . '_step) !== 0 || $_for' . $cnt . '_from == $_for' . $cnt . '_to));';
// adds for properties
if ($usesAny) {
$out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n(";
if ($usesIndex) {
$out .= "\n\t" . '"index" => 0,';
}
if ($usesIteration) {
$out .= "\n\t" . '"iteration" => 1,';
}
if ($usesFirst) {
$out .= "\n\t" . '"first" => null,';
}
if ($usesLast) {
$out .= "\n\t" . '"last" => null,';
}
if ($usesShow) {
$out .= "\n\t" . '"show" => $tmp_shows,';
}
if ($usesTotal) {
$out .= "\n\t" . '"total" => $this->isArray($_for' . $cnt . '_from) ? floor($this->count($_for' . $cnt . '_from) / $_for' . $cnt . '_step) : (is_numeric($_for' . $cnt . '_from) ? abs(($_for' . $cnt . '_to + 1 - $_for' . $cnt . '_from)/$_for' . $cnt . '_step) : 0),';
}
$out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];';
}
// checks if for must be looped
$out .= "\n" . 'if ($tmp_shows)' . "\n{";
// set from/to to correct values if an array was given
$out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) {
$_for' . $cnt . '_to = is_numeric($_for' . $cnt . '_to) ? $_for' . $cnt . '_to - $_for' . $cnt . '_step : $this->count($_for' . $cnt . '_from) - 1;
$_for' . $cnt . '_from = 0;
}';
// if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used
$reverse = false;
$condition = '<=';
$incrementer = '+';
if (preg_match('{^(["\']?)([0-9]+)\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\1$}', $to, $mN2)) {
$from = (int)$mN1[2];
$to = (int)$mN2[2];
if ($from > $to) {
$reverse = true;
$condition = '>=';
$incrementer = '-';
}
}
// reverse from and to if needed
if (!$reverse) {
$out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) {
$tmp = $_for' . $cnt . '_from;
$_for' . $cnt . '_from = $_for' . $cnt . '_to;
$_for' . $cnt . '_to = $tmp;
}';
}
$out .= "\n\t" . 'for ($this->scope[' . $name . '] = $_for' . $cnt . '_from; $this->scope[' . $name . '] ' . $condition . ' $_for' . $cnt . '_to; $this->scope[' . $name . '] ' . $incrementer . '= $_for' . $cnt . '_step)' . "\n\t{";
// updates properties
if ($usesIndex) {
$out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];';
}
if ($usesFirst) {
$out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);';
}
if ($usesLast) {
$out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);';
}
$out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE;
// build post processing output and cache it
$postOut = Compiler::PHP_OPEN . '/* -- for end output */';
// update properties
if ($usesIteration) {
$postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;';
}
// end loop
$postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$postOut .= $params['hasElse'];
}
return $out . $content . $postOut;
}
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\IElseable;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
use Dwoo\Compilation\Exception as CompilationException;
/**
* Similar to the php foreach block, loops over an array.
* Note that if you don't provide the item parameter, the key will act as item
* <pre>
* * from : the array that you want to iterate over
* * key : variable name for the key (or for the item if item is not defined)
* * item : variable name for each item
* * name : foreach name to access it's iterator variables through {$.foreach.name.var} see {@link
* http://wiki.dwoo.org/index.php/IteratorVariables} for details
* </pre>
* Example :
* <code>
* {foreach $array val}
* {$val.something}
* {/foreach}
* </code>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginForeach extends BlockPlugin implements ICompilableBlock, IElseable
{
public static $cnt = 0;
/**
* @param $from
* @param null $key
* @param null $item
* @param string $name
* @param null $implode
*/
public function init($from, $key = null, $item = null, $name = 'default', $implode = null)
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
// get block params and save the current template pointer to use it in the postProcessing method
$currentBlock = &$compiler->getCurrentBlock();
$currentBlock['params']['tplPointer'] = $compiler->getPointer();
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
* @throws CompilationException
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$params = $compiler->getCompiledParams($params);
$tpl = $compiler->getTemplateSource($params['tplPointer']);
// assigns params
$src = $params['from'];
if ($params['item'] !== 'null') {
if ($params['key'] !== 'null') {
$key = $params['key'];
}
$val = $params['item'];
} elseif ($params['key'] !== 'null') {
$val = $params['key'];
} else {
throw new CompilationException($compiler, 'Foreach <em>item</em> parameter missing');
}
$name = $params['name'];
if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
throw new CompilationException($compiler, 'Foreach <em>item</em> parameter must be of type string');
}
if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') {
throw new CompilationException($compiler, 'Foreach <em>key</em> parameter must be of type string');
}
// evaluates which global variables have to be computed
$varName = '$dwoo.foreach.' . trim($name, '"\'') . '.';
$shortVarName = '$.foreach.' . trim($name, '"\'') . '.';
$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
$usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
$usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
$usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
$usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
$usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
$usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
if (strpos($name, '$this->scope[') !== false) {
$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
}
// override globals vars if implode is used
if ($params['implode'] !== 'null') {
$implode = $params['implode'];
$usesAny = true;
$usesLast = true;
$usesIteration = true;
$usesTotal = true;
}
// gets foreach id
$cnt = self::$cnt ++;
// build pre content output
$pre = Compiler::PHP_OPEN . "\n" . '$_fh' . $cnt . '_data = ' . $src . ';';
// adds foreach properties
if ($usesAny) {
$pre .= "\n" . '$this->globals["foreach"][' . $name . '] = array' . "\n(";
if ($usesIndex) {
$pre .= "\n\t" . '"index" => 0,';
}
if ($usesIteration) {
$pre .= "\n\t" . '"iteration" => 1,';
}
if ($usesFirst) {
$pre .= "\n\t" . '"first" => null,';
}
if ($usesLast) {
$pre .= "\n\t" . '"last" => null,';
}
if ($usesShow) {
$pre .= "\n\t" . '"show" => $this->isArray($_fh' . $cnt . '_data, true),';
}
if ($usesTotal) {
$pre .= "\n\t" . '"total" => $this->count($_fh' . $cnt . '_data),';
}
$pre .= "\n);\n" . '$_fh' . $cnt . '_glob =& $this->globals["foreach"][' . $name . '];';
}
// checks if foreach must be looped
$pre .= "\n" . 'if ($this->isTraversable($_fh' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{";
// iterates over keys
$pre .= "\n\t" . 'foreach ($_fh' . $cnt . '_data as ' . (isset($key) ? '$this->scope[' . $key . ']=>' : '') . '$this->scope[' . $val . '])' . "\n\t{";
// updates properties
if ($usesFirst) {
$pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["first"] = (string) ($_fh' . $cnt . '_glob["index"] === 0);';
}
if ($usesLast) {
$pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["last"] = (string) ($_fh' . $cnt . '_glob["iteration"] === $_fh' . $cnt . '_glob["total"]);';
}
$pre .= "\n/* -- foreach start output */\n" . Compiler::PHP_CLOSE;
// build post content output
$post = Compiler::PHP_OPEN . "\n";
if (isset($implode)) {
$post .= '/* -- implode */' . "\n" . 'if (!$_fh' . $cnt . '_glob["last"]) {' . "\n\t" . 'echo ' . $implode . ";\n}\n";
}
$post .= '/* -- foreach end output */';
// update properties
if ($usesIndex) {
$post .= "\n\t\t" . '$_fh' . $cnt . '_glob["index"]+=1;';
}
if ($usesIteration) {
$post .= "\n\t\t" . '$_fh' . $cnt . '_glob["iteration"]+=1;';
}
// end loop
$post .= "\n\t}\n}" . Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$post .= $params['hasElse'];
}
return $pre . $content . $post;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* This plugin serves as a {else} block specifically for the {foreach} plugin.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginForeachelse extends BlockPlugin implements ICompilableBlock
{
public function init()
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$with = &$compiler->findBlock('foreach', true);
$params['initialized'] = true;
$compiler->injectBlock($type, $params);
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
if (!isset($params['initialized'])) {
return '';
}
$block = &$compiler->getCurrentBlock();
$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
return '';
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* This plugin serves as a {else} block specifically for the {for} plugin.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginForelse extends BlockPlugin implements ICompilableBlock
{
public function init()
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$with = &$compiler->findBlock('for', true);
$params['initialized'] = true;
$compiler->injectBlock($type, $params);
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
if (!isset($params['initialized'])) {
return '';
}
$block = &$compiler->getCurrentBlock();
$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
return '';
}
}

View File

@@ -0,0 +1,274 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\IElseable;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
use Dwoo\Compilation\Exception as CompilationException;
/**
* Conditional block, the syntax is very similar to the php one, allowing () || && and
* other php operators. Additional operators and their equivalent php syntax are as follow :.
* eq -> ==
* neq or ne -> !=
* gte or ge -> >=
* lte or le -> <=
* gt -> >
* lt -> <
* mod -> %
* not -> !
* X is [not] div by Y -> (X % Y) == 0
* X is [not] even [by Y] -> (X % 2) == 0 or ((X/Y) % 2) == 0
* X is [not] odd [by Y] -> (X % 2) != 0 or ((X/Y) % 2) != 0
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginIf extends BlockPlugin implements ICompilableBlock, IElseable
{
/**
* @param array $rest
*/
public function init(array $rest)
{
}
/**
* @param array $params
* @param array $tokens
* @param Compiler $compiler
*
* @return array
* @throws CompilationException
*/
public static function replaceKeywords(array $params, array $tokens, Compiler $compiler)
{
$p = array();
reset($params);
while (list($k, $v) = each($params)) {
$v = (string)$v;
if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') {
$vmod = strtolower(substr($v, 1, - 1));
} else {
$vmod = strtolower($v);
}
switch ($vmod) {
case 'and':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '&&';
} else {
$p[] = $v;
}
break;
case 'or':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '||';
} else {
$p[] = $v;
}
break;
case 'xor':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '^';
} else {
$p[] = $v;
}
break;
case 'eq':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '==';
} else {
$p[] = $v;
}
break;
case 'ne':
case 'neq':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '!=';
} else {
$p[] = $v;
}
break;
case 'gte':
case 'ge':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '>=';
} else {
$p[] = $v;
}
break;
case 'lte':
case 'le':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '<=';
} else {
$p[] = $v;
}
break;
case 'gt':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '>';
} else {
$p[] = $v;
}
break;
case 'lt':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '<';
} else {
$p[] = $v;
}
break;
case 'mod':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '%';
} else {
$p[] = $v;
}
break;
case 'not':
if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) {
$p[] = '!';
} else {
$p[] = $v;
}
break;
case '<>':
$p[] = '!=';
break;
case '==':
case '!=':
case '>=':
case '<=':
case '>':
case '<':
case '===':
case '!==':
case '%':
case '!':
case '^':
$p[] = $vmod;
break;
case 'is':
if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) {
$p[] = $v;
break;
}
if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) {
$negate = true;
next($params);
} else {
$negate = false;
}
$ptr = 1 + (int)$negate;
if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) {
break;
}
if (!isset($params[$k + $ptr])) {
$params[$k + $ptr] = '';
} else {
$params[$k + $ptr] = trim($params[$k + $ptr], '"\'');
}
switch ($params[$k + $ptr]) {
case 'div':
if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') {
$p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0';
next($params);
next($params);
next($params);
} else {
throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]);
}
break;
case 'even':
$a = array_pop($p);
if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') {
$b = $params[$k + $ptr + 2];
$p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0';
next($params);
next($params);
} else {
$p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0';
}
next($params);
break;
case 'odd':
$a = array_pop($p);
if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') {
$b = $params[$k + $ptr + 2];
$p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0';
next($params);
next($params);
} else {
$p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0';
}
next($params);
break;
default:
throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]);
}
break;
default:
$p[] = $v;
}
}
return $p;
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$tokens = $compiler->getParamTokens($params);
$params = $compiler->getCompiledParams($params);
$pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE;
$post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$post .= $params['hasElse'];
}
return $pre . $content . $post;
}
}

View File

@@ -0,0 +1,170 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\IElseable;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Loops over an array and moves the scope into each value, allowing for shorter loop constructs.
* Note that to access the array key within a loop block, you have to use the {$_key} variable,
* you can not specify it yourself.
* <pre>
* * from : the array that you want to iterate over
* * name : loop name to access it's iterator variables through {$.loop.name.var} see {@link
* http://wiki.dwoo.org/index.php/IteratorVariables} for details
* </pre>
* Example :
* instead of a foreach block such as :
* <code>
* {foreach $variable value}
* {$value.foo} {$value.bar}
* {/foreach}
* </code>
* you can do :
* <code>
* {loop $variable}
* {$foo} {$bar}
* {/loop}
* </code>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginLoop extends BlockPlugin implements ICompilableBlock, IElseable
{
public static $cnt = 0;
/**
* @param $from
* @param string $name
*/
public function init($from, $name = 'default')
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
// get block params and save the current template pointer to use it in the postProcessing method
$currentBlock = &$compiler->getCurrentBlock();
$currentBlock['params']['tplPointer'] = $compiler->getPointer();
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$params = $compiler->getCompiledParams($params);
$tpl = $compiler->getTemplateSource($params['tplPointer']);
// assigns params
$src = $params['from'];
$name = $params['name'];
// evaluates which global variables have to be computed
$varName = '$dwoo.loop.' . trim($name, '"\'') . '.';
$shortVarName = '$.loop.' . trim($name, '"\'') . '.';
$usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false;
$usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false;
$usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false;
$usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false;
$usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false;
$usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false;
$usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false;
if (strpos($name, '$this->scope[') !== false) {
$usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true;
}
// gets foreach id
$cnt = self::$cnt ++;
// builds pre processing output
$pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';';
// adds foreach properties
if ($usesAny) {
$pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n(";
if ($usesIndex) {
$pre .= "\n\t" . '"index" => 0,';
}
if ($usesIteration) {
$pre .= "\n\t" . '"iteration" => 1,';
}
if ($usesFirst) {
$pre .= "\n\t" . '"first" => null,';
}
if ($usesLast) {
$pre .= "\n\t" . '"last" => null,';
}
if ($usesShow) {
$pre .= "\n\t" . '"show" => $this->isTraversable($_loop' . $cnt . '_data, true),';
}
if ($usesTotal) {
$pre .= "\n\t" . '"total" => $this->count($_loop' . $cnt . '_data),';
}
$pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];';
}
// checks if the loop must be looped
$pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{";
// iterates over keys
$pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{";
// updates properties
if ($usesFirst) {
$pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);';
}
if ($usesLast) {
$pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);';
}
$pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE;
// build post processing output and cache it
$post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);';
// update properties
if ($usesIndex) {
$post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;';
}
if ($usesIteration) {
$post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;';
}
// end loop
$post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$post .= $params['hasElse'];
}
return $pre . $content . $post;
}
}

View File

@@ -0,0 +1,159 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\IElseable;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Compatibility plugin for smarty templates, do not use otherwise, this is deprecated.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginSection extends BlockPlugin implements ICompilableBlock, IElseable
{
public static $cnt = 0;
/**
* @param $name
* @param $loop
* @param null $start
* @param null $step
* @param null $max
* @param bool $show
*/
public function init($name, $loop, $start = null, $step = null, $max = null, $show = true)
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$output = Compiler::PHP_OPEN;
$params = $compiler->getCompiledParams($params);
// assigns params
$loop = $params['loop'];
$start = $params['start'];
$max = $params['max'];
$name = $params['name'];
$step = $params['step'];
$show = $params['show'];
// gets unique id
$cnt = self::$cnt ++;
$output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n";
if ($loop !== 'null') {
$output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n";
} else {
$output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n";
}
if ($show !== 'null') {
$output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n";
} else {
$output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n";
}
if ($name !== 'null') {
$output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n";
} else {
$output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n";
}
if ($max !== 'null') {
$output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n";
} else {
$output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
}
if ($step !== 'null') {
$output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n";
} else {
$output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n";
}
if ($start !== 'null') {
$output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n";
} else {
$output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n";
}
/* if ($usesAny) {
$output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n(";
if ($usesIndex) $output .="\n\t".'"index" => 0,';
if ($usesIteration) $output .="\n\t".'"iteration" => 1,';
if ($usesFirst) $output .="\n\t".'"first" => null,';
if ($usesLast) $output .="\n\t".'"last" => null,';
if ($usesShow) $output .="\n\t".'"show" => ($this->isArray($_for'.$cnt.'_from, true)) || (is_numeric($_for'.$cnt.'_from) && $_for'.$cnt.'_from != $_for'.$cnt.'_to),';
if ($usesTotal) $output .="\n\t".'"total" => $this->isArray($_for'.$cnt.'_from) ? $this->count($_for'.$cnt.'_from) - $_for'.$cnt.'_skip : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),';
$out.="\n);\n".'$_section'.$cnt.'[\'glob\'] =& $this->globals["section"]['.$name.'];'."\n\n";
}
*/
$output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
if ($start === 'null' && $step === 'null' && $max === 'null') {
$output .= ' $_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
} else {
$output .= ' $_section' . $cnt . '[\'total\'] = min(ceil(($_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] - $_section' . $cnt . '[\'start\'] : $_section' . $cnt . '[\'start\'] + 1) / abs($_section' . $cnt . '[\'step\'])), $_section' . $cnt . '[\'max\']);' . "\n";
}
$output .= ' if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . ' $_section' . $cnt . '[\'show\'] = false;' . "\n" . ' }' . "\n" . '} else {' . "\n" . ' $_section' . $cnt . '[\'total\'] = 0;' . "\n}\n";
$output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
$output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n";
$output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n";
$output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n";
$output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n";
$output .= "\t\t" . '$_section' . $cnt . '[\'first\'] = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n";
$output .= "\t\t" . '$_section' . $cnt . '[\'last\'] = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n";
$output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN;
$output .= "\n\t}\n} " . Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$output .= $params['hasElse'];
}
return $output;
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE LGPLv3
* @version 1.3.6
* @date 2017-03-21
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Core;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Smarty compatibility layer for block plugins, this is used internally and you should not call it.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginSmartyinterface extends BlockPlugin implements ICompilableBlock
{
/**
* @param $__funcname
* @param $__functype
* @param array $rest
*/
public function init($__funcname, $__functype, array $rest = array())
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$params = $compiler->getCompiledParams($params);
$func = $params['__funcname'];
$pluginType = $params['__functype'];
$params = $params['*'];
if ($pluginType & Core::CUSTOM_PLUGIN) {
$customPlugins = $compiler->getCore()->getCustomPlugins();
$callback = $customPlugins[$func]['callback'];
if (is_array($callback)) {
if (is_object($callback[0])) {
$callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '(';
} else {
$callback = '' . $callback[0] . '::' . $callback[1] . '(';
}
} else {
$callback = $callback . '(';
}
} else {
$callback = 'smarty_block_' . $func . '(';
}
$paramsOut = '';
foreach ($params as $i => $p) {
$paramsOut .= var_export($i, true) . ' => ' . $p . ',';
}
$curBlock = &$compiler->getCurrentBlock();
$curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE;
return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE;
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
return $content . $params['postOut'];
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Strips the spaces at the beginning and end of each line and also the line breaks
* <pre>
* * mode : sets the content being stripped, available mode are 'default' or 'js'
* for javascript, which strips the comments to prevent syntax errors
* </pre>.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginStrip extends BlockPlugin implements ICompilableBlock
{
/**
* @param string $mode
*/
public function init($mode = 'default')
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return mixed|string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$params = $compiler->getCompiledParams($params);
$mode = trim($params['mode'], '"\'');
switch ($mode) {
case 'js':
case 'javascript':
$content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);
case 'default':
default:
}
$content = preg_replace(array(
"/\n/",
"/\r/",
'/(<\?(?:php)?|<%)\s*/'
), array(
'',
'',
'$1 '
), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));
return $content;
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-20
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Core;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
use Dwoo\Compilation\Exception as CompilationException;
/**
* Defines a sub-template that can then be called (even recursively) with the defined arguments
* <pre>
* * name : template name
* * rest : list of arguments and optional default values
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginTemplate extends BlockPlugin implements ICompilableBlock
{
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
* @throws CompilationException
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$params = $compiler->getCompiledParams($params);
$parsedParams = array();
if (!isset($params['*'])) {
$params['*'] = array();
}
foreach ($params['*'] as $param => $defValue) {
if (is_numeric($param)) {
$param = $defValue;
$defValue = null;
}
$param = trim($param, '\'"');
if (!preg_match('#^[a-z0-9_]+$#i', $param)) {
throw new CompilationException($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _');
}
$parsedParams[$param] = $defValue;
}
$params['name'] = substr($params['name'], 1, - 1);
$params['*'] = $parsedParams;
$params['uuid'] = uniqid();
$compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']);
$currentBlock = &$compiler->getCurrentBlock();
$currentBlock['params'] = $params;
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string|void
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$paramstr = 'Dwoo\Core $dwoo';
$init = 'static $_callCnt = 0;' . "\n" . '$dwoo->scope[\' ' . $params['uuid'] . '\'.$_callCnt] = array();' . "\n" . '$_scope = $dwoo->setScope(array(\' ' . $params['uuid'] . '\'.($_callCnt++)));' . "\n";
$cleanup = '/* -- template end output */ $dwoo->setScope($_scope, true);';
foreach ($params['*'] as $param => $defValue) {
if ($defValue === null) {
$paramstr .= ', $' . $param;
} else {
$paramstr .= ', $' . $param . ' = ' . $defValue;
}
$init .= '$dwoo->scope[\'' . $param . '\'] = $' . $param . ";\n";
}
$init .= '/* -- template start output */';
$funcName = 'Plugin' . Core::toCamelCase($params['name']) . Core::toCamelCase($params['uuid']);
$search = array('$this->charset', '$this->', '$this,',);
$replacement = array('$dwoo->getCharset()', '$dwoo->', '$dwoo,',);
$content = str_replace($search, $replacement, $content);
$body = 'if (!function_exists(\'' . $funcName . "')) {\nfunction " . $funcName . '(' . $paramstr . ') {' . "\n$init" . Compiler::PHP_CLOSE . $prepend . $content . $append . Compiler::PHP_OPEN . $cleanup . "\n}\n}";
$compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body);
}
/**
* @param $name
* @param array $rest
*/
public function init($name, array $rest = array())
{
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Block\Plugin as BlockPlugin;
/**
* Formats a string to the given format, you can wrap lines at a certain
* length and indent them
* <pre>
* * wrap : maximum line length
* * wrap_char : the character(s) to use to break the line
* * wrap_cut : if true, the words that are longer than $wrap are cut instead of overflowing
* * indent : amount of $indent_char to insert before every line
* * indent_char : character(s) to insert before every line
* * indent_first : amount of additional $indent_char to insert before the first line of each paragraphs
* * style : some predefined formatting styles that set up every required variables, can be "email" or "html"
* * assign : if set, the formatted text is assigned to that variable instead of being output
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginTextformat extends BlockPlugin
{
protected $wrap;
protected $wrapChar;
protected $wrapCut;
protected $indent;
protected $indChar;
protected $indFirst;
protected $assign;
/**
* @param int $wrap
* @param string $wrap_char
* @param bool $wrap_cut
* @param int $indent
* @param string $indent_char
* @param int $indent_first
* @param string $style
* @param string $assign
*/
public function init($wrap = 80, $wrap_char = "\r\n", $wrap_cut = false, $indent = 0, $indent_char = ' ', $indent_first = 0, $style = '', $assign = '')
{
if ($indent_char === 'tab') {
$indent_char = "\t";
}
switch ($style) {
case 'email':
$wrap = 72;
$indent_first = 0;
break;
case 'html':
$wrap_char = '<br />';
$indent_char = $indent_char == "\t" ? '&nbsp;&nbsp;&nbsp;&nbsp;' : '&nbsp;';
break;
}
$this->wrap = (int)$wrap;
$this->wrapChar = (string)$wrap_char;
$this->wrapCut = (bool)$wrap_cut;
$this->indent = (int)$indent;
$this->indChar = (string)$indent_char;
$this->indFirst = (int)$indent_first + $this->indent;
$this->assign = (string)$assign;
}
/**
* @return string
*/
public function process()
{
// gets paragraphs
$pgs = explode("\n", str_replace(array(
"\r\n",
"\r"
), "\n", $this->buffer));
while (list($i) = each($pgs)) {
if (empty($pgs[$i])) {
continue;
}
// removes line breaks and extensive white space
$pgs[$i] = preg_replace(array(
'#\s+#',
'#^\s*(.+?)\s*$#m'
), array(
' ',
'$1'
), str_replace("\n", '', $pgs[$i]));
// wordwraps + indents lines
$pgs[$i] = str_repeat($this->indChar, $this->indFirst) . wordwrap($pgs[$i], max($this->wrap - $this->indent, 1), $this->wrapChar . str_repeat($this->indChar, $this->indent), $this->wrapCut);
}
if ($this->assign !== '') {
$this->core->assignInScope(implode($this->wrapChar . $this->wrapChar, $pgs), $this->assign);
} else {
return implode($this->wrapChar . $this->wrapChar, $pgs);
}
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Internal plugin used to wrap the template output, do not use in your templates as it will break them.
* This software is provided 'as-is', without any express or implied warranty.
*/
final class PluginTopLevelBlock extends BlockPlugin implements ICompilableBlock
{
public function init()
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
return '/* end template head */ ob_start(); /* template body */ ' . Compiler::PHP_CLOSE;
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
return $content . Compiler::PHP_OPEN . ' /* end template body */' . "\n" . 'return $this->buffer . ob_get_clean();';
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\IElseable;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* Moves the scope down into the provided variable, allowing you to use shorter
* variable names if you repeatedly access values into a single array.
* The with block won't display anything at all if the provided scope is empty,
* so in effect it acts as {if $var}*content*{/if}
* <pre>
* * var : the variable name to move into
* </pre>
* Example :
* instead of the following :
* <code>
* {if $long.boring.prefix}
* {$long.boring.prefix.val} - {$long.boring.prefix.secondVal} - {$long.boring.prefix.thirdVal}
* {/if}
* </code>
* you can use :
* <code>
* {with $long.boring.prefix}
* {$val} - {$secondVal} - {$thirdVal}
* {/with}
* </code>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginWith extends BlockPlugin implements ICompilableBlock, IElseable
{
protected static $cnt = 0;
/**
* @param $var
*/
public function init($var)
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
$rparams = $compiler->getRealParams($params);
$cparams = $compiler->getCompiledParams($params);
$compiler->setScope($rparams['var']);
$pre = Compiler::PHP_OPEN . 'if (' . $cparams['var'] . ')' . "\n{\n" . '$_with' . (self::$cnt) . ' = $this->setScope("' . $rparams['var'] . '");' . "\n/* -- start with output */\n" . Compiler::PHP_CLOSE;
$post = Compiler::PHP_OPEN . "\n/* -- end with output */\n" . '$this->setScope($_with' . (self::$cnt ++) . ', true);' . "\n}\n" . Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$post .= $params['hasElse'];
}
return $pre . $content . $post;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Blocks
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Blocks;
use Dwoo\Compiler;
use Dwoo\Block\Plugin as BlockPlugin;
use Dwoo\ICompilable\Block as ICompilableBlock;
/**
* This plugin serves as a {else} block specifically for the {with} plugin.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginWithelse extends BlockPlugin implements ICompilableBlock
{
public function init()
{
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $type
*
* @return string
*/
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
{
$with = &$compiler->findBlock('with', true);
$params['initialized'] = true;
$compiler->injectBlock($type, $params);
return '';
}
/**
* @param Compiler $compiler
* @param array $params
* @param string $prepend
* @param string $append
* @param string $content
*
* @return string
*/
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
{
if (!isset($params['initialized'])) {
return '';
}
$block = &$compiler->getCurrentBlock();
$block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
return '';
}
}

View File

@@ -0,0 +1,190 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Filters
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-18
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Filters;
use Dwoo\Filter;
/**
* Formats any html output (must be valid xml where every tag opened is closed)
* using a single tab for indenting. 'pre' and other whitespace sensitive
* tags should not be affected.
* It is not recommended to use this on every template if you render multiple
* templates per page, you should only use it once on the main page template so that
* everything is formatted in one pass.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginHtmlFormat extends Filter
{
/**
* tab count to auto-indent the source.
*
* @var int
*/
protected static $tabCount = - 1;
/**
* stores the additional data (following a tag) of the last call to open/close/singleTag.
*
* @var string
*/
protected static $lastCallAdd = '';
/**
* formats the input using the singleTag/closeTag/openTag functions.
* It is auto indenting the whole code, excluding <textarea>, <code> and <pre> tags that must be kept intact.
* Those tags must however contain only htmlentities-escaped text for everything to work properly.
* Inline tags are presented on a single line with their content
*
* @param string $input the xhtml to format
*
* @return string formatted xhtml
*/
public function process($input)
{
self::$tabCount = - 1;
// auto indent all but textareas & pre (or we have weird tabs inside)
$input = preg_replace_callback("#(<[^>]+>)(\s*)([^<]*)#", array(
'self',
'tagDispatcher'
), $input);
return $input;
}
/**
* helper function for format()'s preg_replace call.
*
* @param array $input array of matches (1=>tag, 2=>whitespace(optional), 3=>additional non-html content)
*
* @return string the indented tag
*/
protected static function tagDispatcher($input)
{
// textarea, pre, code tags and comments are to be left alone to avoid any non-wanted whitespace inside them so it just outputs them as they were
if (substr($input[1], 0, 9) == '<textarea' || substr($input[1], 0, 4) == '<pre' || substr($input[1], 0, 5) == '<code' || substr($input[1], 0, 4) == '<!--' || substr($input[1], 0, 9) == '<![CDATA[') {
return $input[1] . $input[3];
}
// closing textarea, code and pre tags and self-closed tags (i.e. <br />) are printed as singleTags because we didn't use openTag for the formers and the latter is a single tag
if (substr($input[1], 0, 10) == '</textarea' || substr($input[1], 0, 5) == '</pre' || substr($input[1], 0, 6) == '</code' || substr($input[1], - 2) == '/>') {
return self::singleTag($input[1], $input[3], $input[2]);
}
// it's the closing tag
if ($input[0][1] == '/') {
return self::closeTag($input[1], $input[3], $input[2]);
}
// opening tag
return self::openTag($input[1], $input[3], $input[2]);
}
/**
* returns an open tag and adds a tab into the auto indenting.
*
* @param string $tag content of the tag
* @param string $add additional data (anything before the following tag)
* @param string $whitespace white space between the tag and the additional data
*
* @return string
*/
protected static function openTag($tag, $add, $whitespace)
{
$tabs = str_pad('', self::$tabCount ++, "\t");
if (preg_match('#^<(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)(?: [^>]*|)>#', $tag)) {
// if it's one of those tag it's inline so it does not require a leading line break
$result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
} elseif (substr($tag, 0, 9) == '<!DOCTYPE') {
// it's the doctype declaration so no line break here either
$result = $tabs . $tag;
} else {
// normal block tag
$result = "\n" . $tabs . $tag;
if (!empty($add)) {
$result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
}
}
self::$lastCallAdd = $add;
return $result;
}
/**
* returns a closing tag and removes a tab from the auto indenting.
*
* @param string $tag content of the tag
* @param string $add additional data (anything before the following tag)
* @param string $whitespace white space between the tag and the additional data
*
* @return string
*/
protected static function closeTag($tag, $add, $whitespace)
{
$tabs = str_pad('', -- self::$tabCount, "\t");
// if it's one of those tag it's inline so it does not require a leading line break
if (preg_match('#^</(a|label|option|textarea|h1|h2|h3|h4|h5|h6|strong|b|em|i|abbr|acronym|cite|span|sub|sup|u|s|title)>#', $tag)) {
$result = $tag . $whitespace . str_replace("\n", "\n" . $tabs, $add);
} else {
$result = "\n" . $tabs . $tag;
if (!empty($add)) {
$result .= "\n" . $tabs . "\t" . str_replace("\n", "\n\t" . $tabs, $add);
}
}
self::$lastCallAdd = $add;
return $result;
}
/**
* returns a single tag with auto indenting.
*
* @param string $tag content of the tag
* @param string $add additional data (anything before the following tag)
*
* @return string
*/
protected static function singleTag($tag, $add, $whitespace)
{
$tabs = str_pad('', self::$tabCount, "\t");
// if it's img, br it's inline so it does not require a leading line break
// if it's a closing textarea, code or pre tag, it does not require a leading line break either or it creates whitespace at the end of those blocks
if (preg_match('#^<(img|br|/textarea|/pre|/code)(?: [^>]*|)>#', $tag)) {
$result = $tag . $whitespace;
if (!empty($add)) {
$result .= str_replace("\n", "\n" . $tabs, $add);
}
} else {
$result = "\n" . $tabs . $tag;
if (!empty($add)) {
$result .= "\n" . $tabs . str_replace("\n", "\n" . $tabs, $add);
}
}
self::$lastCallAdd = $add;
return $result;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Assigns a value to a variable
* <pre>
* * value : the value that you want to save
* * var : the variable name (without the leading $)
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginAssign extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param mixed $value
* @param mixed $var
*
* @return string
*/
public static function compile(Compiler $compiler, $value, $var)
{
return '$this->assignInScope(' . $value . ', ' . $var . ')';
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.4
* @date 2017-03-01
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Plugin;
/**
* Capitalizes the first letter of each word
* <pre>
* * value : the string to capitalize
* * numwords : if true, the words containing numbers are capitalized as well
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCapitalize extends Plugin
{
/**
* @param string $value
* @param bool $numwords
*
* @return string
*/
public function process($value, $numwords = false)
{
if ($numwords || preg_match('#^[^0-9]+$#', $value)) {
return mb_convert_case((string)$value, MB_CASE_TITLE, $this->core->getCharset());
} else {
$bits = explode(' ', (string)$value);
$out = '';
foreach ($bits as $k => $v){
if (preg_match('#^[^0-9]+$#', $v)) {
$out .= ' ' . mb_convert_case($v, MB_CASE_TITLE, $this->core->getCharset());
} else {
$out .= ' ' . $v;
}
}
return substr($out, 1);
}
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Concatenates any number of variables or strings fed into it
* <pre>
* * rest : two or more strings that will be merged into one
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCat extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param string $value
* @param array $rest
*
* @return string
*/
public static function compile(Compiler $compiler, $value, array $rest)
{
return '(' . $value . ').(' . implode(').(', $rest) . ')';
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Counts the characters in a string
* <pre>
* * value : the string to process
* * count_spaces : if true, the white-space characters are counted as well
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCountCharacters extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param string $value
* @param bool $count_spaces
*
* @return string
*/
public static function compile(Compiler $compiler, $value, $count_spaces = false)
{
if ($count_spaces === 'false') {
return 'preg_match_all(\'#[^\s\pZ]#u\', ' . $value . ', $tmp)';
}
return 'mb_strlen(' . $value . ', $this->charset)';
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Counts the paragraphs in a string
* <pre>
* * value : the string to process
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCountParagraphs extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param string $value
*
* @return string
*/
public static function compile(Compiler $compiler, $value)
{
return '(preg_match_all(\'#[\r\n]+#\', ' . $value . ', $tmp)+1)';
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Counts the sentences in a string
* <pre>
* * value : the string to process
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCountSentences extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param string $value
*
* @return string
*/
public static function compile(Compiler $compiler, $value)
{
return "preg_match_all('#[\\w\\pL]\\.(?![\\w\\pL])#u', $value, \$tmp)";
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Counts the words in a string
* <pre>
* * value : the string to process
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCountWords extends Plugin implements ICompilable
{
public static function compile(Compiler $compiler, $value)
{
return 'preg_match_all(strcasecmp($this->charset, \'utf-8\')===0 ? \'#[\w\pL]+#u\' : \'#\w+#\', ' . $value . ', $tmp)';
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* Copyright (c) 2013-2016
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2016 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.0
* @date 2016-09-19
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Plugin;
/**
* Initiates a counter that is incremented every time you call it
* <pre>
* * name : the counter name, define it if you want to have multiple concurrent counters
* * start : the start value, if it's set, it will reset the counter to this value, defaults to 1
* * skip : the value to add to the counter at each call, defaults to 1
* * direction : "up" (default) or "down" to define whether the counter increments or decrements
* * print : if false, the counter will not output the current count, defaults to true
* * assign : if set, the counter is saved into the given variable and does not output anything, overriding the print
* parameter
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCounter extends Plugin
{
protected $counters = array();
/**
* @param string $name
* @param null $start
* @param null $skip
* @param null $direction
* @param null $print
* @param null $assign
*
* @return mixed
*/
public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null)
{
// init counter
if (!isset($this->counters[$name])) {
$this->counters[$name] = array(
'count' => $start === null ? 1 : (int)$start,
'skip' => $skip === null ? 1 : (int)$skip,
'print' => $print === null ? true : (bool)$print,
'assign' => $assign === null ? null : (string)$assign,
'direction' => strtolower($direction) === 'down' ? - 1 : 1,
);
} // increment
else {
// override setting if present
if ($skip !== null) {
$this->counters[$name]['skip'] = (int)$skip;
}
if ($direction !== null) {
$this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1;
}
if ($print !== null) {
$this->counters[$name]['print'] = (bool)$print;
}
if ($assign !== null) {
$this->counters[$name]['assign'] = (string)$assign;
}
if ($start !== null) {
$this->counters[$name]['count'] = (int)$start;
} else {
$this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']);
}
}
$out = $this->counters[$name]['count'];
if ($this->counters[$name]['assign'] !== null) {
$this->core->assignInScope($out, $this->counters[$name]['assign']);
} elseif ($this->counters[$name]['print'] === true) {
return $out;
}
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Plugin;
/**
* Cycles between several values and returns one of them on each call
* <pre>
* * name : the cycler name, specify if you need to have multiple concurrent cycles running
* * values : an array of values or a string of values delimited by $delimiter
* * print : if false, the pointer will go to the next one but not print anything
* * advance : if false, the pointer will not advance to the next value
* * delimiter : the delimiter used to split values if they are provided as a string
* * assign : if set, the value is saved in that variable instead of being output
* * reset : if true, the pointer is reset to the first value
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginCycle extends Plugin
{
protected $cycles = array();
/**
* @param string $name
* @param null $values
* @param bool $print
* @param bool $advance
* @param string $delimiter
* @param null $assign
* @param bool $reset
*
* @return string|null
*/
public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false)
{
if ($values !== null) {
if (is_string($values)) {
$values = explode($delimiter, $values);
}
if (!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values) {
$this->cycles[$name]['index'] = 0;
}
$this->cycles[$name]['values'] = array_values($values);
} elseif (isset($this->cycles[$name])) {
$values = $this->cycles[$name]['values'];
}
if ($reset) {
$this->cycles[$name]['index'] = 0;
}
if ($print) {
$out = $values[$this->cycles[$name]['index']];
} else {
$out = null;
}
if ($advance) {
if ($this->cycles[$name]['index'] >= count($values) - 1) {
$this->cycles[$name]['index'] = 0;
} else {
++ $this->cycles[$name]['index'];
}
}
if ($assign === null) {
return $out;
}
$this->core->assignInScope($out, $assign);
return null;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Core;
use Dwoo\Plugin;
/**
* Formats a date
* <pre>
* * value : the date, as a unix timestamp, mysql datetime or whatever strtotime() can parse
* * format : output format, see {@link http://php.net/strftime} for details
* * default : a default timestamp value, if the first one is empty
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginDateFormat extends Plugin
{
/**
* @param mixed $value
* @param string $format
* @param null $default
*
* @return string
*/
public function process($value, $format = '%b %e, %Y', $default = null)
{
if (!empty($value)) {
// convert if it's not a valid unix timestamp
if (preg_match('#^-?\d{1,10}$#', $value) === 0) {
$value = strtotime($value);
}
} elseif (!empty($default)) {
// convert if it's not a valid unix timestamp
if (preg_match('#^-?\d{1,10}$#', $default) === 0) {
$value = strtotime($default);
} else {
$value = $default;
}
} else {
return '';
}
// Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin
if (DIRECTORY_SEPARATOR == '\\') {
$_win_from = array(
'%D',
'%h',
'%n',
'%r',
'%R',
'%t',
'%T'
);
$_win_to = array(
'%m/%d/%y',
'%b',
"\n",
'%I:%M:%S %p',
'%H:%M',
"\t",
'%H:%M:%S'
);
if (strpos($format, '%e') !== false) {
$_win_from[] = '%e';
$_win_to[] = sprintf('%\' 2d', date('j', $value));
}
if (strpos($format, '%l') !== false) {
$_win_from[] = '%l';
$_win_to[] = sprintf('%\' 2d', date('h', $value));
}
$format = str_replace($_win_from, $_win_to, $format);
}
return strftime($format, $value);
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Returns a variable or a default value if it's empty
* <pre>
* * value : the variable to check
* * default : fallback value if the first one is empty
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginDefault extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param mixed $value
* @param string $default
*
* @return string
*/
public static function compile(Compiler $compiler, $value, $default = '')
{
return '(($tmp = ' . $value . ')===null||$tmp===\'\' ? ' . $default . ' : $tmp)';
}
}

View File

@@ -0,0 +1,210 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Plugin;
use Iterator;
use ReflectionObject;
/**
* Dumps values of the given variable, or the entire data if nothing provided
* <pre>
* * var : the variable to display
* * show_methods : if set to true, the public methods of any object encountered are also displayed
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginDump extends Plugin
{
protected $outputObjects;
protected $outputMethods;
/**
* @param string $var
* @param bool $show_methods
*
* @return string
*/
public function process($var = '$', $show_methods = false)
{
$this->outputMethods = $show_methods;
if ($var === '$') {
$var = $this->core->getData();
$out = '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">data';
} else {
$out = '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">dump';
}
$this->outputObjects = array();
if (!is_array($var)) {
if (is_object($var)) {
return $this->exportObj('', $var);
} else {
return $this->exportVar('', $var);
}
}
$scope = $this->core->getScope();
if ($var === $scope) {
$out .= ' (current scope): <div style="background:#ccc;">';
} else {
$out .= ':<div style="padding-left:20px;">';
}
$out .= $this->export($var, $scope);
return $out . '</div></div>';
}
/**
* @param $var
* @param $scope
*
* @return string
*/
protected function export($var, $scope)
{
$out = '';
foreach ($var as $i => $v) {
if (is_array($v) || (is_object($v) && $v instanceof Iterator)) {
$out .= $i . ' (' . (is_array($v) ? 'array' : 'object: ' . get_class($v)) . ')';
if ($v === $scope) {
$out .= ' (current scope):<div style="background:#ccc;padding-left:20px;">' . $this->export($v, $scope) . '</div>';
} else {
$out .= ':<div style="padding-left:20px;">' . $this->export($v, $scope) . '</div>';
}
} elseif (is_object($v)) {
$out .= $this->exportObj($i . ' (object: ' . get_class($v) . '):', $v);
} else {
$out .= $this->exportVar($i . ' = ', $v);
}
}
return $out;
}
/**
* @param $i
* @param $v
*
* @return string
*/
protected function exportVar($i, $v)
{
if (is_string($v) || is_bool($v) || is_numeric($v)) {
return $i . htmlentities(var_export($v, true)) . '<br />';
} elseif (is_null($v)) {
return $i . 'null<br />';
} elseif (is_resource($v)) {
return $i . 'resource(' . get_resource_type($v) . ')<br />';
} else {
return $i . htmlentities(var_export($v, true)) . '<br />';
}
}
/**
* @param $i
* @param $obj
*
* @return string
*/
protected function exportObj($i, $obj)
{
if (array_search($obj, $this->outputObjects, true) !== false) {
return $i . ' [recursion, skipped]<br />';
}
$this->outputObjects[] = $obj;
$list = (array)$obj;
$protectedLength = strlen(get_class($obj)) + 2;
$out = array();
if ($this->outputMethods) {
$ref = new ReflectionObject($obj);
foreach ($ref->getMethods() as $method) {
if (!$method->isPublic()) {
continue;
}
if (empty($out['method'])) {
$out['method'] = '';
}
$params = array();
foreach ($method->getParameters() as $param) {
$params[] = ($param->isPassedByReference() ? '&' : '') . '$' . $param->getName() . ($param->isOptional() ? ' = ' . var_export($param->getDefaultValue(), true) : '');
}
$out['method'] .= '(method) ' . $method->getName() . '(' . implode(', ', $params) . ')<br />';
}
}
foreach ($list as $attributeName => $attributeValue) {
if (property_exists($obj, $attributeName)) {
$key = 'public';
} elseif (substr($attributeName, 0, 3) === "\0*\0") {
$key = 'protected';
$attributeName = substr($attributeName, 3);
} else {
$key = 'private';
$attributeName = substr($attributeName, $protectedLength);
}
if (empty($out[$key])) {
$out[$key] = '';
}
$out[$key] .= '(' . $key . ') ';
if (is_array($attributeValue)) {
$out[$key] .= $attributeName . ' (array):<br />
<div style="padding-left:20px;">' . $this->export($attributeValue, false) . '</div>';
} elseif (is_object($attributeValue)) {
$out[$key] .= $this->exportObj($attributeName . ' (object: ' . get_class($attributeValue) . '):', $attributeValue);
} else {
$out[$key] .= $this->exportVar($attributeName . ' = ', $attributeValue);
}
}
$return = $i . '<br /><div style="padding-left:20px;">';
if (!empty($out['method'])) {
$return .= $out['method'];
}
if (!empty($out['public'])) {
$return .= $out['public'];
}
if (!empty($out['protected'])) {
$return .= $out['protected'];
}
if (!empty($out['private'])) {
$return .= $out['private'];
}
return $return . '</div>';
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Returns the correct end of line character(s) for the current operating system.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginEol extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
*
* @return string
*/
public static function compile(Compiler $compiler)
{
return 'PHP_EOL';
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Plugin;
/**
* Applies various escaping schemes on the given string
* <pre>
* * value : the string to process
* * format : escaping format to use, valid formats are : html, htmlall, url, urlpathinfo, quotes, hex, hexentity,
* javascript and mail
* * charset : character set to use for the conversion (applies to some formats only), defaults to the current Dwoo
* charset
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*
* @return mixed|string
*/
class PluginEscape extends Plugin
{
/**
* @param string $value
* @param string $format
* @param null $charset
*
* @return mixed|string
*/
public function process($value = '', $format = 'html', $charset = null)
{
if ($charset === null) {
$charset = $this->core->getCharset();
}
switch ($format) {
case 'html':
return htmlspecialchars((string)$value, ENT_QUOTES, $charset);
case 'htmlall':
return htmlentities((string)$value, ENT_QUOTES, $charset);
case 'url':
return rawurlencode((string)$value);
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode((string)$value));
case 'quotes':
return preg_replace("#(?<!\\\\)'#", "\\'", (string)$value);
case 'hex':
$out = '';
$cnt = strlen((string)$value);
for ($i = 0; $i < $cnt; ++ $i) {
$out .= '%' . bin2hex((string)$value[$i]);
}
return $out;
case 'hexentity':
$out = '';
$cnt = strlen((string)$value);
for ($i = 0; $i < $cnt; ++ $i) {
$out .= '&#x' . bin2hex((string)$value[$i]) . ';';
}
return $out;
case 'javascript':
case 'js':
return strtr((string)$value,
array(
'\\' => '\\\\',
"'" => "\\'",
'"' => '\\"',
"\r" => '\\r',
"\n" => '\\n',
'</' => '<\/'
));
case 'mail':
return str_replace(array(
'@',
'.'
),
array(
'&nbsp;(AT)&nbsp;',
'&nbsp;(DOT)&nbsp;'
),
(string)$value);
default:
$this->core->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript, js or mail, "' . $format . '" given.',
E_USER_WARNING);
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Core;
use Dwoo\Plugin;
use Dwoo\Template\Str as TemplateString;
/**
* Evaluates the given string as if it was a template.
* Although this plugin is kind of optimized and will
* not recompile your string each time, it is still not
* a good practice to use it. If you want to have templates
* stored in a database or something you should probably use
* the Dwoo\Template\Str class or make another class that
* extends it
* <pre>
* * var : the string to use as a template
* * assign : if set, the output of the template will be saved in this variable instead of being output
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginEval extends Plugin
{
/**
* @param string $var
* @param null $assign
*
* @return string
*/
public function process($var, $assign = null)
{
if ($var == '') {
return '';
}
$tpl = new TemplateString($var);
$clone = clone $this->core;
$out = $clone->get($tpl, $this->core->readVar('_parent'));
if ($assign !== null) {
$this->core->assignInScope($out, $assign);
} else {
return $out;
}
}
}

View File

@@ -0,0 +1,206 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE LGPLv3
* @version 1.3.6
* @date 2017-03-21
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
use Dwoo\Exception as Exception;
use Dwoo\Security\Exception as SecurityException;
use Dwoo\Compilation\Exception as CompilationException;
/**
* Extends another template, read more about template inheritance at {@link
* http://wiki.dwoo.org/index.php/TemplateInheritance}
* <pre>
* * file : the template to extend
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginExtends extends Plugin implements ICompilable
{
protected static $childSource;
protected static $regex;
protected static $l;
protected static $r;
protected static $lastReplacement;
public function process()
{
}
/**
* @param Compiler $compiler
* @param $file
*
* @throws CompilationException
*/
public static function compile(Compiler $compiler, $file)
{
list($l, $r) = $compiler->getDelimiters();
self::$l = preg_quote($l, '/');
self::$r = preg_quote($r, '/');
self::$regex = '/
' . self::$l . 'block\s(["\']?)(.+?)\1' . self::$r . '(?:\r?\n?)
((?:
(?R)
|
[^' . self::$l . ']*
(?:
(?! ' . self::$l . '\/?block\b )
' . self::$l . '
[^' . self::$l . ']*+
)*
)*)
' . self::$l . '\/block' . self::$r . '
/six';
if ($compiler->getLooseOpeningHandling()) {
self::$l .= '\s*';
self::$r = '\s*' . self::$r;
}
$inheritanceTree = array(array('source' => $compiler->getTemplateSource()));
$curPath = dirname($compiler->getCore()->getTemplate()->getResourceIdentifier()) . DIRECTORY_SEPARATOR;
$curTpl = $compiler->getCore()->getTemplate();
while (!empty($file)) {
if ($file === '""' || $file === "''" || (substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '\'')) {
throw new CompilationException($compiler, 'Extends : The file name must be a non-empty string');
}
if (preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m)) {
// resource:identifier given, extract them
$resource = $m[1];
$identifier = $m[2];
} else {
// get the current template's resource
$resource = $curTpl->getResourceName();
$identifier = substr($file, 1, - 1);
}
try {
$parent = $compiler->getCore()->templateFactory($resource, $identifier, null, null, null, $curTpl);
}
catch (SecurityException $e) {
throw new CompilationException($compiler, 'Extends : Security restriction : ' . $e->getMessage());
}
catch (Exception $e) {
throw new CompilationException($compiler, 'Extends : ' . $e->getMessage());
}
if ($parent === null) {
throw new CompilationException($compiler, 'Extends : Resource "' . $resource . ':' . $identifier . '" not found.');
} elseif ($parent === false) {
throw new CompilationException($compiler, 'Extends : Resource "' . $resource . '" does not support extends.');
}
$curTpl = $parent;
$newParent = array(
'source' => $parent->getSource(),
'resource' => $resource,
'identifier' => $parent->getResourceIdentifier(),
'uid' => $parent->getUid()
);
if (array_search($newParent, $inheritanceTree, true) !== false) {
throw new CompilationException($compiler, 'Extends : Recursive template inheritance detected');
}
$inheritanceTree[] = $newParent;
if (preg_match('/^' . self::$l . 'extends(?:\(?\s*|\s+)(?:file=)?\s*((["\']).+?\2|\S+?)\s*\)?\s*?' . self::$r . '/i', $parent->getSource(), $match)) {
$curPath = dirname($identifier) . DIRECTORY_SEPARATOR;
if (isset($match[2]) && $match[2] == '"') {
$file = '"' . str_replace('"', '\\"', substr($match[1], 1, - 1)) . '"';
} elseif (isset($match[2]) && $match[2] == "'") {
$file = '"' . substr($match[1], 1, - 1) . '"';
} else {
$file = '"' . $match[1] . '"';
}
} else {
$file = false;
}
}
while (true) {
$parent = array_pop($inheritanceTree);
$child = end($inheritanceTree);
self::$childSource = $child['source'];
self::$lastReplacement = count($inheritanceTree) === 1;
if (!isset($newSource)) {
$newSource = $parent['source'];
}
$newSource = preg_replace_callback(self::$regex, array(
'Dwoo\Plugins\Functions\PluginExtends',
'replaceBlock'
), $newSource);
$newSource = $l . 'do extendsCheck(' . var_export($parent['resource'] . ':' . $parent['identifier'], true) . ')' . $r . $newSource;
if (self::$lastReplacement) {
break;
}
}
$compiler->setTemplateSource($newSource);
$compiler->recompile();
}
/**
* @param array $matches
*
* @return mixed|string
*/
protected static function replaceBlock(array $matches)
{
$matches[3] = self::removeTrailingNewline($matches[3]);
if (preg_match_all(self::$regex, self::$childSource, $override) && in_array($matches[2], $override[2])) {
$key = array_search($matches[2], $override[2]);
$override = self::removeTrailingNewline($override[3][$key]);
$l = stripslashes(self::$l);
$r = stripslashes(self::$r);
if (self::$lastReplacement) {
return preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override);
}
return $l . 'block ' . $matches[1] . $matches[2] . $matches[1] . $r . preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override) . $l . '/block' . $r;
}
if (preg_match(self::$regex, $matches[3])) {
return preg_replace_callback(self::$regex, array(
'Dwoo\Plugins\Functions\PluginExtends',
'replaceBlock'
), $matches[3]);
}
if (self::$lastReplacement) {
return $matches[3];
}
return $matches[0];
}
/**
* @param $text
*
* @return string
*/
protected static function removeTrailingNewline($text)
{
return substr($text, - 1) === "\n" ? substr($text, - 2, 1) === "\r" ? substr($text, 0, - 2) : substr($text, 0, - 1) : $text;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE LGPLv3
* @version 1.3.6
* @date 2017-03-21
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\Compilation\Exception as CompilationException;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Checks whether an extended file has been modified, and if so recompiles the current template. This is for internal
* use only, do not use. This software is provided 'as-is', without any express or implied warranty. In no event will
* the authors be held liable for any damages arising from the use of this software.
*/
class PluginExtendsCheck extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param $file
*
* @return string
* @throws CompilationException
*/
public static function compile(Compiler $compiler, $file)
{
preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m);
$resource = $m[1];
$identifier = $m[2];
$tpl = $compiler->getCore()->templateFactory($resource, $identifier);
if ($tpl === null) {
throw new CompilationException($compiler,
'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
} elseif ($tpl === false) {
throw new CompilationException($compiler,
'Load Templates : Resource "' . $resource . '" does not support includes.');
}
$out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
$modCheck = $tpl->getIsModifiedCode();
if ($modCheck) {
$out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
} else {
$out .= 'try {
$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
} catch (Dwoo\Exception $e) {
$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
}
if ($tpl === null)
$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
elseif ($tpl === false)
$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
}
return $out;
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Plugin;
/**
* Reads a file
* <pre>
* * file : path or URI of the file to read (however reading from another website is not recommended for performance
* reasons)
* * assign : if set, the file will be saved in this variable instead of being output
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginFetch extends Plugin
{
/**
* @param string $file
* @param null $assign
*
* @return string
*/
public function process($file, $assign = null)
{
if ($file === '') {
return '';
}
if ($policy = $this->core->getSecurityPolicy()) {
while (true) {
if (preg_match('{^([a-z]+?)://}i', $file)) {
$this->core->triggerError('The security policy prevents you to read files from external sources.',
E_USER_WARNING);
}
$file = realpath($file);
$dirs = $policy->getAllowedDirectories();
foreach ($dirs as $dir => $dummy) {
if (strpos($file, $dir) === 0) {
break 2;
}
}
$this->core->triggerError('The security policy prevents you to read <em>' . $file . '</em>',
E_USER_WARNING);
}
}
$file = str_replace(array(
"\t",
"\n",
"\r"
),
array(
'\\t',
'\\n',
'\\r'
),
$file);
$out = file_get_contents($file);
if ($assign === null) {
return $out;
}
$this->core->assignInScope($out, $assign);
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Exception as Exception;
use Dwoo\Plugin;
use Dwoo\Security\Exception as SecurityException;
/**
* Inserts another template into the current one
* <pre>
* * file : the resource name of the template
* * cache_time : cache length in seconds
* * cache_id : cache identifier for the included template
* * compile_id : compilation identifier for the included template
* * data : data to feed into the included template, it can be any array and will default to $_root (the current data)
* * assign : if set, the output of the included template will be saved in this variable instead of being output
* * rest : any additional parameter/value provided will be added to the data array
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginInclude extends Plugin
{
/**
* @param $file
* @param null $cache_time
* @param null $cache_id
* @param null $compile_id
* @param string $data
* @param null $assign
* @param array $rest
*
* @return string
*/
public function process($file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array())
{
$include = null;
if ($file === '') {
return '';
}
if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
// resource:identifier given, extract them
$resource = $m[1];
$identifier = $m[2];
} else {
// get the current template's resource
$resource = $this->core->getTemplate()->getResourceName();
$identifier = $file;
}
try {
$include = $this->core->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id);
}
catch (SecurityException $e) {
$this->core->triggerError('Include : Security restriction : ' . $e->getMessage(), E_USER_WARNING);
}
catch (Exception $e) {
$this->core->triggerError('Include : ' . $e->getMessage(), E_USER_WARNING);
}
if ($include === null) {
$this->core->triggerError('Include : Resource "' . $resource . ':' . $identifier . '" not found.',
E_USER_WARNING);
} elseif ($include === false) {
$this->core->triggerError('Include : Resource "' . $resource . '" does not support includes.',
E_USER_WARNING);
}
if (is_string($data)) {
$vars = $this->core->readVar($data);
} else {
$vars = $data;
}
if (count($rest)) {
$vars = $rest + $vars;
}
$clone = clone $this->core;
$out = $clone->get($include, $vars);
if ($assign !== null) {
$this->core->assignInScope($out, $assign);
}
foreach ($clone->getReturnValues() as $name => $value) {
$this->core->assignInScope($value, $name);
}
if ($assign === null) {
return $out;
}
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Indents every line of a text by the given amount of characters
* <pre>
* * value : the string to indent
* * by : how many characters should be inserted before each line
* * char : the character(s) to insert
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginIndent extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param string $value
* @param int $by
* @param string $char
*
* @return string
*/
public static function compile(Compiler $compiler, $value, $by = 4, $char = ' ')
{
return "preg_replace('#^#m', '" . str_repeat(substr($char, 1, - 1), trim($by, '"\'')) . "', $value)";
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE Modified BSD License
* @version 1.3.2
* @date 2017-01-06
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Checks whether a variable is not null
* <pre>
* * var : variable to check
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginIsset extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param mixed $var
*
* @return string
*/
public static function compile(Compiler $compiler, $var)
{
return '(' . $var . ' !== null)';
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Copyright (c) 2013-2017
*
* @category Library
* @package Dwoo\Plugins\Functions
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author David Sanchez <david38sanchez@gmail.com>
* @copyright 2008-2013 Jordi Boggiano
* @copyright 2013-2017 David Sanchez
* @license http://dwoo.org/LICENSE LGPLv3
* @version 1.3.6
* @date 2017-03-21
* @link http://dwoo.org/
*/
namespace Dwoo\Plugins\Functions;
use Dwoo\Compiler;
use Dwoo\Compilation\Exception as CompilationException;
use Dwoo\ICompilable;
use Dwoo\Plugin;
/**
* Loads sub-templates contained in an external file
* <pre>
* * file : the resource name of the file to load
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*/
class PluginLoadTemplates extends Plugin implements ICompilable
{
/**
* @param Compiler $compiler
* @param string $file
*
* @return string
* @throws CompilationException
*/
public static function compile(Compiler $compiler, $file)
{
$file = substr($file, 1, - 1);
if ($file === '') {
return '';
}
if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
// resource:identifier given, extract them
$resource = $m[1];
$identifier = $m[2];
} else {
// get the current template's resource
$resource = $compiler->getCore()->getTemplate()->getResourceName();
$identifier = $file;
}
$tpl = $compiler->getCore()->templateFactory($resource, $identifier);
if ($tpl === null) {
throw new CompilationException($compiler,
'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
} elseif ($tpl === false) {
throw new CompilationException($compiler,
'Load Templates : Resource "' . $resource . '" does not support includes.');
}
$cmp = clone $compiler;
$cmp->compile($compiler->getCore(), $tpl);
foreach ($cmp->getTemplatePlugins() as $template => $args) {
$compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body']);
}
foreach ($cmp->getUsedPlugins() as $plugin => $type) {
$compiler->addUsedPlugin($plugin, $type);
}
$out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
$modCheck = $tpl->getIsModifiedCode();
if ($modCheck) {
$out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
} else {
$out .= 'try {
$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
} catch (Dwoo\Exception $e) {
$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
}
if ($tpl === null)
$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
elseif ($tpl === false)
$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
}
return $out;
}
}

Some files were not shown because too many files have changed in this diff Show More