[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/sitemgr/inc/ -> class.Content_BO.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare SiteMgr - Web Content Management                              *
   4      * http://www.egroupware.org                                                *
   5      * --------------------------------------------                             *
   6      *  This program is free software; you can redistribute it and/or modify it *
   7      *  under the terms of the GNU General Public License as published by the   *
   8      *  Free Software Foundation; either version 2 of the License, or (at your  *
   9      *  option) any later version.                                              *
  10      \**************************************************************************/
  11  
  12      /* $Id: class.Content_BO.inc.php 20295 2006-02-15 12:31:25Z  $ */
  13  
  14  require_once (EGW_INCLUDE_ROOT . SEP . 'sitemgr' . SEP . 'inc' . SEP . 'class.module.inc.php');
  15  
  16  define('SITEMGR_STATE_DRAFT',0);
  17  define('SITEMGR_STATE_PREPUBLISH',1);
  18  define('SITEMGR_STATE_PUBLISH',2);
  19  define('SITEMGR_STATE_PREUNPUBLISH',3);
  20  define('SITEMGR_STATE_ARCHIVE',4);
  21  
  22  define('SITEMGR_VIEWABLE_EVERBODY',0);
  23  define('SITEMGR_VIEWABLE_USER',1);
  24  define('SITEMGR_VIEWABLE_ADMIN',2);
  25  define('SITEMGR_VIEWABLE_ANONYMOUS',3);
  26  
  27      class Content_BO
  28      {
  29          var $so;
  30  
  31  		function Content_BO()
  32          {
  33              $this->so =& CreateObject('sitemgr.Content_SO', true);
  34          }
  35  
  36  		function getContentAreas()
  37          {
  38              $templatedir =  $GLOBALS['Common_BO']->sites->current_site['site_dir'] .  SEP . 'templates' .
  39                  SEP . $GLOBALS['Common_BO']->sites->current_site['themesel'] . SEP;
  40  
  41              if (file_exists($templatefile = $templatedir . 'main.tpl'))
  42              {
  43                  $str = implode('', @file($templatefile));
  44                  if (preg_match_all("/\{contentarea:([^{ ]+)\}/",$str,$matches))
  45                  {
  46                      return $matches[1];
  47                  }
  48                  else
  49                  {
  50                      return lang('No content areas found in selected template');
  51                  }
  52              }
  53              elseif (file_exists($templatefile = $templatedir . 'index.php'))  // mambo open source template
  54              {
  55                  $str = implode('', @file($templatefile));
  56                  if (preg_match_all("/(mosLoadModules|include|include_once|require|require_once)[ (\"']+([^\"']+)/",$str,$matches))
  57                  {
  58                      $matches = $matches[2];
  59                      $conversation = array('includes/footer.php' => 'footer','mainbody.php'=>'center','mainmenu.php'=>'mainmenu');
  60                      foreach($matches as $n => $name)
  61                      {
  62                          if (substr($name,-4) == '.php')
  63                          {
  64                              if (!isset($conversation[$name]))
  65                              {
  66                                  unset($matches[$n]);
  67                              }
  68                              else
  69                              {
  70                                  $matches[$n] = $conversation[$name];
  71                              }
  72                          }
  73                      }
  74                      //echo "<p>getContentAreas($templatefile)=".implode(',',$matches)."</p>";
  75                      return $matches;
  76                  }
  77                  else
  78                  {
  79                      return lang('No content areas found in selected template');
  80                  }
  81              }
  82              else
  83              {
  84                  return lang('No template file found.');
  85              }
  86          }
  87  
  88  
  89  		function addblock($block)
  90          {
  91              $permittedmoduleids = array_keys($GLOBALS['Common_BO']->modules->getcascadingmodulepermissions($block->area,$block->cat_id));
  92              $module = $GLOBALS['Common_BO']->modules->getmodule($block->module_id);
  93  
  94              if ($GLOBALS['Common_BO']->acl->can_write_category($block->cat_id) &&
  95                  in_array($block->module_id,$permittedmoduleids) &&
  96                  $GLOBALS['Common_BO']->modules->createmodule($module['module_name']))
  97              {
  98                  return $this->so->addblock($block);
  99              }
 100              else
 101              {
 102                  return false;
 103              }
 104          }
 105  
 106  		function createversion($blockid)
 107          {
 108              return $this->so->createversion($blockid);
 109          }
 110  
 111  		function deleteversion($versionid,$force=False)
 112          {
 113              if (!$force)
 114              {
 115                  $blockid = $this->so->getblockidforversion($versionid);
 116                  if (!$blockid)
 117                  {
 118                      return false;
 119                  }
 120                  $block = $this->so->getblockdef($blockid);
 121                  if (!($block && $GLOBALS['Common_BO']->acl->can_write_category($block->cat_id)))
 122                  {
 123                      return false;
 124                  }
 125              }
 126              return $this->so->deleteversion($versionid);
 127          }
 128  
 129  		function removeBlocksInPageOrCat($cat_id,$page_id,$force=False)
 130          {
 131              if (!($force || $GLOBALS['Common_BO']->acl->can_write_category($cat_id)))
 132              {
 133                  return false;
 134              }
 135              $blocks = $this->so->getblocksforscope($cat_id,$page_id);
 136              while(list($blockid,) = each($blocks))
 137              {
 138                  $this->removeblock($blockid,True);
 139              }
 140          }
 141  
 142  		function removeblock($blockid,$force=False)
 143          {
 144              if (!$force)
 145              {
 146                  $block = $this->so->getblockdef($blockid);
 147                  if (!($block && $GLOBALS['Common_BO']->acl->can_write_category($block->cat_id)))
 148                  {
 149                      return false;
 150                  }
 151              }
 152              if ($this->so->removeblock($blockid))
 153              {
 154                  $versions = $this->so->getversionidsforblock($blockid);
 155                  while(list(,$versionid) = @each($versions))
 156                  {
 157                      //since we already did the ACL we force
 158                      $this->deleteversion($versionid,True);
 159                  }
 160                  return true;
 161              }
 162              return false;
 163          }
 164  
 165          //the next two functions retrieves all blocks for a certain area, if (cat_id = $site_id and page_id = 0), only site-wide blocks are retrieved.
 166          //if (cat_id != $site_id and page_id is 0), site-wide blocks and all blocks for the category and all its ancestor categories are retrieved.
 167          //if page_id is non zero, cat_id should be the page's category. Page blocks + category blocks + site blocks are retrieved.
 168          //there is no ACL, since these functions are called in a context where getcategory and getpage have been called before and would have intercepted a breach
 169          function &getvisibleblockdefsforarea($area,$cat_id,$page_id,$isadmin,$isuser)
 170          {
 171              $cat_ancestorlist = ($cat_id != CURRENT_SITE_ID) ? 
 172                  $GLOBALS['Common_BO']->cats->getCategoryancestorids($cat_id,True) : 
 173                  False;
 174              return $this->so->getvisibleblockdefsforarea($area,$cat_ancestorlist,$page_id,$isadmin,$isuser);
 175          }
 176  
 177          function &getallblocksforarea($area,$cat_id,$page_id,$lang)
 178          {
 179              $cat_ancestorlist = ($cat_id != CURRENT_SITE_ID) ? 
 180                  $GLOBALS['Common_BO']->cats->getCategoryancestorids($cat_id,True) : 
 181                  False;
 182              return $this->so->getallblocksforarea($area,$cat_ancestorlist,$page_id,$lang);
 183          }
 184  
 185          function &getcommitableblocks()
 186          {
 187              return $this->so->getallblocks($GLOBALS['Common_BO']->cats->getpermittedcatsWrite(),$GLOBALS['Common_BO']->getstates('Commit'));
 188          }
 189  
 190          function &getarchivedblocks()
 191          {
 192              return $this->so->getallblocks($GLOBALS['Common_BO']->cats->getpermittedcatsWrite(),$GLOBALS['Common_BO']->getstates('Archive'));
 193          }
 194  		function getallversionsforblock($blockid,$lang)
 195          {
 196              return $this->so->getallversionsforblock($blockid,$lang);
 197          }
 198  
 199          function &getblock($id,$lang)
 200          {
 201              //do we need ACL here, since we have ACL when getting the block lists, we could do without it here?
 202              return $this->so->getblock($id,$lang);
 203          }
 204  
 205  		function getlangblocktitle($block_id,$lang=false)
 206          {
 207                  return $this->so->getlangblocktitle($block_id,$lang);
 208          }
 209  
 210  		function getlangarrayforblocktitle($block_id)
 211          {
 212              return $this->so->getlangarrayforblocktitle($block_id);
 213          }
 214  
 215  		function getlangarrayforversion($version_id)
 216          {
 217              return $this->so->getlangarrayforversion($version_id);
 218          }
 219  
 220          //this function retrieves blocks only for a certain scope (site-wide, specific to one category or specific to one page), 
 221          //but for all areas.
 222          function &getblocksforscope($cat_id,$page_id)
 223          {
 224              if ($cat_id && !$GLOBALS['Common_BO']->acl->can_read_category($cat_id))
 225              {
 226                  return array();
 227              }
 228              else
 229              {
 230                  return $this->so->getblocksforscope($cat_id,$page_id);
 231              }
 232          }
 233  
 234  		function getversion($version_id,$lang=False)
 235          {
 236              //TODO: add ACL ?
 237              return $this->so->getversion($version_id,$lang);
 238          }
 239  
 240  		function saveblockdata($block,$data,$state,$lang,$scope=False)
 241          {
 242              $oldblock = $this->so->getblockdef($block->id);
 243              if (!($oldblock && $GLOBALS['Common_BO']->acl->can_write_category($oldblock->cat_id)))
 244              {
 245                  return array(lang("You are not entitled to edit block %1",$block->id));
 246              }
 247  
 248              $this->so->saveblockdata($block);
 249              $this->so->saveblockdatalang($block->id,$block->title,$lang);
 250              $this->NotifyUsers($lang, $oldblock->page_id,$oldblock->cat_id,$state,$block->id,$block->title);
 251              if ($scope)
 252              {
 253                  list($cat_id,$page_id) = explode(',',$scope);
 254                  if ($oldblock->cat_id != $cat_id || $oldblock->page_id != $page_id)
 255                  {
 256                      if ($GLOBALS['Common_BO']->acl->can_write_category($cat_id))
 257                      {
 258                          $this->so->updatescope($block->id,$cat_id,$page_id);
 259                      }
 260                      else
 261                      {
 262                          $validationerrors[] = lang("You are not entitled to change the scope of block %1 to Cat %2 and Page %3",$block->id,$cat_id,$page_id);
 263                      }
 264                  }
 265              }
 266              if (is_array($state) && !$this->saveversionstate($block->id,$state))
 267              {
 268                  $validationerrors[] = lang('There can only be one version in (pre(un))published state, with the one exeption that one prepublished version can coexist with one preunpublished version');
 269              }
 270              $moduleobject =& $this->getblockmodule($block->id);
 271  
 272              // we need to loop over the stats (and not the data) as empty checkboxes dont return any data !!!
 273              // so the empty state would not get saved, if there are only empty checkboxes.
 274              foreach($state as $versionid => $s)
 275              {
 276                  $versiondata = isset($data[$versionid]) ? $data[$versionid] : array();
 277  
 278                  if ($moduleobject->validate($versiondata))
 279                  {
 280                      if ($this->saveversiondatalang($block->id,$versionid,$versiondata['i18n'],$lang))
 281                      {
 282                          unset($versiondata['i18n']);
 283                          $this->so->saveversiondata($block->id,$versionid,$versiondata);
 284                      }
 285                  }
 286                  if ($moduleobject->validation_error)
 287                  {
 288                      $validationerrors[] = $moduleobject->validation_error;
 289                  }
 290              }
 291              return $validationerrors ? $validationerrors : True;
 292          }
 293  
 294  		function saveblockdatalang($block,$data,$lang)
 295          {
 296              $oldblock = $this->so->getblockdef($block->id);
 297              if (!($oldblock && $GLOBALS['Common_BO']->acl->can_write_category($oldblock->cat_id)))
 298              {
 299                  return lang("You are not entitled to edit block %1",$block->id);
 300              }
 301              $this->so->saveblockdatalang($block->id,$block->title,$lang);
 302  
 303              $this->NotifyUsers($lang, $oldblock->page_id, $oldblock->cat_id,-1,$block->id,$block->title);
 304              $moduleobject =& $this->getblockmodule($block->id);
 305              while (list($versionid,$versiondata) = @@each($data))
 306              //TODO: check if version really belongs to block
 307              {
 308                  if ($moduleobject->validate($versiondata))
 309                  {
 310                      $this->saveversiondatalang($block->id,$versionid,$versiondata['i18n'],$lang);
 311                  }
 312                  else
 313                  {
 314                      $validationerrors[] = $moduleobject->validation_error;
 315                  }
 316              }
 317              return $validationerrors ? $validationerrors : True;
 318          }
 319  
 320          //takes the array (version_id => version_state) posted from the UI as argument
 321          //and checks if there is only one in (pre(un))published state 
 322          //(exeption one prepublished, and one preunpublished can coexsit)
 323  		function saveversionstate($block_id,$state)
 324          {
 325              $count_array = array_count_values($state);
 326              $active_versions = $count_array[SITEMGR_STATE_PREPUBLISH] + 
 327                  $count_array[SITEMGR_STATE_PUBLISH] + 
 328                  $count_array[SITEMGR_STATE_PREUNPUBLISH];
 329              if (($active_versions < 2) || (($active_versions == 2) && ($count_array[SITEMGR_STATE_PUBLISH] == 0)))
 330              {
 331                  while (list($versionid,$versionstate) = each($state))
 332                  {
 333                      $this->so->saveversionstate($block_id,$versionid,$versionstate);
 334                  }
 335                  return true;
 336              }
 337              else
 338              {
 339                  return false;
 340              }
 341          }
 342  
 343  		function saveversiondatalang($block_id,$version_id,$data,$lang)
 344          {
 345              return ($this->so->getblockidforversion($version_id) == $block_id) ?
 346                  $this->so->saveversiondatalang($version_id,$data,$lang) :
 347                  false;
 348          }
 349  
 350          //this function can be called from a block's get_content function. It stores modification to the 
 351          //blocks arguments in the database
 352  		function savepublicdata(&$block)
 353          {
 354              //TODO: check if argument is public, disentangle session data from arguments
 355              $this->so->saveversiondata($block->id,$block->version,$block->arguments);
 356          }
 357  
 358          function &getblockmodule($blockid)
 359          {
 360              $block = $this->so->getblockdef($blockid);
 361              return $GLOBALS['Common_BO']->modules->createmodule($block->module_name);
 362          }
 363  
 364  		function commit($block_id)
 365          {
 366              $block = $this->so->getblockdef($block_id);
 367              if ($GLOBALS['Common_BO']->acl->can_write_category($block->cat_id))
 368              {
 369                  $this->so->commit($block_id);
 370              }
 371          }
 372  
 373  		function reactivate($block_id)
 374          {
 375              $block = $this->so->getblockdef($block_id);
 376              if ($GLOBALS['Common_BO']->acl->can_write_category($block->cat_id))
 377              {
 378                  $this->so->reactivate($block_id);
 379              }
 380          }
 381  		function NotifyUsers($lang, $page_id,$cat_id,$state,$block_id,$block_name)
 382          {
 383              if (empty($cat_id)) {
 384                  $bl=$this->so->getblockdef($block_id);
 385                  $cat_id=$bl->cat_id;
 386              }
 387              if ($state<0) {
 388                  $state=$this->so->getblockstate($block_id,$lang);
 389              }
 390  
 391              $bo=CreateObject("sitemgr.notification_bo");
 392              $bo->notify_users($GLOBALS['Common_BO']->sites->current_site['site_id'],
 393                  $cat_id,
 394                  $state,
 395                  $lang,
 396                  $GLOBALS['Common_BO']->sites->current_site['sitelanguages']['0'],
 397                  array('page_id'=>$page_id,'lang'=>$lang),
 398                  array(
 399                      array('text'=>"Block name:",'translate'=>True),
 400                      " ",$block_name
 401                  )
 402              );
 403          }
 404      }
 405  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7