/** * Предпросмотр вложений со ссылками на оригиналы * * @param $name * @param CModel $model * @param int $size * @param bool $addLinkToOriginal */ public static function activeAttachPreview($name, CModel $model, $addLinkToOriginal = false, $size = 100) { $attributes = $model->fieldsProperty(); $display = false; if (array_key_exists($name, $attributes)) { $field = $attributes[$name]; if ($field["type"] == FIELD_UPLOADABLE) { $storage = $field["upload_dir"]; $file = $model->{$name}; if ($file !== "") { if (file_exists($storage . $file)) { $display = true; } } } } if ($display) { // заменяем обратный слэш в адресе на прямой $linkWithBackSlash = CUtils::strRight($storage, CORE_CWD) . $file; $link = str_replace('\\', '/', $linkWithBackSlash); $icon = ""; if (CUtils::isImage($storage . $file)) { // показываем превью изображения $icon = WEB_ROOT . "_modules/_thumbnails/?src=" . $link . "&w=" . $size; } else { // показываем значок типа документа $filetype = CUtils::getMimetype($storage . $file); if (file_exists(CORE_CWD . CORE_DS . "images" . CORE_DS . ICON_THEME . CORE_DS . "64x64" . CORE_DS . "mimetypes" . CORE_DS . $filetype . ".png")) { $icon = WEB_ROOT . "images/" . ICON_THEME . "/64x64/mimetypes/" . $filetype . ".png"; } else { $icon = WEB_ROOT . "images/" . ICON_THEME . "/64x64/mimetypes/unknown.png"; } } if ($addLinkToOriginal) { echo '<a href="' . WEB_ROOT . '' . $link . '" target="_blank"'; if (CUtils::isImage($storage . $file)) { echo ' class="image_clearboxy"'; } echo '>'; } echo '<img src="' . $icon . '" />'; if ($addLinkToOriginal) { echo '</a>'; } } if (!self::$_clearboxInit) { self::$_clearboxInit = true; ?> <script> jQuery(document).ready(function(){ jQuery("a.image_clearboxy").colorbox({ maxHeight: "100%", title: function(){ var url = $(this).attr('href'); return '<a href="' + url + '" target="_blank">Открыть в полном размере</a>'; } }); }); </script> <?php } }