You are here

class ActionUploadAddFile in N1ED - Visual editor as CKEditor plugin with Bootstrap support 7

Hierarchy

Expanded class hierarchy of ActionUploadAddFile

1 file declares its use of ActionUploadAddFile
Actions.php in vendor/edsdk/file-uploader-server-php/src/lib/Actions.php

File

vendor/edsdk/file-uploader-server-php/src/lib/action/ActionUploadAddFile.php, line 17

Namespace

EdSDK\FileUploaderServer\lib\action
View source
class ActionUploadAddFile extends AActionUploadId {
  public function getName() {
    return "uploadAddFile";
  }
  public function run($req) {
    $this
      ->validateUploadId($req);
    $file = null;
    if (!isset($req->url)) {
      if ($req->m_fileName === null || $req->m_file === null) {
        throw new MessageException(Message::createMessage(Message::NO_FILE_UPLOADED));
      }
      if ($this->m_config
        ->getMaxUploadFileSize() > 0 && $req->m_fileSize > $this->m_config
        ->getMaxUploadFileSize()) {
        throw new MessageException(Message::createMessage(Message::FILE_SIZE_EXCEEDS_LIMIT, $req->m_fileName, "" . $req->m_fileSize, "" . $this->m_config
          ->getMaxUploadFileSize()));
      }
      $file = new FileUploaded($this->m_config, $req->uploadId, $req->m_fileName, $req->m_fileName);
      $ext = strtolower($file
        ->getExt());
      $allowedExts = $this->m_config
        ->getAllowedExtensions();
      $isAllowedExt = count($allowedExts) == 0;
      for ($i = 0; $i < count($allowedExts) && !$isAllowedExt; $i++) {
        $isAllowedExt = $allowedExts[$i] === $ext;
      }
      if (!$isAllowedExt) {
        $strExts = "";
        for ($i = 0; $i < count($allowedExts); $i++) {
          if ($i > 0) {
            $strExts .= ", ";
          }
          $strExts .= $allowedExts[$i];
        }
        throw new MessageException(Message::createMessage(Message::INCORRECT_EXTENSION, $req->m_fileName, $strExts));
      }
      $file
        ->uploadAndCommit($req->m_file);
    }
    else {
      if (filter_var($req->url, FILTER_VALIDATE_URL) === FALSE) {
        throw new MessageException(Message::createMessage(Message::DOWNLOAD_FAIL_INCORRECT_URL, $req->url));
      }
      $host = strtolower(parse_url($req->url, PHP_URL_HOST));
      $isHostAllowed = false;
      $relocateHosts = $this->m_config
        ->getRelocateFromHosts();
      for ($i = 0; $i < count($relocateHosts) && !$isHostAllowed; $i++) {
        if (strtolower($relocateHosts[$i]) === $host) {
          $isHostAllowed = true;
        }
      }
      if (count($relocateHosts) == 0 || $isHostAllowed) {
        $file = new FileUploaded($this->m_config, $req->uploadId, null, null);
        $file
          ->rehost($req->url);
      }
      else {
        throw new MessageException(Message::createMessage(Message::DOWNLOAD_FAIL_HOST_DENIED, $host));
      }
    }
    $resp = new RespUploadAddFile();
    $resp->file = $file
      ->getData();
    return $resp;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AAction::$m_config protected property
AAction::setConfig public function
AAction::validateBoolean protected function
AAction::validateInteger protected function
AAction::validateString protected function
AActionUploadId::validateUploadId protected function
ActionUploadAddFile::getName public function Overrides AAction::getName
ActionUploadAddFile::run public function Overrides AAction::run