getPath() 공개 정적인 메소드

Get the relative path to an image
public static getPath ( string $src ) : string
$src string The image name or path
리턴 string The relative path
예제 #1
0
 /**
  * Compile global buttons from the table configuration array and return them as HTML
  *
  * @return string
  */
 protected function generateGlobalButtons()
 {
     if (!is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['global_operations'])) {
         return '';
     }
     $return = '';
     foreach ($GLOBALS['TL_DCA'][$this->strTable]['list']['global_operations'] as $k => $v) {
         if (\Input::get('act') == 'select' && !$v['showOnSelect']) {
             continue;
         }
         $v = is_array($v) ? $v : array($v);
         $label = is_array($v['label']) ? $v['label'][0] : $v['label'];
         $title = is_array($v['label']) ? $v['label'][1] : $v['label'];
         $attributes = $v['attributes'] != '' ? ' ' . ltrim($v['attributes']) : '';
         // Custom icon (see #5541)
         if ($v['icon']) {
             $v['class'] = trim($v['class'] . ' header_icon');
             // Add the theme path if only the file name is given
             if (strpos($v['icon'], '/') === false) {
                 $v['icon'] = \Image::getPath($v['icon']);
             }
             $attributes = sprintf('style="background-image:url(\'%s%s\')"', TL_ASSETS_URL, $v['icon']) . $attributes;
         }
         if ($label == '') {
             $label = $k;
         }
         if ($title == '') {
             $title = $label;
         }
         // Call a custom function instead of using the default button
         if (is_array($v['button_callback'])) {
             $this->import($v['button_callback'][0]);
             $return .= $this->{$v['button_callback'][0]}->{$v['button_callback'][1]}($v['href'], $label, $title, $v['class'], $attributes, $this->strTable, $this->root);
             continue;
         } elseif (is_callable($v['button_callback'])) {
             $return .= $v['button_callback']($v['href'], $label, $title, $v['class'], $attributes, $this->strTable, $this->root);
             continue;
         }
         $return .= '<a href="' . $this->addToUrl($v['href']) . '" class="' . $v['class'] . '" title="' . \StringUtil::specialchars($title) . '"' . $attributes . '>' . $label . '</a> ';
     }
     return $return;
 }
예제 #2
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 = \StringUtil::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 = \StringUtil::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 ? '&amp;' : '?') . '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'] = \StringUtil::specialchars($objFile->basename);
             }
             $arrEnclosures[] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'title' => \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => static::getReadableSize($objFile->filesize), 'icon' => \Image::getPath($objFile->icon), 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname, 'enclosure' => $objFiles->path);
         }
     }
     $objTemplate->enclosure = $arrEnclosures;
 }