Changeset 1159
- Timestamp:
- 12/07/11 17:51:00 (6 months ago)
- Location:
- trunk
- Files:
-
- 10 edited
-
common/attachment.php (modified) (1 diff)
-
common/avatar.php (modified) (2 diffs)
-
common/common.php (modified) (1 diff)
-
common/security.php (modified) (2 diffs)
-
scripts/setup (modified) (2 diffs)
-
www/controllers/account.php (modified) (3 diffs)
-
www/controllers/attachment.php (modified) (14 diffs)
-
www/index.php (modified) (1 diff)
-
www/views/account.php (modified) (1 diff)
-
www/views/listattach.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'; -
trunk/scripts/setup
r1155 r1159 230 230 system("chmod g+ws {$ia_root}attach"); 231 231 system("chmod g+ws {$ia_root}cache"); 232 system("chmod g+ws {$ia_root}www/static/images/avatar");233 232 system("chmod g+ws {$ia_root}www/static/images/tmp"); 234 233 system("chmod g+ws {$ia_root}www/static/images/latex"); … … 269 268 } 270 269 270 // Running scripts to keep things simple for new developers 271 system("./{$ia_root}scripts/make-avatar-folder"); 271 272 // FIXME: configure forum 272 273 if (read_bool("Should I try to configure the forum (ugly db stuff)?", true)) { -
trunk/www/controllers/account.php
r1155 r1159 7 7 require_once(IA_ROOT_DIR."www/controllers/account_validator.php"); 8 8 require_once(IA_ROOT_DIR."www/config.php"); 9 require_once(IA_ROOT_DIR."common/avatar.php"); 9 10 10 11 // identify target user and check permission to edit profile … … 129 130 if (!$errors) { 130 131 $disk_name = attachment_get_filepath($attach); 131 if (!move_uploaded_file($_FILES['avatar']['tmp_name'], 132 $disk_name)) { 133 $errors['avatar'] = 'Fisierul nu a putut fi incarcat ' 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 } 144 } 132 $errors['avatar'] = avatar_update( 133 $_FILES['avatar']['tmp_name'], $disk_name, 134 $user['username']); 145 135 } 146 136 } … … 212 202 $view['form_values'] = $data; 213 203 $view['action'] = url_account($user['username']); 204 $view['avatar_exists'] = attachment_get('avatar', IA_USER_TEXTBLOCK_PREFIX . 205 $user['username']); 214 206 if ($ownprofile) { 215 207 $view['topnav_select'] = 'profile'; -
trunk/www/controllers/attachment.php
r1115 r1159 6 6 require_once(IA_ROOT_DIR.'www/controllers/zip_attachment.php'); 7 7 require_once(IA_ROOT_DIR."common/external_libs/zipfile.php"); 8 require_once(IA_ROOT_DIR."common/avatar.php"); 8 9 9 10 // Try to get the textblock model for a certain page. … … 109 110 if (!$form_errors) { 110 111 if ($autoextract) { 111 $zip_files = get_zipped_attachments($_FILES['file_name']['tmp_name']); 112 $zip_files = get_zipped_attachments( 113 $_FILES['file_name']['tmp_name']); 112 114 113 115 if (false === $zip_files) { 114 $form_errors['file_name'] = 'Arhiva ZIP este invalida sau nu poate fi recunoscuta'; 116 $form_errors['file_name'] = 'Arhiva ZIP este invalida sau nu ' 117 . 'poate fi recunoscuta'; 115 118 } else { 116 119 $attachments = $zip_files['attachments']; 117 $skipped_files = $zip_files['total_files'] - count($attachments); 120 $skipped_files = $zip_files['total_files'] - 121 count($attachments); 118 122 } 119 123 } … … 121 125 // simple (single) file attachment 122 126 $attachments = array( 123 array('name' => $form_values['file_name'], 'size' => $form_values['file_size'],124 'disk_name' => $_FILES['file_name']['tmp_name'])125 );127 array('name' => $form_values['file_name'], 128 'size' => $form_values['file_size'], 129 'disk_name' => $_FILES['file_name']['tmp_name'])); 126 130 } 127 131 } … … 141 145 $tmpname = tempnam(IA_ROOT_DIR . 'attach/', 'iatmp'); 142 146 log_assert($tmpname); 143 $res = extract_zipped_attachment($ziparchive, $att['zipindex'], $tmpname); 147 $res = extract_zipped_attachment($ziparchive, $att['zipindex'], 148 $tmpname); 144 149 if ($res) { 145 150 $att['disk_name'] = $tmpname; … … 165 170 $rewrite_count = 0; 166 171 $attach_okcount = 0; 172 $extra_errors = ''; 167 173 if (!$form_errors) { 168 174 for ($i = 0; $i < count($attachments); $i++) { … … 180 186 } 181 187 $file_att['size'] = filesize($file_att['disk_name']); 188 } 189 190 if (is_avatar_attachment($file_att['name'], $page_name)) { 191 if (isset($skipped_files)) { 192 $skipped_files++; 193 } 194 $extra_errors .= ' A fost intalnit un fisier cu numele avatar' . 195 '. Pentru a va modifica imaginea de profil va rugam ' . 196 'folositi pagina "Contul meu".'; 197 continue; 182 198 } 183 199 … … 216 232 $disk_name = attachment_get_filepath($file_att['attach_obj']); 217 233 if (is_uploaded_file($file_att['disk_name'])) { 218 $move_ok = move_uploaded_file($file_att['disk_name'], $disk_name); 234 $move_ok = move_uploaded_file($file_att['disk_name'], 235 $disk_name); 219 236 } else { 220 237 $move_ok = @rename($file_att['disk_name'], $disk_name); … … 232 249 233 250 // custom error message for simple (single) file uploads 234 if (!$form_errors && !$autoextract && 0 >= $attach_okcount) { 235 $form_errors['file_name'] = 'Fisierul nu a putut fi atasat! Eroare necunoscuta ...'; 251 if (!$form_errors && !$autoextract && 0 >= $attach_okcount && 252 !$extra_errors) { 253 $form_errors['file_name'] = 'Fisierul nu a putut fi atasat! Eroare ' . 254 'necunoscuta ...'; 236 255 } 237 256 … … 240 259 if ($autoextract) { 241 260 if ($attach_okcount == 1) { 242 $msg = "Am extras si incarcat un fisier.";261 $msg = 'Am extras si incarcat un fisier.'; 243 262 } else { 244 263 $msg = "Am extras si incarcat {$attach_okcount} fisiere."; … … 246 265 247 266 if ($rewrite_count == 1) { 248 $msg .= " Un fisier mai vechi a fost rescris.";267 $msg .= ' Un fisier mai vechi a fost rescris.'; 249 268 } else if ($rewrite_count > 1) { 250 269 $msg .= " {$rewrite_count} fisiere mai vechi au fost rescrise."; … … 252 271 253 272 if ($skipped_files == 1) { 254 $msg .= " Un fisier nu a fost dezarhivat deoarece era prea mare sau era invalid."; 273 $msg .= ' Un fisier nu a fost dezarhivat deoarece era prea ' . 274 'mare sau era invalid.'; 255 275 } else if ($skipped_files > 1) { 256 $msg .= " {$skipped_files} fisiere nu au fost dezarhivate deoarece erau prea mari sau erau invalide."; 257 } 276 $msg .= " {$skipped_files} fisiere nu au fost dezarhivate " . 277 'deoarece erau prea mari sau erau invalide.'; 278 } 279 $msg .= $extra_errors; 258 280 } 259 281 else { 260 if ($rewrite_count) { 261 $msg = "Fisierul trimis a fost atasat cu succes. Un atasamant mai vechi a fost rescris."; 262 } 263 else { 264 $msg = "Fisierul trimis a fost atasat cu succes."; 282 if ($extra_errors) { 283 $msg = $extra_errors; 284 } else if($rewrite_count) { 285 $msg = 'Fisierul trimis a fost atasat cu succes. Un atasament' . 286 'mai vechi a fost rescris.'; 287 } else { 288 $msg = 'Fisierul trimis a fost atasat cu succes.'; 265 289 } 266 290 } … … 270 294 } 271 295 296 $form_errors['file_name'] .= $extra_errors; 272 297 // Errors, print view template. 273 298 $view['form_errors'] = $form_errors; … … 301 326 } 302 327 328 // Delete the resizedimages in case the page is an avatar 329 $matches = get_page_user_name($page_name); 330 if (is_avatar_attachment($file_name, $page_name)) { 331 avatar_delete($matches[1]); 332 } 303 333 // We've got big balls. 304 334 … … 342 372 if ($old_name == $new_name) { 343 373 redirect(url_attachment_list($page_name)); 374 } 375 376 if (is_avatar_attachment($old_name, $page_name)) { 377 flash_error('Atasamentul "avatar" nu poate fi redenumit.'); 378 redirect(url_textblock($page_name)); 379 } 380 381 if (is_avatar_attachment($new_name, $page_name)) { 382 flash_error('Nu puteti numi un atasament "avatar". Pentru ' 383 . 'a va modifica imaginea de profil va rugam folositi ' 384 . 'pagina "Contul meu".'); 385 redirect(url_textblock($page_name)); 344 386 } 345 387 -
trunk/www/index.php
r1157 r1159 280 280 } 281 281 } 282 else if ($action == ' download-zip') {282 else if ($action == 'attach-bulk-action') { 283 283 require_once(IA_ROOT_DIR.'www/controllers/attachment.php'); 284 284 if(request('download')) { -
trunk/www/views/account.php
r1155 r1159 97 97 </li> 98 98 <li> 99 <?php 100 if ($view['avatar_exists']) { 101 echo format_post_link(url_attachment_delete( 102 IA_USER_TEXTBLOCK_PREFIX . $user['username'], 103 'avatar'), "Sterge Avatar", array(), true, 104 array('onclick' => "return confirm('Aceasta " . 105 'actiune este ireversibila! Doresti ' . 106 "sa continui?')")); 107 } 108 ?> 99 109 <label for="form_avatar">Avatar nou</label> 100 110 <?= ferr_span('avatar') ?> -
trunk/www/views/listattach.php
r1073 r1159 37 37 function format_attach_name($row) { 38 38 global $page_name; 39 39 40 40 $attachurl = '<span id="rename_'.$row['id'].'" style="display: none">'; 41 41 $attachurl .= '<form action="'.url_attachment_rename($page_name).'" method="post">'; … … 126 126 ); 127 127 ?> 128 <form method = 'post' action = ''> 129 <input type = 'hidden' name = 'action' value = ' download-zip'>128 <form method = 'post' action = ''> 129 <input type = 'hidden' name = 'action' value = 'attach-bulk-action'> 130 130 <h1>Atasamente pentru pagina <?= format_link(url_textblock($view['page_name']), $view['page_name']) ?></h1> 131 131 <?php
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)