You are here

static function FlmngrServer::flmngrRequest in N1ED - Visual editor as CKEditor plugin with Bootstrap support 7

File

vendor/edsdk/flmngr-server-php/src/FlmngrServer.php, line 24

Class

FlmngrServer

Namespace

EdSDK\FlmngrServer

Code

static function flmngrRequest($config) {
  $action = NULL;
  if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['action'])) {
      $action = $_POST['action'];
    }
    if ($action == NULL && isset($_POST["data"])) {
      $configUploader = [
        "dirFiles" => $config["dirFiles"],
        "dirTmp" => $config["dirTmp"],
        "config" => isset($config["uploader"]) ? $config["uploader"] : [],
      ];
      FileUploaderServer::fileUploadRequest($configUploader);
      return;
    }
  }
  else {
    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
      $action = $_GET['action'];
    }
    else {
      return;
    }
  }
  try {
    switch ($action) {
      case 'dirList':
        $resp = FlmngrServer::reqDirList($config);
        break;
      case 'dirCreate':
        $resp = FlmngrServer::reqDirCreate($config);
        break;
      case 'dirRename':
        $resp = FlmngrServer::reqDirRename($config);
        break;
      case 'dirDelete':
        $resp = FlmngrServer::reqDirDelete($config);
        break;
      case 'dirCopy':
        $resp = FlmngrServer::reqDirCopy($config);
        break;
      case 'dirMove':
        $resp = FlmngrServer::reqDirMove($config);
        break;
      case 'dirDownload':
        $resp = FlmngrServer::reqDirDownload($config);
        break;
      case 'fileList':
        $resp = FlmngrServer::reqFileList($config);
        break;
      case 'fileDelete':
        $resp = FlmngrServer::reqFileDelete($config);
        break;
      case 'fileCopy':
        $resp = FlmngrServer::reqFileCopy($config);
        break;
      case 'fileRename':
        $resp = FlmngrServer::reqFileRename($config);
        break;
      case 'fileMove':
        $resp = FlmngrServer::reqFileMove($config);
        break;
      case 'fileResize':
        $resp = FlmngrServer::reqFileResize($config);
        break;
      case 'fileOriginal':
        $resp = FlmngrServer::reqFileOriginal($config);

        // will die after valid response or throw MessageException
        break;
      case 'filePreview':
        $resp = FlmngrServer::reqFilePreview($config);

        // will die after valid response or throw MessageException
        break;
      case 'getVersion':
        $resp = FlmngrServer::getVersion();
        break;
      default:
        $resp = new Response(Message::createMessage(Message::ACTION_NOT_FOUND), NULL);
    }
  } catch (MessageException $e) {
    $resp = new Response($e
      ->getFailMessage(), NULL);
  }

  //print_r($resp);
  $strResp = JsonCodec::s_toJson($resp);
  try {
    http_response_code(200);
    header('Content-Type: application/json; charset=UTF-8');
    print $strResp;
  } catch (Exception $e) {
    error_log($e);
  }
}