pwet

Sign in or create your account | Project List | Help | pwet.fr | Planet eZ Publish.fr | Bioutifoul Photos

pwet Svn Source Tree

Root/trunk/www/extension/pwet2/modules/comments/add.php

1<?php
2$NodeID = (int)$Params['NodeID'];
3$Module = $Params['Module'];
4
5function clearRSSCommentCache( $nodeID )
6{
7    $siteINI = eZINI::instance( 'site.ini' );
8    $varDir = $siteINI->variable( 'FileSettings', 'VarDir' );
9    $cacheDir = $siteINI->variable( 'FileSettings', 'CacheDir' );
10    eZFSFileHandler::fileDeleteByWildcard( $varDir . '/' . $cacheDir . '/rss/comment/*' );
11}
12
13$node = eZContentObjectTreeNode::fetch( $NodeID );
14if ( !$node && $node->canCreate() )
15{
16    eZExecution::cleanExit();
17}
18$dataMap = $node->attribute( 'data_map' );
19if ( $dataMap['enable_comments']->attribute( 'content' ) != 1 )
20{
21    eZExecution::cleanExit();
22}
23
24$siteINI = eZINI::instance();
25$http = eZHTTPTool::instance();
26$object = $node->attribute( 'object' );
27
28$pagelayout = 'design:pagelayout_blog.tpl';
29if ( $object->attribute( 'class_identifier' ) == 'photo' )
30{
31    $pagelayout = 'design:pagelayout_photo.tpl';
32}
33
34$author = '';
35$email = '';
36$url = '';
37$subject = '';
38$message = '';
39$error = array();
40$error['title'] = '';
41$error['data'] = array();
42
43
44if ( $http->hasPostVariable( 'PostComment' ) && $http->postVariable( 'PostComment' ) == '1' )
45{
46    if ( $http->hasPostVariable( 'Author' ) && trim( $http->postVariable( 'Author' ) ) != ''
47            && $http->hasPostVariable( 'Email' ) && eZMail::validate( $http->postVariable( 'Email' ) )
48            && $http->hasPostVariable( 'Subject' ) && trim( $http->postVariable( 'Subject' ) ) != ''
49            && $http->hasPostVariable( 'Message' ) && trim( $http->postVariable( 'Message' ) ) != '' )
50    {
51        $ini = eZINI::instance( 'pwet2.ini' );
52        $author = trim( $http->postVariable( 'Author' ) );
53        $email = trim( $http->postVariable( 'Email' ) );
54        $url = trim( $http->postVariable( 'URL' ) );
55        $subject = trim( $http->postVariable( 'Subject' ) );
56        $message = trim( $http->postVariable( 'Message' ) );
57        $message = preg_replace( "/\n\n[\n]+/", "\n\n", str_replace( "\r", "", $message ) );
58        $commentIdentifier = $ini->variable( 'CommentsSettings', 'CommentClassIdentifier' );
59        $class = eZContentClass::fetchByIdentifier( $commentIdentifier );
60        $db = eZDB::instance();
61        $db->begin();
62        $contentObject = $class->instantiate();
63        $contentObjectID = $contentObject->attribute( 'id' );
64        $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObjectID,
65                                                           'contentobject_version' => $contentObject->attribute( 'current_version' ),
66                                                           'parent_node' => $NodeID,
67                                                           'is_main' => 1 ) );
68        $nodeAssignment->store();
69        $dataMap = $contentObject->attribute( 'data_map' );
70        $dataMap['author']->fromString( $author );
71        $dataMap['author']->store();
72        $dataMap['url']->fromString( $url );
73        $dataMap['url']->store();
74        $dataMap['email']->fromString( $email );
75        $dataMap['email']->store();
76        $dataMap['subject']->fromString( $subject );
77        $dataMap['subject']->store();
78        $dataMap['message']->fromString( $message );
79        $dataMap['message']->store();
80        $contentObject->setAttribute( 'status', eZContentObject::STATUS_DRAFT );
81        $contentObject->setAttribute( 'modified', time() );
82        $contentObject->store();
83        $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID,
84                                                                                     'version' => $contentObject->attribute( 'current_version' ) ) );
85        $db->commit();
86        clearRSSCommentCache( $NodeID );
87        $dataMapNode = $node->attribute( 'data_map' );
88        $keywordsArray = array();
89        if ( isset( $dataMapNode['tags'] ) && $dataMapNode['tags']->attribute( 'has_content' ) )
90            $keywordsArray = $dataMapNode['tags']->attribute( 'content' )->attribute( 'keywords' );
91        $classId = $object->attribute( 'contentclass_id' );
92        foreach( $keywordsArray as $keywordString )
93        {
94            $urlAlias = eZKeywordTools::urlAlias( $keywordString );
95            eZKeywordTools::clearKeywordURLAliasCache( $urlAlias );
96        }
97        $uri = $node->attribute( 'url_alias' );
98        eZURI::transformURI( $uri, false, 'full' );
99        $Module->redirectTo( $uri );
100    }
101    else
102    {
103        // error handling
104        $error['title'] = 'Des erreurs ont été détectées';
105        if ( !$http->hasPostVariable( 'Author' ) || trim( $http->postVariable( 'Author' ) ) == '' )
106        {
107            $error['data'][] = 'Le champ <em>Nom / Pseudo</em> n\'est pas rempli';
108        }
109        $author = $http->postVariable( 'Author' );
110        if ( !$http->hasPostVariable( 'Email' ) || !eZMail::validate( $http->postVariable( 'Email' ) ) )
111        {
112            $error['data'][] = 'Le champ <em>Email</em> est mal rempli';
113        }
114        $email = $http->postVariable( 'Email' );
115        if ( !$http->hasPostVariable( 'Subject' ) || trim( $http->postVariable( 'Subject' ) ) == '' )
116        {
117            $error['data'][] = 'Le champ <em>Sujet</em> n\'est pas rempli';
118        }
119        $subject = $http->postVariable( 'Subject' );
120        if ( !$http->hasPostVariable( 'Message' ) || trim( $http->postVariable( 'Message' ) ) == '' )
121        {
122            $error['data'][] = 'Le champ <em>Message</em> n\'est pas rempli';
123        }
124        $message = $http->postVariable( 'Message' );
125        $url = $http->postVariable( 'URL' );
126    }
127}
128
129require_once 'kernel/common/template.php';
130$tpl = templateInit();
131$tpl->setVariable( 'node', $node );
132$tpl->setVariable( 'author', $author );
133$tpl->setVariable( 'email', $email );
134$tpl->setVariable( 'url', $url );
135$tpl->setVariable( 'subject', $subject );
136$tpl->setVariable( 'message', $message );
137if ( count( $error['data'] ) == 0 )
138{
139    $error = false;
140}
141$tpl->setVariable( 'error', $error );
142
143$Result['content_info'] = array( 'persistent_variable' => array(),
144                                 'object_id' => $object->attribute( 'id' ),
145                                 'node_id' => $NodeID );
146$Result['content_info']['persistent_variable'] = array( 'title_page' => "Commenter : " . $node->attribute( 'name' ),
147                                                        'meta_description' => '' );
148$Result['section_id'] = $object->attribute( 'section_id' );
149$Result['content'] = $tpl->fetch( 'design:comments/add.tpl' );
150$Result['path'] = array( array( 'text' => $siteINI->variable( 'SiteSettings', 'SiteURL' ),
151                                'url' => '/' ),
152                         array( 'text' => 'Ajout d\'un commentaire',
153                                'url' => 'comments/add/' . $NodeID ) );
154$Result['pagelayout'] = $pagelayout;
155?>
156

Archive Download this file

Revision: HEAD