-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditavatars.php
More file actions
157 lines (139 loc) · 4.4 KB
/
Copy patheditavatars.php
File metadata and controls
157 lines (139 loc) · 4.4 KB
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
154
155
156
157
<?php
include("lib/common.php");
$title = __("Mood avatars");
AssertForbidden("editMoods");
if(!$loguserid)
Kill(__("You must be logged in to edit your avatars."));
if(isset($_POST['action']))
{
$mid = (int)$_POST['mid'];
if($_POST['action'] == __("Rename"))
{
Query("update moodavatars set name='".justEscape($_POST['name'])."' where mid=".$mid." and uid=".$loguserid);
Alert(__("Avatar renamed."), __("Okay"));
}
else if($_POST['action'] == __("Delete"))
{
Query("delete from moodavatars where uid=".$loguserid." and mid=".$mid);
Query("update posts set mood=0 where user=".$loguserid." and mood=".$mid);
if(file_exists("img/avatars/".$loguserid."_".$mid))
unlink("img/avatars/".$loguserid."_".$mid);
Alert(__("Avatar deleted."), __("Okay"));
}
else if($_POST['action'] == __("Add"))
{
$highest = FetchResult("select mid from moodavatars where uid=".$loguserid." order by mid desc limit 1");
if($highest < 1)
$highest = 1;
$mid = $highest + 1;
//Begin copypasta from edituser/editprofile_avatar...
if($fname = $_FILES['picture']['name'])
{
$fext = strtolower(substr($fname,-4));
$error = "";
$exts = array(".png",".jpg",".gif");
$dimx = 100;
$dimy = 100;
$dimxs = 60;
$dimys = 60;
$size = 30720;
$validext = false;
$extlist = "";
foreach($exts as $ext)
{
if($fext == $ext)
$validext = true;
$extlist .= ($extlist ? ", " : "").$ext;
}
if(!$validext)
$error.="<li>".__("Invalid file type, must be one of:")." ".$extlist."</li>";
if(!$error)
{
$tmpfile = $_FILES['picture']['tmp_name'];
$file = "img/avatars/".$loguserid."_".$mid;
if($_POST['name'] == "")
$_POST['name'] = "#".$mid;
Query("insert into moodavatars (uid, mid, name) values (".$loguserid.", ".$mid.", '".justEscape($_POST['name'])."')");
if($loguser['powerlevel']) //Are we at least a local mod?
copy($tmpfile,$file); //Then ignore the 100x100 rule.
else
{
list($width, $height, $type) = getimagesize($tmpfile);
if($type == 1) $img1 = imagecreatefromgif ($tmpfile);
if($type == 2) $img1 = imagecreatefromjpeg($tmpfile);
if($type == 3) $img1 = imagecreatefrompng ($tmpfile);
if($width <= $dimx && $height <= $dimy && $type<=3)
copy($tmpfile,$file);
elseif($type <= 3)
{
$r = imagesx($img1) / imagesy($img1);
if($r > 1)
{
$img2=imagecreatetruecolor($dimx,floor($dimy / $r));
imagecopyresampled($img2,$img1,0,0,0,0,$dimx,$dimy/$r,imagesx($img1),imagesy($img1));
} else
{
$img2=imagecreatetruecolor(floor($dimx * $r), $dimy);
imagecopyresampled($img2,$img1,0,0,0,0,$dimx*$r,$dimy,imagesx($img1),imagesy($img1));
}
imagepng($img2,$file);
} else
$error.="<li>Invalid format.</li>";
}
$usepic = $file;
} else
Kill(__("Could not update your avatar for the following reason(s):")."<ul>".$error."</ul>");
}
}
}
$moodRows = "";
$rMoods = Query("select mid, name from moodavatars where uid=".$loguserid." order by mid asc");
while($mood = Fetch($rMoods))
{
$cellClass = ($cellClass+1) % 2;
$moodRows .= format(
"
<tr class=\"cell{0}\">
<td style=\"width: 100px;\">
<img src=\"img/avatars/{1}_{2}\" alt=\"\">
</td>
<td>
<form method=\"post\" action=\"editavatars.php\">
<input type=\"hidden\" name=\"mid\" value=\"{2}\" />
<input type=\"text\" id=\"name{2}\" name=\"name\" style=\"width: 60%;\" value=\"{3}\" />
<input type=\"submit\" name=\"action\" value=\"".__("Rename")."\" />
<input type=\"submit\" name=\"action\" value=\"".__("Delete")."\" />
</form>
</td>
</tr>
", $cellClass, $loguserid, $mood['mid'], htmlval($mood['name']));
}
write(
"
<table class=\"margin outline width50\">
<tr class=\"header1\">
<th colspan=\"2\">
".__("Mood avatars")."
</th>
</tr>
{0}
<tr class=\"header1\">
<th colspan=\"2\">
".__("Add new")."
</th>
</tr>
<tr class=\"cell2\">
<td>
</td>
<td>
<form method=\"post\" action=\"editavatars.php\" enctype=\"multipart/form-data\">
<label for=\"newName\">".__("Name:")."</label>
<input type=\"text\" id=\"newName\" name=\"name\" style=\"width: 60%;\" /><br />
<label for=\"pic\">".__("Image:")."</label>
<input type=\"file\" id=\"pic\" name=\"picture\" style=\"width: 75%;\" />
<input type=\"submit\" name=\"action\" value=\"".__("Add")."\" />
</form>
</td>
</table>
", $moodRows);
?>