-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincludes.php
107 lines (88 loc) · 3.03 KB
/
includes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
include 'blogpost.php';
include 'comment.php';
$link;
Connect();
mysql_select_db('blog');
function Connect() {
global $link;
//$link = mysql_connect('localhost', 'root', '');
$link = mysql_connect('marina.db', 'm2samuel', 'MKVoNc4');
if (!$link) die(mysql_error());
}
function Disconnect() {
global $link;
mysql_close($link);
}
function GetBlogPosts($inId=null, $inTagId=null) {
if (!empty($inId)) {
$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC");
} else if (!empty($inTagId)) {
$query = mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" . $tagID . " ORDER BY blog_posts.id DESC");
} else {
$query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
}
$postArray = array();
while ($row = mysql_fetch_assoc($query)) {
$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['author_id'], $row['date_posted']);
array_push($postArray, $myPost);
}
return $postArray;
}
function GetBlogsGivenPerson($inPersonId) {
Connect();
mysql_select_db('blog');
if(!empty($inPersonId)){
$query = mysql_query("SELECT * FROM blog_posts WHERE author_id = " . $inPersonId . " ORDER BY id DESC");
}
$postArray = array();
while ($row = mysql_fetch_assoc($query)) {
$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['author_id'], $row['date_posted'], $row['file']);
array_push($postArray, $myPost);
}
return $postArray;
}
function GetCommentsGivenPostId($postId) {
Connect();
mysql_select_db('blog');
if(!empty($postId)){
$query = mysql_query("SELECT * FROM comments WHERE post_id = " . $postId . " ORDER BY id ASC");
}
$commentArray = array();
while ($row = mysql_fetch_assoc($query)) {
$comment = new Comment($row["id"], $row['name'], $row['email'], $row['website'], $row['comment'], $row['date_posted'], $row['post_id']);
array_push($commentArray, $comment);
}
return $commentArray;
}
function GetPostGivenPostId($postId) {
Connect();
mysql_select_db('blog');
if(!empty($postId)){
$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $postId);
}
$row = mysql_fetch_assoc($query);
$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['author_id'], $row['date_posted'], $row['file']);
return $myPost;
}
function Login($username, $password) {
Connect();
mysql_select_db('blog');
$password = sha1($password);
$sql = "SELECT * FROM people WHERE username = '$username' AND password = '$password'";
$result = mysql_query($sql);
if ($person = mysql_fetch_assoc($result)) {
session_start();
$_SESSION['blog_name'] = $person['blog_name'];
$_SESSION['author_id'] = $person['id'];
$_SESSION['username'] = $username;
$_SESSION['mode'] = "client";
$success = true;
} else {
$error_msg = "Access Denied: invalid username or password";
$success = false;
}
Disconnect();
return $success;
}
?>