BcBaserHelper::_getThemeImage PHP Method

_getThemeImage() protected method

テーマ画像を取得する
protected _getThemeImage ( string $name, array $options = [] ) : string
$name string テーマ画像名( log or main_image )
$options array オプション(初期値 :array()) - `num` : main_imageの場合の番号指定(初期値 : '') - `thumb`: サムネイルを取得する(初期値 : false) - `class`: 画像に設定する class 属性(初期値 : '') - `popup`: ポップアップリンクを指定(初期値 : false) - `alt` : 画像に設定する alt 属性。リンクの title 属性にも設定される。(初期値 : テーマ設定で設定された値) - `link` : リンク先URL。popup を true とした場合、オリジナルの画像へのリンクとなる。(初期値 : テーマ設定で設定された値) - `maxWidth : 最大横幅(初期値 : '') - `maxHeight: 最大高さ(初期値 : '') - `width : 最大横幅(初期値 : '') - `height: 最大高さ(初期値 : '')
return string $tag テーマ画像のHTMLタグ
    protected function _getThemeImage($name, $options = array())
    {
        $ThemeConfig = ClassRegistry::init('ThemeConfig');
        $data = $ThemeConfig->findExpanded();
        $url = $imgPath = $uploadUrl = $uploadThumbUrl = $originUrl = '';
        $thumbSuffix = '_thumb';
        $dir = WWW_ROOT . 'files' . DS . 'theme_configs' . DS;
        $themeDir = $path = getViewPath() . 'img' . DS;
        $num = '';
        if (!empty($options['num'])) {
            $num = '_' . $options['num'];
        }
        $options = array_merge(array('thumb' => false, 'class' => '', 'popup' => false, 'alt' => $data[$name . '_alt' . $num], 'link' => $data[$name . '_link' . $num], 'maxWidth' => '', 'maxHeight' => '', 'width' => '', 'height' => ''), $options);
        $name = $name . $num;
        if ($data[$name]) {
            $pathinfo = pathinfo($data[$name]);
            $uploadPath = $dir . $data[$name];
            $uploadThumbPath = $dir . $pathinfo['filename'] . $thumbSuffix . '.' . $pathinfo['extension'];
            $uploadUrl = '/files/theme_configs/' . $data[$name];
            $uploadThumbUrl = '/files/theme_configs/' . $pathinfo['filename'] . $thumbSuffix . '.' . $pathinfo['extension'];
        }
        if ($data[$name]) {
            if (!$options['thumb']) {
                if (file_exists($uploadPath)) {
                    $imgPath = $uploadPath;
                    $url = $uploadUrl;
                }
            } else {
                if (file_exists($uploadThumbPath)) {
                    $imgPath = $uploadThumbPath;
                    $url = $uploadThumbUrl;
                }
            }
            $originUrl = $uploadUrl;
        }
        if (!$url) {
            $exts = array('png', 'jpg', 'gif');
            foreach ($exts as $ext) {
                if (file_exists($themeDir . $name . '.' . $ext)) {
                    $url = '/theme/' . $this->siteConfig['theme'] . '/img/' . $name . '.' . $ext;
                    $imgPath = $themeDir . $name . '.' . $ext;
                    $originUrl = $url;
                }
            }
        }
        if (!$url) {
            return '';
        }
        $imgOptions = array();
        if ($options['class']) {
            $imgOptions['class'] = $options['class'];
        }
        if ($options['alt']) {
            $imgOptions['alt'] = $options['alt'];
        }
        if ($options['maxWidth'] || $options['maxHeight']) {
            $imginfo = getimagesize($imgPath);
            $widthRate = $heightRate = 0;
            if ($options['maxWidth']) {
                $widthRate = $imginfo[0] / $options['maxWidth'];
            }
            if ($options['maxHeight']) {
                $heightRate = $imginfo[1] / $options['maxHeight'];
            }
            if ($widthRate > $heightRate) {
                if ($options['maxWidth'] && $imginfo[0] > $options['maxWidth']) {
                    $imgOptions['width'] = $options['maxWidth'];
                }
            } else {
                if ($options['maxHeight'] && $imginfo[1] > $options['maxHeight']) {
                    $imgOptions['height'] = $options['maxHeight'];
                }
            }
        }
        if ($options['width']) {
            $imgOptions['width'] = $options['width'];
        }
        if ($options['height']) {
            $imgOptions['height'] = $options['height'];
        }
        $tag = $this->getImg($url, $imgOptions);
        if ($options['link'] || $options['popup']) {
            $linkOptions = array();
            if ($options['popup']) {
                $linkOptions['rel'] = 'colorbox';
                $link = $originUrl;
            } elseif ($options['link']) {
                $link = $options['link'];
            }
            if ($options['alt']) {
                $linkOptions['title'] = $options['alt'];
            }
            $tag = $this->getLink($tag, $link, $linkOptions);
        }
        return $tag;
    }