Example #1
0
function plugin_multilang_inline_link($option, $args)
{
    global $vars;
    $body = array();
    $page = isset($vars['page']) ? $vars['page'] : '';
    $obj_l2c = new Lang2Country();
    foreach ($args as $arg) {
        $arg = htmlsc($arg);
        @(list($lang, $style) = explode('\\+', $arg));
        // en_US=English+flag=us
        @(list($lang, $title) = explode('=', $lang));
        @(list($style, $country) = explode('=', $style));
        if ($style != 'text') {
            // flag or text : default is flag
            if (empty($country)) {
                @(list($lng, $country) = explode('_', $lang));
                // en_US -> en, US
                if (empty($country)) {
                    $country = $obj_l2c->getLang2Country(strtolower($lng));
                }
            }
            if (!empty($country)) {
                $country = strtolower($country);
                $title = '<span class="flag flag-' . $country . '" title="' . $title . '" ></span>';
            }
        }
        array_push($body, '<a href="' . Router::get_cmd_uri('multilang', $page, null, array('lang' => $lang)) . '" rel="alternate" hreflang="' . strtolower(str_replace('_', '-', $lang)) . '">' . $title . '</a>');
    }
    if ($option == 'delim') {
        // default: nodelim
        return PLUGIN_MULTILANG_INLINE_BEFORE . join(PLUGIN_MULTILANG_INLINE_DELIMITER, $body) . PLUGIN_MULTILANG_INLINE_AFTER;
    }
    return '<span class="multilang">' . join(' ', $body) . '</span>';
}
Example #2
0
function plugin_livedoor_inline()
{
    global $vars, $auth_api, $_livedoor_msg;
    if (!$auth_api['livedoor']['use']) {
        return $_livedoor_msg['msg_invalid'];
    }
    $obj = new AuthLivedoor();
    $name = $obj->getSession();
    if (!empty($name['api']) && $obj->auth_name !== $name['api']) {
        return;
    }
    if (isset($name['livedoor_id'])) {
        /*
        $logout_url = $script.'?plugin=livedoor';
        if (! empty($vars['page'])) {
        	$logout_url .= '&amp;page='.rawurlencode($vars['page']).'&amp;logout';
        }
        */
        $logout_url = Router::get_cmd_uri('livedoor', $vars['page']) . '&amp;logout';
        return sprintf($_livedoor_msg['msg_logined'], $name['livedoor_id']) . '(<a href="' . $logout_url . '">' . $_livedoor_msg['msg_logout'] . '</a>)';
    }
    $auth_key = Auth::get_user_name();
    if (!empty($auth_key['nick'])) {
        return $_livedoor_msg['msg_livedoor'];
    }
    $login_url = plugin_livedoor_jump_url(1);
    return '<a href="' . $login_url . '">' . $_livedoor_msg['msg_livedoor'] . '</a>';
}
Example #3
0
function plugin_search_action()
{
    global $post, $vars;
    global $_search_msg, $_LANG;
    /*
    	if (isset($vars['update_index'])){
    		PukiWiki\SearchLucene::updateIndex();
    		return array('msg'=>'done.');
    	}
    */
    if (PLUGIN_SEARCH_DISABLE_GET_ACCESS) {
        $s_word = isset($post['word']) ? htmlsc($post['word']) : '';
    } else {
        $s_word = isset($vars['word']) ? htmlsc($vars['word']) : '';
    }
    if (strlen($s_word) > PLUGIN_SEARCH_MAX_LENGTH) {
        unset($vars['word']);
        // Stop using $_msg_word at lib/html.php
        die_message('Search words too long');
    }
    $type = isset($vars['type']) ? $vars['type'] : '';
    $base = isset($vars['base']) ? $vars['base'] : '';
    $format = isset($vars['format']) ? $vars['format'] : 'html';
    switch ($format) {
        case 'xml':
            // OpenSearch
            // http://www.opensearch.org/
            global $site_name, $notify_from, $shortcut_icon;
            $ret = array('<?xml version="1.0" encoding="UTF-8"?>', '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">', '<ShortName>' . $_search_msg['title_search'] . ' - ' . $site_name . '</ShortName>', '<Description>' . $_search_msg['title_search'] . ' - ' . $site_name . '</Description>', '<Contact>' . $notify_from . '</Contact>', '<Image height="16" width="16" type="image/x-icon">data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA%2F%2F%2F%2FBP%2F8%2BjT%2F7%2BdK%2F%2F38M%2F%2F%2F%2Fw0AAAAAAAAAAAAAAAAAAAAA%2F%2F%2F%2FC%2F%2F%2B%2FTH%2F7%2BdK%2F%2Fv4N%2F%2F%2F%2FwUAAAAA%2F%2F%2F%2FBf%2Ft5IH%2F5djE%2F%2FLsn%2F7u5pT63tKe%2BNzLkOjFmnnq27p%2B%2BOfXk%2Fnl06z%2B7eOV%2F%2FLsn%2F%2Fm2cD%2F6%2BGM%2F%2F%2F%2FBv%2F072P%2F5til%2F%2F%2F%2FGfz4%2BB%2FrqJOE9qBr7vukUv3%2FzoL%2F%2F%2Bao%2F%2Fznsv7337j4662LwPXWyyX%2F%2F%2F8Y%2F%2Bfbmv%2Fz7XD%2F7uaJ%2F%2FDohf%2F%2F%2FwH729Ib9loZzv97Jv7%2Fo0v%2F%2F%2BOt%2F%2F%2Fmrf%2F%2F0oD%2F%2F9KC%2F%2Fm3bu3vsZopAAAAAP%2Fw6H7%2F7uaQ%2FvHpgP%2Fy7JL%2F9vQW%2F1kvvf9UEef%2Fhj7v%2F%2FPP9%2F%2F95Pv%2F9df7%2F7FQ%2Bf%2BxUPT%2F0IPq%2F8V3xf%2F69RT%2F8uyR%2FvHphv%2F28Vr%2F9vGB%2F6qWsf9jK%2Bb%2FhEjm%2F7iF5v%2F16Ob%2F59Ln%2F9iw5%2F%2BZL%2Bf%2Fnzvm%2F%2Bq15v%2B1Zeb%2Bxp6x%2F%2Fbygf%2F07mf%2F%2F%2F8R%2FvHqkP68p9f%2FoW7o%2F4BL5v%2BCROb%2FfCrm%2F4Al5v%2BRPOb%2FvIXm%2F9Sp5v%2Fuxeb%2FsnHn%2F8Ci3f7x6o7%2F%2F%2F8XAAAAAP%2F38lz9o4Tu%2F9K28%2F%2FUs%2Bb%2FYxrm%2F3os5v%2BWSeb%2F1LPm%2F%2F%2F%2F5v%2F%2F%2Feb%2F9Nfm%2F9Wy8v%2BceO7%2F9fBoAAAAAAAAAAD%2F%2BfZD%2Brig8%2F%2FRtvH%2F8OLv%2F5dg5v%2BOSub%2FnFjm%2F8KW5v%2F%2F%2F%2Bb%2F%2F%2F7m%2F%2FPg7v%2FMqfH%2FsZnz%2F%2FfzTQAAAAD%2F%2F%2F8J%2F%2FDpku2EZcL8up71%2F%2BfW8v%2FUu%2B7%2Fp3Dm%2F6hw5v%2FKo%2Bb%2F4s7m%2F8ip7f%2FkzvP%2FzbD1%2FXxazP%2Fw6ZH%2F%2F%2F8O%2F%2Fn1SP%2F18ILtooy19Zt16v%2FUvfL%2Fz7Xy%2F9G07%2F%2FDmub%2F1bnm%2F%2FDn7v%2Fw4%2FL%2F38jy%2FYhb6%2FeTfbn%2F9fCB%2F%2FfyVf%2Fy63v%2F9O6N%2FPX1Hed%2BW7z%2BuZjq%2F%2Bja9P%2Fo2PH%2F4c3y%2F9i%2F8v%2Ft3%2FL%2F4s%2F0%2FKV%2B6%2BlUL8f77%2B0c%2F%2FTujf%2Fy64H%2F7OKA%2F%2FTvhv%2F%2F%2FwL35OAa9rmgwP%2F58On%2B7eL2%2F%2Bre%2BP7j1Pj%2B4M72%2BrCN6uNeOcb22dQi%2F%2F%2F%2FAf%2F074H%2F7OKG%2F%2FLsbf%2Fs4qj%2F%2F%2F8J%2F%2F%2F%2FDv3y8EX84tbL%2Fenh2v7m2vn93s%2F6%2BMq42%2FS6p8z77OhM%2F%2F%2F%2FD%2F%2F%2F%2Fwj%2F7eSc%2F%2FHqev%2F%2F%2Fwn%2F6NyN%2F%2BjcvP%2Fw6KH%2F8ema%2F%2B%2Fmk%2F%2Fv54%2F%2F%2B%2Fk2%2F%2Fv6MP%2Fv54z%2F7%2BaU%2F%2FDpmf%2Fw6KH%2F6d65%2FubZmP%2F%2F%2FwwAAAAA%2F%2F%2F%2FBf%2F59UP%2B7eNl%2FvPtVv%2F%2F%2Fx7%2F%2F%2F8CAAAAAAAAAAD%2F%2F%2F8C%2F%2F%2F%2FG%2F%2F07lP%2B7eNl%2F%2Fj0R%2F%2F%2F%2FwcAAAAAg8GsQQAArEEAAKxBAASsQQAArEEAAKxBAACsQYABrEGAAaxBAACsQQAArEEAAKxBAACsQQAArEEAAKxBgYGsQQ%3D%3D</Image>', '<Language>' . DEFAULT_LANG . '</Language>', '<InputEncoding>UTF-8</InputEncoding>', '<OutputEncoding>UTF-8</OutputEncoding>', '<Url type="text/html" method="' . (!PLUGIN_SEARCH_DISABLE_GET_ACCESS ? 'get' : 'post') . '" template="' . Router::get_script_uri() . '">', '<Param name="cmd" value="search" />', '<Param name="encode_hint" value="' . PKWK_ENCODING_HINT . '" />', '<Param name="type" value="AND" />', '<Param name="word" value="{searchTerms}" />', '</Url>', '<Url type="application/x-suggestions+json" template="' . Router::get_cmd_uri('list', null, null, array('type' => 'json')) . '&amp;word={searchTerms}" />', '<moz:SearchForm>' . Router::get_cmd_uri('search') . '</moz:SearchForm>', '</OpenSearchDescription>');
            header('Content-Type:application/opensearchdescription+xml');
            echo join("\n", $ret);
            exit;
            break;
        default:
            if ($s_word !== '') {
                // Search
                $msg = str_replace('$1', $s_word, $_search_msg['title_result']);
                $body = Search::do_search($vars['word'], $type, FALSE, $base);
            } else {
                // Init
                unset($vars['word']);
                // Stop using $_msg_word at lib/html.php
                $msg = $_search_msg['title_search'];
                $body = '<p>' . $_search_msg['msg_searching'] . '</p>' . "\n";
            }
            // Show search form
            $bases = $base == '' ? array() : array($base);
            $body .= plugin_search_search_form($s_word, $type, $bases);
            break;
    }
    return array('msg' => $msg, 'body' => $body);
}
Example #4
0
function plugin_jugemkey_convert()
{
    global $script, $vars, $auth_api, $_jugemkey_msg;
    if (!$auth_api['jugemkey']['use']) {
        return '<p>' . $_jugemkey_msg['msg_invalid'] . '</p>';
    }
    $obj = new AuthJugem();
    $name = $obj->getSession();
    if (isset($name['title'])) {
        // $name = array('title','ts','token');
        /*
        $logout_url = $script.'?plugin=jugemkey';
        if (! empty($vars['page'])) {
        	$logout_url .= '&amp;page='.rawurlencode($vars['page']).'&amp;logout';
        }
        */
        $logout_url = Router::get_cmd_uri('jugemkey', $vars['page']) . '&amp;logout';
        return <<<EOD
<div>
\t<label>JugemKey</label>:
\t{$name['title']}
\t(<a href="{$logout_url}">{$_jugemkey_msg['msg_logout']}</a>)
</div>

EOD;
    }
    // 他でログイン
    $auth_key = Auth::get_user_name();
    if (!empty($auth_key['nick'])) {
        return '';
    }
    // ボタンを表示するだけ
    $login_url = $script . '?cmd=jugemkey';
    if (!empty($vars['page'])) {
        $login_url .= '&amp;page=' . rawurlencode($vars['page']);
    }
    $login_url .= '&amp;login';
    return <<<EOD
<form action="{$login_url}" method="post">
\t<div>
\t\t<input type="submit" class="btn btn-success" value="{$_jugemkey_msg['btn_login']}" />
\t</div>
</form>

EOD;
}
Example #5
0
function plugin_spam_action()
{
    global $vars, $_spam_messages;
    if (PKWK_READONLY) {
        Utility::die_message($_spam_messages['msg_prohibit']);
    }
    // Dispatch
    $mode = isset($vars['mode']) ? $vars['mode'] : '';
    if ($mode == 'pages') {
        return plugin_spam_pages();
    }
    // TODO:
    // Checking own backup/*.gz, backup/*.txt for determine the clearance
    // Check text
    // Check attach
    $body = 'Choose one: ' . "\n" . '<a href="' . Router::get_cmd_uri('spam', '', '', array('mode' => 'pages')) . '">' . $_spam_messages['title_pages'] . '</a>' . "\n";
    return array('msg' => $_spam_messages['title'] . $_spam_messages['title_menu'], 'body' => nl2br($body));
}
Example #6
0
function plugin_hatena_inline()
{
    global $script, $vars, $auth_api, $_hatena_msg;
    if (!$auth_api['hatena']['use']) {
        return $_hatena_msg['msg_invalid'];
    }
    $obj = new AuthHatena();
    $name = $obj->getSession();
    if (!empty($name['api']) && $obj->auth_name !== $name['api']) {
        return;
    }
    if (isset($name['name'])) {
        // $name = array('name','ts','image_url','thumbnail_url');
        $link = $name['name'] . '<img src="' . $name['thumbnail_url'] . '" alt="id:' . $name['name'] . '" />';
        $logout_url = Router::get_cmd_uri('hatena', null, null, array('page' => $vars['page'], 'logout' => 'true'));
        return sprintf($_hatena_msg['msg_logined'], $link) . '(<a href="' . $logout_url . '">' . $_hatena_msg['msg_logout'] . '</a>)';
    }
    $auth_key = Auth::get_user_name();
    if (!empty($auth_key['nick'])) {
        return $_hatena_msg['msg_hatena'];
    }
    return '<a href="' . $obj->make_login_link() . '">' . $_hatena_msg['msg_hatena'] . '</a>';
}
Example #7
0
 public function open_close($mode, $edit)
 {
     $button_name = array('lock' => T_('Locked'), 'unlock' => T_('Unlocked'));
     if ($mode == 'lock') {
         $edit = 'on';
         $table_mod = 'unlock';
     } else {
         $edit = 'off';
         $table_mod = 'lock';
     }
     $ret = array();
     $ret[] = '<div class="pull-right" id="TableEdit2TableNumber' . $this->count . '">';
     $ret[] = '<a href="' . Router::get_cmd_uri('table_edit2', null, null, array('refer' => $this->page, 'table_mod' => $table_mod, 'table_num' => $this->count, 'encode_hint' => PKWK_ENCODING_HINT)) . '" class="btn btn-secondary" nofollow="nofollow" data-ajax="false" title="' . $button_name[$table_mod] . '"><span class="fa fa-' . $table_mod . '"></span></a>';
     $ret[] = $this->set_csv;
     $ret[] = '</div>';
     $ret[] = '<div class="clearfix"></div>';
     return join("\n", $ret);
 }
Example #8
0
 /**
  * ページのリンクリストを作る
  * @param $pages ページ
  * @param $cmd 使用するプラグイン
  * @param boolean $with_filename ページのファイル名も表示する
  * @return string
  */
 private static function getPageLists($pages, $cmd = 'read', $with_filename = false)
 {
     $contents = array();
     // コンテンツ管理者以上は、: のページも閲覧可能
     $has_permisson = Auth::check_role('role_contents_admin');
     foreach ($pages as $page) {
         $wiki = Factory::Wiki($page);
         // 存在しない場合、当然スルー
         if (!$wiki->has()) {
             continue;
         }
         // 隠しページの場合かつ、隠しページを表示できる権限がない場合スルー
         if ($wiki->isHidden() && $has_permisson) {
             continue;
         }
         // 閲覧できる権限がない場合はスルー
         if (!$wiki->isReadable()) {
             continue;
         }
         $_page = Utility::htmlsc($page, ENT_QUOTES);
         if ($cmd !== 'attach') {
             $contents[] = IS_MOBILE ? '<li><a href="' . $wiki->uri($cmd) . '" data-transition="slide">' . $_page . '</a>' . '<span class="ui-li-count">' . $wiki->passage(false, false) . '</span></li>' : '<li><a href="' . $wiki->uri($cmd) . '">' . $_page . '</a> ' . $wiki->passage() . ($with_filename ? '<br /><var>' . Utility::htmlsc($wiki->filename) . '</var>' : '');
             '</li>';
         } else {
             $ret = array();
             $ret[] = '<li><a href="' . Router::get_cmd_uri('attach', null, null, array('page' => $page, 'ajax' => 'false')) . '">' . $_page . '</a> ';
             $attaches = $wiki->attach();
             if (count($attaches) !== 0) {
                 $ret[] = '<ul>';
                 foreach ($attaches as $filename => $files) {
                     $ret[] = '<li><a href="' . Router::get_cmd_uri('attach', null, null, array('refer' => $page, 'pcmd' => 'info', 'file' => $filename)) . '">' . Utility::htmlsc($filename) . '</a></li>';
                 }
                 $ret[] = '</ul>';
             }
             $ret[] = '</li>';
             $contents[] = join("\n", $ret);
         }
     }
     return $contents;
 }
Example #9
0
 /**
  * ヘッダー配列を取得
  * @param string $content_type Mimeタイプ
  * @param int $modified 更新日時。通常はfilemtimeの値
  * @param int $exprire 有効期限。デフォルトは1週間
  * @return array
  */
 public static function getHeaders($content_type = self::DEFAULT_CONTENT_TYPE, $modified = 0, $expire = 604800)
 {
     global $lastmod, $vars, $_SERVER;
     // これまでのヘッダーを取得
     $headers = function_exists('getallheaders') ? getallheaders() : array();
     $headers['Content-Type'] = $content_type;
     $headers['Content-Language'] = substr(str_replace('_', '-', LANG), 0, 2);
     // 更新日時をチェック
     if ($modified !== 0) {
         // http://firegoby.jp/archives/1730
         $last_modified = gmdate('D, d M Y H:i:s', $modified);
         $etag = md5($last_modified);
         $headers['Cache-Control'] = 'private';
         $headers['Pragma'] = 'cache';
         $headers['Expires'] = gmdate('D, d M Y H:i:s', time() + $expire) . ' GMT';
         $headers['Last-Modified'] = $last_modified;
         $headers['ETag'] = $etag;
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $last_modified || isset($_SERVER['HTTP_IF_NONE_MATCH']) && preg_match('/' . $etag . '/', $_SERVER['HTTP_IF_NONE_MATCH'])) {
             self::WriteResponse($headers, Response::STATUS_CODE_304, null);
             exit;
         }
         //		header('If-Modified-Since: ' . $last_modified );
     } else {
         // PHPで動的に生成されるページはキャシュすべきではない
         $headers['Cache-Control'] = $headers['Pragma'] = 'no-cache';
         $headers['Expires'] = 'Sat, 26 Jul 1997 05:00:00 GMT';
     }
     // RFC2616
     // http://sonic64.com/2004-02-06.html
     $headers['Vary'] = self::getLanguageHeaderVary();
     if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && preg_match('/\\b(gzip|deflate|compress)\\b/i', $_SERVER['HTTP_ACCEPT_ENCODING'], $matches)) {
         $headers['Vary'] .= ',Accept-Encoding';
     }
     // HTTP access control
     // JSON脆弱性対策(Adv.では外部にAjax APIを提供することを考慮しない)
     // https://developer.mozilla.org/ja/HTTP_Access_Control
     $headers['Access-Control-Allow-Origin'] = Router::get_script_uri();
     // Content Security Policy
     // https://developer.mozilla.org/ja/Security/CSP/Using_Content_Security_Policy
     //$headers['Content-Security-Policy'] ='default-src \'self\' \'unsafe-inline\' ' . Render::JQUERY_CDN . ' ' . Render::BOOTSTRAP_CDN . '; img-src *;';
     // IEの自動MIME type判別機能を無効化する
     // http://msdn.microsoft.com/ja-jp/ie/dd218497.aspx
     $headers['X-Content-Type-Options'] = 'nosniff';
     // クリックジャッキング対策(IFRAME呼び出しは禁止!)
     // https://developer.mozilla.org/ja/The_X-FRAME-OPTIONS_response_header
     $headers['X-Frame-Options'] = 'deny';
     // XSS脆弱性対策(これでいいのか?)
     // http://msdn.microsoft.com/ja-jp/ie/dd218482
     $headers['X-XSS-Protection'] = '1; mode=block';
     // PingBack
     if ($vars['cmd'] === 'read' && isset($vars['page'])) {
         $headers['X-Pingback'] = Router::get_cmd_uri('xmlrpc');
     }
     return $headers;
 }
Example #10
0
 /**
  * Atom/rssを出力
  * string $page ページ名(ページ名が入っている場合はキャッシュは無効)
  * string $type rssかatomか。
  * boolean $force キャッシュ生成しない
  * return void
  */
 public static function getFeed($page = '', $type = 'rss', $force = false)
 {
     global $vars, $site_name, $site_logo, $modifier, $modifierlink, $_string, $cache;
     static $feed;
     // rss, atom以外はエラー
     if (!($type === 'rss' || $type === 'atom')) {
         throw new Exception('Recent::getFeed(): Unknown feed type.');
     }
     $content_type = $type === 'rss' ? 'application/rss+xml' : 'application/atom+xml';
     $body = '';
     if (empty($page)) {
         // recentキャッシュの更新チェック
         if ($cache['wiki']->getMetadata(self::RECENT_CACHE_NAME)['mtime'] > $cache['wiki']->getMetadata(self::FEED_CACHE_NAME)['mtime']) {
             $force = true;
         }
         if ($force) {
             // キャッシュ再生成
             unset($feed);
             $cache['wiki']->removeItem(self::FEED_CACHE_NAME);
         } else {
             if (!empty($feed)) {
                 // メモリにキャッシュがある場合
             } else {
                 if ($cache['wiki']->hasItem(self::FEED_CACHE_NAME)) {
                     // キャッシュから最終更新を読み込む
                     $feed = $cache['wiki']->getItem(self::FEED_CACHE_NAME);
                 }
             }
         }
     }
     if (empty($feed)) {
         // Feedを作る
         $feed = new Feed();
         // Wiki名
         $feed->setTitle($site_name);
         // Wikiのアドレス
         $feed->setLink(Router::get_script_absuri());
         // サイトのロゴ
         //$feed->setImage(array(
         //	'title'=>$site_name,
         //	'uri'=>$site_logo,
         //	'link'=>Router::get_script_absuri()
         //));
         // Feedの解説
         $feed->setDescription(sprintf($_string['feed_description'], $site_name));
         // Feedの発行者など
         $feed->addAuthor(array('name' => $modifier, 'uri' => $modifierlink));
         // feedの更新日時(生成された時間なので、この実装で問題ない)
         $feed->setDateModified(time());
         $feed->setDateCreated(time());
         // Feedの生成
         $feed->setGenerator(S_APPNAME, S_VERSION, 'http://pukiwiki.logue.be/');
         if (empty($page)) {
             // feedのアドレス
             // ※Zend\Feedの仕様上、&が自動的に&amp;に変更されてしまう
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&type=atom', 'atom');
             $feed->setFeedLink(Router::get_cmd_uri('feed'), 'rss');
             // PubSubHubbubの送信
             foreach (Ping::$pubsubhubbub_server as $uri) {
                 $feed->addHub($uri);
             }
         } else {
             $r_page = rawurlencode($page);
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&type=atom&refer=' . $r_page, 'atom');
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&refer=' . $r_page, 'rss');
         }
         $i = 0;
         // エントリを取得
         foreach (self::get() as $_page => $time) {
             // ページ名が指定されていた場合、そのページより下位の更新履歴のみ出力
             if (!empty($page) && strpos($_page, $page . '/') === false) {
                 continue;
             }
             $wiki = Factory::Wiki($_page);
             if ($wiki->isHidden()) {
                 continue;
             }
             $entry = $feed->createEntry();
             // ページのタイトル
             $entry->setTitle($wiki->title());
             // ページのアドレス
             $entry->setLink($wiki->uri());
             // ページの更新日時
             $entry->setDateModified($wiki->time());
             // ページの要約
             $entry->setDescription($wiki->description(self::FEED_ENTRY_DESCRIPTION_LENGTH));
             // 項目を追加
             $feed->addEntry($entry);
             $i++;
             if ($i >= self::RECENT_MAX_SHOW_PAGES) {
                 break;
             }
         }
         if (empty($page)) {
             // キャッシュに保存
             $cache['wiki']->setItem(self::FEED_CACHE_NAME, $feed);
         }
     }
     flush();
     $headers = Header::getHeaders($content_type);
     Header::writeResponse($headers, 200, $feed->export($type));
     //header('Content-Type: ' . $content_type);
     //echo $body;
     exit;
 }
Example #11
0
function plugin_adm_auth_wkgrp_convert()
{
    global $_adm_auth_wkgrp_msg, $_LANG;
    if (Auth::check_role('role_adm')) {
        return '';
    }
    if (!PLUGIN_ADM_AUTH_WKGRP_USE_WRITE_FUNC) {
        return '';
    }
    $config_page_name = ':config/' . CONFIG_AUTH_WKGRP;
    $msg = '';
    $script = Router::get_script_uri();
    $cmd_view = Router::get_page_uri($config_page_name);
    $cmd_edit = Router::get_cmd_uri('edit', $config_page_name);
    $cmd_guiedit = Router::get_cmd_uri('guiedit', $config_page_name);
    $cmd_check = Router::get_cmd_uri('adm_auth_wkgrp', '', '', array('pcmd' => 'check'));
    $cmd_import = Router::get_cmd_uri('adm_auth_wkgrp', '', '', array('pcmd' => 'import'));
    $filetime_auth_wkgrp = filemtime(PKWK_AUTH_WKGRP_FILE);
    $date_auth_wkgrp = format_date($filetime_auth_wkgrp);
    if (is_page($config_page_name)) {
        $filetime_config_page = get_filetime($config_page_name);
        $date_config_page = format_date($filetime_config_page);
        $guide_msg = $filetime_config_page > $filetime_auth_wkgrp ? '<strong>' . $_adm_auth_wkgrp_msg['msg_gen'] . '</strong>' : '';
        $link_page = <<<EOD
[<a href="{$cmd_edit}">{$_LANG['skin']['edit']}</a>]
[<a href="{$cmd_guiedit}">{$_LANG['skin']['guiedit']}</a>]

EOD;
        $link_file = <<<EOD
<form action="{$script}" method="post" class="adm_auth_wkgrp_form">
\t<input type="hidden" name="cmd" value="adm_auth_wkgrp" />
\t<input type="hidden" name="pcmd" value="gen" />
\t<input type="submit" class="btn btn-secondary" value="{$_adm_auth_wkgrp_msg['btn_gen']}" />
\t{$guide_msg}
</form>

EOD;
    } else {
        $date_config_page = 'N/A';
        $link_page = '[<a href="' . $cmd_import . '">' . $_adm_auth_wkgrp_msg['msg_import'] . '</a>]';
        $link_file = '';
    }
    $rc = <<<EOD
<div class="adm_auth_wkgrp">
\t<fieldset>
\t\t<legend>{$_adm_auth_wkgrp_msg['head_title']}</legend>
\t\t<table class="table">
\t\t\t<thead>
\t\t\t\t<tr>
\t\t\t\t\t<th>
\t\t\t\t\t\t{$_adm_auth_wkgrp_msg['msg_head_page']}
\t\t\t\t\t\t(<a href="{$cmd_view}">{$_adm_auth_wkgrp_msg['msg_view']}</a>)
\t\t\t\t\t</td>
\t\t\t\t\t<th>
\t\t\t\t\t\t{$_adm_auth_wkgrp_msg['msg_head_file']}
\t\t\t\t\t\t(<a href="{$cmd_check}">{$_adm_auth_wkgrp_msg['msg_check']}</a>)
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</thead>
\t\t\t<tbody>
\t\t\t\t<tr>
\t\t\t\t\t<td>{$_adm_auth_wkgrp_msg['msg_head_update']}: {$date_config_page}</td>
\t\t\t\t\t<td>{$_adm_auth_wkgrp_msg['msg_head_gen']}: {$date_auth_wkgrp}</td>
\t\t\t\t</tr>
\t\t\t\t<tr>
\t\t\t\t\t<td>{$link_page}</td>
\t\t\t\t\t<td>{$link_file}</td>
\t\t\t\t</tr>
\t\t\t</tbody>
\t\t</table>
\t</fieldset>
</div>
EOD;
    return $rc;
}
Example #12
0
 /**
  * 添付ファイル一覧
  * @return string
  */
 private function getAttaches()
 {
     // TODO: UPLOAD_DIRの参照方法の変更
     global $_LANG;
     $ret = array();
     $exists = false;
     $attaches = $this->wiki->attach(false);
     if (!empty($attaches)) {
         $ret[] = '<dl class="list-inline">';
         $ret[] = '<dt>' . $_LANG['skin']['attach_title'] . '</dt>';
         foreach ($attaches as $filename => $files) {
             if (!isset($files[0])) {
                 continue;
             }
             $fileinfo = new AttachFile($this->page, $filename);
             $exists = true;
             if (!$fileinfo->has()) {
                 continue;
             }
             $logfileinfo = new AttachFile($this->page, $filename, 'log');
             $count = $logfileinfo->has() ? $logfileinfo->head(1) : '0';
             $ret[] = '<dd><a href="' . Router::get_cmd_uri('attach', null, null, array('pcmd' => 'open', 'refer' => $this->page, 'age' => 0, 'openfile' => $filename)) . '" title="' . Time::getZoneTimeDate('Y/m/d H:i:s', $fileinfo->time()) . ' ' . sprintf('%01.1f', round($fileinfo->getSize() / 1024, 1)) . 'KB' . '"><span class="fa fa-download"></span>' . Utility::htmlsc($filename) . '</a> ' . '<a href="' . Router::get_cmd_uri('attach', null, null, array('pcmd' => 'info', 'refer' => $this->page, 'file' => $filename)) . '" class="btn btn-default btn-xs" title="' . $_LANG['skin']['attach_info'] . '">' . '<span class="fa fa-info"></span></a>' . '</dd>';
         }
         $ret[] = '</dl>';
     }
     return $exists ? join("\n", $ret) : null;
 }
Example #13
0
 /**
  * リンクを作成(厳密にはimgタグ、audioタグ、videoタグにも使用するが)
  * @param string $term リンクの名前
  * @param string $uri リンク先
  * @param string $tooltip title属性の内容
  * @param string $rel リンクのタイプ
  * @return string
  */
 public static function setLink($term, $uri, $tooltip = '', $rel = '', $is_redirect = PKWK_USE_REDIRECT)
 {
     $_uri = Utility::htmlsc($uri);
     $href = $is_redirect ? Router::get_cmd_uri('redirect', null, null, array('u' => $uri)) : $_uri;
     $_term = Utility::htmlsc($term);
     $_tooltip = !empty($tooltip) ? ' title="' . Utility::htmlsc($tooltip) . '"' : '';
     // rel = "*"を生成
     $rels[] = 'external';
     if (!empty($rel)) {
         $rels[] = $rel;
     }
     if ($is_redirect) {
         $rels[] = 'nofollow';
     }
     $ext_rel = join(" ", $rels);
     // メディアファイル
     if (!PKWK_DISABLE_INLINE_IMAGE_FROM_URI && Utility::isUri($uri)) {
         if (preg_match(RendererDefines::IMAGE_EXTENTION_PATTERN, $uri)) {
             // 画像の場合
             $term = '<img src="' . $_uri . '" alt="' . $_term . '" ' . $_tooltip . ' />';
         } else {
             // 音声/動画の場合
             $anchor = '<a href="' . $href . '" rel="' . (self::isInsideUri($uri) ? $rel : $ext_rel) . '"' . $_tooltip . '>' . $_term . '</a>';
             // 末尾のアイコン
             $icon = self::isInsideUri($uri) ? '<a href="' . $href . '" rel="' . $rel . '">' . RendererDefines::INTERNAL_LINK_ICON . '</a>' : '<a href="' . $href . '" rel="' . $ext_rel . '">' . RendererDefines::EXTERNAL_LINK_ICON . '</a>';
             if (preg_match(RendererDefines::VIDEO_EXTENTION_PATTERN, $uri)) {
                 return '<video src="' . $_uri . '" alt="' . $_term . '" controls="controls"' . $_tooltip . '>' . $anchor . '</video>' . $icon;
             } else {
                 if (preg_match(RendererDefines::AUDIO_EXTENTION_PATTERN, $uri)) {
                     return '<audio src="' . $_uri . '" alt="' . $_term . '" controls="controls"' . $_tooltip . '>' . $anchor . '</audio>' . $icon;
                 }
             }
         }
     }
     // リンクを出力
     return self::isInsideUri($uri) ? '<a href="' . $href . '" rel="' . $rel . '"' . $_tooltip . '>' . $term . RendererDefines::INTERNAL_LINK_ICON . '</a>' : '<a href="' . $href . '" rel="' . $ext_rel . '"' . $_tooltip . '>' . $term . RendererDefines::EXTERNAL_LINK_ICON . '</a>';
 }
Example #14
0
function plugin_calendar_convert()
{
    global $vars, $post, $get, $_labels;
    //global $_calendar_plugin_edit, $_calendar_plugin_empty;
    global $_calendar_msg;
    if (!isset($vars['page'])) {
        return '';
    }
    /* from Plus! */
    $today_view = TRUE;
    $today_args = 'view';
    $date_str = Time::getZoneTimeDate('Ym');
    $base = Utility::stripBracket($vars['page']);
    $today_view = TRUE;
    if (func_num_args() > 0) {
        $args = func_get_args();
        foreach ($args as $arg) {
            if (is_numeric($arg) && strlen($arg) == 6) {
                $date_str = $arg;
            } else {
                if ($arg == 'off') {
                    $today_view = FALSE;
                } else {
                    if ($arg == 'past' || $arg == 'pastex' || $arg == 'future' || $arg == 'futureex' || $arg == 'view' || $arg == 'viewex') {
                        /* from Plus! */
                        $today_args = $arg;
                    } else {
                        $base = Utility::stripBracket($arg);
                    }
                }
            }
        }
    }
    if ($base == '*') {
        $base = '';
        $prefix = '';
    } else {
        $prefix = $base . '/';
    }
    $s_base = Utility::htmlsc($base);
    $s_prefix = Utility::htmlsc($prefix);
    $yr = substr($date_str, 0, 4);
    $mon = substr($date_str, 4, 2);
    if ($yr != get_date('Y') || $mon != get_date('m')) {
        $now_day = 1;
        $other_month = 1;
    } else {
        $now_day = get_date('d');
        $other_month = 0;
    }
    $today = getdate(mktime(0, 0, 0, $mon, $now_day, $yr));
    $m_num = $today['mon'];
    $d_num = $today['mday'];
    $year = $today['year'];
    $f_today = getdate(mktime(0, 0, 0, $m_num, 1, $year));
    $wday = $f_today['wday'];
    $day = 1;
    $m_name = Time::format($today[0], false, $_calendar_msg['_calendar_title_format']);
    $y = substr($date_str, 0, 4) + 0;
    $m = substr($date_str, 4, 2) + 0;
    $format = '%04d%02d';
    $prev_link = Router::get_cmd_uri('calendar', '', '', array('file' => $base, 'mode' => $today_args, 'date' => $m == 1 ? sprintf($format, $y - 1, 12) : sprintf($format, $y, $m - 1)));
    $next_link = Router::get_cmd_uri('calendar', '', '', array('file' => $base, 'mode' => $today_args, 'date' => $m == 12 ? sprintf($format, $y + 1, 1) : sprintf($format, $y, $m + 1)));
    $this_date_str = sprintf($format, $y, $m);
    $page_YM = sprintf('%04d-%02d', $y, $m);
    $ret = '';
    if ($today_view === TRUE) {
        $ret .= '<div class="clearfix">' . "\n" . '<div class="style_calendar_viewer">' . "\n";
        // カレンダーのdivタグ($today_view有効時のみ出力)
    }
    $ret .= <<<EOD
<table class="table table-bordered style_calendar" summary="calendar" data-sortable="false">
\t<thead>
\t\t<tr>
\t\t\t<td class="style_calendar_top" colspan="7">
\t\t\t\t<nav>
\t\t\t\t\t<ul class="style_calendar_navi">
\t\t\t\t\t\t<li class="style_calendar_prev"><a href="{$prev_link}">&lt;&lt;</a></li>
\t\t\t\t\t\t<li class="style_calendar_title"><strong>{$m_name}</strong></li>
\t\t\t\t\t\t<li class="style_calendar_next"><a href="{$next_link}">&gt;&gt;</a></li>
\t\t\t\t\t</ul>
\t\t\t\t</nav>
EOD;
    if ($vars['cmd'] == 'calendar' || $vars['cmd'] == 'calendar_viewer') {
        $base_link = Factory::Wiki($base)->uri();
    } else {
        $base_link = Router::get_cmd_uri('calendar', '', '', array('file' => $base, 'mode' => $today_args, 'date' => sprintf($format, $y, $m)));
    }
    if ($prefix) {
        $ret .= "\n" . '				[<a href="' . $base_link . '">' . $s_base . '</a>]';
    }
    $ret .= "\n" . '			</td>' . "\n" . '		</tr>' . "\n" . '	</thead>' . "\n" . '	<tbody>' . "\n" . '		<tr>' . "\n";
    for ($i = 0; $i < 7; $i++) {
        if ($i == 0) {
            $class = 'week_sun';
        } else {
            if ($i == 6) {
                $class = 'week_sat';
            } else {
                $class = 'week_day';
            }
        }
        $ret .= '			<th class="style_calendar_week"><abbr title="' . $_labels['week'][$i][1] . '" class="' . $class . '">' . $_labels['week'][$i][0] . '</abbr></th>' . "\n";
    }
    unset($i, $class);
    $ret .= '		</tr>' . "\n" . '		<tr>' . "\n";
    // Blank
    for ($i = 0; $i < $wday; $i++) {
        $ret .= '			<td class="blank-cell"></td>' . "\n";
    }
    while (checkdate($m_num, $day, $year)) {
        $dt = sprintf(PLUGIN_CALENDAR_PAGENAME_FORMAT, $year, $m_num, $day);
        $page = $prefix . $dt;
        $s_page = Utility::htmlsc($page);
        $wiki = Factory::Wiki($page);
        if ($wday == 0 && $day > 1) {
            $ret .= '		</tr>' . "\n" . '		<tr>' . "\n";
        }
        /* from Plus! */
        $h_today = PublicHolidayFactory::factory('JP', $year, $m_num, $day);
        $hday = $h_today['rc'];
        $style = 'style_calendar_day';
        // Weekday
        if (!$other_month && $day == $today['mday'] && $m_num == $today['mon'] && $year == $today['year']) {
            // Today
            $style = 'style_calendar_today';
        } else {
            if ($hday !== 0) {
                // Holiday
                $style = 'style_calendar_holiday';
            } else {
                if ($wday == 0) {
                    // Sunday
                    $style = 'style_calendar_sun';
                } else {
                    if ($wday == 6) {
                        // Saturday
                        $style = 'style_calendar_sat';
                    }
                }
            }
        }
        if ($wiki->has()) {
            $link = '<a href="' . $wiki->uri() . '" title="' . $s_page . '"><strong>' . $day . '</strong></a>';
        } else {
            if (PKWK_READONLY) {
                $link = $day;
            } else {
                $link = '<a href="' . $wiki->uri('edit', array('refer' => $base)) . '" title="' . $s_page . '" rel="nofollow">' . $day . '</a>';
            }
        }
        $ret .= '<td class="style_td ' . $style . '">' . $link . '</td>' . "\n";
        ++$day;
        $wday = ++$wday % 7;
    }
    if ($wday > 0) {
        while ($wday++ < 7) {
            // Blank
            $ret .= '<td class="style_td_blank"></td>' . "\n";
        }
    }
    $ret .= '</tr>' . "\n" . '</tbody>' . "\n" . '</table>' . "\n";
    if ($today_view) {
        $ret .= '</div>' . "\n";
        // カレンダーのdivタグを閉じる
        $ret .= '<section class="style_calendar_post">' . "\n";
        if ($today_args == '') {
            $str = '<article id="' . $tpage . '" class="style_calendar_post">' . "\n";
            $tpage = $prefix . sprintf(PLUGIN_CALENDAR_PANENAME_FORMAT, $today['year'], $today['mon'], $today['mday']);
            $t_wiki = Factory::Wiki($tpage);
            if ($t_wiki->has()) {
                $_page = $vars['page'];
                $get['page'] = $post['page'] = $vars['page'] = $tpage;
                preg_replace('/^#navi/', '/\\/\\/#navi/', $source);
                $str .= $t_wiki->render();
                $str .= '<hr /><a href="' . $t_wiki->uri('edit', $tpage) . '">' . $_calendar_msg['_edit'] . '</a>';
                $get['page'] = $post['page'] = $vars['page'] = $_page;
            } else {
                $str .= sprintf($_calendar_msg['_empty'], make_pagelink($prefix . sprintf(PLUGIN_CALENDAR_PANENAME_FORMAT, $today['year'], $today['mon'], $today['mday'])));
            }
            $str .= '</article>' . "\n";
        } else {
            $aryargs = array(rawurldecode($base), $page_YM, $today_args);
            if (exist_plugin('calendar_viewer')) {
                T_bindtextdomain('calendar_viewer', LANG_DIR);
                T_textdomain('calendar_viewer');
                $str = call_user_func_array('plugin_calendar_viewer_convert', $aryargs);
                T_textdomain('calendar');
            }
        }
        $ret .= $str . "\n";
        $ret .= '</section>' . "\n";
        $ret .= '</div>' . "\n";
    }
    return $ret;
}
Example #15
0
function attach_showform()
{
    global $vars, $_attach_messages, $_string;
    if (Auth::check_role('safemode')) {
        die_message($_string['prohibit']);
    }
    $page = isset($vars['page']) ? $vars['page'] : null;
    if (empty($page)) {
        Utility::dieMessage('Page name is not defined');
    }
    $isEditable = Factory::Wiki($page)->isEditable();
    $vars['refer'] = $page;
    $html = array();
    if (!IS_AJAX) {
        $attach_list = attach_list($page);
        $html[] = '<p><small>[<a href="' . Router::get_cmd_uri('attach', null, null, array('pcmd' => 'list')) . '">' . $_attach_messages['msg_listall'] . '</a>]</small></p>';
        if ($isEditable) {
            $html[] = '<h2>' . str_replace('$1', $page, $_attach_messages['msg_upload']) . '</h2>' . "\n";
            $html[] = attach_form($page);
        }
        $html[] = '<h2>' . str_replace('$1', $page, $_attach_messages['msg_listpage']) . '</h2>' . "\n";
        $html[] = $attach_list['body'];
    } else {
        $html[] = '<div class="tabs" role="application">';
        $html[] = '<ul role="tablist">';
        if ($isEditable) {
            $html[] = '<li role="tab"><a href="' . Router::get_cmd_uri('attach', null, null, array('pcmd' => 'form', 'refer' => $page)) . '">' . str_replace('$1', $_attach_messages['msg_thispage'], $_attach_messages['msg_upload']) . '</a></li>';
        }
        $html[] = '<li role="tab"><a href="' . Router::get_cmd_uri('attach', null, null, array('pcmd' => 'list', 'refer' => $page)) . '">' . str_replace('$1', $_attach_messages['msg_thispage'], $_attach_messages['msg_listpage']) . '</a></li>';
        $html[] = '</ul>';
        $html[] = '</div>';
    }
    return array('msg' => $_attach_messages['msg_upload'], 'body' => join("\n", $html));
}
Example #16
0
function plugin_qrcode_inline()
{
    if (!extension_loaded('gd')) {
        return '<span class="ui-state-error">&amp;qrcode(): GD2 extention was not loaded!</span>';
    }
    /**
     * $s サイズ,
     * $e 訂正方法,
     * $v バージョン,
     * $n 分割数
     * $d バーコード化する文字列(Adv.版は非サポート)
     */
    switch (func_num_args()) {
        //		case 5:
        //			list($s,$e,$v,$n,$d) = func_get_args();
        //			break;
        case 4:
            list($s, $e, $v, $d) = func_get_args();
            break;
        case 3:
            list($s, $e, $d) = func_get_args();
            break;
        case 2:
            list($s, $d) = func_get_args();
            break;
        case 1:
            list($d) = func_get_args();
            break;
    }
    // thx, nanashi and customized
    $s = isset($s) && $s <= 0 ? intval($s) : 0;
    $v = isset($v) && !($v <= 0 && $v > PHPQRCode\Constants::QRSPEC_VERSION_MAX) ? intval($v) : PHPQRCode\Constants::QRSPEC_VERSION_MAX;
    //	$n = (isset($n) && !( $n <= 0 && $n > 16 )) ? intval($n) : 0;
    $e = Utility::htmlsc(isset($e) ? $e : 'M');
    if (empty($d)) {
        $d = $d = isset($vars['page']) ? Factory::Wiki($vars['page'])->getUri() : Router::get_cmd_uri();
    }
    // thx, nao-pon
    $d = str_replace('<br />', "\r\n", $d);
    $d = strip_tags($d);
    // docomo is s-jis encoding
    $d = mb_convert_encoding($d, 'SJIS', SOURCE_ENCODING);
    $result = array();
    $result[] = '<figure class="qrcode">';
    //if ($n < 2 || $n > 16) {
    $href = get_cmd_uri('qrcode', '', '', array('d' => $d, 's' => 9, 'v' => $v, 'e' => $e));
    $src = get_cmd_uri('qrcode', '', '', array('d' => $d, 's' => $s, 'v' => $v, 'e' => $e));
    $alt = defined('UA_MOBILE') && UA_MOBILE != 0 ? 'Mobile' : rawurlencode($d);
    $result[] = '<a href="' . $href . '"><img src="' . $src . '" alt="' . $alt . '" title="' . $alt . '" /></a>';
    /*
    }
     else {
    	// パリティを計算
    	$l=strlen($d);
    	if ($l>1){
    		$p=0;
    		$i=0;
    		while ($i<$l){
    			$p=($p ^ ord(substr($d,$i,1)));
    			$i++;
    		}
    	}
    	// 並べる(本来ならPNGを合成するのがきれいでしょうけどね)
    	$i=0;
    	for ($j=1;$j<=$n;$j++) {
    		$splitdata = substr($d,$i,ceil($l/$n));
    		$i += ceil($l/$n);
    		$src = get_cmd_uri('qrcode', '', '', array(
    			'd' => $splitdata,
    			's' => $s,
    			'v' => $v,
    			'e' => $e,
    			'm' => $j
    		));
    		$alt = (defined('UA_MOBILE') && UA_MOBILE != 0) ? 'Mobile' : rawurlencode($splitdata);
    
    		$result[] = '<img src="'.$src.'" alt="'.$alt.'" title="'.$alt.'" />';
    		unset($src);
    	}
    }
    */
    $result[] = '</figure>';
    return join("\n", $result);
}
Example #17
0
function plugin_ref_body($args)
{
    global $vars;
    $page = isset($vars['page']) ? $vars['page'] : '';
    $params = array('left' => FALSE, 'center' => FALSE, 'right' => FALSE, 'justify' => FALSE, 'around' => FALSE, 'noicon' => FALSE, 'noimg' => FALSE, 'nolink' => FALSE, 'zoom' => FALSE, 'rounded' => FALSE, 'circle' => FALSE, 'thumbnail' => FALSE, 'novideo' => FALSE, 'noaudio' => FALSE, 'autoplay' => FALSE, '_align' => PLUGIN_REF_DEFAULT_ALIGN, '_size' => True, '_w' => 0, '_h' => 0, '_%' => 0, '_title' => null, '_body' => null, '_error' => null, '_class' => '');
    // [Page_name/maybe-separated-with/slashes/]AttachedFileName.sfx or URI
    $name = array_shift($args);
    // ファイル名
    // 第一引数が InterWiki か
    if (Utility::isInterWiki($name)) {
        preg_match('/^' . RendererDefines::INTERWIKINAME_PATTERN . '$/', $name, $intermatch);
        $intername = $intermatch[2];
        $interparam = $intermatch[3];
        $interurl = InterWikiName::getInterWikiUrl($intername, $interparam);
        if ($interurl !== FALSE) {
            $name = $interurl;
        }
    }
    $is_url = Utility::isUri($name);
    // アドレスか?
    // 画像
    $seems_image = !$params['noimg'] && preg_match(RendererDefines::IMAGE_EXTENTION_PATTERN, $name);
    // ビデオ
    $seems_video = !$params['novideo'] && preg_match(RendererDefines::VIDEO_EXTENTION_PATTERN, $name);
    // 音声
    $seems_audio = !$params['noaudio'] && preg_match(RendererDefines::AUDIO_EXTENTION_PATTERN, $name);
    $file = '';
    // Path to the attached file
    $is_file = FALSE;
    if (!$is_url) {
        if (!is_dir(UPLOAD_DIR)) {
            $params['_error'] = 'UPLOAD_DIR is not found.';
            return $params;
        }
        // ページ名が空の時は処理しない
        if (empty($page)) {
            return '';
        }
        $matches = array();
        if (preg_match('#^(.+)/([^/]+)$#', $name, $matches)) {
            // Page_name/maybe-separated-with/slashes and AttachedFileName.sfx
            // #ref(ページ名/ファイル名) 新形式の表記
            if ($matches[1] === '.' || $matches[1] === '..') {
                // 相対パスでの指定
                $matches[1] .= '/';
                // Restore relative paths
            }
            // ファイル名を取得
            $name = $matches[2];
            // AttachedFileName.sfx
            $page = Utility::getPageName($matches[1], $page);
            // strip is a compat
        } else {
            if (isset($args[0]) && !empty($args[0]) && !isset($params[$args[0]])) {
                // Is the second argument a page-name or a path-name? (compat)
                // #ref(ファイル名,ページ名) 古い形式の表記
                $_page = array_shift($args);
                // 引用元のページ名
                // Looks like WikiName, or double-bracket-inserted pagename? (compat)
                $is_bracket_bracket = preg_match('/^(' . RendererDefines::WIKINAME_PATTERN . '|\\[\\[' . RendererDefines::BRACKETNAME_PATTERN . '\\]\\])$/', $_page);
                $page = Utility::getPageName(Utility::stripBracket($_page), $page);
                // strip is a compat
                $a = new Attach($_page, $name);
                if (!$is_bracket_bracket || !$a->has()) {
                    // Promote new design
                    if ($is_file && is_file(UPLOAD_DIR . encode($page) . '_' . encode($name))) {
                        // Because of race condition NOW
                        $params['_error'] = 'The same file name "' . $name . '" at both page: "' . $page . '" and "' . $_page . '". Try ref(pagename/filename) to specify one of them';
                    } else {
                        // Because of possibility of race condition, in the future
                        $params['_error'] = 'The style &amp;ref(filename,pagename) is ambiguous ' . 'and become obsolete. ' . 'Please try ref(pagename/filename)';
                    }
                    return $params;
                }
                $page = $_page;
                // Suppose it
            }
        }
        // Attachオブジェクトを生成
        $a = new Attach($page, $name);
        if (!$a->has()) {
            $params['_error'] = 'File not found: "' . Utility::htmlsc($name) . '" at page "' . Utility::htmlsc($page) . '"';
            return $params;
        }
    }
    // 残りの引数の処理
    if (!empty($args)) {
        $keys = array_keys($params);
        $params['_done'] = false;
        foreach ($args as $val) {
            list($_key, $_val) = array_pad(explode(':', $val, 2), 2, TRUE);
            $_key = trim(strtolower($_key));
            if (is_string($_val)) {
                $_val = trim($_val);
            }
            if (in_array($_key, $keys) && $params['_done'] !== TRUE) {
                $params[$_key] = $_val;
                // Exist keys
            } elseif ($val != '') {
                $params['_args'][] = $val;
                // Not exist keys, in '_args'
            }
        }
    }
    $width = $height = 0;
    $url = $url2 = '';
    if ($is_url) {
        // 外部リンクの場合
        $url = $name;
        $url2 = $name;
        if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI) {
            //$params['_error'] = 'PKWK_DISABLE_INLINE_IMAGE_FROM_URI prohibits this';
            //return $params;
            $params['_body'] = '<a href="' . $url . '" rel="external">' . $s_url . '</a>';
            return $params;
        }
        $matches = array();
        $params['_title'] = preg_match('#([^/]+)$#', $url, $matches) ? $matches[1] : $url;
    } else {
        // Wikiの添付ファイルの場合
        // Count downloads with attach plugin
        $url = Router::get_cmd_uri('attach', null, null, array('refer' => $page, 'openfile' => $name));
        $url2 = '';
        $params['_title'] = $name;
        if ($seems_image || $seems_video || $seems_audio) {
            // URI for in-line image output
            $url2 = $url;
            // With ref plugin (faster than attach)
            $url = Router::get_cmd_uri('ref', $page, null, array('src' => $name));
            if ($seems_image) {
                // 画像の場合は、getimagesizeでサイズを読み取る
                $size = getimagesize($a->basename);
                if (is_array($size)) {
                    $params['_w'] = $size[0];
                    $params['_h'] = $size[1];
                }
            }
        }
    }
    // 拡張パラメータをチェック
    if (!empty($params['_args'])) {
        $_title = array();
        foreach ($params['_args'] as $arg) {
            if (preg_match('/^([0-9]+)x([0-9]+)$/', $arg, $matches)) {
                $params['_size'] = TRUE;
                $params['_w'] = $matches[1];
                $params['_h'] = $matches[2];
            } else {
                if (preg_match('/^([0-9.]+)%$/', $arg, $matches) && $matches[1] > 0) {
                    $params['_%'] = $matches[1];
                } else {
                    $_title[] = $arg;
                }
            }
        }
    }
    foreach (array('right', 'left', 'center', 'justify') as $align) {
        if (isset($params[$align])) {
            $params['_align'] = $align;
            unset($params[$align]);
            break;
        }
    }
    $s_title = isset($params['_title']) ? Inline::setLineRules(Utility::htmlsc($params['_title'])) : '';
    $s_info = '';
    if ($seems_image || $seems_video) {
        // 指定されたサイズを使用する
        $info = '';
        if ($width === 0 && $height === 0) {
            $width = $params['_w'];
            $height = $params['_h'];
        }
        if ($params['_size']) {
            if ($params['zoom']) {
                $_w = $params['_w'] ? $width / $params['_w'] : 0;
                $_h = $params['_h'] ? $height / $params['_h'] : 0;
                $zoom = max($_w, $_h);
                if ($zoom) {
                    $width = (int) ($width / $zoom);
                    $height = (int) ($height / $zoom);
                }
            } else {
                $width = $params['_w'] ? $params['_w'] : $width;
                $height = $params['_h'] ? $params['_h'] : $height;
            }
        }
        if ($params['_%']) {
            $width = (int) ($width * $params['_%'] / 100);
            $height = (int) ($height * $params['_%'] / 100);
        }
        $info = $width && $height ? 'width="' . $width . '" height="' . $height . '" ' : '';
        if ($seems_image) {
            $body = '<img src="' . $url . '" ' . 'alt="' . $s_title . '" ' . 'title="' . $s_title . '" ' . 'class="' . $params['_class'] . '" ' . $info . '/>';
        } else {
            if ($seems_video) {
                $body = '<video src="' . $url . '" ' . 'alt="' . $s_title . '" ' . 'title="' . $s_title . '" ' . 'class="' . $params['_class'] . '" ' . $s_info . ' controls="controls" preload="auto">';
            }
        }
        if (!isset($params['nolink']) && $url2) {
            $params['_body'] = '<a href="' . $url2 . '" title="' . $s_title . '"' . (IS_MOBILE ? ' data-ajax="false"' : '') . '>' . "\n" . $body . "\n" . '</a>';
        } else {
            $params['_body'] = $body;
        }
    } else {
        if ($seems_audio) {
            // 音声
            $body = '<audio src="' . $url . '" ' . 'alt="' . $s_title . '" ' . 'title="' . $s_title . '" ' . 'class="' . $params['_class'] . '" controls="controls" preload="auto" />';
            if (!isset($params['nolink']) && $url2) {
                $params['_body'] = '<a href="' . $url2 . '" title="' . $s_title . '"' . (IS_MOBILE ? ' data-ajax="false"' : '') . '>' . "\n" . (isset($params['noicon']) ? '' : '<span class="fa fa-music"></span>') . $body . "\n" . '</a>';
            } else {
                $params['_body'] = $body;
            }
        } else {
            // リンクを貼り付ける
            if (!$is_url && $is_file) {
                $s_info = Utility::htmlsc(get_date('Y/m/d H:i:s', filemtime($file)) . ' ' . sprintf('%01.1f', round(filesize($file) / 1024, 1)) . 'KB');
            }
            $params['_body'] = '<a href="' . $url . '" title="' . $s_info . '"' . (IS_MOBILE ? ' data-ajax="false"' : '') . '>' . (isset($params['noicon']) ? '' : '<span class="fa fa-paperclip"></span>') . $s_title . '</a>';
        }
    }
    return $params;
}
Example #18
0
 /**
  * ページが見つからない
  * @return void
  */
 public static function notFound()
 {
     global $vars, $_button, $_title, $_string;
     $body[] = '<p>[ ';
     if (isset($vars['page']) && !empty($vars['page'])) {
         $body[] = '<a href="' . Factory::Wiki($vars['page'])->uri() . '">' . $_button['back'] . '</a> | ';
         $body[] = '<a href="' . Router::get_cmd_uri('edit', $vars['page']) . '">' . $_button['try_edit'] . '</a> | ';
     }
     $body[] = '<a href="' . Router::get_cmd_uri() . '">Return to FrontPage</a> ]</p>';
     $body[] = '<p class="alert alert-warning"><span class="fa fa-info-sign"></span> <strong>' . $_title['page_not_found'] . '</strong>';
     $body[] = $_string['not_found1'];
     if (isset($vars['page']) && !empty($vars['page'])) {
         $body[] = '<br />' . "\n" . sprintf($_string['not_found2'], Router::get_cmd_uri('backup', $vars['page']), Router::get_cmd_uri('edit', $vars['page']));
     }
     $body[] = '</p>';
     $body[] = '<script type="text/javascript">/' . '* <![CDATA *' . '/';
     $body[] = 'var GOOG_FIXURL_LANG = (navigator.language || null).slice(0,2), GOOG_FIXURL_SITE = location.host;';
     $body[] = '/' . '* ]]> *' . '/</script>';
     $body[] = '<script type="text/javascript" src="//linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>';
     new Render('Page not found', join("\n", $body), Response::STATUS_CODE_404);
 }
Example #19
0
 /**
  * サムネイルを出力
  * @return string
  */
 private function getThumbnail()
 {
     $ret = array();
     // サムネイル(JPEG、TIFFのみ)
     if (extension_loaded('exif') && extension_loaded('gd')) {
         $image_type = exif_imagetype($this->fileinfo);
         if ($image_type === IMAGETYPE_JPEG || $image_type === IMAGETYPE_TIFF_II || $image_type === IMAGETYPE_TIFF_MM) {
             $exif = exif_read_data($this->fileinfo);
             $size = getimagesize($this->fileinfo);
             // 画像でない場合はfalseを返す
             if ($size !== false) {
                 if ($size[2] > 0 && $size[2] < 3) {
                     if ($size[0] < 200) {
                         $w = $size[0];
                         $h = $size[1];
                     } else {
                         $w = 200;
                         $h = $size[1] * (200 / ($size[0] != 0 ? $size[0] : 1));
                     }
                     $ret[] = '<figure class="img-thumbnail">';
                     $ret[] = '<img src="' . Router::get_cmd_uri('ref', null, null, array('page' => $this->page, 'src' => $this->filename));
                     $ret[] = '" width="' . $w . '" height="' . $h . '" />';
                     $ret[] = '</figure>';
                 }
             }
         }
     }
     return join("\n", $ret);
 }
Example #20
0
function get_page_uri($page, $path_reference = 'rel', $query = '', $fragment = '')
{
    if (empty($page)) {
        return null;
    }
    return Router::get_cmd_uri('read', $page, $path_reference, $query, $fragment);
}
Example #21
0
 /**
  * CAPTCHAチェック
  * @param boolean $save セッションに保存するか
  * @param string $message エラーメッセージの内容
  */
 public static function check($save = true, $message = '', $multipart = false)
 {
     global $recaptcha_public_key, $recaptcha_private_key, $vars, $session, $_string, $_button;
     // Captchaのセッション名(ticketとリモートホストの加算値。ticketはプログラマーから見てもわからない)
     $session_name = self::CAPTCHA_SESSION_PREFIX . md5(Utility::getTicket() . REMOTE_ADDR);
     if ($save && $session->offsetExists($session_name) && $session->offsetGet($session_name) === true) {
         // CAPTCHA認証済みの場合
         // return array('msg'=>'CAPTCHA','body'=>'Your host was already to challenged.');
         return;
     }
     if (isset($recaptcha_public_key) && isset($recaptcha_private_key)) {
         // reCaptchaを使う場合
         $captcha = new ReCaptcha($recaptcha_public_key, $recaptcha_private_key);
         // 入力があった場合
         if (isset($vars['recaptcha_challenge_field']) && isset($vars['recaptcha_response_field'])) {
             if ($captcha->verify($vars['recaptcha_challenge_field'], $vars['recaptcha_response_field'])) {
                 if ($save) {
                     // captcha認証済セッションを保存
                     $session->offsetSet($session_name, true);
                     // captcha認証済セッションの有効期間を設定
                     $session->setExpirationSeconds($session_name, self::CAPTCHA_SESSION_EXPIRE);
                 }
                 // return array('msg'=>'CAPTCHA','body'=>'OK!');
                 return;
                 // ここで書き込み処理に戻る
             } else {
                 // CAPTCHA認証失敗ログをつける
                 Utility::dump('captcha');
                 $message = $_string['captcha_failure'];
             }
             // チャレンジ&レスポンスデーターを削除
             unset($vars['recaptcha_challenge_field'], $vars['recaptcha_response_field']);
         }
         // 念のためcaptcha認証済みセッションを削除
         $session->offsetUnset($session_name);
         // reCaptchaの設定をオーバーライド
         // 言語設定
         $captcha->setOption('lang', substr(LANG, 0, 2));
         // テーマ
         $captcha->setOption('theme', self::RECAPTCHA_THEME);
         $form = $captcha->getHTML();
     } else {
         // reCaptchaを使わない場合
         $captcha_dir = CACHE_DIR . self::CAPTCHA_IMAGE_DIR_NAME . DIRECTORY_SEPARATOR;
         self::mkdir_r($captcha_dir);
         if (isset($vars['challenge_field']) && isset($vars['response_field'])) {
             // Captchaチェック処理
             if ($session->offsetGet(self::CAPTCHA_SESSION_PREFIX . $vars['response_field']) === strtolower($vars['challenge_field'])) {
                 if ($save) {
                     // captcha認証済セッションを保存
                     $session->offsetSet($session_name, true);
                     // captcha認証済セッションの有効期間を設定
                     $session->setExpirationSeconds($session_name, self::CAPTCHA_SESSION_EXPIRE);
                 }
                 // 認証用セッションの削除
                 $session->offsetUnset(self::CAPTCHA_SESSION_PREFIX . $vars['response_field']);
                 if (file_exists($captcha_dir . $vars['response_field'] . '.png')) {
                     // キャッシュ画像を削除
                     unlink($captcha_dir . $vars['response_field'] . '.png');
                 }
                 // return array('msg'=>'CAPTCHA','body'=>'OK!');
                 return;
                 // ここで書き込み処理に戻る
             } else {
                 // CAPTCHA認証失敗ログをつける
                 Utility::dump('captcha');
                 $message = $_string['captcha_failure'];
             }
             // チャレンジ&レスポンスデーターを削除
             unset($vars['response_field'], $vars['challenge_field']);
         }
         // 念のためcaptcha認証済みセッションを削除
         $session->offsetUnset($session_name);
         // GDが使える場合、画像認証にする
         if (extension_loaded('gd')) {
             // フォルダが存在しない場合作成を試みる
             if (!file_exists($captcha_dir)) {
                 mkdir($captcha_dir);
                 chmod(0777, $captcha_dir);
             }
             // 古い画像を削除する
             $di = new DirectoryIterator($captcha_dir);
             foreach ($di as $f) {
                 if (!$f->isFile()) {
                     // ファイルでない
                     continue;
                 }
                 if (time() - $f->getMTime() > self::CAPTCHA_TIMEOUT) {
                     // タイムアウト時間よりも古いファイルは削除する
                     unlink($f->getRealPath());
                 }
             }
             /*
             				$handle = opendir($captcha_dir,null);
             				if ($handle) {
             					while( $entry = readdir($handle) ){
             						if( $entry !== '.' && $entry !== '..'){
             							$f = realpath($captcha_dir . $entry);
             							if (time() - filectime($f) > self::CAPTCHA_TIMEOUT) unlink($f);
             						}
             					}
             					closedir($handle);
             				}
             */
             // 画像CAPTCHAを生成
             $captcha = new Image(array('wordLen' => self::CAPTCHA_WORD_LENGTH, 'timeout' => self::CAPTCHA_TIMEOUT, 'font' => LIB_DIR . self::CAPTCHA_IMAGE_FONT, 'ImgDir' => $di->getPath()));
             $captcha->generate();
             // cache_refプラグインを用いて画像を表示
             $form = '<img src="' . Router::get_cmd_uri('cache_ref', null, null, array('src' => self::CAPTCHA_IMAGE_DIR_NAME . '/' . $captcha->getId() . '.png')) . '" height="' . $captcha->getHeight() . '" width="' . $captcha->getWidth() . '" alt="' . Utility::htmlsc($captcha->getImgAlt()) . '" /><br />' . "\n";
             // 画像を取得
         } else {
             // GDがない場合アスキーアート
             $captcha = new Figlet(array('wordLen' => self::CAPTCHA_WORD_LENGTH, 'timeout' => self::CAPTCHA_TIMEOUT));
             $captcha->generate();
             // \が¥に見えるのでフォントを明示的に指定。
             $form = '<pre style="font-family: Monaco, Menlo, Consolas, \'Courier New\' !important;">' . Utility::htmlsc($captcha->getFiglet()->render($captcha->getWord())) . '</pre>' . "\n" . '<br />' . "\n";
             // AAを取得
         }
         // 識別子のセッション名
         $response_session = self::CAPTCHA_SESSION_PREFIX . $captcha->getId();
         // 識別子のセッションを発行
         $session->offsetSet($response_session, $captcha->getWord());
         // captchaの有効期間
         $session->setExpirationSeconds($response_session, self::CAPTCHA_TIMEOUT);
         $form .= '<input type="hidden" name="response_field" value="' . $captcha->getId() . '" />' . "\n";
         $form .= '<div class="input-group">';
         $form .= '<span class="input-group-addon"><span class="fa fa-key"></span></span>';
         $form .= '<input type="text" class="form-control" name="challenge_field" maxlength="' . $captcha->getWordLen() . '" size="' . $captcha->getWordLen() . '" />';
         $form .= '<span class="input-group-btn">';
         $form .= '<button type="submit" class="btn btn-primary" value="submit">' . $_button['submit'] . '</button>';
         $form .= '</span>';
         $form .= '</div>';
         // $form .= $captcha->getWord();
     }
     //	$ret[] = $session->offsetExists($session_name) ? 'true' : 'false';
     //	$ret[] = Zend\Debug\Debug::Dump($vars);
     //	$ret[] = Zend\Debug\Debug::Dump($captcha->getSession());
     if (!empty($message)) {
         $ret[] = '<p class="alert alert-warning"><span class="fa fa-warning"></span>' . $message . '</p>';
     }
     // PostIdが有効な場合
     if (isset($use_spam_check['multiple_post']) && $use_spam_check['multiple_post'] === 1) {
         $vars['postid'] = PostId::generate($vars['cmd']);
     }
     $ret[] = '<fieldset>';
     $ret[] = '<legend>CAPTCHA</legend>';
     $ret[] = '<p>' . $_string['captcha_msg'] . '</p>';
     // フォームを出力
     $ret[] = '<form method="post" action="' . Router::get_script_uri() . '" method="post" class="form-inline">';
     //unset($vars['ajax']);
     // ストアされている値を出力
     foreach ($vars as $key => $value) {
         if ($key === 'ajax') {
             continue;
         }
         if (strpos($key, 'attach_file', 0) === 0) {
             // ファイルフォームだった場合。(あまりいい実装ではない)
             $ret[] = '<input type="file" name="' . $key . '" value="' . (!empty($value) ? Utility::htmlsc($value) : '') . '" class="hidden" />';
             continue;
         }
         $ret[] = '<input type="hidden" name="' . $key . '" value="' . (!empty($value) ? Utility::htmlsc($value) : '') . '" />';
     }
     // CAPTCHAフォームを出力
     $ret[] = $form;
     $ret[] = '</form>';
     $ret[] = '</fieldset>';
     // return array('msg'=>'CAPTCHA','body'=>join("\n",$ret));
     new Render('CAPTCHA', join("\n", $ret));
     exit;
 }