Example #1
0
function buildPostsForPage($pageNumber = 0, $amount = POSTS_PER_PAGE_ADMIN, $removeUnpublished = true, $tagKey = false)
{
    global $dbPosts;
    global $dbTags;
    global $Url;
    $posts = array();
    if ($tagKey) {
        // Get the keys list from tags database, this database is optimized for this case.
        $list = $dbTags->getList($pageNumber, $amount, $tagKey);
    } else {
        // Get the keys list from posts database.
        $list = $dbPosts->getList($pageNumber, $amount, $removeUnpublished);
    }
    // There are not posts for the page number then set the page notfound
    if (empty($list) && $pageNumber > 0) {
        $Url->setNotFound(true);
    }
    // Foreach post key, build the post.
    foreach ($list as $postKey => $values) {
        $Post = buildPost($postKey);
        if ($Post !== false) {
            array_push($posts, $Post);
        }
    }
    return $posts;
}
Example #2
0
 private function getPost($key)
 {
     // Generate the object Post
     $Post = buildPost($key);
     if (!$Post) {
         return json_encode(array('status' => '0', 'bludit' => 'Bludit API plugin', 'message' => 'The post doesn\'t exist'));
     }
     return $Post->json();
 }
Example #3
0
function build_posts_per_page($pageNumber = 0, $amount = 5, $draftPosts = false)
{
    global $dbPosts;
    global $posts;
    global $Url;
    $list = $dbPosts->getPage($pageNumber, $amount, $draftPosts);
    // There are not post for the pageNumber then NotFound page
    if (empty($list) && $pageNumber > 0) {
        $Url->setNotFound(true);
    }
    foreach ($list as $slug => $db) {
        $Post = buildPost($slug);
        if ($Post !== false) {
            array_push($posts, $Post);
        }
    }
}
Example #4
0
function manageStatus()
{
    global $isadmin;
    $threads = countThreads();
    $bans = count(allBans());
    $info = $threads . ' ' . plural('thread', $threads) . ', ' . $bans . ' ' . plural('ban', $bans);
    $output = '';
    if ($isadmin && TINYIB_DBMODE == 'mysql' && function_exists('mysqli_connect')) {
        // Recommend MySQLi
        $output .= <<<EOF
\t<fieldset>
\t<legend>Notice</legend>
\t<p><b>TINYIB_DBMODE</b> is currently <b>mysql</b> in <b>settings.php</b>, but <a href="http://www.php.net/manual/en/book.mysqli.php">MySQLi</a> is installed.  Please change it to <b>mysqli</b>.  This will not affect your data.</p>
\t</fieldset>
EOF;
    }
    $reqmod_html = '';
    if (TINYIB_REQMOD != 'disable') {
        $reqmod_post_html = '';
        $reqmod_posts = latestPosts(false);
        foreach ($reqmod_posts as $post) {
            if ($reqmod_post_html != '') {
                $reqmod_post_html .= '<tr><td colspan="2"><hr></td></tr>';
            }
            $reqmod_post_html .= '<tr><td>' . buildPost($post, TINYIB_INDEXPAGE) . '</td><td valign="top" align="right">
			<table border="0"><tr><td>
			<form method="get" action="?"><input type="hidden" name="manage" value=""><input type="hidden" name="approve" value="' . $post['id'] . '"><input type="submit" value="Approve" class="managebutton"></form>
			</td><td>
			<form method="get" action="?"><input type="hidden" name="manage" value=""><input type="hidden" name="moderate" value="' . $post['id'] . '"><input type="submit" value="More Info" class="managebutton"></form>
			</td></tr><tr><td align="right" colspan="2">
			<form method="get" action="?"><input type="hidden" name="manage" value=""><input type="hidden" name="delete" value="' . $post['id'] . '"><input type="submit" value="Delete" class="managebutton"></form>
			</td></tr></table>
			</td></tr>';
        }
        if ($reqmod_post_html != '') {
            $reqmod_html = <<<EOF
\t<fieldset>
\t<legend>Pending posts</legend>
\t<table border="0" cellspacing="0" cellpadding="0" width="100%">
\t{$reqmod_post_html}
\t</table>
\t</fieldset>
EOF;
        }
    }
    $post_html = '';
    $posts = latestPosts(true);
    foreach ($posts as $post) {
        if ($post_html != '') {
            $post_html .= '<tr><td colspan="2"><hr></td></tr>';
        }
        $post_html .= '<tr><td>' . buildPost($post, TINYIB_INDEXPAGE) . '</td><td valign="top" align="right"><form method="get" action="?"><input type="hidden" name="manage" value=""><input type="hidden" name="moderate" value="' . $post['id'] . '"><input type="submit" value="Moderate" class="managebutton"></form></td></tr>';
    }
    $output .= <<<EOF
\t<fieldset>
\t<legend>Status</legend>
\t
\t<fieldset>
\t<legend>Info</legend>
\t<table border="0" cellspacing="0" cellpadding="0" width="100%">
\t<tbody>
\t<tr><td>
\t\t{$info}
\t</td>
EOF;
    if ($isadmin) {
        $output .= <<<EOF
\t<td valign="top" align="right">
\t\t<form method="get" action="?">
\t\t\t<input type="hidden" name="manage">
\t\t\t<input type="hidden" name="update">
\t\t\t<input type="submit" value="Update TinyIB" class="managebutton">
\t\t</form>
\t</td>
EOF;
    }
    $output .= <<<EOF
\t</tr>
\t</tbody>
\t</table>
\t</fieldset>

\t{$reqmod_html}
\t
\t<fieldset>
\t<legend>Recent posts</legend>
\t<table border="0" cellspacing="0" cellpadding="0" width="100%">
\t{$post_html}
\t</table>
\t</fieldset>
\t
\t</fieldset>
\t<br>
EOF;
    return $output;
}
Example #5
0
// Main
// ============================================================================
// Search for changes on posts by the user.
if (CLI_MODE && false) {
    if ($dbPosts->cliMode()) {
        reIndexTagsPosts();
    }
}
// Execute the scheduler.
if ($dbPosts->scheduler()) {
    // Reindex dbTags.
    reIndexTagsPosts();
}
// Build specific post.
if ($Url->whereAmI() === 'post' && $Url->notFound() === false) {
    $Post = buildPost($Url->slug());
    // The post doesn't exist.
    if ($Post === false) {
        $Url->setNotFound(true);
        unset($Post);
    } elseif (!$Post->published()) {
        $Url->setNotFound(true);
        unset($Post);
    } else {
        $posts[0] = $Post;
    }
} elseif ($Url->whereAmI() === 'tag' && $Url->notFound() === false) {
    $posts = buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug());
} else {
    // Posts for admin area.
    if ($Url->whereAmI() === 'admin') {
Example #6
0
    if ($dbPosts->delete($key)) {
        // Reindex tags, this function is in 70.posts.php
        reIndexTagsPosts();
        Alert::set($Language->g('The post has been deleted successfully'));
        Redirect::page('admin', 'manage-posts');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to delete the post.');
    }
}
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['delete-post'])) {
        deletePost($_POST['key']);
    } else {
        editPost($_POST);
    }
}
// ============================================================================
// Main after POST
// ============================================================================
if (!$dbPosts->postExists($layout['parameters'])) {
    Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to get the post: ' . $layout['parameters']);
    Redirect::page('admin', 'manage-posts');
}
$_Post = buildPost($layout['parameters']);
$layout['title'] .= ' - ' . $Language->g('Edit post') . ' - ' . $_Post->title();
Example #7
0
function manageModeratePost($post)
{
    global $isadmin;
    $ban = banByIP($post['ip']);
    $ban_disabled = !$ban && $isadmin ? '' : ' disabled';
    $ban_disabled_info = !$ban ? '' : ' A ban record already exists for ' . $post['ip'];
    $post_html = buildPost($post, true);
    return <<<EOF
\t<fieldset>
\t<legend>Moderating post No.{$post['id']}</legend>
\t
\t<div class="floatpost">
\t<fieldset>
\t<legend>Post</legend>\t
\t{$post_html}
\t</fieldset>
\t</div>
\t
\t<fieldset>
\t<legend>Action</legend>\t\t\t\t\t
\t<form method="get" action="?">
\t<input type="hidden" name="manage" value="">
\t<input type="hidden" name="delete" value="{$post['id']}">
\t<input type="submit" value="Delete Post" class="managebutton">
\t</form>
\t<br>
\t<form method="get" action="?">
\t<input type="hidden" name="manage" value="">
\t<input type="hidden" name="bans" value="{$post['ip']}">
\t<input type="submit" value="Ban Poster" class="managebutton"{$ban_disabled}>{$ban_disabled_info}
\t</form>
\t</fieldset>
\t
\t</fieldset>
\t<br>
EOF;
}
Example #8
0
<?php

date_default_timezone_set("Europe/Sofia");
$text = $_GET['text'];
$matches = preg_split("/\r?\n/", $text, -1, PREG_SPLIT_NO_EMPTY);
$allLines = trimAllLines($matches);
$posts = [];
foreach ($allLines as $line) {
    $data = trimAllLines(explode(";", $line));
    $dateAsTime = strtotime($data[1]);
    $posts[$dateAsTime] = buildPost($data);
}
krsort($posts);
echo implode("", $posts);
function buildPost($parts)
{
    $result = "";
    $date = date("j F Y", strtotime($parts[1]));
    $author = htmlspecialchars($parts[0]);
    $post = htmlspecialchars($parts[2]);
    $likes = htmlspecialchars($parts[3]);
    $result .= "<article>";
    $result .= "<header><span>{$author}</span><time>{$date}</time></header>";
    $result .= "<main><p>{$post}</p></main>";
    $result .= "<footer><div class=\"likes\">{$likes} people like this</div>";
    if (isset($parts[4])) {
        $comments = explode("/", $parts[4]);
        $result .= "<div class=\"comments\">";
        foreach ($comments as $value) {
            $comment = htmlspecialchars(trim($value));
            $result .= "<p>{$comment}</p>";