Example #1
0
if (session_id() == '' || !isset($_SESSION)) {
    // session isn't started
    session_start();
}
//how to render page?
$showAll = true;
//show all blogposts or just one
$event = null;
//if we're showing only one blogpost, save it's instance in this variable
$postsPerPage = 5;
//posts to load per page - ajax will load this n° of posts eachtime you reach the bottom of the page
if (isset($_GET['id'])) {
    $showAll = false;
    //formatSinglePost();
    $event = new Event(FALSE);
    $event->updateParameters($_GET['id']);
}
//check logged in
$loggedin = isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == 1 ? TRUE : FALSE;
$isAdmin = isset($_SESSION['usertype']) && $_SESSION['usertype'] == "admin" ? TRUE : FALSE;
$errorVisibility = "none";
?>


<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang=""> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
Example #2
0
/**
 * Print Latest newsItems 
 *	
 * @param int $offset 
 * @param int $numberOfPosts
 * @return
 */
function retrievePostsWithTag($tag, $offset, $numberOfPosts)
{
    include_once 'blogpost.inc.php';
    include_once 'event.inc.php';
    include_once 'db.inc.php';
    //Open a database connection and store it
    $db = new PDO(DB_INFO, DB_USER, DB_PASS);
    //initialize array to store retrieved ids
    $results = array();
    //search blogposts
    $sql = "SELECT id, sortdate, created\n\t\t\tFROM blogposts \n\t\t\tWHERE tags LIKE '%" . $tag . "%'";
    //LIMIT ".$numberOfPosts . " OFFSET " . $offset;
    $stmt = $db->prepare($sql);
    $stmt->execute();
    //add results to results array
    while ($row = $stmt->fetch()) {
        array_push($results, array("id" => $row['id'], "created" => $row['created'], "sortdate" => $row['sortdate'], "posttype" => "blogpost"));
        flush();
    }
    $stmt->closeCursor();
    //search events
    $sql = "SELECT id, sortdate, created\n\t\t\tFROM events \n\t\t\tWHERE tags LIKE '%" . $tag . "%'";
    //LIMIT ".$numberOfPosts . " OFFSET " . $offset;
    $stmt = $db->prepare($sql);
    $stmt->execute();
    //add results to results array
    while ($row = $stmt->fetch()) {
        array_push($results, array("id" => $row['id'], "created" => $row['created'], "sortdate" => $row['sortdate'], "posttype" => "event"));
        flush();
    }
    $stmt->closeCursor();
    //if we found results, print them
    if (count($results) > 0) {
        //sort the results array by sortdate and created
        foreach ($results as $key => $row) {
            // Obtain a list of columns
            $sortdate[$key] = $row['sortdate'];
            $created[$key] = $row['created'];
        }
        array_multisort($sortdate, SORT_DESC, $created, SORT_DESC, $results);
        //echo posts
        foreach ($results as $result) {
            switch ($result['posttype']) {
                case 'blogpost':
                    $blogpost = new Blogpost(FALSE);
                    $blogpost->updateParameters($result['id']);
                    echo $blogpost->formatNewspage();
                    flush();
                    break;
                case 'event':
                    $event = new Event(FALSE);
                    $event->updateParameters($result['id']);
                    echo $event->formatEventpage();
                    flush();
                    break;
            }
        }
    } else {
        echo "<h4>Sorry, we found no news articles or events with this tag</h4><br>\n\t\t<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><!-- sorry, I was lazy -->";
    }
}