public function moveFiles(\DataContainer $dc)
 {
     $arrPost = Request::getPost();
     foreach ($arrPost as $key => $value) {
         $arrData = $GLOBALS['TL_DCA'][$dc->table]['fields'][$key];
         if ($arrData['inputType'] != MultiFileUpload::NAME) {
             continue;
         }
         $arrFiles = deserialize($dc->activeRecord->{$key});
         $strUploadFolder = Files::getFolderFromDca($arrData['eval']['uploadFolder'], $dc);
         if ($strUploadFolder === null) {
             throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['uploadNoUploadFolderDeclared'], $key, MultiFileUpload::UPLOAD_TMP));
         }
         if (!is_array($arrFiles)) {
             $arrFiles = array($arrFiles);
         }
         $objFileModels = FilesModel::findMultipleByUuids($arrFiles);
         if ($objFileModels === null) {
             continue;
         }
         $arrPaths = $objFileModels->fetchEach('path');
         $arrTargets = array();
         // do not loop over $objFileModels as $objFile->close() will pull models away
         foreach ($arrPaths as $strPath) {
             $objFile = new \File($strPath);
             $strName = $objFile->name;
             $strTarget = $strUploadFolder . '/' . $strName;
             // upload_path_callback
             if (is_array($arrData['upload_path_callback'])) {
                 foreach ($arrData['upload_path_callback'] as $callback) {
                     $strTarget = \System::importStatic($callback[0])->{$callback[1]}($strTarget, $objFile, $dc) ?: $strTarget;
                 }
             }
             if (StringUtil::startsWith($objFile->path, ltrim($strTarget, '/'))) {
                 continue;
             }
             if ($objFile->renameTo($strTarget)) {
                 $arrTargets[] = $strTarget;
                 $objFile->close();
                 continue;
             }
             $arrTargets[] = $strPath;
         }
         // HOOK: post upload callback
         if (isset($GLOBALS['TL_HOOKS']['postUpload']) && is_array($GLOBALS['TL_HOOKS']['postUpload'])) {
             foreach ($GLOBALS['TL_HOOKS']['postUpload'] as $callback) {
                 if (is_array($callback)) {
                     \System::importStatic($callback[0])->{$callback[1]}($arrTargets);
                 } elseif (is_callable($callback)) {
                     $callback($arrTargets);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public function show()
 {
     global $objPage;
     $back = \Controller::generateFrontendUrl($objPage->row(), null, null, true);
     $blnAjax = false;
     $objModal = new Modal($this->objModal, $this->arrConfig);
     $objModal->setBackLink($back);
     $objResponse = new ResponseSuccess();
     $objResponse->setResult(new ResponseData($objModal->generate(), array('id' => $this->objModal->id)));
     $objResponse->setUrl(AjaxAction::removeAjaxParametersFromUrl(Request::getInstance()->getRequestUri()));
     return $objResponse;
 }
Exemplo n.º 3
0
 protected function getArguments()
 {
     $arrArgumentValues = array();
     $arrArguments = $this->arrAttributes['arguments'];
     $arrOptional = is_array($this->arrAttributes['optional']) ? $this->arrAttributes['optional'] : array();
     $strMethod = Request::getInstance()->getMethod();
     foreach ($arrArguments as $argument) {
         if (is_array($argument) || is_bool($argument)) {
             $arrArgumentValues[] = $argument;
             continue;
         }
         if (!in_array($argument, $arrOptional) && ($strMethod == 'POST' && !isset($_POST[$argument]) || $strMethod == 'GET' && !isset($_GET[$argument]))) {
             header('HTTP/1.1 400 Bad Request');
             die('Bad Request, missing argument ' . $argument);
         }
         $varValue = $strMethod == 'POST' ? Request::getPost($argument) : Request::getGet($argument);
         if ($varValue === 'true' || $varValue === 'false') {
             $varValue = filter_var($varValue, FILTER_VALIDATE_BOOLEAN);
         }
         $arrArgumentValues[] = $varValue;
     }
     return $arrArgumentValues;
 }
Exemplo n.º 4
0
 /**
  * Toggle Subpalette
  * @param      $id
  * @param      $strField
  * @param bool $blnLoad
  *
  * @return ResponseError|ResponseSuccess
  */
 function toggleSubpalette($id, $strField, $blnLoad = false)
 {
     if (!$this->dc->isSubmitted()) {
         return;
     }
     $varValue = Request::getPost($strField) ?: 0;
     if (!is_array($this->dca['palettes']['__selector__']) || !in_array($strField, $this->dca['palettes']['__selector__'])) {
         \Controller::log('Field "' . $strField . '" is not an allowed selector field (possible SQL injection attempt)', __METHOD__, TL_ERROR);
         return new ResponseError();
     }
     $arrData = $this->dca['fields'][$strField];
     if (!Validator::isValidOption($varValue, $arrData, $this->dc)) {
         \Controller::log('Field "' . $strField . '" value is not an allowed option (possible SQL injection attempt)', __METHOD__, TL_ERROR);
         return new ResponseError();
     }
     if (empty(FormHelper::getFieldOptions($arrData, $this->dc))) {
         $varValue = intval($varValue) ? 1 : '';
     }
     $this->dc->setSkipValidation(true);
     // do not validate fields
     $this->dc->setDoNotSubmit(true);
     $this->dc->activeRecord->{$strField} = $varValue;
     $objResponse = new ResponseSuccess();
     if ($blnLoad) {
         $objResponse->setResult(new ResponseData($this->dc->edit(false, $id)));
     }
     return $objResponse;
 }
 /**
  * Redirect and append idGetParameter to url, depending on current configuration
  *
  * @param null $intId The entity id, if null $this->intId will be used from context
  */
 protected function doIdDependentRedirectToEntity($intId = null)
 {
     if ($intId === null) {
         $intId = $this->intId;
     }
     if (!$intId) {
         return;
     }
     if ($this->allowIdAsGetParameter && $this->appendIdToUrlOnCreation && \Input::get($this->idGetParameter) != $intId) {
         $strUrl = Url::addQueryString($this->idGetParameter . '=' . $this->intId);
         // Use AjaxAction::generateUrl(Form::FORMHYBRID_NAME, null, array(Ajax::AJAX_ATTR_AJAXID => $this->objModule->id)) for formhybrid ajax create links
         if (Ajax::isRelated(Form::FORMHYBRID_NAME) !== null && \HeimrichHannot\Request\Request::getGet(Ajax::AJAX_ATTR_AJAXID)) {
             $objResponse = new ResponseRedirect();
             $objResponse->setUrl($strUrl);
             $objResponse->output();
         }
         \Controller::redirect($strUrl);
     }
 }
Exemplo n.º 6
0
 /**
  * Get the active ajax action object
  *
  * @param $strGroupRequested Requested ajax group
  * @param $strActionRequested Requested ajax action within group
  *
  * @return AjaxAction|null  A valid AjaxAction | null if the action is not a registered ajax action
  */
 public static function getActiveAction($strGroupRequested, $strActionRequested)
 {
     $strAct = Request::getGet(static::AJAX_ATTR_ACT);
     if (!$strAct) {
         return null;
     }
     if (($strGroup = static::getActiveGroup($strGroupRequested)) === null) {
         return null;
     }
     if ($strActionRequested != $strAct) {
         return null;
     }
     $arrConfig = $GLOBALS['AJAX'];
     if (!is_array($arrConfig)) {
         return null;
     }
     if (!isset($arrConfig[$strGroup])) {
         return AJAX_ERROR_INVALID_GROUP;
     }
     if (!is_array($arrConfig[$strGroup]['actions'])) {
         return AJAX_ERROR_NO_AVAILABLE_ACTIONS;
     }
     $arrActions = $arrConfig[$strGroup]['actions'];
     if (!array_key_exists($strActionRequested, $arrActions)) {
         return AJAX_ERROR_INVALID_ACTION;
     }
     $arrAttributes = $arrActions[$strAct];
     return new AjaxAction($strGroup, $strAct, $arrAttributes);
 }