Example #1
0
 public function parse($lines)
 {
     $this->last =& $this;
     $matches = array();
     while (!empty($lines)) {
         $line = array_shift($lines);
         // Escape comments
         if (substr($line, 0, 2) === '//') {
             if ($this->is_guiedit) {
                 $this->comments[] = substr($line, 2);
                 $line = '___COMMENT___';
             } else {
                 continue;
             }
         }
         // Extend TITLE by miko
         if (preg_match('/^(TITLE):(.*)$/', $line, $matches)) {
             global $newtitle;
             static $newbase;
             if (!isset($newbase)) {
                 $newbase = trim(Utility::stripHtmlTags(RendererFactory::factory($matches[2])));
                 // For BugTrack/132.
                 $newtitle = Utility::htmlsc($newbase);
             }
             continue;
         }
         if (preg_match('/^(LEFT|CENTER|RIGHT|JUSTIFY):(.*)$/', $line, $matches)) {
             // <div style="text-align:...">
             $align = new Align(strtolower($matches[1]));
             $this->last = $this->last->add($align);
             if (empty($matches[2])) {
                 continue;
             }
             $line = $matches[2];
         }
         $line = rtrim($line, "\t\r\n\v");
         // スペース以外の空白文字をトリム
         // Empty
         if (empty($line)) {
             $this->last =& $this;
             continue;
         }
         // Horizontal Rule
         if (substr($line, 0, 4) == '----') {
             $hrule = new HRule($this, $line);
             $this->insert($hrule);
             continue;
         }
         // Multiline-enabled block plugin #plugin{{ ... }}
         if (preg_match('/^#[^{]+(\\{\\{+)\\s*$/', $line, $matches)) {
             $len = strlen($matches[1]);
             $line .= self::MULTILINE_DELIMITER;
             while (!empty($lines)) {
                 $next_line = preg_replace('/[' . self::MULTILINE_DELIMITER . '\\n]*$/', '', array_shift($lines));
                 if (preg_match('/\\}{' . $len . '}/', $next_line)) {
                     $line .= $next_line;
                     break;
                 } else {
                     $line .= $next_line .= self::MULTILINE_DELIMITER;
                 }
             }
         }
         // The first character
         $head = $line[0];
         // Heading
         if ($head === '*') {
             $heading = new Heading($this, $line);
             $this->insert($heading);
             continue;
         }
         // Pre
         if ($head === ' ' || $head === "\t") {
             $pre = new Pre($this, $line);
             $this->last = $this->last->add($pre);
             continue;
         }
         // CPre (Plus!)
         if (substr($line, 0, 2) === '# ' or substr($line, 0, 2) == "#\t") {
             $sharppre = new SharpPre($this, $line);
             $this->last = $this->last->add($sharppr);
             continue;
         }
         // Line Break
         if (substr($line, -1) === '~') {
             $line = substr($line, 0, -1) . "\r";
         }
         // Other Character
         if (gettype($this->last) === 'object') {
             switch ($head) {
                 case '-':
                     $content = new UList($this, $line);
                     break;
                 case '+':
                     $content = new OList($this, $line);
                     break;
                 case '>':
                 case '<':
                     $content = new Blockquote($this, $line);
                     break;
                     // ここからはファクトリークラスを通す
                 // ここからはファクトリークラスを通す
                 case ':':
                     $content = ElementFactory::factory('DList', $this, $line);
                     break;
                 case '|':
                     $content = ElementFactory::factory('Table', $this, $line);
                     break;
                 case ',':
                     $content = ElementFactory::factory('YTable', $this, $line);
                     break;
                 case '#':
                     if ($this->is_guiedit) {
                         $content = ElementFactory::factory('PluginDummy', $this, $line);
                     } else {
                         $content = ElementFactory::factory('Plugin', $this, $line);
                     }
                     break;
                 default:
                     $content = ElementFactory::factory('InlineElement', null, $line);
                     break;
             }
             // MathJax Expression
             if (PluginRenderer::hasPlugin('mathjax')) {
                 $end_mark = '';
                 // 開始行によって終了行を判定する
                 if (substr($line, 0, 2) === '\\[') {
                     $end_mark = '\\]';
                 } else {
                     if (substr($line, 0, 6) === '\\begin') {
                         $end_mark = '\\end';
                     }
                 }
                 if ($end_mark) {
                     while (!empty($lines)) {
                         if (strpos($line, $end_mark) !== false) {
                             break;
                         }
                         $next_line = preg_replace("/[\r\n]*\$/", '', array_shift($lines));
                         $line .= "\n" . ' ' . $next_line;
                     }
                     $mathjax = new BlockPlugin(array(null, 'mathjax', $line));
                     $this->last = $this->last->add($mathjax);
                     continue;
                 }
             }
             // Default
             $this->last = $this->last->add($content);
             unset($content);
             continue;
         }
     }
 }
Example #2
0
 /**
  * 認証されたAPIの情報を取得
  * @global type $auth_api
  * @global type $auth_wkgrp_user
  * @global type $defaultpage
  * @return array
  */
 static function get_auth_api_info()
 {
     global $auth_api, $auth_wkgrp_user, $defaultpage;
     $retval = array('role' => self::ROLE_GUEST, 'nick' => null, 'key' => null, 'api' => 'plus', 'group' => null, 'displayname' => null, 'home' => null, 'mypage' => null);
     foreach ($auth_api as $api => $val) {
         // どうしても必要な場合のみ開始
         if (!$val['use']) {
             continue;
         }
         break;
     }
     $obj = new AuthApi();
     $msg = $obj->getSession();
     if (isset($msg['api']) && $auth_api[$msg['api']]['use']) {
         if (PluginRenderer::hasPlugin($msg['api'])) {
             $call_func = 'plugin_' . $msg['api'] . '_get_user_name';
             $auth_key = $call_func();
             $auth_key['api'] = $msg['api'];
             if (empty($auth_key['nick'])) {
                 return $auth_key;
             }
             // 上書き・追加する項目
             if (!empty($auth_wkgrp_user[$auth_key['api']][$auth_key['key']])) {
                 $val =& $auth_wkgrp_user[$auth_key['api']][$auth_key['key']];
                 $auth_key['role'] = empty($val['role']) ? self::ROLE_ENROLLEE : $val['role'];
                 $auth_key['group'] = empty($val['group']) ? null : $val['group'];
                 $auth_key['displayname'] = empty($val['displayname']) ? null : $val['displayname'];
                 $auth_key['home'] = empty($val['home']) ? $defaultpage : $val['home'];
                 $auth_key['mypage'] = empty($val['mypage']) ? null : $val['mypage'];
             }
         }
     }
     return $auth_key;
 }
Example #3
0
 /**
  * インラインプラグイン処理メソッド
  */
 static function convert_plugin($matches)
 {
     $aryargs = !empty($matches[2]) ? explode(',', $matches[2]) : array();
     $name = strtolower($matches[1]);
     $body = empty($matches[3]) ? '' : $matches[3];
     //	プラグインが存在しない場合はそのまま返す。
     // if (!file_exists(PLUGIN_DIR . $name . '.inc.php')) {
     if (!PluginRenderer::hasPlugin($name)) {
         return $matches[0];
     }
     switch ($name) {
         case 'aname':
             return '<a name="' . $aryargs[0] . '">' . $body . '</a>';
         case 'br':
             return '<br />';
         case 'color':
             $color = $aryargs[0];
             $bgcolor = $aryargs[1];
             if ($body == '') {
                 return '';
             }
             if ($color != '' && !preg_match('/^(#[0-9a-f]+|[\\w-]+)$/i', $color)) {
                 return $body;
             }
             if ($bgcolor != '' && !preg_match('/^(#[0-9a-f]+|[\\w-]+)$/i', $bgcolor)) {
                 return $body;
             }
             if ($color != '') {
                 $color = 'color:' . $color;
             }
             if ($bgcolor != '') {
                 $bgcolor = ($color ? '; ' : '') . 'background-color:' . $bgcolor;
             }
             return '<span style="' . $color . $bgcolor . '">' . $this->convert($body, TRUE, FALSE) . '</span>';
         case 'sup':
         case 'sub':
             return '<' . $name . '>' . $body . '</' . $name . '>';
         case 'size':
             $size = $aryargs[0];
             if ($size == '' || $body == '') {
                 return '';
             }
             if (!preg_match('/^\\d+$/', $size)) {
                 return $body;
             }
             return '<span style="font-size:' . $size . 'px;line-height:130%">' . $this->convert($body, TRUE, FALSE) . "</span>";
         case 'ref':
             return guiedit_convert_ref($aryargs, FALSE);
     }
     if ($body) {
         $pattern = array("%%", "''", "[[", "]]", "{", "|", "}");
         $replace = array("&#037;&#037;", "&#039;&#039;", "&#091;&#091;", "&#093;&#093;", "&#123;", "&#124;", "&#125;");
         $body = str_replace($pattern, $replace, $body);
     }
     $inner = '&' . $matches[1] . ($matches[2] ? '(' . $matches[2] . ')' : '') . ($body ? '{' . $body . '}' : '') . ';';
     $style = UA_NAME == MSIE ? '' : ' style="cursor:default"';
     return '<span class="plugin text-primary" contenteditable="false"' . $style . '>' . $inner . '</span>';
 }
Example #4
0
function plugin_login_action()
{
    global $vars, $_login_msg, $defaultpage;
    $api = isset($vars['api']) ? $vars['api'] : 'plus';
    $page = isset($vars['page']) ? $vars['page'] : $defaultpage;
    if ($api !== 'plus') {
        if (!PluginRenderer::hasPlugin($vars['api'])) {
            return;
        }
        $call_api = 'plugin_' . $vars['api'] . '_jump_url';
        Utility::redirect($call_api());
        exit;
    }
    $auth = Auth::authenticate();
    if ($auth === true) {
        // ログイン成功
        LogFactory::factory('login')->set();
        Utility::redirect(Factory::Wiki($page)->uri());
        exit;
    }
    return array('msg' => $_login_msg['err_auth'], 'body' => $_login_msg['err_auth_guide'], 'http_code' => 401);
}