<commit_before><?php

    /**
     * @class  textyleView
     * @author sol (<EMAIL>)
     * @brief  textyle 모듈의 View class
     **/

    class textyleView extends textyle {

        /**
         * @brief 초기화
         **/
        function init() {
            if(!$this->checkXECoreVersion('1.2.6')) return $this->stop(sprintf(Context::getLang('msg_requried_version'),'1.2.6'));

            $oTextyleModel = &getModel('textyle');
            $oTextyleController = &getController('textyle');
            $oModuleModel = &getModel('module');

            Context::set('custom_menu', $this->custom_menu = $oTextyleModel->getTextyleCustomMenu());

            if(!$this->module_srl) {
                $site_module_info = Context::get('site_module_info');
                $site_srl = $site_module_info->site_srl;
                if($site_srl) {
                    $this->module_srl = $site_module_info->index_module_srl;
                    $this->module_info = $oModuleModel->getModuleInfoByModuleSrl($this->module_srl);
                    Context::set('module_info',$this->module_info);
                    Context::set('mid',$this->module_info->mid);
                    Context::set('current_module_info',$this->module_info);
                }
            }

            // @brief Textyle 모듈의 기본 설정은 view에서는 언제든지 사용하도록 load하여 Context setting
            if(!$this->module_info->skin) $this->module_info->skin = $this->skin;

            // 만약 skin 미리보기일 경우 관리자라면 스킨을 변경해 보여줌
            if($oModuleModel->isSiteAdmin(Context::get('logged_info'))&&Context::get('skin')) {
                $preview_skin = Context::get('skin');
                if(is_dir($this->module_path.'skins/'.$preview_skin)) {
                    $textyle_config->skin = $this->module_info->skin = $preview_skin;
                }
            }

            // 모듈 정보에 textyle 정보를 합쳐서 저장
            Context::set('module_info',$this->module_info);
            Context::set('current_module_info', $this->module_info);

            $this->textyle = $oTextyleModel->getTextyle($this->module_info->module_srl);
            $this->site_srl = $this->textyle->site_srl;
            Context::set('textyle',$this->textyle);

            // time zone 지정
            if($this->textyle->timezone) $GLOBALS['_time_zone'] = $this->textyle->timezone;

            // favicon 지정
            Context::addHtmlHeader('<link rel="shortcut icon" href="'.$this->textyle->getFaviconSrc().'" />');

            // publish subscription
            if($this->textyle->getSubscriptionDate() <= date('YmdHis')){
                $output = $oTextyleController->publishSubscriptedPost($this->module_info->module_srl);
            }

            // textyle 관리
            if(preg_match("/TextyleTool/",$this->act) || $oTextyleModel->isAttachedMenu($this->act) ) {

                // 숨김 메뉴를 요청할 경우 대시보드로 변경
                if($oTextyleModel->ishiddenMenu($this->act) || ($this->act == 'dispTextyleToolDashboard' && $oTextyleModel->isHiddenMenu(0)) ) {
                    if($oTextyleModel->isHiddenMenu(0)) Context::set('act', $this->act = 'dispTextyleToolPostManageList', true);
                    else Context::set('act', $this->act= 'dispTextyleToolDashboard', true);
                }

                $template_path = sprintf("%stpl",$this->module_path);
                $this->setTemplatePath($template_path);
                $this->setTemplateFile(str_replace('dispTextyleTool','',$this->act));

                if($_COOKIE['tclnb']) Context::addBodyClass('lnbClose');
                else Context::addBodyClass('lnbToggleOpen');

                // browser title 지정
                Context::setBrowserTitle($this->textyle->get('browser_title') . ' - admin');

            // textyle 서비스
            } else {
                Context::addJsFile($this->module_path.'tpl/js/textyle_service.js');

                if(!$preview_skin){
                    $oTextyleModel->checkTextylePath($this->module_srl, $this->module_info->skin);
                    $this->setTemplatePath($oTextyleModel->getTextylePath($this->module_srl));
                }
                else $this->setTemplatePath($this->module_path.'skins/'.$preview_skin);

                $this->setTemplateFile('textyle');
                Context::addCssFile($this->getTemplatePath().'textyle.css',true,'all','',100);

                // Textyle에서 쓰기 위해 변수를 미리 정하여 세팅
                Context::set('root_url', Context::getRequestUri());
                Context::set('home_url', getFullSiteUrl($this->textyle->domain));
                Context::set('profile_url', getSiteUrl($this->textyle->domain,'','mid',$this->module_info->mid,'act','dispTextyleProfile'));
                Context::set('guestbook_url', getSiteUrl($this->textyle->domain,'','mid',$this->module_info->mid,'act','dispTextyleGuestbook'));
                Context::set('tag_url', getSiteUrl($this->textyle->domain,'','mid',$this->module_info->mid,'act','dispTextyleTag'));
                if(Context::get('is_logged')) Context::set('admin_url', getSiteUrl($this->textyle->domain,'','mid',$this->module_info->mid,'act','dispTextyleToolDashboard'));
                else Context::set('admin_url', getSiteUrl($textyle->domain,'','mid','textyle','act','dispTextyleToolLogin'));
                Context::set('textyle_title', $this->textyle->get('textyle_title'));
                if($this->textyle->get('post_use_prefix')=='Y' && $this->textyle->get('post_prefix')) Context::set('post_prefix', $this->textyle->get('post_prefix'));
                if($this->textyle->get('post_use_suffix')=='Y' && $this->textyle->get('post_suffix')) Context::set('post_suffix', $this->textyle->get('post_suffix'));

                // browser title 지정
                Context::setBrowserTitle($this->textyle->get('browser_title'));
            }
        }

        /**
         * @brief rss for publish subscription
         **/
        function rss(){
            $oRss = &getView('rss');
            $oRss->module_info = $this->module_info;
            $oRss->rss();
            $this->setTemplatePath($oRss->getTemplatePath());
            $this->setTemplateFile($oRss->getTemplateFile());
        }

        /**
         * @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');
            $oMaterialModel = &getModel('material');
            $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);
            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->page = 1;
            $args->list_count = 3;
            $logged_info = Context::get('logged_info');
            $args->member_srl = $logged_info->member_srl;
            if($oMaterialModel) {
                $output = $oMaterialModel->getMaterialList($args);
                if(count($output->data)){
                    foreach($output->data as $k => $v){
                        if($v->type=='mov'){
                            $v->content = preg_replace('/width=\"[^\"]*\"/','width="100%"',$v->content);
                            $v->content = preg_replace('/width=\'[^\']*\'/','width="100%"',$v->content);
                        }
                    }
                }
                Context::set('material_list',$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);
        }

        /**
         * @brief Login
         **/
        function dispTextyleToolLogin() {
            $oModuleModel = &getModel('module');
            $member_config = $oModuleModel->getModuleConfig('member');
            Context::set('enable_openid', $member_config->enable_openid);

            Context::addBodyClass('logOn');
        }

        /**
         * @brief Tool 새글쓰기
         **/
        function dispTextyleToolPostManageWrite(){
            // set filter
            Context::addJsFilter($this->module_path.'tpl/filter', 'save_post.xml');

            $oDocumentModel = &getModel('document');
            $document_srl = Context::get('document_srl');
            $material_srl = Context::get('material_srl');

            if($document_srl){
                $oDocument = $oDocumentModel->getDocument($document_srl);
                $alias = $oDocumentModel->getAlias($document_srl);
                Context::set('alias',$alias);

                $oTextyleModel = &getModel('textyle');
                $output = $oTextyleModel->getSubscriptionByDocumentSrl($document_srl);
                if($output->data){
                    $publish_date = $output->data[0]->publish_date;
                    $publish_date = sscanf($publish_date,'%04d%02d%02d%02d%02d');
                    Context::set('publish_date_yyyymmdd',sprintf("%s-%02d-%02d",$publish_date[0],$publish_date[1],$publish_date[2]));
                    Context::set('publish_date_hh',sprintf("%02d",$publish_date[3]));
                    Context::set('publish_date_ii',sprintf("%02d",$publish_date[4]));
                    Context::set('subscription','Y');
                }

            }else{
                $document_srl=0;
                $oDocument = $oDocumentModel->getDocument(0);

                if($material_srl){
                    $oMaterialModel = &getModel('material');
                    $output = $oMaterialModel->getMaterial($material_srl);
                    if($output->data){
                        $material_content = $output->data[0]->content;
                        Context::set('material_content',$material_content);
                    }
                }

            }
            Context::set('oDocument',$oDocument);

            $category_list = $oDocumentModel->getCategoryList($this->module_srl);
            Context::set('category_list',$category_list);

            $oTagModel = &getModel('tag');
            $args->module_srl = $this->module_srl;
            $args->list_count = 20;
            $output = $oTagModel->getTagList($args);
            Context::set('tag_list',$output->data);

            $oEditorModel = &getModel('editor');
            $option->skin = $this->textyle->getPostEditorSkin();
            $option->primary_key_name = 'document_srl';
            $option->content_key_name = 'content';
            $option->allow_fileupload = true;
            $option->enable_autosave = true;
            $option->enable_default_component = true;
            $option->enable_component = $option->skin =='dreditor' ? false : true;
            $option->resizable = true;
            $option->height = 500;
            $option->content_font = $this->textyle->getFontFamily();
            $option->content_font_size = $this->textyle->getFontSize();
            $editor = $oEditorModel->getEditor($document_srl, $option);
            Context::set('editor', $editor);
            Context::set('editor_skin', $option->skin);


            // permalink
            $permalink = '';
            if(isSiteID($this->textyle->domain)){
                if(Context::isAllowRewrite()){
                    $permalink = getFullSiteUrl($this->textyle->domain,'') . '/entry/';
                }else{
                    $permalink = getFullSiteUrl($this->textyle->domain).'?vid='.$this->textyle->domain . '&mid='.Context::get('mid').'&entry=';
                }
            }else{
                if(Context::isAllowRewrite()){
                    $permalink = getFullSiteUrl($this->textyle->domain,'').'entry/';
                }else{
                    $premalink = getFullSiteUrl($this->textyle->domain,'','mid',Context::get('mid')).'&entry=';
                }
            }
            Context::set('permalink',$permalink);
        }

        /**
         * @brief 발행/ 재발행
         **/
        function dispTextyleToolPostManagePublish() {
            $oDocumentModel = &getModel('document');
            $oTextyleModel = &getModel('textyle');

            $document_srl = Context::get('document_srl');
            if(!$document_srl) return new Object(-1,'msg_invalid_request');

            $oDocument = $oDocumentModel->getDocument($document_srl);
            if(!$oDocument->isExists()) return new Object(-1,'msg_invalid_request');

            $alias = $oDocumentModel->getAlias($document_srl);
            Context::set('alias',$alias);

            $output = $oTextyleModel->getSubscriptionByDocumentSrl($document_srl);
            if($output->data){
                $publish_date = $output->data[0]->publish_date;
                $publish_date = sscanf($publish_date,'%04d%02d%02d%02d%02d');
                Context::set('publish_date_yyyymmdd',sprintf("%s-%02d-%02d",$publish_date[0],$publish_date[1],$publish_date[2]));
                Context::set('publish_date_hh',sprintf("%02d",$publish_date[3]));
                Context::set('publish_date_ii',sprintf("%02d",$publish_date[4]));
                Context::set('subscription','Y');
            }

            if($oDocument->get('module_srl') != $this->module_srl){
                Context::set('from_saved',true);
            }

            Context::set('oDocument', $oDocument);
            Context::set('oTextyle', $oTextyleModel->getTextyle($this->module_srl));
            Context::set('oPublish', $oTextyleModel->getPublishObject($this->module_srl, $oDocument->document_srl));
            Context::set('category_list', $oDocumentModel->getCategoryList($this->module_srl));

            Context::addJsFilter($this->module_path.'tpl/filter', 'publish_post.xml');
        }

        /**
         * @brief Document Alias check (API)
         **/
        function dispTextylePostCheckAlias(){
            $mid = Context::get('mid');
            $alias = Context::get('alias');
            $oDocumentModel = &getModel('document');
            $document_srl = $oDocumentModel->getDocumentSrlByAlias($mid,$alias);
            Context::set('document_srl',$document_srl);
        }

        /**
         * @brief Tool 내 글 관리
         **/
        function dispTextyleToolPostManageList(){

            $args->page = Context::get('page');
            if(!$args->page) $args->page = 1;
            Context::set('page',$args->page);

            // 검색과 정렬을 위한 변수 설정
            $args->search_target = Context::get('search_target');
            $args->search_keyword = Context::get('search_keyword');
            $args->category_srl = Context::get('search_category_srl');
            $args->sort_index = Context::get('sort_index');
            //$args->order_type = Context::get('order_type');

            // module_srl이 음수면 예약 발행글
            $published = Context::get('published');
            $logged_info = Context::get('logged_info');

            // 모든글
            if(!$published){
                $args->module_srl = array($this->module_srl,$this->module_srl * -1,$logged_info->member_srl);
            // 발행된 글
            }else if($published > 0){
                $args->module_srl = array($this->module_srl,$this->module_srl * -1);
            // 임시보관 글
            }else{
                $args->module_srl = $logged_info->member_srl;
            }

            $oDocumentModel = &getModel('document');
            $output = $oDocumentModel->getDocumentList($args);
            Context::set('post_list',$output->data);
            Context::set('page_navigation', $output->page_navigation);

            $oDocumentModel = &getModel('document');
            $category_list = $oDocumentModel->getCategoryList($this->module_srl);
            Context::set('category_list', $category_list);

            foreach($this->search_option as $opt) $search_option[$opt] = Context::getLang($opt);
            Context::set('search_option', $search_option);

            Context::addJsFilter($this->module_path.'tpl/filter', 'update_allow.xml');
        }

        /**
         * @brief Tool 글감보관함
         **/
        function dispTextyleToolPostManageDeposit(){
            $oMaterialModel = &getModel('material');

            $page = Context::get('page');
            $logged_info = Context::get('logged_info');
            $args->page = $page;
            $args->member_srl = $logged_info->member_srl;

            if($oMaterialModel) {
                $output = $oMaterialModel->getMaterialList($args);
                $bookmark_url = $oMaterialModel->getBookmarkUrl($this->textyle->domain, $logged_info->member_srl);

                Context::set('page',$output->page_navigation->cur_page);
                Context::set('bookmark_url',$bookmark_url);
                Context::set('material_list',$output->data);
                Context::set('page_navigation',$output->page_navigation);
            } else {
                Context::set('bookmark_url','#');
            }

            Context::set('containerClassName','ece');
        }

        /**
         * @brief Tool 카테고리 관리
         **/
        function dispTextyleToolPostManageCategory(){
            $oDocumentModel = &getModel('document');
            $catgegory_content = $oDocumentModel->getCategoryHTML($this->module_srl);

            Context::set('module_srl',$this->module_srl);
            Context::set('category_content', $catgegory_content);
            Context::set('module_info', $this->module_info);
        }

        /**
         * @brief tool 태그 관리
         **/
        function dispTextyleToolPostManageTag(){
            $args->module_srl = $this->module_srl;
            $args->list_count = 100;
            $args->sort_index = Context::get('sort_index');

            $oTagModel = &getModel('tag');
            $output = $oTagModel->getTagList($args);
            Context::set('tag_list',$output->data);
            Context::set('tag_list_count',count($output->data));

            $args->list_count = 10;
            $args->sort_index = 'regdate';
            $output = $oTagModel->getTagList($args);
            Context::set('tag_recent_list',$output->data);

            unset($args);
            $args->tag = Context::get('selected_tag');
            if($args->tag){
                $args->module_srl = $this->module_srl;<commit_msg>#18548733 * 태그관리에서 실제 태그수와 다르게 표시되는 문제 수정<commit_after><?php

    /**
     * @class  textyleView
     * @author sol (<EMAIL>)
     * @brief  textyle 모듈의 View class
     **/

    class textyleView extends textyle {

        /**
         * @brief 초기화
         **/
        function init() {
            if(!$this->checkXECoreVersion('1.2.6')) return $this->stop(sprintf(Context::getLang('msg_requried_version'),'1.2.6'));

            $oTextyleModel = &getModel('textyle');
            $oTextyleController = &getController('textyle');
            $oModuleModel = &getModel('module');

            Context::set('custom_menu', $this->custom_menu = $oTextyleModel->getTextyleCustomMenu());

            if(!$this->module_srl) {
                $site_module_info = Context::get('site_module_info');
                $site_srl = $site_module_info->site_srl;
                if($site_srl) {
                    $this->module_srl = $site_module_info->index_module_srl;
                    $this->module_info = $oModuleModel->getModuleInfoByModuleSrl($this->module_srl);
                    Context::set('module_info',$this->module_info);
                    Context::set('mid',$this->module_info->mid);
                    Context::set('current_module_info',$this->module_info);
                }
            }

            // @brief Textyle 모듈의 기본 설정은 view에서는 언제든지 사용하도록 load하여 Context setting
            if(!$this->module_info->skin) $this->module_info->skin = $this->skin;

            // 만약 skin 미리보기일 경우 관리자라면 스킨을 변경해 보여줌
            if($oModuleModel->isSiteAdmin(Context::get('logged_info'))&&Context::get('skin')) {
                $preview_skin = Context::get('skin');
                if(is_dir($this->module_path.'skins/'.$preview_skin)) {
                    $textyle_config->skin = $this->module_info->skin = $preview_skin;
                }
            }

            // 모듈 정보에 textyle 정보를 합쳐서 저장
            Context::set('module_info',$this->module_info);
            Context::set('current_module_info', $this->module_info);

            $this->textyle = $oTextyleModel->getTextyle($this->module_info->module_srl);
            $this->site_srl = $this->textyle->site_srl;
            Context::set('textyle',$this->textyle);

            // time zone 지정
            if($this->textyle->timezone) $GLOBALS['_time_zone'] = $this->textyle->timezone;

            // favicon 지정
            Context::addHtmlHeader('<link rel="shortcut icon" href="'.$this->textyle->getFaviconSrc().'" />');

            // publish subscription
            if($this->textyle->getSubscriptionDate() <= date('YmdHis')){
                $output = $oTextyleController->publishSubscriptedPost($this->module_info->module_srl);
            }

            // textyle 관리
            if(preg_match("/TextyleTool/",$this->act) || $oTextyleModel->isAttachedMenu($this->act) ) {

                // 숨김 메뉴를 요청할 경우 대시보드로 변경
                if($oTextyleModel->ishiddenMenu($this->act) || ($this->act == 'dispTextyleToolDashboard' && $oTextyleModel->isHiddenMenu(0)) ) {
                    if($oTextyleModel->isHiddenMenu(0)) Context::set('act', $this->act = 'dispTextyleToolPostManageList', true);
                    else Context::set('act', $this->act= 'dispTextyleToolDashboard', true);
                }

                $template_path = sprintf("%stpl",$this->module_path);
                $this->setTemplatePath($template_path);
                $this->setTemplateFile(str_replace('dispTextyleTool','',$this->act));

                if($_COOKIE['tclnb']) Context::addBodyClass('lnbClose');
                else Context::addBodyClass('lnbToggleOpen');

                // browser title 지정
                Context::setBrowserTitle($this->textyle->get('browser_title') . ' - admin');

            // textyle 서비스
            } else {
                Context::addJsFile($this->module_path.'tpl/js/textyle_service.js');

                if(!$preview_skin){
                    $oTextyleModel->checkTextylePath($this->module_srl, $this->module_info->skin);
                    $this->setTemplatePath($oTextyleModel->getTextylePath($this->module_srl));
                }
                else $this->setTemplatePath($this->module_path.'skins/'.$preview_skin);

                $this->setTemplateFile('textyle');
                Context::addCssFile($this->getTemplatePath().'textyle.css',true,'all','',100);

                // Textyle에서 쓰기 위해 변수를 미리 정하여 세팅
                Context::set('root_url', Context::getRequestUri());
                Context::set('home_url', getFullSiteUrl($this->textyle->domain));
                Context::set('profile_url', getSiteUrl($this->textyle->domain,'','mid',$this->module_info->mid,'act','dispTextyleProfile'));
                Context::set('guestbook_url', getSiteUrl($this->textyle->domain,'','mid',$this->module_info->mid,'act','dispTextyleGuestbook'));
                Context::set('tag_url', getSiteUrl($this->textyle->domain,'','mid',$this->module_info->mid,'act','dispTextyleTag'));
                if(Context::get('is_logged')) Context::set('admin_url', getSiteUrl($this->textyle->domain,'','mid',$this->module_info->mid,'act','dispTextyleToolDashboard'));
                else Context::set('admin_url', getSiteUrl($textyle->domain,'','mid','textyle','act','dispTextyleToolLogin'));
                Context::set('textyle_title', $this->textyle->get('textyle_title'));
                if($this->textyle->get('post_use_prefix')=='Y' && $this->textyle->get('post_prefix')) Context::set('post_prefix', $this->textyle->get('post_prefix'));
                if($this->textyle->get('post_use_suffix')=='Y' && $this->textyle->get('post_suffix')) Context::set('post_suffix', $this->textyle->get('post_suffix'));

                // browser title 지정
                Context::setBrowserTitle($this->textyle->get('browser_title'));
            }
        }

        /**
         * @brief rss for publish subscription
         **/
        function rss(){
            $oRss = &getView('rss');
            $oRss->module_info = $this->module_info;
            $oRss->rss();
            $this->setTemplatePath($oRss->getTemplatePath());
            $this->setTemplateFile($oRss->getTemplateFile());
        }

        /**
         * @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');
            $oMaterialModel = &getModel('material');
            $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);
            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->page = 1;
            $args->list_count = 3;
            $logged_info = Context::get('logged_info');
            $args->member_srl = $logged_info->member_srl;
            if($oMaterialModel) {
                $output = $oMaterialModel->getMaterialList($args);
                if(count($output->data)){
                    foreach($output->data as $k => $v){
                        if($v->type=='mov'){
                            $v->content = preg_replace('/width=\"[^\"]*\"/','width="100%"',$v->content);
                            $v->content = preg_replace('/width=\'[^\']*\'/','width="100%"',$v->content);
                        }
                    }
                }
                Context::set('material_list',$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);
        }

        /**
         * @brief Login
         **/
        function dispTextyleToolLogin() {
            $oModuleModel = &getModel('module');
            $member_config = $oModuleModel->getModuleConfig('member');
            Context::set('enable_openid', $member_config->enable_openid);

            Context::addBodyClass('logOn');
        }

        /**
         * @brief Tool 새글쓰기
         **/
        function dispTextyleToolPostManageWrite(){
            // set filter
            Context::addJsFilter($this->module_path.'tpl/filter', 'save_post.xml');

            $oDocumentModel = &getModel('document');
            $document_srl = Context::get('document_srl');
            $material_srl = Context::get('material_srl');

            if($document_srl){
                $oDocument = $oDocumentModel->getDocument($document_srl);
                $alias = $oDocumentModel->getAlias($document_srl);
                Context::set('alias',$alias);

                $oTextyleModel = &getModel('textyle');
                $output = $oTextyleModel->getSubscriptionByDocumentSrl($document_srl);
                if($output->data){
                    $publish_date = $output->data[0]->publish_date;
                    $publish_date = sscanf($publish_date,'%04d%02d%02d%02d%02d');
                    Context::set('publish_date_yyyymmdd',sprintf("%s-%02d-%02d",$publish_date[0],$publish_date[1],$publish_date[2]));
                    Context::set('publish_date_hh',sprintf("%02d",$publish_date[3]));
                    Context::set('publish_date_ii',sprintf("%02d",$publish_date[4]));
                    Context::set('subscription','Y');
                }

            }else{
                $document_srl=0;
                $oDocument = $oDocumentModel->getDocument(0);

                if($material_srl){
                    $oMaterialModel = &getModel('material');
                    $output = $oMaterialModel->getMaterial($material_srl);
                    if($output->data){
                        $material_content = $output->data[0]->content;
                        Context::set('material_content',$material_content);
                    }
                }

            }
            Context::set('oDocument',$oDocument);

            $category_list = $oDocumentModel->getCategoryList($this->module_srl);
            Context::set('category_list',$category_list);

            $oTagModel = &getModel('tag');
            $args->module_srl = $this->module_srl;
            $args->list_count = 20;
            $output = $oTagModel->getTagList($args);
            Context::set('tag_list',$output->data);

            $oEditorModel = &getModel('editor');
            $option->skin = $this->textyle->getPostEditorSkin();
            $option->primary_key_name = 'document_srl';
            $option->content_key_name = 'content';
            $option->allow_fileupload = true;
            $option->enable_autosave = true;
            $option->enable_default_component = true;
            $option->enable_component = $option->skin =='dreditor' ? false : true;
            $option->resizable = true;
            $option->height = 500;
            $option->content_font = $this->textyle->getFontFamily();
            $option->content_font_size = $this->textyle->getFontSize();
            $editor = $oEditorModel->getEditor($document_srl, $option);
            Context::set('editor', $editor);
            Context::set('editor_skin', $option->skin);


            // permalink
            $permalink = '';
            if(isSiteID($this->textyle->domain)){
                if(Context::isAllowRewrite()){
                    $permalink = getFullSiteUrl($this->textyle->domain,'') . '/entry/';
                }else{
                    $permalink = getFullSiteUrl($this->textyle->domain).'?vid='.$this->textyle->domain . '&mid='.Context::get('mid').'&entry=';
                }
            }else{
                if(Context::isAllowRewrite()){
                    $permalink = getFullSiteUrl($this->textyle->domain,'').'entry/';
                }else{
                    $premalink = getFullSiteUrl($this->textyle->domain,'','mid',Context::get('mid')).'&entry=';
                }
            }
            Context::set('permalink',$permalink);
        }

        /**
         * @brief 발행/ 재발행
         **/
        function dispTextyleToolPostManagePublish() {
            $oDocumentModel = &getModel('document');
            $oTextyleModel = &getModel('textyle');

            $document_srl = Context::get('document_srl');
            if(!$document_srl) return new Object(-1,'msg_invalid_request');

            $oDocument = $oDocumentModel->getDocument($document_srl);
            if(!$oDocument->isExists()) return new Object(-1,'msg_invalid_request');

            $alias = $oDocumentModel->getAlias($document_srl);
            Context::set('alias',$alias);

            $output = $oTextyleModel->getSubscriptionByDocumentSrl($document_srl);
            if($output->data){
                $publish_date = $output->data[0]->publish_date;
                $publish_date = sscanf($publish_date,'%04d%02d%02d%02d%02d');
                Context::set('publish_date_yyyymmdd',sprintf("%s-%02d-%02d",$publish_date[0],$publish_date[1],$publish_date[2]));
                Context::set('publish_date_hh',sprintf("%02d",$publish_date[3]));
                Context::set('publish_date_ii',sprintf("%02d",$publish_date[4]));
                Context::set('subscription','Y');
            }

            if($oDocument->get('module_srl') != $this->module_srl){
                Context::set('from_saved',true);
            }

            Context::set('oDocument', $oDocument);
            Context::set('oTextyle', $oTextyleModel->getTextyle($this->module_srl));
            Context::set('oPublish', $oTextyleModel->getPublishObject($this->module_srl, $oDocument->document_srl));
            Context::set('category_list', $oDocumentModel->getCategoryList($this->module_srl));

            Context::addJsFilter($this->module_path.'tpl/filter', 'publish_post.xml');
        }

        /**
         * @brief Document Alias check (API)
         **/
        function dispTextylePostCheckAlias(){
            $mid = Context::get('mid');
            $alias = Context::get('alias');
            $oDocumentModel = &getModel('document');
            $document_srl = $oDocumentModel->getDocumentSrlByAlias($mid,$alias);
            Context::set('document_srl',$document_srl);
        }

        /**
         * @brief Tool 내 글 관리
         **/
        function dispTextyleToolPostManageList(){

            $args->page = Context::get('page');
            if(!$args->page) $args->page = 1;
            Context::set('page',$args->page);

            // 검색과 정렬을 위한 변수 설정
            $args->search_target = Context::get('search_target');
            $args->search_keyword = Context::get('search_keyword');
            $args->category_srl = Context::get('search_category_srl');
            $args->sort_index = Context::get('sort_index');
            //$args->order_type = Context::get('order_type');

            // module_srl이 음수면 예약 발행글
            $published = Context::get('published');
            $logged_info = Context::get('logged_info');

            // 모든글
            if(!$published){
                $args->module_srl = array($this->module_srl,$this->module_srl * -1,$logged_info->member_srl);
            // 발행된 글
            }else if($published > 0){
                $args->module_srl = array($this->module_srl,$this->module_srl * -1);
            // 임시보관 글
            }else{
                $args->module_srl = $logged_info->member_srl;
            }

            $oDocumentModel = &getModel('document');
            $output = $oDocumentModel->getDocumentList($args);
            Context::set('post_list',$output->data);
            Context::set('page_navigation', $output->page_navigation);

            $oDocumentModel = &getModel('document');
            $category_list = $oDocumentModel->getCategoryList($this->module_srl);
            Context::set('category_list', $category_list);

            foreach($this->search_option as $opt) $search_option[$opt] = Context::getLang($opt);
            Context::set('search_option', $search_option);

            Context::addJsFilter($this->module_path.'tpl/filter', 'update_allow.xml');
        }

        /**
         * @brief Tool 글감보관함
         **/
        function dispTextyleToolPostManageDeposit(){
            $oMaterialModel = &getModel('material');

            $page = Context::get('page');
            $logged_info = Context::get('logged_info');
            $args->page = $page;
            $args->member_srl = $logged_info->member_srl;

            if($oMaterialModel) {
                $output = $oMaterialModel->getMaterialList($args);
                $bookmark_url = $oMaterialModel->getBookmarkUrl($this->textyle->domain, $logged_info->member_srl);

                Context::set('page',$output->page_navigation->cur_page);
                Context::set('bookmark_url',$bookmark_url);
                Context::set('material_list',$output->data);
                Context::set('page_navigation',$output->page_navigation);
            } else {
                Context::set('bookmark_url','#');
            }

            Context::set('containerClassName','ece');
        }

        /**
         * @brief Tool 카테고리 관리
         **/
        function dispTextyleToolPostManageCategory(){
            $oDocumentModel = &getModel('document');
            $catgegory_content = $oDocumentModel->getCategoryHTML($this->module_srl);

            Context::set('module_srl',$this->module_srl);
            Context::set('category_content', $catgegory_content);
            Context::set('module_info', $this->module_info);
        }

        /**
         * @brief tool 태그 관리
         **/
        function dispTextyleToolPostManageTag(){
            $args->module_srl = $this->module_srl;
            $args->list_count = 100000;
            $args->sort_index = Context::get('sort_index');

            $oTagModel = &getModel('tag');
            $output = $oTagModel->getTagList($args);
            Context::set('tag_list',$output->data);
            Context::set('tag_list_count',count($output->data));

            $args->list_count = 10;
            $args->sort_index = 'regdate';
            $output = $oTagModel->getTagList($args);
            Context::set('tag_recent_list',$output->data);

            unset($args);
            $args->tag = Context::get('selected_tag');
            if($args->tag){
                $args->module_srl = $this->module_srl;
{'fraction_non_alphanumeric': 0.16786394056609566, 'fraction_numerical': 0.0057510079613597755, 'mean_word_length': 2.0104121742344896, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 2, '>': 739, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1306875', 'n_tokens_mistral': 14861, 'n_tokens_neox': 14590, 'n_words': 1694}