Esempio n. 1
0
function getBlogContent($path)
{
    $action = array_shift($path);
    if ($action == null) {
        $action = '1';
    }
    switch ($action) {
        case "post":
            global $title;
            $postId = array_shift($path);
            if (isValidId($postId, "posts")) {
                $title = fetchPostTitle($postId) . " (Post)" . $title;
                return getPost($postId);
            } else {
                return get404();
            }
            break;
        case "tags":
            global $currentTag;
            global $title;
            $currentTag = array_shift($path);
            if (isValidId($currentTag, "tags")) {
                $title = fetchTagName($currentTag) . " (Tag)" . $title;
                return getTag($currentTag);
            } else {
                return get404();
            }
            break;
        default:
            global $title;
            $validNumber = preg_match("/^[0-9]+\$/", $action, $matches);
            if (!$validNumber) {
                return get404();
            }
            if (getPageCount("posts") < $action) {
                return get404();
            }
            $title = "Blog" . $title;
            if ($action == 1) {
                $content = '<h1>Blog</h1><p>A small collection of thoughts and progress notes I thought the would would possibly what to know about. I try to keep my updates sparse but informative but I can\'t hold that promise.</p>';
            } else {
                $content = getPageLinks("You are viewing blog posts from a past time.<br>", $action, "/blog/", "posts");
            }
            return $content . getRecentPosts($action - 1) . getPageLinks("Page Selection<br>", $action, "/blog/", "posts");
            break;
    }
}
Esempio n. 2
0
    /**
     * Find the ten most recent posts.
     * Accessed by action=recent.
     */
    public function action_recent()
    {
        global $txt, $scripturl, $user_info, $context, $modSettings, $board;
        $db = database();
        loadTemplate('Recent');
        $context['page_title'] = $txt['recent_posts'];
        $context['sub_template'] = 'recent';
        require_once SUBSDIR . '/Recent.subs.php';
        if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) {
            $_REQUEST['start'] = 95;
        }
        $query_parameters = array();
        // Recent posts by category id's
        if (!empty($_REQUEST['c']) && empty($board)) {
            $categories = array_map('intval', explode(',', $_REQUEST['c']));
            if (count($categories) === 1) {
                require_once SUBSDIR . '/Categories.subs.php';
                $name = categoryName($categories[0]);
                if (empty($name)) {
                    fatal_lang_error('no_access', false);
                }
                $context['linktree'][] = array('url' => $scripturl . '#c' . $categories[0], 'name' => $name);
            }
            // Find the number of posts in these categorys, exclude the recycle board.
            require_once SUBSDIR . '/Boards.subs.php';
            $boards_posts = boardsPosts(array(), $categories, false, false);
            $total_cat_posts = array_sum($boards_posts);
            $boards = array_keys($boards_posts);
            if (empty($boards)) {
                fatal_lang_error('error_no_boards_selected');
            }
            // The query for getting the messages
            $query_this_board = 'b.id_board IN ({array_int:boards})';
            $query_parameters['boards'] = $boards;
            // If this category has a significant number of posts in it...
            if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) {
                $query_this_board .= '
						AND m.id_msg >= {int:max_id_msg}';
                $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 400 - $_REQUEST['start'] * 7);
            }
            $context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $categories), $_REQUEST['start'], min(100, $total_cat_posts), 10, false);
        } elseif (!empty($_REQUEST['boards'])) {
            $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
            foreach ($_REQUEST['boards'] as $i => $b) {
                $_REQUEST['boards'][$i] = (int) $b;
            }
            // Fetch the number of posts for the supplied board IDs
            require_once SUBSDIR . '/Boards.subs.php';
            $boards_posts = boardsPosts($_REQUEST['boards'], array());
            $total_posts = array_sum($boards_posts);
            $boards = array_keys($boards_posts);
            if (empty($boards)) {
                fatal_lang_error('error_no_boards_selected');
            }
            // Build the query for finding the messages
            $query_this_board = 'b.id_board IN ({array_int:boards})';
            $query_parameters['boards'] = $boards;
            // If these boards have a significant number of posts in them...
            if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) {
                $query_this_board .= '
						AND m.id_msg >= {int:max_id_msg}';
                $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 500 - $_REQUEST['start'] * 9);
            }
            $context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false);
        } elseif (!empty($board)) {
            require_once SUBSDIR . '/Boards.subs.php';
            $board_data = fetchBoardsInfo(array('boards' => $board), array('selects' => 'posts'));
            $query_this_board = 'b.id_board = {int:board}';
            $query_parameters['board'] = $board;
            // If this board has a significant number of posts in it...
            if ($board_data[$board]['num_posts'] > 80 && $board_data[$board]['num_posts'] > $modSettings['totalMessages'] / 10) {
                $query_this_board .= '
						AND m.id_msg >= {int:max_id_msg}';
                $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 600 - $_REQUEST['start'] * 10);
            }
            $context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $board_data[$board]['num_posts']), 10, true);
        } else {
            $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
						AND b.id_board != {int:recycle_board}' : '') . '
						AND m.id_msg >= {int:max_id_msg}';
            $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 100 - $_REQUEST['start'] * 6);
            $query_parameters['recycle_board'] = $modSettings['recycle_board'];
            // Set up the pageindex
            require_once SUBSDIR . '/Boards.subs.php';
            $context['page_index'] = constructPageIndex($scripturl . '?action=recent', $_REQUEST['start'], min(100, sumRecentPosts()), 10, false);
        }
        $context['linktree'][] = array('url' => $scripturl . '?action=recent' . (empty($board) ? empty($categories) ? '' : ';c=' . implode(',', $categories) : ';board=' . $board . '.0'), 'name' => $context['page_title']);
        $key = 'recent-' . $user_info['id'] . '-' . md5(serialize(array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start'];
        if (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null) {
            $done = false;
            while (!$done) {
                // Find the 10 most recent messages they can *view*.
                // @todo SLOW This query is really slow still, probably?
                $request = $db->query('', '
					SELECT m.id_msg
					FROM {db_prefix}messages AS m
						INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
					WHERE ' . $query_this_board . '
						AND m.approved = {int:is_approved}
					ORDER BY m.id_msg DESC
					LIMIT {int:offset}, {int:limit}', array_merge($query_parameters, array('is_approved' => 1, 'offset' => $_REQUEST['start'], 'limit' => 10)));
                // If we don't have 10 results, try again with an unoptimized version covering all rows, and cache the result.
                if (isset($query_parameters['max_id_msg']) && $db->num_rows($request) < 10) {
                    $db->free_result($request);
                    $query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board);
                    $cache_results = true;
                    unset($query_parameters['max_id_msg']);
                } else {
                    $done = true;
                }
            }
            $messages = array();
            while ($row = $db->fetch_assoc($request)) {
                $messages[] = $row['id_msg'];
            }
            $db->free_result($request);
            if (!empty($cache_results)) {
                cache_put_data($key, $messages, 120);
            }
        }
        // Nothing here... Or at least, nothing you can see...
        if (empty($messages)) {
            $context['posts'] = array();
            return;
        }
        list($context['posts'], $board_ids) = getRecentPosts($messages, $_REQUEST['start']);
        // There might be - and are - different permissions between any and own.
        $permissions = array('own' => array('post_reply_own' => 'can_reply', 'delete_own' => 'can_delete'), 'any' => array('post_reply_any' => 'can_reply', 'mark_any_notify' => 'can_mark_notify', 'delete_any' => 'can_delete'));
        // Provide an easy way for integration to interact with the recent display items
        call_integration_hook('integrate_recent_message_list', array($messages, &$permissions));
        // Now go through all the permissions, looking for boards they can do it on.
        foreach ($permissions as $type => $list) {
            foreach ($list as $permission => $allowed) {
                // They can do it on these boards...
                $boards = boardsAllowedTo($permission);
                // If 0 is the only thing in the array, they can do it everywhere!
                if (!empty($boards) && $boards[0] == 0) {
                    $boards = array_keys($board_ids[$type]);
                }
                // Go through the boards, and look for posts they can do this on.
                foreach ($boards as $board_id) {
                    // Hmm, they have permission, but there are no topics from that board on this page.
                    if (!isset($board_ids[$type][$board_id])) {
                        continue;
                    }
                    // Okay, looks like they can do it for these posts.
                    foreach ($board_ids[$type][$board_id] as $counter) {
                        if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) {
                            $context['posts'][$counter]['tests'][$allowed] = true;
                        }
                    }
                }
            }
        }
        $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
        foreach ($context['posts'] as $counter => $post) {
            // Some posts - the first posts - can't just be deleted.
            $context['posts'][$counter]['tests']['can_delete'] &= $context['posts'][$counter]['delete_possible'];
            // And some cannot be quoted...
            $context['posts'][$counter]['tests']['can_quote'] = $context['posts'][$counter]['tests']['can_reply'] && $quote_enabled;
            // Let's add some buttons here!
            $context['posts'][$counter]['buttons'] = array('remove' => array('href' => $scripturl . '?action=deletemsg;msg=' . $post['id'] . ';topic=' . $post['topic'] . ';recent;' . $context['session_var'] . '=' . $context['session_id'], 'text' => $txt['remove'], 'test' => 'can_delete', 'custom' => 'onclick="return confirm(' . JavaScriptEscape($txt['remove_message'] . '?') . ');"'), 'notify' => array('href' => $scripturl . '?action=notify;topic=' . $post['topic'] . '.' . $post['start'], 'text' => $txt['notify'], 'test' => 'can_mark_notify'), 'reply' => array('href' => $scripturl . '?action=post;topic=' . $post['topic'] . '.' . $post['start'], 'text' => $txt['reply'], 'test' => 'can_reply'), 'quote' => array('href' => $scripturl . '?action=post;topic=' . $post['topic'] . '.' . $post['start'] . ';quote=' . $post['id'], 'text' => $txt['quote'], 'test' => 'can_quote'));
        }
    }
Esempio n. 3
0
<?php 
echo '<div id="sidebar"><br><br>';
echo '<div class="sidebar_content"><h4>Recent Posts</h4><br>';
$x = 0;
foreach (getRecentPosts() as $recentPost) {
    if ($x > 0) {
        echo '<br>';
    }
    echo '<a class="recent_post_title" href="/blog/post/' . $recentPost['post_id'] . '">' . $recentPost['post_title'] . '</a><br>';
    echo '<p class="note recent_post_note">' . date("F jS, Y", strtotime($recentPost['post_time'])) . '<br>';
    foreach (getPostTags($recentPost['post_id']) as $recentPostTag) {
        echo '<a class="recent_post_note" href="/blog/tag/' . $recentPostTag . '">' . $recentPostTag . '</a>&nbsp; ';
    }
    echo '</p>';
    $x++;
}
echo '</div><div class="sidebar_content"><h4>All Posts</h4><br>';
echo '<a class="recent_post_title" href="/blog/all">Click Here</a><br>';
echo '<p class="note recent_post_note">to see a full blog post listing.</p>';
echo '</div><div class="sidebar_content"><h4>Tags</h4><br>';
$sortTags = getTags();
usort($sortTags, "tagSort");
foreach ($sortTags as $tag) {
    echo '<p class="note tag_note"><a class="tag_link" href="/blog/tag/' . $tag['tag_id'] . '">' . $tag['tag_name'] . '</a>';
    echo '&nbsp;(' . getTagCount($tag['tag_id']) . ')</p>' . "\n";
}
echo '</div></div>';
?>

Esempio n. 4
0
$pageTitle = "发现";
require_once 'includes/header.php';
//list new users from zhx_user
$rows = getRecentUsers(10);
echo '<p class="user_list_title">最新用户:</p><hr>';
echo '<ul class="user_list">';
foreach ($rows as $row) {
    echo '<li><a href="viewUser.php?target_uid=' . $row['uid'] . '"><img  src="images/uploads/avatar_100/' . $row['avatar'] . '"><br>';
    //show user's avatar
    echo '<span>' . $row['name'] . '</span></a></li>';
}
echo '</ul>';
//end user_list ul
//list new posts from zhx_post
$rows1 = getRecentPosts(10);
echo '<p  class="user_list_title">最新记录:</p><hr>';
echo '<ul class="post_list_find">';
foreach ($rows1 as $row) {
    //get post time
    $postTimeRow = $row['date'];
    $postTime = strtotime($postTimeRow);
    $time = new Mygettime(time(), $postTime);
    $showTime = $time->index();
    //get post like people
    $sql = "select zhx_post.pid,zhx_like.uid,lid from zhx_post left join zhx_like on zhx_post.pid=zhx_like.pid where zhx_post.pid={$row['pid']} order by lid desc";
    $like_data = fetchAll($sql);
    $likeNum = getNumByPid($row['pid'], "zhx_like");
    //get post comment
    $sql = "select zhx_post.pid,zhx_comment.uid,zhx_comment.cid,zhx_comment.comment,zhx_comment.date from zhx_post left join zhx_comment on zhx_post.pid=zhx_comment.pid where zhx_post.pid={$row['pid']} order by cid desc";
    $comment_data = fetchAll($sql);