-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.php
274 lines (230 loc) · 8.71 KB
/
blog.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?PHP
/*
-----------------------------------------
NewLife Blogging System Version 3
-----------------------------------------
Nick F <nick@sevengraff.com>
www.sevengraff.com
-----------------------------------------
This product is distributed under the GNU
GPL liscense. A copy of that liscense
should be packaged with this product.
-----------------------------------------
*/
require_once 'config.php';
require_once 'system/functions.php';
require_once 'system/ets_sql.php';
require_once 'system/sqldb2.class.php';
require_once 'system/nlb_blog.class.php';
require_once 'system/nlb_user.class.php';
require_once 'system/nlb_config.class.php';
require_once 'system/text.class.php';
require_once 'ets.php';
$path = fetch_url_data();
$db = new sqldb2( $DB_CONFIG );
$blog = new nlb_blog( $db );
$config = new nlb_config( $db );
require_once $config->langfile();
$user = new nlb_user( $db );
$user->checkLogin();
if( isset( $path['id']) ) {
/**
* =======================================
* Show single blog & Comments
* =======================================
*/
$blog_id = $path['id'];
if( !is_numeric($blog_id) ) {
jsRedirect( script_path . 'index.php' );
}
// blog exists?
$test = $db->getArray('SELECT count(blog_id) as c FROM ' . db_blogs . ' WHERE blog_id="' . $blog_id . '";');
if( $test['c'] == 0 ) {
// bad blog id
jsRedirect( script_path . 'index.php' );
}
$q = '# GET BLOG
SELECT b.blog_id, b.author_id, b.date, b.subject, b.body, b.access, b.mood, b.custom AS custom_text, b.comments, b.html, b.smiles, b.bb, u.username AS author, u.custom AS custom_title, u.date_format
FROM ' . db_blogs . ' AS b, ' . db_users . ' AS u
WHERE b.author_id = u.user_id AND b.blog_id = "' . $blog_id . '"
ORDER BY b.date DESC
LIMIT 1 ;';
$thisblog = $db->getArray( $q );
if( $thisblog['access'] == access_news ) {
jsRedirect( build_link('index.php', array('action'=>'comment', 'id'=>$blog_id)) );
}
if( $thisblog['access'] == access_private && !$user->isLogedIn ) {
jsRedirect( script_path . 'index.php' );
}
if( $thisblog['access'] == access_private && $user->isLogedIn && $user->id != $thisblog['author_id'] ) {
jsRedirect( script_path . 'index.php' );
}
if( $thisblog['access'] == access_friendsonly && !$user->isLogedIn ) {
jsRedirect( script_path . 'index.php' );
}
if( $thisblog['access'] == access_friendsonly && $user->isLogedIn ) {
$isAFriend = false;
// get list of blog owners' friends
// This should probally be a method of nlb_users, but I only have to do this once...
$f = $db->query('SELECT friend_id FROM ' . db_friends . ' WHERE owner_id=' . $thisblog['author_id'] . ';');
while( $row = mysql_fetch_assoc( $f ) ) {
if( $row['friend_id'] == $user->id ) {
$isAFriend = true;
break;
}
}
if( !$isAFriend ) {
// Can't see this blog :(
jsRedirect( script_path . 'index.php' );
}
}
$blog->setData( $thisblog );
$blog->setDate( $thisblog['date_format'] );
if( $user->isLogedIn ) {
$blog->setDateOffset( $config->get('server_timezone'), $user->get('timezone') );
}
$USERID = $blog->data['author_id'];
// check for avatars
$avatar = $db->getArray('SELECT file, isCustom FROM ' . db_avatars . ' WHERE owner_id=' . $USERID . ' AND type=1;');
if( !empty( $avatar ) ) {
if( $avatar['isCustom'] == 1 ) {
$file = 'avatars/';
} else {
$file = 'avatars/default/';
}
$file .= $avatar['file'];
$ets->avatar_url = script_path . $file;
$ets->avatar = '<img src="' . script_path . $file . '" />';
}
$ets->username = $thisblog['author'];
$ets->blog = $blog->format( false, $user, $l['edit']);
$ets->list_comments = $blog->getComments( $blog_id, $config->get('comment_date_format'), $l['guest'], $user, $l['edit'] );
if( $blog->data['comments'] != -1 ) {
$ets->view_comments = true;
} else {
$ets->view_comments = false;
}
// form to add comment
if( $user->isAllowed('comment') || !$user->isLogedIn ) {
$name = $user->isLogedIn ? $user->get('username') : $l['guest'];
$submit_text = sprintf($l['comment_submit'], $name);
$ets->add_comment = '
<script type="text/javascript">
function insertWindow( gotopage ) {
window.open( gotopage, \'newwindow\',\'toolbar=0,location=0,directories=0,menuBar=0,resizable=1,scrollbars=yes,width=400,height=500,left=20,top=20\');
}
</script>
<form method="post" action="' . script_path . 'addcomment.php" name="new_entry">
<input type="hidden" name="parent" value="' . $blog->data['blog_id'] . '">
<textarea name="body" class="nlb_add_comment"></textarea> <br>
<input class="nlb_add_comment" type="submit" value="' . $submit_text . '">
</form>';
$ets->link_smiles = $l['link_smiles'];
$ets->link_bbcode = $l['link_bbcode'];
} else {
$ets->add_comment = $l['disallow-comments'];
}
$ets->USER_TEMPLATE = serialize( array( 'type' => 'blog', 'user_id' => $blog->data['author_id'] ) );
$OUTTER = serialize( array( 'type' => 'outter' ) );
} else if( isset( $path['user'] ) ) {
/**
* =======================================
* Show page of blogs
* =======================================
*/
$USERID = $path['user'];
if( !is_numeric($USERID) ) {
jsRedirect( script_path . 'index.php' );
}
// user exists?
$test = $db->getArray('SELECT count(user_id) as c FROM ' . db_users . ' WHERE user_id="' . $USERID . '";');
if( $test['c'] == 0 ) {
// bad user id
jsRedirect( script_path . 'index.php' );
}
$u = new nlb_user( $db, $USERID );
$page = 0;
if( isset( $path['page']) ) {
$page = $path['page'];
}
$perpage = $u->get('perpage');
$page_start = $page * $perpage;
// get count of all the blogs
$total = $u->get('blog_count');
// setup some vars for the query
$limit = $page_start . ', ' . $perpage;
// check to see what blogs we can view
$access_in = access_public; // default is public blogs only.
if( $user->isLogedIn ) {
// if we are the author, we can see all
if( $user->id == $u->id ) {
$access_in = access_public . ', ' . access_private . ', ' . access_friendsonly;
}
// are we a friend?
if( $u->areFriends( $user->id ) ) {
$access_in = access_public . ', ' . access_friendsonly;
}
}
// get the blogs
$all = $db->getAllArray('# Get page of blogs
SELECT b.blog_id, b.author_id, b.date, b.subject, b.body, b.access,
b.mood, b.custom AS custom_text, b.comments, b.html, b.smiles,
b.bb, u.username AS author, u.custom AS custom_title, u.date_format
FROM ' . db_blogs . ' AS b, ' . db_users . ' AS u
WHERE u.user_id = ' . $USERID . ' AND b.author_id = u.user_id AND b.access IN(' . $access_in . ')
ORDER BY b.date DESC
LIMIT ' . $limit . ';');
// timezone settings
if( $user->isLogedIn ) {
$blog->setDateOffset( $config->get('server_timezone'), $user->get('timezone') );
}
// check for avatars
$avatar = $db->getArray('SELECT file, isCustom FROM ' . db_avatars . ' WHERE owner_id=' . $USERID . ' AND type=1;');
if( !empty( $avatar ) ) {
if( $avatar['isCustom'] == 1 ) {
$file = 'avatars/';
} else {
$file = 'avatars/default/';
}
$file .= $avatar['file'];
$ets->avatar_url = script_path . $file;
$ets->avatar = '<img src="' . script_path . $file . '" />';
}
// parse the blogs
$blog->setDate( $u->get('date_format') );
foreach( $all as $item ) {
$ets->blog[] = $blog->format( $item, $user, $l['edit'] );
}
// setup tags for next/prev pages.
if( $page > 0 ) {
$ets->url_page_prev = build_link('blog.php', array('page'=>($page-1), 'user'=>$USERID));
}
if( $total > ($page_start + $perpage) ) {
$ets->url_page_next = build_link('blog.php', array('page'=>($page+1), 'user'=>$USERID));
}
$ets->username = $u->get('username');
$ets->USER_TEMPLATE = serialize( array( 'type' => 'blog', 'user_id' => $USERID ) );
$OUTTER = serialize( array( 'type' => 'outter' ) );
} else {
/**
* =======================================
* Deal with missing data
* =======================================
*/
if( $user->isLogedIn ) {
// no data specified, redirecting to users blog
jsRedirect( build_link('blog.php', array('user'=>$this->id)) );
} else {
// no data & not loged in, return to homepage
jsRedirect( script_path . 'index.php');
}
}
// setup some standard tags
$uid_array = array('user'=>$USERID);
$ets->url_home = build_link('blog.php', $uid_array);
$ets->url_profile = build_link('profile.php', $uid_array);
$ets->url_friends = build_link('friends.php', $uid_array);
$ets->rss_url = build_link('rss.php', array('id'=>$USERID));
$ets->rss_img = '<a href="' . $ets->rss_url . '"><img src="' . script_path . 'xml.gif" border="0" /></a>';
printt( $ets, $OUTTER );
?>