Changeset 1155
- Timestamp:
- 11/12/11 17:18:55 (6 months ago)
- Location:
- trunk
- Files:
-
- 3 added
- 13 edited
-
common/attachment.php (modified) (1 diff)
-
common/avatar.php (added)
-
common/common.php (modified) (1 diff)
-
common/db/user.php (modified) (1 diff)
-
config.php.sample (modified) (1 diff)
-
scripts/make-avatar-folder (added)
-
scripts/setup (modified) (2 diffs)
-
smf/Sources/Load.php (modified) (1 diff)
-
www/controllers/account.php (modified) (2 diffs)
-
www/controllers/image_attachment.php (modified) (2 diffs)
-
www/format/format.php (modified) (3 diffs)
-
www/htaccess.sample (modified) (1 diff)
-
www/macros/macro_userimage.php (added)
-
www/url.php (modified) (1 diff)
-
www/views/account.php (modified) (1 diff)
-
www/views/sitewide.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/attachment.php
r1115 r1155 146 146 } 147 147 148 /** 149 * Resizes an image whose filepath is given by the parameters into a new 150 * location specified by the other parameters 151 * 152 * Returns whether or not the image has been successfully resized 153 * Note that it returns false if the image doesn't have a known file-type 154 * 155 * The $new_filepath parameter if ommited or given as null will result in the 156 * image being outputted directly to the client 157 * 158 * @param array $image_info An array containing information about the 159 * original image: width, height, mime-type 160 * @param string $filepath 161 * @param array $new_image_info An array containing the new width and 162 * height 163 * @param string $new_filepath 164 * @return bool 165 */ 166 function image_resize($image_info, $filepath, $new_image_info, 167 $new_filepath = null) { 168 list($image_width, $image_height, $image_type, $image_attribute) = $image_info; 169 list($new_image_width, $new_image_height) = $new_image_info; 170 171 switch ($image_type) { 172 case IMAGETYPE_GIF: 173 // NOTE: animated GIFs become static. Only the first frame is saved 174 // Seems like a good thing anyway 175 $image = imagecreatefromgif($filepath); 176 $image_resized = imagecreate($new_image_width, $new_image_height); 177 // reset palette and transparent color to that of the original file 178 $trans_col = imagecolortransparent($image); 179 imagepalettecopy($image_resized, $image); 180 imagefill($image_resized, 0, 0, $trans_col); 181 imagecolortransparent($image_resized, $trans_col); 182 imagecopyresampled($image_resized, $image, 0, 0, 0, 0, 183 $new_image_width, $new_image_height, $image_width, 184 $image_height); 185 186 if ($new_filepath != null) { 187 return imagegif($image_resized, $new_filepath); 188 } 189 return imagegif($image_resized); 190 191 case IMAGETYPE_JPEG: 192 $image = imagecreatefromjpeg($filepath); 193 $image_resized = imagecreatetruecolor($new_image_width, 194 $new_image_height); 195 imagecopyresampled($image_resized, $image, 0, 0, 0, 0, 196 $new_image_width, $new_image_height, $image_width, 197 $image_height); 198 199 if ($new_filepath != null) { 200 return imagejpeg($image_resized, $new_filepath); 201 } 202 return imagejpeg($image_resized); 203 204 case IMAGETYPE_PNG: 205 $image = imagecreatefrompng($filepath); 206 $image_resized = imagecreatetruecolor($new_image_width, 207 $new_image_height); 208 // turn off the alpha blending to keep the alpha channel 209 imagealphablending($image_resized, false); 210 // allocate transparent color 211 $col = imagecolorallocatealpha($image_resized, 0, 0, 0, 127); 212 // fill the image with the new color 213 imagefilledrectangle($image_resized, 0, 0, $new_image_width, 214 $new_image_height, $col); 215 imagecopyresampled($image_resized, $image, 0, 0, 0, 0, 216 $new_image_width, $new_image_height, $image_width, 217 $image_height); 218 imagesavealpha($image_resized, true); 219 if ($new_filepath != null) { 220 return imagepng($image_resized, $new_filepath); 221 } 222 return imagepng($image_resized); 223 224 default: 225 // unsupported image type 226 return false; 227 } 228 } 148 229 ?> -
trunk/common/common.php
r1083 r1155 260 260 function is_taggable($obj) { 261 261 return $obj == 'user' || $obj == 'task' || $obj == 'round' || $obj == 'textblock'; 262 } 263 264 /** 265 * Returns whether or not the size type given is an existent one on the site 266 * 267 * @param string $size_type 268 * @return bool 269 */ 270 function is_valid_size_type($size_type) { 271 $size_types = array("full", "tiny", "small", "normal", "forum", "big"); 272 return in_array($size_type, $size_types); 262 273 } 263 274 -
trunk/common/db/user.php
r1110 r1155 168 168 { 169 169 log_assert_valid(user_validate($user)); 170 170 171 171 // Update DB 172 172 db_update("ia_user", $user, "id = ".db_quote($user['id'])); -
trunk/config.php.sample
r1085 r1155 32 32 // Slashes at both ends. 33 33 define("IA_URL_PREFIX", "--write-me-IA_URL_PREFIX--"); 34 35 // Define the place the avatars are being stored 36 define("IA_AVATAR_FOLDER", "--write-me-IA_AVATAR_FOLDER--"); 34 37 35 38 -
trunk/scripts/setup
r1021 r1155 135 135 136 136 // Ask user. 137 $config_vars['IA_ROOT_DIR'] = read_line("SVN checkout dir?", $config_vars['IA_ROOT_DIR']); 137 $config_vars['IA_ROOT_DIR'] = read_line("SVN checkout dir?", 138 $config_vars['IA_ROOT_DIR']); 138 139 $config_vars['IA_ROOT_DIR'] = slash_string( 139 140 realpath($config_vars['IA_ROOT_DIR']), true, true); 141 $config_vars['IA_AVATAR_FOLDER'] = 142 $config_vars['IA_ROOT_DIR'].'www/static/images/avatar/'; 143 $config_vars['IA_AVATAR_FOLDER'] = read_line("Avatar Folder?", 144 $config_vars['IA_AVATAR_FOLDER']); 145 $config_vars['IA_AVATAR_FOLDER'] = slash_string( 146 realpath($config_vars['IA_AVATAR_FOLDER']), true, true); 140 147 $config_vars['IA_URL_HOST'] = read_line("Host part of url (with http)?", 141 148 $config_vars['IA_URL_HOST']); … … 223 230 system("chmod g+ws {$ia_root}attach"); 224 231 system("chmod g+ws {$ia_root}cache"); 232 system("chmod g+ws {$ia_root}www/static/images/avatar"); 225 233 system("chmod g+ws {$ia_root}www/static/images/tmp"); 226 234 system("chmod g+ws {$ia_root}www/static/images/latex"); -
trunk/smf/Sources/Load.php
r1154 r1155 1005 1005 1006 1006 // use infoarena avatars 1007 $avatar_img_src = url_user_avatar($profile['memberName'], ' 75x75', true);1007 $avatar_img_src = url_user_avatar($profile['memberName'], 'forum', true); 1008 1008 1009 1009 // What a monstrous array... -
trunk/www/controllers/account.php
r1069 r1155 4 4 require_once(IA_ROOT_DIR."common/db/attachment.php"); 5 5 require_once(IA_ROOT_DIR."common/db/smf.php"); 6 require_once(IA_ROOT_DIR."common/avatar.php"); 6 7 require_once(IA_ROOT_DIR."www/controllers/account_validator.php"); 8 require_once(IA_ROOT_DIR."www/config.php"); 7 9 8 10 // identify target user and check permission to edit profile … … 131 133 $errors['avatar'] = 'Fisierul nu a putut fi incarcat ' 132 134 .'pe server.'; 135 } else { 136 // resize the avatar if it is a correct mime-type 137 global $IA_SAFE_MIME_TYPES; 138 $img_info = getimagesize($disk_name); 139 // check if mime-type is from accepted ones 140 if (in_array($img_info['mime'], $IA_SAFE_MIME_TYPES)) { 141 avatar_cache_resized($disk_name, $img_info, 142 "a".$user['username']); 143 } 133 144 } 134 145 } -
trunk/www/controllers/image_attachment.php
r923 r1155 70 70 // Image is placed in output buffer, cached, then flushed. 71 71 ob_start(); 72 switch ($img_type) { 73 case IMAGETYPE_GIF: 74 // NOTE: animated GIFs become static. Only the first frame is saved 75 // Seems like a good thing anyway 76 $im = imagecreatefromgif($real_name); 77 $im_resized = imagecreate($new_width, $new_height); 78 // reset palette and transparent color to that of the original file 79 $trans_col = imagecolortransparent($im); 80 imagepalettecopy($im_resized, $im); 81 imagefill($im_resized, 0, 0, $trans_col); 82 imagecolortransparent($im_resized, $trans_col); 83 imagecopyresampled($im_resized, $im, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height); 84 imagegif($im_resized); 85 break; 72 $image_supported = image_resize($ret, $real_name, array($new_width, $new_height)); 86 73 87 case IMAGETYPE_JPEG: 88 $im = imagecreatefromjpeg($real_name); 89 $im_resized = imagecreatetruecolor($new_width, $new_height); 90 imagecopyresampled($im_resized, $im, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height); 91 imagejpeg($im_resized); 92 break; 93 94 case IMAGETYPE_PNG: 95 $im = imagecreatefrompng($real_name); 96 $im_resized = imagecreatetruecolor($new_width, $new_height); 97 // turn off the alpha blending to keep the alpha channel 98 imagealphablending($im_resized, false); 99 // allocate transparent color 100 $col = imagecolorallocatealpha($im_resized, 0, 0, 0, 127); 101 // fill the image with the new color 102 imagefilledrectangle($im_resized, 0, 0, $new_width, $new_height, $col); 103 imagecopyresampled($im_resized, $im, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height); 104 imagesavealpha($im_resized, true); 105 imagepng($im_resized); 106 break; 107 108 default: 109 ob_end_clean(); 110 // unsupported image type 111 die_http_error(500, "Unsupported image type"); 74 if ($image_supported == false) { 75 ob_end_clean(); 76 die_http_error(500, "Unsupported image"); 112 77 } 113 78 … … 120 85 header("Content-Type: " . image_type_to_mime_type($img_type)); 121 86 header("Content-Disposition: inline; filename=" . urlencode($file_name) . ";"); 122 // WARNING: strlen() is supposed to be binary safe but some say it may 87 // WARNING: strlen() is supposed to be binary safe but some say it may 123 88 // be shadowed by mb_strlen() and treat strings as unicode by default, 124 89 // thus reporting invalid lengths for random binary buffers. -
trunk/www/format/format.php
r1105 r1155 130 130 131 131 // Format avatar img. 132 function format_user_avatar($user_name, $ width = 50, $height = 50,132 function format_user_avatar($user_name, $size_type = "full", 133 133 $absolute = false) 134 134 { 135 log_assert(is_whole_number($width), "Invalid width"); 136 log_assert(is_whole_number($height), "Invalid height"); 137 $url = url_user_avatar($user_name, "L{$width}x{$height}"); 135 log_assert(is_valid_size_type($size_type), "Invalid size type"); 136 $url = url_user_avatar($user_name, $size_type); 138 137 if ($absolute) { 139 138 $url = url_absolute($url); … … 166 165 $result .= "<span class=\"tiny-user\">"; 167 166 $result .= format_link($user_url, 168 format_user_avatar($user_name, 16, 16, false).$user_fullname,167 format_user_avatar($user_name, "tiny", false).$user_fullname, 169 168 false); 170 169 $result .= ' '.$rbadge; … … 188 187 $result .= "<div class=\"normal-user\">"; 189 188 $result .= format_link($user_url, 190 format_user_avatar($user_name, 32, 32, false),189 format_user_avatar($user_name, "small", false), 191 190 false); 192 191 $result .= "<span class=\"fullname\">$user_fullname</span><br />"; -
trunk/www/htaccess.sample
r980 r1155 12 12 RewriteCond %{REQUEST_URI} !^.*/stiri/.*$ 13 13 RewriteCond %{REQUEST_URI} !^.*/news_feed$ 14 RewriteCond %{REQUEST_URI} !^.*/avatar/.*$ 14 15 RewriteRule ^(.*) index.php?page=$1 [QSA] 16 17 RewriteRule ^avatar/(tiny|small|normal|forum|big|full)/(.+)$ static/images/avatar/$1/a$2 18 RewriteCond %{REQUEST_FILENAME} !-f 19 RewriteCond %{REQUEST_FILENAME} !-d 20 RewriteRule ^static/images/avatar/(tiny|small|normal|forum|big|full)/(.+)$ static/images/avatar/$1/noimage 21 15 22 RewriteRule ^stiri/(.*)$ blog/$1 [R=301,QSA] 16 23 RewriteRule ^news_feed$ blog?action=rss [R=301,QSA] -
trunk/www/url.php
r1132 r1155 239 239 } 240 240 241 function url_user_avatar($username, $resize = "50x50") { 242 return url_image_resize(IA_USER_TEXTBLOCK_PREFIX . $username, 'avatar', $resize); 241 /** 242 * Returns an url to an user's avatar with a given size 243 * 244 * @param string $username 245 * @param string $size_type 246 * @return string 247 */ 248 function url_user_avatar($username, $size_type = "full") { 249 return url_complex("avatar/".$size_type."/".$username); 243 250 } 244 251 -
trunk/www/views/account.php
r1149 r1155 92 92 <?php 93 93 // display avatar 94 $avatar_url = url_user_avatar($user['username'], " 150x150");94 $avatar_url = url_user_avatar($user['username'], "big"); 95 95 echo '<img class="avatar" src="'.html_escape($avatar_url).'" alt="avatar"/>'; 96 96 ?> -
trunk/www/views/sitewide.php
r1064 r1155 16 16 <?php if (!identity_is_anonymous()) { $username = $identity_user['username']; ?> 17 17 <div id="userbox"> 18 <?= format_link(url_user_profile($username, true), format_user_avatar($username, 50, 50, true), false) ?>18 <?= format_link(url_user_profile($username, true), format_user_avatar($username, "normal", true), false) ?> 19 19 <div class="user"> 20 20 <strong><?= html_escape($identity_user['full_name']) ?></strong><br/>
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)