当前位置: 首页>>代码示例>>PHP>>正文


PHP StringUtil::uuidToBin方法代码示例

本文整理汇总了PHP中StringUtil::uuidToBin方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::uuidToBin方法的具体用法?PHP StringUtil::uuidToBin怎么用?PHP StringUtil::uuidToBin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringUtil的用法示例。


在下文中一共展示了StringUtil::uuidToBin方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onCreate

 public function onCreate($strTable, $insertID, $arrSet, \DataContainer $dc)
 {
     if (($objModel = SubmissionArchiveModel::findByPk($insertID)) === null) {
         return;
     }
     if (($uuid = Submissions::getDefaultAttachmentSRC()) !== null && \Validator::isUuid($uuid)) {
         $objModel->attachmentUploadFolder = class_exists('Contao\\StringUtil') ? \StringUtil::uuidToBin($uuid) : \String::uuidToBin($uuid);
     }
     $objModel->save();
 }
开发者ID:heimrichhannot,项目名称:contao-submissions,代码行数:10,代码来源:SubmissionArchiveBackend.php

示例2: findByUuidAndPidAndUrl

 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);
 }
开发者ID:heimrichhannot,项目名称:contao-filecredits,代码行数:10,代码来源:FileCreditModel.php

示例3: generate

    /**
     * Import images and other media file for products
     *
     * @return string
     */
    public function generate()
    {
        $objTree = new \FileTree(\FileTree::getAttributesFromDca($GLOBALS['TL_DCA']['tl_iso_product']['fields']['source'], 'source', null, 'source', 'tl_iso_product'));
        // Import assets
        if (\Input::post('FORM_SUBMIT') == 'tl_iso_product_import' && \Input::post('source') != '') {
            $objFolder = \FilesModel::findByUuid(\StringUtil::uuidToBin(\Input::post('source')));
            if (null !== $objFolder) {
                $this->importFromPath($objFolder->path);
            }
        }
        // Return form
        return '
<div id="tl_buttons">
<a href="' . ampersand(str_replace('&key=import', '', \Environment::get('request'))) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBT']) . '">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>

<h2 class="sub_headline">' . $GLOBALS['TL_LANG']['tl_iso_product']['import'][1] . '</h2>

<div class="tl_message"><div class="tl_info">' . $GLOBALS['TL_LANG']['tl_iso_product']['importAssetsDescr'] . '</div></div>
' . \Message::generate() . '

<form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_iso_product_import" class="tl_form" method="post">
<div class="tl_formbody_edit iso_importassets">
<input type="hidden" name="FORM_SUBMIT" value="tl_iso_product_import">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">

<div class="tl_tbox block">
  <h3><label for="source">' . $GLOBALS['TL_LANG']['tl_iso_product']['source'][0] . '</label></h3>
  ' . $objTree->generate() . (strlen($GLOBALS['TL_LANG']['tl_iso_product']['source'][1]) ? '
  <p class="tl_help">' . $GLOBALS['TL_LANG']['tl_iso_product']['source'][1] . '</p>' : '') . '
</div>

</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
<input type="submit" name="save" id="save" class="tl_submit" alt="import product assets" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_iso_product']['import'][0]) . '">
</div>

</div>
</form>';
    }
开发者ID:ralfhartmann,项目名称:isotope_core,代码行数:48,代码来源:AssetImport.php

示例4: validator

 /**
  * Return an array if the "multiple" attribute is set
  *
  * @param mixed $varInput
  *
  * @return mixed
  */
 protected function validator($varInput)
 {
     // Store the order value
     if ($this->orderField != '') {
         $arrNew = array_map('StringUtil::uuidToBin', explode(',', \Input::post($this->strOrderName)));
         // Only proceed if the value has changed
         if ($arrNew !== $this->{$this->orderField}) {
             $this->Database->prepare("UPDATE {$this->strTable} SET tstamp=?, {$this->orderField}=? WHERE id=?")->execute(time(), serialize($arrNew), $this->activeRecord->id);
             $this->objDca->createNewVersion = true;
             // see #6285
         }
     }
     // Return the value as usual
     if ($varInput == '') {
         if ($this->mandatory) {
             $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['mandatory'], $this->strLabel));
         }
         return '';
     } elseif (strpos($varInput, ',') === false) {
         $varInput = \StringUtil::uuidToBin($varInput);
         return $this->multiple ? array($varInput) : $varInput;
     } else {
         $arrValue = array_filter(explode(',', $varInput));
         return $this->multiple ? array_map('StringUtil::uuidToBin', $arrValue) : \StringUtil::uuidToBin($arrValue[0]);
     }
 }
开发者ID:eknoes,项目名称:core,代码行数:33,代码来源:FileTree.php

示例5: run

 /**
  * 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&amp;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();
 }
开发者ID:bytehead,项目名称:contao-core,代码行数:80,代码来源:BackendFile.php

示例6: findMultipleByUuidsAndExtensions

 /**
  * 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|FilesModel[]|FilesModel|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 = \StringUtil::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);
 }
开发者ID:qzminski,项目名称:contao-core-bundle,代码行数:32,代码来源:FilesModel.php

示例7: getImageObject

 /**
  * Get an image object from id/uuid and an optional size configuration
  *
  * @param  int|string   $id         ID, UUID string or binary
  * @param  string|array $size       [width, height, mode] optionally serialized
  * @param  int          $maxSize    Gets passed to addImageToTemplate as $intMaxWidth
  * @param  string       $lightboxId Gets passed to addImageToTemplate as $strLightboxId
  * @param  array        $item       Gets merged and passed to addImageToTemplate as $arrItem
  * @return object                   Image object (similar as addImageToTemplate)
  */
 public function getImageObject($id, $size = null, $maxSize = null, $lightboxId = null, $item = array())
 {
     global $objPage;
     if (!$id) {
         return null;
     }
     if (strlen($id) === 36) {
         $id = \StringUtil::uuidToBin($id);
     }
     if (strlen($id) === 16) {
         $image = \FilesModel::findByUuid($id);
     } else {
         $image = \FilesModel::findByPk($id);
     }
     if (!$image) {
         return null;
     }
     try {
         $file = new \File($image->path, true);
         if (!$file->exists()) {
             return null;
         }
     } catch (\Exception $e) {
         return null;
     }
     $imageMeta = $this->getMetaData($image->meta, $objPage->language);
     if (is_string($size) && trim($size)) {
         $size = deserialize($size);
     }
     if (!is_array($size)) {
         $size = array();
     }
     $size[0] = isset($size[0]) ? $size[0] : 0;
     $size[1] = isset($size[1]) ? $size[1] : 0;
     $size[2] = isset($size[2]) ? $size[2] : 'crop';
     $image = array('id' => $image->id, 'uuid' => isset($image->uuid) ? $image->uuid : null, 'name' => $file->basename, 'singleSRC' => $image->path, 'size' => serialize($size), 'alt' => $imageMeta['title'], 'imageUrl' => $imageMeta['link'], 'caption' => $imageMeta['caption']);
     $image = array_merge($image, $item);
     $imageObject = new \FrontendTemplate('rsce_image_object');
     $this->addImageToTemplate($imageObject, $image, $maxSize, $lightboxId);
     $imageObject = (object) $imageObject->getData();
     if (empty($imageObject->src)) {
         $imageObject->src = $imageObject->singleSRC;
     }
     return $imageObject;
 }
开发者ID:madeyourday,项目名称:contao-rocksolid-custom-elements,代码行数:55,代码来源:CustomElement.php

示例8: moveTempFile

 /**
  * Move temp files. If DBAFS support is enabled add entries to the dbafs.
  *
  * @CtoCommunication Enable
  *
  * @param  array   $arrFileList List with files for moving.
  *
  * @param  boolean $blnIsDbafs  Flag if we have to change the dbafs system.
  *
  * @return array The list with some more information about the moving of the file.
  */
 public function moveTempFile($arrFileList, $blnIsDbafs)
 {
     foreach ($arrFileList as $key => $value) {
         try {
             $blnMovedFile = false;
             $strTempFile = $this->objSyncCtoHelper->standardizePath($GLOBALS['SYC_PATH']['tmp'], "sync", $value["path"]);
             // Check if the tmp file exists.
             if (!file_exists(TL_ROOT . DIRECTORY_SEPARATOR . $strTempFile)) {
                 $arrFileList[$key]['saved'] = false;
                 $arrFileList[$key]['error'] = sprintf($GLOBALS['TL_LANG']['ERR']['unknown_file'], $strTempFile);
                 $arrFileList[$key]['skipreasons'] = $GLOBALS['TL_LANG']['ERR']['missing_file_information'];
                 continue;
             }
             // Generate the folder if not already there.
             $strFolderPath = dirname($value["path"]);
             if ($strFolderPath != ".") {
                 $objFolder = new Folder($strFolderPath);
                 unset($objFolder);
             }
             // Build folders.
             $strFileSource = $this->objSyncCtoHelper->standardizePath($GLOBALS['SYC_PATH']['tmp'], "sync", $value["path"]);
             $strFileDestination = $this->objSyncCtoHelper->standardizePath($value["path"]);
             // DBAFS support. Check if we have the file already in the locale dbafs system.
             if ($blnIsDbafs) {
                 // Get the information from the dbafs.
                 /**  @var \Model $objLocaleData */
                 $objLocaleData = \FilesModel::findByPath($strFileDestination);
                 // If we have no entry in the dbafs just overwrite the current file and add the entry to the dbafs.
                 if ($objLocaleData == null) {
                     // Move file.
                     $blnMovedFile = $this->objFiles->copy($strFileSource, $strFileDestination);
                     // If success add file to the database.
                     if ($blnMovedFile) {
                         // First add it to the dbafs.
                         $objLocaleData = \Dbafs::addResource($strFileDestination);
                         // PHP 7 compatibility
                         // See #309 (https://github.com/contao/core-bundle/issues/309)
                         if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) {
                             $objLocaleData->uuid = \StringUtil::uuidToBin($value['tl_files']['uuid']);
                         } else {
                             $objLocaleData->uuid = \String::uuidToBin($value['tl_files']['uuid']);
                         }
                         $objLocaleData->meta = $value['tl_files']['meta'];
                         $objLocaleData->save();
                         // Add a status report for debugging and co.
                         $arrFileList[$key]['dbafs']['msg'] = 'Moved file and add to database.';
                         $arrFileList[$key]['dbafs']['state'] = SyncCtoEnum::DBAFS_CREATE;
                     }
                 } else {
                     // PHP 7 compatibility
                     // See #309 (https://github.com/contao/core-bundle/issues/309)
                     if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) {
                         // Get the readable UUID for the work.
                         $strLocaleUUID = \StringUtil::binToUuid($objLocaleData->uuid);
                     } else {
                         // Get the readable UUID for the work.
                         $strLocaleUUID = \String::binToUuid($objLocaleData->uuid);
                     }
                     // Okay it seems we have already a file with this values.
                     if ($strLocaleUUID == $value['tl_files']['uuid']) {
                         // Move file.
                         $blnMovedFile = $this->objFiles->copy($strFileSource, $strFileDestination);
                         // If success add file to the database.
                         if ($blnMovedFile) {
                             $objLocaleData->hash = $value['checksum'];
                             $objLocaleData->meta = $value['tl_files']['meta'];
                             $objLocaleData->save();
                             // Add a status report for debugging and co.
                             $arrFileList[$key]['dbafs']['msg'] = 'UUID same no problem found. Update database with new hash.';
                             $arrFileList[$key]['dbafs']['state'] = SyncCtoEnum::DBAFS_SAME;
                         }
                     } elseif ($strLocaleUUID != $value['tl_files']['uuid']) {
                         // Get information about the current file information.
                         $arrDestinationInformation = pathinfo($strFileDestination);
                         // Try to rename it to _1 or _2 and so on.
                         $strNewDestinationName = null;
                         $intFileNumber = 1;
                         for ($i = 1; $i < 100; $i++) {
                             $strNewDestinationName = sprintf('%s' . DIRECTORY_SEPARATOR . '%s_%s.%s', $arrDestinationInformation['dirname'], $arrDestinationInformation['filename'], $i, $arrDestinationInformation['extension']);
                             if (!file_exists(TL_ROOT . DIRECTORY_SEPARATOR . $strNewDestinationName)) {
                                 $intFileNumber = $i;
                                 break;
                             }
                         }
                         // Move the current file to another name, that we have space for the new one.
                         $this->objFiles->copy($strFileDestination, $strNewDestinationName);
                         $objRenamedLocaleData = \Dbafs::moveResource($strFileDestination, $strNewDestinationName);
                         // Move the tmp file.
                         $blnMovedFile = $this->objFiles->copy($strFileSource, $strFileDestination);
//.........这里部分代码省略.........
开发者ID:menatwork,项目名称:synccto,代码行数:101,代码来源:SyncCtoFiles.php

示例9: dispatchAjaxRequest

 /**
  * Dispatch an AJAX request
  * @param string
  * @param \DataContainer
  */
 public function dispatchAjaxRequest($strAction, \DataContainer $dc)
 {
     switch ($strAction) {
         // Upload the file
         /** @noinspection PhpMissingBreakStatementInspection */
         case 'fineuploader_upload':
             $arrData['strTable'] = $dc->table;
             $arrData['id'] = $dc->id;
             // @todo what was $this->strAjaxName for?
             $arrData['name'] = \Input::post('name');
             /** @var FineUploaderWidget $objWidget */
             $objWidget = new $GLOBALS['BE_FFL']['fineUploader']($arrData, $dc);
             $strFile = $objWidget->validateUpload();
             if ($objWidget->hasErrors()) {
                 $arrResponse = array('success' => false, 'error' => $objWidget->getErrorAsString(), 'preventRetry' => true);
             } else {
                 $arrResponse = array('success' => true, 'file' => $strFile);
             }
             $response = new \Haste\Http\Response\JsonResponse($arrResponse);
             $response->send();
             // no break, response exits script
             // Reload the widget
         // no break, response exits script
         // Reload the widget
         case 'fineuploader_reload':
             $intId = \Input::get('id');
             $strField = $dc->field = \Input::post('name');
             // Handle the keys in "edit multiple" mode
             if (\Input::get('act') == 'editAll') {
                 $intId = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', $strField);
                 $strField = preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $strField);
             }
             // The field does not exist
             if (!isset($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField])) {
                 System::log('Field "' . $strField . '" does not exist in DCA "' . $dc->table . '"', __METHOD__, TL_ERROR);
                 header('HTTP/1.1 400 Bad Request');
                 die('Bad Request');
             }
             $objRow = null;
             $varValue = null;
             // Load the value
             if ($GLOBALS['TL_DCA'][$dc->table]['config']['dataContainer'] == 'File') {
                 $varValue = $GLOBALS['TL_CONFIG'][$strField];
             } elseif ($intId > 0 && Database::getInstance()->tableExists($dc->table)) {
                 $objRow = Database::getInstance()->prepare("SELECT * FROM " . $dc->table . " WHERE id=?")->execute($intId);
                 // The record does not exist
                 if ($objRow->numRows < 1) {
                     System::log('A record with the ID "' . $intId . '" does not exist in table "' . $dc->table . '"', __METHOD__, TL_ERROR);
                     header('HTTP/1.1 400 Bad Request');
                     die('Bad Request');
                 }
                 $varValue = $objRow->{$strField};
                 $dc->activeRecord = $objRow;
             }
             // Call the load_callback
             if (is_array($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['load_callback'])) {
                 foreach ($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['load_callback'] as $callback) {
                     if (is_array($callback)) {
                         $varValue = System::importStatic($callback[0])->{$callback}[1]($varValue, $dc);
                     } elseif (is_callable($callback)) {
                         $varValue = $callback($varValue, $dc);
                     }
                 }
             }
             $varValue = \Input::post('value', true);
             // Convert the selected values
             if ($varValue != '') {
                 $varValue = trimsplit(',', $varValue);
                 foreach ($varValue as $k => $v) {
                     if (\Validator::isUuid($v) && !is_file(TL_ROOT . '/' . $v)) {
                         $varValue[$k] = \StringUtil::uuidToBin($v);
                     }
                 }
                 $varValue = serialize($varValue);
             }
             // Build the attributes based on the "eval" array
             $arrAttribs = $GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['eval'];
             $arrAttribs['id'] = $dc->field;
             $arrAttribs['name'] = $dc->field;
             $arrAttribs['value'] = $varValue;
             $arrAttribs['strTable'] = $dc->table;
             $arrAttribs['strField'] = $strField;
             $arrAttribs['activeRecord'] = $dc->activeRecord;
             $objWidget = new $GLOBALS['BE_FFL']['fineUploader']($arrAttribs);
             $response = new \Haste\Http\Response\HtmlResponse($objWidget->parse());
             $response->send();
     }
 }
开发者ID:terminal42,项目名称:contao-fineuploader,代码行数:93,代码来源:FineUploaderAjax.php

示例10: loadCallback

 /**
  * Field load callback
  *
  * Finds the current value for the field
  *
  * @param  string         $value Current value
  * @param  \DataContainer $dc    Data container
  * @return string                Current value for the field
  */
 public function loadCallback($value, $dc)
 {
     if ($value !== null) {
         return $value;
     }
     $value = $this->getNestedValue($dc->field);
     if ($value === null && isset($GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['default'])) {
         $value = $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['default'];
     }
     if (version_compare(VERSION, '3.2', '>=') && $value && ($GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['inputType'] === 'fileTree' || $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['inputType'] === 'fineUploader')) {
         // Multiple files
         if (substr($value, 0, 2) === 'a:') {
             $value = serialize(array_map(function ($value) {
                 if (strlen($value) === 36) {
                     $value = \StringUtil::uuidToBin($value);
                 } else {
                     if (is_numeric($value) && ($file = \FilesModel::findByPk($value))) {
                         // Convert 3.1 format into 3.2 format
                         $value = $file->uuid;
                     }
                 }
                 return $value;
             }, deserialize($value)));
         } else {
             if (strlen($value) === 36) {
                 $value = \StringUtil::uuidToBin($value);
             } else {
                 if (is_numeric($value) && ($file = \FilesModel::findByPk($value))) {
                     // Convert 3.1 format into 3.2 format
                     $value = $file->uuid;
                 }
             }
         }
     }
     return $value;
 }
开发者ID:madeyourday,项目名称:contao-rocksolid-custom-elements,代码行数:45,代码来源:CustomElements.php

示例11: validatorSingle

 /**
  * 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;
 }
开发者ID:terminal42,项目名称:contao-fineuploader,代码行数:19,代码来源:FineUploaderBase.php

示例12: validator

 public function validator($varInput)
 {
     if ($varInput == '' || $varInput == '[]') {
         $varInput = '[]';
     }
     $arrFiles = json_decode($varInput);
     $arrDeleted = json_decode($this->getPost('deleted_' . $this->strName));
     $blnEmpty = false;
     if (is_array($arrFiles) && is_array($arrDeleted)) {
         $blnEmpty = empty(array_diff($arrFiles, $arrDeleted));
     }
     if ($this->mandatory && $blnEmpty) {
         if ($this->strLabel == '') {
             $this->addError($GLOBALS['TL_LANG']['ERR']['mdtryNoLabel']);
         } else {
             $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['mandatory'], $this->strLabel));
         }
         // do no delete last file if mandatory
         return;
     }
     $this->deleteScheduledFiles($arrDeleted);
     if (is_array($arrFiles)) {
         foreach ($arrFiles as $k => $v) {
             if (!\Validator::isUuid($v)) {
                 $this->addError($GLOBALS['TL_LANG']['ERR']['invalidUuid']);
                 return;
             }
             // cleanup non existing files on save
             if (($objFile = Files::getFileFromUuid($v)) === null || !$objFile->exists()) {
                 unset($arrFiles[$k]);
                 continue;
             }
             $arrFiles[$k] = \StringUtil::uuidToBin($v);
         }
     } else {
         if (!\Validator::isUuid($arrFiles)) {
             $this->addError($GLOBALS['TL_LANG']['ERR']['invalidUuid']);
             return;
         }
         // cleanup non existing files on save
         if (($objFile = Files::getFileFromUuid($arrFiles)) === null || !$objFile->exists()) {
             return;
         }
         $arrFiles = \StringUtil::uuidToBin($arrFiles);
     }
     return $arrFiles;
 }
开发者ID:heimrichhannot,项目名称:contao-multifileupload,代码行数:47,代码来源:FormMultiFileUpload.php

示例13: onsubmitCallback

 public function onsubmitCallback(\DataContainer $dc)
 {
     if ($dc->id && substr($dc->id, -5) === '.base') {
         $type = 'html';
         if (substr($dc->id, -9, 4) === '.css') {
             $type = 'css';
         }
         list($data, $template) = static::parseBaseFile(file_get_contents(TL_ROOT . '/' . $dc->id), $type);
         // Check if parsing the file was successful
         if (empty($data) || empty($data['fileHash']) || empty($data['templateVars']) || !trim($template)) {
             $this->redirect('contao/main.php?act=error');
             return;
         }
         if (\Input::post('variations') && substr(\Input::post('variations'), 0, 9) === 'variation') {
             $variation = (int) substr(\Input::post('variations'), 9);
             foreach ($data['templateVars'] as $key => $var) {
                 if (isset($data['templateVars'][$key]['defaultValues'][$variation])) {
                     $data['templateVars'][$key]['value'] = $data['templateVars'][$key]['defaultValues'][$variation];
                 } elseif (isset($data['templateVars'][$key]['defaultValues'][0])) {
                     $data['templateVars'][$key]['value'] = $data['templateVars'][$key]['defaultValues'][0];
                 }
             }
         } else {
             foreach ($data['templateVars'] as $key => $var) {
                 if (\Input::post($key) === null) {
                     continue;
                 }
                 $value = \Input::post($key);
                 if ($data['templateVars'][$key]['type'] === 'color') {
                     if (strlen($value) === 6) {
                         $value = '#' . strtolower($value);
                     } else {
                         $value = $data['templateVars'][$key]['value'];
                     }
                 } elseif ($data['templateVars'][$key]['type'] === 'boolean') {
                     $value = (bool) $value;
                 } elseif ($data['templateVars'][$key]['type'] === 'image') {
                     $file = null;
                     if (trim($value)) {
                         if (version_compare(VERSION, '3.2', '<')) {
                             $file = \FilesModel::findByPk($value);
                         } else {
                             $file = \FilesModel::findByUuid(\StringUtil::uuidToBin($value));
                         }
                     }
                     if ($file) {
                         $value = substr($file->path, strlen($GLOBALS['TL_CONFIG']['uploadPath']) + 1);
                     } else {
                         $value = '';
                     }
                 } elseif ($data['templateVars'][$key]['type'] === 'background-image') {
                     $file = null;
                     if (trim($value)) {
                         if (version_compare(VERSION, '3.2', '<')) {
                             $file = \FilesModel::findByPk($value);
                         } else {
                             $file = \FilesModel::findByUuid(\StringUtil::uuidToBin($value));
                         }
                     }
                     if ($file) {
                         $value = 'url("' . static::getRelativePath(dirname($dc->id), $file->path) . '")';
                     } else {
                         $value = 'none';
                     }
                 } elseif ($data['templateVars'][$key]['type'] === 'length') {
                     if (is_array($value)) {
                         $value['value'] = empty($value['value']) ? '0' : $value['value'];
                         $value['unit'] = empty($value['unit']) ? '' : $value['unit'];
                         $value = trim($value['value']) . trim($value['unit']);
                     } else {
                         if (is_string($value) && trim($value)) {
                             $value = trim($value);
                         } else {
                             $value = '0';
                         }
                     }
                 } elseif ($data['templateVars'][$key]['type'] === 'set') {
                     if (count($value) === 1) {
                         $emptyValues = true;
                         foreach ($value[0] as $setValue) {
                             if ($setValue) {
                                 $emptyValues = false;
                                 break;
                             }
                         }
                         if ($emptyValues) {
                             $value = array();
                         }
                     }
                 }
                 $data['templateVars'][$key]['value'] = $value;
             }
         }
         $rendered = $this->renderTemplate($template, $data, $type);
         if (!$rendered) {
             $this->log('Parse error in Theme Assistant template "' . $dc->id . '"', 'MadeYourDay\\Contao\\ThemeAssistant::onsubmitCallback', TL_ERROR);
             return $this->redirect('contao/main.php?act=error');
         }
         file_put_contents(TL_ROOT . '/' . substr($dc->id, 0, -5), $rendered);
         $data['fileHash'] = md5_file(TL_ROOT . '/' . substr($dc->id, 0, -5));
//.........这里部分代码省略.........
开发者ID:madeyourday,项目名称:contao-rocksolid-theme-assistant,代码行数:101,代码来源:ThemeAssistant.php


注:本文中的StringUtil::uuidToBin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。