-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
131 lines (106 loc) · 4.97 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/***********************
Nikházy Ákos
index.php
The idea is keeping PHP clean from HTML and text.
This small framework does just that. It is pretty
good for small sites.
***********************/
require 'require/head.php';
// ****************
// ini cache
//
// Caching for 10 seconds. If there is a cache that is younger than
// 10 seconds this is the last line that runs in this script.
// You can test this by changing the loop to 100, render the page then
// turn it back to 10 and try rendering it again you will see the 100
// lines in 10 seconds window. Also when you change your code you should
// delete cache files if you work with long Caching times.
//
// If you want to calculate POSTs, GETs or other dynamic stuff you better
// do it before the Cache class. Also based on you dynamic content you
// can do a Cache(0) to re-cache the content at that point.
// ****************
$cache = new Cache(10); // keep cache for X seconds
// $cache = new Cache(0); this effectively turns off caching for this page
// ****************
// ini template class
//
// Template('the name of template file')
// in the template file you find {{something}}. you can replace
// {{something}} with value by using the tagList[] property
// $template -> tagList['something'] = value property
// ****************
$template = new Template('index'); // this will template the index.html file in the templates folder
$listLineTemplate = new Template('listItem'); // this will template the listItem.html file in the templates folder
$rawTextTemplate = new Template('',' {{texthere}} at rendering'); // This will template that string. The file must be NULL
// ****************
// ini text class
//
// Text('the name of the text file')
// $text->PrintText('textID') method
// returns the text
// ****************
$text = new Text('index');
// ****************
// Calculating stuff before using the main template.
// this is where you put the content together for
// the template
// ****************
$list = '';
for($i = 1; $i<=10; $i++)
{
// you can use smaller templates. This one keeps a simple <li>{{listItemText}}</li> HTML line
// also here we use the Text class, that loads text from a .json file by id, instead putting text
// in PHP code.
$listLineTemplate -> tagList['item'] = $text->PrintText('listItemText') . $i;
// ****************
// We collect the list items as a string in a variable.
// This line returns the templated HTML string (first paramater is true), but do not work on
// one lineing it (second parameter is false) as at the end it will be one lined anyway.
// ****************
$list .= $listLineTemplate->Templating(true,false);
}
/*
// a better way for list or even tables. Instead of connecting strings, you put them in an array
// the Templating method will implode it like this implode('',$array);
$list = array();
for($i = 1; $i<=10; $i++)
{
// you can use smaller templates. This one keeps a simple <li>{{listItemText}}</li> HTML line
// also here we use the Text class, that loads text from a .json file by id, instead putting text
// in PHP code.
$listLineTemplate -> tagList['item'] = $text->PrintText('listItemText') . $i;
// ****************
// We collect the list items as a string in a variable.
// This line returns the templated HTML string (first paramater is true), but do not work on
// one lineing it (second parameter is false) as at the end it will be one lined anyway.
// ****************
$list[] = $listLineTemplate->Templating(true,false);
}
*/
// ****************
// Populate the template here
// Examples:
// ****************
$template -> tagList['someText'] = $text->PrintText('someText');
$template -> tagList['content'] = 'This is the content. You should use the Text.class to put text in these parts,
but for the example I write this here. Also this only makes sense if you see
it in the PHP code in index.php';
$template -> tagList['aList'] = $list;
$template -> tagList['otherHTML'] = NULL; // this will replace the {{otherHTML}} tag to the otherHTML file's content
// we templating string same way as files
$rawTextTemplate -> tagList['texthere'] = $text -> PrintText('complete');
$template -> tagList['rawStringExample'] = $rawTextTemplate -> Templating();
$template -> tagList['formatedText'] = $text -> PrintText('formatedText','string',3,3.3);
// ****************
// Show filled template for user and putting it in a cache
// we never reach this point if cache already exists.
// here we use the basic parameters (both true) so we return the templated HTML string in one line.
// then cache it and print it with exit() (happens in the Cache class.
// ****************
$cache -> cache($template -> Templating());
// ****************
// check out the index_no_comment.php file to see how little code does
// how much, to present content to the user.
// ****************