This repository was archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmotd.php
127 lines (102 loc) · 3.08 KB
/
motd.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
<?php
/**
* WoWRoster.net WoWRoster
*
* Message of the Day image generator
*
*
* @copyright 2002-2011 WoWRoster.net
* @license http://www.gnu.org/licenses/gpl.html Licensed under the GNU General Public License v3.
* @package WoWRoster
*/
define('IN_ROSTER', true);
//==========[ SETTINGS ]========================================================
$roster_root_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
if( isset($_GET['motd']) )
{
$guildMOTD = substr(stripslashes(urldecode($_GET['motd'])), 0, 145);
}
elseif( isset($_GET['id']) )
{
include ($roster_root_path . 'settings.php');
$guild_escape = $_GET['id'];
$query = "SELECT `guild_motd`"
. " FROM `" . $roster->db->table('guild') . "`"
. " WHERE `guild_id` = '" . $guild_escape . "';";
$guild_motd = $roster->db->query_first($query);
if( !$guild_motd )
{
$guild_motd = 'Failed to fetch guild MOTD';
}
$guildMOTD = substr(htmlspecialchars($guild_motd), 0, 145);
}
else
{
include ($roster_root_path . 'settings.php');
$guildMOTD = 'Invalid Access';
}
// Path to font folder
$image_path = $roster_root_path . 'img' . DIRECTORY_SEPARATOR;
$font_path = $roster_root_path . 'fonts' . DIRECTORY_SEPARATOR;
motd_img($guildMOTD, $image_path, $font_path);
die();
//==========[ IMAGE GENERATOR ]=================================================
function motd_img( $guildMOTD , $image_path , $font_path )
{
$guildMOTD = html_entity_decode($guildMOTD);
$maxw = 750;
$vadj = 0;
// Set ttf font
$visitor = $font_path . 'VERANDA.TTF';
// Get sizes of text
$box = imagettfbbox(11, 0, $visitor, $guildMOTD);
$text_length = $box[2] - $box[6];
// Get how many times to print center
$image_size = ($text_length < $maxw ? ceil($text_length / 198) : ceil($maxw / 198));
$final_size = 54 + ($image_size * 198);
// Create new image
$img = imagecreatetruecolor($final_size, 38);
// Get and combine base images, set colors
$img_file = imagecreatefrompng($image_path . 'gmotd.png');
// Copy image file into new image
// Copy Left part
imagecopy($img, $img_file, 0, 0, 0, 0, 38, 38);
// Copy center part however times needed
for( $i = 0; $i < $image_size; $i++ )
{
imagecopy($img, $img_file, ($i * 198) + 38, 0, 39, 0, 198, 38);
}
// Copy Right part
imagecopy($img, $img_file, ($image_size * 198) + 38, 0, 237, 0, 17, 38);
$textcolor = imagecolorallocate($img, 255, 255, 255);
if( $text_length > $maxw )
{
$i = $text_length;
$t = strlen($guildMOTD);
while( $i > $maxw )
{
$t--;
$box = imagettfbbox(11, 0, $visitor, substr($guildMOTD, 0, $t));
$i = abs($box[0]) + abs($box[2]);
}
$t = strrpos(substr($guildMOTD, 0, $t), ' ');
$output[0] = substr($guildMOTD, 0, $t);
$output[1] = ltrim(substr($guildMOTD, $t));
$vadj = -6;
}
else
{
$output[0] = $guildMOTD;
}
$i = 0;
foreach( $output as $value )
{
$box = imagettfbbox(11, 0, $visitor, $value);
$text_length = abs($box[0]) + abs($box[2]);
imagettftext($img, 11, 0, round(($final_size - $text_length) / 2), 23 + ($i * 14) + $vadj, $textcolor, $visitor, $value);
$i++;
}
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
}