eZ Publish  [4.1]
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.1.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2009 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
00032 */
00033 
00034 /*!
00035   \class eZPackageType ezpackagetype.php
00036   \ingroup eZDatatype
00037   \brief The class eZPackageType does
00038 
00039 */
00040 require_once( 'kernel/common/i18n.php' );
00041 
00042 class eZPackageType extends eZDataType
00043 {
00044     const DATA_TYPE_STRING = 'ezpackage';
00045     const TYPE_FIELD = 'data_text1';
00046     const TYPE_VARIABLE = '_ezpackage_type_';
00047     const VIEW_MODE_FIELD = 'data_int1';
00048     const VIEW_MODE_VARIABLE = '_ezpackage_view_mode_';
00049 
00050     /*!
00051      Constructor
00052     */
00053     function eZPackageType()
00054     {
00055         $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', 'Package', 'Datatype name' ),
00056                            array( 'serialize_supported' => true ) );
00057     }
00058 
00059     /*!
00060      Sets the default value.
00061     */
00062     function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
00063     {
00064     }
00065 
00066     function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
00067     {
00068         return eZInputValidator::STATE_ACCEPTED;
00069     }
00070 
00071     /*!
00072      Fetches the http post var string input and stores it in the data instance.
00073     */
00074     function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
00075     {
00076         if ( $http->hasPostVariable( $base . '_ezpackage_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00077         {
00078             $data = $http->postVariable( $base . '_ezpackage_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00079 
00080             // Save in ini files if the package type is sitestyle.
00081             $classAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
00082             if ( $classAttribute->attribute( self::TYPE_FIELD ) == 'sitestyle' )
00083             {
00084                 $package = eZPackage::fetch( $data );
00085                 if ( $package )
00086                 {
00087                     $fileList = $package->fileList( 'default' );
00088                     foreach ( array_keys( $fileList ) as $key )
00089                     {
00090                         $file =& $fileList[$key];
00091                         $fileIdentifier = $file["variable-name"];
00092                         if ( $fileIdentifier == 'sitecssfile' )
00093                         {
00094                             $siteCSS = $package->fileItemPath( $file, 'default' );
00095                         }
00096                         else if ( $fileIdentifier == 'classescssfile' )
00097                         {
00098                             $classesCSS = $package->fileItemPath( $file, 'default' );
00099                         }
00100                     }
00101                     $currentSiteAccess = $http->hasPostVariable( 'CurrentSiteAccess' )
00102                                          ? $http->postVariable( 'CurrentSiteAccess' )
00103                                          : false;
00104                     $iniPath = 'settings/override';
00105                     if ( $currentSiteAccess != 'Global' and $currentSiteAccess !== false )
00106                     {
00107                         $data .= ':' . $currentSiteAccess;
00108                         $iniPath = 'settings/siteaccess/' . $currentSiteAccess;
00109                     }
00110 
00111                     $designINI = eZINI::instance( 'design.ini.append.php', $iniPath, null, false, null, true );
00112                     $designINI->setVariable( 'StylesheetSettings', 'SiteCSS', $siteCSS );
00113                     $designINI->setVariable( 'StylesheetSettings', 'ClassesCSS', $classesCSS );
00114                     $designINI->save();
00115                 }
00116             }
00117             $contentObjectAttribute->setAttribute( 'data_text', $data );
00118         }
00119         return true;
00120     }
00121 
00122     /*!
00123      Does nothing since it uses the data_text field in the content object attribute.
00124      See fetchObjectAttributeHTTPInput for the actual storing.
00125     */
00126     function storeObjectAttribute( $attribute )
00127     {
00128         $ini = eZINI::instance();
00129         // Delete compiled template
00130         $siteINI = eZINI::instance();
00131         if ( $siteINI->hasVariable( 'FileSettings', 'CacheDir' ) )
00132         {
00133             $cacheDir = $siteINI->variable( 'FileSettings', 'CacheDir' );
00134             if ( $cacheDir[0] == "/" )
00135             {
00136                 $cacheDir = eZDir::path( array( $cacheDir ) );
00137             }
00138             else
00139             {
00140                 if ( $siteINI->hasVariable( 'FileSettings', 'VarDir' ) )
00141                 {
00142                     $varDir = $siteINI->variable( 'FileSettings', 'VarDir' );
00143                     $cacheDir = eZDir::path( array( $varDir, $cacheDir ) );
00144                 }
00145             }
00146         }
00147         else if ( $siteINI->hasVariable( 'FileSettings', 'VarDir' ) )
00148         {
00149             $varDir = $siteINI->variable( 'FileSettings', 'VarDir' );
00150             $cacheDir = $ini->variable( 'FileSettings', 'CacheDir' );
00151             $cacheDir = eZDir::path( array( $varDir, $cacheDir ) );
00152         }
00153         else
00154         {
00155             $cacheDir =  eZSys::cacheDirectory();
00156         }
00157         $compiledTemplateDir = $cacheDir ."/template/compiled";
00158         eZDir::unlinkWildcard( $compiledTemplateDir . "/", "*pagelayout*.*" );
00159 
00160         // Expire template block cache
00161         eZContentCacheManager::clearTemplateBlockCacheIfNeeded( false );
00162     }
00163 
00164     function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
00165     {
00166         $packageTypeName = $base . self::TYPE_VARIABLE . $classAttribute->attribute( 'id' );
00167         if ( $http->hasPostVariable( $packageTypeName ) )
00168         {
00169             $packageTypeValue = $http->postVariable( $packageTypeName );
00170             $classAttribute->setAttribute( self::TYPE_FIELD, $packageTypeValue );
00171         }
00172         $packageViewModeName = $base . self::VIEW_MODE_VARIABLE . $classAttribute->attribute( 'id' );
00173         if ( $http->hasPostVariable( $packageViewModeName ) )
00174         {
00175             $packageViewModeValue = $http->postVariable( $packageViewModeName );
00176             $classAttribute->setAttribute( self::VIEW_MODE_FIELD, $packageViewModeValue );
00177         }
00178         return true;
00179     }
00180 
00181     /*!
00182      Returns the content.
00183     */
00184     function objectAttributeContent( $contentObjectAttribute )
00185     {
00186         $packageName = $contentObjectAttribute->attribute( "data_text" );
00187         $package = eZPackage::fetch( $packageName );
00188         return $package;
00189     }
00190 
00191     /*!
00192      Returns the meta data used for storing search indeces.
00193     */
00194     function metaData( $contentObjectAttribute )
00195     {
00196         return $contentObjectAttribute->attribute( 'data_text' );
00197     }
00198 
00199     /*!
00200      Returns the content of the string for use as a title
00201     */
00202     function title( $contentObjectAttribute, $name = null )
00203     {
00204         return $contentObjectAttribute->attribute( 'data_text' );
00205     }
00206 
00207     function hasObjectAttributeContent( $contentObjectAttribute )
00208     {
00209         return trim( $contentObjectAttribute->attribute( 'data_text' ) ) != '';
00210     }
00211 
00212     function isIndexable()
00213     {
00214         return false;
00215     }
00216 
00217     function sortKey( $contentObjectAttribute )
00218     {
00219         return strtolower( $contentObjectAttribute->attribute( 'data_text' ) );
00220     }
00221 
00222     function sortKeyType()
00223     {
00224         return 'string';
00225     }
00226 
00227     function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
00228     {
00229         $type = $classAttribute->attribute( self::TYPE_FIELD );
00230         $dom = $attributeParametersNode->ownerDocument;
00231         $typeNode = $dom->createElement( 'type' );
00232         $typeNode->appendChild( $dom->createTextNode( $type ) );
00233         $attributeParametersNode->appendChild( $typeNode );
00234     }
00235 
00236     function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
00237     {
00238         $type = $attributeParametersNode->getElementsByTagName( 'type' )->item( 0 )->textContent;
00239         $classAttribute->setAttribute( self::TYPE_FIELD, $type );
00240     }
00241 
00242     function diff( $old, $new, $options = false )
00243     {
00244         return null;
00245     }
00246 }
00247 
00248 eZDataType::register( eZPackageType::DATA_TYPE_STRING, 'eZPackageType' );
00249 
00250 ?>