First release

This commit is contained in:
Knah Tsaeb 2020-01-06 14:14:28 +01:00
commit acea5c67f2
85 changed files with 4411 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
config/config.php
tmp/*
!tmp/.gitkeep
script/cronTask.sh

2
.htaccess Normal file
View file

@ -0,0 +1,2 @@
AddDefaultCharset UTF-8
Options -Indexes

13
LICENCE Normal file
View file

@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2020 Knah Tsaeb
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

26
README.md Normal file
View file

@ -0,0 +1,26 @@
# PerYouDow
**PER**sonal **YOU**tube-dl **DOW**nloader is limited PHP/HTML GUI for downloading video on your machine.
## Instalation
#### Without git
`mkdir /tmp/peryoudow`
`cd /tmp/peryoudown`
`wget https://forge.leslibres.org/Knah-Tsaeb/peryoudow/archive/ master.zip`
`unzip master.zip`
`mv master.zip /path/of/web/server/peryoudown`
#### With git
`mkdir /path/of/web/server/peryoudown`
`cd /path/of/web/server/peryoudown`
`git clone https://forge.leslibres.org/Knah-Tsaeb/peryoudow.git .`
Open it this location in your browser.
Fill username, password and list of possible destination path separate with semicolon.
`cp /path/of/web/server/peryoudown/script/cronTask.sh.sample /path/of/web/server/peryoudown/script/cronTask.sh`
Setup a cron job for /path/of/web/server/peryoudown/script/cronTask.sh you can run task every 15 min.
Enjoy :-)

14
apps/config.php Normal file
View file

@ -0,0 +1,14 @@
<?php
class MyConfig
{
public static function read($filename)
{
$config = include 'config/'.$filename.'.php';
return $config;
}
public static function write($filename, array $config)
{
$config = var_export($config, true);
file_put_contents('config/'.$filename.'.php', "<?php return $config ;");
}
}

3
apps/createTask.php Normal file
View file

@ -0,0 +1,3 @@
<?php
file_put_contents('tmp/'.uniqid().'.request',$url.';'.$config['listOfDestPath'][$destination]."\n");

46
apps/input.php Normal file
View file

@ -0,0 +1,46 @@
<?php
if(!empty($_POST['logout'])){
session_unset();
}
if(!empty($_POST['page'])){
$page = filter_input(INPUT_POST, 'page', FILTER_SANITIZE_SPECIAL_CHARS);
}
if(!empty($_GET['page'])){
$page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_SPECIAL_CHARS);
}
if(!empty($_POST['createLogin'])){
$createLogin = filter_input(INPUT_POST, 'createLogin', FILTER_SANITIZE_SPECIAL_CHARS);
}
if(!empty($_POST['createPassword'])){
$createPassword = password_hash($_POST['createPassword'], PASSWORD_DEFAULT);
}
if(!empty($_POST['createPath'])){
$createPath = explode(';', $_POST['createPath']);
$createPath = array_filter($createPath);
array_walk($createPath, 'trim_value');
foreach($createPath as $key => &$value){
if(empty($value)){
unset($createPath[$key]);
}
if(substr($value, -1) !== '/'){
$value = $value.'/';
}
}
}
if(isset($_POST['videoUrl'])){
$url = escapeshellcmd($_POST['videoUrl']);
$destination = escapeshellcmd($_POST['destination']);
require 'apps/createTask.php';
//exec('bash script/cronTask.sh.sample', $array);
}
function trim_value(&$value)
{
$value = trim($value);
}

1
apps/login.php Normal file
View file

@ -0,0 +1 @@
<?php

5
composer.json Normal file
View file

@ -0,0 +1,5 @@
{
"require": {
"league/plates": "^3.3"
}
}

73
composer.lock generated Normal file
View file

@ -0,0 +1,73 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8d66baa2c76613c389165111a19784c0",
"packages": [
{
"name": "league/plates",
"version": "3.3.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/plates.git",
"reference": "b1684b6f127714497a0ef927ce42c0b44b45a8af"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/plates/zipball/b1684b6f127714497a0ef927ce42c0b44b45a8af",
"reference": "b1684b6f127714497a0ef927ce42c0b44b45a8af",
"shasum": ""
},
"require": {
"php": "^5.3 | ^7.0"
},
"require-dev": {
"mikey179/vfsstream": "^1.4",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~1.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"League\\Plates\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jonathan Reinink",
"email": "jonathan@reinink.ca",
"role": "Developer"
}
],
"description": "Plates, the native PHP template system that's fast, easy to use and easy to extend.",
"homepage": "http://platesphp.com",
"keywords": [
"league",
"package",
"templates",
"templating",
"views"
],
"time": "2016-12-28T00:14:17+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}

1
config/.htaccess Normal file
View file

@ -0,0 +1 @@
Deny from All

3
css/local.css Normal file
View file

@ -0,0 +1,3 @@
label {
font-weight: bold;
}

232
css/w3.css Normal file
View file

@ -0,0 +1,232 @@
/* W3.CSS 4.13 June 2019 by Jan Egil and Borge Refsnes */
html{box-sizing:border-box}*,*:before,*:after{box-sizing:inherit}
/* Extract from normalize.css by Nicolas Gallagher and Jonathan Neal git.io/normalize */
html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}
article,aside,details,figcaption,figure,footer,header,main,menu,nav,section{display:block}summary{display:list-item}
audio,canvas,progress,video{display:inline-block}progress{vertical-align:baseline}
audio:not([controls]){display:none;height:0}[hidden],template{display:none}
a{background-color:transparent}a:active,a:hover{outline-width:0}
abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}
b,strong{font-weight:bolder}dfn{font-style:italic}mark{background:#ff0;color:#000}
small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
sub{bottom:-0.25em}sup{top:-0.5em}figure{margin:1em 40px}img{border-style:none}
code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}hr{box-sizing:content-box;height:0;overflow:visible}
button,input,select,textarea,optgroup{font:inherit;margin:0}optgroup{font-weight:bold}
button,input{overflow:visible}button,select{text-transform:none}
button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}
button::-moz-focus-inner,[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner{border-style:none;padding:0}
button:-moz-focusring,[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring{outline:1px dotted ButtonText}
fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}
legend{color:inherit;display:table;max-width:100%;padding:0;white-space:normal}textarea{overflow:auto}
[type=checkbox],[type=radio]{padding:0}
[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}
[type=search]{-webkit-appearance:textfield;outline-offset:-2px}
[type=search]::-webkit-search-decoration{-webkit-appearance:none}
::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}
/* End extract */
html,body{font-family:Verdana,sans-serif;font-size:15px;line-height:1.5}html{overflow-x:hidden}
h1{font-size:36px}h2{font-size:30px}h3{font-size:24px}h4{font-size:20px}h5{font-size:18px}h6{font-size:16px}.w3-serif{font-family:serif}
h1,h2,h3,h4,h5,h6{font-family:"Segoe UI",Arial,sans-serif;font-weight:400;margin:10px 0}.w3-wide{letter-spacing:4px}
hr{border:0;border-top:1px solid #eee;margin:20px 0}
.w3-image{max-width:100%;height:auto}img{vertical-align:middle}a{color:inherit}
.w3-table,.w3-table-all{border-collapse:collapse;border-spacing:0;width:100%;display:table}.w3-table-all{border:1px solid #ccc}
.w3-bordered tr,.w3-table-all tr{border-bottom:1px solid #ddd}.w3-striped tbody tr:nth-child(even){background-color:#f1f1f1}
.w3-table-all tr:nth-child(odd){background-color:#fff}.w3-table-all tr:nth-child(even){background-color:#f1f1f1}
.w3-hoverable tbody tr:hover,.w3-ul.w3-hoverable li:hover{background-color:#ccc}.w3-centered tr th,.w3-centered tr td{text-align:center}
.w3-table td,.w3-table th,.w3-table-all td,.w3-table-all th{padding:8px 8px;display:table-cell;text-align:left;vertical-align:top}
.w3-table th:first-child,.w3-table td:first-child,.w3-table-all th:first-child,.w3-table-all td:first-child{padding-left:16px}
.w3-btn,.w3-button{border:none;display:inline-block;padding:8px 16px;vertical-align:middle;overflow:hidden;text-decoration:none;color:inherit;background-color:inherit;text-align:center;cursor:pointer;white-space:nowrap}
.w3-btn:hover{box-shadow:0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19)}
.w3-btn,.w3-button{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
.w3-disabled,.w3-btn:disabled,.w3-button:disabled{cursor:not-allowed;opacity:0.3}.w3-disabled *,:disabled *{pointer-events:none}
.w3-btn.w3-disabled:hover,.w3-btn:disabled:hover{box-shadow:none}
.w3-badge,.w3-tag{background-color:#000;color:#fff;display:inline-block;padding-left:8px;padding-right:8px;text-align:center}.w3-badge{border-radius:50%}
.w3-ul{list-style-type:none;padding:0;margin:0}.w3-ul li{padding:8px 16px;border-bottom:1px solid #ddd}.w3-ul li:last-child{border-bottom:none}
.w3-tooltip,.w3-display-container{position:relative}.w3-tooltip .w3-text{display:none}.w3-tooltip:hover .w3-text{display:inline-block}
.w3-ripple:active{opacity:0.5}.w3-ripple{transition:opacity 0s}
.w3-input{padding:8px;display:block;border:none;border-bottom:1px solid #ccc;width:100%}
.w3-select{padding:9px 0;width:100%;border:none;border-bottom:1px solid #ccc}
.w3-dropdown-click,.w3-dropdown-hover{position:relative;display:inline-block;cursor:pointer}
.w3-dropdown-hover:hover .w3-dropdown-content{display:block}
.w3-dropdown-hover:first-child,.w3-dropdown-click:hover{background-color:#ccc;color:#000}
.w3-dropdown-hover:hover > .w3-button:first-child,.w3-dropdown-click:hover > .w3-button:first-child{background-color:#ccc;color:#000}
.w3-dropdown-content{cursor:auto;color:#000;background-color:#fff;display:none;position:absolute;min-width:160px;margin:0;padding:0;z-index:1}
.w3-check,.w3-radio{width:24px;height:24px;position:relative;top:6px}
.w3-sidebar{height:100%;width:200px;background-color:#fff;position:fixed!important;z-index:1;overflow:auto}
.w3-bar-block .w3-dropdown-hover,.w3-bar-block .w3-dropdown-click{width:100%}
.w3-bar-block .w3-dropdown-hover .w3-dropdown-content,.w3-bar-block .w3-dropdown-click .w3-dropdown-content{min-width:100%}
.w3-bar-block .w3-dropdown-hover .w3-button,.w3-bar-block .w3-dropdown-click .w3-button{width:100%;text-align:left;padding:8px 16px}
.w3-main,#main{transition:margin-left .4s}
.w3-modal{z-index:3;display:none;padding-top:100px;position:fixed;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgb(0,0,0);background-color:rgba(0,0,0,0.4)}
.w3-modal-content{margin:auto;background-color:#fff;position:relative;padding:0;outline:0;width:600px}
.w3-bar{width:100%;overflow:hidden}.w3-center .w3-bar{display:inline-block;width:auto}
.w3-bar .w3-bar-item{padding:8px 16px;float:left;width:auto;border:none;display:block;outline:0}
.w3-bar .w3-dropdown-hover,.w3-bar .w3-dropdown-click{position:static;float:left}
.w3-bar .w3-button{white-space:normal}
.w3-bar-block .w3-bar-item{width:100%;display:block;padding:8px 16px;text-align:left;border:none;white-space:normal;float:none;outline:0}
.w3-bar-block.w3-center .w3-bar-item{text-align:center}.w3-block{display:block;width:100%}
.w3-responsive{display:block;overflow-x:auto}
.w3-container:after,.w3-container:before,.w3-panel:after,.w3-panel:before,.w3-row:after,.w3-row:before,.w3-row-padding:after,.w3-row-padding:before,
.w3-cell-row:before,.w3-cell-row:after,.w3-clear:after,.w3-clear:before,.w3-bar:before,.w3-bar:after{content:"";display:table;clear:both}
.w3-col,.w3-half,.w3-third,.w3-twothird,.w3-threequarter,.w3-quarter{float:left;width:100%}
.w3-col.s1{width:8.33333%}.w3-col.s2{width:16.66666%}.w3-col.s3{width:24.99999%}.w3-col.s4{width:33.33333%}
.w3-col.s5{width:41.66666%}.w3-col.s6{width:49.99999%}.w3-col.s7{width:58.33333%}.w3-col.s8{width:66.66666%}
.w3-col.s9{width:74.99999%}.w3-col.s10{width:83.33333%}.w3-col.s11{width:91.66666%}.w3-col.s12{width:99.99999%}
@media (min-width:601px){.w3-col.m1{width:8.33333%}.w3-col.m2{width:16.66666%}.w3-col.m3,.w3-quarter{width:24.99999%}.w3-col.m4,.w3-third{width:33.33333%}
.w3-col.m5{width:41.66666%}.w3-col.m6,.w3-half{width:49.99999%}.w3-col.m7{width:58.33333%}.w3-col.m8,.w3-twothird{width:66.66666%}
.w3-col.m9,.w3-threequarter{width:74.99999%}.w3-col.m10{width:83.33333%}.w3-col.m11{width:91.66666%}.w3-col.m12{width:99.99999%}}
@media (min-width:993px){.w3-col.l1{width:8.33333%}.w3-col.l2{width:16.66666%}.w3-col.l3{width:24.99999%}.w3-col.l4{width:33.33333%}
.w3-col.l5{width:41.66666%}.w3-col.l6{width:49.99999%}.w3-col.l7{width:58.33333%}.w3-col.l8{width:66.66666%}
.w3-col.l9{width:74.99999%}.w3-col.l10{width:83.33333%}.w3-col.l11{width:91.66666%}.w3-col.l12{width:99.99999%}}
.w3-rest{overflow:hidden}.w3-stretch{margin-left:-16px;margin-right:-16px}
.w3-content,.w3-auto{margin-left:auto;margin-right:auto}.w3-content{max-width:980px}.w3-auto{max-width:1140px}
.w3-cell-row{display:table;width:100%}.w3-cell{display:table-cell}
.w3-cell-top{vertical-align:top}.w3-cell-middle{vertical-align:middle}.w3-cell-bottom{vertical-align:bottom}
.w3-hide{display:none!important}.w3-show-block,.w3-show{display:block!important}.w3-show-inline-block{display:inline-block!important}
@media (max-width:1205px){.w3-auto{max-width:95%}}
@media (max-width:600px){.w3-modal-content{margin:0 10px;width:auto!important}.w3-modal{padding-top:30px}
.w3-dropdown-hover.w3-mobile .w3-dropdown-content,.w3-dropdown-click.w3-mobile .w3-dropdown-content{position:relative}
.w3-hide-small{display:none!important}.w3-mobile{display:block;width:100%!important}.w3-bar-item.w3-mobile,.w3-dropdown-hover.w3-mobile,.w3-dropdown-click.w3-mobile{text-align:center}
.w3-dropdown-hover.w3-mobile,.w3-dropdown-hover.w3-mobile .w3-btn,.w3-dropdown-hover.w3-mobile .w3-button,.w3-dropdown-click.w3-mobile,.w3-dropdown-click.w3-mobile .w3-btn,.w3-dropdown-click.w3-mobile .w3-button{width:100%}}
@media (max-width:768px){.w3-modal-content{width:500px}.w3-modal{padding-top:50px}}
@media (min-width:993px){.w3-modal-content{width:900px}.w3-hide-large{display:none!important}.w3-sidebar.w3-collapse{display:block!important}}
@media (max-width:992px) and (min-width:601px){.w3-hide-medium{display:none!important}}
@media (max-width:992px){.w3-sidebar.w3-collapse{display:none}.w3-main{margin-left:0!important;margin-right:0!important}.w3-auto{max-width:100%}}
.w3-top,.w3-bottom{position:fixed;width:100%;z-index:1}.w3-top{top:0}.w3-bottom{bottom:0}
.w3-overlay{position:fixed;display:none;width:100%;height:100%;top:0;left:0;right:0;bottom:0;background-color:rgba(0,0,0,0.5);z-index:2}
.w3-display-topleft{position:absolute;left:0;top:0}.w3-display-topright{position:absolute;right:0;top:0}
.w3-display-bottomleft{position:absolute;left:0;bottom:0}.w3-display-bottomright{position:absolute;right:0;bottom:0}
.w3-display-middle{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%)}
.w3-display-left{position:absolute;top:50%;left:0%;transform:translate(0%,-50%);-ms-transform:translate(-0%,-50%)}
.w3-display-right{position:absolute;top:50%;right:0%;transform:translate(0%,-50%);-ms-transform:translate(0%,-50%)}
.w3-display-topmiddle{position:absolute;left:50%;top:0;transform:translate(-50%,0%);-ms-transform:translate(-50%,0%)}
.w3-display-bottommiddle{position:absolute;left:50%;bottom:0;transform:translate(-50%,0%);-ms-transform:translate(-50%,0%)}
.w3-display-container:hover .w3-display-hover{display:block}.w3-display-container:hover span.w3-display-hover{display:inline-block}.w3-display-hover{display:none}
.w3-display-position{position:absolute}
.w3-circle{border-radius:50%}
.w3-round-small{border-radius:2px}.w3-round,.w3-round-medium{border-radius:4px}.w3-round-large{border-radius:8px}.w3-round-xlarge{border-radius:16px}.w3-round-xxlarge{border-radius:32px}
.w3-row-padding,.w3-row-padding>.w3-half,.w3-row-padding>.w3-third,.w3-row-padding>.w3-twothird,.w3-row-padding>.w3-threequarter,.w3-row-padding>.w3-quarter,.w3-row-padding>.w3-col{padding:0 8px}
.w3-container,.w3-panel{padding:0.01em 16px}.w3-panel{margin-top:16px;margin-bottom:16px}
.w3-code,.w3-codespan{font-family:Consolas,"courier new";font-size:16px}
.w3-code{width:auto;background-color:#fff;padding:8px 12px;border-left:4px solid #4CAF50;word-wrap:break-word}
.w3-codespan{color:crimson;background-color:#f1f1f1;padding-left:4px;padding-right:4px;font-size:110%}
.w3-card,.w3-card-2{box-shadow:0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12)}
.w3-card-4,.w3-hover-shadow:hover{box-shadow:0 4px 10px 0 rgba(0,0,0,0.2),0 4px 20px 0 rgba(0,0,0,0.19)}
.w3-spin{animation:w3-spin 2s infinite linear}@keyframes w3-spin{0%{transform:rotate(0deg)}100%{transform:rotate(359deg)}}
.w3-animate-fading{animation:fading 10s infinite}@keyframes fading{0%{opacity:0}50%{opacity:1}100%{opacity:0}}
.w3-animate-opacity{animation:opac 0.8s}@keyframes opac{from{opacity:0} to{opacity:1}}
.w3-animate-top{position:relative;animation:animatetop 0.4s}@keyframes animatetop{from{top:-300px;opacity:0} to{top:0;opacity:1}}
.w3-animate-left{position:relative;animation:animateleft 0.4s}@keyframes animateleft{from{left:-300px;opacity:0} to{left:0;opacity:1}}
.w3-animate-right{position:relative;animation:animateright 0.4s}@keyframes animateright{from{right:-300px;opacity:0} to{right:0;opacity:1}}
.w3-animate-bottom{position:relative;animation:animatebottom 0.4s}@keyframes animatebottom{from{bottom:-300px;opacity:0} to{bottom:0;opacity:1}}
.w3-animate-zoom {animation:animatezoom 0.6s}@keyframes animatezoom{from{transform:scale(0)} to{transform:scale(1)}}
.w3-animate-input{transition:width 0.4s ease-in-out}.w3-animate-input:focus{width:100%!important}
.w3-opacity,.w3-hover-opacity:hover{opacity:0.60}.w3-opacity-off,.w3-hover-opacity-off:hover{opacity:1}
.w3-opacity-max{opacity:0.25}.w3-opacity-min{opacity:0.75}
.w3-greyscale-max,.w3-grayscale-max,.w3-hover-greyscale:hover,.w3-hover-grayscale:hover{filter:grayscale(100%)}
.w3-greyscale,.w3-grayscale{filter:grayscale(75%)}.w3-greyscale-min,.w3-grayscale-min{filter:grayscale(50%)}
.w3-sepia{filter:sepia(75%)}.w3-sepia-max,.w3-hover-sepia:hover{filter:sepia(100%)}.w3-sepia-min{filter:sepia(50%)}
.w3-tiny{font-size:10px!important}.w3-small{font-size:12px!important}.w3-medium{font-size:15px!important}.w3-large{font-size:18px!important}
.w3-xlarge{font-size:24px!important}.w3-xxlarge{font-size:36px!important}.w3-xxxlarge{font-size:48px!important}.w3-jumbo{font-size:64px!important}
.w3-left-align{text-align:left!important}.w3-right-align{text-align:right!important}.w3-justify{text-align:justify!important}.w3-center{text-align:center!important}
.w3-border-0{border:0!important}.w3-border{border:1px solid #ccc!important}
.w3-border-top{border-top:1px solid #ccc!important}.w3-border-bottom{border-bottom:1px solid #ccc!important}
.w3-border-left{border-left:1px solid #ccc!important}.w3-border-right{border-right:1px solid #ccc!important}
.w3-topbar{border-top:6px solid #ccc!important}.w3-bottombar{border-bottom:6px solid #ccc!important}
.w3-leftbar{border-left:6px solid #ccc!important}.w3-rightbar{border-right:6px solid #ccc!important}
.w3-section,.w3-code{margin-top:16px!important;margin-bottom:16px!important}
.w3-margin{margin:16px!important}.w3-margin-top{margin-top:16px!important}.w3-margin-bottom{margin-bottom:16px!important}
.w3-margin-left{margin-left:16px!important}.w3-margin-right{margin-right:16px!important}
.w3-padding-small{padding:4px 8px!important}.w3-padding{padding:8px 16px!important}.w3-padding-large{padding:12px 24px!important}
.w3-padding-16{padding-top:16px!important;padding-bottom:16px!important}.w3-padding-24{padding-top:24px!important;padding-bottom:24px!important}
.w3-padding-32{padding-top:32px!important;padding-bottom:32px!important}.w3-padding-48{padding-top:48px!important;padding-bottom:48px!important}
.w3-padding-64{padding-top:64px!important;padding-bottom:64px!important}
.w3-left{float:left!important}.w3-right{float:right!important}
.w3-button:hover{color:#000!important;background-color:#ccc!important}
.w3-transparent,.w3-hover-none:hover{background-color:transparent!important}
.w3-hover-none:hover{box-shadow:none!important}
/* Colors */
.w3-amber,.w3-hover-amber:hover{color:#000!important;background-color:#ffc107!important}
.w3-aqua,.w3-hover-aqua:hover{color:#000!important;background-color:#00ffff!important}
.w3-blue,.w3-hover-blue:hover{color:#fff!important;background-color:#2196F3!important}
.w3-light-blue,.w3-hover-light-blue:hover{color:#000!important;background-color:#87CEEB!important}
.w3-brown,.w3-hover-brown:hover{color:#fff!important;background-color:#795548!important}
.w3-cyan,.w3-hover-cyan:hover{color:#000!important;background-color:#00bcd4!important}
.w3-blue-grey,.w3-hover-blue-grey:hover,.w3-blue-gray,.w3-hover-blue-gray:hover{color:#fff!important;background-color:#607d8b!important}
.w3-green,.w3-hover-green:hover{color:#fff!important;background-color:#4CAF50!important}
.w3-light-green,.w3-hover-light-green:hover{color:#000!important;background-color:#8bc34a!important}
.w3-indigo,.w3-hover-indigo:hover{color:#fff!important;background-color:#3f51b5!important}
.w3-khaki,.w3-hover-khaki:hover{color:#000!important;background-color:#f0e68c!important}
.w3-lime,.w3-hover-lime:hover{color:#000!important;background-color:#cddc39!important}
.w3-orange,.w3-hover-orange:hover{color:#000!important;background-color:#ff9800!important}
.w3-deep-orange,.w3-hover-deep-orange:hover{color:#fff!important;background-color:#ff5722!important}
.w3-pink,.w3-hover-pink:hover{color:#fff!important;background-color:#e91e63!important}
.w3-purple,.w3-hover-purple:hover{color:#fff!important;background-color:#9c27b0!important}
.w3-deep-purple,.w3-hover-deep-purple:hover{color:#fff!important;background-color:#673ab7!important}
.w3-red,.w3-hover-red:hover{color:#fff!important;background-color:#f44336!important}
.w3-sand,.w3-hover-sand:hover{color:#000!important;background-color:#fdf5e6!important}
.w3-teal,.w3-hover-teal:hover{color:#fff!important;background-color:#009688!important}
.w3-yellow,.w3-hover-yellow:hover{color:#000!important;background-color:#ffeb3b!important}
.w3-white,.w3-hover-white:hover{color:#000!important;background-color:#fff!important}
.w3-black,.w3-hover-black:hover{color:#fff!important;background-color:#000!important}
.w3-grey,.w3-hover-grey:hover,.w3-gray,.w3-hover-gray:hover{color:#000!important;background-color:#9e9e9e!important}
.w3-light-grey,.w3-hover-light-grey:hover,.w3-light-gray,.w3-hover-light-gray:hover{color:#000!important;background-color:#f1f1f1!important}
.w3-dark-grey,.w3-hover-dark-grey:hover,.w3-dark-gray,.w3-hover-dark-gray:hover{color:#fff!important;background-color:#616161!important}
.w3-pale-red,.w3-hover-pale-red:hover{color:#000!important;background-color:#ffdddd!important}
.w3-pale-green,.w3-hover-pale-green:hover{color:#000!important;background-color:#ddffdd!important}
.w3-pale-yellow,.w3-hover-pale-yellow:hover{color:#000!important;background-color:#ffffcc!important}
.w3-pale-blue,.w3-hover-pale-blue:hover{color:#000!important;background-color:#ddffff!important}
.w3-text-amber,.w3-hover-text-amber:hover{color:#ffc107!important}
.w3-text-aqua,.w3-hover-text-aqua:hover{color:#00ffff!important}
.w3-text-blue,.w3-hover-text-blue:hover{color:#2196F3!important}
.w3-text-light-blue,.w3-hover-text-light-blue:hover{color:#87CEEB!important}
.w3-text-brown,.w3-hover-text-brown:hover{color:#795548!important}
.w3-text-cyan,.w3-hover-text-cyan:hover{color:#00bcd4!important}
.w3-text-blue-grey,.w3-hover-text-blue-grey:hover,.w3-text-blue-gray,.w3-hover-text-blue-gray:hover{color:#607d8b!important}
.w3-text-green,.w3-hover-text-green:hover{color:#4CAF50!important}
.w3-text-light-green,.w3-hover-text-light-green:hover{color:#8bc34a!important}
.w3-text-indigo,.w3-hover-text-indigo:hover{color:#3f51b5!important}
.w3-text-khaki,.w3-hover-text-khaki:hover{color:#b4aa50!important}
.w3-text-lime,.w3-hover-text-lime:hover{color:#cddc39!important}
.w3-text-orange,.w3-hover-text-orange:hover{color:#ff9800!important}
.w3-text-deep-orange,.w3-hover-text-deep-orange:hover{color:#ff5722!important}
.w3-text-pink,.w3-hover-text-pink:hover{color:#e91e63!important}
.w3-text-purple,.w3-hover-text-purple:hover{color:#9c27b0!important}
.w3-text-deep-purple,.w3-hover-text-deep-purple:hover{color:#673ab7!important}
.w3-text-red,.w3-hover-text-red:hover{color:#f44336!important}
.w3-text-sand,.w3-hover-text-sand:hover{color:#fdf5e6!important}
.w3-text-teal,.w3-hover-text-teal:hover{color:#009688!important}
.w3-text-yellow,.w3-hover-text-yellow:hover{color:#d2be0e!important}
.w3-text-white,.w3-hover-text-white:hover{color:#fff!important}
.w3-text-black,.w3-hover-text-black:hover{color:#000!important}
.w3-text-grey,.w3-hover-text-grey:hover,.w3-text-gray,.w3-hover-text-gray:hover{color:#757575!important}
.w3-text-light-grey,.w3-hover-text-light-grey:hover,.w3-text-light-gray,.w3-hover-text-light-gray:hover{color:#f1f1f1!important}
.w3-text-dark-grey,.w3-hover-text-dark-grey:hover,.w3-text-dark-gray,.w3-hover-text-dark-gray:hover{color:#3a3a3a!important}
.w3-border-amber,.w3-hover-border-amber:hover{border-color:#ffc107!important}
.w3-border-aqua,.w3-hover-border-aqua:hover{border-color:#00ffff!important}
.w3-border-blue,.w3-hover-border-blue:hover{border-color:#2196F3!important}
.w3-border-light-blue,.w3-hover-border-light-blue:hover{border-color:#87CEEB!important}
.w3-border-brown,.w3-hover-border-brown:hover{border-color:#795548!important}
.w3-border-cyan,.w3-hover-border-cyan:hover{border-color:#00bcd4!important}
.w3-border-blue-grey,.w3-hover-border-blue-grey:hover,.w3-border-blue-gray,.w3-hover-border-blue-gray:hover{border-color:#607d8b!important}
.w3-border-green,.w3-hover-border-green:hover{border-color:#4CAF50!important}
.w3-border-light-green,.w3-hover-border-light-green:hover{border-color:#8bc34a!important}
.w3-border-indigo,.w3-hover-border-indigo:hover{border-color:#3f51b5!important}
.w3-border-khaki,.w3-hover-border-khaki:hover{border-color:#f0e68c!important}
.w3-border-lime,.w3-hover-border-lime:hover{border-color:#cddc39!important}
.w3-border-orange,.w3-hover-border-orange:hover{border-color:#ff9800!important}
.w3-border-deep-orange,.w3-hover-border-deep-orange:hover{border-color:#ff5722!important}
.w3-border-pink,.w3-hover-border-pink:hover{border-color:#e91e63!important}
.w3-border-purple,.w3-hover-border-purple:hover{border-color:#9c27b0!important}
.w3-border-deep-purple,.w3-hover-border-deep-purple:hover{border-color:#673ab7!important}
.w3-border-red,.w3-hover-border-red:hover{border-color:#f44336!important}
.w3-border-sand,.w3-hover-border-sand:hover{border-color:#fdf5e6!important}
.w3-border-teal,.w3-hover-border-teal:hover{border-color:#009688!important}
.w3-border-yellow,.w3-hover-border-yellow:hover{border-color:#ffeb3b!important}
.w3-border-white,.w3-hover-border-white:hover{border-color:#fff!important}
.w3-border-black,.w3-hover-border-black:hover{border-color:#000!important}
.w3-border-grey,.w3-hover-border-grey:hover,.w3-border-gray,.w3-hover-border-gray:hover{border-color:#9e9e9e!important}
.w3-border-light-grey,.w3-hover-border-light-grey:hover,.w3-border-light-gray,.w3-hover-border-light-gray:hover{border-color:#f1f1f1!important}
.w3-border-dark-grey,.w3-hover-border-dark-grey:hover,.w3-border-dark-gray,.w3-hover-border-dark-gray:hover{border-color:#616161!important}
.w3-border-pale-red,.w3-hover-border-pale-red:hover{border-color:#ffe7e7!important}.w3-border-pale-green,.w3-hover-border-pale-green:hover{border-color:#e7ffe7!important}
.w3-border-pale-yellow,.w3-hover-border-pale-yellow:hover{border-color:#ffffcc!important}.w3-border-pale-blue,.w3-hover-border-pale-blue:hover{border-color:#e7ffff!important}

14
humans.txt Normal file
View file

@ -0,0 +1,14 @@
/* TEAM */
Projet: Knah Tsaeb
From: France
/* SITE */
Last update:2020/01/02
Language: English
Doctype:HTML5
IDE: Code OSS
/* TECHNOLOGY */
CSS3, HTML5
W3C.css, Plates

97
index.php Normal file
View file

@ -0,0 +1,97 @@
<?php
session_start();
/**
* /mnt/Stock/http/img.local/photos/;/mnt/Stock/http/img.local/photos/Vidéos/test/
*/
/**
* Améliore la sortie print.
*
* @author Tatane http://www.tatane.info/index.php/print_rn
* @author http://www.blog.cactuscrew.com/77-print_rn.html
*
* @param $data (array) tableau à examiner
* @param $name (string) nom a affiché
*
* @return false affiche les clef valeur du tableau $data
*/
function n_print($data, $name = '')
{
$aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>';
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '</fieldset><br />';
}
require 'vendor/autoload.php';
require 'apps/config.php';
$templates = new League\Plates\Engine('template');
if (file_exists('config/config.php')) {
$config = MyConfig::read('config');
} else {
$page = 'install';
}
require 'apps/input.php';
if (!empty($page) && $page === 'about') {
echo $templates->render($page);
}
if (!empty($page) && $page === 'install' && !file_exists('config/config.php')) {
if (!isset($createLogin) && empty($createLogin)) {
echo $templates->render($page, ['missing' => 'login']);
exit();
}
if (!isset($createPassword) && empty($createPassword)) {
echo $templates->render($page, ['missing' => 'password']);
exit();
}
if (!isset($createPath) && empty($createPath)) {
echo $templates->render($page, ['missing' => 'path']);
exit();
}
$conf = array('login' => $createLogin, 'password' => $createPassword, 'listOfDestPath' => $createPath);
$config = MyConfig::write('config', $conf);
$page = 'login';
}
if (!empty($page) && $page === 'login') {
$loginError = false;
if (!empty($_POST['login'])) {
$login = filter_input(INPUT_POST, 'login', FILTER_SANITIZE_SPECIAL_CHARS);
if ($login !== $config['login']) {
$loginError = true;
}
} else {
$loginError = true;
}
if (!empty($_POST['password'])) {
if (!password_verify($_POST['password'], $config['password'])) {
$loginError = true;
}
} else {
$loginError = true;
}
if ($loginError) {
echo $templates->render('login');
} else {
echo $templates->render('addVideo', array('listOfDestPath' => $config['listOfDestPath']));
}
$_SESSION['login'] = 'logged';
}
if (empty($page)) {
if (isset($_SESSION['login']) && $_SESSION['login'] === 'logged') {
echo $templates->render('addVideo', array('listOfDestPath' => $config['listOfDestPath']));
} else {
echo $templates->render('login');
}
}
//echo $templates->render($page);

2
robots.txt Normal file
View file

@ -0,0 +1,2 @@
User-agent: *
Disallow: /

1
script/.htaccess Normal file
View file

@ -0,0 +1 @@
Deny from All

32
script/cronTask.sh.sample Normal file
View file

@ -0,0 +1,32 @@
#!/bin/bash/
######################
#### START CONFIG ####
######################
tmpDir=../tmp/
######################
#### END CONFIG ######
######################
cd $tmpDir
if [ -f task.lock ];
then
exit
fi
touch task.lock
for file in $tempDest*.request
do
if [ -f $tmpDir/$file ];
then
while IFS=';' read url finalPath
do
echo $url
echo $finalPath
youtube-dl -c --write-thumbnail --write-sub --sub-lang fr --write-info-json --no-check-certificate -f "[height <=?720]" -o $finalPath"%(title)s.%(ext)s" "$url"
done < $file
rm $file
fi
done
rm task.lock

1
template/.htaccess Normal file
View file

@ -0,0 +1 @@
Deny from All

5
template/about.php Normal file
View file

@ -0,0 +1,5 @@
<?php $this->layout('template') ?>
<h2>About</h2>
<p>
<b>PER</b>sonal <b>YOU</b>tube-dl <b>DOW</b>nloader is limited PHP/HTML GUI for downloading video on your machine.
</p>

20
template/addVideo.php Normal file
View file

@ -0,0 +1,20 @@
<?php $this->layout('template')?>
<h3>Add video</h3>
<form method="post" class="w3-container">
<label class="w3-text-teal">Video URL</label>
<input type="text" name="videoUrl" class="w3-input w3-border w3-round" required/>
<label class="w3-text-teal">Destination path</label>
<select name="destination" class="w3-select w3-border w3-round" required>
<?php foreach ($listOfDestPath as $key => $value): ?>
<option value="<?=$key?>"><?=$value?></option>
<?php endforeach?>
</select>
<input type="submit" class="w3-button w3-teal w3-round"/>
</form>
<form class="w3-container" method="post">
<input type="hidden" name="logout" value="true"/>
<input class="w3-button w3-teal w3-round" type="submit" value="Logout">
</form>

18
template/install.php Normal file
View file

@ -0,0 +1,18 @@
<?php $this->layout('template') ?>
<h3>Setup</h3>
<p>
<?php if(!empty($missing)):?>
You must complete <span class="error"><?=$missing?></span> field.
<?php endif ?>
</p>
<form method="post" class="w3-container">
<label class="w3-text-teal">Login</label>
<input class="w3-input w3-border w3-round" type="text" name="createLogin" reuired/>
<label class="w3-text-teal">Password</label>
<input class="w3-input w3-border w3-round" type="password" name="createPassword" requred/>
<label class="w3-text-teal">List of destination path (separe by semicolon)
<textarea name="createPath" class="w3-input w3-border w3-round" ></textarea>
<input type="hidden" name="page" value="install"/>
<input class="w3-button w3-input w3-border w3-round" type="submit" value="Register" />
</form>

12
template/login.php Normal file
View file

@ -0,0 +1,12 @@
<?php $this->layout('template') ?>
<h3>Login</h3>
<form method="post" class="w3-container">
<label class="w3-text-teal">Login</label>
<input type="text" name="login" class="w3-input w3-border w3-round"/>
<label class="w3-text-teal">Password</label>
<input type="password" name="password" class="w3-input w3-border w3-round"/>
<input type="hidden" name="page" value="login"/>
<input type="submit" value="Login" class="w3-button w3-teal w3-round"/>
</form>

24
template/template.php Normal file
View file

@ -0,0 +1,24 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PerYouDow</title>
<meta name="description" content="PERsonal YOUtube DOWloader">
<meta name="author" content="Knah Tsaeb">
<link rel="stylesheet" href="css/w3.css">
<link rel="stylesheet" href="css/local.css">
<link rel="author" href="humans.txt" />
</head>
<body style="width:60%; margin:0 auto">
<header class="w3-container w3-teal">
<h1><a href="index.php">PerYouDow</a></h1>
</header>
<div class="w3-container w3-section">
<?=$this->section('content')?>
</div>
<footer class="w3-container w3-teal">
<p><a href="">Source<a> | <a href="?page=about">About</a> | <a href="https://fr.wikipedia.org/wiki/WTFPL">Licence WTFPL</a></p>
</footer>
</body>
</html>

0
tmp/.gitkeep Normal file
View file

7
vendor/autoload.php vendored Normal file
View file

@ -0,0 +1,7 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit87aa1b93006dd3e21f13b7afcae147e1::getLoader();

445
vendor/composer/ClassLoader.php vendored Normal file
View file

@ -0,0 +1,445 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

21
vendor/composer/LICENSE vendored Normal file
View file

@ -0,0 +1,21 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

9
vendor/composer/autoload_classmap.php vendored Normal file
View file

@ -0,0 +1,9 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View file

@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

10
vendor/composer/autoload_psr4.php vendored Normal file
View file

@ -0,0 +1,10 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'League\\Plates\\' => array($vendorDir . '/league/plates/src'),
);

52
vendor/composer/autoload_real.php vendored Normal file
View file

@ -0,0 +1,52 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit87aa1b93006dd3e21f13b7afcae147e1
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit87aa1b93006dd3e21f13b7afcae147e1', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit87aa1b93006dd3e21f13b7afcae147e1', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit87aa1b93006dd3e21f13b7afcae147e1::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
return $loader;
}
}

31
vendor/composer/autoload_static.php vendored Normal file
View file

@ -0,0 +1,31 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInit87aa1b93006dd3e21f13b7afcae147e1
{
public static $prefixLengthsPsr4 = array (
'L' =>
array (
'League\\Plates\\' => 14,
),
);
public static $prefixDirsPsr4 = array (
'League\\Plates\\' =>
array (
0 => __DIR__ . '/..' . '/league/plates/src',
),
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit87aa1b93006dd3e21f13b7afcae147e1::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit87aa1b93006dd3e21f13b7afcae147e1::$prefixDirsPsr4;
}, null, ClassLoader::class);
}
}

59
vendor/composer/installed.json vendored Normal file
View file

@ -0,0 +1,59 @@
[
{
"name": "league/plates",
"version": "3.3.0",
"version_normalized": "3.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/plates.git",
"reference": "b1684b6f127714497a0ef927ce42c0b44b45a8af"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/plates/zipball/b1684b6f127714497a0ef927ce42c0b44b45a8af",
"reference": "b1684b6f127714497a0ef927ce42c0b44b45a8af",
"shasum": ""
},
"require": {
"php": "^5.3 | ^7.0"
},
"require-dev": {
"mikey179/vfsstream": "^1.4",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~1.5"
},
"time": "2016-12-28T00:14:17+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"League\\Plates\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jonathan Reinink",
"email": "jonathan@reinink.ca",
"role": "Developer"
}
],
"description": "Plates, the native PHP template system that's fast, easy to use and easy to extend.",
"homepage": "http://platesphp.com",
"keywords": [
"league",
"package",
"templates",
"templating",
"views"
]
}
]

22
vendor/league/plates/CONTRIBUTING.md vendored Normal file
View file

@ -0,0 +1,22 @@
# Contributing
Contributions are **welcome** and will be fully **credited**.
We accept contributions via Pull Requests on [Github](https://github.com/thephpleague/plates).
## Pull Requests
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the README and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow semver. Randomly breaking public APIs is not an option.
- **Create topic branches** - Don't ask us to pull from your master branch.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.
## Running Tests
``` bash
$ phpunit
```
**Happy coding**!

21
vendor/league/plates/LICENSE vendored Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013 The League of Extraordinary Packages
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

63
vendor/league/plates/README.md vendored Normal file
View file

@ -0,0 +1,63 @@
Plates
======
[![Author](http://img.shields.io/badge/author-@reinink-blue.svg?style=flat-square)](https://twitter.com/reinink)
[![Source Code](http://img.shields.io/badge/source-league/plates-blue.svg?style=flat-square)](https://github.com/thephpleague/plates)
[![Latest Version](https://img.shields.io/github/release/thephpleague/plates.svg?style=flat-square)](https://github.com/thephpleague/plates/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/thephpleague/plates/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/plates)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/plates.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/plates/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/plates.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/plates)
[![Total Downloads](https://img.shields.io/packagist/dt/league/plates.svg?style=flat-square)](https://packagist.org/packages/league/plates)
Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent [Twig](http://twig.sensiolabs.org/) template engine and strives to bring modern template language functionality to native PHP templates. Plates is designed for developers who prefer to use native PHP templates over compiled template languages, such as Twig or Smarty.
### Highlights
- Native PHP templates, no new [syntax](http://platesphp.com/templates/syntax/) to learn
- Plates is a template system, not a template language
- Plates encourages the use of existing PHP functions
- Increase code reuse with template [layouts](http://platesphp.com/templates/layouts/) and [inheritance](http://platesphp.com/templates/inheritance/)
- Template [folders](http://platesphp.com/engine/folders/) for grouping templates into namespaces
- [Data](http://platesphp.com/templates/data/#preassigned-and-shared-data) sharing across templates
- Preassign [data](http://platesphp.com/templates/data/#preassigned-and-shared-data) to specific templates
- Built-in [escaping](http://platesphp.com/templates/escaping/) helpers
- Easy to extend using [functions](http://platesphp.com/engine/functions/) and [extensions](http://platesphp.com/engine/extensions/)
- Framework-agnostic, will work with any project
- Decoupled design makes templates easy to test
- Composer ready and PSR-2 compliant
## Installation
Plates is available via Composer:
```
composer require league/plates
```
## Documentation
Full documentation can be found at [platesphp.com](http://platesphp.com/).
## Testing
```bash
phpunit
```
## Contributing
Please see [CONTRIBUTING](https://github.com/thephpleague/plates/blob/master/CONTRIBUTING.md) for details.
## Security
If you discover any security related issues, please email jonathan@reinink.ca instead of using the issue tracker.
## Credits
- [Jonathan Reinink](https://github.com/reinink)
- [All Contributors](https://github.com/thephpleague/plates/contributors)
## License
The MIT License (MIT). Please see [License File](https://github.com/thephpleague/plates/blob/master/LICENSE) for more information.

41
vendor/league/plates/composer.json vendored Normal file
View file

@ -0,0 +1,41 @@
{
"name": "league/plates",
"description": "Plates, the native PHP template system that's fast, easy to use and easy to extend.",
"keywords": [
"league",
"package",
"templating",
"templates",
"views"
],
"homepage": "http://platesphp.com",
"license": "MIT",
"authors" : [
{
"name": "Jonathan Reinink",
"email": "jonathan@reinink.ca",
"role": "Developer"
}
],
"require" : {
"php": "^5.3 | ^7.0"
},
"require-dev": {
"mikey179/vfsStream": "^1.4",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~1.5"
},
"autoload": {
"psr-4": {
"League\\Plates\\": "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"scripts": {
"test": "phpunit"
}
}

1
vendor/league/plates/docs/CNAME vendored Normal file
View file

@ -0,0 +1 @@
platesphp.com

View file

@ -0,0 +1,8 @@
# Path to project specific favicon.ico, leave blank to use default
favicon: /favicon.ico
# Path to project specific apple-touch-icon-precomposed.png, leave blank to use default
apple_touch: /apple-touch-icon-precomposed.png
# Path to project logo
logo: /logo.png

View file

@ -0,0 +1,24 @@
Getting Started:
Introduction: '/'
Simple example: '/simple-example/'
Installation: '/installation/'
Changelog: '/changelog/'
The Engine:
Overview: '/engine/'
File extensions: '/engine/file-extensions/'
Folders: '/engine/folders/'
Functions: '/engine/functions/'
Extensions: '/engine/extensions/'
Templates:
Overview: '/templates/'
Data: '/templates/data/'
Functions: '/templates/functions/'
Nesting: '/templates/nesting/'
Layouts: '/templates/layouts/'
Sections: '/templates/sections/'
Inheritance: '/templates/inheritance/'
Escaping: '/templates/escaping/'
Syntax: '/templates/syntax/'
Extensions:
Asset: '/extensions/asset/'
URI: '/extensions/uri/'

View file

@ -0,0 +1,4 @@
title: Plates
tagline: Native PHP Templates
description: 'Plates is a Twig inspired, native PHP template system that brings modern template language functionality to native PHP templates.'
google_analytics_tracking_id: UA-46050814-2

View file

@ -0,0 +1,107 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% if page.url == '/' %}
<title>{{ site.data.project.title }} - {{ site.data.project.tagline }}</title>
{% else %}
<title>{{ page.title }} - {{ site.data.project.title }}</title>
{% endif %}
{% if site.data.project.description %}
<meta name="description" content="{{ site.data.project.description }}">
{% endif %}
{% if site.github.url %}
<base href="{{ site.github.url }}">
{% endif %}
{% if site.data.images.favicon %}
<link rel="icon" type="image/x-icon" href="{{ site.data.images.favicon }}" />
{% else %}
<link rel="icon" type="image/x-icon" href="http://theme.thephpleague.com/img/favicon.ico" />
{% endif %}
{% if site.data.images.apple_touch %}
<link rel="apple-touch-icon-precomposed" href="{{ site.data.images.apple_touch }}">
{% else %}
<link rel="apple-touch-icon-precomposed" href="http://theme.thephpleague.com/img/apple-touch-icon-precomposed.png">
{% endif %}
<link rel="stylesheet" href="http://theme.thephpleague.com/css/all.css">
<link rel="stylesheet" href="/css/custom.css">
</head>
<body>
<a href="https://github.com/thephpleague/plates" class="github">
<img src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png">
</a>
<section class="all_packages">
<a href="http://thephpleague.com/">
<img src="http://theme.thephpleague.com/img/loep_logo.png" width="195" height="200" alt="The League of Extraordinary Packages">
</a>
<h2>Our Packages:</h2>
<ul>
<!-- Loaded via JavaScript -->
</ul>
</section>
<header>
<a class="logo" href="/">
{% if site.data.images.logo %}
<span class="icon">
<img src="{{ site.data.images.logo }}" width="50" height="40" alt="{{ site.data.project.title }} - {{ site.data.project.tagline }}">
</span>
{% endif %}
<span class="name">{{ site.data.project.title }}</span>
<span class="tagline">{{ site.data.project.tagline }}</span>
</a>
<a href="http://thephpleague.com/" class="league">
Presented by The League of Extraordinary Packages
</a>
</header>
<input type="checkbox" id="menu">
<label for="menu" onclick>
<div class="closed">&#9776; Menu</div>
<div class="open">&#9776; Hide Menu</div>
</label>
<main>
<menu>
{% for section in site.data.menu %}
<h2>{{ section[0] }}</h2>
<ul>
{% for link in section[1] %}
<li {% if page.url == link[1] %}class="selected"{% endif %}>
<a href="{{ link[1] }}">{{ link[0] }}</a>
</li>
{% endfor %}
</ul>
{% endfor %}
</menu>
<article>
{{ content }}
</article>
</main>
<footer>
<span>&copy; Copyright <a href="http://thephpleague.com">The League of Extraordinary Packages</a>.</span>
<span>Site design by <a href="http://reinink.ca">Jonathan Reinink</a>.</span>
</footer>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://theme.thephpleague.com/js/scripts.js"></script>
<script src="http://theme.thephpleague.com/js/prism.js"></script>
{% if site.data.project.google_analytics_tracking_id %}
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','{{ site.data.project.google_analytics_tracking_id }}');ga('send','pageview');
</script>
{% endif %}
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

15
vendor/league/plates/docs/changelog.md vendored Normal file
View file

@ -0,0 +1,15 @@
---
layout: default
permalink: changelog/
title: Changelog
---
Changelog
=========
All notable changes to this project will be documented in this file.
{% for release in site.github.releases %}
## [{{ release.name }}]({{ release.html_url }}) - {{ release.published_at | date: "%Y-%m-%d" }}
{{ release.body | markdownify }}
{% endfor %}

View file

@ -0,0 +1,16 @@
---
---
.github {
position: absolute;
top: 0;
right: 0;
border: 0;
z-index: 1000;
}
@media screen and (max-width: 1065px) {
.github {
display: none;
}
}

View file

@ -0,0 +1,120 @@
---
layout: default
permalink: engine/extensions/
title: Extensions
---
Extensions
==========
Creating extensions couldn't be easier, and can really make Plates sing for your specific project. Start by creating a class that implements `\League\Plates\Extension\ExtensionInterface`. Next, register your template [functions](/engine/functions/) within a `register()` method.
## Simple extensions example
~~~ php
use League\Plates\Engine;
use League\Plates\Extension\ExtensionInterface;
class ChangeCase implements ExtensionInterface
{
public function register(Engine $engine)
{
$engine->registerFunction('uppercase', [$this, 'uppercaseString']);
$engine->registerFunction('lowercase', [$this, 'lowercaseString']);
}
public function uppercaseString($var)
{
return strtoupper($var);
}
public function lowercaseString($var)
{
return strtolower($var);
}
}
~~~
To use this extension in your template, simply call your new functions:
~~~ php
<p>Hello, <?=$this->e($this->uppercase($name))?></p>
~~~
They can also be used in a [batch](/templates/functions/#batch-function-calls) compatible function:
~~~ php
<h1>Hello <?=$this->e($name, 'uppercase')</h1>
~~~
## Single method extensions
Alternatively, you may choose to expose the entire extension object to the template using a single function. This can make your templates more legible and also reduce the chance of conflicts with other extensions.
~~~ php
use League\Plates\Engine;
use League\Plates\Extension\ExtensionInterface;
class ChangeCase implements ExtensionInterface
{
public function register(Engine $engine)
{
$engine->registerFunction('case', [$this, 'getObject']);
}
public function getObject()
{
return $this;
}
public function upper($var)
{
return strtoupper($var);
}
public function lower($var)
{
return strtolower($var);
}
}
~~~
To use this extension in your template, first call the primary function, then the secondary functions:
~~~ php
<p>Hello, <?=$this->e($this->case()->upper($name))?></p>
~~~
## Loading extensions
To enable an extension, load it into the [engine](/engine/) object using the `loadExtension()` method.
~~~ php
$engine->loadExtension(new ChangeCase());
~~~
## Accessing the engine and template
It may be desirable to access the `engine` or `template` objects from within your extension. Plates makes both of these objects available to you. The engine is automatically passed to the `register()` method, and the template is assigned as a parameter on each function call.
~~~ php
use League\Plates\Engine;
use League\Plates\Extension\ExtensionInterface;
class MyExtension implements ExtensionInterface
{
protected $engine;
public $template; // must be public
public function register(Engine $engine)
{
$this->engine = $engine;
// Access template data:
$data = $this->template->data();
// Register functions
// ...
}
}
~~~

View file

@ -0,0 +1,36 @@
---
layout: default
permalink: engine/file-extensions/
title: File extensions
---
File extensions
===============
Plates does not enforce a specific template file extension. By default it assumes `.php`. This file extension is automatically appended to your template names when rendered. You are welcome to change the default extension using one of the following methods.
## Constructor method
~~~ php
// Create new engine and set the default file extension to ".tpl"
$template = new League\Plates\Engine('/path/to/templates', 'tpl');
~~~
## Setter method
~~~ php
// Sets the default file extension to ".tpl" after engine instantiation
$template->setFileExtension('tpl');
~~~
## Manually assign
If you prefer to manually set the file extension, simply set the default file extension to `null`.
~~~ php
// Disable automatic file extensions
$template->setFileExtension(null);
// Render template
echo $templates->render('home.php');
~~~

View file

@ -0,0 +1,50 @@
---
layout: default
permalink: engine/folders/
title: Folders
---
Folders
=======
Folders make it really easy to organize and access your templates. Folders allow you to group your templates under different namespaces, each of which having their own file system path.
## Creating folders
To create folders, use the `addFolder()` method:
~~~ php
// Create new Plates instance
$templates = new League\Plates\Engine();
// Add folders
$templates->addFolder('admin', '/path/to/admin/templates');
$templates->addFolder('emails', '/path/to/email/templates');
~~~
## Using folders
To use the folders you created within your project simply append the folder name with two colons before the template name. For example, to render a welcome email:
~~~ php
$email = $templates->render('emails::welcome');
~~~
This works with template functions as well, such as layouts or nested templates. For example:
~~~ php
<?php $this->layout('shared::template') ?>
~~~
## Folder fallbacks
When enabled, if a folder template is missing, Plates will automatically fallback and look for a template with the **same** name in the default folder. This can be helpful when using folders to manage themes. To enable fallbacks, simply pass `true` as the third parameter in the `addFolders()` method.
~~~ php
// Create new Plates engine
$templates = new \League\Plates\Engine('/path/to/default/theme');
// Add themes
$templates->addFolder('theme1', '/path/to/theme/1', true);
$templates->addFolder('theme2', '/path/to/theme/2', true);
~~~

View file

@ -0,0 +1,34 @@
---
layout: default
permalink: engine/functions/
title: Functions
---
Functions
=========
While [extensions](/engine/extensions/) are awesome for adding additional reusable functionality to Plates, sometimes it's easier to just create a one-off function for a specific use case. Plates makes this easy to do.
## Registering functions
~~~ php
// Create new Plates engine
$templates = new \League\Plates\Engine('/path/to/templates');
// Register a one-off function
$templates->registerFunction('uppercase', function ($string) {
return strtoupper($string);
});
~~~
To use this function in a template, simply call it like any other function:
~~~ php
<h1>Hello <?=$this->e($this->uppercase($name))</h1>
~~~
It can also be used in a [batch](/templates/functions/#batch-function-calls) compatible function:
~~~ php
<h1>Hello <?=$this->e($name, 'uppercase')</h1>
~~~

View file

@ -0,0 +1,56 @@
---
layout: default
permalink: engine/
title: The Engine
---
The Engine
==========
Plates uses a central object called the `Engine`, which is used to store the environment configuration, functions and extensions. It helps decouple your templates from the file system and other dependencies. For example, if you want to change the folder where your templates are stored, you can do so by simply changing the path in one location.
## Basic usage
~~~ php
// Create new Plates engine
$templates = new League\Plates\Engine('/path/to/templates');
// Add any any additional folders
$templates->addFolder('emails', '/path/to/emails');
// Load any additional extensions
$templates->loadExtension(new League\Plates\Extension\Asset('/path/to/public'));
// Create a new template
$template = $templates->make('emails::welcome');
~~~
## Dependency Injection
Plates is designed to be easily passed around your application and easily injected in your controllers or other application objects. Simply pass an instance of the `Engine` to any consuming objects, and then use either the `make()` method to create a new template, or the `render()` method to render it immediately. For example:
~~~ php
class Controller
{
private $templates;
public function __construct(League\Plates\Engine $templates)
{
$this->templates = $templates;
}
// Create a template object
public function getIndex()
{
$template = $this->templates->make('home');
return $template->render();
}
// Render a template directly
public function getIndex()
{
return $this->templates->render('home');
}
}
~~~

View file

@ -0,0 +1,59 @@
---
layout: default
permalink: extensions/asset/
title: Asset extension
---
Asset
=====
The asset extension can be used to quickly create "cache busted" asset URLs in your templates. This is particularly helpful for aggressively cached files that can potentially change in the future, such as CSS files, JavaScript files and images. It works by appending the timestamp of the file's last update to its URL. For example, `/css/all.css` becomes `/css/all.1373577602.css`. As long as the file does not change, the timestamp remains the same and caching occurs. However, if the file is changed, a new URL is automatically generated with a new timestamp, and visitors receive the new file.
## Installing the asset extension
The asset extension comes packaged with Plates but is not enabled by default, as it requires extra parameters passed to it at instantiation.
~~~ php
// Load asset extension
$engine->loadExtension(new League\Plates\Extension\Asset('/path/to/public/assets/', true));
~~~
The first constructor parameter is the file system path of the assets directory. The second is an optional `boolean` parameter that if set to true uses the filename caching method (ie. `file.1373577602.css`) instead of the default query string method (ie. `file.css?v=1373577602`).
## Filename caching
To make filename caching work, some URL rewriting is required:
### Apache example
~~~ php
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>
~~~
### Nginx example
~~~ php
location ~* (.+)\.(?:\d+)\.(js|css|png|jpg|jpeg|gif)$ {
try_files $uri $1.$2;
}
~~~
## Using the asset extension
~~~ php
<html>
<head>
<title>Asset Extension Example</title>
<link rel="stylesheet" href="<?=$this->asset('/css/all.css')?>" />
</head>
<body>
<img src="<?=$this->asset('/img/logo.png')?>">
</body>
</html>
~~~

View file

@ -0,0 +1,83 @@
---
layout: default
permalink: extensions/uri/
title: URI extension
---
URI
===
The URI extension is designed to make URI checks within templates easier. The most common use is marking the current page in a menu as "selected". It only has one function, `uri()`, but can do a number of helpful tasks depending on the parameters passed to it.
## Installing the URI extension
The URI extension comes packaged with Plates but is not enabled by default, as it requires an extra parameter passed to it at instantiation.
~~~ php
// Load URI extension using global variable
$engine->loadExtension(new League\Plates\Extension\URI($_SERVER['PATH_INFO']));
// Load URI extension using a HttpFoundation's request object
$engine->loadExtension(new League\Plates\Extension\URI($request->getPathInfo()));
~~~
## URI example
~~~ php
<ul>
<li <?=$this->uri('/', 'class="selected"')?>><a href="/">Home</a></li>
<li <?=$this->uri('/about', 'class="selected"')?>><a href="/about">About</a></li>
<li <?=$this->uri('/products', 'class="selected"')?>><a href="/products">Products</a></li>
<li <?=$this->uri('/contact', 'class="selected"')?>><a href="/contact">Contact</a></li>
</ul>
~~~
## Using the URI extension
Get the whole URI.
~~~ php
<?=$this->uri()?>
~~~
Get a specified segment of the URI.
~~~ php
<?=$this->uri(1)?>
~~~
Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns `true` on success or `false` on failure.
~~~ php
<?php if ($this->uri(1, 'home')): ?>
~~~
Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns string (third parameter) on success or `false` on failure.
~~~ php
<?=$this->uri(1, 'home', 'success')?>
~~~
Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns string (third parameter) on success or string (fourth parameter) on failure.
~~~ php
<?=$this->uri(1, 'home', 'success', 'fail')?>
~~~
Check if a regular expression string matches the current URI. Returns `true` on success or `false` on failure.
~~~ php
<?php if($this->uri('/home')): ?>
~~~
Check if a regular expression string (first parameter) matches the current URI. Returns string (second parameter) on success or `false` on failure.
~~~ php
<?=$this->uri('/home', 'success')?>
~~~
Check if a regular expression string (first parameter) matches the current URI. Returns string (second parameter) on success or string (third parameter) on failure.
~~~ php
<?=$this->uri('/home', 'success', 'fail')?>
~~~

BIN
vendor/league/plates/docs/favicon.ico vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

40
vendor/league/plates/docs/index.md vendored Normal file
View file

@ -0,0 +1,40 @@
---
layout: default
permalink: /
title: Introduction
---
Introduction
============
[![Author](http://img.shields.io/badge/author-@reinink-blue.svg?style=flat-square)](https://twitter.com/reinink)
[![Source Code](http://img.shields.io/badge/source-league/plates-blue.svg?style=flat-square)](https://github.com/thephpleague/plates)
[![Latest Version](https://img.shields.io/github/release/thephpleague/plates.svg?style=flat-square)](https://github.com/thephpleague/plates/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/thephpleague/plates/blob/master/LICENSE)<br />
[![Build Status](https://img.shields.io/travis/thephpleague/plates/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/plates)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/plates.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/plates/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/plates.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/plates)
[![Total Downloads](https://img.shields.io/packagist/dt/league/plates.svg?style=flat-square)](https://packagist.org/packages/league/plates)
## About
Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent [Twig](http://twig.sensiolabs.org/) template engine and strives to bring modern template language functionality to native PHP templates. Plates is designed for developers who prefer to use native PHP templates over compiled template languages, such as Twig or Smarty.
## Highlights
- Native PHP templates, no new [syntax](/templates/syntax/) to learn
- Plates is a template system, not a template language
- Plates encourages the use of existing PHP functions
- Increase code reuse with template [layouts](/templates/layouts/) and [inheritance](/templates/inheritance/)
- Template [folders](/engine/folders/) for grouping templates into namespaces
- [Data](/templates/data/#preassigned-and-shared-data) sharing across templates
- Preassign [data](/templates/data/#preassigned-and-shared-data) to specific templates
- Built-in [escaping](/templates/escaping/) helpers
- Easy to extend using [functions](/engine/functions/) and [extensions](/engine/extensions/)
- Framework-agnostic, will work with any project
- Decoupled design makes templates easy to test
- Composer ready and PSR-2 compliant
## Questions?
Plates was created by [Jonathan Reinink](https://twitter.com/reinink). Submit issues to [Github](https://github.com/thephpleague/plates/issues).

View file

@ -0,0 +1,35 @@
---
layout: default
permalink: installation/
title: Installation
---
Installation
============
## Using Composer
Plates is available on [Packagist](https://packagist.org/packages/league/plates) and can be installed using [Composer](https://getcomposer.org/). This can be done by running the following command or by updating your `composer.json` file.
~~~ bash
composer require league/plates
~~~
<div class="filename">composer.json</div>
~~~ javascript
{
"require": {
"league/plates": "3.*"
}
}
~~~
Be sure to also include your Composer autoload file in your project:
~~~ php
require 'vendor/autoload.php';
~~~
## Downloading .zip file
This project is also available for download as a `.zip` file on GitHub. Visit the [releases page](https://github.com/thephpleague/plates/releases), select the version you want, and click the "Source code (zip)" download button.

BIN
vendor/league/plates/docs/logo.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,54 @@
---
layout: default
permalink: simple-example/
title: Simple example
---
Simple example
==============
Here is a simple example of how to use Plates. We will assume the following directory stucture:
~~~
`-- path
`-- to
`-- templates
|-- template.php
|-- profile.php
~~~
## Within your controller
~~~ php
// Create new Plates instance
$templates = new League\Plates\Engine('/path/to/templates');
// Render a template
echo $templates->render('profile', ['name' => 'Jonathan']);
~~~
## The page template
<div class="filename">profile.php</div>
~~~ php
<?php $this->layout('template', ['title' => 'User Profile']) ?>
<h1>User Profile</h1>
<p>Hello, <?=$this->e($name)?></p>
~~~
## The layout template
<div class="filename">template.php</div>
~~~ php
<html>
<head>
<title><?=$this->e($title)?></title>
</head>
<body>
<?=$this->section('content')?>
</body>
</html>
~~~

View file

@ -0,0 +1,61 @@
---
layout: default
permalink: templates/data/
title: Data
---
Data
====
It's very common to share application data (variables) with a template. Data can be whatever you want: strings, arrays, objects, etc. Plates allows you set both template specific data as well as shared template data.
## Assign data
Assigning data is done from within your application code, such as a controller. There are a number of ways to assign the data, depending on how you structure your objects.
~~~ php
// Create new Plates instance
$templates = new League\Plates\Engine('/path/to/templates');
// Assign via the engine's render method
echo $templates->render('profile', ['name' => 'Jonathan']);
// Assign via the engine's make method
$template = $templates->make('profile', ['name' => 'Jonathan']);
// Assign directly to a template object
$template = $templates->make('profile');
$template->data(['name' => 'Jonathan']);
~~~
## Accessing data
Template data is available as locally scoped variables at the time of rendering. Continuing with the example above, here is how you would [escape](/templates/escaping/) and output the "name" value in a template:
~~~ php
<p>Hello <?=$this->e($name)?></p>
~~~
<p class="message-notice">Prior to Plates 3.0, variables were accessed using the <code>$this</code> pseudo-variable. This is no longer possible. Use the locally scoped variables instead.</p>
## Preassigned and shared data
If you have data that you want assigned to a specific template each time that template is rendered throughout your application, the `addData()` function can help organize that code in one place.
~~~ php
$templates->addData(['name' => 'Jonathan'], 'emails::welcome');
~~~
You can pressaign data to more than one template by passing an array of templates:
~~~ php
$templates->addData(['name' => 'Jonathan'], ['login', 'template']);
~~~
To assign data to ALL templates, simply omit the second parameter:
~~~ php
$templates->addData(['name' => 'Jonathan']);
~~~
Keep in mind that shared data is assigned to a template when it's first created, meaning any conflicting data assigned that's afterwards to a specific template will overwrite the shared data. This is generally desired behavior.

View file

@ -0,0 +1,50 @@
---
layout: default
permalink: templates/escaping/
title: Escaping
---
Escaping
========
Escaping is a form of [data filtering](http://www.phptherightway.com/#data_filtering) which sanitizes unsafe, user supplied input prior to outputting it as HTML. Plates provides two shortcuts to the `htmlspecialchars()` function.
## Escaping example
~~~ php
<h1>Hello, <?=$this->escape($name)?></h1>
<!-- Using the alternative, shorthand function -->
<h1>Hello, <?=$this->e($name)?></h1>
~~~
## Batch function calls
The escape functions also support [batch](/templates/functions/#batch-function-calls) function calls, which allow you to apply multiple functions, including native PHP functions, to a variable at one time.
~~~ php
<p>Welcome <?=$this->e($name, 'strip_tags|strtoupper')?></p>
~~~
## Escaping HTML attributes
<p class="message-notice">It's VERY important to always double quote HTML attributes that contain escaped variables, otherwise your template will still be open to injection attacks.</p>
Some [libraries](http://framework.zend.com/manual/2.1/en/modules/zend.escaper.escaping-html-attributes.html) go as far as having a special function for escaping HTML attributes. However, this is somewhat redundant considering that if a developer forgets to properly quote an HTML attribute, they will likely also forget to use this special function. Here is how you properly escape HTML attributes:
~~~ php
<!-- Good -->
<img src="portrait.jpg" alt="<?=$this->e($name)?>">
<!-- BAD -->
<img src="portrait.jpg" alt='<?=$this->e($name)?>'>
<!-- BAD -->
<img src="portrait.jpg" alt=<?=$this->e($name)?>>
~~~
## Automatic escaping
Probably the biggest drawbacks to native PHP templates is the inability to auto-escape variables properly. Template languages like Twig and Smarty can identify "echoed" variables during a parsing stage and automatically escape them. This cannot be done in native PHP as the language does not offer overloading functionality for it's output functions (ie. `print` and `echo`).
Don't worry, escaping can still be done safely, it just means you are responsible for manually escaping each variable on output. Consider creating a snippet for one of the above, built-in escaping functions to make this process easier.

View file

@ -0,0 +1,47 @@
---
layout: default
permalink: templates/functions/
title: Functions
---
Functions
=========
Template functions in Plates are accessed using the `$this` pseudo-variable.
~~~ php
<p>Hello, <?=$this->escape($name)?></p>
~~~
## Custom fuctions
In addition to the functions included with Plates, it's also possible to add [one-off functions](/engine/functions/), or even groups of functions, known as [extensions](/engine/extensions/).
## Batch function calls
Sometimes you need to apply more than function to a variable in your templates. This can become somewhat illegible. The `batch()` function helps by allowing you to apply multiple functions, including native PHP functions, to a variable at one time.
~~~ php
<!-- Example without using batch -->
<p>Welcome <?=$this->escape(strtoupper(strip_tags($name)))?></p>
<!-- Example using batch -->
<p>Welcome <?=$this->batch($name, 'strip_tags|strtoupper|escape')?></p>
~~~
The [escape](/templates/escaping/) functions also support batch function calls.
~~~ php
<p>Welcome <?=$this->e($name, 'strip_tags|strtoupper')?></p>
~~~
The batch functions works well for "piped" functions that accept one parameter, modify it, and then return it. It's important to note that they execute functions left to right and will favour extension functions over native PHP functions if there are conflicts.
~~~ php
<!-- Will output: JONATHAN -->
<?=$this->batch('Jonathan', 'escape|strtolower|strtoupper')?>
<!-- Will output: jonathan -->
<?=$this->batch('Jonathan', 'escape|strtoupper|strtolower')?>
~~~

View file

@ -0,0 +1,73 @@
---
layout: default
permalink: templates/
title: Templates
---
Templates
=========
Plates templates are very simple PHP objects. Generally you'll want to create these using the two factory methods, `make()` and `render()`, in the [engine](/engine/). For example:
~~~ php
// Create new Plates instance
$templates = new League\Plates\Engine('/path/to/templates');
// Render a template in a subdirectory
echo $templates->render('partials/header');
// Render a template
echo $templates->render('profile', ['name' => 'Jonathan']);
~~~
For more information about how Plates is designed to be easily added to your application, see the section on [dependency injection](/engine/#dependency-injection).
## Manually creating templates
It's also possible to create templates manually. The only dependency they require is an instance of the [engine](/engine/) object. For example:
~~~ php
// Create new Plates instance
$templates = new League\Plates\Engine('/path/to/templates');
// Create a new template
$template = new League\Plates\Template\Template($templates, 'profile');
// Render the template
echo $template->render(['name' => 'Jonathan']);
// You can also render the template using the toString() magic method
echo $template;
~~~
## Check if a template exists
When dynamically loading templates, you may need to check if they exist. This can be done using the engine's `exists()` method:
~~~ php
if ($templates->exists('articles::beginners_guide')) {
// It exists!
}
~~~
You can also run this check on an existing template:
~~~ php
if ($template->exists()) {
// It exists!
}
~~~
## Get a template path
To get a template path from its name, use the engine's `path()` method:
~~~ php
$path = $templates->path('articles::beginners_guide');
~~~
You can also get the path from an existing template:
~~~ php
$path = $template->path();
~~~

View file

@ -0,0 +1,63 @@
---
layout: default
permalink: templates/inheritance/
title: Inheritance
---
Inheritance
===========
By combining [layouts](/templates/layouts/) and [sections](/templates/sections/), Plates allows you to "build up" your pages using predefined sections. This is best understand using an example:
## Inheritance example
The following example illustrates a pretty standard website. Start by creating a site template, which includes your header and footer as well as any predefined content [sections](/templates/sections/). Notice how Plates makes it possible to even set default section content, in the event that a page doesn't define it.
<div class="filename">template.php</div>
~~~ php
<html>
<head>
<title><?=$this->e($title)?></title>
</head>
<body>
<img src="logo.png">
<div id="page">
<?=$this->section('page')?>
</div>
<div id="sidebar">
<?php if ($this->section('sidebar')): ?>
<?=$this->section('sidebar')?>
<?php else: ?>
<?=$this->fetch('default-sidebar')?>
<?php endif ?>
</div>
</body>
</html>
~~~
With the template defined, any page can now "implement" this [layout](/templates/layouts/). Notice how each section of content is defined between the `start()` and `end()` functions.
<div class="filename">profile.php</div>
~~~ php
<?php $this->layout('template', ['title' => 'User Profile']) ?>
<?php $this->start('page') ?>
<h1>Welcome!</h1>
<p>Hello <?=$this->e($name)?></p>
<?php $this->stop() ?>
<?php $this->start('sidebar') ?>
<ul>
<li><a href="/link">Example Link</a></li>
<li><a href="/link">Example Link</a></li>
<li><a href="/link">Example Link</a></li>
<li><a href="/link">Example Link</a></li>
<li><a href="/link">Example Link</a></li>
</ul>
<?php $this->stop() ?>
~~~

View file

@ -0,0 +1,102 @@
---
layout: default
permalink: templates/layouts/
title: Layouts
---
Layouts
=======
The `layout()` function allows you to define a layout template that a template will implement. It's like having separate header and footer templates in one file.
## Define a layout
The `layout()` function can be called anywhere in a template, since the layout template is actually rendered second. Typically it's placed at the top of the file.
~~~ php
<?php $this->layout('template') ?>
<h1>User Profile</h1>
<p>Hello, <?=$this->e($name)?></p>
~~~
This function also works with [folders](/engine/folders/):
~~~ php
<?php $this->layout('shared::template') ?>
~~~
## Assign data
To assign data (variables) to a layout template, pass them as an array to the `layout()` function. This data will then be available as locally scoped variables within the layout template.
~~~ php
<?php $this->layout('template', ['title' => 'User Profile']) ?>
~~~
## Accessing the content
To access the rendered template content within the layout, use the `section()` function, passing `'content'` as the section name. This will return all outputted content from the template that hasn't been defined in a [section](/templates/sections/).
~~~ php
<html>
<head>
<title><?=$this->e($title)?></title>
</head>
<body>
<?=$this->section('content')?>
</body>
</html>
~~~
## Stacked layouts
Plates allows stacking of layouts, allowing even further simplification and organization of templates. Instead of just using one main layout, it's possible to break templates into more specific layouts, which themselves implement a main layout. Consider this example:
### The main site layout
<div class="filename">template.php</div>
~~~ php
<html>
<head>
<title><?=$this->e($title)?></title>
</head>
<body>
<?=$this->section('content')?>
</body>
</html>
~~~
### The blog layout
<div class="filename">blog.php</div>
~~~ php
<?php $this->layout('template') ?>
<h1>The Blog</h1>
<section>
<article>
<?=$this->section('content')?>
</article>
<aside>
<?=$this->insert('blog/sidebar')?>
</aside>
</section>
~~~
### A blog article
<div class="filename">blog-article.php</div>
~~~ php
<?php $this->layout('blog', ['title' => $article->title]) ?>
<h2><?=$this->e($article->title)?></h2>
<article>
<?=$this->e($article->content)?>
</article>
~~~

View file

@ -0,0 +1,44 @@
---
layout: default
permalink: templates/nesting/
title: Nesting
---
Nesting
=======
Including another template into the current template is done using the `insert()` function:
~~~ php
<?php $this->insert('partials/header') ?>
<p>Your content.</p>
<?php $this->insert('partials/footer') ?>
~~~
The `insert()` function also works with [folders](/engine/folders/):
~~~ php
<?php $this->insert('partials::header') ?>
~~~
## Alternative syntax
The `insert()` function automatically outputs the rendered template. If you prefer to manually output the response, use the `fetch()` function instead:
~~~ php
<?=$this->fetch('partials/header')?>
~~~
## Assign data
To assign data (variables) to a nested template, pass them as an array to the `insert()` or `fetch()` functions. This data will then be available as locally scoped variables within the nested template.
~~~ php
<?php $this->insert('partials/header', ['name' => 'Jonathan']) ?>
<p>Your content.</p>
<?php $this->insert('partials/footer') ?>
~~~

View file

@ -0,0 +1,80 @@
---
layout: default
permalink: templates/sections/
title: Sections
---
Sections
========
The `start()` and `stop` functions allow you to build sections (or blocks) of content within your template, and instead of them being rendered directly, they are saved for use elsewhere. For example, in your [layout](/templates/layouts/) template.
## Creating sections
You define the name of the section with the `start()` function. To end a section call the `stop()` function.
~~~ php
<?php $this->start('welcome') ?>
<h1>Welcome!</h1>
<p>Hello <?=$this->e($name)?></p>
<?php $this->stop() ?>
~~~
## Stacking section content
By default, when you render a section its content will overwrite any existing content for that section. However, it's possible to append (or stack) the content instead using the `push()` method. This can be useful for specifying any JavaScript libraries required by your child views.
~~~ php
<?php $this->push('scripts') ?>
<script src="example.js"></script>
<?php $this->end() ?>
~~~
<p class="message-notice">The <code>end()</code> function is simply an alias of <code>stop()</code>. These functions can be used interchangeably.</p>
## Accessing section content
Access rendered section content using the name you assigned in the `start()` method. This variable can be accessed from the current template and layout templates using the `section()` function.
~~~ php
<?=$this->section('welcome')?>
~~~
<p class="message-notice">Prior to Plates 3.0, accessing template content was done using either the <code>content()</code> or <code>child()</code> functions. For consistency with sections, this is no longer possible.</p>
## Default section content
In situations where a page doesn't implement a particular section, it's helpful to assign default content. There are a couple ways to do this:
### Defining it inline
If the default content can be defined in a single line of code, it's best to simply pass it as the second parameter of the `content()` function.
~~~ php
<div id="sidebar">
<?=$this->section('sidebar', $this->fetch('default-sidebar')?>
</div>
~~~
### Use an if statement
If the default content requires more than a single line of code, it's best to use a simple if statement to check if a section exists, and otherwise display the default.
~~~ php
<div id="sidebar">
<?php if ($this->section('sidebar')): ?>
<?=$this->section('sidebar')?>
<?php else: ?>
<ul>
<li><a href="/link">Example Link</a></li>
<li><a href="/link">Example Link</a></li>
<li><a href="/link">Example Link</a></li>
<li><a href="/link">Example Link</a></li>
<li><a href="/link">Example Link</a></li>
</ul>
<?php endif ?>
</div>
~~~

View file

@ -0,0 +1,50 @@
---
layout: default
permalink: templates/syntax/
title: Syntax
---
Syntax
======
While the actual syntax you use in your templates is entirely your choice (it's just PHP after all), we suggest the following syntax guidelines to help keep templates clean and legible.
## Guidelines
- Always use HTML with inline PHP. Never use blocks of PHP.
- Always escape potentially dangerous variables prior to outputting using the built-in escape functions. More on escaping [here](/templates/escaping/).
- Always use the short echo syntax (`<?=`) when outputting variables. For all other inline PHP code, use full the `<?php` tag. Do not use [short tags](http://us3.php.net/manual/en/ini.core.php#ini.short-open-tag).
- Always use the [alternative syntax for control structures](http://php.net/manual/en/control-structures.alternative-syntax.php), which are designed to make templates more legible.
- Never use PHP curly brackets.
- Only ever have one statement in each PHP tag.
- Avoid using semicolons. They are not needed when there is only one statement per PHP tag.
- Never use the `use` operator. Templates should not be interacting with classes in this way.
- Never use the `for`, `while` or `switch` control structures. Instead use `if` and `foreach`.
- Avoid variable assignment.
## Syntax example
Here is an example of a template that complies with the above syntax rules.
~~~ php
<?php $this->layout('template', ['title' => 'User Profile']) ?>
<h1>Welcome!</h1>
<p>Hello <?=$this->e($name)?></p>
<h2>Friends</h2>
<ul>
<?php foreach($friends as $friend): ?>
<li>
<a href="/profile/<?=$this->e($friend->id)?>">
<?=$this->e($friend->name)?>
</a>
</li>
<?php endforeach ?>
</ul>
<?php if ($invitations): ?>
<h2>Invitations</h2>
<p>You have some friend invites!</p>
<?php endif ?>
~~~

View file

@ -0,0 +1,12 @@
<?php
include '../vendor/autoload.php';
// Create new Plates instance
$templates = new League\Plates\Engine('templates');
// Preassign data to the layout
$templates->addData(['company' => 'The Company Name'], 'layout');
// Render a template
echo $templates->render('profile', ['name' => 'Jonathan']);

View file

@ -0,0 +1,12 @@
<html>
<head>
<title><?=$this->e($title)?> | <?=$this->e($company)?></title>
</head>
<body>
<?=$this->section('content')?>
<?=$this->section('scripts')?>
</body>
</html>

View file

@ -0,0 +1,12 @@
<?php $this->layout('layout', ['title' => 'User Profile']) ?>
<h1>User Profile</h1>
<p>Hello, <?=$this->e($name)?>!</p>
<?php $this->insert('sidebar') ?>
<?php $this->push('scripts') ?>
<script>
// Some JavaScript
</script>
<?php $this->end() ?>

View file

@ -0,0 +1,6 @@
<ul>
<li><a href="#link">Example sidebar link</a></li>
<li><a href="#link">Example sidebar link</a></li>
<li><a href="#link">Example sidebar link</a></li>
<li><a href="#link">Example sidebar link</a></li>
</ul>

20
vendor/league/plates/phpunit.xml.dist vendored Executable file
View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="all">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>

279
vendor/league/plates/src/Engine.php vendored Normal file
View file

@ -0,0 +1,279 @@
<?php
namespace League\Plates;
use League\Plates\Extension\ExtensionInterface;
use League\Plates\Template\Data;
use League\Plates\Template\Directory;
use League\Plates\Template\FileExtension;
use League\Plates\Template\Folders;
use League\Plates\Template\Func;
use League\Plates\Template\Functions;
use League\Plates\Template\Name;
use League\Plates\Template\Template;
/**
* Template API and environment settings storage.
*/
class Engine
{
/**
* Default template directory.
* @var Directory
*/
protected $directory;
/**
* Template file extension.
* @var FileExtension
*/
protected $fileExtension;
/**
* Collection of template folders.
* @var Folders
*/
protected $folders;
/**
* Collection of template functions.
* @var Functions
*/
protected $functions;
/**
* Collection of preassigned template data.
* @var Data
*/
protected $data;
/**
* Create new Engine instance.
* @param string $directory
* @param string $fileExtension
*/
public function __construct($directory = null, $fileExtension = 'php')
{
$this->directory = new Directory($directory);
$this->fileExtension = new FileExtension($fileExtension);
$this->folders = new Folders();
$this->functions = new Functions();
$this->data = new Data();
}
/**
* Set path to templates directory.
* @param string|null $directory Pass null to disable the default directory.
* @return Engine
*/
public function setDirectory($directory)
{
$this->directory->set($directory);
return $this;
}
/**
* Get path to templates directory.
* @return string
*/
public function getDirectory()
{
return $this->directory->get();
}
/**
* Set the template file extension.
* @param string|null $fileExtension Pass null to manually set it.
* @return Engine
*/
public function setFileExtension($fileExtension)
{
$this->fileExtension->set($fileExtension);
return $this;
}
/**
* Get the template file extension.
* @return string
*/
public function getFileExtension()
{
return $this->fileExtension->get();
}
/**
* Add a new template folder for grouping templates under different namespaces.
* @param string $name
* @param string $directory
* @param boolean $fallback
* @return Engine
*/
public function addFolder($name, $directory, $fallback = false)
{
$this->folders->add($name, $directory, $fallback);
return $this;
}
/**
* Remove a template folder.
* @param string $name
* @return Engine
*/
public function removeFolder($name)
{
$this->folders->remove($name);
return $this;
}
/**
* Get collection of all template folders.
* @return Folders
*/
public function getFolders()
{
return $this->folders;
}
/**
* Add preassigned template data.
* @param array $data;
* @param null|string|array $templates;
* @return Engine
*/
public function addData(array $data, $templates = null)
{
$this->data->add($data, $templates);
return $this;
}
/**
* Get all preassigned template data.
* @param null|string $template;
* @return array
*/
public function getData($template = null)
{
return $this->data->get($template);
}
/**
* Register a new template function.
* @param string $name;
* @param callback $callback;
* @return Engine
*/
public function registerFunction($name, $callback)
{
$this->functions->add($name, $callback);
return $this;
}
/**
* Remove a template function.
* @param string $name;
* @return Engine
*/
public function dropFunction($name)
{
$this->functions->remove($name);
return $this;
}
/**
* Get a template function.
* @param string $name
* @return Func
*/
public function getFunction($name)
{
return $this->functions->get($name);
}
/**
* Check if a template function exists.
* @param string $name
* @return boolean
*/
public function doesFunctionExist($name)
{
return $this->functions->exists($name);
}
/**
* Load an extension.
* @param ExtensionInterface $extension
* @return Engine
*/
public function loadExtension(ExtensionInterface $extension)
{
$extension->register($this);
return $this;
}
/**
* Load multiple extensions.
* @param array $extensions
* @return Engine
*/
public function loadExtensions(array $extensions = array())
{
foreach ($extensions as $extension) {
$this->loadExtension($extension);
}
return $this;
}
/**
* Get a template path.
* @param string $name
* @return string
*/
public function path($name)
{
$name = new Name($this, $name);
return $name->getPath();
}
/**
* Check if a template exists.
* @param string $name
* @return boolean
*/
public function exists($name)
{
$name = new Name($this, $name);
return $name->doesPathExist();
}
/**
* Create a new template.
* @param string $name
* @return Template
*/
public function make($name)
{
return new Template($this, $name);
}
/**
* Create a new template and render it.
* @param string $name
* @param array $data
* @return string
*/
public function render($name, array $data = array())
{
return $this->make($name)->render($data);
}
}

View file

@ -0,0 +1,85 @@
<?php
namespace League\Plates\Extension;
use League\Plates\Engine;
use League\Plates\Template\Template;
use LogicException;
/**
* Extension that adds the ability to create "cache busted" asset URLs.
*/
class Asset implements ExtensionInterface
{
/**
* Instance of the current template.
* @var Template
*/
public $template;
/**
* Path to asset directory.
* @var string
*/
public $path;
/**
* Enables the filename method.
* @var boolean
*/
public $filenameMethod;
/**
* Create new Asset instance.
* @param string $path
* @param boolean $filenameMethod
*/
public function __construct($path, $filenameMethod = false)
{
$this->path = rtrim($path, '/');
$this->filenameMethod = $filenameMethod;
}
/**
* Register extension function.
* @param Engine $engine
* @return null
*/
public function register(Engine $engine)
{
$engine->registerFunction('asset', array($this, 'cachedAssetUrl'));
}
/**
* Create "cache busted" asset URL.
* @param string $url
* @return string
*/
public function cachedAssetUrl($url)
{
$filePath = $this->path . '/' . ltrim($url, '/');
if (!file_exists($filePath)) {
throw new LogicException(
'Unable to locate the asset "' . $url . '" in the "' . $this->path . '" directory.'
);
}
$lastUpdated = filemtime($filePath);
$pathInfo = pathinfo($url);
if ($pathInfo['dirname'] === '.') {
$directory = '';
} elseif ($pathInfo['dirname'] === '/') {
$directory = '/';
} else {
$directory = $pathInfo['dirname'] . '/';
}
if ($this->filenameMethod) {
return $directory . $pathInfo['filename'] . '.' . $lastUpdated . '.' . $pathInfo['extension'];
}
return $directory . $pathInfo['filename'] . '.' . $pathInfo['extension'] . '?v=' . $lastUpdated;
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace League\Plates\Extension;
use League\Plates\Engine;
/**
* A common interface for extensions.
*/
interface ExtensionInterface
{
public function register(Engine $engine);
}

View file

@ -0,0 +1,113 @@
<?php
namespace League\Plates\Extension;
use League\Plates\Engine;
use League\Plates\Template\Template;
use LogicException;
/**
* Extension that adds a number of URI checks.
*/
class URI implements ExtensionInterface
{
/**
* Instance of the current template.
* @var Template
*/
public $template;
/**
* The request URI.
* @var string
*/
protected $uri;
/**
* The request URI as an array.
* @var array
*/
protected $parts;
/**
* Create new URI instance.
* @param string $uri
*/
public function __construct($uri)
{
$this->uri = $uri;
$this->parts = explode('/', $this->uri);
}
/**
* Register extension functions.
* @param Engine $engine
* @return null
*/
public function register(Engine $engine)
{
$engine->registerFunction('uri', array($this, 'runUri'));
}
/**
* Perform URI check.
* @param null|integer|string $var1
* @param mixed $var2
* @param mixed $var3
* @param mixed $var4
* @return mixed
*/
public function runUri($var1 = null, $var2 = null, $var3 = null, $var4 = null)
{
if (is_null($var1)) {
return $this->uri;
}
if (is_numeric($var1) and is_null($var2)) {
return array_key_exists($var1, $this->parts) ? $this->parts[$var1] : null;
}
if (is_numeric($var1) and is_string($var2)) {
return $this->checkUriSegmentMatch($var1, $var2, $var3, $var4);
}
if (is_string($var1)) {
return $this->checkUriRegexMatch($var1, $var2, $var3);
}
throw new LogicException('Invalid use of the uri function.');
}
/**
* Perform a URI segment match.
* @param integer $key
* @param string $string
* @param mixed $returnOnTrue
* @param mixed $returnOnFalse
* @return mixed
*/
protected function checkUriSegmentMatch($key, $string, $returnOnTrue = null, $returnOnFalse = null)
{
if (array_key_exists($key, $this->parts) && $this->parts[$key] === $string) {
return is_null($returnOnTrue) ? true : $returnOnTrue;
}
return is_null($returnOnFalse) ? false : $returnOnFalse;
}
/**
* Perform a regular express match.
* @param string $regex
* @param mixed $returnOnTrue
* @param mixed $returnOnFalse
* @return mixed
*/
protected function checkUriRegexMatch($regex, $returnOnTrue = null, $returnOnFalse = null)
{
if (preg_match('#^' . $regex . '$#', $this->uri) === 1) {
return is_null($returnOnTrue) ? true : $returnOnTrue;
}
return is_null($returnOnFalse) ? false : $returnOnFalse;
}
}

View file

@ -0,0 +1,93 @@
<?php
namespace League\Plates\Template;
use LogicException;
/**
* Preassigned template data.
*/
class Data
{
/**
* Variables shared by all templates.
* @var array
*/
protected $sharedVariables = array();
/**
* Specific template variables.
* @var array
*/
protected $templateVariables = array();
/**
* Add template data.
* @param array $data;
* @param null|string|array $templates;
* @return Data
*/
public function add(array $data, $templates = null)
{
if (is_null($templates)) {
return $this->shareWithAll($data);
}
if (is_array($templates)) {
return $this->shareWithSome($data, $templates);
}
if (is_string($templates)) {
return $this->shareWithSome($data, array($templates));
}
throw new LogicException(
'The templates variable must be null, an array or a string, ' . gettype($templates) . ' given.'
);
}
/**
* Add data shared with all templates.
* @param array $data;
* @return Data
*/
public function shareWithAll($data)
{
$this->sharedVariables = array_merge($this->sharedVariables, $data);
return $this;
}
/**
* Add data shared with some templates.
* @param array $data;
* @param array $templates;
* @return Data
*/
public function shareWithSome($data, array $templates)
{
foreach ($templates as $template) {
if (isset($this->templateVariables[$template])) {
$this->templateVariables[$template] = array_merge($this->templateVariables[$template], $data);
} else {
$this->templateVariables[$template] = $data;
}
}
return $this;
}
/**
* Get template data.
* @param null|string $template;
* @return array
*/
public function get($template = null)
{
if (isset($template, $this->templateVariables[$template])) {
return array_merge($this->sharedVariables, $this->templateVariables[$template]);
}
return $this->sharedVariables;
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace League\Plates\Template;
use LogicException;
/**
* Default template directory.
*/
class Directory
{
/**
* Template directory path.
* @var string
*/
protected $path;
/**
* Create new Directory instance.
* @param string $path
*/
public function __construct($path = null)
{
$this->set($path);
}
/**
* Set path to templates directory.
* @param string|null $path Pass null to disable the default directory.
* @return Directory
*/
public function set($path)
{
if (!is_null($path) and !is_dir($path)) {
throw new LogicException(
'The specified path "' . $path . '" does not exist.'
);
}
$this->path = $path;
return $this;
}
/**
* Get path to templates directory.
* @return string
*/
public function get()
{
return $this->path;
}
}

View file

@ -0,0 +1,45 @@
<?php
namespace League\Plates\Template;
/**
* Template file extension.
*/
class FileExtension
{
/**
* Template file extension.
* @var string
*/
protected $fileExtension;
/**
* Create new FileExtension instance.
* @param null|string $fileExtension
*/
public function __construct($fileExtension = 'php')
{
$this->set($fileExtension);
}
/**
* Set the template file extension.
* @param null|string $fileExtension
* @return FileExtension
*/
public function set($fileExtension)
{
$this->fileExtension = $fileExtension;
return $this;
}
/**
* Get the template file extension.
* @return string
*/
public function get()
{
return $this->fileExtension;
}
}

View file

@ -0,0 +1,109 @@
<?php
namespace League\Plates\Template;
use LogicException;
/**
* A template folder.
*/
class Folder
{
/**
* The folder name.
* @var string
*/
protected $name;
/**
* The folder path.
* @var string
*/
protected $path;
/**
* The folder fallback status.
* @var boolean
*/
protected $fallback;
/**
* Create a new Folder instance.
* @param string $name
* @param string $path
* @param boolean $fallback
*/
public function __construct($name, $path, $fallback = false)
{
$this->setName($name);
$this->setPath($path);
$this->setFallback($fallback);
}
/**
* Set the folder name.
* @param string $name
* @return Folder
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get the folder name.
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set the folder path.
* @param string $path
* @return Folder
*/
public function setPath($path)
{
if (!is_dir($path)) {
throw new LogicException('The specified directory path "' . $path . '" does not exist.');
}
$this->path = $path;
return $this;
}
/**
* Get the folder path.
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Set the folder fallback status.
* @param boolean $fallback
* @return Folder
*/
public function setFallback($fallback)
{
$this->fallback = $fallback;
return $this;
}
/**
* Get the folder fallback status.
* @return boolean
*/
public function getFallback()
{
return $this->fallback;
}
}

View file

@ -0,0 +1,75 @@
<?php
namespace League\Plates\Template;
use LogicException;
/**
* A collection of template folders.
*/
class Folders
{
/**
* Array of template folders.
* @var array
*/
protected $folders = array();
/**
* Add a template folder.
* @param string $name
* @param string $path
* @param boolean $fallback
* @return Folders
*/
public function add($name, $path, $fallback = false)
{
if ($this->exists($name)) {
throw new LogicException('The template folder "' . $name . '" is already being used.');
}
$this->folders[$name] = new Folder($name, $path, $fallback);
return $this;
}
/**
* Remove a template folder.
* @param string $name
* @return Folders
*/
public function remove($name)
{
if (!$this->exists($name)) {
throw new LogicException('The template folder "' . $name . '" was not found.');
}
unset($this->folders[$name]);
return $this;
}
/**
* Get a template folder.
* @param string $name
* @return Folder
*/
public function get($name)
{
if (!$this->exists($name)) {
throw new LogicException('The template folder "' . $name . '" was not found.');
}
return $this->folders[$name];
}
/**
* Check if a template folder exists.
* @param string $name
* @return boolean
*/
public function exists($name)
{
return isset($this->folders[$name]);
}
}

View file

@ -0,0 +1,107 @@
<?php
namespace League\Plates\Template;
use League\Plates\Extension\ExtensionInterface;
use LogicException;
/**
* A template function.
*/
class Func
{
/**
* The function name.
* @var string
*/
protected $name;
/**
* The function callback.
* @var callable
*/
protected $callback;
/**
* Create new Func instance.
* @param string $name
* @param callable $callback
*/
public function __construct($name, $callback)
{
$this->setName($name);
$this->setCallback($callback);
}
/**
* Set the function name.
* @param string $name
* @return Func
*/
public function setName($name)
{
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $name) !== 1) {
throw new LogicException(
'Not a valid function name.'
);
}
$this->name = $name;
return $this;
}
/**
* Get the function name.
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set the function callback
* @param callable $callback
* @return Func
*/
public function setCallback($callback)
{
if (!is_callable($callback, true)) {
throw new LogicException(
'Not a valid function callback.'
);
}
$this->callback = $callback;
return $this;
}
/**
* Get the function callback.
* @return callable
*/
public function getCallback()
{
return $this->callback;
}
/**
* Call the function.
* @param Template $template
* @param array $arguments
* @return mixed
*/
public function call(Template $template = null, $arguments = array())
{
if (is_array($this->callback) and
isset($this->callback[0]) and
$this->callback[0] instanceof ExtensionInterface
) {
$this->callback[0]->template = $template;
}
return call_user_func_array($this->callback, $arguments);
}
}

View file

@ -0,0 +1,78 @@
<?php
namespace League\Plates\Template;
use LogicException;
/**
* A collection of template functions.
*/
class Functions
{
/**
* Array of template functions.
* @var array
*/
protected $functions = array();
/**
* Add a new template function.
* @param string $name;
* @param callback $callback;
* @return Functions
*/
public function add($name, $callback)
{
if ($this->exists($name)) {
throw new LogicException(
'The template function name "' . $name . '" is already registered.'
);
}
$this->functions[$name] = new Func($name, $callback);
return $this;
}
/**
* Remove a template function.
* @param string $name;
* @return Functions
*/
public function remove($name)
{
if (!$this->exists($name)) {
throw new LogicException(
'The template function "' . $name . '" was not found.'
);
}
unset($this->functions[$name]);
return $this;
}
/**
* Get a template function.
* @param string $name
* @return Func
*/
public function get($name)
{
if (!$this->exists($name)) {
throw new LogicException('The template function "' . $name . '" was not found.');
}
return $this->functions[$name];
}
/**
* Check if a template function exists.
* @param string $name
* @return boolean
*/
public function exists($name)
{
return isset($this->functions[$name]);
}
}

View file

@ -0,0 +1,202 @@
<?php
namespace League\Plates\Template;
use League\Plates\Engine;
use LogicException;
/**
* A template name.
*/
class Name
{
/**
* Instance of the template engine.
* @var Engine
*/
protected $engine;
/**
* The original name.
* @var string
*/
protected $name;
/**
* The parsed template folder.
* @var Folder
*/
protected $folder;
/**
* The parsed template filename.
* @var string
*/
protected $file;
/**
* Create a new Name instance.
* @param Engine $engine
* @param string $name
*/
public function __construct(Engine $engine, $name)
{
$this->setEngine($engine);
$this->setName($name);
}
/**
* Set the engine.
* @param Engine $engine
* @return Name
*/
public function setEngine(Engine $engine)
{
$this->engine = $engine;
return $this;
}
/**
* Get the engine.
* @return Engine
*/
public function getEngine()
{
return $this->engine;
}
/**
* Set the original name and parse it.
* @param string $name
* @return Name
*/
public function setName($name)
{
$this->name = $name;
$parts = explode('::', $this->name);
if (count($parts) === 1) {
$this->setFile($parts[0]);
} elseif (count($parts) === 2) {
$this->setFolder($parts[0]);
$this->setFile($parts[1]);
} else {
throw new LogicException(
'The template name "' . $this->name . '" is not valid. ' .
'Do not use the folder namespace separator "::" more than once.'
);
}
return $this;
}
/**
* Get the original name.
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set the parsed template folder.
* @param string $folder
* @return Name
*/
public function setFolder($folder)
{
$this->folder = $this->engine->getFolders()->get($folder);
return $this;
}
/**
* Get the parsed template folder.
* @return string
*/
public function getFolder()
{
return $this->folder;
}
/**
* Set the parsed template file.
* @param string $file
* @return Name
*/
public function setFile($file)
{
if ($file === '') {
throw new LogicException(
'The template name "' . $this->name . '" is not valid. ' .
'The template name cannot be empty.'
);
}
$this->file = $file;
if (!is_null($this->engine->getFileExtension())) {
$this->file .= '.' . $this->engine->getFileExtension();
}
return $this;
}
/**
* Get the parsed template file.
* @return string
*/
public function getFile()
{
return $this->file;
}
/**
* Resolve template path.
* @return string
*/
public function getPath()
{
if (is_null($this->folder)) {
return $this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file;
}
$path = $this->folder->getPath() . DIRECTORY_SEPARATOR . $this->file;
if (!is_file($path) and $this->folder->getFallback() and is_file($this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file)) {
$path = $this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file;
}
return $path;
}
/**
* Check if template path exists.
* @return boolean
*/
public function doesPathExist()
{
return is_file($this->getPath());
}
/**
* Get the default templates directory.
* @return string
*/
protected function getDefaultDirectory()
{
$directory = $this->engine->getDirectory();
if (is_null($directory)) {
throw new LogicException(
'The template name "' . $this->name . '" is not valid. '.
'The default directory has not been defined.'
);
}
return $directory;
}
}

View file

@ -0,0 +1,346 @@
<?php
namespace League\Plates\Template;
use Exception;
use League\Plates\Engine;
use LogicException;
use Throwable;
/**
* Container which holds template data and provides access to template functions.
*/
class Template
{
/**
* Instance of the template engine.
* @var Engine
*/
protected $engine;
/**
* The name of the template.
* @var Name
*/
protected $name;
/**
* The data assigned to the template.
* @var array
*/
protected $data = array();
/**
* An array of section content.
* @var array
*/
protected $sections = array();
/**
* The name of the section currently being rendered.
* @var string
*/
protected $sectionName;
/**
* Whether the section should be appended or not.
* @var boolean
*/
protected $appendSection;
/**
* The name of the template layout.
* @var string
*/
protected $layoutName;
/**
* The data assigned to the template layout.
* @var array
*/
protected $layoutData;
/**
* Create new Template instance.
* @param Engine $engine
* @param string $name
*/
public function __construct(Engine $engine, $name)
{
$this->engine = $engine;
$this->name = new Name($engine, $name);
$this->data($this->engine->getData($name));
}
/**
* Magic method used to call extension functions.
* @param string $name
* @param array $arguments
* @return mixed
*/
public function __call($name, $arguments)
{
return $this->engine->getFunction($name)->call($this, $arguments);
}
/**
* Alias for render() method.
* @throws \Throwable
* @throws \Exception
* @return string
*/
public function __toString()
{
return $this->render();
}
/**
* Assign or get template data.
* @param array $data
* @return mixed
*/
public function data(array $data = null)
{
if (is_null($data)) {
return $this->data;
}
$this->data = array_merge($this->data, $data);
}
/**
* Check if the template exists.
* @return boolean
*/
public function exists()
{
return $this->name->doesPathExist();
}
/**
* Get the template path.
* @return string
*/
public function path()
{
return $this->name->getPath();
}
/**
* Render the template and layout.
* @param array $data
* @throws \Throwable
* @throws \Exception
* @return string
*/
public function render(array $data = array())
{
$this->data($data);
unset($data);
extract($this->data);
if (!$this->exists()) {
throw new LogicException(
'The template "' . $this->name->getName() . '" could not be found at "' . $this->path() . '".'
);
}
try {
$level = ob_get_level();
ob_start();
include $this->path();
$content = ob_get_clean();
if (isset($this->layoutName)) {
$layout = $this->engine->make($this->layoutName);
$layout->sections = array_merge($this->sections, array('content' => $content));
$content = $layout->render($this->layoutData);
}
return $content;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
} catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
}
/**
* Set the template's layout.
* @param string $name
* @param array $data
* @return null
*/
public function layout($name, array $data = array())
{
$this->layoutName = $name;
$this->layoutData = $data;
}
/**
* Start a new section block.
* @param string $name
* @return null
*/
public function start($name)
{
if ($name === 'content') {
throw new LogicException(
'The section name "content" is reserved.'
);
}
if ($this->sectionName) {
throw new LogicException('You cannot nest sections within other sections.');
}
$this->sectionName = $name;
ob_start();
}
/**
* Start a new append section block.
* @param string $name
* @return null
*/
public function push($name)
{
$this->appendSection = true;
$this->start($name);
}
/**
* Stop the current section block.
* @return null
*/
public function stop()
{
if (is_null($this->sectionName)) {
throw new LogicException(
'You must start a section before you can stop it.'
);
}
if (!isset($this->sections[$this->sectionName])) {
$this->sections[$this->sectionName] = '';
}
$this->sections[$this->sectionName] = $this->appendSection ? $this->sections[$this->sectionName] . ob_get_clean() : ob_get_clean();
$this->sectionName = null;
$this->appendSection = false;
}
/**
* Alias of stop().
* @return null
*/
public function end()
{
$this->stop();
}
/**
* Returns the content for a section block.
* @param string $name Section name
* @param string $default Default section content
* @return string|null
*/
public function section($name, $default = null)
{
if (!isset($this->sections[$name])) {
return $default;
}
return $this->sections[$name];
}
/**
* Fetch a rendered template.
* @param string $name
* @param array $data
* @return string
*/
public function fetch($name, array $data = array())
{
return $this->engine->render($name, $data);
}
/**
* Output a rendered template.
* @param string $name
* @param array $data
* @return null
*/
public function insert($name, array $data = array())
{
echo $this->engine->render($name, $data);
}
/**
* Apply multiple functions to variable.
* @param mixed $var
* @param string $functions
* @return mixed
*/
public function batch($var, $functions)
{
foreach (explode('|', $functions) as $function) {
if ($this->engine->doesFunctionExist($function)) {
$var = call_user_func(array($this, $function), $var);
} elseif (is_callable($function)) {
$var = call_user_func($function, $var);
} else {
throw new LogicException(
'The batch function could not find the "' . $function . '" function.'
);
}
}
return $var;
}
/**
* Escape string.
* @param string $string
* @param null|string $functions
* @return string
*/
public function escape($string, $functions = null)
{
static $flags;
if (!isset($flags)) {
$flags = ENT_QUOTES | (defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0);
}
if ($functions) {
$string = $this->batch($string, $functions);
}
return htmlspecialchars($string, $flags, 'UTF-8');
}
/**
* Alias to escape function.
* @param string $string
* @param null|string $functions
* @return string
*/
public function e($string, $functions = null)
{
return $this->escape($string, $functions);
}
}