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/content/pwet2handler.php

1<?php
2
3class pwet2Handler extends eZContentObjectEditHandler
4{
5
6    function fetchInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage )
7    {
8
9    }
10
11    static function storeActionList()
12    {
13        return array();
14    }
15
16    function publish( $contentObjectID, $contentObjectVersion )
17    {
18        eZDebug::writeDebug( 'call pwet2Handler::publish()' );
19        $object = eZContentObject::fetch( $contentObjectID );
20        if ( self::handlePublishDate( $object ) )
21        {
22            // only clear keywords related caches if the object
23            // is really published
24            self::handleKeywords( $object );
25        }
26    }
27
28    static function handlePublishDate( $object )
29    {
30        $ini = eZINI::instance( 'pwet2.ini' );
31        $publishAttributeIdentifier = $ini->variable( 'BlogSettings', 'PublishDateTimeAttribute' );
32        $dataMap = $object->attribute( 'data_map' );
33        if ( !isset( $dataMap[$publishAttributeIdentifier] ) )
34        {
35            eZDebug::writeDebug( $object->attribute( 'name' )
36                                . ' does NOT have a "'
37                                . $publishAttributeIdentifier
38                                . '" attribute' );
39            return true;
40        }
41        $publishAttribute = $dataMap[$publishAttributeIdentifier];
42        if ( !$publishAttribute->attribute( 'has_content' ) )
43        {
44            eZDebug::writeDebug( 'Attribute "' . $publishAttributeIdentifier . '" does not have content' );
45            return true;
46        }
47        $timestamp = $publishAttribute->attribute( 'content' )->attribute( 'timestamp' );
48        if ( $timestamp > time() )
49        {
50            eZDebug::writeDebug( $timestamp . '>' . time() . ' => hiding' );
51            $nodes = $object->attribute( 'assigned_nodes' );
52            foreach( $nodes as $node )
53            {
54                eZContentObjectTreeNode::hideSubTree( $node );
55            }
56            return false;
57        }
58        return true;
59    }
60
61    static function handleKeywords( $object )
62    {
63        $ini = eZINI::instance( 'pwet2.ini' );
64        $classIdentifier = $object->attribute( 'class_identifier' );
65        if ( !in_array( $classIdentifier, $ini->variable( 'TagSettings', 'ContentClass' ) ) )
66        {
67            return ;
68        }
69        $dataMap = $object->attribute( 'data_map' );
70        if ( !isset( $dataMap['tags'] ) )
71        {
72            return ;
73        }
74        $keywordsArray = self::keywordsArray( $object );
75        $classId = $object->attribute( 'contentclass_id' );
76        foreach( $keywordsArray as $keywordString )
77        {
78            eZDebug::writeDebug( 'eZKeywordTools::storeKeywordURLAlias( ' . $keywordString . ', ' . $classId . ' )' );
79            $urlAlias = eZKeywordTools::urlAlias( $keywordString );
80            eZKeywordTools::storeKeywordURLAlias( $keywordString, $classId );
81            eZKeywordTools::clearKeywordURLAliasCache( $urlAlias );
82        }
83        eZKeywordTools::clearRSSWeblogCache();
84        eZKeywordTools::clearCloudCache();
85    }
86
87    public static function keywordsArray( eZContentObject $object )
88    {
89        $keywordsArray = array();
90        $dataMap = $object->attribute( 'data_map' );
91        if ( $dataMap['tags']->attribute( 'has_content' ) )
92        {
93            $keywordsArray = $dataMap['tags']->attribute( 'content' )->attribute( 'keywords' );
94        }
95        return $keywordsArray;
96    }
97}
98
99
100?>
101

Archive Download this file

Revision: HEAD