function getNewsFromAgency() { //Retrieve recent news and set them into context $newest_news_url = sprintf("http://www.xeshoppingmall.com/?module=newsagency&act=getNewsagencyArticle&inst=notice&top=6&loc=%s", _XE_LOCATION_); $cache_file = sprintf("%sfiles/cache/nstore_news.%s.cache.php", _XE_PATH_, _XE_LOCATION_); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) { // Considering if data cannot be retrieved due to network problem, modify filemtime to prevent trying to reload again when refreshing textmessageistration page // Ensure to access the textmessageistration page even though news cannot be displayed FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($newest_news_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } if (file_exists($cache_file)) { $oXml = new XmlParser(); $buff = $oXml->parse(FileHandler::readFile($cache_file)); $item = $buff->zbxe_news->item; if ($item) { if (!is_array($item)) { $item = array($item); } foreach ($item as $key => $val) { $obj = null; $obj->title = $val->body; $obj->date = $val->attrs->date; $obj->url = $val->attrs->url; $news[] = $obj; } return $news; } } }
/** * @brief 외부 http로 요청되는 파일일 경우 파일을 받아와서 저장 후 return **/ function getHtmlPage($path, $caching_interval, $cache_file) { // 캐시 검사 if ($caching_interval > 0 && file_exists($cache_file) && filemtime($cache_file) + $caching_interval * 60 > time()) { $content = FileHandler::readFile($cache_file); } else { FileHandler::getRemoteFile($path, $cache_file); $content = FileHandler::readFile($cache_file); } // opage controller 생성 $oOpageController =& getController('opage'); // 외부 서버의 페이지 일 경우 이미지, css, javascript등의 url을 변경 $content = $oOpageController->replaceSrc($content, $path); // 해당 문서를 utf-8로 변경 $buff->content = $content; $buff = Context::convertEncoding($buff); $content = $buff->content; // title 추출 $title = $oOpageController->getTitle($content); if ($title) { Context::setBrowserTitle($title); } // header script 추출 $head_script = $oOpageController->getHeadScript($content); if ($head_script) { Context::addHtmlHeader($head_script); } // body 내용 추출 $body_script = $oOpageController->getBodyScript($content); if (!$body_script) { $body_script = $content; } return $content; }
function checkLicense($prodid, $user_id, $serial_number, $force = FALSE) { $hostinfo = array($_SERVER['SERVER_ADDR'], $_SERVER['SERVER_NAME'], $_SERVER['HTTP_HOST']); $agency_url = sprintf("http://www.xeshoppingmall.com/?module=drmagency&act=getDrmagencyLicense&prodid=%s&hostinfo=%s&user=%s&serial=%s", $prodid, implode(',', $hostinfo), $user_id, $serial_number); $cache_file = sprintf("%sfiles/cache/license_%s.cache.php", _XE_PATH_, $prodid); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time() || $force == TRUE) { FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($agency_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } return $cache_file; }
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; }
/** * @brief Display Super Admin Dashboard **/ function dispTextmessageAdminIndex() { $oTextmessageModel = getModel('textmessage'); $config = $oTextmessageModel->getConfig(); if (!$config) { Context::set('isSetupCompleted', false); } else { Context::set('isSetupCompleted', true); } Context::set('config', $config); //Retrieve recent news and set them into context $newest_news_url = sprintf("http://www.coolsms.co.kr/?module=newsagency&act=getNewsagencyArticle&inst=notice&loc=%s", _XE_LOCATION_); $cache_file = sprintf("%sfiles/cache/cool_news.%s.cache.php", _XE_PATH_, _XE_LOCATION_); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) { // Considering if data cannot be retrieved due to network problem, modify filemtime to prevent trying to reload again when refreshing textmessageistration page // Ensure to access the textmessage registration page even though news cannot be displayed FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($newest_news_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } if (file_exists($cache_file)) { $oXml = new XmlParser(); $buff = $oXml->parse(FileHandler::readFile($cache_file)); $item = $buff->zbxe_news->item; if ($item) { if (!is_array($item)) { $item = array($item); } foreach ($item as $key => $val) { $obj = new stdClass(); $obj->title = $val->body; $obj->date = $val->attrs->date; $obj->url = $val->attrs->url; $news[] = $obj; } Context::set('news', $news); } Context::set('released_version', $buff->zbxe_news->attrs->released_version); Context::set('download_link', $buff->zbxe_news->attrs->download_link); } $this->setTemplateFile('index'); }
/** * @brief 첨부파일 정리 **/ function importAttaches($fp, $module_srl, $upload_target_srl, &$files) { $uploaded_count = 0; $started = false; $buff = null; while (!feof($fp)) { $str = trim(fgets($fp, 1024)); // </attaches>로 끝나면 중단 if (trim($str) == '</attaches>') { break; } // <attach>로 시작하면 첨부파일 수집 if (trim($str) == '<attach>') { $file_obj = null; $file_obj->file_srl = getNextSequence(); $file_obj->upload_target_srl = $upload_target_srl; $file_obj->module_srl = $module_srl; $started = true; $buff = null; // <file>로 시작하면 xml파일내의 첨부파일로 처리 } else { if (trim($str) == '<file>') { $file_obj->file = $this->saveTemporaryFile($fp); continue; } } if ($started) { $buff .= $str; } // </attach>로 끝나면 첨부파일 정리 if (trim($str) == '</attach>') { $xmlDoc = $this->oXmlParser->parse($buff . $str); $file_obj->source_filename = base64_decode($xmlDoc->attach->filename->body); $file_obj->download_count = base64_decode($xmlDoc->attach->download_count->body); if (!$file_obj->file) { $url = base64_decode($xmlDoc->attach->url->body); $path = base64_decode($xmlDoc->attach->path->body); if ($path && file_exists($path)) { $file_obj->file = $path; } else { $file_obj->file = $this->getTmpFilename(); FileHandler::getRemoteFile($url, $file_obj->file); } } if (file_exists($file_obj->file)) { // 이미지인지 기타 파일인지 체크하여 upload path 지정 if (preg_match("/\\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|asaf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)\$/i", $file_obj->source_filename)) { $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); $filename = $path . $file_obj->source_filename; $file_obj->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))); $file_obj->direct_download = 'N'; } // 디렉토리 생성 if (!FileHandler::makeDir($path)) { continue; } if (preg_match('/^\\.\\/files\\/cache\\/importer/i', $file_obj->file)) { FileHandler::rename($file_obj->file, $filename); } else { @copy($file_obj->file, $filename); } // DB입력 unset($file_obj->file); if (file_exists($filename)) { $file_obj->uploaded_filename = $filename; $file_obj->file_size = filesize($filename); $file_obj->comment = NULL; $file_obj->member_srl = 0; $file_obj->sid = md5(rand(rand(1111111, 4444444), rand(4444445, 9999999))); $file_obj->isvalid = 'Y'; $output = executeQuery('file.insertFile', $file_obj); if ($output->toBool()) { $uploaded_count++; $tmp_obj = null; $tmp_obj->source_filename = $file_obj->source_filename; if ($file_obj->direct_download == 'Y') { $files[$file_obj->source_filename] = $file_obj->uploaded_filename; } else { $files[$file_obj->source_filename] = getUrl('', 'module', 'file', 'act', 'procFileDownload', 'file_srl', $file_obj->file_srl, 'sid', $file_obj->sid); } } } } } } return $uploaded_count; }
/** * Import attachment * @param resource $fp * @param int $module_srl * @param int $upload_target_srl * @param array $files * @return int */ function importAttaches($fp, $module_srl, $upload_target_srl, &$files) { $uploaded_count = 0; $started = false; $buff = null; $file_obj = new stdClass(); while (!feof($fp)) { $str = trim(fgets($fp, 1024)); // If it ends with </attaches>, break if (trim($str) == '</attaches>') { break; } // If it starts with <attach>, collect attachments if (trim($str) == '<attach>') { $file_obj->file_srl = getNextSequence(); $file_obj->upload_target_srl = $upload_target_srl; $file_obj->module_srl = $module_srl; $started = true; $buff = null; // If it starts with <file>, handle the attachement in xml file } else { if (trim($str) == '<file>') { $file_obj->file = $this->saveTemporaryFile($fp); continue; } } if ($started) { $buff .= $str; } // If it ends with </attach>, handle attachements if (trim($str) == '</attach>') { $xmlDoc = $this->oXmlParser->parse($buff . $str); $file_obj->source_filename = base64_decode($xmlDoc->attach->filename->body); $file_obj->download_count = base64_decode($xmlDoc->attach->download_count->body); if (!$file_obj->file) { $url = base64_decode($xmlDoc->attach->url->body); $path = base64_decode($xmlDoc->attach->path->body); if ($path && file_exists($path)) { $file_obj->file = $path; } else { $file_obj->file = $this->getTmpFilename(); FileHandler::getRemoteFile($url, $file_obj->file); } } if (file_exists($file_obj->file)) { // Set upload path by checking if the attachement is an image or other kind of file 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_obj->source_filename)) { // Immediately remove the direct file if it has any kind of extensions for hacking $file_obj->source_filename = preg_replace('/\\.(php|phtm|phar|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x', $file_obj->source_filename); $file_obj->source_filename = str_replace(array('<', '>'), array('%3C', '%3E'), $file_obj->source_filename); $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); $ext = substr(strrchr($file_obj->source_filename, '.'), 1); $_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++; } $file_obj->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))); $file_obj->direct_download = 'N'; } // Create a directory if (!FileHandler::makeDir($path)) { continue; } if (strncmp('./files/cache/importer/', $file_obj->file, 23) === 0) { FileHandler::rename($file_obj->file, $filename); } else { copy($file_obj->file, $filename); } // Insert the file to the DB unset($file_obj->file); if (file_exists($filename)) { $file_obj->uploaded_filename = $filename; $file_obj->file_size = filesize($filename); $file_obj->comment = NULL; $file_obj->member_srl = 0; $file_obj->sid = md5(rand(rand(1111111, 4444444), rand(4444445, 9999999))); $file_obj->isvalid = 'Y'; $output = executeQuery('file.insertFile', $file_obj); if ($output->toBool()) { $uploaded_count++; $tmp_obj = null; $tmp_obj->source_filename = $file_obj->source_filename; if ($file_obj->direct_download == 'Y') { $files[$file_obj->source_filename] = $file_obj->uploaded_filename; } else { $files[$file_obj->source_filename] = getUrl('', 'module', 'file', 'act', 'procFileDownload', 'file_srl', $file_obj->file_srl, 'sid', $file_obj->sid); } } } } } } return $uploaded_count; }
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; }
/** * Include admin menu php file and make menu url * Setting admin logo, newest news setting * @return void */ function makeGnbUrl($module = 'admin') { global $lang; // Check is_shortcut column $oDB = DB::getInstance(); if (!$oDB->isColumnExists('menu_item', 'is_shortcut')) { return; } $oAdminAdminModel = getAdminModel('admin'); $lang->menu_gnb_sub = $oAdminAdminModel->getAdminMenuLang(); $result = $oAdminAdminModel->checkAdminMenu(); include $result->php_file; $oModuleModel = getModel('module'); // get current menu's subMenuTitle $moduleActionInfo = $oModuleModel->getModuleActionXml($module); $currentAct = Context::get('act'); $subMenuTitle = ''; foreach ((array) $moduleActionInfo->menu as $key => $value) { if (isset($value->acts) && is_array($value->acts) && in_array($currentAct, $value->acts)) { $subMenuTitle = $value->title; break; } } // get current menu's srl(=parentSrl) $parentSrl = 0; $oMenuAdminConroller = getAdminController('menu'); foreach ((array) $menu->list as $parentKey => $parentMenu) { if (!is_array($parentMenu['list']) || !count($parentMenu['list'])) { continue; } if ($parentMenu['href'] == '#' && count($parentMenu['list'])) { $firstChild = current($parentMenu['list']); $menu->list[$parentKey]['href'] = $firstChild['href']; } foreach ($parentMenu['list'] as $childKey => $childMenu) { if ($subMenuTitle == $childMenu['text'] && $parentSrl == 0) { $parentSrl = $childMenu['parent_srl']; } } } // Admin logo, title setup $objConfig = $oModuleModel->getModuleConfig('admin'); $gnbTitleInfo = new stdClass(); $gnbTitleInfo->adminTitle = $objConfig->adminTitle ? $objConfig->adminTitle : 'XE Admin'; $gnbTitleInfo->adminLogo = $objConfig->adminLogo ? $objConfig->adminLogo : 'modules/admin/tpl/img/xe.h1.png'; $browserTitle = ($subMenuTitle ? $subMenuTitle : 'Dashboard') . ' - ' . $gnbTitleInfo->adminTitle; // Get list of favorite $oAdminAdminModel = getAdminModel('admin'); $output = $oAdminAdminModel->getFavoriteList(0, true); Context::set('favorite_list', $output->get('favoriteList')); // Retrieve recent news and set them into context, // move from index method, because use in admin footer $newest_news_url = sprintf("http://news.xpressengine.com/%s/news.php?version=%s&package=%s", _XE_LOCATION_, __XE_VERSION__, _XE_PACKAGE_); $cache_file = sprintf("%sfiles/cache/newest_news.%s.cache.php", _XE_PATH_, _XE_LOCATION_); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < $_SERVER['REQUEST_TIME']) { // Considering if data cannot be retrieved due to network problem, modify filemtime to prevent trying to reload again when refreshing administration page // Ensure to access the administration page even though news cannot be displayed FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($newest_news_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } if (file_exists($cache_file)) { $oXml = new XmlParser(); $buff = $oXml->parse(FileHandler::readFile($cache_file)); $item = $buff->zbxe_news->item; if ($item) { if (!is_array($item)) { $item = array($item); } foreach ($item as $key => $val) { $obj = new stdClass(); $obj->title = $val->body; $obj->date = $val->attrs->date; $obj->url = $val->attrs->url; $news[] = $obj; } Context::set('news', $news); if (isset($news) && is_array($news)) { Context::set('latestVersion', array_shift($news)); } } Context::set('released_version', $buff->zbxe_news->attrs->released_version); Context::set('download_link', $buff->zbxe_news->attrs->download_link); } Context::set('subMenuTitle', $subMenuTitle); Context::set('gnbUrlList', $menu->list); Context::set('parentSrl', $parentSrl); Context::set('gnb_title_info', $gnbTitleInfo); Context::setBrowserTitle($browserTitle); }
function getLicenseFromAgency() { $hostinfo = array($_SERVER['SERVER_ADDR'], $_SERVER['SERVER_NAME'], $_SERVER['HTTP_HOST']); $agency_url = sprintf("http://store.nurigo.net/?module=drmagency&act=getDrmagencyLicense&prodid=%s&hostinfo=%s", $this->getExtMod(), implode(',', $hostinfo)); $cache_file = sprintf("%sfiles/cache/ncart_drm.%s.cache.php", _XE_PATH_, _XE_LOCATION_); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) { FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($agency_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } }
/** * @brief 관리자 메인 페이지 출력 **/ function dispAdminIndex() { /** * 최근 뉴스를 가져와서 세팅 **/ $newest_news_url = sprintf("http://news.xpressengine.com/%s/news.php", Context::getLangType()); $cache_file = sprintf("%sfiles/cache/newest_news.%s.cache.php", _XE_PATH_, Context::getLangType()); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) { // 네트웍 상태로 데이터를 가져오지 못할 상황을 고려해 일단 filemtime을 변경하여 관리자 페이지 refresh시에 다시 읽ㅇ 오지 않도록 함 // 뉴스를 보지는 못하지만 관리자 페이지 접속은 이상없도록 함 FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($newest_news_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } if (file_exists($cache_file)) { $oXml = new XmlParser(); $buff = $oXml->parse(FileHandler::readFile($cache_file)); $item = $buff->zbxe_news->item; if ($item) { if (!is_array($item)) { $item = array($item); } foreach ($item as $key => $val) { $obj = null; $obj->title = $val->body; $obj->date = $val->attrs->date; $obj->url = $val->attrs->url; $news[] = $obj; } Context::set('news', $news); } Context::set('released_version', $buff->zbxe_news->attrs->released_version); Context::set('download_link', $buff->zbxe_news->attrs->download_link); } // DB 정보를 세팅 $db_info = Context::getDBInfo(); Context::set('selected_lang', $db_info->lang_type); // 현재 버젼과 설치 경로 세팅 Context::set('current_version', __ZBXE_VERSION__); Context::set('installed_path', realpath('./')); // 모듈 목록을 가져옴 $oModuleModel =& getModel('module'); $module_list = $oModuleModel->getModuleList(); Context::set('module_list', $module_list); // 애드온 목록을 가져옴 $oAddonModel =& getAdminModel('addon'); $addon_list = $oAddonModel->getAddonList(); Context::set('addon_list', $addon_list); /** * 각종 통계를 추출 **/ $args->date = date("Ymd000000", time() - 60 * 60 * 24); $today = date("Ymd"); // 회원현황 $output = executeQueryArray("admin.getMemberStatus", $args); if ($output->data) { foreach ($output->data as $var) { if ($var->date == $today) { $status->member->today = $var->count; } else { $status->member->yesterday = $var->count; } } } $output = executeQuery("admin.getMemberCount", $args); $status->member->total = $output->data->count; // 문서현황 $output = executeQueryArray("admin.getDocumentStatus", $args); if ($output->data) { foreach ($output->data as $var) { if ($var->date == $today) { $status->document->today = $var->count; } else { $status->document->yesterday = $var->count; } } } $output = executeQuery("admin.getDocumentCount", $args); $status->document->total = $output->data->count; // 댓글현황 $output = executeQueryArray("admin.getCommentStatus", $args); if ($output->data) { foreach ($output->data as $var) { if ($var->date == $today) { $status->comment->today = $var->count; } else { $status->comment->yesterday = $var->count; } } } $output = executeQuery("admin.getCommentCount", $args); $status->comment->total = $output->data->count; // 엮인글현황 $output = executeQueryArray("admin.getTrackbackStatus", $args); if ($output->data) { foreach ($output->data as $var) { if ($var->date == $today) { $status->trackback->today = $var->count; } else { $status->trackback->yesterday = $var->count; } } } $output = executeQuery("admin.getTrackbackCount", $args); $status->trackback->total = $output->data->count; // 첨부파일현황 $output = executeQueryArray("admin.getFileStatus", $args); if ($output->data) { foreach ($output->data as $var) { if ($var->date == $today) { $status->file->today = $var->count; } else { $status->file->yesterday = $var->count; } } } $output = executeQuery("admin.getFileCount", $args); $status->file->total = $output->data->count; // 게시물 신고현황 $output = executeQueryArray("admin.getDocumentDeclaredStatus", $args); if ($output->data) { foreach ($output->data as $var) { if ($var->date == $today) { $status->documentDeclared->today = $var->count; } else { $status->documentDeclared->yesterday = $var->count; } } } $output = executeQuery("admin.getDocumentDeclaredCount", $args); $status->documentDeclared->total = $output->data->count; // 댓글 신고현황 $output = executeQueryArray("admin.getCommentDeclaredStatus", $args); if ($output->data) { foreach ($output->data as $var) { if ($var->date == $today) { $status->commentDeclared->today = $var->count; } else { $status->commentDeclared->yesterday = $var->count; } } } $output = executeQuery("admin.getCommentDeclaredCount", $args); $status->commentDeclared->total = $output->data->count; $site_args->site_srl = 0; $output = executeQuery('module.getSiteInfo', $site_args); Context::set('start_module', $output->data); Context::set('status', $status); Context::set('layout', 'none'); $this->setTemplateFile('index'); }
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; }
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 _doLoginXEJoin($func_arg) { $oMemberModel = getModel('member'); $config = $oMemberModel->getMemberConfig(); $oMemberController = getController('member'); $oLoginXEServerModel = getModel('loginxeclient'); $module_config = $oLoginXEServerModel->getConfig(); // call a trigger (before) $trigger_output = ModuleHandler::triggerCall('member.procMemberInsert', 'before', $config); if (!$trigger_output->toBool()) { return $trigger_output; } // Check if an administrator allows a membership or module config allows external join function if ($module_config->loginxe_joinenable == '') { $module_config->loginxe_joinenable = 'true'; } if ($config->enable_join != 'Y' || $module_config->loginxe_joinenable != 'true') { return new Object(-1, 'msg_signup_disabled'); } if ($oMemberModel->getMemberInfoByEmailAddress($func_arg->email)) { return new Object(-1, 'loginxecli_duplicate_email'); } $args = new stdClass(); list($args->email_id, $args->email_host) = explode('@', $func_arg->email); $args->allow_mailing = "N"; $args->allow_message = "Y"; $args->email_address = $func_arg->email; $args->find_account_answer = md5($func_arg->state) . '@' . $args->email_host; $args->find_account_question = "1"; $args->nick_name = $func_arg->nick_name; while ($oMemberModel->getMemberSrlByNickName($args->nick_name)) { $args->nick_name = $func_arg->nick_name . substr(md5($func_arg->state . rand(0, 9999)), 0, 5); } $args->password = $func_arg->password; // check password strength if (!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength)) { $message = Context::getLang('about_password_strength'); return new Object(-1, $message[$config->password_strength]); } $args->user_id = substr($args->email_id, 0, 20); $useN = FALSE; //if id's first char is number, add n for first char. if (preg_match('/[0-9]/', substr($args->user_id, 0, 1))) { $useN = TRUE; $args->user_id = 'lxe' . substr($args->email_id, 0, 17); } while ($oMemberModel->getMemberInfoByUserID($args->user_id)) { if ($useN) { $args->user_id = 'lxe' . substr($args->email_id, 0, 7) . substr(md5($func_arg->state . rand(0, 9999)), 0, 10); } else { $args->user_id = substr($args->email_id, 0, 10) . substr(md5($func_arg->state . rand(0, 9999)), 0, 10); } } $args->user_name = $func_arg->nick_name; // remove whitespace $checkInfos = array('user_id', 'nick_name', 'email_address'); $replaceStr = array("\r\n", "\r", "\n", " ", "\t", ""); foreach ($checkInfos as $val) { if (isset($args->{$val})) { $args->{$val} = str_replace($replaceStr, '', $args->{$val}); } } $output = $oMemberController->insertMember($args); if (!$output->toBool()) { return $output; } $site_module_info = Context::get('site_module_info'); if ($site_module_info->site_srl > 0) { $columnList = array('site_srl', 'group_srl'); $default_group = $oMemberModel->getDefaultGroup($site_module_info->site_srl, $columnList); if ($default_group->group_srl) { $oMemberModel->addMemberToGroup($args->member_srl, $default_group->group_srl, $site_module_info->site_srl); } } $LoginXEMember = new stdClass(); $LoginXEMember->srl = $args->member_srl; $LoginXEMember->enc_id = $func_arg->enc_id; $LoginXEMember->type = $func_arg->type; $output = executeQuery('loginxeclient.insertLoginxeclientMember', $LoginXEMember); if (!$output->toBool()) { return new Object(-1, $output->message); } $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $args->email_id)); if (!is_dir('./files/cache/tmp')) { FileHandler::makeDir('./files/cache/tmp'); } $ping_header = array(); $ping_header['Pragma'] = 'no-cache'; $ping_header['Accept'] = '*/*'; $request_config = array(); $request_config['ssl_verify_peer'] = false; FileHandler::getRemoteFile($func_arg->profile, $tmp_file, null, 10, 'GET', null, $ping_header, array(), array(), $request_config); if (file_exists($tmp_file)) { $oMemberController->insertProfileImage($args->member_srl, $tmp_file); } if ($config->identifier == 'email_address') { $oMemberController->doLogin($args->email_address); } else { $oMemberController->doLogin($args->user_id); } $_SESSION['rechecked_password_step'] = 'INPUT_DATA'; if ($config->redirect_url) { $this->redirect_Url = $config->redirect_url; } else { $this->redirect_Url = getNotEncodedUrl('', 'act', 'dispMemberModifyInfo'); } FileHandler::removeFile($tmp_file); unset($_SESSION['loginxetemp_joindata']); return new Object(); }
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 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 Save the file and return if a file is requested by http */ function getHtmlPage($path, $caching_interval, $cache_file) { // Verify cache if ($caching_interval > 0 && file_exists($cache_file) && filemtime($cache_file) + $caching_interval * 60 > $_SERVER['REQUEST_TIME']) { $content = FileHandler::readFile($cache_file); } else { FileHandler::getRemoteFile($path, $cache_file); $content = FileHandler::readFile($cache_file); } // Create opage controller $oPageController = getController('page'); // change url of image, css, javascript and so on if the page is from external server $content = $oPageController->replaceSrc($content, $path); // Change the document to utf-8 format $buff = new stdClass(); $buff->content = $content; $buff = Context::convertEncoding($buff); $content = $buff->content; // Extract a title $title = $oPageController->getTitle($content); if ($title) { Context::setBrowserTitle($title); } // Extract header script $head_script = $oPageController->getHeadScript($content); if ($head_script) { Context::addHtmlHeader($head_script); } // Extract content from the body $body_script = $oPageController->getBodyScript($content); if (!$body_script) { $body_script = $content; } return $content; }
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; }
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; }
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; }