コード例 #1
0
ファイル: main.php プロジェクト: tas2580/wiki
 /**
  * Display an article
  *
  * @param	string	$article	URL of the article
  * @return	object
  */
 public function article($article)
 {
     $this->user->add_lang_ext('tas2580/wiki', 'common');
     if (!$this->auth->acl_get('u_wiki_view')) {
         trigger_error('NOT_AUTHORISED');
     }
     $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['WIKI'], 'U_VIEW_FORUM' => $this->helper->route('tas2580_wiki_index', array())));
     $this->template->assign_vars(array('WIKI_FOOTER' => $this->user->lang('WIKI_FOOTER', base64_decode('aHR0cHM6Ly90YXMyNTgwLm5ldA=='), base64_decode('dGFzMjU4MA=='))));
     include $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
     include $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
     $action = $this->request->variable('action', '');
     $id = $this->request->variable('id', 0);
     switch ($action) {
         case 'edit':
             return $this->edit->edit_article($article);
         case 'versions':
             return $this->compare->view_versions($article);
         case 'compare':
             $from = $this->request->variable('from', 0);
             $to = $this->request->variable('to', 0);
             return $this->compare->compare_versions($article, $from, $to);
         case 'delete':
             return $this->delete->version($id);
         case 'detele_article':
             return $this->delete->article($article);
         case 'active':
             return $this->edit->active($id);
         case 'deactivate':
             return $this->edit->deactivate($article);
         default:
             return $this->view->view_article($article, $id);
     }
 }
コード例 #2
0
ファイル: view.php プロジェクト: tas2580/wiki
    /**
     * View an article
     *
     * @param	string	$article	URL of the article
     * @param	int		$id		ID of the article
     * @return	object
     */
    public function view_article($article, $id = 0)
    {
        // Setup message parser
        $this->message_parser = $this->setup_parser();
        $where = $id === 0 ? "article_url = '" . $this->db->sql_escape($article) . "' AND article_approved = 1" : 'article_id = ' . (int) $id;
        $sql_array = array('SELECT' => 'a.*, u.user_id, u.username, u.user_colour', 'FROM' => array($this->article_table => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = a.article_user_id')), 'WHERE' => $where, 'ORDER_BY' => 'a.article_last_edit DESC');
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, 1);
        $this->data = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // Do we have a newer version?
        if ($id === 0 && $this->auth->acl_get('u_wiki_set_active')) {
            $sql = 'SELECT article_id
				FROM ' . $this->article_table . "\n\t\t\t\tWHERE article_url = '" . $this->db->sql_escape($this->data['article_url']) . "'\n\t\t\t\t\tAND article_id <> " . (int) $this->data['article_id'] . '
					AND article_last_edit > ' . (int) $this->data['article_last_edit'] . '
				ORDER BY article_last_edit DESC';
            $result = $this->db->sql_query_limit($sql, 1);
            $row = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            if (!empty($row['article_id'])) {
                $this->template->assign_vars(array('S_NEW_VERSION' => true, 'U_NEW_VERSION' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'id' => $row['article_id']))));
            }
        }
        if ($id != 0 && $this->data['article_approved'] != 1 && $this->auth->acl_get('u_wiki_set_active')) {
            $this->template->assign_vars(array('U_SET_ACTIVE' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'active', 'id' => $id))));
        }
        if (!empty($this->data['article_title']) && !empty($article)) {
            $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->data['article_title'], 'U_VIEW_FORUM' => $this->helper->route('tas2580_wiki_article', array('article' => $article))));
        }
        // If the article do not exist generate it
        if (!$this->data) {
            // Do we have a inactive article?
            if ($this->auth->acl_get('m_wiki_view_inactive')) {
                $sql = 'SELECT article_id
					FROM ' . $this->article_table . "\n\t\t\t\t\tWHERE article_url = '" . $this->db->sql_escape($article) . "'";
                $result = $this->db->sql_query_limit($sql, 1);
                $row = $this->db->sql_fetchrow($result);
                if (!empty($row['article_id'])) {
                    return $this->compare->view_versions($article);
                }
            }
            return $this->edit->edit_article($article);
        } else {
            $sources = explode("\n", $this->data['article_sources']);
            foreach ($sources as $source) {
                if (!empty($source)) {
                    $this->template->assign_block_vars('article_sources', array('SOURCE' => $source));
                }
            }
            $this->message_parser->message = $this->data['article_text'];
            $this->message_parser->bbcode_bitfield = $this->data['bbcode_bitfield'];
            $this->message_parser->bbcode_uid = $this->data['bbcode_uid'];
            $allow_bbcode = $allow_magic_url = $allow_smilies = true;
            $this->message_parser->format_display($allow_bbcode, $allow_magic_url, $allow_smilies);
            if (!empty($this->data['article_redirect'])) {
                $redirect_note = $this->user->lang('NO_ARTICLE_REDIRECT', $this->helper->route('tas2580_wiki_article', array('article' => $this->data['article_redirect'])), $this->data['article_redirect']);
                if ($this->auth->acl_get('u_wiki_set_redirect')) {
                    $redirect_note = $redirect_note . $this->message_parser->message;
                }
            }
            // article views
            if (isset($this->user->data['session_page']) && !$this->user->data['is_bot'] && (strpos($this->user->data['session_page'], 'wiki/' . $this->data['article_url']) === false || isset($this->user->data['session_created']))) {
                $article_id = $this->data['article_id'];
                $sql = 'UPDATE ' . $this->article_table . "\n\t\t\t\t\t\tSET article_views = article_views + 1\n\t\t\t\t\t\tWHERE article_id = {$article_id}";
                $this->db->sql_query($sql);
            }
            $s_edit_redirect = !empty($this->data['article_redirect']) && $this->auth->acl_get('u_wiki_set_redirect') || empty($this->data['article_redirect']) ? true : false;
            $this->template->assign_vars(array('ARTICLE_TITLE' => $this->data['article_title'], 'ARTICLE_TEXT' => $this->data['article_redirect'] ? $redirect_note : $this->message_parser->message, 'LAST_EDIT' => $this->user->format_date($this->data['article_last_edit']), 'LAST_EDIT_ISO' => date('Y-m-d', $this->data['article_last_edit']), 'ARTICLE_USER' => get_username_string('full', $this->data['user_id'], $this->data['username'], $this->data['user_colour']), 'S_EDIT' => $this->auth->acl_get('u_wiki_edit') && $s_edit_redirect, 'U_EDIT' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'edit')), 'S_VERSIONS' => $this->auth->acl_get('u_wiki_versions'), 'U_VERSIONS' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'versions')), 'S_DELETE' => $this->auth->acl_get('m_wiki_delete') && !$this->data['article_approved'], 'U_DELETE' => $this->helper->route('tas2580_wiki_index', array('article' => $article, 'action' => 'delete', 'id' => $this->data['article_id'])), 'ARTICLE_VERSION' => $id, 'ARTICLE_VIEWS_TEXT' => $this->user->lang('ARTICLE_VIEWS_TEXT', $this->data['article_views']), 'EDIT_REASON' => $id != 0 ? $this->data['article_edit_reason'] : '', 'U_TOPIC' => $this->data['article_topic_id'] != 0 ? append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, 't=' . $this->data['article_topic_id']) : ''));
        }
        return $this->helper->render('article_body.html', $this->data['article_title']);
    }