eZ Publish  [4.0]
ezpackagetype.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZPackageType class
00004 //
00005 // Created on: <15-Oct-2003 13:17:04 wy>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezpackagetype.php
00032 */
00033 
00034 /*!
00035   \class eZPackageType ezpackagetype.php
00036   \ingroup eZDatatype
00037   \brief The class eZPackageType does
00038 
00039 */
00040 //include_once( 'kernel/classes/ezdatatype.php' );
00041 //include_once( 'kernel/classes/ezpackage.php' );
00042 require_once( 'kernel/common/i18n.php' );
00043 
00044 class eZPackageType extends eZDataType
00045 {
00046     const DATA_TYPE_STRING = 'ezpackage';
00047     const TYPE_FIELD = 'data_text1';
00048     const TYPE_VARIABLE = '_ezpackage_type_';
00049     const VIEW_MODE_FIELD = 'data_int1';
00050     const VIEW_MODE_VARIABLE = '_ezpackage_view_mode_';
00051 
00052     /*!
00053      Constructor
00054     */
00055     function eZPackageType()
00056     {
00057         $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', 'Package', 'Datatype name' ),
00058                            array( 'serialize_supported' => true ) );
00059     }
00060 
00061     /*!
00062      Sets the default value.
00063     */
00064     function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
00065     {
00066     }
00067 
00068     /*!
00069      \reimp
00070     */
00071     function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
00072     {
00073         return eZInputValidator::STATE_ACCEPTED;
00074     }
00075 
00076     /*!
00077      Fetches the http post var string input and stores it in the data instance.
00078     */
00079     function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
00080     {
00081         if ( $http->hasPostVariable( $base . '_ezpackage_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00082         {
00083             $data = $http->postVariable( $base . '_ezpackage_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00084 
00085             // Save in ini files if the package type is sitestyle.
00086             $classAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
00087             if ( $classAttribute->attribute( self::TYPE_FIELD ) == 'sitestyle' )
00088             {
00089                 $package = eZPackage::fetch( $data );
00090                 if ( $package )
00091                 {
00092                     $fileList = $package->fileList( 'default' );
00093                     foreach ( array_keys( $fileList ) as $key )
00094                     {
00095                         $file =& $fileList[$key];
00096                         $fileIdentifier = $file["variable-name"];
00097                         if ( $fileIdentifier == 'sitecssfile' )
00098                         {
00099                             $siteCSS = $package->fileItemPath( $file, 'default' );
00100                         }
00101                         else if ( $fileIdentifier == 'classescssfile' )
00102                         {
00103                             $classesCSS = $package->fileItemPath( $file, 'default' );
00104                         }
00105                     }
00106                     $currentSiteAccess = $http->hasPostVariable( 'CurrentSiteAccess' )
00107                                          ? $http->postVariable( 'CurrentSiteAccess' )
00108                                          : false;
00109                     $iniPath = 'settings/override';
00110                     if ( $currentSiteAccess != 'Global' and $currentSiteAccess !== false )
00111                     {
00112                         $data .= ':' . $currentSiteAccess;
00113                         $iniPath = 'settings/siteaccess/' . $currentSiteAccess;
00114                     }
00115 
00116                     $designINI = eZINI::instance( 'design.ini.append.php', $iniPath, null, false, null, true );
00117                     $designINI->setVariable( 'StylesheetSettings', 'SiteCSS', $siteCSS );
00118                     $designINI->setVariable( 'StylesheetSettings', 'ClassesCSS', $classesCSS );
00119                     $designINI->save();
00120                 }
00121             }
00122             $contentObjectAttribute->setAttribute( 'data_text', $data );
00123         }
00124         return true;
00125     }
00126 
00127     /*!
00128      Does nothing since it uses the data_text field in the content object attribute.
00129      See fetchObjectAttributeHTTPInput for the actual storing.
00130     */
00131     function storeObjectAttribute( $attribute )
00132     {
00133         $ini = eZINI::instance();
00134         // Delete compiled template
00135         $siteINI = eZINI::instance();
00136         if ( $siteINI->hasVariable( 'FileSettings', 'CacheDir' ) )
00137         {
00138             $cacheDir = $siteINI->variable( 'FileSettings', 'CacheDir' );
00139             if ( $cacheDir[0] == "/" )
00140             {
00141                 $cacheDir = eZDir::path( array( $cacheDir ) );
00142             }
00143             else
00144             {
00145                 if ( $siteINI->hasVariable( 'FileSettings', 'VarDir' ) )
00146                 {
00147                     $varDir = $siteINI->variable( 'FileSettings', 'VarDir' );
00148                     $cacheDir = eZDir::path( array( $varDir, $cacheDir ) );
00149                 }
00150             }
00151         }
00152         else if ( $siteINI->hasVariable( 'FileSettings', 'VarDir' ) )
00153         {
00154             $varDir = $siteINI->variable( 'FileSettings', 'VarDir' );
00155             $cacheDir = $ini->variable( 'FileSettings', 'CacheDir' );
00156             $cacheDir = eZDir::path( array( $varDir, $cacheDir ) );
00157         }
00158         else
00159         {
00160             $cacheDir =  eZSys::cacheDirectory();
00161         }
00162         $compiledTemplateDir = $cacheDir ."/template/compiled";
00163         eZDir::unlinkWildcard( $compiledTemplateDir . "/", "*pagelayout*.*" );
00164 
00165         // Expire template block cache
00166         //include_once( 'kernel/classes/ezcontentcachemanager.php' );
00167         eZContentCacheManager::clearTemplateBlockCacheIfNeeded( false );
00168     }
00169 
00170     /*!
00171      \reimp
00172     */
00173     function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
00174     {
00175         $packageTypeName = $base . self::TYPE_VARIABLE . $classAttribute->attribute( 'id' );
00176         if ( $http->hasPostVariable( $packageTypeName ) )
00177         {
00178             $packageTypeValue = $http->postVariable( $packageTypeName );
00179             $classAttribute->setAttribute( self::TYPE_FIELD, $packageTypeValue );
00180         }
00181         $packageViewModeName = $base . self::VIEW_MODE_VARIABLE . $classAttribute->attribute( 'id' );
00182         if ( $http->hasPostVariable( $packageViewModeName ) )
00183         {
00184             $packageViewModeValue = $http->postVariable( $packageViewModeName );
00185             $classAttribute->setAttribute( self::VIEW_MODE_FIELD, $packageViewModeValue );
00186         }
00187         return true;
00188     }
00189 
00190     /*!
00191      Returns the content.
00192     */
00193     function objectAttributeContent( $contentObjectAttribute )
00194     {
00195         $packageName = $contentObjectAttribute->attribute( "data_text" );
00196         $package = eZPackage::fetch( $packageName );
00197         return $package;
00198     }
00199 
00200     /*!
00201      Returns the meta data used for storing search indeces.
00202     */
00203     function metaData( $contentObjectAttribute )
00204     {
00205         return $contentObjectAttribute->attribute( 'data_text' );
00206     }
00207 
00208     /*!
00209      Returns the content of the string for use as a title
00210     */
00211     function title( $contentObjectAttribute, $name = null )
00212     {
00213         return $contentObjectAttribute->attribute( 'data_text' );
00214     }
00215 
00216     function hasObjectAttributeContent( $contentObjectAttribute )
00217     {
00218         return trim( $contentObjectAttribute->attribute( 'data_text' ) ) != '';
00219     }
00220 
00221     /*!
00222      \reimp
00223     */
00224     function isIndexable()
00225     {
00226         return false;
00227     }
00228 
00229     /*!
00230      \reimp
00231     */
00232     function sortKey( $contentObjectAttribute )
00233     {
00234         return strtolower( $contentObjectAttribute->attribute( 'data_text' ) );
00235     }
00236 
00237     /*!
00238      \reimp
00239     */
00240     function sortKeyType()
00241     {
00242         return 'string';
00243     }
00244 
00245     /*!
00246      \reimp
00247     */
00248     function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
00249     {
00250         $type = $classAttribute->attribute( self::TYPE_FIELD );
00251         $dom = $attributeParametersNode->ownerDocument;
00252         $typeNode = $dom->createElement( 'type' );
00253         $typeNode->appendChild( $dom->createTextNode( $type ) );
00254         $attributeParametersNode->appendChild( $typeNode );
00255     }
00256 
00257     /*!
00258      \reimp
00259     */
00260     function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
00261     {
00262         $type = $attributeParametersNode->getElementsByTagName( 'type' )->item( 0 )->textContent;
00263         $classAttribute->setAttribute( self::TYPE_FIELD, $type );
00264     }
00265 
00266     /*!
00267       \reimp
00268     */
00269     function diff( $old, $new, $options = false )
00270     {
00271         return null;
00272     }
00273 }
00274 
00275 eZDataType::register( eZPackageType::DATA_TYPE_STRING, 'eZPackageType' );
00276 
00277 ?>