Changeset 1159 for trunk/common
- Timestamp:
- 12/07/11 17:51:00 (6 months ago)
- Location:
- trunk/common
- Files:
-
- 4 edited
-
attachment.php (modified) (1 diff)
-
avatar.php (modified) (2 diffs)
-
common.php (modified) (1 diff)
-
security.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/attachment.php
r1155 r1159 178 178 $trans_col = imagecolortransparent($image); 179 179 imagepalettecopy($image_resized, $image); 180 imagefill($image_resized, 0, 0, $trans_col); 180 if ($trans_col != -1) { 181 imagefill($image_resized, 0, 0, $trans_col); 182 } 181 183 imagecolortransparent($image_resized, $trans_col); 182 184 imagecopyresampled($image_resized, $image, 0, 0, 0, 0, -
trunk/common/avatar.php
r1156 r1159 7 7 require_once(IA_ROOT_DIR.'www/controllers/account_validator.php'); 8 8 require_once(IA_ROOT_DIR.'common/common.php'); 9 require_once(IA_ROOT_DIR.'www/config.php'); 9 10 require_once(IA_ROOT_DIR.'common/attachment.php'); 11 12 /** 13 * Returns whether the attachment of the given page is an avatar attachment 14 * @param string $attachment_name 15 * @param string $page_name 16 * @return bool 17 */ 18 function is_avatar_attachment($attachment_name, $page_name) { 19 $matches = get_page_user_name($page_name); 20 21 if ($attachment_name === 'avatar' && $matches) { 22 return true; 23 } 24 25 return false; 26 } 27 28 /** 29 * Resizes a newly uploaded avatar and returns errors if any 30 * @param string $temporary_name 31 * @param string $filepath The filepath where to copy the attachment 32 * @param string $username 33 * @return mixed Error message or null on success 34 */ 35 function avatar_update($temporary_name, $filepath, $username) { 36 // resize the avatar if it has a correct mime-type 37 $avatar_mime_types = array('image/gif', 'image/jpeg', 'image/png'); 38 $image_info = getimagesize($temporary_name); 39 if (!in_array($image_info['mime'], $avatar_mime_types)) { 40 return 'Fisierul nu este o imagine acceptata pe site. ' . 41 'Utilizati doar imagini GIF, JPEG sau PNG.'; 42 } 43 44 // write the file on disk. 45 if (!move_uploaded_file($temporary_name, $filepath)) { 46 return 'Fisierul nu a putut fi incarcat pe server.'; 47 } 48 // resize the avatar 49 avatar_cache_resized($filepath, $image_info, "a".$username); 50 return null; 51 } 10 52 11 53 /** … … 45 87 } 46 88 89 /** 90 * Delete's an user avatar, the rest is done from the attachment page 91 * 92 * @param string $username 93 */ 94 function avatar_delete($username) { 95 $resize_folders = array('tiny/', 'small/', 'normal/', 'forum/', 'big/'); 96 97 // Unlink the hardlinked full-sized image 98 $filepath = IA_AVATAR_FOLDER . 'full/a' . $username; 99 if (is_file($filepath) || is_link($filepath)) { 100 unlink($filepath); 101 } 102 103 // Delete the resized ones 104 foreach ($resize_folders as $resize_folder) { 105 $filepath = IA_AVATAR_FOLDER . $resize_folder . 'a' 106 . $username; 107 if (is_file($filepath) || is_link($filepath)) { 108 unlink($filepath); 109 } 110 } 111 } 47 112 ?> -
trunk/common/common.php
r1155 r1159 154 154 function is_page_name($page_name) { 155 155 return preg_match('/^'.IA_RE_PAGE_NAME.'$/xi', $page_name); 156 } 157 158 /** 159 * Validates user page name 160 * 161 * @param string $page_name 162 * @return array returns an array containing the matched user 163 */ 164 function get_page_user_name($page_name) { 165 preg_match("/^ ". 166 preg_quote(IA_USER_TEXTBLOCK_PREFIX, '/'). 167 '('.IA_RE_USER_NAME.") (\/?.*) $/xi", 168 $page_name, $matches); 169 return $matches; 156 170 } 157 171 -
trunk/common/security.php
r1150 r1159 193 193 // HACK: Forward security to user. 194 194 // HACK: based on name 195 if (preg_match("/^ ". 196 preg_quote(IA_USER_TEXTBLOCK_PREFIX, '/'). 197 '('.IA_RE_USER_NAME.") (\/?.*) $/xi", 198 $textblock['name'], $matches)) { 195 if (count($matches = get_page_user_name($textblock['name'])) > 0) { 199 196 require_once(IA_ROOT_DIR . "common/db/user.php"); 200 197 $ouser = user_get_by_username($matches[1]); … … 205 202 // This is a horrible hack to prevent deleting or moving an user page. 206 203 // This is pure evil. 207 if ($matches[2] != '') {208 return false;209 }210 204 if ($action == 'textblock-delete' || $action == 'textblock-move') { 211 205 $action = 'simple-critical';
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)