forked from jdearaujo/Business-Card-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
html.inc.php
147 lines (141 loc) · 5.46 KB
/
html.inc.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* Manages the HTML output. Technically, it also manages JS and CSS output.
*
* @package Business-Card-Generator
*/
global $http, $html;
if ( !defined( 'ROOT' ) ) define( 'ROOT', dirname( __FILE__ ) );
require_once( ROOT.'/m.inc.php' );
if ( !class_exists( 'html' ) ) {
/**
* Manages the HTML output. Technically, it also manages JS and CSS output.
*
* @since 0.1b
* @package Business-Card-Generator
*/
class html {
/**
* HTML buffer
* @var string
*/
public static $buffer='';
/**
* Empties the buffer, and doesn't display it.
*
* @since 0.1b
* @uses self::$buffer
*/
function __construct( ) {
self::$buffer = '';
}
/**
* Dumps the buffer in a smart way.
*
* @since 0.1b
* @uses self::$buffer
* @uses global $http
* @uses BUFFER_SIZE
*
* @param $return If true, it will return the buffer. If false, it will echo the buffer.
* @return bool|string True if $return is false, self::$buffer (string) if $return is true. If the buffer is empty, false is returned.
*/
function dump( $return=false ) {
if ( empty( self::$buffer ) ) return false;
global $http;
$http->__destruct( ); // Sends the HTTP headers (if they aren't already sent)
hook( 'pre_html_dump' );
$fullbuffer = self::$buffer;
self::$buffer = '';
if ( $return===true ) return $fullbuffer;
// If we get to this point, we are going to echo the content. We'll loop through the buffer and send it out in a bunch of mini-buffers (and flush between mini-buffers)
while ( strlen( $fullbuffer ) >= 1 ) {
if ( BUFFER_SIZE >= strlen( $fullbuffer ) ) {
// The buffer is so small we will just echo the all of the remaining buffer.
echo $fullbuffer;
$fullbuffer = ''; // The buffer is now empty.
}
else {
// The buffer is still higher than the buffer size, so we'll only echo a portion of the buffer.
echo substr( $fullbuffer, 0, BUFFER_SIZE );
$fullbuffer = substr( $fullbuffer, BUFFER_SIZE );
}
flush( ); // Flush it, or else the above is obsolete!
}
return true;
}
/**
* Adds HTML to the buffer.
*
* @since 0.1b
* @uses self::$buffer
*
* @param string $code The HTML to add to the buffer.
* @return bool True.
*/
function code( $code ) {
self::$buffer.=$code;
return true;
}
/**
* Adds a hero-unit (from BootStrap) to the buffer.
*
* @since 0.11
* @uses self::$buffer
* @uses self::code()
*
* @param int $title The ID of the title (ID is used with the __ function)
* @param int $arg,... Optional. Each ID will be used as a paragraph of content (ID is used with the __ function)
* @return bool True.
*/
function hero( $title ) {
$args = func_get_args( );
array_shift( $args ); // ignores the $title.
$hero_text = '';
foreach ( $args as $paragraph ) {
$hero_text.='<p>'.__( $paragraph ).'</p>';
}
self::code( '<div class="hero-unit"><h1>'.__( $title ).'</h1>'.$hero_text.'</div>' );
return true;
}
/**
* Creates a row of that will be split up into columns
*
* @since 0.11
* @uses self::code()
*
* @param array $col,... Optional. Each column should be an array. Each array has a specific format, detailed in the function.
* @return bool True.
*/
function row( ) {
$cols = func_get_args( );
$code = '';
self::code( '<div class="row">' );
foreach ( $cols as $col ) {
// The column's width is specified on a scale from 1-12, 12 being the widest, is stored with the key 'width'
$code.='<div class="span'.$col[ 'width' ].'">';
// The column's name is stored in its 'title' key.
$code.='<h2>'.__( $col[ 'title' ] ).'</h2>';
// Content that should be wrapped in <p> tags should be put in an array in the key 'p' - and remember to store this content in the __ function (located in talk.inc.php)
if ( is_array( $col[ 'p' ] ) ) {
foreach ( $col[ 'p' ] as $p ) $code.='<p>'.__( $p ).'</p>';
}
// Content that you shouldn't be wrapped in <p> tags (like the application) should be put in the 'vanilla' key. This is NOT put through the __ function, so you have to explicitly use the __ function when applicable.
if ( isset( $col[ 'vanilla' ] ) ) $code.=$col[ 'vanilla' ];
self::code( $code.'</div>' );
}
self::code( '</div>' );
}
function __isset( $name ) {
return true;
}
function __get( $name ) {
return self::dump( true );
}
function __destruct( ) {
self::dump( false );
return true;
}
}
}
?>