-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewdiscussionpost.php
170 lines (141 loc) · 7.03 KB
/
newdiscussionpost.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
<?php
/*
Copyright (C) 2008-2009 Gilles Dubuc (www.kouiskas.com - [email protected])
Page where users can post a reply to a specific discussion thread
*/
require_once(dirname(__FILE__).'/entities/community.php');
require_once(dirname(__FILE__).'/entities/communitymembership.php');
require_once(dirname(__FILE__).'/entities/discussionpost.php');
require_once(dirname(__FILE__).'/entities/discussionpostlist.php');
require_once(dirname(__FILE__).'/entities/discussionthread.php');
require_once(dirname(__FILE__).'/entities/user.php');
require_once(dirname(__FILE__).'/entities/userpaging.php');
require_once(dirname(__FILE__).'/utilities/page.php');
require_once(dirname(__FILE__).'/utilities/string.php');
$user = User::getSessionUser();
$page = new Page('DISCUSS', 'COMMUNITIES', $user);
$page->addJavascript('NEW_DISCUSSION_POST');
$page->startHTML();
$nid = isset($_REQUEST['nid'])?$_REQUEST['nid']:null;
$oid = isset($_REQUEST['oid'])?$_REQUEST['oid']:null;
if ($oid !== null) try {
$replied_to = DiscussionPost::get($oid);
} catch (DiscussionPostException $e) {
$oid = null;
}
try {
$thread = DiscussionThread::get($nid);
$subtitle = '<a href="'.$PAGE['DISCUSSION_THREAD'].'?lid='.$user->getLid().'&nid='.$nid.'">'.String::htmlentities($thread->getTitle()).'</a>';
$xid = $thread->getXid();
if ($xid === null) {
$title = 'General discussion';
$backlink = $PAGE['BOARD'].'?lid='.$user->getLid();
$page->setTitle('<translate id="NEW_DISCUSSION_POST_PAGE_TITLE_GENERAL">Write a new discussion post in the "<string value="'.String::fromaform($thread->getTitle()).'"/>" discussion of the General Discussion board on inspi.re</translate>');
} else {
$community = Community::get($xid);
$name = String::fromaform($community->getName());
if ($xid == 267) {
$title = '<translate id="PRIZE_COMMUNITY_NAME">'.$community->getName().'</translate>';
} else {
$title = $name;
}
$backlink = $PAGE['BOARD'].'?lid='.$user->getLid().'&xid='.$xid;
$page->setTitle('<translate id="NEW_DISCUSSION_POST_PAGE_TITLE">Write a new discussion post in the "<string value="'.String::fromaform($thread->getTitle()).'"/>" discussion of the <string value="'.$name.'"/> community on inspi.re</translate>');
}
if (isset($community) && $user->getUid() != $community->getUid())
$membership = CommunityMembership::get($xid, $user->getUid());
} catch (Exception $e) {
header('Location: '.$PAGE['DISCUSS'].'?lid='.$user->getLid());
exit(0);
}
echo '<div id="thread_title">';
echo '<a href="'.$backlink.'">';
echo $title;
echo '</a>';
echo '<div id="thread_subtitle">'.$subtitle.'</div>';
echo '</div> <!-- thread_title -->';
if ($oid !== null) {
$all_posts = array();
try {
$all_posts = DiscussionPostList::getByNidAndStatus($nid, $DISCUSSION_POST_STATUS['POSTED']);
} catch (DiscussionPostListException $e) {
}
if ($user->getStatus() == $USER_STATUS['UNREGISTERED']) {
try {
$anonymous_posts = DiscussionPostList::getByUidAndStatus($user->getUid(), $DISCUSSION_POST_STATUS['ANONYMOUS']);
foreach ($anonymous_posts as $anonymous_oid => $anonymous_timestamp) {
$anonymous_post = DiscussionPost::get($anonymous_oid);
if ($anonymous_post->getNid() == $nid) $all_posts[$anonymous_oid] = $anonymous_timestamp;
}
} catch (DiscussionPostListException $e) {
}
}
asort($all_posts);
$amount_per_page = UserPaging::getPagingValue($user->getUid(), 'DISCUSSION_THREAD_POSTS');
$key = array_search($oid, array_keys($all_posts));
if ($key === false) $key = 0;
$page_offset = ceil(($key + 1) / $amount_per_page);
$post = DiscussionPost::get($oid);
$reply_to_oid = $post->getReplyToOid();
if ($reply_to_oid !== null)
$replied_to_replied_to = DiscussionPost::get($reply_to_oid);
echo '<div id="post_'.$oid.'" class="listing_item">';
echo '<div class="listing_thumbnail">';
echo '<profile_picture uid="'.$post->getUid().'" size="small"/>';
echo '</div> <!-- listing_thumbnail -->';
echo '<div class="listing_header listing_header_thumbnail_margin">';
if ($reply_to_oid === null) {
echo '<translate id="DISCUSSION_THREAD_HEADER">';
echo '<duration value="'.(time() - $post->getCreationTime()).'" /> ago <user_name uid="'.$post->getUid().'"/> wrote';
echo '</translate>';
} else {
$key = array_search($reply_to_oid, array_keys($all_posts));
if ($key === false) $key = 0;
$reply_page_offset = ceil(($key + 1) / $amount_per_page);
$reply_link = $PAGE['DISCUSSION_THREAD'].'?lid='.$user->getLid().'&nid='.$nid.'&page='.$reply_page_offset.'&scrollto=post_'.$reply_to_oid;
echo '<translate id="DISCUSSION_THREAD_HEADER_REPLY_TO">';
echo '<duration value="'.(time() - $post->getCreationTime()).'" /> ago, in reply to <a href="'.$reply_link.'">this message</a> from <user_name uid="'.$replied_to_replied_to->getUid().'"/>, <user_name uid="'.$post->getUid().'"/> wrote';
echo '</translate>';
}
echo '</div> <!-- listing_header -->';
echo '<div class="post_text">';
echo String::fromaform($post->getText());
echo '</div> <!-- post_text -->';
echo '</div> <!-- listing_item -->';
echo '<form id="new_post" method="post" action="'.$REQUEST['NEW_DISCUSSION_POST'].'?nid='.$nid.($oid !== null?'&oid='.$oid:'').'">';
echo '<div class="listing_item">';
echo '<div class="listing_thumbnail">';
echo '<profile_picture uid="'.$user->getUid().'" size="small"/>';
echo '</div> <!-- listing_thumbnail -->';
echo '<div class="listing_header listing_header_thumbnail_margin">';
echo '<translate id="NEW_DISCUSSION_POST_HEADER_REPLY_TO">';
echo 'In reply to <a href="'.$PAGE['DISCUSSION_THREAD'].'?lid='.$user->getLid().'&nid='.$nid.($page_offset > 1?'&page='.$page_offset:'').'&scrollto=post_'.$oid.'">this post</a> from <user_name uid="'.$replied_to->getUid().'"/>, <user_name uid="'.$user->getUid().'"/> wrote';
echo '</translate>';
} else {
echo '<form id="new_post" method="post" action="'.$REQUEST['NEW_DISCUSSION_POST'].'?nid='.$nid.($oid !== null?'&oid='.$oid:'').'">';
echo '<div class="listing_item">';
echo '<div class="listing_thumbnail">';
echo '<profile_picture uid="'.$user->getUid().'" size="small"/>';
echo '</div> <!-- listing_thumbnail -->';
echo '<div class="listing_header listing_header_thumbnail_margin">';
echo '<translate id="NEW_DISCUSSION_POST_HEADER">';
echo '<user_name uid="'.$user->getUid().'"/> wrote';
echo '</translate>';
}
echo '</div> <!-- listing_header -->';
echo '<textarea minimum="2" maximum="5000" id="text" name="text" minimumrows="8" autoexpand="true" class="new_post_text">';
echo '</textarea> <!-- new_post_text -->';
echo '<div id="send_post" class="post_action">';
echo '<a href="javascript:submitPost()"><translate id="NEW_DISCUSSION_POST_SUBMIT">Submit this post</translate></a>';
echo '</div> <!-- post_action -->';
echo '</div> <!-- post -->';
echo '<div id="length_errors">';
echo '<span class="length_error" id="post_too_short"><translate id="NEW_DISCUSSION_POST_TOO_SHORT">Post is too short</translate></span>';
echo '<span class="length_error" id="post_too_long" style="display:none"><translate id="NEW_DISCUSSION_POST_TOO_LONG">Post is too long</translate></span>';
echo '</div>';
echo '</form>';
?>
<?php
$page->endHTML();
$page->render();
?>