rhymix/modules/document/document.item.php
2007-07-19 23:42:23 +00:00

264 lines
9.1 KiB
PHP

<?php
/**
* @class documentItem
* @author zero (zero@nzeo.com)
* @brief document 객체
**/
class documentItem extends Object {
var $document_srl = 0;
function documentItem($document_srl = 0) {
$this->document_srl = $document_srl;
$this->_loadFromDB();
}
function setDocument($document_srl) {
$this->document_srl = $document_srl;
$this->_loadFromDB();
}
function _loadFromDB() {
if(!$this->document_srl) return;
$args->document_srl = $this->document_srl;
$output = executeQuery('document.getDocument', $args);
$this->setAttribute($output->data);
}
function setAttribute($attribute) {
if(!$attribute->document_srl || !$attribute->content) {
$this->document_srl = null;
return;
}
$this->document_srl = $attribute->document_srl;
$this->adds($attribute);
// 태그 정리
if($this->get('tags')) {
$tags = explode(',',$this->get('tags'));
$tag_count = count($tags);
for($i=0;$i<$tag_count;$i++) if(trim($tags[$i])) $tag_list[] = trim($tags[$i]);
$this->add('tag_list', $tag_list);
}
}
function isExists() {
return $this->document_srl ? true : false;
}
function isGranted() {
if($_SESSION['own_document'][$this->document_srl]) return true;
if(!Context::get('is_logged')) return false;
$logged_info = Context::get('logged_info');
if($logged_info->is_admin == 'Y') return true;
if($this->get('member_srl') && $this->get('member_srl') == $logged_info->member_srl) return true;
return false;
}
function setGrant() {
$_SESSION['own_document'][$this->document_srl] = true;
}
function isAccessible() {
return $_SESSION['accessible'][$this->document_srl]==true?true:false;
}
function allowComment() {
return $this->get('allow_comment') == 'Y' || !$this->isExists() ? true : false;
}
function allowTrackback() {
return $this->get('allow_trackback') == 'Y' || !$this->isExists() ? true : false;
}
function isLocked() {
return $this->get('lock_comment') == 'Y' ? true : false;
}
function isEditable() {
if($this->isGranted() || !$this->get('member_srl')) return true;
return false;
}
function isSecret() {
return $this->get('is_secret') == 'Y' ? true : false;
}
function isNotice() {
return $this->get('is_notice') == 'Y' ? true : false;
}
function getUserID() {
return htmlspecialchars($this->get('user_id'));
}
function getUserName() {
return htmlspecialchars($this->get('user_name'));
}
function getNickName() {
return htmlspecialchars($this->get('nick_name'));
}
function getTitleText($cut_size = 0, $tail='...') {
return htmlspecialchars($this->getTitle($cut_size, $tail));
}
function getTitle($cut_size = 0, $tail='...') {
if($this->isSecret() && !$this->isGranted()) return Context::getLang('msg_is_secret');
if($cut_size) return cut_str($this->get('title'), $cut_size, $tail);
return $this->get('title');
}
function getContentText() {
if($this->isSecret() && !$this->isGranted()) return Context::getLang('msg_is_secret');
$_SESSION['accessible'][$this->document_srl] = true;
$content = $this->get('content');
$content = preg_replace("!<iframe(.*?)<\/iframe>!is","",$content);
return htmlspecialchars($content);
}
function getContent() {
if($this->isSecret() && !$this->isGranted()) return Context::getLang('msg_is_secret');
$_SESSION['accessible'][$this->document_srl] = true;
$content = $this->get('content');
$content = preg_replace("!<iframe(.*?)<\/iframe>!is","",$content);
return sprintf('<!--BeforeDocument(%d,%d)-->%s<!--AfterDocument(%d,%d)-->', $this->document_srl, $this->get('member_srl'), $content, $this->document_srl, $this->get('member_srl'));
}
function getSummary($str_size = 50) {
$content = strip_tags($this->get('content'));
return cut_str($content, $str_size, '...');
}
function getRegdate($format = 'Y.m.d H:i:s') {
return zdate($this->get('regdate'), $format);
}
function getPermanentUrl() {
return getUrl('','document_srl',$this->document_srl);
}
function getTrackbackUrl() {
return getUrl('','document_srl',$this->document_srl,'act','trackback');
}
function updateReadedCount() {
$oDocumentController = &getController('document');
if($oDocumentController->updateReadedCount($this)) {
$readed_count = $this->get('readed_count');
$readed_count++;
$this->add('readed_count', $readed_count);
}
}
function getCommentCount() {
if(!$this->isGranted() && $this->isSecret()) return 0;
return $this->get('comment_count');
}
function getComments() {
if(!$this->allowComment() || !$this->get('comment_count')) return;
if(!$this->isGranted() && $this->isSecret()) return;
$oCommentModel = &getModel('comment');
return $oCommentModel->getCommentList($this->document_srl, $is_admin);
}
function getTrackbackCount() {
return $this->get('trackback_count');
}
function getTrackbacks() {
if(!$this->allowTrackback() || !$this->get('trackback_count')) return;
$oTrackbackModel = &getModel('trackback');
return $oTrackbackModel->getTrackbackList($this->document_srl, $is_admin);
}
function thumbnailExists($width) {
if(!$this->getThumbnail($width)) return false;
return true;
}
function getThumbnail($width = 80) {
$document_path = sprintf('./files/attach/images/%d/%d/',$this->get('module_srl'), $this->get('document_srl'));
if(!is_dir($document_path)) FileHandler::makeDir($document_path);
$thumbnail_file = sprintf('%sthumbnail_%d.gif', $document_path, $width);
$tmp_file = sprintf('%sthumbnail_%d.tmp.gif', $document_path, $width);
if(file_exists($thumbnail_file)) {
$modified_time = $this->get('last_update');
$hour = (int)substr($modified_time,8,2);
$min = (int)substr($modified_time,10,2);
$sec = (int)substr($modified_time,12,2);
$year = (int)substr($modified_time,0,4);
$month = (int)substr($modified_time,4,2);
$day = (int)substr($modified_time,6,2);
$modified_time = mktime($hour, $min, $sec, $month?$month:1, $day?$day:1, $year);
if($modified_time > filectime($thumbnail_file)) unlink($thumbnail_file);
}
if(!file_exists($thumbnail_file)) {
FileHandler::writeFile($thumbnail_file, '', 'w');
$content = $this->get('content');
// 첨부된 파일부터 찾아봄 (DB말고 내용에서 추출)
preg_match_all("!(\"|')files\/([^ ^\"^']*?)\.(jpg|png|gif|jpeg)!is", $content, $matches);
$attached_file_list = $matches[0];
if(count($attached_file_list)) {
$src = preg_replace("!^(\"|')!is","",$attached_file_list[0]);
copy("./".$src, $tmp_file);
// 첨부된 파일이 없으면 http로 시작하는 경로를 찾음
} else {
preg_match('!src=("|\'){0,1}([^"|^\'|^\ ]*)("|\'| ){0,1}!is', $content, $matches);
$src = $matches[2];
if($src) FileHandler::getRemoteFile($src, $tmp_file);
else return;
}
FileHandler::createImageFile($tmp_file, $thumbnail_file, $width, $width, 'gif');
@unlink($tmp_file);
}
if(filesize($thumbnail_file)<1) return;
$thumbnail_url = Context::getRequestUri().$thumbnail_file;
return $thumbnail_url;
}
function hasUploadedFiles() {
if($this->isSecret() && !$this->isGranted()) return false;
return $this->get('uploaded_count')? true : false;
}
function getUploadedFiles() {
if($this->isSecret() && !$this->isGranted()) return;
if(!$this->get('uploaded_count')) return;
$oFileModel = &getModel('file');
$file_list = $oFileModel->getFiles($this->document_srl, $is_admin);
return $file_list;
}
}
?>