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