function _getWidgetContent() { // Arrange a widget ryeolro if ($this->module_info->mcontent) { $cache_file = sprintf("%sfiles/cache/page/%d.%s.m.cache.php", _XE_PATH_, $this->module_info->module_srl, Context::getLangType()); $interval = (int) $this->module_info->page_caching_interval; if ($interval > 0) { if (!file_exists($cache_file) || filesize($cache_file) < 1) { $mtime = 0; } else { $mtime = filemtime($cache_file); } if ($mtime + $interval * 60 > $_SERVER['REQUEST_TIME']) { $page_content = FileHandler::readFile($cache_file); $page_content = preg_replace('@<\\!--#Meta:@', '<!--Meta:', $page_content); } else { $oWidgetController = getController('widget'); $page_content = $oWidgetController->transWidgetCode($this->module_info->mcontent); FileHandler::writeFile($cache_file, $page_content); } } else { if (file_exists($cache_file)) { FileHandler::removeFile($cache_file); } $page_content = $this->module_info->mcontent; } } else { $page_content = $this->module_info->content; } return $page_content; }
/** * @brief 설치가 이상이 없는지 체크하는 method **/ function checkUpdate() { if (file_exists($this->cache_file)) { FileHandler::removeFile($this->cache_file); } return false; }
/** * @brief 특정 모두의 첨부파일 모두 삭제 **/ function deleteModuleFiles($module_srl) { // 전체 첨부파일 목록을 구함 $args->module_srl = $module_srl; $output = executeQueryArray('file.getModuleFiles', $args); if (!$output) { return $output; } $files = $output->data; // DB에서 삭제 $args->module_srl = $module_srl; $output = executeQuery('file.deleteModuleFiles', $args); if (!$output->toBool()) { return $output; } // 실제 파일 삭제 (일단 약속에 따라서 한번에 삭제) FileHandler::removeDir(sprintf("./files/attach/images/%s/", $module_srl)); FileHandler::removeDir(sprintf("./files/attach/binaries/%s/", $module_srl)); // DB에서 구한 파일 목록을 삭제 $path = array(); $cnt = count($files); for ($i = 0; $i < $cnt; $i++) { $uploaded_filename = $files[$i]->uploaded_filename; FileHandler::removeFile($uploaded_filename); $path_info = pathinfo($uploaded_filename); if (!in_array($path_info['dirname'], $path)) { $path[] = $path_info['dirname']; } } // 해당 글의 첨부파일 디렉토리 삭제 for ($i = 0; $i < count($path); $i++) { FileHandler::removeBlankDir($path[$i]); } return $output; }
function procAuthenticationAdminConfig() { $args = Context::getRequestVars(); if (!trim(strip_tags($args->agreement))) { $agreement_file = _XE_PATH_ . 'files/authentication/agreement_' . Context::get('lang_type') . '.txt'; FileHandler::removeFile($agreement_file); $args->agreement = NULL; } // check agreement value exist if ($args->agreement) { $agreement_file = _XE_PATH_ . 'files/authentication/agreement_' . Context::get('lang_type') . '.txt'; $output = FileHandler::writeFile($agreement_file, $args->agreement); unset($args->agreement); } if (!$args->sender_no) { $args->sender_no = NULL; } if (!$args->message_content) { $args->message_content = NULL; } if (!$args->list) { $args->list = NULL; } if (!$args->cellphone_fieldname) { $args->cellphone_fieldname = NULL; } // save module configuration. $oModuleController = getController('module'); $output = $oModuleController->updateModuleConfig('authentication', $args); $this->setMessage('success_saved'); $redirectUrl = getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAuthenticationAdminConfig'); $this->setRedirectUrl($redirectUrl); }
public function testFileMethods() { $mock = dirname(__FILE__) . '/mock.txt'; $mock2 = dirname(__FILE__) . '/mock2.txt'; touch($mock); // copy file $this->assertTrue(is_readable($mock)); FileHandler::copyFile($mock, $mock2); $this->assertTrue(is_readable($mock2)); // remove file $this->assertTrue(FileHandler::removeFile($mock2)); $this->assertFalse(is_readable($mock2)); $this->assertFalse(FileHandler::removeFile($mock2)); // rename file $this->assertTrue(FileHandler::rename($mock, $mock2)); $this->assertFalse(is_readable($mock)); $this->assertTrue(is_readable($mock2)); $this->assertFalse(FileHandler::rename($mock, $mock2)); // move file $this->assertTrue(FileHandler::rename($mock2, $mock)); $this->assertTrue(is_readable($mock)); $this->assertFalse(is_readable($mock2)); $this->assertTrue(touch($mock2) && is_readable($mock2)); $this->assertTrue(FileHandler::moveFile($mock, $mock2)); $this->assertFalse(is_readable($mock)); $this->assertTrue(is_readable($mock2)); // remove file $this->assertFalse(FileHandler::removeFile($mock)); $this->assertTrue(FileHandler::removeFile($mock2)); $this->assertFalse(is_readable($mock)); $this->assertFalse(is_readable($mock2)); }
function _getWidgetContent() { // Arrange a widget ryeolro if ($this->module_info->mcontent) { $cache_file = sprintf("%sfiles/cache/page/%d.%s.m.cache.php", _XE_PATH_, $this->module_info->module_srl, Context::getLangType()); $interval = (int) $this->module_info->page_caching_interval; if ($interval > 0) { if (!file_exists($cache_file) || filesize($cache_file) < 1) { $mtime = 0; } else { $mtime = filemtime($cache_file); } if ($mtime + $interval * 60 > time()) { $page_content = FileHandler::readFile($cache_file); $page_content = preg_replace('@<\\!--#Meta:@', '<!--Meta:', $page_content); } else { $oWidgetController =& getController('widget'); $page_content = $oWidgetController->transWidgetCode($this->module_info->mcontent); FileHandler::writeFile($cache_file, $page_content); } } else { if (file_exists($cache_file)) { FileHandler::removeFile($cache_file); } $page_content = $this->module_info->mcontent; } } else { preg_match_all('!(<img)([^\\>]*)(widget=)([^\\>]*?)(\\>)!is', $this->module_info->content, $matches); $page_content = ''; for ($i = 0, $c = count($matches[0]); $i < $c; $i++) { $page_content .= preg_replace('/ style\\=\\"([^\\"]+)\\" /i', ' style="overflow:hidden;clear:both;margin:0 0 20px 0; _margin-right:10px;" ', $matches[0][$i]) . "\n\n"; } } return $page_content; }
function procDoNotify() { $oController =& getController('module'); $output = $oController->lock('commentnotify', 400); if (!$output->toBool()) { return; } $deadline = $output->get('deadline'); if (file_exists($this->cachedir . $this->cachefile)) { FileHandler::removeFile($this->cachedir . $this->cachefile); } $oModel =& getModel('tccommentnotify'); $output = $oModel->GetCommentsFromNotifyQueue(); if (!$output->toBool()) { debugPrint("Error"); debugPrint($output); } if ($output->data) { foreach ($output->data as $data) { $this->deleteFromQueue($data->comment_srl); $this->sendCommentNotify($data->comment_srl); } } $oController->unlock('commentnotify', $deadline); }
/** * @brief 일반 요청시 출력 **/ function dispPageIndex() { // 템플릿에서 사용할 변수를 Context::set() if ($this->module_srl) { Context::set('module_srl', $this->module_srl); } // 캐시 파일 지정 $cache_file = sprintf("%sfiles/cache/page/%d.%s.cache.php", _XE_PATH_, $this->module_info->module_srl, Context::getLangType()); $interval = (int) $this->module_info->page_caching_interval; if ($interval > 0) { if (!file_exists($cache_file)) { $mtime = 0; } else { $mtime = filemtime($cache_file); } if ($mtime + $interval * 60 > time()) { $page_content = FileHandler::readFile($cache_file); } else { $oWidgetController =& getController('widget'); $page_content = $oWidgetController->transWidgetCode($this->module_info->content); FileHandler::writeFile($cache_file, $page_content); } } else { if (file_exists($cache_file)) { FileHandler::removeFile($cache_file); } $page_content = $this->module_info->content; } Context::set('module_info', $this->module_info); Context::set('page_content', $page_content); $this->setTemplateFile('content'); }
/** * @brief RSS 전체피드 설정 **/ function procRssAdminInsertConfig() { $oModuleModel =& getModel('module'); $total_config = $oModuleModel->getModuleConfig('rss'); $config_vars = Context::getRequestVars(); $config_vars->feed_document_count = (int) $config_vars->feed_document_count; if (!$config_vars->use_total_feed) { $alt_message = 'msg_invalid_request'; } if (!in_array($config_vars->use_total_feed, array('Y', 'N'))) { $config_vars->open_rss = 'Y'; } if ($config_vars->image || $config_vars->del_image) { $image_obj = $config_vars->image; $config_vars->image = $total_config->image; // 삭제 요청에 대한 변수를 구함 if ($config_vars->del_image == 'Y' || $image_obj) { FileHandler::removeFile($config_vars->image); $config_vars->image = ''; $total_config->image = ''; } // 정상적으로 업로드된 파일이 아니면 무시 if ($image_obj['tmp_name'] && is_uploaded_file($image_obj['tmp_name'])) { // 이미지 파일이 아니어도 무시 (swf는 패스~) $image_obj['name'] = Context::convertEncodingStr($image_obj['name']); if (!preg_match("/\\.(jpg|jpeg|gif|png)\$/i", $image_obj['name'])) { $alt_message = 'msg_rss_invalid_image_format'; } else { // 경로를 정해서 업로드 $path = './files/attach/images/rss/'; // 디렉토리 생성 if (!FileHandler::makeDir($path)) { $alt_message = 'msg_error_occured'; } else { $filename = $path . $image_obj['name']; // 파일 이동 if (!move_uploaded_file($image_obj['tmp_name'], $filename)) { $alt_message = 'msg_error_occured'; } else { $config_vars->image = $filename; } } } } } if (!$config_vars->image && $config_vars->del_image != 'Y') { $config_vars->image = $total_config->image; } $output = $this->setFeedConfig($config_vars); if (!$alt_message) { $alt_message = 'success_updated'; } $alt_message = Context::getLang($alt_message); Context::set('msg', $alt_message); $this->setLayoutPath('./common/tpl'); $this->setLayoutFile('default_layout.html'); $this->setTemplatePath($this->module_path . 'tpl'); $this->setTemplateFile("top_refresh.html"); }
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 캐시 파일 재생성 **/ function recompileCache() { // 레이아웃 캐시 삭제 (수정본은 지우지 않음) $path = './files/cache/layout'; if (!is_dir($path)) { FileHandler::makeDir($path); return; } $directory = dir($path); while ($entry = $directory->read()) { if ($entry == "." || $entry == ".." || preg_match('/\\.html$/i', $entry)) { continue; } FileHandler::removeFile($path . "/" . $entry); } $directory->close(); }
/** * @brief 모든 캐시 파일 재생성 **/ function procAdminRecompileCacheFile() { $oModuleModel =& getModel('module'); $module_list = $oModuleModel->getModuleList(); // 개발 디버그 파일들 제거 FileHandler::removeFile(_XE_PATH_ . 'files/_debug_message.php'); FileHandler::removeFile(_XE_PATH_ . 'files/_debug_db_query.php'); FileHandler::removeFile(_XE_PATH_ . 'files/_db_slow_query.php'); // 각 모듈마다 돌면서 캐시 파일 제거 foreach ($module_list as $module) { $oModule = null; $oModule =& getClass($module->module); if (method_exists($oModule, 'recompileCache')) { $oModule->recompileCache(); } } $this->setMessage('success_updated'); }
/** * @brief 캐시 파일 재생성 **/ function recompileCache() { // 템플릿 컴파일 파일 삭제 FileHandler::removeFilesInDir("./files/cache/template_compiled"); // optimized 파일 삭제 FileHandler::removeFilesInDir("./files/cache/optimized"); // js_filter_compiled 파일 삭제 FileHandler::removeFilesInDir("./files/cache/js_filter_compiled"); // queries 파일 삭제 FileHandler::removeFilesInDir("./files/cache/queries"); // ./files/cache/news* 파일 삭제 $directory = dir(_XE_PATH_ . "files/cache/"); while ($entry = $directory->read()) { if (substr($entry, 0, 11) == 'newest_news') { FileHandler::removeFile("./files/cache/" . $entry); } } $directory->close(); }
/** * @brief 새 쪽지 보여줌 **/ function dispCommunicationNewMessage() { $this->setLayoutFile('popup_layout'); // 로그인이 되어 있지 않으면 오류 표시 if (!Context::get('is_logged')) { return $this->stop('msg_not_logged'); } $logged_info = Context::get('logged_info'); $oCommunicationModel =& getModel('communication'); // 새 쪽지를 가져옴 $message = $oCommunicationModel->getNewMessage(); if ($message) { Context::set('message', $message); } // 플래그 삭제 $flag_path = './files/communication_extra_info/new_message_flags/' . getNumberingPath($logged_info->member_srl); $flag_file = sprintf('%s%s', $flag_path, $logged_info->member_srl); FileHandler::removeFile($flag_file); $this->setTemplateFile('new_message'); }
function procMagiccontentSetup() { $req = Context::getRequestVars(); $widget_sequence = $req->widget_sequence; $is_complete = $req->is_complete; unset($req->is_complete); unset($req->widget_sequence); unset($req->act); foreach ($req as $key => $value) { if ($value == '') { unset($req->{$key}); } } $serialize_data = serialize($req); $args = new stdClass(); $args->data = $serialize_data; $args->widget_sequence = $widget_sequence; $args->is_complete = $is_complete; if ($is_complete == 1) { $dargs = new stdClass(); $dargs->widget_sequence = $widget_sequence; $dargs->is_complete = 0; $output = executeQuery('magiccontent.deleteMagicContentData', $dargs); } $oMagiccontentModel =& getModel('magiccontent'); if ($oMagiccontentModel->getSetupData($widget_sequence, $is_complete) === false) { $args->data_srl = getNextSequence(); $output = executeQuery('magiccontent.insertMagicContentData', $args); } else { $output = executeQuery('magiccontent.updateMagicContentData', $args); } $oCacheHandler = CacheHandler::getInstance('template'); if ($oCacheHandler->isSupport()) { $key = 'widget_cache:' . $widget_sequence; $oCacheHandler->delete($key); } $lang_type = Context::getLangType(); $cache_file = sprintf('%s%d.%s.cache', $this->cache_path, $widget_sequence, $lang_type); FileHandler::removeFile($cache_file); return new Object(0, 'success'); }
/** * @brief 외부페이지 추가 **/ function procOpageAdminInsert() { // module 모듈의 model/controller 객체 생성 $oModuleController =& getController('module'); $oModuleModel =& getModel('module'); // 게시판 모듈의 정보 설정 $args = Context::getRequestVars(); $args->module = 'opage'; $args->mid = $args->opage_name; unset($args->opage_name); // module_srl이 넘어오면 원 모듈이 있는지 확인 if ($args->module_srl) { $module_info = $oModuleModel->getModuleInfoByModuleSrl($args->module_srl); if ($module_info->module_srl != $args->module_srl) { unset($args->module_srl); } } // module_srl의 값에 따라 insert/update if (!$args->module_srl) { $args->module_srl = getNextSequence(); $output = $oModuleController->insertModule($args); $msg_code = 'success_registed'; } else { $output = $oModuleController->updateModule($args); $msg_code = 'success_updated'; // 캐시 파일 삭제 $cache_file = sprintf("./files/cache/opage/%d.cache.php", $module_info->module_srl); if (file_exists($cache_file)) { FileHandler::removeFile($cache_file); } } if (!$output->toBool()) { return $output; } // 등록 성공후 return될 메세지 정리 $this->add("module_srl", $output->get('module_srl')); $this->add("opage", Context::get('opage')); $this->setMessage($msg_code); }
/** * @brief Configure the database */ function dispInstallDBConfig() { // Display check_env if it is not installable if (!self::$checkEnv) { return $this->dispInstallCheckEnv(); } // Delete mod_rewrite check file FileHandler::removeFile(_XE_PATH_ . self::$rewriteCheckFilePath); // Save mod_rewrite check status. if (Context::get('rewrite') === 'Y') { Context::set('use_rewrite', $_SESSION['use_rewrite'] = 'Y'); } // FTP config is disabled in Rhymix. /* if(ini_get('safe_mode') && !Context::isFTPRegisted()) { Context::set('progressMenu', '3'); Context::set('server_ip_address', $_SERVER['SERVER_ADDR']); Context::set('server_ftp_user', get_current_user()); $this->setTemplateFile('ftp'); return; } */ $defaultDatabase = 'mysqli'; $disableList = DB::getDisableList(); if (is_array($disableList)) { foreach ($disableList as $key => $value) { if ($value->db_type == $defaultDatabase) { $defaultDatabase = 'mysql'; break; } } } Context::set('defaultDatabase', $defaultDatabase); Context::set('progressMenu', '4'); Context::set('error_return_url', getNotEncodedUrl('', 'act', Context::get('act'), 'db_type', Context::get('db_type'))); $this->setTemplateFile('db_config'); }
/** * Delete the attachment of a particular module * * @param int $module_srl Sequence of module to delete files * @return Object */ function deleteModuleFiles($module_srl) { // Get a full list of attachments $args = new stdClass(); $args->module_srl = $module_srl; $columnList = array('file_srl', 'uploaded_filename'); $output = executeQueryArray('file.getModuleFiles', $args, $columnList); if (!$output) { return $output; } $files = $output->data; // Remove from the DB $args->module_srl = $module_srl; $output = executeQuery('file.deleteModuleFiles', $args); if (!$output->toBool()) { return $output; } // Remove the file FileHandler::removeDir(sprintf("./files/attach/images/%s/", $module_srl)); FileHandler::removeDir(sprintf("./files/attach/binaries/%s/", $module_srl)); // Remove the file list obtained from the DB $path = array(); $cnt = count($files); for ($i = 0; $i < $cnt; $i++) { $uploaded_filename = $files[$i]->uploaded_filename; FileHandler::removeFile($uploaded_filename); $path_info = pathinfo($uploaded_filename); if (!in_array($path_info['dirname'], $path)) { $path[] = $path_info['dirname']; } } // Remove a file directory of the document for ($i = 0; $i < count($path); $i++) { FileHandler::removeBlankDir($path[$i]); } return $output; }
/** * @brief 레이아웃 미리 보기 **/ function dispLayoutAdminPreview() { $layout_srl = Context::get('layout_srl'); $code = Context::get('code'); $code_css = Context::get('code_css'); if (!$layout_srl || !$code) { return new Object(-1, 'msg_invalid_request'); } // 레이아웃 정보 가져오기 $oLayoutModel =& getModel('layout'); $layout_info = $oLayoutModel->getLayout($layout_srl); if (!$layout_info) { return new Object(-1, 'msg_invalid_request'); } // faceoff 레이아웃일 경우 별도 처리 if ($layout_info && $layout_info->type == 'faceoff') { $oLayoutModel->doActivateFaceOff($layout_info); } // 직접 입력된 CSS 적용 Context::addHtmlHeader("<style type=\"text/css\" charset=\"UTF-8\">" . $code_css . "</style>"); // 레이아웃 정보중 extra_vars의 이름과 값을 $layout_info에 입력 if ($layout_info->extra_var_count) { foreach ($layout_info->extra_var as $var_id => $val) { $layout_info->{$var_id} = $val->value; } } // 레이아웃 정보중 menu를 Context::set if ($layout_info->menu_count) { foreach ($layout_info->menu as $menu_id => $menu) { if (file_exists($menu->php_file)) { @(include $menu->php_file); } Context::set($menu_id, $menu); } } Context::set('layout_info', $layout_info); Context::set('content', Context::getLang('layout_preview_content')); // 코드를 임시로 저장 $edited_layout_file = sprintf('./files/cache/layout/tmp.tpl'); FileHandler::writeFile($edited_layout_file, $code); // 컴파일 $oTemplate =& TemplateHandler::getInstance(); $layout_path = $layout_info->path; $layout_file = 'layout'; $layout_tpl = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file); Context::set('layout', 'none'); // 위젯등을 변환 $oContext =& Context::getInstance(); Context::set('layout_tpl', $layout_tpl); // 임시 파일 삭제 FileHandler::removeFile($edited_layout_file); $this->setTemplateFile('layout_preview'); }
/** * @brief 등록된 메뉴 이미지 제거 **/ function procMenuAdminDeleteButton() { $menu_srl = Context::get('menu_srl'); $menu_item_srl = Context::get('menu_item_srl'); $target = Context::get('target'); $filename = Context::get('filename'); FileHandler::removeFile($filename); $this->add('target', $target); }
/** * Delete thumbnails with subdirectory * @return void */ function deleteThumbnailFile($path) { $directory = dir($path); while ($entry = $directory->read()) { if ($entry != "." && $entry != "..") { if (is_dir($path . "/" . $entry)) { $this->deleteThumbnailFile($path . "/" . $entry); } else { if (!preg_match('/^thumbnail_([^\\.]*)\\.jpg$/i', $entry)) { continue; } FileHandler::removeFile($path . '/' . $entry); } } } $directory->close(); }
/** * Delete the signature file * * @param string $member_srl * * @return void */ function delSignature($member_srl) { $filename = sprintf('files/member_extra_info/signature/%s%d.gif', getNumberingPath($member_srl), $member_srl); FileHandler::removeFile($filename); }
function deleteMaterial($material_srl) { if (strpos($material_srl, ',') === false) { $args->material_srl = $material_srl; } else { $args->material_srls = $material_srl; } $output = executeQuery('material.deleteMaterial', $args); // delete thumnail image $oFileModel =& getModel('file'); $file_list = array(); if (strpos(',', $material_srl) === false) { $file_list = $oFileModel->getFiles($material_srl); } else { $material_srls = explode(',', $material_srl); foreach ($material_srls as $srl) { $files = $oFileModel->getFiles($srl); if ($files) { $file_list = array_merge($file_list, $files); } } } if (count($file_list)) { foreach ($file_list as $k => $file) { $ext = substr(strrchr($file->source_filename, '.'), 1); $_filename = sprintf("%s%s.%%s.%s", preg_replace("/\\/[^\\/]*\$/", "/", $file->uploaded_filename), $material_srl, $ext); $s_filename = sprintf($_filename, 'S'); $l_filename = sprintf($_filename, 'L'); FileHandler::removeFile($s_filename); FileHandler::removeFile($l_filename); } } $obj->document_srl = $material_srl; // trigger 호출 (after) if ($output->toBool()) { $trigger_output = ModuleHandler::triggerCall('material.deleteMaterial', 'after', $obj); if (!$trigger_output->toBool()) { return $trigger_output; } } return $output; }
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; }
/** * Update product images * @param Product $product * @return bool * @throws ShopException */ public function updateProductImages(Product &$product) { $args = new stdClass(); $args->image_srls = $product->delete_images; $shopModel = getModel('shop'); $imageRepository = $shopModel->getImageRepository(); $this->updatePrimaryImage($product); if (isset($args->image_srls)) { $delete_images = $imageRepository->getImages($args->image_srls); if (in_array($product->primary_image, $args->image_srls)) { $this->setNewPrimaryImage($product); } foreach ($delete_images as $delete_image) { $path = sprintf('./files/attach/images/shop/%d/product-images/%d/%s', $product->module_srl, $product->product_srl, $delete_image->filename); FileHandler::removeFile($path); } $output = executeQuery('shop.deleteProductImages', $args); if (!$output->toBool()) { throw new ShopException($output->getMessage(), $output->getError()); } } $this->insertProductImages($product); return TRUE; }
/** * @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); }
function deleteModuleFileBox($vars) { // delete real file $oModuleModel =& getModel('module'); $output = $oModuleModel->getModuleFileBox($vars->module_filebox_srl); FileHandler::removeFile($output->data->filename); $args->module_filebox_srl = $vars->module_filebox_srl; return executeQuery('module.deleteModuleFileBox', $args); }
public function procMemberAdminInsertSignupConfig() { $oMemberModel = getModel('member'); $oModuleController = getController('module'); $args = Context::gets('limit_day', 'limit_day_description', 'agreement', 'redirect_url', 'profile_image', 'profile_image_max_width', 'profile_image_max_height', 'image_name', 'image_name_max_width', 'image_name_max_height', 'image_mark', 'image_mark_max_width', 'image_mark_max_height', 'signature_editor_skin', 'sel_editor_colorset'); $list_order = Context::get('list_order'); $usable_list = Context::get('usable_list'); $all_args = Context::getRequestVars(); $args->limit_day = (int) $args->limit_day; if (!trim(strip_tags($args->agreement))) { $agreement_file = _XE_PATH_ . 'files/member_extra_info/agreement_' . Context::get('lang_type') . '.txt'; FileHandler::removeFile($agreement_file); $args->agreement = NULL; } if ($args->redirect_url) { $oModuleModel = getModel('module'); $redirectModuleInfo = $oModuleModel->getModuleInfoByModuleSrl($args->redirect_url, array('mid')); if (!$redirectModuleInfo) { return new Object('-1', 'msg_exist_selected_module'); } $args->redirect_url = Context::getDefaultUrl() . $redirectModuleInfo->mid; } $args->profile_image = $args->profile_image ? 'Y' : 'N'; $args->image_name = $args->image_name ? 'Y' : 'N'; $args->image_mark = $args->image_mark ? 'Y' : 'N'; $args->signature = $args->signature != 'Y' ? 'N' : 'Y'; $args->identifier = $all_args->identifier; // set default $all_args->is_nick_name_public = 'Y'; $all_args->is_find_account_question_public = 'N'; // signupForm global $lang; $signupForm = array(); $items = array('user_id', 'password', 'user_name', 'nick_name', 'email_address', 'find_account_question', 'homepage', 'blog', 'birthday', 'signature', 'profile_image', 'image_name', 'image_mark', 'profile_image_max_width', 'profile_image_max_height', 'image_name_max_width', 'image_name_max_height', 'image_mark_max_width', 'image_mark_max_height'); $mustRequireds = array('email_address', 'nick_name', 'password', 'find_account_question'); $extendItems = $oMemberModel->getJoinFormList(); foreach ($list_order as $key) { $signupItem = new stdClass(); $signupItem->isIdentifier = $key == $all_args->identifier; $signupItem->isDefaultForm = in_array($key, $items); $signupItem->name = $key; if (!in_array($key, $items)) { $signupItem->title = $key; } else { $signupItem->title = $lang->{$key}; } $signupItem->mustRequired = in_array($key, $mustRequireds); $signupItem->imageType = strpos($key, 'image') !== false; $signupItem->required = $all_args->{$key} == 'required' || $signupItem->mustRequired || $signupItem->isIdentifier; $signupItem->isUse = in_array($key, $usable_list) || $signupItem->required; $signupItem->isPublic = $all_args->{'is_' . $key . '_public'} == 'Y' && $signupItem->isUse ? 'Y' : 'N'; if ($signupItem->imageType) { $signupItem->max_width = $all_args->{$key . '_max_width'}; $signupItem->max_height = $all_args->{$key . '_max_height'}; } // set extends form if (!$signupItem->isDefaultForm) { $extendItem = $extendItems[$all_args->{$key . '_member_join_form_srl'}]; $signupItem->type = $extendItem->column_type; $signupItem->member_join_form_srl = $extendItem->member_join_form_srl; $signupItem->title = $extendItem->column_title; $signupItem->description = $extendItem->description; // check usable value change, required/option if ($signupItem->isUse != ($extendItem->is_active == 'Y') || $signupItem->required != ($extendItem->required == 'Y')) { unset($update_args); $update_args = new stdClass(); $update_args->member_join_form_srl = $extendItem->member_join_form_srl; $update_args->is_active = $signupItem->isUse ? 'Y' : 'N'; $update_args->required = $signupItem->required ? 'Y' : 'N'; $update_output = executeQuery('member.updateJoinForm', $update_args); } unset($extendItem); } $signupForm[] = $signupItem; } $args->signupForm = $signupForm; // create Ruleset $this->_createSignupRuleset($signupForm, $args->agreement); $this->_createLoginRuleset($args->identifier); $this->_createFindAccountByQuestion($args->identifier); // check agreement value exist if ($args->agreement) { $agreement_file = _XE_PATH_ . 'files/member_extra_info/agreement_' . Context::get('lang_type') . '.txt'; $output = FileHandler::writeFile($agreement_file, $args->agreement); unset($args->agreement); } $output = $oModuleController->updateModuleConfig('member', $args); // default setting end $this->setMessage('success_updated'); $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminSignUpConfig'); $this->setRedirectUrl($returnUrl); }
/** * display a new message * @return void|Object (void : success, Object : fail) */ function dispCommunicationNewMessage() { $this->setLayoutPath('./common/tpl/'); $this->setLayoutFile('popup_layout'); // Error appears if not logged-in if (!Context::get('is_logged')) { return $this->stop('msg_not_logged'); } $logged_info = Context::get('logged_info'); $oCommunicationModel = getModel('communication'); // get a new message $columnList = array('message_srl', 'member_srl', 'nick_name', 'title', 'content', 'sender_srl'); $message = $oCommunicationModel->getNewMessage($columnList); if ($message) { stripEmbedTagForAdmin($message->content, $message->sender_srl); Context::set('message', $message); } // Delete a flag $flag_path = './files/communication_extra_info/new_message_flags/' . getNumberingPath($logged_info->member_srl); $flag_file = sprintf('%s%s', $flag_path, $logged_info->member_srl); FileHandler::removeFile($flag_file); $this->setTemplateFile('new_message'); }
/** * Remove add-on information in the virtual site * * @param int $site_srl Site srl * @return void **/ function removeAddonConfig($site_srl) { $addon_path = _XE_PATH_ . 'files/cache/addons/'; $addon_file = $addon_path . $site_srl . '.acivated_addons.cache.php'; if (file_exists($addon_file)) { FileHandler::removeFile($addon_file); } $args->site_srl = $site_srl; executeQuery('addon.deleteSiteAddons', $args); }