Example #1
0
 public function setPattern($arr, $page)
 {
     global $foot_explain, $vars;
     list(, $body) = $this->splice($arr);
     // Recover of notes(miko)
     if (count($foot_explain) === 0) {
         self::$note_id = 0;
     }
     $script = !self::ALLOW_RELATIVE_FOOTNOTE_ANCHOR ? Factory::Wiki($page)->uri() : '';
     $id = ++self::$note_id;
     $note = InlineFactory::factory($body);
     $page = isset($vars['page']) ? rawurlencode($vars['page']) : null;
     // Footnote
     $foot_explain[$id] = '<li id="notefoot_' . $id . '">' . '<a href="' . $script . '#notetext_' . $id . '" class="note_super">' . RendererDefines::FOOTNOTE_ANCHOR_ICON . $id . '</a>' . $note . '</li>';
     if (!IS_MOBILE) {
         // A hyperlink, content-body to footnote
         if (!is_numeric(self::FOOTNOTE_TITLE_MAX) || self::FOOTNOTE_TITLE_MAX <= 0) {
             $title = '';
         } else {
             $title = strip_tags($note);
             $count = mb_strlen($title, SOURCE_ENCODING);
             $title = mb_substr($title, 0, self::FOOTNOTE_TITLE_MAX, SOURCE_ENCODING);
             $abbr = mb_strlen($title) < $count ? '...' : '';
             $title = ' title="' . $title . $abbr . '"';
         }
         $name = '<a id="notetext_' . $id . '" href="' . $script . '#notefoot_' . $id . '" class="note_super"' . $title . '>' . RendererDefines::FOOTNOTE_ANCHOR_ICON . $id . '</a>';
     } else {
         // モバイルは、ツールチップで代用
         $name = '<span class="note_super" aria-describedby="tooltip" data-msgtext="' . strip_tags($note) . '">' . RendererDefines::FOOTNOTE_ANCHOR_ICON . $id . '</span>';
     }
     return parent::setParam($page, $name, $body);
 }
Example #2
0
 public function setPattern($arr, $page)
 {
     list($name) = $this->splice($arr);
     // Ignore words listed
     if (in_array($name, $this->forceignorepages)) {
         return FALSE;
     }
     return parent::setParam($page, $name, null, 'pagename', $name);
 }
Example #3
0
 public function __toString()
 {
     global $nofollow;
     $icon = parent::isInsideUri($this->url) ? RendererDefines::INTERNAL_LINK_ICON : RendererDefines::EXTERNAL_LINK_ICON;
     $target = empty($this->redirect) ? $this->url : $this->redirect . rawurlencode($this->url);
     if (!$this->url) {
         return sprintf(RendererDefines::NOEXISTS_STRING, $this->interwikiname . ':' . $this->param);
     }
     return '<a href="' . $target . $this->anchor . '" title="' . $this->name . '" rel="' . ($nofollow === FALSE ? 'external' : 'external nofollow') . '">' . RendererDefines::INTERWIKINAME_ICON . $this->alias . $icon . '</a>';
 }
Example #4
0
 public function __toString()
 {
     global $nofollow;
     $rel = 'external' . ($nofollow === TRUE) ? ' nofollow' : '';
     $target = empty($this->redirect) ? $this->name : $this->redirect . rawurlencode($this->name);
     $purl = parse_url($target);
     if (isset($purl['host']) && extension_loaded('intl')) {
         // Fix punycode URL
         $url = preg_replace('/' . $purl['host'] . '/', idn_to_ascii($purl['host']), $target);
     } else {
         $url = $target;
     }
     return parent::setLink($this->alias, $url, $this->name, $rel);
 }
Example #5
0
 public function __toString()
 {
     $body = empty($this->body) ? null : InlineFactory::factory($this->body);
     $str = FALSE;
     // Try to call the plugin
     $str = PluginRenderer::executePluginInline($this->name, $this->param, $body);
     if ($str !== FALSE) {
         return $str;
         // Succeed
     } else {
         // No such plugin, or Failed
         $body = (empty($body) ? '' : '{' . $body . '}') . ';';
         return parent::setLineRules(Utility::htmlsc('&' . $this->plain) . $body);
     }
 }
Example #6
0
 public function setPattern($arr, $page)
 {
     list(, $alias, $toname, $host) = $this->splice($arr);
     $name = $orginalname = $toname . $host;
     if (extension_loaded('intl')) {
         // 国際化ドメイン対応
         if (preg_match('/[^A-Za-z0-9.-]/', $host)) {
             $name = $toname . idn_to_ascii($host);
         } else {
             if (!$alias && strtolower(substr($host, 0, 4)) === 'xn--') {
                 $orginalname = $toname . idn_to_utf8($host);
             }
         }
     }
     return parent::setParam($page, $name, '', 'mailto', $alias === '' ? $orginalname : $alias);
 }
Example #7
0
function plugin_redirect_convert()
{
    $argv = func_get_args();
    $argc = func_num_args();
    $field = array('caption', 'url', 'img');
    for ($i = 0; $i < $argc; $i++) {
        ${$field}[$i] = Utility::htmlsc($argv[$i], ENT_QUOTES);
    }
    if (empty($url)) {
        return 'usage: #redirect(caption, url, img)';
    }
    if (empty($caption)) {
        $caption = 'no title';
    }
    if (!empty($img)) {
        $caption = '<img src="' . $img . '" alt="' . $caption . '" title="' . $caption . '" />';
    }
    return Inline::setLink($caption, $url, null, 'noreferer', true);
}
Example #8
0
 public function __toString()
 {
     return parent::setAutoLink($this->name, $this->alias, null, $this->page, TRUE);
 }
Example #9
0
 public function __toString()
 {
     return parent::setAutoLink($this->name, $this->alias, $this->anchor, $this->page);
 }
Example #10
0
 public function setPattern($arr, $page)
 {
     list(, $alias, $tel) = $this->splice($arr);
     $name = $orginalname = $tel;
     return parent::setParam($page, $name, '', 'tel', $alias === '' ? $orginalname : $alias);
 }
Example #11
0
 /**
  * 変換
  * @param string $string
  * @param string $page
  * @return type
  */
 public function convert($string, $page)
 {
     $this->page = $page;
     $this->result = array();
     $string = preg_replace_callback('/' . $this->pattern . '/x', function ($arr) {
         $obj = $this->getConverter($arr);
         $this->result[] = $obj !== NULL && $obj->setPattern($arr, $this->page) !== FALSE ? $obj->__toString() : Inline::setLineRules(Utility::htmlsc($arr[0]));
         return "";
         // Add a mark into latest processed part
     }, $string);
     $arr = explode("", Inline::setLineRules(Utility::htmlsc($string)));
     $retval = null;
     while (!empty($arr)) {
         // $retval .= array_shift($arr) . array_shift($this->result);
         $retval .= str_replace('\\$$', '$$', array_shift($arr)) . array_shift($this->result);
     }
     return trim($retval);
 }
Example #12
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 #13
0
 /**
  * プロフィールのリンクを生成
  * @return string
  */
 function get_profile_link()
 {
     $message = $this->getSession();
     if (empty($message['name'])) {
         return '';
     }
     return Inline::setLink($message['name'], self::hatena_profile_url($message['name']), '', 'nofollow', false);
 }
Example #14
0
 public function __toString()
 {
     global $nofollow;
     $target = empty($this->redirect) ? $this->name : $this->redirect . rawurlencode($this->name);
     return parent::setLink($this->alias, $target, $this->name, $nofollow === FALSE ? null : 'nofollow');
 }
Example #15
0
 public function setPattern($arr, $page)
 {
     list(, $this->param, $body) = $this->splice($arr);
     $this->param = trim($this->param);
     return parent::setParam($page, 'ref', $body, 'plugin');
 }
Example #16
0
function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolink = FALSE)
{
    return Inline::setAutoLink($page, $alias, $anchor, $refer, $isautolink);
}
Example #17
0
 function get_profile_link()
 {
     $message = $this->getSession();
     if (!empty($message['api']) && $this->auth_name !== $message['api']) {
         return false;
     }
     if (empty($message['nick'])) {
         return '';
     }
     return Inline::setLink($message['name'], self::typekey_profile_url($message['name']), '', 'nofollow', false);
 }