示例#1
1
 /**
  * @brief Get the points
  */
 function getPoint($member_srl, $from_db = false)
 {
     $member_srl = abs($member_srl);
     // Get from instance memory
     if (!$from_db && $this->pointList[$member_srl]) {
         return $this->pointList[$member_srl];
     }
     // Get from file cache
     $path = sprintf(_XE_PATH_ . 'files/member_extra_info/point/%s', getNumberingPath($member_srl));
     $cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl);
     if (!$from_db && file_exists($cache_filename)) {
         return $this->pointList[$member_srl] = trim(FileHandler::readFile($cache_filename));
     }
     // Get from the DB
     $args = new stdClass();
     $args->member_srl = $member_srl;
     $output = executeQuery('point.getPoint', $args);
     if (isset($output->data->member_srl)) {
         $point = (int) $output->data->point;
         $this->pointList[$member_srl] = $point;
         if (!is_dir($path)) {
             FileHandler::makeDir($path);
         }
         FileHandler::writeFile($cache_filename, $point);
         return $point;
     }
     return 0;
 }
示例#2
0
 /**
  * Returns the path to the thumbnail image
  *
  * If a thumbnail does not already exist, it is generated,
  * written to disk and then the new path is returned
  *
  * @param int    $width
  * @param int    $height
  * @param string $thumbnail_type
  * @return mixed|string
  */
 public function getThumbnailPath($width = 80, $height = 0, $thumbnail_type = '')
 {
     // If signiture height setting is omitted, create a square
     if (!$height) {
         $height = $width;
     }
     // get thumbail generation info on the doc module configuration.
     if (!in_array($thumbnail_type, array('crop', 'ratio'))) {
         $thumbnail_type = 'ratio';
     }
     // Define thumbnail information
     $thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($this->unique_identifier, 3));
     $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
     // If thumbnail was already created, return path to it
     if (is_file($thumbnail_file)) {
         return $thumbnail_file;
     }
     // Retrieve info about original image: path and extension
     $source_file = $this->full_image_path;
     $ext = pathinfo($source_file, PATHINFO_EXTENSION);
     // Create thumbnail
     $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, $ext, $thumbnail_type);
     if ($output) {
         return $thumbnail_file;
     } else {
         return '';
     }
 }
示例#3
0
/**
 * @brief If member_srl exists in the div or span, replace to image name or nick image for each member_srl
 * */
function memberTransImageName($matches)
{
    // If member_srl < 0, then return text only in the body
    $member_srl = $matches[3];
    if ($member_srl < 0) {
        return $matches[5];
    }
    // If member_srl=o(not a member), return the entire body
    if (!$member_srl) {
        return $matches[0];
    }
    $oMemberModel = getModel('member');
    $nick_name = $matches[5];
    // Initialize global variable for cache
    if (!isset($GLOBALS['_transImageNameList'][$member_srl])) {
        $GLOBALS['_transImageNameList'][$member_srl] = new stdClass();
    }
    $_tmp =& $GLOBALS['_transImageNameList'][$member_srl];
    // If pre-defined data in the global variables, return it
    if (!$_tmp->cached) {
        $_tmp->cached = true;
        $image_name_file = sprintf('files/member_extra_info/image_name/%s%d.gif', getNumberingPath($member_srl), $member_srl);
        $image_mark_file = sprintf('files/member_extra_info/image_mark/%s%d.gif', getNumberingPath($member_srl), $member_srl);
        if (file_exists(_XE_PATH_ . $image_name_file)) {
            $_tmp->image_name_file = $image_name_file . '?' . date('YmdHis', filemtime(_XE_PATH_ . $image_name_file));
            $image_name_file = $_tmp->image_name_file;
        } else {
            $image_name_file = '';
        }
        if (file_exists(_XE_PATH_ . $image_mark_file)) {
            $_tmp->image_mark_file = $image_mark_file . '?' . date('YmdHis', filemtime(_XE_PATH_ . $image_mark_file));
            $image_mark_file = $_tmp->image_mark_file;
        } else {
            $image_mark_file = '';
        }
        $site_module_info = Context::get('site_module_info');
        $group_image = $oMemberModel->getGroupImageMark($member_srl, $site_module_info->site_srl);
        $_tmp->group_image = $group_image;
    } else {
        $group_image = $_tmp->group_image;
        $image_name_file = $_tmp->image_name_file;
        $image_mark_file = $_tmp->image_mark_file;
    }
    // If image name and mark doesn't exist, set the original information
    if (!$image_name_file && !$image_mark_file && !$group_image) {
        return $matches[0];
    }
    // check member_config
    $config = $oMemberModel->getMemberConfig();
    if ($config->image_name == 'Y' && $image_name_file) {
        $nick_name = sprintf('<img src="%s%s" alt="id: %s" title="id: %s" style="border:0;vertical-align:middle;margin-right:3px" />', Context::getRequestUri(), $image_name_file, strip_tags($nick_name), strip_tags($nick_name));
    }
    if ($config->image_mark == 'Y' && $image_mark_file) {
        $nick_name = sprintf('<img src="%s%s" alt="id: %s" title="id : %s" style="border:0;vertical-align:middle;margin-right:3px"/>%s', Context::getRequestUri(), $image_mark_file, strip_tags($nick_name), strip_tags($nick_name), $nick_name);
    }
    if ($group_image) {
        $nick_name = sprintf('<img src="%s" style="border:0;max-height:16px;vertical-align:middle;margin-right:3px" alt="%s" title="%s" />%s', $group_image->src, $group_image->title, $group_image->description, $nick_name);
    }
    return preg_replace('/' . preg_quote($matches[5], '/') . '<\\/' . $matches[6] . '>$/', '', $matches[0]) . $nick_name . '</' . $matches[6] . '>';
}
示例#4
0
 /**
  * Returns path to full size (original) product image
  *
  * @return string
  */
 public function getFullPath()
 {
     $image_path = "./files/attach/images/shop/{$this->module_srl}/product-images/{$this->product_srl}/{$this->filename}";
     if (is_file($image_path)) {
         return $image_path;
     }
     return "./files/attach/shop/" . getNumberingPath($this->module_srl, 3) . "/img/missingProduct.png";
 }
/**
 * @brief div 또는 span에 member_번호 가 있을때 해당 회원 번호에 맞는 이미지이름이나 닉이미지를 대체
 **/
function memberTransImageName($matches)
{
    // 회원번호를 추출하여 0보다 찾으면 본문중 text만 return
    $member_srl = $matches[3];
    if ($member_srl < 0) {
        return $matches[5];
    }
    $site_module_info = Context::get('site_module_info');
    $oMemberModel =& getModel('member');
    $group_image = $oMemberModel->getGroupImageMark($member_srl, $site_module_info->site_srl);
    // 회원이 아닐경우(member_srl = 0) 본문 전체를 return
    $nick_name = $matches[5];
    if (!$member_srl) {
        return $matches[0];
    }
    // 전역변수에 미리 설정한 데이터가 있다면 그걸 return
    if (!$GLOBALS['_transImageNameList'][$member_srl]->cached) {
        $GLOBALS['_transImageNameList'][$member_srl]->cached = true;
        $image_name_file = sprintf('files/member_extra_info/image_name/%s%d.gif', getNumberingPath($member_srl), $member_srl);
        $image_mark_file = sprintf('files/member_extra_info/image_mark/%s%d.gif', getNumberingPath($member_srl), $member_srl);
        if (file_exists($image_name_file)) {
            $GLOBALS['_transImageNameList'][$member_srl]->image_name_file = $image_name_file;
        } else {
            $image_name_file = '';
        }
        if (file_exists($image_mark_file)) {
            $GLOBALS['_transImageNameList'][$member_srl]->image_mark_file = $image_mark_file;
        } else {
            $image_mark_file = '';
        }
    } else {
        $image_name_file = $GLOBALS['_transImageNameList'][$member_srl]->image_name_file;
        $image_mark_file = $GLOBALS['_transImageNameList'][$member_srl]->image_mark_file;
    }
    // 이미지이름이나 마크가 없으면 원본 정보를 세팅
    if (!$image_name_file && !$image_mark_file && !$group_image) {
        return $matches[0];
    }
    if ($image_name_file) {
        $nick_name = sprintf('<img src="%s%s" border="0" alt="id: %s" title="id: %s" style="vertical-align:middle;margin-right:3px" />', Context::getRequestUri(), $image_name_file, strip_tags($nick_name), strip_tags($nick_name));
    }
    if ($image_mark_file) {
        $nick_name = sprintf('<img src="%s%s" border="0" alt="id: %s" title="id : %s" style="vertical-align:middle;margin-right:3px"/>%s', Context::getRequestUri(), $image_mark_file, strip_tags($nick_name), strip_tags($nick_name), $nick_name);
    }
    if ($group_image) {
        $nick_name = sprintf('<img src="%s" border="0" style="vertical-align:middle;margin-right:3px"/>%s', $group_image->src, $nick_name);
    }
    $orig_text = preg_replace('/' . preg_quote($matches[5], '/') . '<\\/' . $matches[6] . '>$/', '', $matches[0]);
    return $orig_text . $nick_name . '</' . $matches[6] . '>';
}
示例#6
0
 /**
  * @brief 포인트를 구해옴
  **/
 function getPoint($member_srl, $from_db = false)
 {
     $member_srl = abs($member_srl);
     $path = sprintf('./files/member_extra_info/point/%s', getNumberingPath($member_srl));
     if (!is_dir($path)) {
         FileHandler::makeDir($path);
     }
     $cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl);
     if (!$from_db && file_exists($cache_filename)) {
         return trim(FileHandler::readFile($cache_filename));
     }
     // DB에서 가져옴
     $args->member_srl = $member_srl;
     $output = executeQuery('point.getPoint', $args);
     $point = (int) $output->data->point;
     FileHandler::writeFile($cache_filename, $point);
     return $point;
 }
 /**
  * @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');
 }
 private function insertProfileImageFromUrl($member_srl, $url)
 {
     $oModuleModel =& getModel('module');
     $config = $oModuleModel->getModuleConfig('member');
     $max_width = $config->profile_image_max_width;
     if (!$max_width) {
         $max_width = "80";
     }
     //default 90
     $max_height = $config->profile_image_max_height;
     if (!$max_height) {
         $max_height = "80";
     }
     //default 20
     $target_path = sprintf('files/member_extra_info/profile_image/%s', getNumberingPath($member_srl));
     $target_tmpfile = $target_path . "sample.jpg";
     FileHandler::makeDir($target_path);
     //지정된 URL 로부터 프로필 이미지 가져오기
     if (file_exists($target_tmpfile)) {
         unlink($target_tmpfile);
     }
     $this->getProfileImageFromUrl($url, $target_tmpfile);
     list($width, $height, $type, $attrs) = @getimagesize($target_tmpfile);
     if ($type == 3) {
         $ext = 'png';
     } elseif ($type == 2) {
         $ext = 'jpg';
     } else {
         $ext = 'gif';
     }
     $target_filename = sprintf('%s%d.%s', $target_path, $member_srl, $ext);
     $target_filename_mask = sprintf('%s%d.%s', $target_path, $member_srl, '*');
     array_map('unlink', glob($target_filename_mask));
     if ($width > $max_width || $height > $max_height || !$type != 1) {
         FileHandler::createImageFile($target_tmpfile, $target_filename, $max_width, $max_height, $ext);
     } else {
         @copy($target_tmpfile, $target_filename);
     }
     unlink($target_tmpfile);
 }
 function getThumbnail($file_srl = null, $width = 80, $height = 0, $thumbnail_type = 'crop')
 {
     $oFileModel = getModel('file');
     if (!$file_srl) {
         return;
     }
     if (!$height) {
         $height = $width;
     }
     // Define thumbnail information
     $thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($file_srl, 3));
     $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
     $thumbnail_url = Context::getRequestUri() . $thumbnail_file;
     // Return false if thumbnail file exists and its size is 0. Otherwise, return its path
     if (file_exists($thumbnail_file)) {
         if (filesize($thumbnail_file) < 1) {
             return false;
         } else {
             return $thumbnail_url;
         }
     }
     // Target File
     $source_file = NULL;
     $file = $oFileModel->getFile($file_srl);
     if ($file) {
         $source_file = $file->uploaded_filename;
     }
     if ($source_file) {
         $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
     }
     // Return its path if a thumbnail is successfully genetated
     if ($output) {
         return $thumbnail_url;
     } else {
         FileHandler::writeFile($thumbnail_file, '', 'w');
     }
     return;
 }
示例#10
0
 /**
  * Delete a category
  * @param int $category_srl
  * @return object
  */
 function deleteCategory($category_srl)
 {
     $args = new stdClass();
     $args->category_srl = $category_srl;
     $oDocumentModel = getModel('document');
     $category_info = $oDocumentModel->getCategory($category_srl);
     // Display an error that the category cannot be deleted if it has a child
     $output = executeQuery('document.getChildCategoryCount', $args);
     if (!$output->toBool()) {
         return $output;
     }
     if ($output->data->count > 0) {
         return new Object(-1, 'msg_cannot_delete_for_child');
     }
     // Delete a category information
     $output = executeQuery('document.deleteCategory', $args);
     if (!$output->toBool()) {
         return $output;
     }
     $this->makeCategoryFile($category_info->module_srl);
     // remove cache
     $page = 0;
     while (true) {
         $args = new stdClass();
         $args->category_srl = $category_srl;
         $args->list_count = 100;
         $args->page = ++$page;
         $output = executeQuery('document.getDocumentList', $args, array('document_srl'));
         if ($output->data == array()) {
             break;
         }
         foreach ($output->data as $val) {
             Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($val->document_srl) . $val->document_srl);
         }
     }
     // Update category_srl of the documents in the same category to 0
     $args = new stdClass();
     $args->target_category_srl = 0;
     $args->source_category_srl = $category_srl;
     $output = executeQuery('document.updateDocumentCategory', $args);
     return $output;
 }
示例#11
0
 /**
  * @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);
 }
示例#12
0
 /**
  * @brief 포인트 설정
  **/
 function setPoint($member_srl, $point, $mode = null)
 {
     $member_srl = abs($member_srl);
     $mode_arr = array('add', 'minus', 'update', 'signup');
     if (!$mode || !in_array($mode, $mode_arr)) {
         $mode = 'update';
     }
     // 설정 정보 가져오기
     $oMemberModel =& getModel('member');
     $oModuleModel =& getModel('module');
     $oPointModel =& getModel('point');
     $config = $oModuleModel->getModuleConfig('point');
     // 기존 포인트 정보를 구함
     $prev_point = $oPointModel->getPoint($member_srl, true);
     $prev_level = $oPointModel->getLevel($prev_point, $config->level_step);
     // 포인트 변경
     $args->member_srl = $member_srl;
     $args->point = $prev_point;
     switch ($mode) {
         case 'add':
             $args->point += $point;
             break;
         case 'minus':
             $args->point -= $point;
             break;
         case 'update':
             $args->point = $point;
             break;
         case 'signup':
             $args->point = $point;
             break;
     }
     if ($args->point < 0) {
         $args->point = 0;
     }
     $point = $args->point;
     // 포인트가 있으면 update, 없으면 insert
     $oPointModel =& getModel('point');
     if ($oPointModel->isExistsPoint($member_srl)) {
         executeQuery("point.updatePoint", $args);
     } else {
         executeQuery("point.insertPoint", $args);
     }
     // 새로운 레벨을 구함
     $level = $oPointModel->getLevel($point, $config->level_step);
     // 기존 레벨과 새로운 레벨이 다르면 포인트 그룹 설정 시도
     if ($level != $prev_level) {
         // 현재 포인트 대비하여 레벨을 계산하고 레벨에 맞는 그룹 설정을 체크
         $point_group = $config->point_group;
         // 포인트 그룹 정보가 있을때 시행
         if ($point_group && is_array($point_group) && count($point_group)) {
             // 기본 그룹을 구함
             $default_group = $oMemberModel->getDefaultGroup();
             // 제거될 그룹과 새로 부여 받을 그룹을 구함
             $del_group_list = array();
             $new_group_srls = array();
             asort($point_group);
             // 포인트 그룹 설정을 돌면서 현재 레벨까지 체크
             foreach ($point_group as $group_srl => $target_level) {
                 if ($config->group_reset != 'N') {
                     $del_group_list[] = $group_srl;
                 }
                 if ($target_level <= $level) {
                     $new_group_srls[] = $group_srl;
                 }
             }
             // 만약 새로운 그룹이 없다면 기본 그룹을 부여 받음
             if (!$new_group_srls[0]) {
                 $new_group_srls[0] = $default_group->group_srl;
             }
             // 연동 그룹 제거
             if ($config->group_reset != 'N' && $del_group_list && count($del_group_list)) {
                 $del_group_args->member_srl = $member_srl;
                 $del_group_args->group_srl = implode(',', $del_group_list);
                 $del_group_output = executeQuery('point.deleteMemberGroup', $del_group_args);
             }
             // 새로운 그룹을 부여
             foreach ($new_group_srls as $group_srl) {
                 $new_group_args->member_srl = $member_srl;
                 $new_group_args->group_srl = $group_srl;
                 executeQuery('member.addMemberToGroup', $new_group_args);
             }
         }
     }
     // 캐시 설정
     $cache_path = sprintf('./files/member_extra_info/point/%s/', getNumberingPath($member_srl));
     FileHandler::makedir($cache_path);
     $cache_filename = sprintf('%s%d.cache.txt', $cache_path, $member_srl);
     FileHandler::writeFile($cache_filename, $point);
     return $output;
 }
示例#13
0
 /**
  * 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');
 }
示例#14
0
 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;
 }
示例#15
0
 /**
  * Delete all documents of the module
  * @param int $module_srl
  * @return object
  */
 function deleteModuleDocument($module_srl)
 {
     $args = new stdClass();
     $args->module_srl = $module_srl;
     $oDocumentModel = getModel('document');
     $args->module_srl = $module_srl;
     $document_list = $oDocumentModel->getDocumentList($args);
     $documents = $document_list->data;
     $output = executeQuery('document.deleteModuleDocument', $args);
     if (is_array($documents)) {
         foreach ($documents as $oDocument) {
             $document_srl_list[] = $oDocument->document_srl;
         }
     }
     //remove from cache
     $oCacheHandler = CacheHandler::getInstance('object');
     if ($oCacheHandler->isSupport()) {
         if (is_array($document_srl_list)) {
             foreach ($document_srl_list as $document_srl) {
                 $cache_key_item = 'document_item:' . getNumberingPath($document_srl) . $document_srl;
                 $oCacheHandler->delete($cache_key_item);
             }
         }
     }
     return $output;
 }
 function procMaterialInsert()
 {
     $var = Context::getRequestVars();
     if (!$var->auth || !$var->type) {
         return new Object(-1, 'msg_not_permitted');
     }
     $oMaterialModel =& getModel('material');
     $member_srl = $oMaterialModel->getMemberSrlByAuth($var->auth);
     if (!$member_srl) {
         return new Object(-1, 'msg_invalid_request');
     }
     if ($var->type == 'img') {
         if ($var->image) {
             $path = sprintf('files/cache/material/tmp/%s/', getNumberingPath($member_srl));
             $filename = basename($var->image);
             $file = $path . $filename;
             FileHandler::makeDir($path);
             FileHandler::getRemoteFile($var->image, $file);
             if (file_exists($file)) {
                 $material_srl = getNextSequence();
                 $ext = substr(strrchr($filename, '.'), 1);
                 $ext = array_shift(explode('?', $ext));
                 // insert file module
                 $file_info = array();
                 $file_info['tmp_name'] = $file;
                 $file_info['name'] = sprintf("%s.%s", $material_srl, $ext);
                 $oFileController =& getController('file');
                 $output = $oFileController->insertFile($file_info, $member_srl, $material_srl, 0, true);
                 if (!$output->toBool()) {
                     return $output;
                 }
                 //set File valid
                 $oFileController->setFilesValid($output->get('upload_target_srl'));
                 // delete temp file
                 FileHandler::removeFile($filename);
                 $uploaded_filename = $output->get('uploaded_filename');
                 $_filename = sprintf("%s%s.%%s.%s", preg_replace("/\\/[^\\/]*\$/", "/", $uploaded_filename), $material_srl, $ext);
                 $s_filename = sprintf($_filename, 'S');
                 list($w, $h) = @getimagesize($uploaded_filename);
                 if ($w > $this->thum['S']['width'] || $h > $this->thum['S']['height']) {
                     FileHandler::createImageFile($uploaded_filename, $s_filename, $this->thum['S']['width'], $h, '', 'ratio');
                 } else {
                     FileHandler::copyFile($uploaded_filename, $s_filename);
                 }
                 // replace image src
                 $var->content = str_replace($var->image, $uploaded_filename, $var->content);
             } else {
                 $var->image = null;
             }
         } else {
             return new Object(-1, 'msg_not_select_image');
         }
     }
     // there is no file or copy failed
     if ($var->type == 'img' && !$var->image) {
         return new Object(-1, 'msg_fail_image_save');
     }
     $args->material_srl = $material_srl ? $material_srl : getNextSequence();
     $args->member_srl = $member_srl;
     $args->type = $var->type;
     $args->content = $var->content;
     $output = executeQuery('material.insertMaterial', $args);
     return $output;
 }
 /**
  * @brief Tool dashboard
  **/
 function dispTextyleToolDashboard()
 {
     set_include_path(_XE_PATH_ . "libs/PEAR");
     require_once 'PEAR.php';
     require_once 'HTTP/Request.php';
     $oCounterModel =& getModel('counter');
     $oDocumentModel =& getModel('document');
     $oCommentModel =& getModel('comment');
     $oTextyleModel =& getModel('textyle');
     $url = sprintf("http://news.textyle.kr/%s/news.php", Context::getLangType());
     $cache_file = sprintf("%sfiles/cache/textyle/news/%s%s.cache.xml", _XE_PATH_, getNumberingPath($this->module_srl), Context::getLangType());
     if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) {
         FileHandler::writeFile($cache_file, '');
         if (__PROXY_SERVER__ !== null) {
             $oRequest = new HTTP_Request(__PROXY_SERVER__);
             $oRequest->setMethod('POST');
             $oRequest->_timeout = $timeout;
             $oRequest->addPostData('arg', serialize(array('Destination' => $url)));
         } else {
             $oRequest = new HTTP_Request($url);
             if (!$content_type) {
                 $oRequest->addHeader('Content-Type', 'text/html');
             } else {
                 $oRequest->addHeader('Content-Type', $content_type);
             }
             if (count($headers)) {
                 foreach ($headers as $key => $val) {
                     $oRequest->addHeader($key, $val);
                 }
             }
             $oRequest->_timeout = 2;
         }
         if (isSiteID($this->textyle->domain)) {
             $oRequest->addHeader('REQUESTURL', Context::getRequestUri() . $this->textyle->domain);
         } else {
             $oRequest->addHeader('REQUESTURL', $this->textyle->domain);
         }
         $oResponse = $oRequest->sendRequest();
         $body = $oRequest->getResponseBody();
         FileHandler::writeFile($cache_file, $body);
     }
     if (file_exists($cache_file)) {
         $oXml = new XmlParser();
         $buff = $oXml->parse(FileHandler::readFile($cache_file));
         $item = $buff->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);
         }
     }
     $time = time();
     $w = date("D");
     while (date("D", $time) != "Sun") {
         $time += 60 * 60 * 24;
     }
     $time -= 60 * 60 * 24;
     while (date("D", $time) != "Sun") {
         $thisWeek[] = date("Ymd", $time);
         $time -= 60 * 60 * 24;
     }
     $thisWeek[] = date("Ymd", $time);
     asort($thisWeek);
     $thisWeekCounter = $oCounterModel->getStatus($thisWeek, $this->site_srl);
     $time -= 60 * 60 * 24;
     while (date("D", $time) != "Sun") {
         $lastWeek[] = date("Ymd", $time);
         $time -= 60 * 60 * 24;
     }
     $lastWeek[] = date("Ymd", $time);
     asort($lastWeek);
     $lastWeekCounter = $oCounterModel->getStatus($lastWeek, $this->site_srl);
     $max = 0;
     foreach ($thisWeek as $day) {
         $v = (int) $thisWeekCounter[$day]->unique_visitor;
         if ($v && $v > $max) {
             $max = $v;
         }
         $status->week[date("D", strtotime($day))]->this = $v;
     }
     foreach ($lastWeek as $day) {
         $v = (int) $lastWeekCounter[$day]->unique_visitor;
         if ($v && $v > $max) {
             $max = $v;
         }
         $status->week[date("D", strtotime($day))]->last = $v;
     }
     $status->week_max = $max;
     $idx = 0;
     foreach ($status->week as $key => $val) {
         $_item[] = sprintf("<item id=\"%d\" name=\"%s\" />", $idx, $thisWeek[$idx]);
         $_thisWeek[] = $val->this;
         $_lastWeek[] = $val->last;
         $idx++;
     }
     $buff = '<?xml version="1.0" encoding="utf-8" ?><Graph><gdata title="Textyle Counter" id="data2"><fact>' . implode('', $_item) . '</fact><subFact>';
     $buff .= '<item id="0"><data name="' . Context::getLang('this_week') . '">' . implode('|', $_thisWeek) . '</data></item>';
     $buff .= '<item id="1"><data name="' . Context::getLang('last_week') . '">' . implode('|', $_lastWeek) . '</data></item>';
     $buff .= '</subFact></gdata></Graph>';
     Context::set('xml', $buff);
     $counter = $oCounterModel->getStatus(array(0, date("Ymd")), $this->site_srl);
     $status->total_visitor = $counter[0]->unique_visitor;
     $status->visitor = $counter[date("Ymd")]->unique_visitor;
     $args->module_srl = $this->module_srl;
     $args->regdate = date("Ymd");
     $output = executeQuery('textyle.getTodayCommentCount', $args);
     $status->comment_count = $output->data->count;
     $args->module_srl = $this->module_srl;
     $args->regdate = date("Ymd");
     $output = executeQuery('textyle.getTodayTrackbackCount', $args);
     $status->trackback_count = $output->data->count;
     Context::set('status', $status);
     $doc_args->module_srl = array($this->textyle->get('member_srl'), $this->module_srl);
     $doc_args->sort_index = 'list_order';
     $doc_args->order_type = 'asc';
     $doc_args->list_count = 3;
     $output = $oDocumentModel->getDocumentList($doc_args, false, false);
     Context::set('newest_documents', $output->data);
     $com_args->module_srl = $this->textyle->get('module_srl');
     $com_args->sort_index = 'list_order';
     $com_args->order_type = 'asc';
     $com_args->list_count = 5;
     $output = $oCommentModel->getTotalCommentList($com_args);
     Context::set('newest_comments', $output->data);
     unset($args);
     $args->module_srl = $this->module_srl;
     $args->page = 1;
     $args->list_count = 5;
     $output = $oTextyleModel->getTextyleGuestbookList($args);
     Context::set('guestbook_list', $output->data);
 }
示例#18
0
 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;
 }
示例#19
0
 /**
  * @brief 전체 태그중 인기 태그 return
  * mid : 대상 플래닛 (null이면 전체 플래닛)
  * shuffle : 태그 결과값에 rank를 부여하고 shuffle
  * list_coutn : 추출 대상 수
  **/
 function getPopularTags($shuffle = false, $list_count = 100)
 {
     if (!$this->isExists()) {
         return;
     }
     if (!$this->isHome()) {
         $args->mid = $this->getMid();
     }
     $cache_file = sprintf('%sfiles/cache/planet/%s/%d.%d.txt', _XE_PATH_, getNumberingPath($this->getModuleSrl(), 3), $shuffle ? 1 : 0, $list_count);
     if (!file_exists($cache_file) || filemtime($cache_file) < time() - 60 * 5) {
         $args->list_count = $list_count;
         // 24시간 이내의 태그중에서 인기 태그를 추출
         $args->date = date("YmdHis", time() - 60 * 60 * 24);
         $output = executeQueryArray('planet.getPlanetPopularTags', $args);
         if (!$output->toBool() || !$output->data) {
             return array();
         }
         $tags = array();
         $max = 0;
         $min = 99999999;
         foreach ($output->data as $key => $val) {
             $tag = $val->tag;
             $count = $val->count;
             if ($max < $count) {
                 $max = $count;
             }
             if ($min > $count) {
                 $min = $count;
             }
             $tags[] = $val;
         }
         if ($shuffle) {
             $mid2 = $min + (int) (($max - $min) / 2);
             $mid1 = $mid2 + (int) (($max - $mid2) / 2);
             $mid3 = $min + (int) (($mid2 - $min) / 2);
             $output = null;
             foreach ($tags as $key => $item) {
                 if ($item->count > $mid1) {
                     $rank = 1;
                 } elseif ($item->count > $mid2) {
                     $rank = 2;
                 } elseif ($item->count > $mid3) {
                     $rank = 3;
                 } else {
                     $rank = 4;
                 }
                 $tags[$key]->rank = $rank;
             }
             shuffle($tags);
         }
         FileHandler::writeFile($cache_file, serialize($tags));
     } else {
         $tags = unserialize(FileHandler::readFile($cache_file));
     }
     return $tags;
 }
 /**
  * @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;
 }
示例#21
0
 /**
  * Get Favicon path
  *
  * @author Arnia (dev@xpressengine.org)
  * @param $module_srl
  * @return string
  */
 public function getShopFaviconPath($module_srl) {
     return sprintf('files/attach/shop/favicon/%s', getNumberingPath($module_srl,3));
 }
 /**
  * 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;
 }
示例#23
0
 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;
 }
示例#24
0
/**
 * Trim a given number to a fiven size recursively
 *
 * @param int $no A given number
 * @param int $size A given digits
 */
function getNumberingPath($no, $size = 3)
{
    $mod = pow(10, $size);
    $output = sprintf('%0' . $size . 'd/', $no % $mod);
    if ($no >= $mod) {
        $output .= getNumberingPath((int) $no / $mod, $size);
    }
    return $output;
}
示例#25
0
 /**
  * get user layout path
  * @param int $layout_srl
  * @return string
  */
 function getUserLayoutPath($layout_srl)
 {
     return sprintf("./files/faceOff/%s", getNumberingPath($layout_srl, 3));
 }
示例#26
0
 /**
  * import layout
  * @param int $layout_srl
  * @param string $source_file path of imported file
  * @return void
  */
 function importLayout($layout_srl, $source_file)
 {
     $oLayoutModel = getModel('layout');
     $user_layout_path = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($layout_srl));
     $file_list = $oLayoutModel->getUserLayoutFileList($layout_srl);
     foreach ($file_list as $key => $file) {
         FileHandler::removeFile($user_layout_path . $file);
     }
     require_once _XE_PATH_ . 'libs/tar.class.php';
     $image_path = $oLayoutModel->getUserLayoutImagePath($layout_srl);
     FileHandler::makeDir($image_path);
     $tar = new tar();
     $tar->openTAR($source_file);
     // If layout.ini file does not exist
     if (!$tar->getFile('layout.ini')) {
         return;
     }
     $replace_path = getNumberingPath($layout_srl, 3);
     foreach ($tar->files as $key => $info) {
         FileHandler::writeFile($user_layout_path . $info['name'], str_replace('__LAYOUT_PATH__', $replace_path, $info['file']));
     }
     // Remove uploaded file
     FileHandler::removeFile($source_file);
 }
示例#27
0
 function _clearMemberCache($member_srl, $site_srl = 0)
 {
     $member_srl = getNumberingPath($member_srl) . $member_srl;
     Rhymix\Framework\Cache::delete("member:member_info:{$member_srl}");
     Rhymix\Framework\Cache::delete("member:member_groups:{$member_srl}:site:{$site_srl}");
     if ($site_srl != 0) {
         Rhymix\Framework\Cache::delete("member:member_groups:{$member_srl}:site:0");
     }
 }
示例#28
0
 function _clearMemberCache($member_srl, $site_srl = 0)
 {
     $oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
     if ($oCacheHandler->isSupport()) {
         $object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_' . $site_srl;
         $cache_key = $oCacheHandler->getGroupKey('member', $object_key);
         $oCacheHandler->delete($cache_key);
         if ($site_srl !== 0) {
             $object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0';
             $cache_key = $oCacheHandler->getGroupKey('member', $object_key);
             $oCacheHandler->delete($cache_key);
         }
     }
     $oCacheHandler = CacheHandler::getInstance('object');
     if ($oCacheHandler->isSupport()) {
         $object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
         $cache_key = $oCacheHandler->getGroupKey('member', $object_key);
         $oCacheHandler->delete($cache_key);
     }
 }
示例#29
0
 /**
  * Send a message (DB controll)
  * @param int $sender_srl member_srl of sender
  * @param int $receiver_srl member_srl of receiver_srl
  * @param string $title
  * @param string $content
  * @param boolean $sender_log (default true)
  * @return Object
  **/
 function sendMessage($sender_srl, $receiver_srl, $title, $content, $sender_log = true)
 {
     $content = removeHackTag($content);
     $title = htmlspecialchars($title);
     // messages to save in the sendor's message box
     $sender_args->sender_srl = $sender_srl;
     $sender_args->receiver_srl = $receiver_srl;
     $sender_args->message_type = 'S';
     $sender_args->title = $title;
     $sender_args->content = $content;
     $sender_args->readed = 'N';
     $sender_args->regdate = date("YmdHis");
     $sender_args->related_srl = getNextSequence();
     $sender_args->message_srl = getNextSequence();
     $sender_args->list_order = getNextSequence() * -1;
     // messages to save in the receiver's message box
     $receiver_args->message_srl = $sender_args->related_srl;
     $receiver_args->related_srl = 0;
     $receiver_args->list_order = $sender_args->related_srl * -1;
     $receiver_args->sender_srl = $sender_srl;
     if (!$receiver_args->sender_srl) {
         $receiver_args->sender_srl = $receiver_srl;
     }
     $receiver_args->receiver_srl = $receiver_srl;
     $receiver_args->message_type = 'R';
     $receiver_args->title = $title;
     $receiver_args->content = $content;
     $receiver_args->readed = 'N';
     $receiver_args->regdate = date("YmdHis");
     $oDB =& DB::getInstance();
     $oDB->begin();
     // messages to save in the sendor's message box
     if ($sender_srl && $sender_log) {
         $output = executeQuery('communication.sendMessage', $sender_args);
         if (!$output->toBool()) {
             $oDB->rollback();
             return $output;
         }
     }
     // messages to save in the receiver's message box
     $output = executeQuery('communication.sendMessage', $receiver_args);
     if (!$output->toBool()) {
         $oDB->rollback();
         return $output;
     }
     // create a flag that message is sent (in file format)
     $flag_path = './files/member_extra_info/new_message_flags/' . getNumberingPath($receiver_srl);
     FileHandler::makeDir($flag_path);
     $flag_file = sprintf('%s%s', $flag_path, $receiver_srl);
     $flag_count = FileHandler::readFile($flag_file);
     FileHandler::writeFile($flag_file, ++$flag_count);
     $oDB->commit();
     return new Object(0, 'success_sended');
 }
示例#30
0
 /**
  * Delete all documents of the module
  * @param int $module_srl
  * @return object
  */
 function deleteModuleDocument($module_srl)
 {
     $args = new stdClass();
     $args->module_srl = $module_srl;
     $oDocumentModel = getModel('document');
     $args->module_srl = $module_srl;
     $document_list = $oDocumentModel->getDocumentList($args);
     $documents = $document_list->data;
     $output = executeQuery('document.deleteModuleDocument', $args);
     if (is_array($documents)) {
         foreach ($documents as $oDocument) {
             $document_srl_list[] = $oDocument->document_srl;
         }
     }
     //remove from cache
     foreach ($document_srl_list as $document_srl) {
         Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($document_srl) . $document_srl);
     }
     return $output;
 }