Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

user/articleedit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: articleedit.php 9457 2002-04-23 15:32:42Z bf $
5 //
6 // Created on: <18-Oct-2000 15:04:39 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezlocale.php" );
30 // include_once( "classes/ezcachefile.php" );
31
32 // include_once( "ezuser/classes/ezuser.php" );
33 // include_once( "classes/ezhttptool.php" );
34
35 // include_once( "ezarticle/classes/ezarticletool.php" );
36 // include_once( "ezarticle/classes/ezarticlecategory.php" );
37 // include_once( "ezarticle/classes/ezarticle.php" );
38 // include_once( "ezarticle/classes/ezarticlegenerator.php" );
39 // include_once( "ezarticle/classes/ezarticlerenderer.php" );
40 // include_once( "ezuser/classes/ezobjectpermission.php" );
41 // include_once( "ezuser/classes/ezauthor.php" );
42 // include_once( "ezxml/classes/ezxml.php" );
43
44 // include_once( "ezbulkmail/classes/ezbulkmail.php" );
45 // include_once( "ezbulkmail/classes/ezbulkmailcategory.php" );
46
47 $ini =& eZINI::instance( 'site.ini' );
48
49 $PublishNoticeReceiver = $ini->variable( "eZArticleMain", "PublishNoticeReceiver" );
50 $PublishNoticeSender = $ini->variable( "eZArticleMain", "PublishNoticeSender" );
51
52 $session =& eZSession::globalSession();
53
54 // insert a new article in the database
55 if ( ( $Action == "Insert" ) || ( $Action == "Update" ) )
56 {
57 $user =& eZUser::currentUser();
58
59 $article = new eZArticle( $ArticleID );
60 $article->setName( $Name );
61
62 $article->setAuthor( $user );
63
64 $generator = new eZArticleGenerator();
65
66 $contents = $generator->generateXML( $Contents );
67 $article->setContents( $contents );
68
69 $article->setPageCount( $generator->pageCount() );
70
71
72 // check if author exists in the database, else create
73 $author = new eZAuthor();
74 if ( !$author->getByName( trim( $AuthorText ) ) )
75 {
76 $author = new eZAuthor( );
77 $author->setName( $AuthorText );
78 $author->store();
79
80 $article->setContentsWriter( $author );
81 }
82 else
83 {
84 $article->setContentsWriter( $author );
85 }
86
87 $article->setLinkText( $LinkText );
88 $article->setStartDate( (new eZDateTime())->timeStamp(true) );
89 $article->setStopDate( (new eZDateTime())->timeStamp(true) );
90 $article->store(); // to get ID
91
92 // remove from category if update
93 if ( $Action == "Update" )
94 $article->removeFromCategories();
95
96 // add to categories
97 $category = new eZArticleCategory( $CategoryIDSelect );
98 $category->addArticle( $article );
99
100 $article->setCategoryDefinition( $category );
101
102 // Which group should a user-published article be set to?
103 eZObjectPermission::setPermission( -1, $article->id(), "article_article", 'w' );
104 eZObjectPermission::setPermission( -1, $article->id(), "article_article", 'r' );
105
106 // user-submitted articles are never directly published
107
108
109 // check if the contents is parseable
110 if ( eZXML::domTree( $contents ) )
111 {
112 // generate keywords
113 $contents = strip_tags( $contents );
114 $contents = preg_replace( "#\n#", "", $contents );
115 $contents_array =& preg_split( "/ /", $contents );
116 $contents_array = array_unique( $contents_array );
117
118 $keywords = "";
119 foreach ( $contents_array as $word )
120 {
121
122 $keywords .= $word . " ";
123 }
124
125 $article->setKeywords( $keywords );
126 $article->store();
127
128 // Go to insert item..
129 if ( isset( $AddItem ) )
130 {
131 switch( $ItemToAdd )
132 {
133 case "Image":
134 {
135 $session->setVariable( "ArticleEditID", $article->id() );
136 $articleID = $article->id();
137 // add images
138 eZHTTPTool::header( "Location: /article/articleedit/imagelist/$articleID/" );
139 exit();
140 }
141 break;
142 case "File":
143 {
144 $session->setVariable( "ArticleEditID", $article->id() );
145 $articleID = $article->id();
146 // add files
147 eZHTTPTool::header( "Location: /article/articleedit/filelist/$articleID/" );
148 exit();
149 }
150 break;
151 }
152 }
153
154 if ( $ini->variable( "eZArticleMain", "CanUserPublish" ) == "enabled" )
155 {
156 $article->setIsPublished( true );
157
158 eZArticleTool::deleteCache( $articleID, $CategoryIDSelect, array( $CategoryIDSelect ) );
159 eZArticleTool::notificationMessage( $article );
160 }
161 else
162 {
163 $article->setIsPublished( false );
164 }
165
166 $article->store();
167
168 $session->setVariable( "ArticleEditID", "" );
169 eZHTTPTool::header( "Location: /article/archive/$CategoryIDSelect/" );
170 exit();
171 }
172 else
173 {
174 $Action = "New";
175 $ErrorParsing = true;
176 }
177 }
178
179
180 if ( $Action == "Cancel" )
181 {
182 $article = new eZArticle( $ArticleID );
183
184 $category = $article->categoryDefinition( );
185
186 if ( $category )
187 {
188 $categoryID = $category->id();
189 }
190
191 eZHTTPTool::header( "Location: /article/archive/$categoryID/" );
192 exit();
193 }
194
195
196 $Language = $ini->variable( "eZArticleMain", "Language" );
197
198 // init the section
199 if ( isset ($SectionIDOverride) )
200 {
201 // include_once( "ezsitemanager/classes/ezsection.php" );
202
203 $sectionObject =& eZSection::globalSectionObject( $SectionIDOverride );
204 $sectionObject->setOverrideVariables();
205 }
206
207 $t = new eZTemplate( "kernel/ezarticle/user/" . $ini->variable( "eZArticleMain", "TemplateDir" ),
208 "kernel/ezarticle/user/intl/", $Language, "articleedit.php" );
209
210 $t->setAllStrings();
211
212 $t->set_file( array(
213 "article_edit_page_tpl" => "articleedit.tpl"
214 ) );
215
216 $t->set_block( "article_edit_page_tpl", "value_tpl", "value" );
217 $t->set_block( "article_edit_page_tpl", "error_message_tpl", "error_message" );
218
219
220 if ( isset( $ErrorParsing ) && $ErrorParsing == true )
221 {
222 $t->parse( "error_message", "error_message_tpl" );
223 }
224 else
225 {
226 $t->set_var( "error_message", "" );
227 }
228
229 if ( $Action == "New" )
230 {
231 $user =& eZUser::currentUser();
232 $t->set_var( "author_text", $user->firstName() . " " . $user->lastName());
233 $catDefID = false;
234 $Name = false;
235 $ContentsSet = array();
236 $ContentsSet[0] = false;
237 $ContentsSet[1] = false;
238 $AuthorText = false;
239 $LinkText = false;
240 }
241
242 if ( $Action == "Edit" )
243 {
244 $AuthorText = false;
245 $LinkText = false;
246 $NameSet = false;
247 $ContentsSet = array();
248 $ContentsSet[0] = false;
249 $ContentsSet[1] = false;
250 }
251
252 $t->set_var( "article_id", "" );
253 $t->set_var( "article_name", stripslashes( $Name ) );
254 $t->set_var( "article_contents_0", stripslashes( $ContentsSet[0] ) );
255 $t->set_var( "article_contents_1", stripslashes( $ContentsSet[1] ) );
256 $t->set_var( "author_text", stripslashes( $AuthorText ) );
257 $t->set_var( "link_text", stripslashes( $LinkText ) );
258
259 $t->set_var( "action_value", "insert" );
260
261 if ( $Action == "New" )
262 {
263 $user =& eZUser::currentUser();
264 $t->set_var( "author_text", $user->firstName() . " " . $user->lastName());
265 }
266
267 //pBo modified this: assign the current articleID as suggested by Arne Schirmacher
268 //$articleID = $session->variable( "ArticleEditID" );
269 $articleID = $ArticleID;
270 //end PBo mod
271
272 if ( $Action == "Edit" )
273 {
274 $article = new eZArticle( $articleID );
275
276 $generator = new eZArticleGenerator();
277
278 $contentsArray = $generator->decodeXML( $article->contents() );
279
280 $catDef =& $article->categoryDefinition();
281 $catDefID = $catDef->id();
282
283 $user =& eZUser::currentUser();
284
285 //PBo modification
286 //Check if the id of the author matches the current logged in user
287 //This does refer to the userid who submitted the article, not the possibel "assigned author"
288 //as can be done through the admin interface
289 //If there is no match, the scripts dies which is still al little harch
290
291 $editOwnArticle=$ini->variable( "eZArticleMain", "UserEditOwnArticle" );
292 if (!eZArticle::isAuthor($user, $article->id()) || $editOwnArticle != "enabled" )
293 {
294 echo "You " . $user->id() . " are not the author" . $article->author(false) . " or user side editing is disabled , bye!<br />";
295 die("THE END");
296
297 }
298 //End PBo mod
299
300 $t->set_var( "author_text", $user->firstName() . " " . $user->lastName());
301
302 $t->set_var( "article_name", $article->name() );
303
304 $i=0;
305 foreach ( $contentsArray as $content )
306 {
307 if ( !isset( $Contents[$i] ) )
308 {
309 $t->set_var( "article_contents_$i", htmlspecialchars( $content ) );
310 }
311 $i++;
312 }
313 $t->set_var( "article_keywords", $article->manualKeywords() );
314
315 $t->set_var( "link_text", $article->linkText() );
316
317 $t->set_var( "action_value", "update" );
318 $t->set_var( "article_id", $articleID );
319 }
320
321
322 // category select
323 $tree = new eZArticleCategory();
324 $treeArray = $tree->getTree();
325
326 foreach ( $treeArray as $catItem )
327 {
328 if( eZObjectPermission::hasPermission( $catItem[0]->id(), "article_category", 'w', eZUser::currentUser() ) == true )
329 {
330 $t->set_var( "selected", "" );
331
332 if ( $catDefID == $catItem[0]->id() )
333 {
334 $t->set_var( "selected", "selected" );
335 }
336
337 $t->set_var( "option_value", $catItem[0]->id() );
338 $t->set_var( "option_name", $catItem[0]->name() );
339
340 if ( $catItem[1] > 0 )
341 $t->set_var( "option_level", str_repeat( "&nbsp;", $catItem[1] ) );
342 else
343 $t->set_var( "option_level", "" );
344
345 $t->parse( "value", "value_tpl", true );
346 }
347 }
348
349 if ( isset ($SectionIDOverride) ) $t->set_var( "section_id", $SectionIDOverride );
350
351 $t->pparse( "output", "article_edit_page_tpl" );
352
353 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
$author
$author
Definition: admin/articleedit.php:834
$sectionObject
$sectionObject
Definition: articleheaderlist.php:49
$article
$article
Definition: articlelog.php:45
$editOwnArticle
$editOwnArticle
Definition: articleview.php:636
eZArticleCategory
Definition: ezarticlecategory.php:45
eZArticleGenerator
Definition: ezarticlegenerator.php:40
eZArticleTool\notificationMessage
static notificationMessage(&$article)
Definition: ezarticletool.php:136
eZArticleTool\deleteCache
static deleteCache( $ArticleID, $CategoryID, $CategoryArray)
Definition: ezarticletool.php:52
eZArticle
Definition: ezarticle.php:82
eZArticle\isAuthor
static isAuthor( $user, $articleID)
Definition: ezarticle.php:2672
eZAuthor
Definition: ezauthor.php:40
eZDateTime
Definition: ezdatetime.php:55
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZObjectPermission\hasPermission
static hasPermission( $objectID, $moduleTable, $permission, $user=false)
Definition: ezobjectpermission.php:76
eZObjectPermission\setPermission
static setPermission( $group, $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:236
eZSection\globalSectionObject
static & globalSectionObject( $sectionID)
Definition: ezsection.php:366
eZSession\globalSession
static & globalSession( $id="", $fetch=true)
Definition: kernel/ezsession/classes/ezsession.php:614
eZTemplate
Definition: eztemplate.php:107
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZXML\domTree
static domTree( $xmlDoc, $params=array())
Definition: ezxml.php:60
$Action
$Action
Definition: companysearch.php:80
$ArticleID
$ArticleID
Definition: export.php:48
$contents
$contents
Definition: ezarticle/user/extendedsearch.php:52
$content
$content
Definition: ezimagecatalogue/admin/filedownload.php:53
exit
exit
Definition: folder.php:81
$Name
$Name
Definition: polledit.php:250
$categoryID
else $categoryID
Definition: productview.php:66
$user
$user
Definition: user/adlist.php:39
$articleID
if( $Action=="New") $articleID
Definition: user/articleedit.php:269
$treeArray
$treeArray
Definition: user/articleedit.php:324
$PublishNoticeSender
$PublishNoticeSender
Definition: user/articleedit.php:50
$t
if(isset($SectionIDOverride)) $t
Definition: user/articleedit.php:207
$ini
$ini
Definition: user/articleedit.php:47
$tree
if( $Action=="Edit") $tree
Definition: user/articleedit.php:323
$PublishNoticeReceiver
$PublishNoticeReceiver
Definition: user/articleedit.php:49
$session
$session
Definition: user/articleedit.php:52
$Language
if(( $Action=="Insert")||( $Action=="Update")) if( $Action=="Cancel") $Language
Definition: user/articleedit.php:196
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.