[go: up one dir, main page]

Menu

[r63]: / trunk / blog.php  Maximize  Restore  History

Download this file

194 lines (177 with data), 8.0 kB

  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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
session_start();
include_once('inc/config.php');
mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_database);
include_once('inc/util.inc');
include_once('inc/blog_class.php');
// Setup Theme
$modules = getModules();
$pageTitle = 'Blog';
$curPage = 'blog';
$theme = getTheme();
include_once($theme.'header.php');
$blog = new Blog();
$show_posts = true;
$message = '';
$blog->displayMenu();
//-------------------------------------------------------------------------------------------------
// Show Add Forms
//-------------------------------------------------------------------------------------------------
if (isset($_GET['add'])) {
// Must be admin
if (isLoggedInAdmin()) {
// Post
if ($_GET['add'] == 'post') {
$show_posts = false;
$blog->displayAddPostForm();
}
// Category
if ($_GET['add'] == 'category') {
$show_posts = false;
$blog->displayAddCategoryForm();
}
}
}
//-------------------------------------------------------------------------------------------------
// Show Edit Post Form
//-------------------------------------------------------------------------------------------------
if (isset($_GET['edit'])) {
// Must be admin
if (isLoggedInAdmin()) {
$show_posts = false;
$id = (int)$_GET['edit'];
$blog->displayEditPostForm($id);
}
}
//-------------------------------------------------------------------------------------------------
// Edit post
//-------------------------------------------------------------------------------------------------
if (isset($_POST['submit-edit'])) {
// Must be admin
if (isLoggedInAdmin()) {
$_POST['title'] = trim($_POST['title']);
if (strlen($_POST['title']) > 0 || strlen($_POST['post']) > 0) {
$title = stripMagicQuotes($_POST['title']);
$title = escape_string($title);
$post = stripMagicQuotes($_POST['post']);
$post = escape_string($post);
$sql = "UPDATE `sam_blog`
SET `title` = '$title',
`post` = '$post',
`category` = '".escape_string($_POST['category'])."'
WHERE `id` = '".escape_string($_POST['id'])."'";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$message = array('ok', _('Post Updated'));
} else {
$message = array('error', _('Title and Post are required.'));
$show_posts = false;
$blog->displayAddPostForm($message);
}
}
}
//-------------------------------------------------------------------------------------------------
// Delete post
//-------------------------------------------------------------------------------------------------
if (isset($_GET['delete'])) {
// Must be admin
if (isLoggedInAdmin() && ctype_digit($_GET['delete'])) {
$sql = "DELETE FROM `sam_blog` WHERE `id` = ".$_GET['delete']." LIMIT 1";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$message = array('ok', _('Post Deleted'));
}
}
//-------------------------------------------------------------------------------------------------
// Add new category
//-------------------------------------------------------------------------------------------------
if (isset($_POST['submit-category'])) {
// Must be admin
if (isLoggedInAdmin()) {
$_POST['name'] = trim($_POST['name']);
if (strlen($_POST['name']) > 0) {
$name = stripMagicQuotes($_POST['name']);
$name = escape_string($name);
$date = gmdate('Y-m-d H:i:s');
$sql = "INSERT INTO `sam_category` (
`name`, `type`, `date`
) VALUES (
'$name', 'blog', '$date'
)";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$message = array('ok', _('Category Added'));
} else {
$message = array('error', _('Name is required.'));
$show_posts = false;
$blog->displayAddCategoryForm($message);
}
}
}
//-------------------------------------------------------------------------------------------------
// Add new post
//-------------------------------------------------------------------------------------------------
if (isset($_POST['submit-post'])) {
// Must be admin
if (isLoggedInAdmin()) {
$_POST['title'] = trim($_POST['title']);
if (strlen($_POST['title']) > 0 || strlen($_POST['post']) > 0) {
$title = stripMagicQuotes($_POST['title']);
$title = escape_string($title);
$post = stripMagicQuotes($_POST['post']);
$post = escape_string($post);
$date = gmdate('Y-m-d H:i:s');
$sql = "INSERT INTO `sam_blog` (
`title`, `post`, `category`, `user`, `date`
) VALUES (
'$title', '$post', '".escape_string($_POST['category'])."', '".escape_string($_SESSION['login_id'])."', '$date'
)";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$message = array('ok', _('Post Added'));
} else {
$message = array('error', _('Title and Post are required.'));
$show_posts = false;
$blog->displayAddPostForm($message);
}
}
}
//-------------------------------------------------------------------------------------------------
// Add Comment
//-------------------------------------------------------------------------------------------------
if (isset($_POST['submit-comment'])) {
$comment = stripMagicQuotes($_POST['comment']);
$comment = escape_string($comment);
$date = gmdate('Y-m-d H:i:s');
$sql = "INSERT INTO `sam_comment` (
`type`, `type_id`, `user`, `comment`, `date`
) VALUES (
'blog', '".escape_string($_POST['id'])."', '".escape_string($_POST['user'])."', '$comment', '$date'
)";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
}
//-------------------------------------------------------------------------------------------------
// Show Category List
//-------------------------------------------------------------------------------------------------
if (isset($_GET['category'])) {
$show_posts = false;
$category = escape_string($_GET['category']);
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$blog->displaySideMenu();
$blog->displayPostsByCategory($page, $category, $message);
}
//-------------------------------------------------------------------------------------------------
// Show single post
//-------------------------------------------------------------------------------------------------
if (isset($_GET['id'])) {
$show_posts = false;
$id = (int)$_GET['id'];
$blog->displaySideMenu();
$blog->displayPost($id);
}
//-------------------------------------------------------------------------------------------------
// Show latest posts
//-------------------------------------------------------------------------------------------------
if ($show_posts) {
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$blog->displaySideMenu();
$blog->displayLatestBlogPosts($page, $message);
}
include($theme.'footer.php');