Example #1
0
 /**
  * 最終更新のキャッシュを取得
  * @param boolean $force キャッシュを再生成する
  * @return array
  */
 public static function get($force = false)
 {
     global $cache, $whatsnew;
     static $recent_pages;
     if ($force) {
         // キャッシュ再生成
         unset($recent_pages);
         $cache['wiki']->removeItem(self::RECENT_CACHE_NAME);
     } else {
         if (!empty($recent_pages)) {
             // メモリにキャッシュがある場合
             return $recent_pages;
         } else {
             if ($cache['wiki']->hasItem(self::RECENT_CACHE_NAME)) {
                 // キャッシュから最終更新を読み込む
                 $recent_pages = $cache['wiki']->getItem(self::RECENT_CACHE_NAME);
                 return $recent_pages;
             }
         }
     }
     // Wikiのページ一覧を取得
     $pages = Listing::pages('wiki');
     // ページ一覧からファイルの更新日時を取得
     $recent_pages = array();
     foreach ($pages as $page) {
         if ($page === $whatsnew) {
             continue;
         }
         $wiki = Factory::Wiki($page);
         if ($wiki->isHidden()) {
             continue;
         }
         $recent_pages[$page] = $wiki->time();
     }
     // 更新日時順にソート
     arsort($recent_pages, SORT_NUMERIC);
     $_recent = array();
     foreach ($recent_pages as $key => $value) {
         unset($recent_pages[$key]);
         $_recent[$key] = $value;
     }
     // Save to recent cache data
     $cache['wiki']->setItem(self::RECENT_CACHE_NAME, $_recent);
     return $_recent;
 }
Example #2
0
 /**
  * インデックスファイルを生成
  */
 public static function updateIndex()
 {
     if (empty(self::$igo)) {
         self::$igo = new Tagger(array('dict_dir' => LIB_DIR . 'ipadic', 'reduce_mode' => true));
     }
     Analyzer::setDefault(new Utf8());
     // 索引の作成
     $index = Lucene::create(CACHE_DIR . self::INDEX_NAME);
     foreach (Listing::pages() as $page) {
         if (empty($page)) {
             continue;
         }
         $wiki = Factory::Wiki($page);
         // 読む権限がない場合スキップ
         if (!$wiki->isReadable() || $wiki->isHidden()) {
             continue;
         }
         /*
         			// HTML出力
         			$html[] = '<html><head>';
         			$html[] = '<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>';
         			$html[] = '<title>' . $wiki->title() . '</title>';
         			$html[] = '</head>';
         			$html[] = '<body>' . $wiki->render() . '</body>';
         			$html[] = '</html>';
         */
         $doc = new LuceneDoc();
         $doc->addField(Field::Text('title', $wiki->title()));
         // Store document URL to identify it in the search results
         $doc->addField(Field::Text('url', $wiki->uri()));
         // Index document contents
         //$contents = join(" ", self::$igo->wakati(strip_tags($wiki->render())));
         $contents = strip_tags($wiki->render());
         $doc->addField(Field::UnStored('contents', $contents));
         // 索引へ文書の登録
         $index->addDocument($doc);
     }
     $index->optimize();
 }
Example #3
0
function page_list($pages = array('pagename.txt' => 'pagename'), $cmd = 'read', $withfilename = FALSE)
{
    return Listing::get();
}
Example #4
0
 /**
  * 自動リンクの正規表現パターンを生成
  * @return string
  */
 private function getAutoLinkPattern($force = false)
 {
     global $cache;
     static $pattern;
     // キャッシュ処理
     if ($force) {
         unset($pattern);
         $cache['wiki']->removeItem(self::AUTO_LINK_PATTERN_CACHE);
     } else {
         if (!empty($pattern)) {
             return $pattern;
         } else {
             if ($cache['wiki']->hasItem(self::AUTO_LINK_PATTERN_CACHE)) {
                 $pattern = $cache['wiki']->getItem(self::AUTO_LINK_PATTERN_CACHE);
                 $cache['wiki']->touchItem(self::AUTO_LINK_PATTERN_CACHE);
                 return $pattern;
             }
         }
     }
     // 用語マッチパターンキャッシュを生成
     global $autolink, $nowikiname;
     $config = new Config('AutoLink');
     // FIXME
     $config->read();
     $ignorepages = $config->get('IgnoreList');
     $forceignorepages = $config->get('ForceIgnoreList');
     unset($config);
     $auto_pages = array_merge($ignorepages, $forceignorepages);
     foreach (Listing::pages('wiki') as $page) {
         if (preg_match('/^' . RendererDefines::WIKINAME_PATTERN . '$/', $page) ? $nowikiname : strlen($page) >= $autolink) {
             $auto_pages[] = $page;
         }
     }
     if (empty($auto_pages)) {
         $result = $result_a = $nowikiname ? '(?!)' : RendererDefines::WIKINAME_PATTERN;
     } else {
         $auto_pages = array_unique($auto_pages);
         sort($auto_pages, SORT_STRING);
         $auto_pages_a = array_values(preg_grep('/^[A-Z]+$/i', $auto_pages));
         $auto_pages = array_values(array_diff($auto_pages, $auto_pages_a));
         // 正規表現を最適化
         $result = Trie::regex($auto_pages);
         $result_a = Trie::regex($auto_pages_a);
     }
     $pattern = array($result, $result_a, $forceignorepages);
     $cache['wiki']->setItem(self::AUTO_LINK_PATTERN_CACHE, $pattern);
     return $pattern;
 }
Example #5
0
function plugin_ls2_show_lists($prefix, &$params)
{
    //	global $_ls2_err_nopages;
    $pages = array();
    foreach (Listing::pages('wiki') as $page) {
        if (!Factory::Wiki($page)->isReadable()) {
            continue;
        }
        if (!empty($prefix) && strpos($page, $prefix) === false) {
            continue;
        }
        $pages[] = $page;
    }
    natcasesort($pages);
    if ($params['reverse']) {
        $pages = array_reverse($pages);
    }
    foreach ($pages as $page) {
        $params['page_ ' . $page] = 0;
    }
    if (empty($pages)) {
        return str_replace('$1', Utility::htmlsc($prefix), '<p>' . T_("There is no child page in ' \$1'") . '</p>');
    } else {
        $params['result'] = $params['saved'] = array();
        foreach ($pages as $page) {
            plugin_ls2_get_headings($page, $params, 1);
        }
        return join("\n", $params['result']) . join("\n", $params['saved']);
    }
}
Example #6
0
 /**
  * 編集画面を表示
  * @param string $page 編集しようとしているページ名
  * @param string $data 入力データー
  * @param boolean $show_template テンプレートを表示するか
  */
 public static function editForm($page, $data, $show_template = TRUE)
 {
     global $vars, $session;
     global $_button, $_string;
     global $notimeupdate, $load_template_func, $load_refer_related;
     if (empty($page)) {
         return self::dieMessage('Page name was not defined.');
     }
     $postdata = is_array($data) ? join("\n", $data) : $data;
     $original = isset($vars['original']) ? $vars['original'] : $postdata;
     // ticketは、PliginRenderer::addHiddenField()で自動挿入されるので、同じアルゴリズムでチケット名を生成
     $ticket_name = md5(Utility::getTicket() . REMOTE_ADDR);
     // BugTrack/95 fix Problem: browser RSS request with session
     $session->offsetSet('origin-' . $ticket_name, md5(self::getTicket() . str_replace("\r", '', $original)));
     $ret[] = '<form action="' . Router::get_script_uri() . '" role="form" method="post" class="form-edit" data-collision-check-strict="true">';
     $ret[] = '<input type="hidden" name="cmd" value="edit" />';
     $ret[] = '<input type="hidden" name="page" value="' . self::htmlsc($page) . '" />';
     $ret[] = isset($vars['id']) ? '<input type="hidden" name="id" value="' . self::htmlsc($vars['id']) . '" />' : null;
     if ($load_template_func && $show_template) {
         // ひな形を読み込む
         foreach (Listing::pages() as $_page) {
             $_w = Factory::Wiki($_page);
             if (!$_w->isEditable() || $_w->isHidden()) {
                 continue;
             }
             $_s_page = self::htmlsc($_page);
             $_pages[$_page] = '<option value="' . $_s_page . '">' . $_s_page . '</option>' . "\n";
         }
         // ナチュラルソート
         ksort($_pages, SORT_NATURAL);
         $ret[] = '<div class="form-inline">';
         $ret[] = '<div class="form-group">';
         $ret[] = '<select class="form-control" name="template_page" class="template">';
         $ret[] = '<option value="" disabled="disabled" selected="selected">-- ' . $_button['template'] . ' --</option>';
         $ret[] = join("\n", $_pages);
         $ret[] = '</select>';
         $ret[] = '</div>';
         $ret[] = '<button type="submit" class="btn btn-secondary" name="template" accesskey="l">' . $_button['load'] . '</button>';
         $ret[] = '</div>';
         unset($_s_page, $_w, $_pages);
     }
     // 編集フォーム
     $ret[] = '<textarea name="msg" id="msg" rows="15" class="form-control">' . self::htmlsc(($load_refer_related && isset($vars['refer']) && !empty($vars['refer']) ? '[[' . self::stripBracket($vars['refer']) . ']]' . "\n\n" : '') . $postdata) . '</textarea>';
     $ret[] = '<div class="form-inline">';
     if (IS_MOBILE) {
         // モバイル用
         $ret[] = '<input type="submit" id="btn_submit" name="write" value="' . $_button['update'] . '" data-icon="check" data-inline="true" data-theme="b" />';
         $ret[] = '<input type="submit" id="btn_preview" name="preview" value="' . $_button['preview'] . '" accesskey="p" data-icon="gear" data-inline="true" data-theme="e" />';
         $ret[] = '<input type="submit" id="btn_cancel" name="cancel" value="' . $_button['cancel'] . '" accesskey="c" data-icon="delete" data-inline="true" />';
         $ret[] = $notimeupdate === 2 && Auth::check_role('role_contents_admin') ? '<div data-role="fieldcontain">' : null;
         if ($notimeupdate !== 0 && Factory::Wiki($page)->isValied()) {
             // タイムスタンプを更新しないのチェックボックス
             $ret[] = '<input type="checkbox" name="notimestamp" id="_edit_form_notimestamp" value="true" ' . (isset($vars['notimestamp']) ? ' checked="checked"' : null) . ' />';
             $ret[] = '<label for="_edit_form_notimestamp" data-inline="true">' . $_button['notchangetimestamp'] . '</label>';
         }
         // 管理人のパス入力
         $ret[] = $notimeupdate == 2 && Auth::check_role('role_contents_admin') ? '<input type="password" name="pass" size="12"  data-inline="true" />' . "\n" . '</div>' : null;
         $ret[] = isset($vars['add']) ? '<input type="checkbox" name="add_top" value="true"' . (isset($vars['add']) ? ' checked="checked"' : '') . ' /><label for="add_top">' . $_button['addtop'] . '</label>' : null;
     } else {
         // 通常用
         $ret[] = '<button type="submit" class="btn btn-primary" name="write" accesskey="s"><span class="fa fa-check"></span>' . $_button['update'] . '</button>';
         $ret[] = isset($vars['add']) ? '<input type="checkbox" name="add_top" value="true"' . (isset($vars['add']) ? ' checked="checked"' : '') . ' /><label for="add_top">' . $_button['addtop'] . '</label>' : null;
         $ret[] = '<button type="submit" class="btn btn-secondary" name="preview" accesskey="p"><span class="fa fa-eye"></span>' . $_button['preview'] . '</button>';
         if ($notimeupdate !== 0 && Factory::Wiki($page)->isValied()) {
             // タイムスタンプを更新しないのチェックボックス
             $ret[] = '<div class="checkbox">';
             $ret[] = '<input type="checkbox" name="notimestamp" id="_edit_form_notimestamp" value="true"' . (isset($vars['notimestamp']) ? ' checked="checked"' : null) . ' />';
             $ret[] = '<label for="_edit_form_notimestamp">' . $_button['notchangetimestamp'] . '</label>';
             $ret[] = '</div>';
             //	$ret[] = '<div class="checkbox">';
             //	$ret[] = '<input type="checkbox" name="ping" id="_edit_form_ping" value="true"' . (isset($vars['ping']) ? ' checked="checked"' : null) . ' />';
             //	$ret[] = '<label for="_edit_form_ping">' . $_button['send_ping'] . '</label>';
             //	$ret[] = '</div>';
             //	$ret[] = '<div class="checkbox">';
             //	$ret[] = '<input type="checkbox" name="tweet" id="_edit_form_tweet" value="true"' . (isset($vars['tweet']) ? ' checked="checked"' : null) . ' />';
             //	$ret[] = '<label for="_edit_form_tweet"><span class="fa  fa-twitter"></span></label>';
             //	$ret[] = '</div>';
             //	$ret[] = '<div class="checkbox">';
             //	$ret[] = '<input type="checkbox" name="ping" id="_edit_form_fb" value="true"' . (isset($vars['facebook']) ? ' checked="checked"' : null) . ' />';
             //	$ret[] = '<label for="_edit_form_tweet"><span class="fa  fa-facebook"></span></label>';
             //	$ret[] = '</div>';
         }
         // 管理人のパス入力
         if ($notimeupdate === 2 && Auth::check_role('role_contents_admin')) {
             $ret[] = '<div class="form-group">';
             $ret[] = '<div class="input-group">';
             $ret[] = '<span class="input-group-addon"><span class="fa fa-key"></span></span>';
             $ret[] = '<input type="password" name="pass" class="form-control" size="12" placeholder="Password" />';
             $ret[] = '</div>';
             $ret[] = '</div>';
         }
         $ret[] = '<button type="submit" class="btn btn-warning" name="cancel" accesskey="c"><span class="fa fa-ban"></span>' . $_button['cancel'] . '</button>';
     }
     $ret[] = '</div>';
     $ret[] = '</form>';
     if (isset($vars['help'])) {
         // テキストの整形ルールを表示
         $rule_wiki = Factory::Wiki(self::RULE_PAGENAME);
         $ret[] = '<hr />';
         $ret[] = $rule_wiki->has() ? $rule_wiki->render() : '<p class="alert alert-warning">Sorry, page \'' . Utility::htmlsc(self::RULE_PAGENAME) . '\' unavailable.</p>';
     } else {
         $ret[] = '<ul><li><a href="' . Factory::Wiki($page)->uri('edit', array('help' => 'true')) . '" id="FormatRule">' . $_string['help'] . '</a></li></ul>';
     }
     return join("\n", $ret);
 }
Example #7
0
function attach_list()
{
    global $vars, $_attach_messages, $_string;
    if (Auth::check_role('safemode')) {
        Utility::dieMessage($_string['prohibit']);
    }
    $page = isset($vars['page']) ? $vars['page'] : null;
    $refer = isset($vars['refer']) ? $vars['refer'] : $page;
    $type = isset($vars['type']) ? $vars['type'] : null;
    if (!empty($refer)) {
        $wiki = Factory::Wiki($refer);
        $wiki->isReadable();
        $attaches = $wiki->attach();
        if ($type === 'json') {
            $headers = Header::getHeaders('application/json');
            Header::writeResponse($headers, 200, Json::encode($attaches));
            exit;
        }
        // ページ別添付ファイル一覧
        $msg = str_replace('$1', Utility::htmlsc($refer), $_attach_messages['msg_listpage']);
        if (count($attaches) === 0) {
            return array('msg' => $msg, 'body' => 'No files uploaded.');
        }
        $ret[] = '<table class="table table-borderd plugin-attach-list" data-pagenate="true" data-sortable="true"><thead>';
        $ret[] = '<thead>';
        $ret[] = '<tr>';
        $ret[] = '<th>' . $_attach_messages['msg_file'] . '</th>';
        $ret[] = '<th>' . $_attach_messages['msg_filesize'] . '</th>';
        $ret[] = '<th>' . $_attach_messages['msg_type'] . '</th>';
        $ret[] = '<th>' . $_attach_messages['msg_date'] . '</th>';
        $ret[] = '</tr>';
        $ret[] = '</thead>';
        $ret[] = '<tbody>';
        foreach ($attaches as $name => $files) {
            unset($files['log']);
            foreach ($files as $backup => $file) {
                $attach = new Attach($refer, $name, $backup);
                $ret[] = '<tr>';
                if ($backup === 0) {
                    $ret[] = '<td>' . $attach->toString() . '</td>';
                } else {
                    $ret[] = '<td>' . $name . '<em>(Backup no.' . $backup . ')</em></td>';
                }
                $ret[] = '<td>' . $attach->getSize() . '</td>';
                $ret[] = '<td>' . $attach->getMime() . '</td>';
                $ret[] = '<td>' . $attach->getDate() . '</td>';
                $ret[] = '</tr>';
            }
        }
        $ret[] = '</tbody>';
        $ret[] = '</table>';
    } else {
        // 全ページ添付ファイル一覧
        $msg = $_attach_messages['msg_listall'];
        $ret[] = Listing::get('attach', 'attach');
    }
    return array('msg' => $msg, 'body' => join("\n", $ret));
}
Example #8
0
 /**
  * ページ一覧を取得
  * @param type $dir
  * @param type $ext
  * @return type
  */
 public static function get_existpages($type = 'wiki')
 {
     $rc = array();
     // ページ名の取得
     $pages = Listing::pages($type);
     // $pages = get_existpages($dir, $ext);
     // コンテンツ管理者以上は、: のページも閲覧可能
     $has_permisson = self::check_role('role_contents_admin');
     // 役割の取得
     // $now_role = self::get_role_level();
     $rc = array();
     if (is_array($pages)) {
         foreach ($pages as $file => $page) {
             $wiki = Factory::Wiki($page);
             // 存在しない場合、当然スルー
             if (!$wiki->has()) {
                 continue;
             }
             // 隠しページの場合かつ、隠しページを表示できる権限がない場合スルー
             if ($wiki->isHidden() && $has_permisson) {
                 continue;
             }
             // 閲覧できる権限がない場合はスルー
             if (!$wiki->isReadable()) {
                 continue;
             }
             $rc[$file] = $page;
         }
     }
     ksort($rc, SORT_NATURAL);
     return $rc;
 }
Example #9
0
function plugin_backup_get_list_all($withfilename = FALSE)
{
    global $_string;
    if (Auth::check_role('safemode')) {
        die_message($_string['prohibit']);
    }
    return Listing::get('backup', 'backup', $withfilename);
}
Example #10
0
 /**
  * 検索メイン処理
  * @param string $word 検索ワード
  * @param string $type 検索方法(and, or)
  * @param boolean $non_format
  * @param string $base ベースとなるページ
  * @return string
  */
 public static function do_search($word, $type = 'and', $non_format = FALSE, $base = '')
 {
     global $show_passage;
     global $_string;
     $retval = array();
     // 検索ワードをパース
     $keys = self::get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
     foreach ($keys as &$value) {
         $value = '/' . $value . '/S';
     }
     // AND:TRUE OR:FALSE
     $b_type = $type == 'and';
     // ページ一覧
     $pages = Listing::pages();
     $count = count($pages);
     // 基準となるページが指定されてた場合、それ以外を配列から削除
     if (!empty($base)) {
         $pages = preg_grep('/^' . preg_quote($base, '/') . '/S', $pages);
     }
     foreach ($pages as $page) {
         if (empty($page)) {
             continue;
         }
         $wiki = Factory::Wiki($page);
         // 読む権限がない場合スキップ(Adv.の場合Wikiクラスで権限を管理している)
         if (!$wiki->isReadable() || $wiki->isHidden()) {
             continue;
         }
         $b_match = FALSE;
         // ページ名から検索
         if (!$non_format) {
             $b_match = self::search_keys($keys, $page, $b_type);
         }
         // 通常検索
         $b_match = self::search_keys($keys, $wiki->get(true), $b_type);
         // マッチしない場合スキップ
         if (!$b_match) {
             continue;
         }
         // 結果を配列に保存
         $retval[] = $non_format ? $page : '<li><a href="' . $wiki->uri('read', array('word' => $word)) . '" class="search-summary">' . Utility::htmlsc($page) . '</a>' . ($show_passage ? ' ' . $wiki->passage() : '') . '</li>' . "\n";
     }
     $count = count($retval);
     // フォーマットせずに配列で出力
     if ($non_format) {
         return $retval;
     }
     if ($count === 0) {
         return '<p class="alert alert-warning">' . str_replace('$1', Utility::htmlsc($word), $_string['notfoundresult']) . '</p>';
     }
     return '<p class="alert alert-success">' . str_replace('$1', Utility::htmlsc($word), str_replace('$2', $count, str_replace('$3', count($pages), $b_type ? $_string['andresult'] : $_string['orresult']))) . '</p>' . "\n" . '<div class="list_pages"><ul>' . join("\n", $retval) . '</ul></div>';
 }
Example #11
0
function plugin_spam_pages()
{
    global $vars, $post, $_msg_invalidpass, $_spam_messages;
    $ob = ob_get_level();
    $script = Router::get_script_uri();
    $start = isset($post['start']) ? $post['start'] : NULL;
    $s_start = $start === NULL ? '' : Utility::htmlsc($start);
    $pass = isset($post['pass']) ? $post['pass'] : NULL;
    $sort = isset($post['sort']);
    $s_sort = $sort ? ' checked' : '';
    $per = 100;
    $form = <<<EOD
<form action="{$script}" method="post" class="spam_form">
\t<input type="hidden" name="cmd" value="spam" />
\t<input type="hidden" name="mode" value="pages" />
\t<fieldset>
\t\t<legend>{$_spam_messages['msg_pages']}</legend>
\t\t<label for="start">{$_spam_messages['label_start']}</label>
\t\t<input type="text" name="start" id="start" size="40" value="{$s_start}" /><br />
\t\t<input type="checkbox" name="sort" value="on" id="sort" {$s_sort} />
\t\t<label for="sort">{$_spam_messages['label_sort']}</label><br />
\t\t<label for="pass">{$_spam_messages['label_pass']}</label>
\t\t<input type="password" name="pass" id="pass" size="12" /><br />
\t\t<input type="submit" class="btn btn-primary" name="check" value="{$_spam_messages['check']}" />
\t</fieldset>
</form>

EOD;
    if ($pass !== NULL && Auth::login($pass)) {
        // Check and report
        $method = array('_comment' => '_default', 'badhost' => TRUE);
        echo $form;
        flush();
        if ($ob) {
            @ob_flush();
        }
        $pages = Listing::exists();
        if ($sort) {
            sort($pages, SORT_STRING);
        }
        $count = $search = $hit = 0;
        foreach ($pages as $pagename) {
            ++$count;
            if ($start !== '') {
                if ($start == $pagename) {
                    $start = '';
                } else {
                    continue;
                }
            }
            ++$search;
            if ($search % $per == 0) {
                flush();
                if ($ob) {
                    @ob_flush();
                }
            }
            $progress = Spam::check_uri_spam(Factory::Wiki($pagename)->get(), $method);
            if (empty($progress['is_spam'])) {
                echo Utility::htmlsc($pagename);
                echo '<br />' . "\n";
            } else {
                ++$hit;
                echo '<div style="padding: 0pt 0.7em;" class="ui-state-error ui-corner-all">' . '<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>' . sprintf($_spam_messages['msg_found'], Utility::htmlsc($pagename)) . '</p>';
                echo '<p>' . "\n";
                $tmp = Spam::summarize_detail_badhost($progress);
                if ($tmp != '') {
                    echo '&nbsp; DETAIL_BADHOST: ' . str_replace('  ', '&nbsp; ', nl2br(htmlsc($tmp) . "\n"));
                }
            }
        }
        echo '</p>' . "\n";
        echo '<hr />' . "\n";
        echo sprintf($_spam_messages['msg_hits'], $hit, $search, $count);
        exit;
    }
    $body = $pass === NULL ? '' : '<p><strong>' . $_msg_invalidpass . '</strong></p>' . "\n";
    $body .= $form;
    return array('msg' => $_spam_messages['title'] . $_spam_messages['title_pages'], 'body' => $body);
}
Example #12
0
 /**
  * Returns a list of all Wiki pages in the remote Wiki
  * 全てのページ名からなる配列を返す。
  * @return array
  */
 public function getAllPages()
 {
     return Listing::pages();
 }
Example #13
0
 /**
  * リンクのデーターベースを初期化
  * @return void
  */
 public function init()
 {
     // Init database
     $this->adapter->query('DELETE FROM rel', Adapter::QUERY_MODE_EXECUTE);
     $this->adapter->query('DELETE FROM ref', Adapter::QUERY_MODE_EXECUTE);
     $ref = array();
     // Reference from
     foreach (Listing::pages('wiki') as $_page) {
         $rel = array();
         // Reference to
         $objs = self::getObjects($_page);
         if (empty($objs)) {
             continue;
         }
         foreach ($objs as $_obj) {
             if (!isset($_obj->type) || $_obj->type !== 'pagename' || empty($_obj->name) || $_obj->name === $_page) {
                 continue;
             }
             $_name = $_obj->name;
             if ($_obj instanceof AutoAlias) {
                 $_alias = AutoAlias::getAutoAlias($_name);
                 if (!Factory::Wiki($_alias)->isValied()) {
                     continue;
                 }
                 // not PageName
                 $_name = $_alias;
             }
             $rel[] = $_name;
             if (!isset($ref[$_name][$_page])) {
                 $ref[$_name][$_page] = 1;
             }
             if (!$_obj instanceof AutoLink) {
                 $ref[$_name][$_page] = 0;
             }
         }
         ksort($rel, SORT_NATURAL);
         if (empty($rel)) {
             continue;
         }
         self::setRel($_page, $rel);
     }
     unset($rel, $_page);
     ksort($ref, SORT_NATURAL);
     foreach ($ref as $_page => $arr) {
         foreach ($arr as $ref_page => $ref_auto) {
             $data[] = $ref_page . "\t" . $ref_auto;
         }
         self::setRef($_page, $data);
         unset($data);
     }
     // メモリを開放
     self::getObjects();
     unset($ref_page, $ref_auto);
     // 最適化
     $this->adapter->query('VACUUM', Adapter::QUERY_MODE_EXECUTE);
 }
Example #14
0
function plugin_popular_getlist($view, $max = PLUGIN_POPULAR_DEFAULT, $except)
{
    static $localtime;
    if (!isset($localtime)) {
        list($zone, $zonetime) = Time::setTimeZone(DEFAULT_LANG);
        $localtime = UTIME + $zonetime;
    }
    $today = gmdate('Y/m/d', $localtime);
    // $yesterday = gmdate('Y/m/d', strtotime('yesterday', $localtime));
    $yesterday = gmdate('Y/m/d', gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime)));
    $counters = array();
    foreach (Listing::pages() as $page) {
        if (!empty($except) && preg_match("/" . $except . "/", $page)) {
            continue;
        }
        $wiki = Factory::Wiki($page);
        if (!$wiki->isReadable() || $wiki->isHidden() || !$wiki->isValied()) {
            continue;
        }
        //$count_file = COUNTER_DIR . str_replace('.txt','.count', $file);
        $count_file = COUNTER_DIR . Utility::encode($page) . '.count';
        if (file_exists($count_file)) {
            $array = file($count_file);
            $count = rtrim($array[0]);
            $date = rtrim($array[1]);
            $today_count = rtrim($array[2]);
            $yesterday_count = rtrim($array[3]);
            $counters['_' . $page] = 0;
            if ($view == 'today' or $view == 'recent') {
                // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
                // array_splice()によってキー値が変更されてしまうのを防ぐ
                // ため、キーに '_' を連結する
                if ($today == $date) {
                    $counters['_' . $page] = $today_count;
                }
            }
            if ($view == 'yesterday' or $view == 'recent') {
                if ($today == $date) {
                    $counters['_' . $page] += $yesterday_count;
                } elseif ($yesterday == $date) {
                    $counters['_' . $page] += $today_count;
                }
            }
            if ($view == 'total') {
                $counters['_' . $page] = $count;
            }
            if ($counters['_' . $page] == 0) {
                unset($counters['_' . $page]);
            }
        }
    }
    asort($counters, SORT_NUMERIC);
    // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
    $counters = array_reverse($counters, TRUE);
    // with array_splice()
    if ($max && $max != 0) {
        $counters = array_splice($counters, '0', $max);
    }
    return $counters;
}
Example #15
0
 function loadRows()
 {
     $base = $this->form->base . '/';
     $len = strlen($base);
     $regex = '#^' . preg_quote($base, '#') . '#';
     $this->page_line = count(plugin_tracker_get_source($this->form->config->page . '/page'));
     // Plus! (?)
     // foreach (preg_grep($regex, array_values(get_existpages())) as $pagename) {
     foreach (preg_grep($regex, Listing::pages()) as $pagename) {
         // Plus!
         if (!Factory::Wiki($pagename)->isReadable()) {
             continue;
         }
         if (preg_match(PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN, substr($pagename, $len))) {
             continue;
         }
         if ($this->addRow($pagename) === FALSE) {
             return FALSE;
         }
     }
     if (empty($this->rows)) {
         $this->error = 'Pages not found under: ' . $base;
         return FALSE;
     }
     return TRUE;
 }