|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZINIAddonPackageHandler class 00004 // 00005 // Created on: <23-Jul-2003 16:11:42 amos> 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 ezcontentclasspackagehandler.php 00032 */ 00033 00034 /*! 00035 \class eZINIAddonPackageHandler ezcontentclasspackagehandler.php 00036 \brief Handles content classes in the package system 00037 00038 */ 00039 00040 //include_once( 'kernel/classes/ezpackagehandler.php' ); 00041 00042 class eZINIAddonPackageHandler extends eZPackageHandler 00043 { 00044 /*! 00045 Constructor 00046 */ 00047 function eZINIAddonPackageHandler() 00048 { 00049 $this->eZPackageHandler( 'eziniaddon', 00050 array( 'extract-install-content' => true ) ); 00051 } 00052 00053 /*! 00054 \reimp 00055 Creates a new override setting for the specified override. 00056 00057 \param installParameters - optional value 00058 array( 'site_access_map' => array( <package site access> => <install site access> ) ) 00059 */ 00060 function install( $package, $installType, $parameters, 00061 $name, $os, $filename, $subdirectory, 00062 $content, $installParameters, 00063 &$installData ) 00064 { 00065 //include_once( 'lib/ezdb/classes/ezdb.php' ); 00066 $db = eZDB::instance(); 00067 00068 $siteAccess = $content->getAttribute( 'site-access' ); 00069 if ( isset( $installParameters['site_access_map'] ) && 00070 isset( $installParameters['site_access_map'][$siteAccess] ) ) 00071 { 00072 $siteAccess = $installParameters['site_access_map'][$siteAccess]; 00073 } 00074 00075 $filename = $content->getAttribute( 'filename' ); 00076 00077 //include_once( 'lib/ezutils/classes/ezini.php' ); 00078 $ini = eZINI::instance( $filename, 'settings', null, null, true ); 00079 $ini->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' ); 00080 $ini->loadCache(); 00081 00082 $blocks =& $content->elementByName( 'blocks' ); 00083 $blockArray =& $blocks->getElementsByTagName( 'block' ); 00084 00085 foreach ( $blockArray as $block ) 00086 { 00087 $blockname = $block->getAttribute( 'name' ); 00088 00089 $blockVariableArray = $block->getElementsByTagName( 'block-variable' ); 00090 foreach( $blockVariableArray as $blockVariable ) 00091 { 00092 $variableName = $blockVariable->getAttribute( 'name' ); 00093 $variableValues = $blockVariable->getElementsByTagName( 'value' ); 00094 00095 if ( count( $variableValues ) == 1 ) 00096 { 00097 $value = eZINIAddonPackageHandler::currentID( $variableValues[0], $db ); 00098 $ini->setVariable( $blockname, $variableName, $value ); 00099 } 00100 else 00101 { 00102 $valueArray = array(); 00103 foreach( $variableValues as $variableNode ) 00104 { 00105 $valueName = $variableNode->getAttribute( 'name' ); 00106 $value = eZINIAddonPackageHandler::currentID( $variableNode, $db ); 00107 $valueArray[$valueName] = $value; 00108 } 00109 $ini->setVariable( $blockname, $variableName, $valueArray ); 00110 } 00111 } 00112 } 00113 00114 $ini->save(); 00115 00116 return true; 00117 } 00118 00119 /*! 00120 \static get current id of value node 00121 00122 \param value DOMNode 00123 \param db connection 00124 */ 00125 static function currentID( $valueNode, $db ) 00126 { 00127 $remoteIDType = $valueNode->getAttribute( 'remote-id' ); 00128 $value = $valueNode->textContent; 00129 00130 if ( $remoteIDType !== false ) 00131 { 00132 switch( $remoteIDType ) 00133 { 00134 case 'class': 00135 { 00136 $result = $db->arrayQuery( 'SELECT id FROM ezcontentclass WHERE remote_id=\'' . $db->escapeString( $value ) . '\'' ); 00137 } break; 00138 00139 case 'node': 00140 { 00141 $result = $db->arrayQuery( 'SELECT node_id FROM ezcontentobject_tree WHERE remote_id=\'' . $db->escapeString( $value ) . '\'' ); 00142 } break; 00143 00144 case 'object': 00145 { 00146 $result = $db->arrayQuery( 'SELECT id FROM ezcontentobject WHERE remote_id=\'' . $db->escapeString( $value ) . '\'' ); 00147 } break; 00148 00149 default: 00150 { 00151 eZDebug::writeError( 'Unknown remote id type ' . $remoteIDType, 00152 'eZINIAddonPackageHandler::currentID()' ); 00153 } break; 00154 } 00155 00156 if ( count( $result ) != 1 ) 00157 { 00158 eZDebug::writeError( 'Invalid result fetching id from ' . $remoteIDType . ', remote_id: ' . $value, 00159 'eZINIAddonPackageHandler::currentID()' ); 00160 } 00161 else 00162 { 00163 $value = $result[0][0]; 00164 } 00165 } 00166 00167 return $value; 00168 } 00169 00170 /*! 00171 \static 00172 Adds the content of the ini override to the package 00173 00174 \param package 00175 \param ini filename, ex: site.ini 00176 \param iniOverrideArray structure array( <site_access> => array( <ini_block_name> => array( <ini_block_values> ) ) ) 00177 \param remoteIDArrat structure: array( <class|node|object> => array( <id> => <remote_id> ) ) 00178 */ 00179 function addOverrideAddon( $package, $filename, &$iniOverrideArray, $remoteIDArray ) 00180 { 00181 foreach( array_keys( $iniOverrideArray ) as $siteAccess ) 00182 { 00183 $iniNode = eZINIAddonPackageHandler::iniDOMTree( $filename, $siteAccess, $iniOverrideArray[$siteAccess], $remoteIDArray ); 00184 if ( !$overrideNode ) 00185 { 00186 continue; 00187 } 00188 00189 $package->appendInstall( 'eziniaddon', false, false, true, 00190 $siteAccess . '-' . $filename, 'eziniaddon', 00191 array( 'content' => $iniNode ) ); 00192 $package->appendInstall( 'eziniaddon', false, false, false, 00193 $siteAccess . '-' . $filename, 'eziniaddon', 00194 array( 'content' => false ) ); 00195 } 00196 } 00197 00198 /*! 00199 \static 00200 00201 Create DOMNode from inioverride 00202 00203 \param ini filename 00204 \param siteaccess 00205 \param ini values, struct: array( <ini_block_name> => array( <ini_block_values> ) ) 00206 \param remoteID array 00207 00208 \return DOMNode, false if fails 00209 */ 00210 function iniDOMTree( $filename, $siteAccess, &$blockArray, $remoteIDArray ) 00211 { 00212 if ( !$filename || !$siteAccess || !$blockArray ) 00213 { 00214 return false; 00215 } 00216 00217 $iniNode = eZDOMDocument::createElementNode( 'ini-addon', array( 'site-access' => $siteAccess, 00218 'filename' => $filename ) ); 00219 00220 $blocksNode = eZDOMDocument::createElementNode( 'blocks' ); 00221 $iniNode->appendChild( $blocksNode ); 00222 foreach( array_keys( $blockArray ) as $blockName ) 00223 { 00224 $block =& $blockArray[$blockName]; 00225 unset( $blockNode ); 00226 $blockNode = eZDOMDocument::createElementNode( 'block', array( 'name' => $blockName ) ); 00227 $blocksNode->appendChild( $blockNode ); 00228 00229 foreach( array_keys( $block ) as $blockVariable ) 00230 { 00231 $variableValue =& $block[$blockVariable]; 00232 unset( $variableNode ); 00233 $variableNode = eZDomDocument::createElementNode( 'block-variable', array( 'name' => $blockVariable ) ); 00234 $blockNode->appendChild( $variableNode ); 00235 00236 if ( is_array( $variableValue ) ) 00237 { 00238 foreach( array_keys( $variableValue) as $valueName ) 00239 { 00240 $value = $variableValue[$valueName]; 00241 unset( $valueNode ); 00242 $valueNode = eZDomDocument::createElementNode( 'value', array( 'name' => $valueName ) ); 00243 $variableNode->appendChild( $valueNode ); 00244 $remoteID = false; 00245 if ( is_int( $value ) ) 00246 { 00247 if ( strpos( $valueName, 'class' ) !== false ) 00248 { 00249 $value = $remoteIDArray['class'][(string)$value]; 00250 $remoteID = 'class'; 00251 } 00252 else if( strpos( $valueName, 'node' ) !== false ) 00253 { 00254 $value = $remoteIDArray['node'][(string)$value]; 00255 $remoteID = 'node'; 00256 } 00257 else if ( strpos( $valueName, 'object' ) !== false ) 00258 { 00259 $value = $remoteIDArray['class'][(string)$value]; 00260 $remoteID = 'object'; 00261 } 00262 else 00263 { 00264 eZDebug::writeNotice( 'Could not interpret ' . $valueName . ': ' . $value, 00265 'eZINIAddonPackageHandler::iniDOMTree()' ); 00266 } 00267 } 00268 if ( $remoteID ) 00269 { 00270 $valueNode->appendAttribute( eZDomDocument::createAttributeNode( 'remote-id', $remoteID ) ); 00271 } 00272 $valueNode->appendChild( eZDomDocument::createTextNode( $value ) ); 00273 } 00274 } 00275 else 00276 { 00277 $remoteID = false; 00278 if ( is_int( $variableValue ) ) 00279 { 00280 if ( strpos( $blockVariable, 'class' ) !== false ) 00281 { 00282 $variableValue = $remoteIDArray['class'][(string)$value]; 00283 $remoteID = 'class'; 00284 } 00285 else if( strpos( $blockVariable, 'node' ) !== false ) 00286 { 00287 $variableValue = $remoteIDArray['node'][(string)$value]; 00288 $remoteID = 'node'; 00289 } 00290 else if ( strpos( $blockVariable, 'object' ) !== false ) 00291 { 00292 $variableValue = $remoteIDArray['class'][(string)$value]; 00293 $remoteID = 'object'; 00294 } 00295 else 00296 { 00297 eZDebug::writeNotice( 'Could not interpret ' . $blockVariable . ': ' . $variableValue, 00298 'eZINIAddonPackageHandler::iniDOMTree()' ); 00299 } 00300 } 00301 unset( $valueNode ); 00302 $valueNode = eZDomDocument::createElementNode( 'value' ); 00303 $variableNode->appendChild( $valueNode ); 00304 if ( $remoteID ) 00305 { 00306 $valueNode->appendAttribute( eZDomDocument::createAttributeNode( 'remote-id', $remoteID ) ); 00307 } 00308 $valueNode->appendChild( eZDomDocument::createTextNode( $variableValue ) ); 00309 } 00310 } 00311 } 00312 return $iniNode; 00313 } 00314 } 00315 ?>