* * 액션 스크립트 : 문서 삭제 (삭제된 후) * * @package narinwiki * @subpackage event * @license GPL2 (http://narinwiki.org/license) * @author byfun (http://byfun.com) * @filesource */ if (!defined('_GNUBOARD_')) exit; $wikiArticle =& wiki_class_load("Article"); $article = $delete_article; $doc = wiki_doc($article['ns'], $article['doc']); $backlinks = $wikiArticle->getBackLinks($doc, $includeSelf = false); for($i=0; $i<count($backlinks); $i++) { $wikiArticle->shouldUpdateCache($backlinks[$i]['wr_id'], 1); } $wikiArticle->deleteArticleById($wr_id); // 문서 이력 삭제 $wikiHistory =& wiki_class_load("History"); $wikiHistory->setUnlinked($wr_id, $doc); //$wikiHistory->clear($wr_id, $delete_all = true); // 캐시 삭제 $wikiCache =& wiki_class_load("Cache");
/** * * dataout inline 처리 without js (currently no js version though) * * @param array $args 파라미터 * @param array $params {@link NarinParser} 에서 전달하는 파라미터/ can be null * @return string output */ public function wiki_dataout_inline_nojs($args, $params) { if($args['having']>0) { $having = "HAVING COUNT(1)=".$args['having']; } if($args['method'] == "rank") { if($args['having_target']>0) { $having_target = "HAVING COUNT(1)=".$args['having_target']; } $sql_wr_id = "SELECT wr_id FROM ".$args['db_table']." WHERE bo_table='".$this->bo_table."' AND ".$args['filter_keyword']." AND (".$args['filter_target'].") GROUP BY wr_id ".$having_target; $res_wr_id = sql_query($sql_wr_id); $row_wr_id = mysql_fetch_assoc($res_wr_id); $sort_wr_id = $row_wr_id['wr_id']; if(!$sort_wr_id) return " <span style='color:red;'>등록정보없음</span> "; // make all wr_id list without filter_target mysql_query("SET @rank=0"); $sql_rank = "SELECT rank FROM ( SELECT @rank:=@rank+1 AS rank, wr_id, val FROM ( SELECT d.wr_id, val FROM ( SELECT wr_id FROM ".$args['db_table']." WHERE bo_table='".$this->bo_table."' AND ".$args['filter_keyword']." AND (".$args['filter_where'].") GROUP BY wr_id ".$having." ) c, ".$args['db_table']." d WHERE d.bo_table='".$this->bo_table."' AND ".$args['filter_keyword']." AND d.wr_id=c.wr_id AND col = '".$args['field']."' ORDER BY CAST(val AS DECIMAL) ".$args['sort']." ) r ) g WHERE g.wr_id = ".$sort_wr_id; //TODO: order should be done by proper casting.. maybe need to specify the data type // e.g. _int --> CAST(val AS UNSIGNED), _dt --> CAST(val AS DATETIME), _num --> CAST(val AS DECIMAL) $res_rank = sql_query($sql_rank); $row_rank = mysql_fetch_assoc($res_rank); return " ".$row_rank['rank']." "; } $sql_wr_id = "SELECT wr_id FROM ".$args['db_table']." WHERE bo_table='".$this->bo_table."' AND ".$args['filter_keyword']." AND (".$args['filter_where'].") GROUP BY wr_id ".$having; $res_wr_id = sql_query($sql_wr_id); if($args['method'] == "count") { $nb_count = mysql_num_rows($res_wr_id); return " ".$nb_count." "; }else { $data_array = array(); while($row_wr_id = mysql_fetch_assoc($res_wr_id)) { $wr_id = $row_wr_id['wr_id']; // fullpath is reserved for %pageid%, docname is reserved for %title% if($args['field']=='fullpath' || $args['field']=='%pageid%' || $args['field']=='%title%') { $wikiArticle =& wiki_class_load("Article"); $write = $wikiArticle->getArticleById($wr_id); $fullpath = wiki_doc($write['ns'], $write['doc']); $href = wiki_url('read', array('doc'=>$fullpath)); if($args['field']=='fullpath' || $args['field']=='%pageid%') { array_push($data_array, "<a href='".$href."' class='wiki_active_link'>".$fullpath."</a>"); }else { array_push($data_array, "<a href='".$href."' class='wiki_active_link'>".$write['doc']."</a>"); } }else { $sql = "SELECT val FROM ".$args['db_table']." WHERE bo_table='".$this->bo_table."' AND ".$args['filter_keyword']." AND col='".$args['field']."' AND wr_id=".$wr_id." GROUP BY wr_id"; $row = sql_fetch($sql); array_push($data_array, $row['val']); } if($args['method'] == "item") { return " ".array_shift($data_array)." "; } } if(count($data_array) == 0) return " <span style='color:red;'>등록정보없음</span> "; sort($data_array); return " ".implode(", ", $data_array)." "; } }
<? /** * * 액션 스크립트 : 댓글 삭제 (삭제된 후) * * @package narinwiki * @subpackage event * @license GPL2 (http://narinwiki.org/license) * @author byfun (http://byfun.com) * @filesource */ if (!defined('_GNUBOARD_')) exit; if($article_of_delete_comment) { $doc = wiki_doc($article_of_delete_comment['ns'], $article_of_delete_comment['doc']); // 최근 변경 내역 업데이트 $wikiChanges =& wiki_class_load("Changes"); $wikiChanges->update("DOC", $doc, "댓글삭제", ($member['mb_id'] ? $member['mb_id'] : $write['wr_name'])); } ?>
/** * * 폴더내 파일 목록 반환 * * @param string $parent 폴더경로 * @return array 파일정보배열 : array(array("id"=>파일id, * "ns"=>폴더경로, * "source"=>파일원본이름, * "file"=>저장된파일이름, * "path"=>파일저장경로(파일명포함), * "href"=>다운로드URL, * "imgsrc"=>이미지SRC (href와 같음), * "filesize"=>파일크기(bytes), * "downloads"=>다운로드카운트, * "reg_date"=>파일등록시간, * "img_width"=>이미지너비(px), * "img_height"=>이미지높이(px), * "img_type"=>이미지유형, * "mb_id"=>파일등록자 아이디, * "mb_name"=>파일등록자 이름, * "mb_nick"=>파일등록자 닉네임)) */ function getList($parent = "/") { $escapedParent = mysql_real_escape_string($parent); $regp = ($parent == "/" ? "/" : $escapedParent."/"); $sql = "SELECT m.id, nt.ns, m.source, m.file, m.filesize, m.downloads, m.reg_date, m.img_width, m.img_height, m.img_type, m.downloads, m.mb_id, mb.mb_name, mb.mb_nick, m.reg_date FROM ".$this->wiki['media_ns_table']." AS nt LEFT JOIN ".$this->wiki['media_table']." AS m ON nt.ns = m.ns AND nt.bo_table = m.bo_table LEFT JOIN {$this->g4['member_table']} AS mb ON m.mb_id = mb.mb_id WHERE nt.ns = '$escapedParent' AND nt.bo_table = '".$this->wiki['bo_table']."' ORDER BY m.reg_date DESC"; $files = array(); $result = sql_query($sql); while ($row = sql_fetch_array($result)) { if($row['ns'] == $parent) { if(!$row['source']) continue; //if(is_callable($filter) && !$filter($row)) continue; $row['path'] = WIKI_PATH.'/data/'.$this->wiki['bo_table'].'/files/'.$row['file']; $row['href'] = $this->wiki['url'].'/exe/media_download.php?bo_table='.$this->wiki['bo_table'].'&file='.urlencode(wiki_doc($row['ns'], $row['source'])); $row['imgsrc'] = $this->wiki['url'].'/exe/media_download.php?bo_table='.$this->wiki['bo_table'].'&w=img&file='.urlencode(wiki_doc($row['ns'], $row['source'])); array_push($files, $row); } } return $files; }
* include head.sub 스크립트 * * @package narinwiki * @subpackage event * @license GPL2 (http://narinwiki.org/license) * @author byfun (http://byfun.com) * @filesource */ if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 if(file_exists(WIKI_PATH."/narin.config.php") ) { if(!$doc && $wr_id) { $wikiArticle =& wiki_class_load("Article"); $tmp = &$wikiArticle->getArticleById($wr_id); $doc = wiki_doc($tmp['ns'], $tmp['doc']); list($ns, $docname, $doc) = wiki_page_name($doc); } $scriptFile = basename($_SERVER['SCRIPT_NAME']); $wikiEvent =& wiki_class_load("Event"); extract($wikiEvent->trigger("LOAD_HEAD", array("script"=>$scriptFile, "folder"=>$ns, "docname"=>$docname, "doc"=>$doc))); $css_path = $wiki['url'].'/css.php'; $js_path = $wiki['url'].'/js.php'; if($wiki['fancy_url']) { $css_path = $wiki['url'].'/_narin.css'; $js_path = $wiki['url'].'/_narin.js'; }
parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $args); if(!empty($args)) { extract($args); foreach($args as $k => $v) $_GET[$k] = $v; } } // $doc, $loc 변수 셋팅 $loc = str_replace('+', ' ', stripcslashes($loc)); $doc = str_replace('+', ' ', stripcslashes($doc)); if($loc && $doc) $doc = $loc."/".$doc; else if(!$doc && $wr_doc) $doc = $wr_doc; else if(!$doc && $wr_id) { $wikiArticle =& wiki_class_load("Article"); $wr = $wikiArticle->getArticleById($wr_id); $doc = wiki_doc($wr['ns'], $wr['doc']); } else if(!$doc) $doc = "/".$wiki['front']; $doc = preg_replace('/\/+/', '/', $doc); list($ns, $docname, $doc) = wiki_validate_doc($doc); // 이벤트 오브젝트 로드 $wikiEvent =& wiki_class_load("Event"); // 스킨 패스/URL 설정 // fancy url 지원을 위해 절대경로와 URL경로로 구분하여 사용 define(SKIN_PATH, WIKI_PATH.'/skin/board/'.$skin); define(SKIN_URL, $wiki['url'].'/skin/board/'.$skin); /**
* @license GPL2 (http://narinwiki.org/license) * @author byfun (http://byfun.com) * @filesource */ include_once "./_common.php"; if( !$is_wiki_admin ) { alert("권한이 없습니다"); exit; } $folder = stripcslashes($folder); $move_to_folder = stripcslashes($move_to_folder); if($folder != $move_to_folder) { $wikiArticle =& wiki_class_load("Article"); for($i=0; $i<count($chk_wr_id); $i++) { $wr = &$wikiArticle->getArticleById($chk_wr_id[$i]); if(!$wr) continue; $fromDoc = wiki_doc($folder, $wr['wr_subject']); $toDoc = wiki_doc($move_to_folder, $wr['wr_subject']); $wikiArticle->moveDoc($fromDoc, $toDoc, $wr['wr_id']); } } header("location:".wiki_url('folder', array('loc'=>stripcslashes($move_to_folder)))); ?>
/** * * template 처리 * * @param array $matches 패턴매칭 결과 * @param array $params {@link NarinParser} 에서 전달하는 파라미터 * @return */ public function wiki_template($matches, $params) { // matches[1] : /template/form // matches[4] : list of parameter=value after '?' $pattern = '/((.*)\\/)([^\\/\\#]*)(\\#(.*))?$/'; preg_match($pattern, $matches[1], $m); // m[1]: root namespace if m[2]=NULL // m[2]: non-root namespace // m[3]: docname // m[5]: secname if any $args = array(); $args['loc'] = $m[2] ? $m[2] : $m[1]; $args['docname'] = $m[3]; $args['secname'] = $m[5] ? $m[5] : ""; $args['path'] = wiki_doc($args['loc'], $args['docname']); // $args['options'] = htmlspecialchars($matches[4]); $args['options'] = urlencode($matches[4]); // 작성자 레벨 셋팅 if ($params[view][mb_id]) { $writer = get_member($params[view][mb_id]); $args['writer_level'] = $writer[mb_level]; } else { $args['writer_level'] = 0; } $templated = $this->wiki_template_nojs(&$args, &$params); $options = wiki_json_encode($args); return '<nocache plugin="template" method="cache_render" params="' . addslashes($options) . '">' . $templated . '</nocache>'; }
function get_media_list($parent = "/", $add_where = "", $paging = array(), $ordering = array()) { $escapedParent = mysql_real_escape_string($parent); $regp = ($parent == "/" ? "/" : $escapedParent."/"); $top = ""; $use_paging = false; $limit = ""; $from_record = 0; $page_rows = 0; if(isset($paging['page']) && isset($paging['page_rows']) && $ordering['by'] != 'random') { $sql = "SELECT count(m.id) as count FROM ".$this->wiki['media_ns_table']." AS nt LEFT JOIN ".$this->wiki['media_table']." AS m ON nt.ns = m.ns AND nt.bo_table = m.bo_table WHERE nt.ns = '$escapedParent' AND nt.bo_table = '".$this->wiki['bo_table']."'"; $tmp = sql_fetch($sql); $total = $tmp['count']; $page = $paging['page']; $page_rows = $paging['page_rows']; $from_record = ($page - 1) * $page_rows; // 시작 열을 구함 $limit = " LIMIT $from_record, " . $page_rows; $use_paging = true; } $order_by = 'm.reg_date'; $order = 'DESC'; $order_by = 'm.'.$ordering['by']; $order = $ordering['order']; if($ordering['by'] == 'random') { $order_by = 'RAND()'; $order = ''; if($limit) { $limit = ''; } } $sql = "SELECT m.id, nt.ns, m.source, m.file, m.filesize, m.downloads, m.reg_date, m.img_width, m.img_height, m.img_type, m.mb_id, mb.mb_name, mb.mb_nick FROM ".$this->wiki['media_ns_table']." AS nt LEFT JOIN ".$this->wiki['media_table']." AS m ON nt.ns = m.ns AND nt.bo_table = m.bo_table LEFT JOIN {$this->g4['member_table']} AS mb ON m.mb_id = mb.mb_id WHERE nt.ns = '$escapedParent' AND nt.bo_table = '".$this->wiki['bo_table']."' $add_where ORDER BY $order_by $order $limit"; $files = array(); $result = sql_query($sql); while ($row = sql_fetch_array($result)) { if($row['ns'] == $parent) { if(!$row['source']) continue; //if(is_callable($filter) && !$filter($row)) continue; $row['path'] = $this->wiki['url'].'/data/'.$this->wiki['bo_table'].'/files/'.$row['file']; if(!$this->wiki['fancy_url']) { $row['href'] = $this->wiki['url'].'/exe/media_download.php?file='.urlencode(wiki_doc($row['ns'], $row['source'])); $row['imgsrc'] = $this->wiki['url'].'/exe/media_download.php?file='.urlencode(wiki_doc($row['ns'], $row['source'])); } else { $row['href'] = $this->wiki['url'].'/_media/'.wiki_doc($row['ns'], $row['source']); $row['imgsrc'] = $this->wiki['url'].'/_media/'.wiki_doc($row['ns'], $row['source']); } array_push($files, $row); } } return array($total, $from_record, $page_rows, $files); }
/** * * include 처리 * * @param array $matches 패턴매칭 결과 * @param array $params {@link NarinParser} 에서 전달하는 파라미터 * @return string include되고 파싱된 결과 */ public function wiki_include($matches, $params) { // matches[1] : (/folder)/article(#section) // matches[4] : parameters after '?' $args = array(); $pattern = '/((.*)\\/)([^\\/\\#]*)(\\#(.*))?$/'; preg_match($pattern, $matches[1], $m); // parse options if ($matches[4]) { parse_str(str_replace("&", "&", $matches[4]), $args); } // m[1]: root namespace if m[2]=NULL // m[2]: non-root namespace // m[3]: docname // m[5]: secname if any $args['loc'] = $m[2] ? $m[2] : $m[1]; $args['docname'] = $m[3]; $args['secname'] = $m[5] ? $m[5] : ""; $args['path'] = wiki_doc($args['loc'], $args['docname']); // plugin settings and alternative flags $args['nocontainer'] = $this->setting_nocontainer && ($args['box'] == "no" || isset($args['nocontainer'])) ? true : false; $args['firstseconly'] = $this->include_range == "FS" || (isset($args['firstseconly']) || isset($args['fso'])) ? true : false; // 작성자 레벨 셋팅 if ($params[view][mb_id]) { $writer = get_member($params[view][mb_id]); $writer_level = $writer[mb_level]; } else { $writer_level = 0; } // Include 사용 level check if ($this->allow_level > $writer_level) { return ""; } $args['includeTopSectionLevel'] = 999; $args['outdentation'] = 0; $included = $this->wiki_include_nojs($args, &$params); if (isset($args['partialnocache']) || isset($args['pnc'])) { $options = wiki_json_encode($args); return '<nocache plugin="include" method="cache_render" params="' . addslashes($options) . '">' . $included . '</nocache>'; } else { return $included; } }
/** * * datatable/datalist 출력 * * @param array $matches 패턴매칭 결과 * @param array $params {@link NarinParser} 에서 전달하는 파라미터 * @return string output */ public function wiki_dataout($matches, $params) { // $matches[1] = table or list // $matches[2] = content $args = array(); $args['type'] = $matches[1]; $content = $matches[2]; // content format // cols : %pageid%, name, description, author, lastupdate_dt // headers : Details, 플러그인 이름, 설명, 저자, 최종수정일 // max : 10 // filter : class=plugins // sort : ^name $fields = array(); $args['headers'] = array(); // only works for table $args['max'] = -1; $keyword = ''; $filter_keyword = '1'; $filters = array(); $sort_dir = 'ASC'; $sort_col = ''; $lines = preg_split( '/\r\n|\r|\n/', $content); foreach($lines as $line) { $kv = array_map('trim', explode(':', $line, 2)); switch($kv[0]) { case 'cols': case 'col': $cols = array_map('trim', explode(',', $kv[1])); foreach($cols as $col) { switch($col) { case '%pageid%': array_push($fields, 'fullpath'); break; case '%title%': array_push($fields, 'docname'); break; case '%class%': array_push($fields, 'class'); break; default: array_push($fields, $col); } } break; case 'headers': case 'header': case 'head': $args['headers'] = array_map('trim', explode(',', $kv[1])); break; case 'max': case 'limit': $args['max'] = $kv[1]; break; case 'filter': case 'where': case 'fiterand': case 'and': $op_pattern = '/^(.*?)(=|\!=|<>|<|<=|=>|>|\~|\!\~)(.*)$/s'; preg_match($op_pattern, $kv[1], $op_matches); $col = $op_matches[1]; $val = $op_matches[3]; $op = $op_matches[2]; $not = ""; if($op=='~') { // wildcard $op = 'LIKE'; $val = preg_replace('/\*/', '%', $val); }elseif($op=='!~') { // wildcard $op = 'LIKE'; $not = 'NOT'; $val = preg_replace('/\*/', '%', $val); }elseif($op=='!=' || $op=='<>') { $op = '='; $not = 'NOT'; }else { $op = preg_replace('/</','<',$op); $op = preg_replace('/>/','>',$op); } if($col == 'class') { $keyword = 'class'; $filter_keyword = $not." keyword ".$op." '".$val."' "; } else array_push($filters, "(col = '".$col."' AND ".$not." val ".$op." '".$val."')"); break; case 'sort': case 'order': if(preg_match('/^\^/',$kv[1])) { $sort_dir = 'DESC'; } $sort_col = trim($kv[1],'^'); break; } } $args['fields'] = $fields; // if headers are not specified, use col($fields) instead if(!$args['headers']) $args['headers'] = $args['fields']; $wikiArticle =& wiki_class_load("Article"); // retrieve the data $list = array(); $list_sort = array(); // filtering $filter_where = "1"; if(count($filters)) $filter_where = implode(' AND ', $filters); // currently dataentry without keyword might have a problem to show $sql_wr_id = "SELECT DISTINCT wr_id FROM ".$this->db_table." WHERE bo_table='".$this->bo_table."' AND ".$filter_keyword." AND ".$filter_where; $res_wr_id = sql_query($sql_wr_id); while($row_wr_id = sql_fetch_array($res_wr_id)) { $data = array(); $wr_id = $row_wr_id['wr_id']; $write = $wikiArticle->getArticleById($wr_id); foreach($fields as $field) { // fullpath is reserved for %pageid%, docname is reserved for %title% if($field=='fullpath' || $field=='docname') { $data['fullpath'] = wiki_doc($write['ns'], $write['doc']); $data['docname'] = $write['doc']; continue; } // class is reserved for %class% if($field == 'class') { // not much special treatment.. unless providing dynamic datatable page for specific class $data['class'] = $keyword; continue; } // other fields, potentially multiple values $sql = "SELECT col, val FROM ".$this->db_table." WHERE bo_table='".$this->bo_table."' AND wr_id=".$wr_id." AND ".$filter_keyword." AND col='".$field."'"; $res = sql_query($sql); $val_array = array(); while($row = sql_fetch_array($res)) { array_push($val_array, $row['val']); } $data[$field] = implode(", ", $val_array); // store the values for sorting.. for now %..% fields cannot be used for sorting.. WTH if($field == $sort_col) array_push($list_sort, $data[$field]); } array_push($list, $data); } // sorting if($sort_col) { if($sort_dir == 'ASC') { array_multisort($list_sort, SORT_ASC, $list); }else { array_multisort($list_sort, SORT_DESC, $list); } } if($args['type'] == 'table' || $args['type'] == 'stable') return $this->render_table($args, &$list, &$params); else return $this->render_list($args, &$list, &$params); }
/** * * 문서 반환 by wr_id * * @param int $wr_id 문서id (그누보드 게시판의 wr_id) * @return array 문서 데이터 */ public function & getArticleById($wr_id) { if($this->cache[$wr_id]) return $this->cache[$wr_id]; $wr_id = mysql_real_escape_string($wr_id); $sql = "SELECT wb.*, nt.*, wb.wr_subject AS doc, ht.reg_date AS update_date FROM ".$this->wiki['write_table']." AS wb LEFT JOIN ".$this->wiki['nsboard_table']." AS nt ON wb.wr_id = nt.wr_id LEFT JOIN ".$this->wiki['history_table']." AS ht ON wb.wr_id = ht.wr_id WHERE nt.bo_table = '".$this->wiki['bo_table']."' AND wb.wr_id = '$wr_id' ORDER BY ht.reg_date DESC LIMIT 1 "; $write = sql_fetch($sql); $write['contributors'] = $this->getContributor($wr_id); $full = wiki_doc($write['ns'], $write['doc']); $this->cache[$full] = &$write; $this->cache[$wr_id] = &$write; return $write; }