차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
tech:randompage [2013/10/08 10:13] V_Ltech:randompage [2016/07/12 09:26] (현재) – 바깥 편집 127.0.0.1
줄 1: 줄 1:
 +{{tag>randompage 도쿠위키 플러긴 dokuwiki plugin}}
 +======랜덤페이지 (Randompage) 플러긴======
 +
 +랜덤페이지 플러긴이다. 네임스페이스 지원하도록 약간 수정했다. 
 +다른 위키엔진들은 대부분 기본 기능인데;; 
 +(원작: https://www.dokuwiki.org/plugin:random_page )
 +
 +아래의 파일을 받아서 ''lib/plugins/randompage'' 안에 ''action.php''라는 이름으로 넣으면 된다.
 +
 +  ?do=randompage    
 +혹은
 +  ?do=nsrandompage
 +하면 된다.
 +
 +  * [[?do=randompage|http://openwiki.kr/tech:randompage?do=randompage]]  이것은 전체 위키페이지 중 무작위로 가고,
 +  * [[?do=nsrandompage|http://openwiki.kr/tech:randompage?do=nsrandompage]]   이것은 현재 이름공간의 페이지 중에서 골라 간다.
 +
 +
 +This supports namespaces.
 +
 +<file php action.php>
 +<?php
 +/**
 + * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 + * @author     Pete Prodoehl <[email protected]> and Jean Marc Massou <[email protected]>
 + */
 +
 +require_once(DOKU_PLUGIN.'action.php');
 +
 +class action_plugin_randompage extends Dokuwiki_Action_Plugin {
 +
 + /**
 + * Register its handlers with the dokuwiki's event controller
 + */
 + function register(&$controller) {
 + $controller->register_hook('ACTION_HEADERS_SEND', 'BEFORE', $this, 'init', 'header');
 + }
 +
 + function init(&$event, $args)
 + {
 + // Catch the good request
 + if ($_REQUEST['do'] == 'randompage'|| $_REQUEST['do'] == 'nsrandompage' ) {
 + // On efface les headers par defaut
 + if ($args == 'header') {
 + $this->action_randompage($event, $args);
 + }
 + }
 + }
 +
 +
 + function action_randompage(&$event, $args) {
 +
 + global $conf;
 + global $ID;
 +        global $INFO;
 +
 + $data = array();
 + $dir = $conf['savedir'];
 +
 + $data = file ($dir.'/index/page.idx');
 +
 + //if current page is in 
 + function isCurNS($value){
 + global $INFO;
 +            return stripos($value, $INFO['namespace'])===0 ? true : false;
 +        }
 +
 +       if ($INFO['namespace']!=null && $_REQUEST['do'] == 'nsrandompage' ) { 
 + $data=array_filter($data,"isCurNS" );
 +       }
 +          
 +        //We loops through ten random page...
 + $i = 1;
 + while ($i <= 10 & $i <> "ok"):
 + //echo $i;
 + $i++;
 +
 + $id = rtrim($data[array_rand($data)]);
 + $testACL = auth_aclcheck($id,$_SERVER['REMOTE_USER'],$USERINFO['grps']);
 +
 + if (($testACL > 1) and (file_exists(wikiFN($id)))){
 + $i="ok";
 + //echo $id;
 + }
 +
 + endwhile;
 +
 + if ($testACL < 1){
 + $id = $ID;
 + }
 +
 + header("Location: ".wl(trim($id),'',true));
 + //echo wl($page,'',true);
 + exit();
 + }
 +
 + //Function from Php manual to get  a random number in a Array
 + function array_rand($array, $lim=1) {
 + mt_srand((double) microtime() * 1000000);
 + for($a=0; $a<=$lim; $a++) {
 + $num[] = mt_srand(0, count($array)-1);
 + }
 + return @$num;
 + }    
 +}</file>
 +
 +^  누구나 수정하실 수 있다. [[http://vaslor.net/syntax|위키 사용법]] 참고하라.  ^
 +