From be4f83cd2a17a0ec05f5bce50c91befaafaa6e0c Mon Sep 17 00:00:00 2001 From: jhunkeler Date: Sun, 20 Dec 2009 18:38:08 +0000 Subject: Test. git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@376 c5b2fb0a-d05d-0410-98c8-828840a80ff6 --- modules/news/functions.php | 260 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 modules/news/functions.php (limited to 'modules/news/functions.php') diff --git a/modules/news/functions.php b/modules/news/functions.php new file mode 100644 index 0000000..66c8b68 --- /dev/null +++ b/modules/news/functions.php @@ -0,0 +1,260 @@ +. + */ + + /** + * getNewsComments($id) + * Function getting an array of comments for posted news + * @param id - news_id cooresponding to `bayonet_news` + * @return - associative array of comments + */ +function getNewsComments($id){ + + global $db; + $result = $db->Query("SELECT c.comment_id, c.news_id, c.author_id, c.message, c.date, u.username AS author, u.avatar as avatar ". + "FROM `bayonet_news_comments` AS c ". + "LEFT OUTER JOIN `mybb_users` AS u ON u.uid = c.author_id ". + "WHERE c.news_id = '$id' ". + "ORDER BY date ASC"); + while(($row = $db->Fetch($result)) != false) + { + $comments[] = $row; + } + + $db->Free($result); + + return $comments; +} + + /** + * displayComments($data) + * Function that takes an array of comments and displays them in html + * @param data - associative array of comments from the database + */ +function displayComments($data){ + + date_default_timezone_set("America/New_York"); + OpenTable(); + ?> + +
+ + + + + +

User Comments

Add Yours
+
    + + +
  1. +
    + +
    + "; + }else{ + echo ""; + } + ?> +

    + 0){ + echo "{$comment['author']}"; + }else{ + echo "Guest"; + } + ?> + + +

    +
    + +
    + +

    + +
    + +
    +
  2. + + "; + + commentForm(); + + CloseTable(); +} + + /** + * getNumOfComments($id) + * Function that gets the number of comments a news post has + * @param id - news_id cooresponding to `bayonet_news` + */ +function getNumOfComments($id){ + + global $db; + $result = $db->Query("SELECT `comment_id` FROM `bayonet_news_comments` WHERE `news_id` = '$id'"); + + return $db->Rows($result);; +} + + /** + * getNumOfComments($id) + * Function that gets the desired news from the database and returns it as an array + * @param id - (optional) news_id cooresponding to `bayonet_news` + */ +function getNews($id = NULL){ + + global $db; + $query = "SELECT n.news_id, n.title, n.message, n.date, n.category_id, u.username AS author, c.name AS catname, c.image AS catimage ". + "FROM `bayonet_news` AS n ". + "INNER JOIN `bayonet_news_categories` AS c ON c.category_id = n.category_id ". + "LEFT OUTER JOIN `mybb_users` AS u ON u.uid = n.author_id "; + if(isset($id)){ + $query = $query."WHERE n.news_id = '$id' "; + }else{ + $query = $query."ORDER BY date DESC"; + if($limit !=NULL){ + $query = $query." LIMIT '$limit'"; + } + } + + $result = $db->Query($query); + while(($row = $db->Fetch($result)) != false) + { + $data[] = $row; + } + + $db->Free($result); + + return $data; +} + + /** + * displayNews($data) + * Function that takes an array of news and displays it as html + * @param data - associative array of news from the database + */ +function displayNews($data){ + + date_default_timezone_set("America/New_York"); + foreach($data as $news) + { + $numComments = getNumOfComments($news['news_id']); + + OpenTable(); ?> + +
    + + + + + +
    Posted by:
    +
    +
    + <?php echo $news['catname']; ?> + +
    + + + "; + } +} + +/** This was coded on Coda with a MacBook Pro **/ +function commentForm(){ + + global $db; + + if(isset($_POST['processed'])) + { + $comment = stripslashes($_POST['comment']); + $author_id = stripslashes($_POST['author']); + + echo "Author: {$author_id}
    Comment: {$comment}
    "; + echo "Your comment has been processed. Please wait.
    "; + } + + $cur_user_id = 0; //testing variable, until i get the login system working for this + + $logged_in = false; + $result = $db->Query("SELECT `username`, `avatar` FROM `mybb_users` WHERE `uid` = '$cur_user_id' LIMIT 1"); + while(($row = $db->Fetch($result)) != false) + { + $username = $row['username']; + $avatar = $row['avatar']; + $logged_in = true; + } + +?> + +

    Add Your Comment

    + +
      +
    1. + +
      + "; + }else{ + echo ""; + } + ?> +

      + +

      +
      +
      + + + + + +
      +
    2. +
    + + \ No newline at end of file -- cgit