/** * Returns the path to the thumbnail image * * If a thumbnail does not already exist, it is generated, * written to disk and then the new path is returned * * @param int $width * @param int $height * @param string $thumbnail_type * @return mixed|string */ public function getThumbnailPath($width = 80, $height = 0, $thumbnail_type = '') { // If signiture height setting is omitted, create a square if (!$height) { $height = $width; } // get thumbail generation info on the doc module configuration. if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $thumbnail_type = 'ratio'; } // Define thumbnail information $thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($this->unique_identifier, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); // If thumbnail was already created, return path to it if (is_file($thumbnail_file)) { return $thumbnail_file; } // Retrieve info about original image: path and extension $source_file = $this->full_image_path; $ext = pathinfo($source_file, PATHINFO_EXTENSION); // Create thumbnail $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, $ext, $thumbnail_type); if ($output) { return $thumbnail_file; } else { return ''; } }
function getThumbnailByUrl($image_url, $width = 80, $height = 0, $thumbnail_type = '') { if (!$height) { $height = $width; } if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $config = $GLOBALS['__document_config__']; if (!$config) { $oDocumentModel = getModel('document'); $config = $oDocumentModel->getDocumentConfig(); $GLOBALS['__document_config__'] = $config; } $thumbnail_type = $config->thumbnail_type; } if (!is_dir('./files/thumbnails/magiccontent_thumbnail')) { FileHandler::makeDir('./files/thumbnails/magiccontent_thumbnail'); } $thumbnail_path = sprintf('files/thumbnails/magiccontent_thumbnail/%s', base64_encode($image_url)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; if (file_exists($thumbnail_file)) { if (filesize($thumbnail_file) < 1) { return false; } else { return $thumbnail_url; } } $tmp_file = sprintf('./files/cache/tmp/%s', md5(rand(111111, 999999) . $image_url)); if (!is_dir('./files/cache/tmp')) { FileHandler::makeDir('./files/cache/tmp'); } if (!preg_match('/^(http|https):\\/\\//i', $image_url)) { $image_url = Context::getRequestUri() . $image_url; } FileHandler::getRemoteFile($image_url, $tmp_file); if (!file_exists($tmp_file)) { return false; } else { list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file); if (!in_array($_t, array(1, 2, 3, 6, 7, 8))) { FileHandler::writeFile($thumbnail_file, '', 'w'); return false; } $source_file = $tmp_file; } $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); FileHandler::removeFile($source_file); if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return false; }
private function insertProfileImageFromUrl($member_srl, $url) { $oModuleModel =& getModel('module'); $config = $oModuleModel->getModuleConfig('member'); $max_width = $config->profile_image_max_width; if (!$max_width) { $max_width = "80"; } //default 90 $max_height = $config->profile_image_max_height; if (!$max_height) { $max_height = "80"; } //default 20 $target_path = sprintf('files/member_extra_info/profile_image/%s', getNumberingPath($member_srl)); $target_tmpfile = $target_path . "sample.jpg"; FileHandler::makeDir($target_path); //지정된 URL 로부터 프로필 이미지 가져오기 if (file_exists($target_tmpfile)) { unlink($target_tmpfile); } $this->getProfileImageFromUrl($url, $target_tmpfile); list($width, $height, $type, $attrs) = @getimagesize($target_tmpfile); if ($type == 3) { $ext = 'png'; } elseif ($type == 2) { $ext = 'jpg'; } else { $ext = 'gif'; } $target_filename = sprintf('%s%d.%s', $target_path, $member_srl, $ext); $target_filename_mask = sprintf('%s%d.%s', $target_path, $member_srl, '*'); array_map('unlink', glob($target_filename_mask)); if ($width > $max_width || $height > $max_height || !$type != 1) { FileHandler::createImageFile($target_tmpfile, $target_filename, $max_width, $max_height, $ext); } else { @copy($target_tmpfile, $target_filename); } unlink($target_tmpfile); }
function getThumbnail($file_srl = null, $width = 80, $height = 0, $thumbnail_type = 'crop') { $oFileModel = getModel('file'); if (!$file_srl) { return; } if (!$height) { $height = $width; } // Define thumbnail information $thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($file_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // Return false if thumbnail file exists and its size is 0. Otherwise, return its path if (file_exists($thumbnail_file)) { if (filesize($thumbnail_file) < 1) { return false; } else { return $thumbnail_url; } } // Target File $source_file = NULL; $file = $oFileModel->getFile($file_srl); if ($file) { $source_file = $file->uploaded_filename; } if ($source_file) { $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); } // Return its path if a thumbnail is successfully genetated if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }
/** * Image resize * * @return Object **/ function procFileImageResize() { $source_src = Context::get('source_src'); $width = Context::get('width'); $height = Context::get('height'); $type = Context::get('type'); $output_src = Context::get('output_src'); if (!$source_src || !$width) { return new Object(-1, 'msg_invalid_request'); } if (!$output_src) { $output_src = $source_src . '.resized' . strrchr($source_src, '.'); } if (!$type) { $type = 'ratio'; } if (!$height) { $height = $width - 1; } if (FileHandler::createImageFile($source_src, $output_src, $width, $height, '', 'ratio')) { $output->info = getimagesize($output_src); $output->src = $output_src; } else { return new Object(-1, 'msg_invalid_request'); } $this->add('resized_info', $output); }
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // return false if no doc exists if (!$this->comment_srl) { return; } if ($this->isSecret() && !$this->isGranted()) { return; } // If signiture height setting is omitted, create a square if (!$height) { $height = $width; } // return false if neigher attached file nor image; if (!$this->hasUploadedFiles() && !preg_match("!<img!is", $this->get('content'))) { return; } // get thumbail generation info on the doc module configuration. if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $thumbnail_type = 'crop'; } // Define thumbnail information $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // return false if a size of existing thumbnail file is 0. otherwise return the file path if (file_exists($thumbnail_file) || file_exists($thumbnail_lockfile)) { if (filesize($thumbnail_file) < 1) { return FALSE; } else { return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file)); } } // Create lockfile to prevent race condition FileHandler::writeFile($thumbnail_lockfile, '', 'w'); // Target file $source_file = NULL; $is_tmp_file = FALSE; // find an image file among attached files if ($this->hasUploadedFiles()) { $file_list = $this->getUploadedFiles(); $first_image = null; foreach ($file_list as $file) { if ($file->direct_download !== 'Y') { continue; } if ($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) { $source_file = $file->uploaded_filename; break; } if ($first_image) { continue; } if (preg_match("/\\.(jpe?g|png|gif|bmp)\$/i", $file->source_filename)) { if (file_exists($file->uploaded_filename)) { $first_image = $file->uploaded_filename; } } } if (!$source_file && $first_image) { $source_file = $first_image; } } // get an image file from the doc content if no file attached. if (!$source_file) { preg_match_all("!<img\\s[^>]*?src=(\"|')([^\"' ]*?)(\"|')!is", $this->get('content'), $matches, PREG_SET_ORDER); foreach ($matches as $match) { $target_src = htmlspecialchars_decode(trim($match[2])); if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) { continue; } else { if (!preg_match('/^https?:\\/\\//i', $target_src)) { $target_src = Context::getRequestUri() . $target_src; } $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->comment_srl)); if (!is_dir('./files/cache/tmp')) { FileHandler::makeDir('./files/cache/tmp'); } FileHandler::getRemoteFile($target_src, $tmp_file); if (!file_exists($tmp_file)) { continue; } else { if ($is_img = @getimagesize($tmp_file)) { list($_w, $_h, $_t, $_a) = $is_img; } else { continue; } $source_file = $tmp_file; $is_tmp_file = TRUE; break; } } } } $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); // Remove source file if it was temporary if ($is_tmp_file) { FileHandler::removeFile($source_file); } // Remove lockfile FileHandler::removeFile($thumbnail_lockfile); // Return the thumbnail path if it was successfully generated if ($output) { return $thumbnail_url . '?' . date('YmdHis'); } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }
/** * @brief 파일 검색 **/ function _getFiles($target, $module_srls_list, $search_keyword, $page, $list_count, $direct_download = 'Y') { if (is_array($module_srls_list)) { $module_srls = implode(',', $module_srls_list); } else { $module_srls = $module_srls_list; } if ($target == 'exclude') { $args->exclude_module_srl = $module_srls; } else { $args->module_srl = $module_srls; } $args->page = $page; $args->list_count = $list_count; $args->page_count = 10; $args->search_target = 'filename'; $args->search_keyword = $search_keyword; $args->sort_index = 'files.file_srl'; $args->order_type = 'desc'; $args->isvalid = 'Y'; $args->direct_download = $direct_download == 'Y' ? 'Y' : 'N'; // 대상 문서들을 가져옴 $oFileAdminModel =& getAdminModel('file'); $output = $oFileAdminModel->getFileList($args); if (!$output->toBool() || !$output->data) { return $output; } $list = array(); foreach ($output->data as $key => $val) { $obj = null; $obj->filename = $val->source_filename; $obj->download_count = $val->download_count; if (substr($val->download_url, 0, 2) == './') { $val->download_url = substr($val->download_url, 2); } $obj->download_url = Context::getRequestUri() . $val->download_url; $obj->target_srl = $val->upload_target_srl; $obj->file_size = $val->file_size; // 이미지 if (preg_match('/\\.(jpg|jpeg|gif|png)$/i', $val->source_filename)) { $obj->type = 'image'; $thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($val->file_srl, 3)); if (!is_dir($thumbnail_path)) { FileHandler::makeDir($thumbnail_path); } $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, 70, 70, 'crop'); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; if (!file_exists($thumbnail_file)) { FileHandler::createImageFile($val->uploaded_filename, $thumbnail_file, 70, 70, 'jpg', 'crop'); } $obj->src = sprintf('<img src="%s" alt="%s" width="%d" height="%d" />', $thumbnail_url, htmlspecialchars($obj->filename), 70, 70); // 동영상 } elseif (preg_match('/\\.(swf|flv|wmv|avi|mpg|mpeg|asx|asf|mp3)$/i', $val->source_filename)) { $obj->type = 'multimedia'; $obj->src = sprintf('<script type="text/javascript">displayMultimedia("%s",80,80);</script>', $obj->download_url); // 기타 } else { $obj->type = 'binary'; $obj->src = ''; } $list[] = $obj; $target_list[] = $val->upload_target_srl; } $output->data = $list; $oDocumentModel =& getModel('document'); $document_list = $oDocumentModel->getDocuments($target_list); if ($document_list) { foreach ($document_list as $key => $val) { foreach ($output->data as $k => $v) { if ($v->target_srl == $val->document_srl) { $output->data[$k]->url = $val->getPermanentUrl(); $output->data[$k]->regdate = $val->getRegdate("Y-m-d H:i"); $output->data[$k]->nick_name = $val->getNickName(); } } } } $oCommentModel =& getModel('comment'); $comment_list = $oCommentModel->getComments($target_list); if ($comment_list) { foreach ($comment_list as $key => $val) { foreach ($output->data as $k => $v) { if ($v->target_srl == $val->comment_srl) { $output->data[$k]->url = $val->getPermanentUrl(); $output->data[$k]->regdate = $val->getRegdate("Y-m-d H:i"); $output->data[$k]->nick_name = $val->getNickName(); } } } } return $output; }
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // return false if no doc exists if (!$this->comment_srl) { return; } // If signiture height setting is omitted, create a square if (!$height) { $height = $width; } // return false if neigher attached file nor image; if (!$this->hasUploadedFiles() && !preg_match("!<img!is", $this->get('content'))) { return; } // get thumbail generation info on the doc module configuration. if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $thumbnail_type = 'crop'; } // Define thumbnail information $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // return false if a size of existing thumbnail file is 0. otherwise return the file path if (file_exists($thumbnail_file)) { if (filesize($thumbnail_file) < 1) { return FALSE; } else { return $thumbnail_url; } } // Target file $source_file = NULL; $is_tmp_file = FALSE; // find an image file among attached files if ($this->hasUploadedFiles()) { $file_list = $this->getUploadedFiles(); if (count($file_list)) { foreach ($file_list as $file) { if ($file->direct_download != 'Y') { continue; } if (!preg_match("/\\.(jpg|png|jpeg|gif|bmp)\$/i", $file->source_filename)) { continue; } $source_file = $file->uploaded_filename; if (!file_exists($source_file)) { $source_file = NULL; } else { break; } } } } // get an image file from the doc content if no file attached. if (!$source_file) { $content = $this->get('content'); $target_src = NULL; preg_match_all("!src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER); $cnt = count($matches); for ($i = 0; $i < $cnt; $i++) { $target_src = $matches[$i][2]; if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) { continue; } else { if (!preg_match('/^(http|https):\\/\\//i', $target_src)) { $target_src = Context::getRequestUri() . $target_src; } $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->comment_srl)); FileHandler::makeDir('./files/cache/tmp'); FileHandler::getRemoteFile($target_src, $tmp_file); if (!file_exists($tmp_file)) { continue; } else { list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file); if ($_w < $width || $_h < $height) { continue; } $source_file = $tmp_file; $is_tmp_file = TRUE; break; } } } } $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); if ($is_tmp_file) { FileHandler::removeFile($source_file); } // return the thumbnail path if successfully generated. if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }
function _get($item) { $status = array('items' => 0, 'tags' => 0, 'images' => 0); $body = Context::convertEncodingStr(FileHandler::getRemoteResource($item->rss_url, null, 3, 'GET', 'application/xml', array('User-Agent' => 'liveXE ( ' . Context::getRequestUri() . ' )'))); if (!$body) { $this->doUpdateRssCrawlerTime($item->livexe_rss_srl); return $status; } $body = $this->_checkAndCorrectEncodingInPI($body); $data = $this->parseRss($body); if (!$data || !count($data)) { $this->doUpdateRssCrawlerTime($item->livexe_rss_srl); return $status; } $items = array(); for ($i = 0, $c = count($data); $i < $c; $i++) { unset($get_args); $get_args->module_srl = $item->module_srl; $get_args->link = $data[$i]->link; $output = executeQuery('livexe.getLiveDocumentExists', $get_args); if ($output->data) { continue; } $items[$data[$i]->link] = $data[$i]; } if (!count($items)) { $this->doUpdateRssCrawlerTime($item->livexe_rss_srl); return $status; } $gap = $start = $end = null; foreach ($items as $link => $obj) { unset($args); $args->module_srl = $item->module_srl; $args->livexe_rss_srl = $item->livexe_rss_srl; $args->livexe_document_srl = getNextSequence(); $args->member_srl = $item->member_srl; $args->author = $obj->author; $args->title = $obj->title; $args->content = $obj->content; $args->link = $obj->link; if (count($obj->tags)) { $_tag = array(); foreach ($obj->tags as $key => $val) { $val = trim(str_replace(array(' ', "\t"), '', $val)); if (!$val) { continue; } $_tag[] = $val; } $args->tags = implode(',', $_tag); } $args->regdate = $obj->regdate; $args->list_order = $args->livexe_document_srl * -1; if (preg_match_all('/<img([^>]+)>/is', $args->content, $matches)) { for ($i = 0, $c = count($matches[1]); $i < $c; $i++) { if (preg_match('/"(http)([^"]+)"/i', $matches[1][$i], $match)) { $filename = str_replace(array('"', '&'), array('', '&'), $match[0]); if ($filename) { $target = _XE_PATH_ . 'files/cache/tmp/' . $args->livexe_document_srl; $thumbnail_name = $args->livexe_document_srl . rand(111111, 333333) . '.jpg'; $path = sprintf("./files/attach/images/%s/%s", $item->module_srl, getNumberingPath($args->livexe_document_srl, 3)); FileHandler::getRemoteFile($filename, $target); list($width, $height, $type, $attrs) = @getimagesize($target); if ($width > 80 && $height > 80) { if (FileHandler::createImageFile($target, _XE_PATH_ . $path . $thumbnail_name, 100, 100, 'jpeg', 'crop')) { $args->thumbnail = $path . $thumbnail_name; $status['images']++; } break; } FileHandler::removeFile($target); } } } } $output = executeQuery('livexe.insertLiveDocument', $args); if (!$output->toBool()) { continue; } $status['items']++; if (!$start) { $start = strtotime($args->regdate); } else { $end = strtotime($args->regdate); if ($end - $start > $gap) { $gap = $end - $start; } $start = $end; } if (!count($obj->tags)) { continue; } foreach ($obj->tags as $tag) { unset($tag_args); $tag_args->module_srl = $item->module_srl; $tag_args->livexe_rss_srl = $item->livexe_rss_srl; $tag_args->livexe_document_srl = $args->livexe_document_srl; $tag_args->tag = str_replace(array(' ', "\t"), '', $tag); $tag_args->regdate = $args->regdate; $output = executeQuery('livexe.insertLiveTag', $tag_args); if (!$output->toBool()) { $status['tags']++; } $status['tags']++; } } $start = $args->regdate; $update_args->livexe_rss_srl = $item->livexe_rss_srl; $update_args->crawler_time = time() + $gap; executeQuery('livexe.updateRSSPeriod', $update_args); return $status; }
function procMaterialInsert() { $var = Context::getRequestVars(); if (!$var->auth || !$var->type) { return new Object(-1, 'msg_not_permitted'); } $oMaterialModel =& getModel('material'); $member_srl = $oMaterialModel->getMemberSrlByAuth($var->auth); if (!$member_srl) { return new Object(-1, 'msg_invalid_request'); } if ($var->type == 'img') { if ($var->image) { $path = sprintf('files/cache/material/tmp/%s/', getNumberingPath($member_srl)); $filename = basename($var->image); $file = $path . $filename; FileHandler::makeDir($path); FileHandler::getRemoteFile($var->image, $file); if (file_exists($file)) { $material_srl = getNextSequence(); $ext = substr(strrchr($filename, '.'), 1); $ext = array_shift(explode('?', $ext)); // insert file module $file_info = array(); $file_info['tmp_name'] = $file; $file_info['name'] = sprintf("%s.%s", $material_srl, $ext); $oFileController =& getController('file'); $output = $oFileController->insertFile($file_info, $member_srl, $material_srl, 0, true); if (!$output->toBool()) { return $output; } //set File valid $oFileController->setFilesValid($output->get('upload_target_srl')); // delete temp file FileHandler::removeFile($filename); $uploaded_filename = $output->get('uploaded_filename'); $_filename = sprintf("%s%s.%%s.%s", preg_replace("/\\/[^\\/]*\$/", "/", $uploaded_filename), $material_srl, $ext); $s_filename = sprintf($_filename, 'S'); list($w, $h) = @getimagesize($uploaded_filename); if ($w > $this->thum['S']['width'] || $h > $this->thum['S']['height']) { FileHandler::createImageFile($uploaded_filename, $s_filename, $this->thum['S']['width'], $h, '', 'ratio'); } else { FileHandler::copyFile($uploaded_filename, $s_filename); } // replace image src $var->content = str_replace($var->image, $uploaded_filename, $var->content); } else { $var->image = null; } } else { return new Object(-1, 'msg_not_select_image'); } } // there is no file or copy failed if ($var->type == 'img' && !$var->image) { return new Object(-1, 'msg_fail_image_save'); } $args->material_srl = $material_srl ? $material_srl : getNextSequence(); $args->member_srl = $member_srl; $args->type = $var->type; $args->content = $var->content; $output = executeQuery('material.insertMaterial', $args); return $output; }
/** * @brief file upload **/ function mobileFileUpload() { $oFileModel =& getModel('file'); $oFileController =& getController('file'); $oMobileexModel =& getModel('mobileex'); $mobileex_config = $oMobileexModel->getMobileexConfig($this->module_srl); // after upload set template $this->setTemplatePath($this->module_path . 'tpl'); $this->setTemplateFile("after_upload"); // file lang load Context::loadLang('./modules/file/lang'); $module_srl = $this->module_srl; $file_info = Context::get('Filedata'); $upload_type = Context::get('upload_type'); $upload_target_srl = intval(Context::get('uploadTargetSrl')); if (!$upload_target_srl) { $upload_target_srl = intval(Context::get('upload_target_srl')); } // mobile document check if ($upload_target_srl && Context::get('document_srl')) { $mobile_check = $oMobileexModel->getMobileDocument($upload_target_srl); if (!$mobile_check->data) { Context::set('msg', Context::getLang('msg_not_mobile_document')); return; } } if (!$upload_target_srl) { $upload_target_srl = getNextSequence(); } // file exist check if (!$file_info['tmp_name'] || !is_uploaded_file($file_info['tmp_name'])) { Context::set('msg', Context::getLang('msg_no_file')); return; } // grant check $allow_fileupload = $oMobileexModel->getUploadGrant($module_srl, $upload_type); if (!$allow_fileupload) { Context::set('msg', Context::getLang('msg_not_fileupload_grant')); return; } // file ext check $allow_filetype = $oMobileexModel->getAllowedFileType($file_info, $module_srl); if (!$allow_filetype->allowed) { $msg = strtoupper(str_replace('.', '', $allow_filetype->file_ext)) . " " . Context::getLang('msg_not_allowed_filetype'); Context::set('msg', $msg); return; } // get file type $imglist = "GIF|PNG|JPG|JPEG"; if (!eregi(strtoupper(str_replace('.', '', $allow_filetype->file_ext)), $imglist)) { $is_img = 'N'; } else { $is_img = 'Y'; } $img_resize_width = (int) $mobileex_config->img_resize_width; $img_resize_height = (int) $mobileex_config->img_resize_height; if ($img_resize_width > 0 || $img_resize_height > 0) { $img_resize_use = true; } else { $img_resize_use = false; } if ($is_img == 'N' || $is_img == 'Y' && !$img_resize_use) { // file size check $allow_filesize = $oMobileexModel->getAllowedFileSize(filesize($file_info['tmp_name']), $module_srl, $upload_target_srl, $upload_type); if (!$allow_filesize->allowed_filesize || !$allow_filesize->allowed_attach_size) { if (!$allow_filesize->allowed_filesize) { Context::set('msg', Context::getLang('msg_not_allowed_filesize')); } else { if (!$allow_filesize->allowed_attach_size) { Context::set('msg', Context::getLang('msg_not_allowed_attach_size')); } } return; } } //insert file // A workaround for Firefox upload bug if (preg_match('/^=\\?UTF-8\\?B\\?(.+)\\?=$/i', $file_info['name'], $match)) { $file_info['name'] = base64_decode(strtr($match[1], ':', '/')); } // upload path if (preg_match("/\\.(jpe?g|gif|png|wm[va]|mpe?g|avi|swf|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)\$/i", $file_info['name'])) { // direct 파일에 해킹을 의심할 수 있는 확장자가 포함되어 있으면 바로 삭제함 $file_info['name'] = preg_replace('/\\.(php|phtm|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x', $file_info['name']); $file_info['name'] = str_replace(array('<', '>'), array('%3C', '%3E'), $file_info['name']); $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); // special character to '_' // change to md5 file name. because window php bug. window php is not recognize unicode character file name - by cherryfilter $ext = substr(strrchr($file_info['name'], '.'), 1); //$_filename = preg_replace('/[#$&*?+%"\']/', '_', $file_info['name']); $_filename = md5(crypt(rand(1000000, 900000), rand(0, 100))) . '.' . $ext; $filename = $path . $_filename; $idx = 1; while (file_exists($filename)) { $filename = $path . preg_replace('/\\.([a-z0-9]+)$/i', '_' . $idx . '.$1', $_filename); $idx++; } $direct_download = 'Y'; } else { $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); $filename = $path . md5(crypt(rand(1000000, 900000), rand(0, 100))); $direct_download = 'N'; } // make dir if (!FileHandler::makeDir($path)) { Context::set('msg', Context::getLang('msg_not_permitted_create')); return; } // move file if (!@move_uploaded_file($file_info['tmp_name'], $filename)) { $re_name = md5(crypt(rand(1000000, 900000) . $file_info['name'])); $filename = $path . $re_name . '.' . $ext; if (!@move_uploaded_file($file_info['tmp_name'], $filename)) { Context::set('msg', Context::getLang('msg_file_upload_error')); return; } } // image resize if ($is_img == 'Y' && $img_resize_use) { $resizeimg = $oMobileexModel->getImgResizeValue($filename, $img_resize_width, $img_resize_height); if ($resizeimg->width || $resizeimg->height) { $resize_target_width = $resizeimg->width; $resize_target_height = $resizeimg->height; $img_ext = '.' . $ext; $resize_path = str_replace($img_ext, "", $filename); $resize_file = $resize_path . '.' . $ext; $resize_url = Context::getRequestUri() . $resize_file; // resize $source_file = $filename; $resize_img = FileHandler::createImageFile($source_file, $resize_file, $resize_target_width, $resize_target_height, $ext, 'ratio'); $allow_filesize = $oMobileexModel->getAllowedFileSize(@filesize($filename), $module_srl, $upload_target_srl, $upload_type); if (!$allow_filesize->allowed_filesize || !$allow_filesize->allowed_attach_size) { FileHandler::removeFile($filename); if (!$allow_filesize->allowed_filesize) { Context::set('msg', Context::getLang('msg_not_allowed_filesize')); } else { if (!$allow_filesize->allowed_attach_size) { Context::set('msg', Context::getLang('msg_not_allowed_attach_size')); } } return; } } } // get member info $oMemberModel =& getModel('member'); $member_srl = $oMemberModel->getLoggedMemberSrl(); // file info $args->file_srl = getNextSequence(); $args->upload_target_srl = $upload_target_srl; $args->module_srl = $module_srl; $args->direct_download = $direct_download; $args->source_filename = $file_info['name']; $args->uploaded_filename = $filename; $args->download_count = $download_count; $args->file_size = @filesize($filename); $args->comment = NULL; $args->member_srl = $member_srl; $args->sid = md5(rand(rand(1111111, 4444444), rand(4444445, 9999999))); $output = executeQuery('file.insertFile', $args); if (!$output->toBool()) { Context::set('msg', Context::getLang('msg_file_upload_error')); return; } $_SESSION['__XE_UPLOADING_FILES_INFO__'][$args->file_srl] = true; $output->add('file_srl', $args->file_srl); $output->add('file_size', $args->file_size); $output->add('sid', $args->sid); $output->add('direct_download', $args->direct_download); $output->add('source_filename', $args->source_filename); $output->add('upload_target_srl', $upload_target_srl); $output->add('uploaded_filename', $args->uploaded_filename); // add file insert if ($mobileex_config->addfile_auto == 'Y' && $is_img == 'Y') { $args->module_srl = $module_srl; $args->upload_target_srl = $output->get('upload_target_srl'); $args->file_srl = $output->get('file_srl'); executeQuery('mobileex.insertMobileAddFile', $args); } if ($is_img != 'Y') { $img_href = './modules/editor/tpl/images/files.gif'; } else { $img_href = $output->get('uploaded_filename'); // create thumb $preview_thumb = $oMobileexModel->getFileThumbnail($output->get('file_srl'), $width = 100, $height = 100, $thumbnail_type = 'crop'); if (!$preview_thumb) { $preview_thumb = './modules/editor/tpl/images/files.gif'; } $img_href = $preview_thumb; if ($mobileex_config->addfile_thumb_use == 'Y') { $addfile_max_size = (int) $mobileex_config->addfile_max_size; // max_thumb $max_thumb = $oMobileexModel->getFileThumbnail($value->file_srl, $width = $addfile_max_size, $height = '', $thumbnail_type = ''); if (!$max_thumb) { $max_thumb = './modules/editor/tpl/images/files.gif'; } } } // get file size convert for kb $file_size = (int) $output->get('file_size') / 1024; $file_size = round($file_size, 1); // set uploaded file info Context::set('module_srl', $module_srl); Context::set('file_srl', $output->get('file_srl')); Context::set('upload_target_srl', $output->get('upload_target_srl')); // if temp document Context::set('source_filename', $output->get('source_filename')); Context::set('file_size', $file_size); Context::set('is_img', $is_img); Context::set('img_href', $img_href); }
/** * @brief 플래닛 이미지 등록 **/ function insertPlanetPhoto($module_srl, $source) { $oPlanetModel =& getModel('planet'); $path = $oPlanetModel->getPlanetPhotoPath($module_srl); if (!is_dir($path)) { FileHandler::makeDir($path); } $filename = sprintf('%s/%d.jpg', $path, $module_srl); FileHandler::createImageFile($source, $filename, 96, 96, 'jpg', 'crop'); }
function UploadMmsImage($document_srl, $ggname, $gg_FILES) { @mkdir('files/ggmailing/'); @chmod('files/ggmailing/', 0755); @mkdir('files/ggmailing/mms/'); @chmod('files/ggmailing/mms/', 0755); $target_path = 'files/ggmailing/mms/'; // 파일이 없거나 jpeg 이 아니면 되돌려 보냄 if (!$gg_FILES[$ggname]['tmp_name'] || $gg_FILES[$ggname]['type'] != 'image/jpeg') { $returnUrl = getNotEncodedUrl('', 'module', 'admin', 'act', 'dispGgmailingAdminSmsList'); //$this->setRedirectUrl($returnUrl); header("Location:" . $returnUrl); return; } $file_tmp_name = $gg_FILES[$ggname]['tmp_name']; $file_name = $document_srl . '_' . $ggname . '.jpg'; $file_path = $target_path . $file_name; //일단 파일을 삭제 @unlink($file_path); @move_uploaded_file($file_tmp_name, $file_path); //파일 크기가 20k를 넘으면 섬네일 리사이징 if ($gg_FILES[$ggname]['size'] > 20480) { //리사이징 FileHandler::createImageFile($file_path, $file_path, '176', '144', 'jpg', 'ratio'); } @chmod($file_path, 0707); $single_size = 40 * 1024; $multi_size = 60 * 1024; $mms_file1 = _XE_PATH_ . "files/ggmailing/mms/" . $document_srl . "_mms_file1.jpg"; $mms_file2 = _XE_PATH_ . "files/ggmailing/mms/" . $document_srl . "_mms_file2.jpg"; $mms_file3 = _XE_PATH_ . "files/ggmailing/mms/" . $document_srl . "_mms_file3.jpg"; if (filesize($file_path) > $single_size) { @unlink($file_path); } if (filesize($mms_file1) + filesize($mms_file2) + filesize($mms_file3) > $multi_size) { @unlink($file_path); } }
function procHomepageInsertCafeBanner() { global $lang; $oHomepageModel =& getModel('homepage'); $site_srl = Context::get('site_srl'); if (!$site_srl) { return new Object(-1, 'msg_invalid_request'); } $title = Context::get('cafe_title'); if (!$title) { return new Object(-1, sprintf($lang->filter->isnull, $lang->cafe_title)); } $description = Context::get('cafe_description'); if (!$description) { return new Object(-1, sprintf($lang->filter->isnull, $lang->cafe_description)); } // 홈페이지 제목/내용 변경 $homepage_info = $oHomepageModel->getHomepageInfo($site_srl); if (!$homepage_info->site_srl) { return new Object(-1, 'msg_invalid_request'); } $args->title = $title; $args->description = $description; $args->layout_srl = $homepage_info->layout_srl; $args->site_srl = $homepage_info->site_srl; $output = executeQuery('homepage.updateHomepage', $args); if (!$output->toBool()) { return $output; } $cafe_banner = Context::get('cafe_banner'); if ($cafe_banner['name']) { $banner_src = 'files/attach/cafe_banner/' . $homepage_info->site_srl . '.jpg'; FileHandler::createImageFile($cafe_banner['tmp_name'], $banner_src, 100, 100, 'jpg', 'crop'); } $this->setTemplatePath($this->module_path . 'tpl'); $this->setTemplateFile('redirect.html'); }
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // Return false if the document doesn't exist if (!$this->document_srl) { return; } if ($this->isSecret() && !$this->isGranted()) { return; } // If not specify its height, create a square if (!$height) { $height = $width; } if ($this->get('content')) { $content = $this->get('content'); } else { $args = new stdClass(); $args->document_srl = $this->document_srl; $output = executeQuery('document.getDocument', $args); $content = $output->data->content; } // Return false if neither attachement nor image files in the document if (!$this->get('uploaded_count') && !preg_match("!<img!is", $content)) { return; } // Get thumbnai_type information from document module's configuration if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $config = $GLOBALS['__document_config__']; if (!$config) { $oDocumentModel = getModel('document'); $config = $oDocumentModel->getDocumentConfig(); $GLOBALS['__document_config__'] = $config; } $thumbnail_type = $config->thumbnail_type ?: 'crop'; } // Define thumbnail information $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->document_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // Return false if thumbnail file exists and its size is 0. Otherwise, return its path if (file_exists($thumbnail_file) || file_exists($thumbnail_lockfile)) { if (filesize($thumbnail_file) < 1) { return FALSE; } else { return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file)); } } // Create lockfile to prevent race condition FileHandler::writeFile($thumbnail_lockfile, '', 'w'); // Target File $source_file = null; $is_tmp_file = false; // Find an iamge file among attached files if exists if ($this->hasUploadedFiles()) { $file_list = $this->getUploadedFiles(); $first_image = null; foreach ($file_list as $file) { if ($file->direct_download !== 'Y') { continue; } if ($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) { $source_file = $file->uploaded_filename; break; } if ($first_image) { continue; } if (preg_match("/\\.(jpe?g|png|gif|bmp)\$/i", $file->source_filename)) { if (file_exists($file->uploaded_filename)) { $first_image = $file->uploaded_filename; } } } if (!$source_file && $first_image) { $source_file = $first_image; } } // If not exists, file an image file from the content if (!$source_file) { preg_match_all("!<img\\s[^>]*?src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $target_src = htmlspecialchars_decode(trim($match[2])); if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) { continue; } else { if (!preg_match('/^https?:\\/\\//i', $target_src)) { $target_src = Context::getRequestUri() . $target_src; } $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->document_srl)); if (!is_dir('./files/cache/tmp')) { FileHandler::makeDir('./files/cache/tmp'); } FileHandler::getRemoteFile($target_src, $tmp_file); if (!file_exists($tmp_file)) { continue; } else { if ($is_img = @getimagesize($tmp_file)) { list($_w, $_h, $_t, $_a) = $is_img; } else { continue; } $source_file = $tmp_file; $is_tmp_file = true; break; } } } } if ($source_file) { $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); } // Remove source file if it was temporary if ($is_tmp_file) { FileHandler::removeFile($source_file); } // Remove lockfile FileHandler::removeFile($thumbnail_lockfile); // Return the thumbnail path if it was successfully generated if ($output) { return $thumbnail_url . '?' . date('YmdHis'); } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // 존재하지 않는 문서일 경우 return false if (!$this->comment_srl) { return; } // 높이 지정이 별도로 없으면 정사각형으로 생성 if (!$height) { $height = $width; } // 첨부파일이 없거나 내용중 이미지가 없으면 return false; if (!$this->hasUploadedFiles() && !preg_match("!<img!is", $this->get('content'))) { return; } // 문서 모듈의 기본 설정에서 Thumbnail의 생성 방법을 구함 if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $thumbnail_type = 'crop'; } // 썸네일 정보 정의 $thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($this->comment_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // 썸네일 파일이 있을 경우 파일의 크기가 0 이면 return false 아니면 경로 return if (file_exists($thumbnail_file)) { if (filesize($thumbnail_file) < 1) { return false; } else { return $thumbnail_url; } } // 대상 파일 $source_file = null; $is_tmp_file = false; // 첨부된 파일중 이미지 파일이 있으면 찾음 if ($this->hasUploadedFiles()) { $file_list = $this->getUploadedFiles(); if (count($file_list)) { foreach ($file_list as $file) { if ($file->direct_download != 'Y') { continue; } if (!preg_match("/\\.(jpg|png|jpeg|gif|bmp)\$/i", $file->source_filename)) { continue; } $source_file = $file->uploaded_filename; if (!file_exists($source_file)) { $source_file = null; } else { break; } } } } // 첨부된 파일이 없으면 내용중 이미지 파일을 구함 if (!$source_file) { $content = $this->get('content'); $target_src = null; preg_match_all("!src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER); $cnt = count($matches); for ($i = 0; $i < $cnt; $i++) { $target_src = $matches[$i][2]; if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) { continue; } else { if (!preg_match('/^(http|https):\\/\\//i', $target_src)) { $target_src = Context::getRequestUri() . $target_src; } $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->comment_srl)); if (!is_dir('./files/cache/tmp')) { FileHandler::makeDir('./files/cache/tmp'); } FileHandler::getRemoteFile($target_src, $tmp_file); if (!file_exists($tmp_file)) { continue; } else { list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file); if ($_w < $width || $_h < $height) { continue; } $source_file = $tmp_file; $is_tmp_file = true; break; } } } } $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); if ($is_tmp_file) { FileHandler::removeFile($source_file); } // 썸네일 생성 성공시 경로 return if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }
/** * @brief 플래닛 이미지 유무 체크후 경로 return **/ function getPlanetPhotoSrc($module_srl, $width = 96, $height = 96) { $path = $this->getPlanetPhotoPath($module_srl); $source_filename = sprintf('%s/%d.jpg', $path, $module_srl); if (!is_dir($path) || !file_exists($source_filename)) { return sprintf("%s%s%s", Context::getRequestUri(), $this->module_path, 'tpl/images/blank_photo.gif'); } if ($width != 96 && $height != 96) { $filename = sprintf('%s%d.%d.%d.jpg', $path, $module_srl, $width, $height); if (!file_exists($filename) || filemtime($source_filename) > filemtime($filename)) { if (FileHandler::createImageFile($source_filename, $filename, $width, $height)) { $source_filename = $filename; } } } else { $filename = $source_filename; } return Context::getRequestUri() . $filename . "?rnd=" . filemtime($filename); }
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // Return false if the document doesn't exist if (!$this->document_srl) { return; } if ($this->isSecret() && !$this->isGranted()) { return; } // If not specify its height, create a square if (!$height) { $height = $width; } // Return false if neither attachement nor image files in the document if (!$this->get('uploaded_count') && !preg_match("!<img!is", $this->get('content'))) { return; } // Get thumbnai_type information from document module's configuration if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $config = $GLOBALS['__document_config__']; if (!$config) { $oDocumentModel = getModel('document'); $config = $oDocumentModel->getDocumentConfig(); $GLOBALS['__document_config__'] = $config; } $thumbnail_type = $config->thumbnail_type; } // Define thumbnail information $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->document_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // Return false if thumbnail file exists and its size is 0. Otherwise, return its path if (file_exists($thumbnail_file)) { if (filesize($thumbnail_file) < 1) { return false; } else { return $thumbnail_url; } } // Target File $source_file = null; $is_tmp_file = false; // Find an iamge file among attached files if exists if ($this->hasUploadedFiles()) { $file_list = $this->getUploadedFiles(); $first_image = null; foreach ($file_list as $file) { if ($file->direct_download !== 'Y') { continue; } if ($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) { $source_file = $file->uploaded_filename; break; } if ($first_image) { continue; } if (preg_match("/\\.(jpe?g|png|gif|bmp)\$/i", $file->source_filename)) { if (file_exists($file->uploaded_filename)) { $first_image = $file->uploaded_filename; } } } if (!$source_file && $first_image) { $source_file = $first_image; } } // If not exists, file an image file from the content if (!$source_file) { $content = $this->get('content'); $target_src = null; preg_match_all("!src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER); $cnt = count($matches); for ($i = 0; $i < $cnt; $i++) { $target_src = trim($matches[$i][2]); if (!preg_match("/\\.(jpg|png|jpeg|gif|bmp)\$/i", $target_src)) { continue; } if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) { continue; } else { if (!preg_match('/^(http|https):\\/\\//i', $target_src)) { $target_src = Context::getRequestUri() . $target_src; } $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->document_srl)); if (!is_dir('./files/cache/tmp')) { FileHandler::makeDir('./files/cache/tmp'); } FileHandler::getRemoteFile($target_src, $tmp_file); if (!file_exists($tmp_file)) { continue; } else { list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file); if ($_w < $width || $_h < $height) { continue; } $source_file = $tmp_file; $is_tmp_file = true; break; } } } } if ($source_file) { $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); } if ($is_tmp_file) { FileHandler::removeFile($source_file); } // Return its path if a thumbnail is successfully genetated if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }
/** * Image resize * * @return Object */ function procFileImageResize() { $file_srl = Context::get('file_srl'); $width = Context::get('width'); $height = Context::get('height'); if (!$file_srl || !$width) { return new Object(-1, 'msg_invalid_request'); } $oFileModel = getModel('file'); $fileInfo = $oFileModel->getFile($file_srl); if (!$fileInfo || $fileInfo->direct_download != 'Y') { return new Object(-1, 'msg_invalid_request'); } $source_src = $fileInfo->uploaded_filename; $output_src = $source_src . '.resized' . strrchr($source_src, '.'); if (!$height) { $height = $width - 1; } if (FileHandler::createImageFile($source_src, $output_src, $width, $height, '', 'ratio')) { $output = new stdClass(); $output->info = getimagesize($output_src); $output->src = $output_src; } else { return new Object(-1, 'msg_invalid_request'); } $this->add('resized_info', $output); }
/** * Insert a image mark * * @param int $member_srl * @param object $target_file * * @return void */ function insertImageMark($member_srl, $target_file) { $oModuleModel = getModel('module'); $config = $oModuleModel->getModuleConfig('member'); // Get an image size $max_width = $config->image_mark_max_width; if (!$max_width) { $max_width = "20"; } $max_height = $config->image_mark_max_height; if (!$max_height) { $max_height = "20"; } $target_path = sprintf('files/member_extra_info/image_mark/%s/', getNumberingPath($member_srl)); FileHandler::makeDir($target_path); $target_filename = sprintf('%s%d.gif', $target_path, $member_srl); // Get file information list($width, $height, $type, $attrs) = @getimagesize($target_file); if ($width > $max_width || $height > $max_height || $type != 1) { FileHandler::createImageFile($target_file, $target_filename, $max_width, $max_height, 'gif'); } else { @copy($target_file, $target_filename); } }
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // return false if no doc exists if (!$this->comment_srl) { return; } if ($this->isSecret() && !$this->isGranted()) { return; } // If signiture height setting is omitted, create a square if (!$height) { $height = $width; } $content = $this->get('content'); if (!$this->hasUploadedFiles()) { if (!$content) { $args = new stdClass(); $args->comment_srl = $this->comment_srl; $output = executeQuery('document.getComment', $args, array('content')); if ($output->toBool() && $output->data) { $content = $output->data->content; $this->add('content', $content); } } if (!preg_match("!<img!is", $content)) { return; } } // get thumbail generation info on the doc module configuration. if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $thumbnail_type = 'crop'; } // Define thumbnail information $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // return false if a size of existing thumbnail file is 0. otherwise return the file path if (file_exists($thumbnail_file) || file_exists($thumbnail_lockfile)) { if (filesize($thumbnail_file) < 1) { return FALSE; } else { return $thumbnail_url; } } // Create lockfile to prevent race condition FileHandler::writeFile($thumbnail_lockfile, '', 'w'); // Target file $source_file = NULL; $is_tmp_file = FALSE; // find an image file among attached files if ($this->hasUploadedFiles()) { $file_list = $this->getUploadedFiles(); $first_image = null; foreach ($file_list as $file) { if ($file->direct_download !== 'Y') { continue; } if ($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) { $source_file = $file->uploaded_filename; break; } if ($first_image) { continue; } if (preg_match("/\\.(jpe?g|png|gif|bmp)\$/i", $file->source_filename)) { if (file_exists($file->uploaded_filename)) { $first_image = $file->uploaded_filename; } } } if (!$source_file && $first_image) { $source_file = $first_image; } } // get an image file from the doc content if no file attached. $is_tmp_file = false; if (!$source_file) { $random = new Password(); preg_match_all("!<img[^>]*src=(?:\"|\\')([^\"\\']*?)(?:\"|\\')!is", $content, $matches, PREG_SET_ORDER); foreach ($matches as $target_image) { $target_src = trim($target_image[1]); if (preg_match('/\\/(common|modules|widgets|addons|layouts|m\\.layouts)\\//i', $target_src)) { continue; } if (!preg_match('/^(http|https):\\/\\//i', $target_src)) { $target_src = Context::getRequestUri() . $target_src; } $target_src = htmlspecialchars_decode($target_src); $tmp_file = _XE_PATH_ . 'files/cache/tmp/' . $random->createSecureSalt(32, 'hex'); FileHandler::getRemoteFile($target_src, $tmp_file); if (!file_exists($tmp_file)) { continue; } $imageinfo = getimagesize($tmp_file); list($_w, $_h) = $imageinfo; if ($imageinfo === false || $_w < $width * 0.3 && $_h < $height * 0.3) { FileHandler::removeFile($tmp_file); continue; } $source_file = $tmp_file; $is_tmp_file = true; break; } } $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); // Remove source file if it was temporary if ($is_tmp_file) { FileHandler::removeFile($source_file); } // Remove lockfile FileHandler::removeFile($thumbnail_lockfile); // Return the thumbnail path if it was successfully generated if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }