/**
  * Processes submitting of the form which is generated in
  * {@link \Mibew\Controller\TranslationImportController::showFormAction()}
  * method.
  *
  * @param Request $request Incoming request.
  * @return string Rendered page content.
  */
 public function submitFormAction(Request $request)
 {
     csrf_check_token($request);
     $errors = array();
     $target = $request->request->get('target');
     if (!preg_match("/^[\\w-]{2,5}\$/", $target)) {
         $target = get_current_locale();
     }
     $override = (bool) $request->request->get('override', false);
     // Validate uploaded file
     $file = $request->files->get('translation_file');
     if ($file) {
         // Process uploaded file.
         $orig_filename = $file->getClientOriginalName();
         $file_size = $file->getSize();
         if ($file_size == 0 || $file_size > Settings::get('max_uploaded_file_size')) {
             $errors[] = failed_uploading_file($orig_filename, "Uploaded file size exceeded");
         } elseif ($file->getClientOriginalExtension() != 'po') {
             $errors[] = failed_uploading_file($orig_filename, "Invalid file type");
         }
     } else {
         $errors[] = getlocal("No file selected");
     }
     // Try to process uploaded file
     if (count($errors) == 0) {
         try {
             // Try to import new messages.
             import_messages($target, $file->getRealPath(), $override);
             // Remove cached client side translations.
             $this->getCache()->getItem('translation/js/' . $target)->clear();
             // The file is not needed any more. Remove it.
             unlink($file->getRealPath());
         } catch (\Exception $e) {
             $errors[] = $e->getMessage();
         }
     }
     if (count($errors) != 0) {
         $request->attributes->set('errors', $errors);
         // The form should be rebuild. Invoke appropriate action.
         return $this->showFormAction($request);
     }
     // Redirect the operator to the same page using GET method.
     $redirect_to = $this->generateUrl('translation_import', array('stored' => true));
     return $this->redirect($redirect_to);
 }
示例#2
0
 /**
  * Processes submitting of the form which is generated in
  * {@link \Mibew\Controller\Operator\AvatarController::showFormAction()}
  * method.
  *
  * @param Request $request Incoming request.
  * @return string Rendered page content.
  * @throws NotFoundException If the operator with specified ID is not found
  *   in the system.
  */
 public function submitFormAction(Request $request)
 {
     csrf_check_token($request);
     $operator = $this->getOperator();
     $op_id = $request->attributes->getInt('operator_id');
     $errors = array();
     // Try to load the target operator.
     $op = operator_by_id($op_id);
     if (!$op) {
         throw new NotFoundException('The operator is not found');
     }
     $avatar = $op['vcavatar'];
     $file = $request->files->get('avatarFile');
     if ($file) {
         // Process uploaded file.
         $valid_types = array("gif", "jpg", "png", "tif", "jpeg");
         $ext = $file->getClientOriginalExtension();
         $orig_filename = $file->getClientOriginalName();
         $new_file_name = intval($op_id) . ".{$ext}";
         $file_size = $file->getSize();
         if ($file_size == 0 || $file_size > Settings::get('max_uploaded_file_size')) {
             $errors[] = failed_uploading_file($orig_filename, "Uploaded file size exceeded");
         } elseif (!in_array($ext, $valid_types)) {
             $errors[] = failed_uploading_file($orig_filename, "Invalid file type");
         } else {
             // Remove avatar if it already exists
             $avatar_local_dir = MIBEW_FS_ROOT . '/files/avatar/';
             $full_file_path = $avatar_local_dir . $new_file_name;
             if (file_exists($full_file_path)) {
                 unlink($full_file_path);
             }
             // Move uploaded file to avatar directory
             try {
                 $file->move($avatar_local_dir, $new_file_name);
                 $avatar = 'files/avatar/' . $new_file_name;
             } catch (Exception $e) {
                 $errors[] = failed_uploading_file($orig_filename, "Error moving file");
             }
         }
     } else {
         $errors[] = getlocal("No file selected");
     }
     if (count($errors) != 0) {
         $request->attributes->set('errors', $errors);
         // The form should be rebuild. Invoke appropriate action.
         return $this->showFormAction($request);
     }
     // Update path to avatar in the database
     update_operator_avatar($op['operatorid'], $avatar);
     // Operator's data are cached in the authentication manager thus we need
     // to update them manually.
     if ($avatar && $operator['operatorid'] == $op_id) {
         $operator['vcavatar'] = $avatar;
         $this->getAuthenticationManager()->setOperator($operator);
     }
     // Redirect the operator to the same page using GET method.
     $redirect_to = $this->generateUrl('operator_avatar', array('operator_id' => $op_id));
     return $this->redirect($redirect_to);
 }
示例#3
0
文件: avatar.php 项目: kuell/chat
         $ext = preg_replace('/\\//', '', strtolower(substr($orig_filename, 1 + strrpos($orig_filename, "."))));
         $new_file_name = intval($opId) . ".{$ext}";
         loadsettings();
         $file_size = $_FILES['avatarFile']['size'];
         if ($file_size == 0 || $file_size > $settings['max_uploaded_file_size']) {
             $errors[] = failed_uploading_file($orig_filename, "errors.file.size.exceeded");
         } elseif (!in_array($ext, $valid_types)) {
             $errors[] = failed_uploading_file($orig_filename, "errors.invalid.file.type");
         } else {
             $avatar_local_dir = dirname(__FILE__) . "/../images/avatar/";
             $full_file_path = $avatar_local_dir . $new_file_name;
             if (file_exists($full_file_path)) {
                 unlink($full_file_path);
             }
             if (!@move_uploaded_file($_FILES['avatarFile']['tmp_name'], $full_file_path)) {
                 $errors[] = failed_uploading_file($orig_filename, "errors.file.move.error");
             } else {
                 $avatar = "{$mibewroot}/images/avatar/{$new_file_name}";
             }
         }
     } else {
         $errors[] = "No file selected";
     }
 }
 if (count($errors) == 0) {
     update_operator_avatar($op['operatorid'], $avatar);
     if ($opId && $avatar && $_SESSION["{$mysqlprefix}operator"] && $operator['operatorid'] == $opId) {
         $_SESSION["{$mysqlprefix}operator"]['vcavatar'] = $avatar;
     }
     header("Location: {$mibewroot}/operator/avatar.php?op=" . intval($opId));
     exit;