[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/lib/eztemplate/classes/ -> eztemplatetoolbarfunction.php (source)

   1  <?php
   2  //
   3  // Definition of eZTemplateToolbarFunction class
   4  //
   5  // Created on: <04-Mar-2004 13:22:32 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 eztemplatetoolbarfunction.php
  30  */
  31  
  32  /*!
  33    \class eZTemplateToolbarFunction eztemplatetoolbarfunction.php
  34    \brief The class eZTemplateToolarFunction does
  35  
  36  */
  37  
  38  class eZTemplateToolbarFunction
  39  {
  40  
  41      /*!
  42       Initializes the object with names.
  43      */
  44      function eZTemplateToolbarFunction( $blockName = 'tool_bar' )
  45      {
  46          $this->BlockName = $blockName;
  47      }
  48  
  49      /*!
  50       Returns an array containing the name of the block function, default is "block".
  51       The name is specified in the constructor.
  52      */
  53      function functionList()
  54      {
  55          return array( $this->BlockName );
  56      }
  57  
  58      function functionTemplateHints()
  59      {
  60          return array( $this->BlockName => array( 'parameters' => true,
  61                                                   'static' => false,
  62                                                   'transform-children' => false,
  63                                                   'tree-transformation' => true,
  64                                                   'transform-parameters' => true ) );
  65      }
  66  
  67      function templateNodeTransformation( $functionName, &$node,
  68                                           &$tpl, $parameters, $privateData )
  69      {
  70          if ( $functionName != $this->BlockName )
  71              return false;
  72  
  73          $parameters = eZTemplateNodeTool::extractFunctionNodeParameters( $node );
  74  
  75          if ( !isset( $parameters['name'] ) )
  76              return false;
  77  
  78          // Read ini file
  79          $toolbarIni =& eZINI::instance( "toolbar.ini" );
  80  
  81          if ( isset( $parameters["view"] ) )
  82          {
  83              $viewData = $parameters["view"];
  84              $viewMode = eZTemplateNodeTool::elementStaticValue( $viewData );
  85          }
  86          else
  87          {
  88              $viewMode = "full";
  89          }
  90  
  91          $params = $parameters;
  92          $namespaceValue = false;
  93          if ( isset( $parameters["name"] ) )
  94          {
  95              $nameData = $parameters["name"];
  96              if ( !eZTemplateNodeTool::isStaticElement( $nameData ) )
  97                  return false;
  98  
  99              $nameValue = eZTemplateNodeTool::elementStaticValue( $nameData );
 100  
 101              $toolbarPosition = $nameValue;
 102              $toolbarName = "Toolbar_" . $toolbarPosition;
 103              $toolArray = $toolbarIni->variable( $toolbarName, 'Tool' );
 104              if ( !is_array( $toolArray ) )
 105                  $toolArray = array();
 106  
 107              $newNodes = array();
 108              foreach ( array_keys( $toolArray ) as $toolKey )
 109              {
 110                  $tool = $toolArray[$toolKey];
 111                  $placement = $toolKey + 1;
 112  
 113                  $uriString = "design:toolbar/$viewMode/$tool.tpl";
 114  
 115                  $placementValue = "";
 116                  $firstValue = false;
 117                  $lastValue = false;
 118                  if ( $placement == 1 )
 119                  {
 120                      if ( $placement == count( $toolArray ) )
 121                      {
 122                          $firstValue = true;
 123                          $lastValue = true;
 124                          $placementValue = "last";
 125                      }
 126                      else
 127                      {
 128                          $firstValue = true;
 129                          $placementValue = "first";
 130                      }
 131                  }
 132                  else if ( $placement == count( $toolArray ) )
 133                  {
 134                      $lastValue = true;
 135                      $placementValue = "last";
 136                  }
 137  
 138                  $resourceName = "";
 139                  $templateName = "";
 140                  $resource =& $tpl->resourceFor( $uriString, $resourceName, $templateName );
 141                  $resourceData = $tpl->resourceData( $resource, $uriString, $resourceName, $templateName );
 142                  $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();
 143  
 144                  $includeNodes = $resource->templateNodeTransformation( $functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue );
 145                  if ( $includeNodes === false )
 146                      return false;
 147  
 148                  $uniqID = md5( uniqid('inc') );
 149                  $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$oldRestoreIncludeArray" . "_$uniqID = isset( \$restoreIncludeArray ) ? \$restoreIncludeArray : array();\n".
 150                                                                         "\$restoreIncludeArray = array();\n");
 151                  $variableList = array();
 152                  foreach ( array_keys( $parameters ) as $parameterName )
 153                  {
 154                      if ( $parameterName == 'name' or
 155                           $parameterName == 'view' )
 156                          continue;
 157                      $parameterData =& $parameters[$parameterName];
 158                      $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( isset( \$vars['']['$parameterName'] ) )\n".
 159                                                                             "    \$restoreIncludeArray[] = array( '', '$parameterName', \$vars['']['$parameterName'] );\n".
 160                                                                             "elseif ( !isset( \$vars['']['$parameterName'] ) ) \n".
 161                                                                             "    \$restoreIncludeArray[] = array( '', '$parameterName', 'unset' );\n" );
 162  
 163                      $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameterData, false, array(),
 164                                                                            array( $namespaceValue, EZ_TEMPLATE_NAMESPACE_SCOPE_RELATIVE, $parameterName ) );
 165                      $variableList[] = $parameterName;
 166                  }
 167  
 168                  $actionParameters = array();
 169                  if ( $toolbarIni->hasGroup( "Tool_" . $tool ) )
 170                  {
 171                      $actionParameters = $toolbarIni->group( "Tool_" . $tool );
 172                  }
 173                  if ( $toolbarIni->hasGroup( "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement ) )
 174                  {
 175                      $actionParameters = array_merge( $actionParameters, $toolbarIni->group( "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement ) );
 176                  }
 177                  foreach ( array_keys( $actionParameters ) as $key )
 178                  {
 179                      $itemValue = $actionParameters[$key];
 180                      $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $itemValue, false, array(),
 181                                                                            array( $namespaceValue, EZ_TEMPLATE_NAMESPACE_SCOPE_RELATIVE, $key ) );
 182                      $variableList[] = $key;
 183                  }
 184  
 185                  // Add parameter tool_id and offset
 186                  $toolIDValue =  "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement;
 187                  $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $toolIDValue, false, array(),
 188                                                                        array( $namespaceValue, EZ_TEMPLATE_NAMESPACE_SCOPE_RELATIVE, "tool_id" ) );
 189                  $variableList[] = "tool_id";
 190  
 191                  $toolOffset = $placement;
 192                  $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $toolOffset, false, array(),
 193                                                                        array( $namespaceValue, EZ_TEMPLATE_NAMESPACE_SCOPE_RELATIVE, "offset" ) );
 194                  $variableList[] = "offset";
 195  
 196                  // Add parameter first, last and placement
 197                  $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $firstValue, false, array(),
 198                                                                        array( $namespaceValue, EZ_TEMPLATE_NAMESPACE_SCOPE_RELATIVE, "first" ) );
 199                  $variableList[] = "first";
 200  
 201                  $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $lastValue, false, array(),
 202                                                                        array( $namespaceValue, EZ_TEMPLATE_NAMESPACE_SCOPE_RELATIVE, "last" ) );
 203                  $variableList[] = "last";
 204  
 205                  $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $placementValue, false, array(),
 206                                                                        array( $namespaceValue, EZ_TEMPLATE_NAMESPACE_SCOPE_RELATIVE, "placement" ) );
 207                  $variableList[] = "placement";
 208  
 209                  $newNodes = array_merge( $newNodes, $includeNodes );
 210  
 211                  // Restore previous variables, before including
 212                  $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "foreach ( \$restoreIncludeArray as \$element )\n".
 213                                                                         "{\n".
 214                                                                         "    if ( \$element[2] === 'unset' )\n".
 215                                                                         "    {\n".
 216                                                                         "        unset( \$vars[\$element[0]][\$element[1]] );\n".
 217                                                                         "        continue;\n".
 218                                                                         "    }\n".
 219                                                                         "    \$vars[\$element[0]][\$element[1]] = \$element[2];\n".
 220                                                                         "}\n".
 221                                                                         "\$restoreIncludeArray = \$oldRestoreIncludeArray" . "_$uniqID;\n" );
 222              }
 223          }
 224          return $newNodes;
 225      }
 226  
 227      /*!
 228       Processes the function with all it's children.
 229      */
 230      function process( &$tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
 231      {
 232          $params = $functionParameters;
 233          switch ( $functionName )
 234          {
 235              case $this->BlockName:
 236              {
 237                  $viewMode = "full";
 238                  $name = $currentNamespace;
 239                  // Read ini file
 240                  $toolbarIni =& eZINI::instance( "toolbar.ini" );
 241  
 242                  if ( isset( $functionParameters["view"] ) )
 243                  {
 244                      $viewMode = $tpl->elementValue( $functionParameters["view"], $rootNamespace, $currentNamespace, $functionPlacement );
 245                  }
 246  
 247                  if ( isset( $functionParameters["name"] ) )
 248                  {
 249                      reset( $params );
 250                      $whatParamsShouldBeUnset = array();
 251                      $whatParamsShouldBeReplaced = array();
 252                      while ( ( $key = key( $params ) ) !== null )
 253                      {
 254                          $item =& $params[$key];
 255                          switch ( $key )
 256                          {
 257                              case "name":
 258                              case "view":
 259                                  break;
 260  
 261                              default:
 262                              {
 263                                  if ( !$tpl->hasVariable( $key, $name ) )
 264                                  {
 265                                      $whatParamsShouldBeUnset[] = $key; // Tpl vars should be removed after including
 266                                  }
 267                                  else
 268                                  {
 269                                      $whatParamsShouldBeReplaced[$key] = $tpl->variable( $key, $name ); // Tpl vars should be replaced after including
 270                                  }
 271  
 272                                  $item_value = $tpl->elementValue( $item, $rootNamespace, $currentNamespace, $functionPlacement );
 273                                  $tpl->setVariable( $key, $item_value, $name );
 274                              } break;
 275                          }
 276                          next( $params );
 277                      }
 278                      $toolbarPosition = $tpl->elementValue( $functionParameters["name"], $rootNamespace, $currentNamespace, $functionPlacement );
 279                      $definedVariables = array();
 280                      $toolbarName = "Toolbar_" . $toolbarPosition;
 281                      $toolArray = $toolbarIni->variable( $toolbarName, 'Tool' );
 282  
 283                      if ( !is_array( $toolArray ) )
 284                          $toolArray = array();
 285  
 286                      $actionParameters = array();
 287                      foreach ( array_keys( $toolArray ) as $toolKey )
 288                      {
 289                          $definedVariables = array();
 290                          $tool = $toolArray[$toolKey];
 291                          $placement = $toolKey + 1;
 292                          if ( $toolbarIni->hasGroup( "Tool_" . $tool ) )
 293                          {
 294                              $actionParameters = $toolbarIni->group( "Tool_" . $tool );
 295                          }
 296                          if ( $toolbarIni->hasGroup( "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement ) )
 297                          {
 298                              $actionParameters = array_merge( $actionParameters, $toolbarIni->group( "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement ) );
 299                          }
 300                          foreach ( array_keys( $actionParameters ) as $key )
 301                          {
 302                              $itemValue = $actionParameters[$key];
 303                              $tpl->setVariable( $key, $itemValue, $name );
 304                              $definedVariables[] = $key;
 305                          }
 306                          $toolIDValue =  "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement;
 307                          $tpl->setVariable( "tool_id", $toolIDValue, $name );
 308                          $definedVariables[] = "tool_id";
 309                          $toolOffset = $placement;
 310                          $tpl->setVariable( "offset", $toolOffset, $name );
 311                          $definedVariables[] = "offset";
 312                          $uri = "design:toolbar/$viewMode/$tool.tpl";
 313  
 314                          if ( $placement == 1 )
 315                          {
 316                              if ( count( $toolArray ) == 1 )
 317                              {
 318                                  $tpl->setVariable( "first", true );
 319                                  $tpl->setVariable( "last", true );
 320                                  $tpl->setVariable( "placement", "last" );
 321                                  $definedVariables[] = "first";
 322                                  $definedVariables[] = "last";
 323                                  $definedVariables[] = "placement";
 324                              }
 325                              else
 326                              {
 327                                  $tpl->setVariable( "first", true );
 328                                  $tpl->setVariable( "last", false );
 329                                  $tpl->setVariable( "placement", "first" );
 330                                  $definedVariables[] = "first";
 331                                  $definedVariables[] = "last";
 332                                  $definedVariables[] = "placement";
 333                              }
 334                          }
 335                          else if ( $placement == count( $toolArray ) )
 336                          {
 337                              $tpl->setVariable( "first", false );
 338                              $tpl->setVariable( "last", true );
 339                              $tpl->setVariable( "placement", "last" );
 340                              $definedVariables[] = "first";
 341                              $definedVariables[] = "last";
 342                              $definedVariables[] = "placement";
 343                          }
 344                          else
 345                          {
 346                              $tpl->setVariable( "first", false );
 347                              $tpl->setVariable( "last",  false );
 348                              $tpl->setVariable( "placement", "" );
 349                              $definedVariables[] = "placement";
 350                          }
 351                          $tpl->processURI( $uri, true, $extraParameters, $textElements, $name, $name );
 352                          // unset var
 353                          foreach ( $whatParamsShouldBeUnset as $key )
 354                          {
 355                              $tpl->unsetVariable( $key, $name );
 356                          }
 357                          // replace var
 358                          foreach ( $whatParamsShouldBeReplaced as $key => $item_value )
 359                          {
 360                              $tpl->setVariable( $key, $item_value, $name );
 361                          }
 362                      }
 363                  }
 364              }
 365          }
 366      }
 367  
 368      /*!
 369       Returns false.
 370      */
 371      function hasChildren()
 372      {
 373          return false;
 374      }
 375  }
 376  
 377  ?>


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