Exemplo n.º 1
0
<?php

//included in index.php which has configs.php included already
$base = $GLOBALS['base_url'];
$url = $_SERVER["REQUEST_URI"];
if ($part_count === 4) {
    $_GET['cat'] = $url_parts[1];
    $_GET['search'] = urldecode($url_parts[2]);
    $_GET['page'] = (int) $url_parts[$part_count - 1];
    //page is always last part of url or 1
    try {
        $cat = $_GET['cat'];
        $page = $_GET['page'];
        $search = $_GET['search'];
        $parsedown = new Parsedown();
        $post_views = new PostViews($parsedown);
        $db = MongoConnection();
        $db_getter = new MongoGetter($db);
        $post_controller = new PostController($db_getter, $post_views);
        $mongo_results = $post_controller->getSearchPagePosts($page, $cat, $search);
        //false if no result set
        $template = file_get_contents($GLOBALS['template_dir'] . "/base_page.txt");
        $title = $cat . " search '" . $search . "' page " . $page . " - " . $_SERVER['HTTP_HOST'];
        $desc = $_SERVER['HTTP_HOST'] . " - browse " . $cat . " search '" . $search . "' page " . $page;
        if ($mongo_results) {
            //need to special chars anything using $search param that gets inserted into HTML
            $tmplt_data = array();
            $tmplt_data["title"] = htmlspecialchars($title, ENT_QUOTES);
            $tmplt_data["description"] = htmlspecialchars($desc, ENT_QUOTES);
            $tmplt_data["styles"] = "";
            $tmplt_data["scripts"] = "";
Exemplo n.º 2
0
<?php

include_once dirname(__FILE__) . "/../configs.php";
if (isset($_GET["id"]) && isset($_GET["cat"])) {
    $id = $_GET["id"];
    $cat = $_GET["cat"];
    try {
        $db = MongoConnection();
        $db_getter = new MongoGetter($db);
        $post_data = $db_getter->getSingleRowById($id);
        if ($post_data !== NULL) {
            //post is found
            $post_cat = in_array($cat, $post_data["category"]) ? $cat : $post_data["category"][0];
            //it is possible the post is no longer part of the given cat so check if it is and if it is not give the post a cat it belongs to
            $post_data["show_id"] = true;
            //make id visable
            $parse_down = new Parsedown();
            $post_views = new PostViews($parse_down);
            $post_template = file_get_contents($GLOBALS['template_dir'] . "/blog_post.txt");
            echo $post_views->makePostHtmlFromData($post_data, $post_cat, $post_template);
        }
    } catch (MongoCursorException $e) {
        //echo "error message: ".$e->getMessage()."\n";
    }
}
<?php

include_once dirname(__FILE__) . "/../configs.php";
if (isset($_GET["cat"]) && isset($_GET["ts"])) {
    $time = floatval($_GET["ts"]);
    $time_stamp = $time / 1000;
    //js use milliseconds mongo uses seconds convert milliseconds to seconds
    $cat = $_GET['cat'];
    try {
        $db = MongoConnection();
        $db_getter = new MongoGetter($db);
        $post_data = $db_getter->getPreviousPostsFromTimestamp($cat, $time_stamp);
        $post_template = file_get_contents($GLOBALS['template_dir'] . "/next_post_button.txt");
        foreach ($post_data as $posting) {
            $post_view = new PostViews(new Parsedown());
            echo $post_view->getNextPostButton($posting, $cat, $post_template);
        }
    } catch (MongoCursorException $e) {
        echo "error message: " . $e->getMessage() . "\n";
    }
}
Exemplo n.º 4
0
 $db_getter = new MongoGetter($db);
 if (strlen($cat) === 0 && isset($_GET["search"])) {
     $search = $_GET["search"];
     $cursor = $db_getter->getPostsFromDbBySearch($page_num, $search);
 } else {
     $cursor = $db_getter->getBlogManagePosts($page_num, $cat);
 }
 $posts = iterator_to_array($cursor);
 if (count($posts) > $GLOBALS['amount_on_manger_tab']) {
     array_pop($posts);
     $next = true;
 } else {
     $next = false;
 }
 $parsedown = new Parsedown();
 $post_views = new PostViews($parsedown);
 $modified_array = array();
 $post_template = file_get_contents($GLOBALS['template_dir'] . "/blog_post.txt");
 foreach ($posts as $row) {
     $post_cat = strlen($cat) > 0 ? $cat : $row["category"][0];
     //when viewing all posts/search cat will be empty string so use base cat
     $modified_row = $post_views->generateModifedListingForPostInfo($row, $post_cat);
     $row["show_id"] = true;
     //show_id on template, so manager page JavaScript can identify them
     $post_html = $post_views->makePostHtmlFromData($row, $post_cat, $post_template);
     array_push($modified_array, array("post_data" => $modified_row, "post_html" => $post_html));
 }
 $prev = $page_num > 1 ? true : false;
 $data = array("posts" => $modified_array, "next" => $next, "prev" => $prev);
 header('Content-Type: application/json; charset=utf-8');
 echo json_encode(array("result" => true, "data" => $data));
Exemplo n.º 5
0
$server = dirname(__FILE__) . "/../";
include_once $server . "/configs.php";
if (count($GLOBALS['url_parts']) === 6) {
    $base = $GLOBALS['base_url'];
    $cat = $GLOBALS['url_parts'][1];
    $year = $GLOBALS['url_parts'][2];
    $month = $GLOBALS['url_parts'][3];
    $date = $GLOBALS['url_parts'][4];
    $title = $GLOBALS['url_parts'][5];
    $initial_date = "{$year}-{$month}-{$date}";
    $start = strtotime($initial_date);
    $end = strtotime("{$initial_date}+23 hours 59 minutes 59 seconds");
    try {
        $db = MongoConnection();
        $db_getter = new MongoGetter($db);
        $post_views = new PostViews(new Parsedown());
        $non_hyphenated_title = $post_views->convertPostTitleHyphensToSpaces($title);
        $single_post_data = $db_getter->getSingleRowFromDate($non_hyphenated_title, $start, $end);
        //NULL if not found
        $page_template = file_get_contents($GLOBALS['template_dir'] . "/base_page.txt");
        $post_template = file_get_contents($GLOBALS['template_dir'] . "/blog_post.txt");
        if ($single_post_data !== NULL) {
            $tmplt_data = array();
            $tmplt_data["title"] = $single_post_data["title"] . " - " . $_SERVER['HTTP_HOST'];
            $tmplt_data["description"] = $single_post_data["description"];
            $tmplt_data["styles"] = "";
            $tmplt_data["scripts"] = "<script src='/scripts/page_actions/post_actions.js' ></script>";
            $tmplt_data["base"] = $base;
            $tmplt_data["header"] = $post_views->getCatHeaderList($cat);
            $tmplt_data["category"] = $cat;
            $tmplt_data["search_placeholder"] = "search {$cat}";
Exemplo n.º 6
0
<?php

include_once dirname(__FILE__) . "/../configs.php";
$json = json_decode($_POST['json'], true);
$post_view = new PostViews(new Parsedown());
$post_template = file_get_contents($GLOBALS['template_dir'] . "/blog_post.txt");
$single = array();
$single["_id"] = "5428784f7f8b9afe1a779e93";
//just a dummy ID means nothing
$single["lastModified"] = new MongoDate();
$single["title"] = "Preview";
$single["post_data"] = $json;
$single["author"] = $_SESSION['user'];
echo $post_view->makePostHtmlFromData($single, $GLOBALS['post_categories'][0], $post_template);
//post category is just a placeholder the link will not work i the preview it is just a sample