protected function fixUuidToBinary($strUuid) { if (\Validator::isStringUuid($strUuid)) { $strUuid = \String::uuidToBin($strUuid); } return $strUuid; }
/** * Find a watchlist item by its pid and uuid * * @param string $intPid The watchlist id * @param string $intUuid The files uuid * @param array $arrOptions An optional options array * * @return \Model|null The model or null if there is no watchlist */ public static function findByPidAndUuid($intPid, $strUuid, array $arrOptions = array()) { $t = static::$strTable; // Convert UUIDs to binary if (\Validator::isStringUuid($strUuid)) { $strUuid = \String::uuidToBin($strUuid); } return static::findOneBy(array("{$t}.pid=?", "{$t}.uuid=UNHEX(?)"), array($intPid, bin2hex($strUuid)), $arrOptions); }
public static function findByUuidAndPidAndUrl($strUuid, $intPid, $strUrl, array $arrOptions = array()) { $t = static::$strTable; // Convert UUIDs to binary if (\Validator::isStringUuid($strUuid)) { $strUuid = \StringUtil::uuidToBin($strUuid); } $arrColumns = array("{$t}.uuid=UNHEX(?) AND {$t}.pid=? AND {$t}.url=?"); return static::findBy($arrColumns, array(bin2hex($strUuid), $intPid, $strUrl), $arrOptions); }
/** * Run the controller and parse the template */ public function run() { $this->Template = new BackendTemplate('be_picker'); $this->Template->main = ''; // Ajax request if ($_POST && Environment::get('isAjaxRequest')) { $this->objAjax = new Ajax(Input::post('action')); $this->objAjax->executePreActions(); } $strTable = Input::get('table'); $strField = Input::get('field'); // Define the current ID define('CURRENT_ID', Input::get('table') ? $this->Session->get('CURRENT_ID') : Input::get('id')); $this->loadDataContainer($strTable); $strDriver = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer']; $objDca = new $strDriver($strTable); // AJAX request if ($_POST && Environment::get('isAjaxRequest')) { $this->objAjax->executePostActions($objDca); } $this->Session->set('filePickerRef', \Environment::get('request')); $arrValues = array_filter(explode(',', Input::get('value'))); // Convert UUIDs to binary foreach ($arrValues as $k => $v) { // Can be a UUID or a path if (Validator::isStringUuid($v)) { $arrValues[$k] = String::uuidToBin($v); } } // Prepare the widget $class = $GLOBALS['BE_FFL']['fileSelector']; $objFileTree = new $class($class::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$strField], $strField, $arrValues, $strField, $strTable, $objDca)); $this->Template->main = $objFileTree->generate(); $this->Template->theme = Backend::getTheme(); $this->Template->base = Environment::get('base'); $this->Template->language = $GLOBALS['TL_LANGUAGE']; $this->Template->title = specialchars($GLOBALS['TL_LANG']['MSC']['filepicker']); $this->Template->charset = Config::get('characterSet'); $this->Template->addSearch = false; $this->Template->search = $GLOBALS['TL_LANG']['MSC']['search']; $this->Template->action = ampersand(Environment::get('request')); $this->Template->value = $this->Session->get('file_selector_search'); $this->Template->manager = $GLOBALS['TL_LANG']['MSC']['fileManager']; $this->Template->managerHref = 'contao/main.php?do=files&popup=1'; $this->Template->breadcrumb = $GLOBALS['TL_DCA']['tl_files']['list']['sorting']['breadcrumb']; Config::set('debugMode', false); $this->Template->output(); }
/** * Run the controller and parse the template */ public function run() { /** @var \BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_picker'); $objTemplate->main = ''; // Ajax request if ($_POST && \Environment::get('isAjaxRequest')) { $this->objAjax = new \Ajax(\Input::post('action')); $this->objAjax->executePreActions(); } $strTable = \Input::get('table'); $strField = \Input::get('field'); // Define the current ID define('CURRENT_ID', \Input::get('table') ? $this->Session->get('CURRENT_ID') : \Input::get('id')); $this->loadDataContainer($strTable); $strDriver = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer']; $objDca = new $strDriver($strTable); $objDca->field = $strField; // Set the active record if ($this->Database->tableExists($strTable)) { /** @var \Model $strModel */ $strModel = \Model::getClassFromTable($strTable); if (class_exists($strModel)) { $objModel = $strModel::findByPk(\Input::get('id')); if ($objModel !== null) { $objDca->activeRecord = $objModel; } } } // AJAX request if ($_POST && \Environment::get('isAjaxRequest')) { $this->objAjax->executePostActions($objDca); } $this->Session->set('filePickerRef', \Environment::get('request')); $arrValues = array_filter(explode(',', \Input::get('value'))); // Convert UUIDs to binary foreach ($arrValues as $k => $v) { // Can be a UUID or a path if (\Validator::isStringUuid($v)) { $arrValues[$k] = \StringUtil::uuidToBin($v); } } // Call the load_callback if (is_array($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['load_callback'])) { foreach ($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $arrValues = $this->{$callback[0]}->{$callback[1]}($arrValues, $objDca); } elseif (is_callable($callback)) { $arrValues = $callback($arrValues, $objDca); } } } /** @var \FileSelector $strClass */ $strClass = $GLOBALS['BE_FFL']['fileSelector']; /** @var \FileSelector $objFileTree */ $objFileTree = new $strClass($strClass::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$strField], $strField, $arrValues, $strField, $strTable, $objDca)); $objTemplate->main = $objFileTree->generate(); $objTemplate->theme = \Backend::getTheme(); $objTemplate->base = \Environment::get('base'); $objTemplate->language = $GLOBALS['TL_LANGUAGE']; $objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['filepicker']); $objTemplate->charset = \Config::get('characterSet'); $objTemplate->addSearch = false; $objTemplate->search = $GLOBALS['TL_LANG']['MSC']['search']; $objTemplate->action = ampersand(\Environment::get('request')); $objTemplate->value = $this->Session->get('file_selector_search'); $objTemplate->manager = $GLOBALS['TL_LANG']['MSC']['fileManager']; $objTemplate->managerHref = 'contao/main.php?do=files&popup=1'; $objTemplate->breadcrumb = $GLOBALS['TL_DCA']['tl_files']['list']['sorting']['breadcrumb']; if (\Input::get('switch')) { $objTemplate->switch = $GLOBALS['TL_LANG']['MSC']['pagePicker']; $objTemplate->switchHref = str_replace('contao/file.php', 'contao/page.php', ampersand(\Environment::get('request'))); } \Config::set('debugMode', false); $objTemplate->output(); }
/** * Find multiple files by UUID and a list of extensions * * @param array $arrUuids An array of file UUIDs * @param array $arrExtensions An array of file extensions * @param array $arrOptions An optional options array * * @return \Model\Collection|null A collection of models or null of there are no matching files */ public static function findMultipleByUuidsAndExtensions($arrUuids, $arrExtensions, array $arrOptions = array()) { if (!is_array($arrUuids) || empty($arrUuids) || !is_array($arrExtensions) || empty($arrExtensions)) { return null; } foreach ($arrExtensions as $k => $v) { if (!preg_match('/^[a-z0-9]{2,5}$/i', $v)) { unset($arrExtensions[$k]); } } $t = static::$strTable; foreach ($arrUuids as $k => $v) { // Convert UUIDs to binary if (\Validator::isStringUuid($v)) { $v = \String::uuidToBin($v); } $arrUuids[$k] = "UNHEX('" . bin2hex($v) . "')"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "{$t}.uuid!=" . implode(", {$t}.uuid!=", $arrUuids); } return static::findBy(array("{$t}.uuid IN(" . implode(",", $arrUuids) . ") AND {$t}.extension IN('" . implode("','", $arrExtensions) . "')"), null, $arrOptions); }
/** * Fix imageSort bug to add UUID support */ protected function updatePhotoalbums2AlbumImageSortField() { $objModel = $this->Database->prepare("SELECT id, imageSort FROM tl_photoalbums2_album")->execute(); while ($objModel->next()) { $arrItem = deserialize($objModel->imageSort); if (is_array($arrItem)) { foreach ($arrItem as $k => $v) { if (\Validator::isStringUuid($v)) { $arrItem[$k] = \String::uuidToBin($v); } } } $this->Database->prepare("UPDATE tl_photoalbums2_album %s WHERE id=?")->set(array('imageSort' => serialize($arrItem)))->execute($objModel->id); } }
/** * Adds a new item to the watchlist * @param WatchlistItemModel $objItem * @throws \Exception */ public function addItem(WatchlistItemModel $objItem) { // Throw an exception if there's no id: if (!\Validator::isStringUuid($objItem->uuid)) { throw new \Exception('The watchlist requires items with an unique file uuid.'); } $strUuid = $objItem->uuid; $objItem->uuid = \String::uuidToBin($objItem->uuid); // transform string to bin // Add or delete: if (isset($this->arrItems[$strUuid])) { \Input::setGet('act', WATCHLIST_ACT_DELETE); $this->deleteItem($strUuid); } else { $objItem = $objItem->save(); $this->arrItems[$strUuid] = $objItem; $this->arrIds[] = $strUuid; // Store the id, too! $this->addNotification(sprintf($GLOBALS['TL_LANG']['WATCHLIST']['notify_add_item'], $objItem->getTitle()), WATCHLIST_NOTIFICATION_ADD_ITEM); } }
/** * Validate the single file * @param mixed * @param string * @return mixed */ protected function validatorSingle($varFile, $strDestination) { $varOld = $varFile; // Move the temporary file if (!\Validator::isStringUuid($varFile) && is_file(TL_ROOT . '/' . $varFile)) { $varFile = $this->moveTemporaryFile($varFile, $strDestination); } // Convert uuid to binary format if (\Validator::isStringUuid($varFile)) { $varFile = \String::uuidToBin($varFile); } // Store in the mapper $this->arrFilesMapper[$varOld] = $varFile; return $varFile; }
/** * Manipulate the field definition for custom file trees. * * @param array $arrFieldDef The field definition to manipulate. * * @return void */ private function handleCustomFileTree(&$arrFieldDef) { if (strlen($this->get('file_uploadFolder'))) { // Set root path of file chooser depending on contao version. $objFile = null; if (\Validator::isStringUuid($this->get('file_uploadFolder')) || \Validator::isBinaryUuid($this->get('file_uploadFolder'))) { $objFile = \FilesModel::findByUuid($this->get('file_uploadFolder')); } // Check if we have a file. if ($objFile != null) { $arrFieldDef['eval']['path'] = $objFile->path; } else { // Fallback. $arrFieldDef['eval']['path'] = $this->get('file_uploadFolder'); } } if (strlen($this->get('file_validFileTypes'))) { $arrFieldDef['eval']['extensions'] = $this->get('file_validFileTypes'); } if (strlen($this->get('file_filesOnly'))) { $arrFieldDef['eval']['filesOnly'] = true; } }
/** * Validate a single file. * * @param mixed * @param string * @return mixed */ protected function validatorSingle($varFile, $strDestination) { // Move the temporary file if (!\Validator::isStringUuid($varFile) && is_file(TL_ROOT . '/' . $varFile)) { $varFile = $this->moveTemporaryFile($varFile, $strDestination); } // Convert uuid to binary format if (\Validator::isStringUuid($varFile)) { $varFile = \StringUtil::uuidToBin($varFile); } return $varFile; }