forked from sourcefabric/Newscoop
/
do_edit.php
180 lines (160 loc) · 6.76 KB
/
do_edit.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
<?php
require_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/articles/article_common.php");
require_once($GLOBALS['g_campsiteDir']."/classes/ArticleComment.php");
if (!SecurityToken::isValid()) {
camp_html_display_error(getGS('Invalid security token!'));
exit;
}
$f_publication_id = Input::Get('f_publication_id', 'int', 0, true);
$f_issue_number = Input::Get('f_issue_number', 'int', 0, true);
$f_section_number = Input::Get('f_section_number', 'int', 0, true);
$f_language_id = Input::Get('f_language_id', 'int', 0, true);
$f_language_selected = Input::Get('f_language_selected', 'int', 0);
$f_article_number = Input::Get('f_article_number', 'int', 0);
$f_article_author = Input::Get('f_article_author', 'array', array(), true);
$f_article_author_type = Input::Get('f_article_author_type', 'array', array(), true);
$f_on_front_page = Input::Get('f_on_front_page', 'string', '', true);
$f_on_section_page = Input::Get('f_on_section_page', 'string', '', true);
$f_is_public = Input::Get('f_is_public', 'string', '', true);
$f_keywords = Input::Get('f_keywords');
$f_article_title = Input::Get('f_article_title');
$f_message = Input::Get('f_message', 'string', '', true);
$f_creation_date = Input::Get('f_creation_date');
$f_publish_date = Input::Get('f_publish_date');
$f_comment_status = Input::Get('f_comment_status', 'string', '', true);
if (isset($_REQUEST['save_and_close'])) {
$f_save_button = 'save_and_close';
$BackLink = "/$ADMIN/articles/index.php?f_publication_id=$f_publication_id&f_issue_number=$f_issue_number&f_language_id=$f_language_id&f_section_number=$f_section_number";
} else {
$f_save_button = 'save';
$BackLink = "/$ADMIN/";
}
if (!Input::IsValid()) {
camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()), $BackLink);
exit;
}
// Fetch article
$articleObj = new Article($f_language_selected, $f_article_number);
if (!$articleObj->exists()) {
camp_html_display_error(getGS('No such article.'), $BackLink);
exit;
}
$articleTypeObj = $articleObj->getArticleData();
$dbColumns = $articleTypeObj->getUserDefinedColumns(false, true);
$articleFields = array();
foreach ($dbColumns as $dbColumn) {
if ($dbColumn->getType() == ArticleTypeField::TYPE_BODY) {
$dbColumnParam = $dbColumn->getName() . '_' . $f_article_number;
} else {
$dbColumnParam = $dbColumn->getName();
}
if (isset($_REQUEST[$dbColumnParam])) {
$articleFields[$dbColumn->getName()] = trim(Input::Get($dbColumnParam));
} else {
$articleFields[$dbColumn->getName()] = null;
}
}
if (!empty($f_message)) {
camp_html_add_msg($f_message, "ok");
}
if (!$articleObj->userCanModify($g_user)) {
camp_html_add_msg(getGS("You do not have the right to change this article. You may only edit your own articles and once submitted an article can only be changed by authorized users."));
camp_html_goto_page($BackLink);
exit;
}
// Only users with a lock on the article can change it.
if ($articleObj->isLocked() && ($g_user->getUserId() != $articleObj->getLockedByUser())) {
$diffSeconds = time() - strtotime($articleObj->getLockTime());
$hours = floor($diffSeconds/3600);
$diffSeconds -= $hours * 3600;
$minutes = floor($diffSeconds/60);
$lockUser = new User($articleObj->getLockedByUser());
camp_html_add_msg(getGS('Could not save the article. It has been locked by $1 $2 hours and $3 minutes ago.', $lockUser->getRealName(), $hours, $minutes));
camp_html_goto_page($BackLink);
exit;
}
// Update the first comment if the article title has changed
if ($f_article_title != $articleObj->getTitle()) {
$firstPostId = ArticleComment::GetCommentThreadId($articleObj->getArticleNumber(), $articleObj->getLanguageId());
if ($firstPostId) {
$firstPost = new Phorum_message($firstPostId);
$firstPost->setSubject($f_article_title);
}
}
// Update the article author
if (!empty($f_article_author)) {
ArticleAuthor::OnArticleLanguageDelete($articleObj->getArticleNumber(), $articleObj->getLanguageId());
$i = 0;
foreach ($f_article_author as $author) {
$authorObj = new Author($author);
if (!$authorObj->exists() && strlen(trim($author)) > 0) {
$authorData = Author::ReadName($author);
$authorObj->create($authorData);
}
// Sets the author type selected
$author_type = $f_article_author_type[$i];
$authorObj->setType($author_type);
// Links the author to the article
$articleAuthorObj = new ArticleAuthor($articleObj->getArticleNumber(),
$articleObj->getLanguageId(),
$authorObj->getId(), $author_type);
if (!$articleAuthorObj->exists()) {
$articleAuthorObj->create();
}
$i++;
}
}
// Update the article.
$articleObj->setOnFrontPage(!empty($f_on_front_page));
$articleObj->setOnSectionPage(!empty($f_on_section_page));
$articleObj->setIsPublic(!empty($f_is_public));
$articleObj->setKeywords($f_keywords);
$articleObj->setTitle($f_article_title);
$articleObj->setIsIndexed(false);
if (!empty($f_comment_status)) {
if ($f_comment_status == "enabled" || $f_comment_status == "locked") {
$commentsEnabled = true;
} else {
$commentsEnabled = false;
}
// If status has changed, then you need to show/hide all the comments
// as appropriate.
if ($articleObj->commentsEnabled() != $commentsEnabled) {
$articleObj->setCommentsEnabled($commentsEnabled);
$comments = ArticleComment::GetArticleComments($f_article_number, $f_language_selected);
if ($comments) {
foreach ($comments as $comment) {
$comment->setStatus($commentsEnabled?PHORUM_STATUS_APPROVED:PHORUM_STATUS_HIDDEN);
}
}
}
$articleObj->setCommentsLocked($f_comment_status == "locked");
}
// Make sure that the time stamp is updated.
$articleObj->setProperty('time_updated', 'NOW()', true, true);
// Verify creation date is in the correct format.
// If not, dont change it.
if (preg_match("/\d{4}-\d{2}-\d{2}/", $f_creation_date)) {
$articleObj->setCreationDate($f_creation_date);
}
// Verify publish date is in the correct format.
// If not, dont change it.
if (preg_match("/\d{4}-\d{2}-\d{2}/", $f_publish_date)) {
$articleObj->setPublishDate($f_publish_date);
}
foreach ($articleFields as $dbColumnName => $text) {
$articleTypeObj->setProperty($dbColumnName, $text);
}
$articleObj->setIsLocked(false);
Log::ArticleMessage($articleObj, getGS('Content edited'), $g_user->getUserId(), 37);
if ($f_save_button == "save") {
camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'edit.php'), false);
} elseif ($f_save_button == "save_and_close") {
if ($f_publication_id > 0) {
camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'index.php'), false);
} else {
camp_html_goto_page("/$ADMIN/", false);
}
}
ArticleIndex::RunIndexer(3, 10, true);
?>