[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/classes/ -> ezcontentbrowse.php (source)

   1  <?php
   2  //
   3  // Definition of eZContentBrowse class
   4  //
   5  // Created on: <28-Apr-2003 11:04:47 sp>
   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 ezcontentbrowse.php
  30  */
  31  
  32  /*!
  33    \class eZContentBrowse ezcontentbrowse.php
  34    \brief Handles browsing of content in the node tree
  35  
  36    This class makes it easy to use the browse system to
  37    search for content objects or nodes. The class will take
  38    care of storing the necessary session variables and redirect
  39    to the browse page.
  40  
  41    Using it is simply to call the \link browse \endlink function with some parameters.
  42  
  43  \code
  44  eZContentBrowse::browse( array( 'action_name' => 'MyActionName' ), $module );
  45  \endcode
  46  
  47    It requires the module objects as the second parameter to redirect and the first
  48    define how the browse page should behave. Normally you just want to set \c action_name
  49    and define the behaviour of that action in settings/browse.ini.
  50  
  51  */
  52  
  53  include_once ( 'lib/ezutils/classes/ezhttptool.php' );
  54  
  55  class eZContentBrowse
  56  {
  57      /*!
  58       Initializes the object with the session data if they are found.
  59       If \a $params is supplied it used instead.
  60      */
  61      function eZContentBrowse( $params = false )
  62      {
  63          $http =& eZHTTPTool::instance();
  64          if ( !$params && $http->hasSessionVariable( 'BrowseParameters' ) )
  65          {
  66              $this->Parameters =& $http->sessionVariable( 'BrowseParameters' );
  67          }
  68          else
  69          {
  70              $this->Parameters = $params;
  71          }
  72      }
  73  
  74      /*!
  75       \return an array with attribute names.
  76      */
  77      function attributes()
  78      {
  79          return array_keys( $this->Parameters );
  80      }
  81  
  82      /*!
  83       \return true if the attribute name \a $attributeName is among the browse parameters.
  84      */
  85      function hasAttribute( $attributeName )
  86      {
  87          return array_key_exists( $attributeName, $this->Parameters );
  88      }
  89  
  90      /*!
  91       \return the attribute value of the attribute named \a $attributeName or \c null if no such attribute.
  92      */
  93      function &attribute( $attributeName )
  94      {
  95          if ( isset( $this->Parameters[$attributeName] ) )
  96              return $this->Parameters[$attributeName];
  97          else
  98          {
  99              eZDebug::writeError( "Attribute '$attributeName' does not exist", 'eZContentBrowse::attribute' );
 100              $attribute = null;
 101              return $attribute;
 102          }
 103      }
 104  
 105      /*!
 106       \static
 107       Sets some session data taken from \a $parameters and start the browse module by redirecting to it using \a $module.
 108       Most data will be automatically derived from the \c action_name value taken from settings/browse.ini, other
 109       values will override default values.
 110      */
 111      function browse( $parameters = array(), &$module )
 112      {
 113          $ini =& eZINI::instance( 'browse.ini' );
 114  
 115          if ( !isset( $parameters['action_name'] ) )
 116              $parameters['action_name'] = $ini->variable( 'BrowseSettings', 'DefaultActionName' );
 117  
 118          if ( !isset( $parameters['type'] ) )
 119              $parameters['type'] = $parameters['action_name']; //$ini->variable( $parameters['action_name'], 'BrowseType' );
 120  
 121          if ( !isset( $parameters['selection'] ) )
 122          {
 123              if ( $ini->hasVariable( $parameters['type'], 'SelectionType' ) )
 124                  $parameters['selection'] = $ini->variable( $parameters['type'], 'SelectionType' );
 125              else
 126                  $parameters['selection'] = $ini->variable( 'BrowseSettings', 'DefaultSelectionType' );
 127          }
 128  
 129          if ( !isset( $parameters['return_type'] ) )
 130          {
 131              if ( $ini->hasVariable( $parameters['type'], 'ReturnType' ) )
 132                  $parameters['return_type'] = $ini->variable( $parameters['type'], 'ReturnType' );
 133              else
 134                  $parameters['return_type'] = $ini->variable( 'BrowseSettings', 'DefaultReturnType' );
 135          }
 136  
 137          if ( !isset( $parameters['browse_custom_action'] ) )
 138              $parameters['browse_custom_action'] = false;
 139  
 140          if ( !isset( $parameters['custom_action_data'] ) )
 141              $parameters['custom_action_data'] = false;
 142  
 143          if ( !isset( $parameters['description_template'] ) )
 144              $parameters['description_template'] = false;
 145  
 146          if ( !isset( $parameters['start_node'] ) )
 147              $parameters['start_node'] = $ini->variable( $parameters['type'], 'StartNode' );
 148  
 149          if ( !isset( $parameters['ignore_nodes_select'] ) )
 150              $parameters['ignore_nodes_select'] = array();
 151  
 152          if ( !isset( $parameters['ignore_nodes_select_subtree'] ) )
 153              $parameters['ignore_nodes_select_subtree'] = array();
 154  
 155          if ( !isset( $parameters['ignore_nodes_click'] ) )
 156              $parameters['ignore_nodes_click'] = array();
 157  
 158          if ( !isset( $parameters['class_array'] ) )
 159          {
 160              if ( $ini->hasVariable( $parameters['type'], 'Class' ) )
 161              {
 162                  $parameters['class_array'] = $ini->variable( $parameters['type'], 'Class' );
 163              }
 164              else
 165              {
 166                  $parameters['class_array'] = false;
 167              }
 168          }
 169  
 170          if ( isset( $parameters['keys'] ) )
 171          {
 172              $overrideStartNode = false;
 173              foreach ( $parameters['keys'] as $key => $keyValue )
 174              {
 175                  $variableName = 'StartNode_' . $key;
 176                  if ( !$ini->hasVariable( $parameters['type'], $variableName ) )
 177                      continue;
 178                  $keyData = $ini->variable( $parameters['type'], $variableName );
 179                  if ( is_array( $keyValue ) )
 180                  {
 181                      foreach ( $keyValue as $keySubValue )
 182                      {
 183                          if ( isset( $keyData[$keySubValue] ) )
 184                              $overrideStartNode = $keyData[$keySubValue];
 185                      }
 186                  }
 187                  else if ( isset( $keyData[$keyValue] ) )
 188                  {
 189                      $overrideStartNode = $keyData[$keyValue];
 190                  }
 191                  if ( $overrideStartNode )
 192                      break;
 193              }
 194              if ( $overrideStartNode )
 195                  $parameters['start_node'] = $overrideStartNode;
 196          }
 197  
 198          if ( !isset( $parameters['persistent_data'] ) )
 199              $parameters['persistent_data'] = false;
 200  
 201          if ( !isset( $parameters['permission'] ) )
 202              $parameters['permission'] = false;
 203  
 204          if ( !isset( $parameters['top_level_nodes'] ) )
 205          {
 206              $parameters['top_level_nodes'] = $ini->variable( 'BrowseSettings', 'DefaultTopLevelNodes' );
 207              if ( $ini->hasVariable( $parameters['type'], 'TopLevelNodes' ) )
 208                  $parameters['top_level_nodes'] = $ini->variable( $parameters['type'], 'TopLevelNodes' );
 209          }
 210  
 211          if ( !is_numeric( $parameters['start_node'] ) )
 212              $parameters['start_node'] = eZContentBrowse::nodeAliasID( $parameters['start_node'] );
 213  
 214          for ( $i =0; $i < count( $parameters['top_level_nodes'] ); $i++ )
 215          {
 216              if ( !is_numeric( $parameters['top_level_nodes'][$i] ) )
 217                  $parameters['top_level_nodes'][$i] = eZContentBrowse::nodeAliasID( $parameters['top_level_nodes'][$i] );
 218          }
 219  
 220          if ( !isset( $parameters['cancel_page'] ) )
 221              $parameters['cancel_page'] = false;
 222  
 223          if ( !isset( $parameters['from_page'] ) )
 224              eZDebug::writeError( $parameters, 'eZContentBrowse::browse() $parameters[\'from_page\'] is not set' );
 225  
 226          $http =& eZHTTPTool::instance();
 227          $http->setSessionVariable( 'BrowseParameters', $parameters );
 228  
 229          if ( is_null( $module ) )
 230          {
 231              return "/content/browse/";
 232          }
 233          else
 234          {
 235              $module->redirectTo( "/content/browse/" );
 236              return "/content/browse/";
 237          }
 238      }
 239  
 240      /*!
 241       \static
 242       \return the node ID for the node alias \a $nodeName or \c false if no ID could be found.
 243      */
 244      function nodeAliasID( $nodeName )
 245      {
 246          if ( is_numeric( $nodeName ) )
 247              return $nodeName;
 248          $browseINI =& eZINI::instance( 'browse.ini' );
 249          $aliasList = $browseINI->variable( 'BrowseSettings', 'AliasList' );
 250          if ( isset( $aliasList[$nodeName] ) )
 251              return $aliasList[$nodeName];
 252          $contentINI =& eZINI::instance( 'content.ini' );
 253          if ( $nodeName == 'content' )
 254              return $contentINI->variable( 'NodeSettings', 'RootNode' );
 255          else if ( $nodeName == 'users' )
 256              return $contentINI->variable( 'NodeSettings', 'UserRootNode' );
 257          else if ( $nodeName == 'media' )
 258              return $contentINI->variable( 'NodeSettings', 'MediaRootNode' );
 259          else if ( $nodeName == 'setup' )
 260              return $contentINI->variable( 'NodeSettings', 'SetupRootNode' );
 261          else
 262              return false;
 263      }
 264  
 265      /*!
 266       Sets the node ID where browsing starts.
 267      */
 268      function setStartNode( $nodeID )
 269      {
 270          $this->Parameters['start_node'] = $nodeID;
 271      }
 272  
 273      /*!
 274       \static
 275       \return the result of the previous browse operation or \c false if no result was found.
 276               It uses the action name \a $actionName to determine which result to look for.
 277      */
 278      function result( $actionName, $asObject = false )
 279      {
 280          $ini =& eZINI::instance( 'browse.ini' );
 281          $isNodeSelection = $ini->variable( $actionName, 'ReturnType' ) == 'NodeID';
 282          if ( $isNodeSelection )
 283              $postName = 'SelectedNodeIDArray';
 284          else
 285              $postName = 'SelectedObjectIDArray';
 286          $http =& eZHTTPTool::instance();
 287          if ( $http->hasPostVariable( $postName ) && !$http->hasPostVariable( 'BrowseCancelButton' ) )
 288          {
 289              $postList = $http->postVariable( $postName );
 290              $list = array();
 291              foreach ( $postList as $value )
 292              {
 293                  if ( !is_numeric( $value ) )
 294                  {
 295                      eZDebug::writeError( "Non-numeric value ($value) found for POST variable $postName for browse action '$actionName', the value will be excluded",
 296                                           'eZContentBrowse::result' );
 297                      continue;
 298                  }
 299                  // Append the value as a real integer, avoids XSS problems.
 300                  $intValue = (int)$value;
 301                  if ( $value != $intValue )
 302                  {
 303                      eZDebug::writeError( "Non-integer value ($value) found for POST variable $postName for browse action '$actionName', the value will be excluded",
 304                                           'eZContentBrowse::result' );
 305                      continue;
 306                  }
 307                  $list[] = $intValue;
 308              }
 309              return array_unique( $list );
 310          }
 311          return false;
 312      }
 313  
 314      /// \privatesection
 315      /// The browse parameters.
 316      var $Parameters = false;
 317  }
 318  
 319  ?>


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