[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/visual/ -> toolbar.php (source)

   1  <?php
   2  //
   3  // Definition of Toolbar class
   4  //
   5  // Created on: <05-Mar-2004 12:36:14 wy>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file toolbar.php
  30  */
  31  
  32  $http =& eZHTTPTool::instance();
  33  $module =& $Params["Module"];
  34  
  35  $currentSiteAccess = ( $Params['SiteAccess'] ) ? $Params['SiteAccess'] : false;
  36  $toolbarPosition = ( $Params['Position'] ) ? $Params['Position'] : false;
  37  
  38  include_once ( "kernel/common/template.php" );
  39  include_once ( 'lib/ezutils/classes/ezhttptool.php' );
  40  include_once ( 'kernel/classes/ezcontentbrowse.php' );
  41  include_once ( "kernel/classes/ezsiteaccess.php" );
  42  
  43  $http =& eZHTTPTool::instance();
  44  
  45  $siteini =& eZINI::instance();
  46  if ( !$currentSiteAccess or
  47       !$toolbarPosition or
  48       !in_array( $currentSiteAccess, $siteini->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' ) ) )
  49      return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
  50  
  51  $iniPath = eZSiteAccess::findPathToSiteAccess( $currentSiteAccess );
  52  $ini =& eZINI::instance( "toolbar.ini", 'settings', null, false, null, false );
  53  
  54  $iniAppend =& eZINI::instance( 'toolbar.ini.append', $iniPath, null, false, null, true );
  55  
  56  $toolArray = array();
  57  if ( $iniAppend->hasVariable( "Toolbar_" . $toolbarPosition, "Tool" ) )
  58  {
  59      $toolArray =  $iniAppend->variable( "Toolbar_" . $toolbarPosition, "Tool" );
  60  }
  61  else if ( $ini->hasVariable( "Toolbar_" . $toolbarPosition, "Tool" ) )
  62  {
  63      $toolArray =  $ini->variable( "Toolbar_" . $toolbarPosition, "Tool" );
  64  }
  65  
  66  $storeList = false;
  67  $removeCache = false;
  68  $checkCurrAction = false;   //Checks if it is needed to clear $parameterValue
  69  
  70  $currentAction = $module->currentAction();
  71  
  72  if ( $currentAction == 'BackToToolbars' )
  73  {
  74      return $Module->redirectToView( 'toolbarlist', array() );
  75  }
  76  elseif ( $currentAction == 'SelectToolbarNode' )
  77  {
  78      $selectedNodeIDArray = eZContentBrowse::result( 'SelectToolbarNode' );
  79  
  80      $nodeID = $selectedNodeIDArray[0];
  81      if ( is_numeric( $nodeID ) )
  82      {
  83          $toolIndex = $http->variable( 'tool_index' );
  84          $parameterName = $http->variable( 'parameter_name' );
  85  
  86          $iniAppend->setVariable( "Tool_" . $toolbarPosition . "_" . $toolArray[$toolIndex] . "_" . ( $toolIndex + 1 ), $parameterName, $nodeID );
  87          $succeed = $iniAppend->save(  false, false, false, false, true, true );
  88      }
  89  }
  90  elseif ( $currentAction == 'SelectToolbarNodePath' )
  91  {
  92      $selectedNodeIDArray = eZContentBrowse::result( 'SelectToolbarNode' );
  93  
  94      $nodeID = $selectedNodeIDArray[0];
  95      if  ( !$http->hasPostVariable( 'BrowseCancelButton' ) )
  96      {
  97          if ( !is_numeric( $nodeID ) )
  98             $nodeID = 2;
  99          $toolIndex = $http->variable( 'tool_index' );
 100          $parameterName = $http->variable( 'parameter_name' );
 101          $iniAppend->setVariable( "Tool_" . $toolbarPosition . "_" . $toolArray[$toolIndex] . "_" . ( $toolIndex + 1 ), $parameterName, $nodeID );
 102          $succeed = $iniAppend->save(  false, false, false, false, true, true );
 103      }
 104  }
 105  elseif ( $currentAction == 'NewTool' ||
 106           $currentAction == 'UpdatePlacement' ||
 107           $currentAction == 'Browse' ||
 108           $currentAction == 'Remove' )
 109  {
 110      $deleteToolArray = array();
 111      if ( $currentAction == 'Remove' &&
 112           $http->hasPostVariable( 'deleteToolArray' ) )
 113      {
 114          $deleteToolArray = $http->postVariable( 'deleteToolArray' );
 115      }
 116  
 117      $updatedToolArray = array();
 118      $existingToolArray = $toolArray;
 119      $deleteToolKeys = array_keys( $deleteToolArray );
 120  
 121      $positionMap = array();
 122      $updatedBlockArray = array();
 123      for ( $originalIndex = 0; $originalIndex < count( $existingToolArray ); ++$originalIndex )
 124      {
 125          $originalPlacement = $originalIndex + 1;
 126          if ( in_array( $originalIndex, $deleteToolArray ) )
 127          {
 128              continue;
 129          }
 130          if ( $http->hasPostVariable( 'placement_' . $originalIndex ) )
 131          {
 132              $newIndex = $http->postVariable( 'placement_' . $originalIndex );
 133              if ( isset( $positionMap[$newIndex] ) )
 134              {
 135                  $newPositionMap = array();
 136                  foreach ( $positionMap as $positionIndex => $positionOriginalIndex )
 137                  {
 138                      if ( $positionIndex > $newIndex )
 139                          ++$positionIndex;
 140                      $newPositionMap[$positionIndex] = $positionOriginalIndex;
 141                  }
 142                  $positionMap = $newPositionMap;
 143                  ++$newIndex;
 144              }
 145              $positionMap[$newIndex] = $originalIndex;
 146          }
 147      }
 148      ksort( $positionMap );
 149      reset( $positionMap );
 150      $newIndex =0 ;
 151      foreach ( $positionMap as $originalIndex )
 152      {
 153          $originalPlacement = $originalIndex + 1;
 154          $newPlacement = $newIndex + 1;
 155          $toolName = $existingToolArray[$originalIndex];
 156          $updatedToolArray[$newIndex] = $toolName;
 157          if ( $iniAppend->hasGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . $originalPlacement ) )
 158          {
 159              $actionParameters = $iniAppend->group( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . $originalPlacement );
 160  
 161              $updatedBlockArray[] = array( 'blockName' => "Tool_" . $toolbarPosition . "_" . $toolName . "_" . $newPlacement,
 162                                            'parameters' => $actionParameters );
 163              $iniAppend->removeGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . $originalPlacement );
 164          }
 165          ++$newIndex;
 166      }
 167      foreach ( $deleteToolArray as $deleteToolIndex )
 168      {
 169          $deleteToolPlacement = $deleteToolIndex + 1;
 170          $toolName = $existingToolArray[$deleteToolIndex];
 171          if ( $iniAppend->hasGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . $deleteToolPlacement ) )
 172          {
 173              $iniAppend->removeGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . $deleteToolPlacement );
 174          }
 175      }
 176  
 177      if ( $currentAction == 'NewTool' &&
 178           $http->hasPostVariable( 'toolName' ) )
 179      {
 180          $addedToolName = $http->postVariable( 'toolName' );
 181          array_push( $updatedToolArray, $addedToolName );
 182      }
 183  
 184      foreach ( $updatedBlockArray as $updatedBlock )
 185      {
 186          $blockName = $updatedBlock['blockName'];
 187          $parameters = $updatedBlock['parameters'];
 188          foreach ( array_keys( $parameters ) as $key )
 189          {
 190              $parameterValue = $parameters[$key];
 191              $iniAppend->setVariable( $blockName, $key, $parameterValue );
 192          }
 193      }
 194  
 195      $iniAppend->setVariable( "Toolbar_" . $toolbarPosition, "Tool", $updatedToolArray );
 196      $succeed = $iniAppend->save( false, false, false, false, true, true );
 197  
 198      if ( $currentAction == 'Browse' )
 199      {
 200          $browseArray = $http->postVariable( 'BrowseButton' );
 201          if ( preg_match( "/_node$/", key( $browseArray ) ) )
 202          {
 203              if ( preg_match( "/(.+)_parameter_(.+)/", key( $browseArray ), $res ) )
 204              {
 205                  eZContentBrowse::browse( array( 'action_name' => 'SelectToolbarNode',
 206                                                  'description_template' => false,
 207                                                  'persistent_data' => array( 'tool_index' => $res[1], 'parameter_name' => $res[2] ),
 208                                                  'from_page' => "/visual/toolbar/$currentSiteAccess/$toolbarPosition/" ),
 209                                           $module );
 210                  removeRelatedCache( $currentSiteAccess );
 211                  return;
 212              }
 213  
 214          }
 215          else if ( preg_match( "/_subtree$/", key( $browseArray ) ) )
 216          {
 217              if ( preg_match( "/(.+)_parameter_(.+)/", key( $browseArray ), $res ) )
 218              {
 219                  eZContentBrowse::browse( array( 'action_name' => 'SelectToolbarNodePath',
 220                                                  'description_template' => false,
 221                                                  'persistent_data' => array( 'tool_index' => $res[1], 'parameter_name' => $res[2] ),
 222                                                  'from_page' => "/visual/toolbar/$currentSiteAccess/$toolbarPosition/" ),
 223                                           $module );
 224                  removeRelatedCache( $currentSiteAccess );
 225                  return;
 226              }
 227          }
 228      }
 229      $toolArray = $updatedToolArray;
 230      $removeCache = true;
 231  }
 232  elseif ( $currentAction == 'Store' )
 233  {
 234      $storeList = true;
 235      $removeCache = true;
 236      $checkCurrAction = true;
 237  }
 238  
 239  $toolList = array();
 240  foreach ( array_keys( $toolArray ) as $toolKey )
 241  {
 242      unset( $actionParameters );
 243      $actionParameters = array();
 244      $defaultActionParameters = array();
 245      $actionDescription = false;
 246      $toolName = $toolArray[$toolKey];
 247      if ( $ini->hasGroup( "Tool_" . $toolName ) )
 248      {
 249          $defaultActionParameters = $ini->group( "Tool_" . $toolName );
 250      }
 251      if ( $iniAppend->hasGroup( "Tool_" . $toolName . '_description' ) )
 252      {
 253          $actionDescription = $iniAppend->group( "Tool_" . $toolName . '_description' );
 254      }
 255      elseif ( $ini->hasGroup( "Tool_" . $toolName . '_description' ) )
 256      {
 257          $actionDescription = $ini->group( "Tool_" . $toolName . '_description' );
 258      }
 259      /* if ( $ini->hasGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ) ) )
 260      {
 261          $defaultActionParameters = array_merge( $defaultActionParameters, $ini->group( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ) ) );
 262      }*/
 263  
 264      if ( $iniAppend->hasGroup( "Tool_" . $toolName ) )
 265      {
 266          $actionParameters = array_merge( $actionParameters, $iniAppend->group( "Tool_" . $toolName ) );
 267      }
 268      if ( $iniAppend->hasGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ) ) )
 269      {
 270          $actionParameters = array_merge( $actionParameters, $iniAppend->group( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ) ) );
 271      }
 272      $actionParameters = array_merge( $defaultActionParameters, $actionParameters );
 273      if ( !$actionDescription )
 274      {
 275          $actionDescription = array();
 276          foreach ( $actionParameters as $actionParameterKey => $actionParameter )
 277          {
 278              $actionDescription[$actionParameterKey] = $actionParameterKey;
 279          }
 280      }
 281      $removeNewBlock = true;
 282      $newActionParameters = array();
 283      $toolParameters = array();
 284      $customInputList = array();
 285      if ( $http->hasPostVariable( 'CustomInputList' ) )
 286          $customInputList = $http->postVariable( 'CustomInputList' );
 287      foreach ( array_keys( $actionParameters ) as $key )
 288      {
 289          $oldParameterValue = false;
 290          if ( isset( $defaultActionParameters[$key] ) )
 291              $oldParameterValue = $defaultActionParameters[$key];
 292  
 293          $parameterValue = $actionParameters[$key];
 294  
 295          if ( !isset( $customInputList[$toolKey . "_parameter_" . $key] ) && $checkCurrAction )
 296              $parameterValue = '';
 297  
 298  
 299          if ( $storeList and
 300               $http->hasPostVariable( $toolKey . "_parameter_" . $key ) )
 301          {
 302              $parameterValue = $http->postVariable( $toolKey . "_parameter_" . $key );
 303              if ( $oldParameterValue != $parameterValue )
 304              {
 305                  $makeNewBlock = true;
 306                  $newActionParameters[$key] = $parameterValue;
 307              }
 308          }
 309          else if ( $storeList and
 310                    isset( $customInputList[$toolKey . "_parameter_" . $key] ) )
 311          {
 312              $parameterValue = implode( ',', $customInputList[$toolKey . "_parameter_" . $key] );
 313              if ( $oldParameterValue != $parameterValue )
 314              {
 315                  $makeNewBlock = true;
 316                  $newActionParameters[$key] = $parameterValue;
 317              }
 318          }
 319  
 320          $toolParameterArray = array();
 321          $toolParameterArray['name'] = $key;
 322          $toolParameterArray['value'] = $parameterValue;
 323          $toolParameterArray['description'] = $actionDescription[$key];
 324          $toolParameters[] = $toolParameterArray;
 325      }
 326      $toolList[] = array( 'name' => $toolName,
 327                           'parameters' => $toolParameters );
 328      if ( $storeList )
 329      {
 330          if ( count( $newActionParameters ) == 0 )
 331          {
 332              if ( $iniAppend->hasGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ) ) )
 333              {
 334                  $iniAppend->removeGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ) );
 335              }
 336          }
 337          else
 338          {
 339              $removedActionParameters = array_diff( $actionParameters, $newActionParameters );
 340              if ( count( $removedActionParameters ) > 0 )
 341              {
 342                  if ( $iniAppend->hasGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ) ) )
 343                  {
 344                      $iniAppend->removeGroup( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ) );
 345                  }
 346              }
 347              foreach ( array_keys( $newActionParameters ) as $newKey )
 348              {
 349                  $parameterValue = $newActionParameters[$newKey];
 350                  $iniAppend->setVariable( "Tool_" . $toolbarPosition . "_" . $toolName . "_" . ( $toolKey + 1 ), $newKey, $parameterValue );
 351              }
 352          }
 353      }
 354  }
 355  if ( $storeList )
 356  {
 357      $succeed = $iniAppend->save( false, false, false, false, true, true );
 358  }
 359  if ( $removeCache )
 360  {
 361      removeRelatedCache( $currentSiteAccess );
 362  }
 363  
 364  $toolbarIni =& eZINI::instance( "toolbar.ini", 'settings', null, false, true, false );
 365  $toolbarIni->prependOverrideDir( "siteaccess/$currentSiteAccess", false, 'siteaccess' );
 366  $toolbarIni->parse();
 367  
 368  if ( $toolbarIni->hasVariable( "Tool", "AvailableToolArray" ) )
 369  {
 370      $availableToolArray = $toolbarIni->variable( "Tool", "AvailableToolArray" );
 371  }
 372  
 373  $tpl =& templateInit();
 374  
 375  $tpl->setVariable( 'toolbar_position', $toolbarPosition );
 376  $tpl->setVariable( 'tool_list', $toolList );
 377  $tpl->setVariable( 'available_tool_list', $availableToolArray  );
 378  $tpl->setVariable( 'current_siteaccess', $currentSiteAccess );
 379  
 380  $Result = array();
 381  $Result['content'] =& $tpl->fetch( "design:visual/toolbar.tpl" );
 382  $Result['path'] = array( array( 'url' => 'visual/toolbarlist',
 383                                  'text' => ezi18n( 'kernel/design', 'Toolbar list' ) ) );
 384  
 385  function removeRelatedCache( $siteAccess )
 386  {
 387      // Delete compiled template
 388      $ini =& eZINI::instance();
 389      $iniPath = eZSiteAccess::findPathToSiteAccess( $siteAccess );
 390      $siteINI = eZINI::instance( 'site.ini.append', $iniPath );
 391      if ( $siteINI->hasVariable( 'FileSettings', 'CacheDir' ) )
 392      {
 393          $cacheDir = $siteINI->variable( 'FileSettings', 'CacheDir' );
 394          if ( $cacheDir[0] == "/" )
 395          {
 396              $cacheDir = eZDir::path( array( $cacheDir ) );
 397          }
 398          else
 399          {
 400              if ( $siteINI->hasVariable( 'FileSettings', 'VarDir' ) )
 401              {
 402                  $varDir = $siteINI->variable( 'FileSettings', 'VarDir' );
 403                  $cacheDir = eZDir::path( array( $varDir, $cacheDir ) );
 404              }
 405          }
 406      }
 407      else if ( $siteINI->hasVariable( 'FileSettings', 'VarDir' ) )
 408      {
 409           $varDir = $siteINI->variable( 'FileSettings', 'VarDir' );
 410           $cacheDir = $ini->variable( 'FileSettings', 'CacheDir' );
 411           $cacheDir = eZDir::path( array( $varDir, $cacheDir ) );
 412      }
 413      else
 414      {
 415          $cacheDir =  eZSys::cacheDirectory();
 416      }
 417      $compiledTemplateDir = $cacheDir . "/template/compiled";
 418      eZDir::unlinkWildcard( $compiledTemplateDir . "/", "*pagelayout*.*" );
 419      include_once ( 'kernel/classes/ezcache.php' );
 420      eZCache::clearByTag( 'template-block' );
 421  
 422      // Expire content view cache
 423      include_once ( 'kernel/classes/ezcontentcachemanager.php' );
 424      eZContentCacheManager::clearAllContentCache();
 425  }
 426  
 427  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7