getMetaData() public static method

Get the meta data from a serialized string
public static getMetaData ( string $strData, string $strLanguage ) : array
$strData string
$strLanguage string
return array
Exemplo n.º 1
0
 /**
  * Add enclosures to a template
  *
  * @param object $objTemplate The template object to add the enclosures to
  * @param array  $arrItem     The element or module as array
  * @param string $strKey      The name of the enclosures field in $arrItem
  */
 public static function addEnclosuresToTemplate($objTemplate, $arrItem, $strKey = 'enclosure')
 {
     $arrEnclosures = deserialize($arrItem[$strKey]);
     if (!is_array($arrEnclosures) || empty($arrEnclosures)) {
         return;
     }
     $objFiles = \FilesModel::findMultipleByUuids($arrEnclosures);
     if ($objFiles === null) {
         return;
     }
     $file = \Input::get('file', true);
     // Send the file to the browser and do not send a 404 header (see #5178)
     if ($file != '') {
         while ($objFiles->next()) {
             if ($file == $objFiles->path) {
                 static::sendFileToBrowser($file);
             }
         }
         $objFiles->reset();
     }
     /** @var \PageModel $objPage */
     global $objPage;
     $arrEnclosures = array();
     $allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload')));
     // Add download links
     while ($objFiles->next()) {
         if ($objFiles->type == 'file') {
             if (!in_array($objFiles->extension, $allowedDownload) || !is_file(TL_ROOT . '/' . $objFiles->path)) {
                 continue;
             }
             $objFile = new \File($objFiles->path);
             $strHref = \Environment::get('request');
             // Remove an existing file parameter (see #5683)
             if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
                 $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
             }
             $strHref .= (strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFiles->path);
             $arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->language);
             if (empty($arrMeta) && $objPage->rootFallbackLanguage !== null) {
                 $arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
             }
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = specialchars($objFile->basename);
             }
             $arrEnclosures[] = array('link' => $arrMeta['title'], 'filesize' => static::getReadableSize($objFile->filesize), 'title' => specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'href' => $strHref, 'enclosure' => $objFiles->path, 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'extension' => $objFile->extension, 'meta' => $arrMeta);
         }
     }
     $objTemplate->enclosure = $arrEnclosures;
 }