forked from gambitph/Titan-Framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iframe-font-preview.php
153 lines (142 loc) · 4.83 KB
/
iframe-font-preview.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
148
149
150
151
152
153
<?php
/*
* Create a preview of a font
*/
if ( empty( $_GET ) ) {
return;
}
// Sanitize the inputs
foreach ( $_GET as $key => $value ) {
$_GET[ $key ] = htmlspecialchars( $value );
}
// @see http://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/
function hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
$rgb = array($r, $g, $b);
//return implode(",", $rgb); // returns the rgb values separated by commas
return $rgb; // returns an array with the rgb values
}
$textShadow = '';
if ( $_GET['text-shadow-location'] != 'none' ) {
if ( stripos( $_GET['text-shadow-location'], 'left' ) !== false ) {
$textShadow .= '-' . $_GET['text-shadow-distance'];
} else if ( stripos( $_GET['text-shadow-location'], 'right' ) !== false ) {
$textShadow .= $_GET['text-shadow-distance'];
} else {
$textShadow .= '0';
}
$textShadow .= ' ';
if ( stripos( $_GET['text-shadow-location'], 'top' ) !== false ) {
$textShadow .= '-' . $_GET['text-shadow-distance'];
} else if ( stripos( $_GET['text-shadow-location'], 'bottom' ) !== false ) {
$textShadow .= $_GET['text-shadow-distance'];
} else {
$textShadow .= '0';
}
$textShadow .= ' ';
$textShadow .= $_GET['text-shadow-blur'];
$textShadow .= ' ';
$rgb = hex2rgb( $_GET['text-shadow-color'] );
$rgb[] = $_GET['text-shadow-opacity'];
$textShadow .= 'rgba(' . implode( ',', $rgb ) . ')';
} else {
$textShadow .= $_GET['text-shadow-location'];
}
?>
<html>
<head>
<?php
if ( $_GET['font-type'] == 'google' ) {
$weight = $_GET['font-weight'];
if ( $weight == 'normal' ) {
$weight = array( '400' );
} else if ( $weight == 'bold' ) {
$weight = array( '500' );//, '700' );
} else if ( $weight == 'bolder' ) {
$weight = array( '800' );//, '900' );
} else if ( $weight == 'lighter' ) {
$weight = array( '100' );//, '200', '300' );
} else {
$weight = array( $weight );
}
if ( $_GET['font-style'] == 'italic' ) {
foreach ( $weight as $key => $value ) {
$weight[$key] = $value . 'italic';
}
}
printf( "<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=%s:400,%s&subset=latin,cyrillic-ext,greek-ext,greek,latin-ext,vietnamese,cyrillic' type='text/css' media='all' />",
str_replace( ' ', '+', str_replace( '%20', '+', $_GET['font-family'] ) ),
implode( ',', $weight )
);
$_GET['font-family'] = '"' . $_GET['font-family'] . '"';
} else {
$_GET['font-family'] = stripslashes( $_GET['font-family'] );
}
?>
<style>
p {
margin-left: 50px;
margin-right: 20px;
font-family: <?php echo $_GET['font-family'] ?>;
color: <?php echo $_GET['color'] ?>;
font-size: <?php echo $_GET['font-size'] ?>;
font-weight: <?php echo $_GET['font-weight'] ?>;
font-style: <?php echo $_GET['font-style'] ?>;
line-height: <?php echo $_GET['line-height'] ?>;
letter-spacing: <?php echo $_GET['letter-spacing'] ?>;
text-transform: <?php echo $_GET['text-transform'] ?>;
font-variant: <?php echo $_GET['font-variant'] ?>;
text-shadow: <?php echo $textShadow ?>;
}
body {
margin: 20px 0;
background: #fff;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
body.dark {
background: #333;
}
</style>
<script>
function toggleClass(element, className){
if (!element || !className){
return;
}
var classString = element.className, nameIndex = classString.indexOf(className);
if (nameIndex == -1) {
classString += ' ' + className;
}
else {
classString = classString.substr(0, nameIndex) + classString.substr(nameIndex+className.length);
}
element.className = classString;
}
</script>
</head>
<body class='<?php echo $_GET['dark'] ?>'>
<?php
if ( empty( $_GET['text'] ) ):
?>
<p>Grumpy wizards make toxic brew for the evil Queen and Jack</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam at dolor non purus adipiscing rhoncus. Nullam vitae turpis pharetra odio feugiat gravida sed ac velit. Nullam luctus ultrices suscipit. Fusce condimentum laoreet cursus. Suspendisse sed accumsan tortor. Quisque pharetra pulvinar ante, feugiat varius nibh sodales nec. Fusce vel mattis lectus. Vivamus magna felis, pharetra in lacinia sed, condimentum quis nisi. Ut at rutrum urna. Vivamus convallis posuere metus vel ullamcorper.</p>
<?php
else:
echo "<p>" . str_replace( "\n", "</p><p>", $_GET['text'] ) . "</p>";
endif;
?>
</body>
</html>