[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/inc/ -> class.website.php (source)

   1  <?php
   2  /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
   3  /*
   4  # ***** BEGIN LICENSE BLOCK *****
   5  # This file is part of Plume CMS, a website management application.
   6  # Copyright (C) 2001-2005 Loic d'Anterroches and contributors.
   7  #
   8  # Plume CMS is free software; you can redistribute it and/or modify
   9  # it under the terms of the GNU General Public License as published by
  10  # the Free Software Foundation; either version 2 of the License, or
  11  # (at your option) any later version.
  12  #
  13  # Plume CMS is distributed in the hope that it will be useful,
  14  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  # GNU General Public License for more details.
  17  #
  18  # You should have received a copy of the GNU General Public License
  19  # along with this program; if not, write to the Free Software
  20  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  21  #
  22  # ***** END LICENSE BLOCK ***** */
  23  
  24  require_once dirname(__FILE__).'/class.l10n.php';
  25  require_once dirname(__FILE__).'/../extinc/class.recordset.php';
  26  
  27  /**
  28   * Storage of a website.
  29   *
  30   * A website is not like the other resources as it needs some files
  31   * on disc to run (the configuration, the templates).
  32   * The result is that it is a little more complex to manage, thus this
  33   * Website class has more methods than for example the News class.
  34   * On the other side, it is still possible to use the standard methods
  35   * like set(), check(), commit(), remove() with all the ugly work
  36   * being hidden in background.
  37   */
  38  class Website extends recordset
  39  {
  40      /**
  41       * Constructor
  42       *
  43       * @param Array Data from a possible SQL query ('')
  44       */
  45      function Website($data='')
  46      {
  47          parent::recordset($data);
  48      }
  49  
  50  
  51      /**
  52       * Generate an id for a website from its web address.
  53       *
  54       * Not always unique.
  55       *
  56       * @param string Website address
  57       * @return string Id
  58       */
  59      function generateId($address)
  60      {
  61          return substr(preg_replace('/[^A-Za-z0-9]/', '', $address), 4); 
  62      }
  63  
  64      /**
  65       * Set the data of the website.
  66       *
  67       * @param string Name
  68       * @param string Description
  69       * @param string Format of the description
  70       * @param string Lang of the site 
  71       * @param string Website address
  72       * @param string Website path on the file system
  73       * @param string Website xmedia address
  74       * @param string Website xmedia path on the file system
  75       * @return bool True
  76       */
  77      function set($name, $description, $format, $lang, $address,
  78                   $path, $xmedia, $xmedia_path)
  79      {
  80          $this->setField('website_name', trim($name));
  81          $this->setField('website_description', 
  82                          '='.$format."\n".trim($description));
  83          $this->setField('website_lang', $lang);
  84  
  85          $address = preg_replace('#(/)+$#', '', trim($address));
  86          $this->setField('website_url', $address);
  87  
  88          $path = preg_replace('#(/)+$#', '', trim($path));
  89          $this->setField('website_path', files::real_path($path));
  90  
  91          $xmedia = preg_replace('#(/)+$#', '', trim($xmedia));
  92          $this->setField('website_xmedia_url', $xmedia);
  93  
  94          $xmedia_path = preg_replace('#(/)+$#', '', trim($xmedia_path));
  95          $this->setField('website_xmedia_path', files::real_path($xmedia_path));
  96          
  97          return true;
  98      }
  99  
 100      /**
 101       * Check if the given website is valid.
 102       *
 103       * In case of failure the error message is set.
 104       *
 105       * @return bool Success
 106       */
 107      function check()
 108      {
 109          if ((strlen($this->f('website_xmedia_path')) == 0)
 110              or !file_exists($this->f('website_xmedia_path'))) {
 111              $this->setError(sprintf(__('The provided file and image folder %s is not available. Please check the folder you gave.'), 
 112                                      $this->f('website_xmedia_path')), 
 113                              400);
 114          }
 115          if ((strlen($this->f('website_path')) == 0)
 116              or !file_exists($this->f('website_path'))) {
 117              $this->setError(sprintf(__('The document root folder of the website %s is not available. Please check the folder you gave.'), 
 118                                      $this->f('website_path')), 
 119                              400);
 120          }
 121          if (2 != strlen($this->f('website_lang'))) {
 122              $this->setError(__('The website language must be composed of the 2 ISO standard letters, for example de (German), fr (French), jp (Japanese).'), 
 123                              400);
 124          }
 125          if (0 == strlen($this->f('website_url'))) {
 126              $this->setError(__('You must give a website address.'), 400);
 127          }
 128          if (0 == strlen($this->f('website_xmedia_url'))) {
 129              $this->setError(__('You must give the URL to the file and image folder.'), 400);
 130          }
 131          if (0 != strlen($this->f('website_url')) and 
 132              !preg_match('#^(http|https)://#i', $this->f('website_address'))) {
 133              $this->setError(__('The website address must start with http(s)://.'), 400);
 134          }
 135          if (0 == strlen($this->f('website_xmedia_url')) and
 136              !preg_match('#^(http|https)://#i', $this->f('website_xmedia'))) {
 137              $this->setError(__('The URL to the file and image folder must start with http(s)://.'), 400);
 138          }
 139          if (0 == strlen(text::getRawContent($this->f('website_description')))) {
 140              $this->setError(__('You must provide a website description.'),
 141                              400);
 142          }
 143          if (0 == strlen($this->f('website_name'))) {
 144              $this->setError(__('You must give a website name.'), 400);
 145          }
 146  
 147          if (false !== $this->error(true, false)) {
 148              return false;
 149          }
 150          return true;
 151      }
 152  
 153      /**
 154       * Check the rights on the files and folders.
 155       *
 156       * As some hosting environments are not providing the necessary rights
 157       * to write files and create folders, the check of those rights must be
 158       * done separately to have the possibility to install without touching
 159       * the files, and then do the file installation by hand.
 160       *
 161       * @return bool Success
 162       */
 163      function checkFileRights()
 164      {
 165          if ((strlen($this->f('website_xmedia_path')) != 0)
 166              && file_exists($this->f('website_xmedia_path')) 
 167              && !is_writable($this->f('website_xmedia_path'))) {
 168              $this->setError(sprintf(__('The system has no write access to the file and image folder %s. Check the permissions on the server.'), 
 169                                      $this->f('website_xmedia_path')), 
 170                              400);
 171          }
 172          if ((strlen($this->f('website_path')) != 0)
 173              && file_exists($this->f('website_path')) 
 174              && !is_writable($this->f('website_path'))) {
 175              $this->setError(sprintf(__('The system has no write access to the document root folder %s. Check the permissions on the server.'), 
 176                                      $this->f('website_path')), 
 177                              400);
 178          }
 179          if (!is_writable(dirname(__FILE__).'/../conf/')) {
 180              $this->setError(__('The system has no write access to the configuration folder manager/conf/. Check the permissions on the server.'), 400);
 181          }
 182          if (!is_writable(dirname(__FILE__).'/../templates/')) {
 183              $this->setError(__('The system has no write access to the template folder manager/templates/. Check the permissions on the server.'), 400);
 184          }
 185  
 186          if (false !== $this->error(true, false)) {
 187              return false;
 188          }
 189          return true;
 190      }
 191  
 192      /**
 193       * Save the website.
 194       *
 195       * It is possible to only save the data into the database without touching
 196       * the configuration files.
 197       * As during the process many files need to be updated a log is created and
 198       * it is possible to have the list of files to move/update by hand if
 199       * needed and not the rights to do it.
 200       *
 201       * @param &array Associative array with the log of the process
 202       * @param bool Save only in the database (True)
 203       * @return bool Success
 204       */
 205      function commit(&$log, $only_in_db=true)
 206      {
 207          $log = array();
 208  
 209          if (false == $this->check()) {
 210              return false;
 211          }
 212          if (!$only_in_db and false == $this->checkFileRights()) {
 213              return false;
 214          }
 215  
 216          // Check if update or new website
 217          $update = true;
 218          if (0 == strlen($this->f('website_id'))) {
 219              $this->setField('website_id', 
 220                              $this->generateId($this->f('website_url')));
 221              $update = false;
 222          }
 223          $website_exists = $this->website_exists($this->f('website_id'));
 224          if ($website_exists === false) {
 225              return false;
 226          }
 227          if ($new_site and $website_exists == $this->f('website_id')) {
 228              $this->setError(sprintf(__('Adding a new website with id %s, but a website with this id already exists.'), $this->f('website_id')), 500);
 229              return false;
 230          }
 231          if ($website_exists === '') {
 232              $update = false;
 233          }
 234  
 235          $this->getConnection();
 236  
 237          if ($update) {
 238              $req = 'UPDATE '.$this->con->pfx.'websites SET ';
 239          } else {
 240              $req = 'INSERT INTO '.$this->con->pfx.'websites SET
 241                   website_id =\''.$this->con->esc($this->f('website_id')).'\',
 242                   website_startdate = \''.date::stamp().'\', ';
 243          }
 244          $req .= 'website_name = \''.$this->con->esc($this->f('website_name')).'\',
 245               website_url = \''.$this->con->esc($this->f('website_url')).'\',
 246               website_reurl = \''.$this->con->esc($this->f('website_reurl')).'\',
 247               website_path = \''.$this->con->esc($this->f('website_path')).'\',
 248               website_xmedia_reurl = \''.$this->con->esc($this->f('website_xmedia_reurl')).'\',
 249               website_xmedia_path = \''.$this->con->esc($this->f('website_xmedia_path')).'\',
 250               website_description = \''.$this->con->esc($this->f('website_description')).'\' ';
 251          if ($update) {
 252              $req .= 'WHERE website_id =\''.$this->con->esc($this->f('website_id')).'\'';
 253          }
 254  
 255          if (!$this->con->execute($req)) {
 256              $this->setError('MySQL: '.$this->con->error(), 500);
 257              return false;
 258          }
 259  
 260  
 261          if (!$update) {
 262              include_once dirname(__FILE__).'/lib.auth.php';
 263              // As this user adds the site, give him root access to it
 264              $insReq = 'INSERT INTO '.$this->con->pfx.'grants SET
 265                  website_id =\''.$this->con->escapeStr($id).'\',
 266                  user_id = \''.$this->con->escapeStr($this->user->_userid).'\',
 267                  level = \''.PX_AUTH_ADMIN.'\'';
 268  
 269              if (!$this->con->execute($insReq)) {
 270                  $this->setError('MySQL: '.$this->con->error(), 500);
 271                  return false;
 272              }
 273  
 274              // Add the root category
 275              $hp_title = __('Home Page');
 276              $hp_desc = __('Root category, that plays the role of homepage.');
 277              $hp_kw = __('homepage, index, default');
 278              $insReq='INSERT INTO '.$this->con->pfx.'categories SET
 279                  website_id=\''.$this->con->escapeStr($id).'\',
 280                  category_name=\''.$this->con->escapeStr($hp_title).'\',
 281                  category_description=\''.$this->con->escapeStr($hp_desc).'\',
 282                  category_keywords=\''.$this->con->escapeStr($hp_kw).'\',
 283                  category_path=\'/\',
 284                  category_publicationdate=\''.timestamp().'\',
 285                  category_creationdate=\''.timestamp().'\',
 286                  category_enddate=99991231235959,
 287                  category_template=\'category_homepage.php\',
 288                  category_type=\'default\',
 289                  category_cachetime=86400';
 290              if (!$this->con->execute($insReq)) {
 291                  $this->setError('MySQL : '.$this->con->error(), 500);
 292                  return false;
 293              }
 294              if (false == ($catid = $this->con->getLastID())) {
 295                  $this->setError('MySQL: '.$this->con->error(), 500);
 296                  return false;
 297              }
 298              $updReq = 'UPDATE '.$this->con->pfx.'categories SET 
 299                  category_parentid=\''.$this->con->escapeStr($catid).'\'
 300                  WHERE category_id = \''.$this->con->escapeStr($catid).'\'';
 301  
 302              if (!$this->con->execute($updReq)) {
 303                  $this->setError('MySQL: '.$this->con->error(), 500);
 304                  return false;
 305              }
 306              // Add 2 default subtypes
 307  
 308              if (false === $this->saveType('', 'articles', __('Article'), 
 309                                            'resource_article.php', 3600, '', '',
 310                                            $id)) {
 311                  return false;
 312              }
 313              if (false === $this->saveType('', 'news', __('News'), 
 314                                            'resource_news.php', 3600, '1', '', 
 315                                            $id)) {
 316                  return false;
 317              }
 318  
 319  
 320  
 321      }
 322  
 323      /**
 324       * Check if a website with a given id exists.
 325       *
 326       * @param string Id
 327       * @return mixed Id of the website if exists, empty string if not existing
 328       *               false if error
 329       */
 330      function website_exists($id)
 331      {
 332          $this->getConnection();
 333          if (($rs = $this->con->select(SQL::getWebsite($id))) !== false) {
 334              if ($rs->nbRow() > 0) {
 335                  return $rs->f('website_id');
 336              } else {
 337                  return '';
 338              }
 339          } else {
 340              $this->setError('MySQL: '.$this->con->error(), 500);
 341              return false;
 342          }
 343  
 344      }
 345  }
 346  
 347  //if (false) {
 348  
 349      /**
 350       * Save a site or create a new one. If $id is empty, a new site 
 351       * is created and the log of the creation is set in &$log_new_site. 
 352       * The log is pure HTML ready for display.
 353       */
 354      function saveSite($id, $name, $description, $sitelang, $website_address, $website_path, $xmedia_name, &$log_new_site, $force_new_id='')
 355      {
 356          include_once dirname(__FILE__).'/../extinc/class.configfile.php';
 357          include_once dirname(__FILE__).'/class.checklist.php';
 358          global $_PX_config;
 359  
 360          $update = (empty($id)) ? false : true;
 361          $xmedia_path = '';
 362          if (!empty($website_path) && !empty($xmedia_name))
 363              $xmedia_path = files::real_path($website_path).'/'.$xmedia_name;
 364          $parsedurl = parse_url($website_address);
 365  
 366          if ($update) {
 367              // check the data if $update
 368              if (0 == strlen(trim($id))) {
 369                  $this->setError( __('Error: Internal error, please report your actions leading to this error message.'),500);
 370              }
 371              if (preg_match('/[^A-Za-z0-9]/', $id)) {
 372                  $this->setError( __('Error: Internal error, please report your actions leading to this error message.'),500);
 373              }
 374          }
 375  
 376          // get the website with this id
 377          if (empty($id)) {
 378              if (!empty($force_new_id)) $id = $force_new_id; //to be able to force the first site with the "default" id.
 379              else $id = substr(preg_replace('/[^A-Za-z0-9]/', '', $website_address), 4); //new id from the address (without http but the s)
 380          }
 381  
 382          $site = $this->getSites($id);
 383  
 384          if ($update) {
 385              if (!file_exists(dirname(__FILE__).'/../conf/configweb_'.$id.'.php') || !is_writable(dirname(__FILE__).'/../conf/configweb_'.$id.'.php')) {
 386                  $this->setError(sprintf( __('Error: The configuration file %s is not writeable.'), files::real_path(dirname(__FILE__).'/../conf/').'/configweb_'.$id.'.php'), 500);
 387                  return false;
 388              }
 389              if ($site->nbRow() == 0) {
 390                  $this->setError( __('This site is not available.') , 400);
 391                  return false;
 392              }
 393  
 394          } else {
 395              // check if this website already exists
 396              if ($site->nbRow() >= 1) {
 397                  $this->setError( __('Error: Id already used.') , 400);
 398                  return false;
 399              }
 400              // need to create a new file
 401              // copy paste the config_default.php
 402              if (!is_writable(dirname(__FILE__).'/../conf/')) {
 403                  $this->setError(sprintf( __('Error: The configuration folder %s is not writeable.'),
 404                                           files::real_path(dirname(__FILE__).'/../conf/')), 500);
 405                  return false;
 406              }
 407              $source_file      = dirname(__FILE__).'/../conf/configweb_default.copy.php';
 408              $destination_file = dirname(__FILE__).'/../conf/configweb_'.$id.'.php';
 409              if (file_exists($destination_file)) {
 410                  @unlink ($destination_file);
 411              }
 412              if (!copy($source_file, $destination_file)) {
 413                  $this->setError( __('Error: Impossible to create the configuration file.') , 500);
 414                  return false;
 415              }
 416              @chmod($destination_file, 0666);
 417  
 418          }
 419          // open file for edition of the data
 420          $cfg = new configfile(dirname(__FILE__).'/../conf/configweb_'.$id.'.php');
 421          $cfg->prefix = '_PX_website_config';
 422          $cfg->editVar('website_id',    (string) $id);
 423          $cfg->editVar('xmedia_root',   (string) $xmedia_path);
 424          $cfg->editVar('domain',        (string) $domain);
 425          $cfg->editVar('rel_url',       (string) $reurl);
 426          $cfg->editVar('rel_url_files', (string) $xmedia_reurl);
 427          $cfg->editVar('secure',        (bool)   $secure);
 428          $cfg->editVar('lang',          (string) $sitelang);
 429  
 430          if (!$cfg->saveFile()) {
 431              $this->setError( __('Error: Impossible to create the configuration file.') , 500);
 432              return false;
 433          }
 434          // no update or add in the db
 435          if ($update) {
 436              $insReq = 'UPDATE '.$this->con->pfx.'websites SET ';
 437          } else {
 438              $insReq = 'INSERT INTO '.$this->con->pfx.'websites SET
 439                                            website_id =\''.$this->con->escapeStr($id).'\',
 440                                            website_startdate = \''.timestamp().'\', ';
 441          }
 442          $securestring = $secure ? 's' : '';
 443          $insReq .= 'website_name   = \''.$this->con->escapeStr($name).'\', ';
 444          $insReq .= 'website_url    = \''.$this->con->escapeStr('http'.$securestring.'://'.$domain.$reurl).'\', ';
 445          $insReq .= 'website_reurl  = \''.$this->con->escapeStr($reurl).'\', ';
 446          $insReq .= 'website_path   = \''.$this->con->escapeStr('').'\', ';
 447          $insReq .= 'website_xmedia_reurl   = \''.$this->con->escapeStr($xmedia_reurl).'\', ';
 448          $insReq .= 'website_xmedia_path   = \''.$this->con->escapeStr($xmedia_path).'\', ';
 449          $insReq .= 'website_description  = \''.$this->con->escapeStr($description).'\' ';
 450          if ($update) {
 451              $insReq .= 'WHERE website_id =\''.$this->con->escapeStr($id).'\'';
 452          }
 453  
 454          if (!$this->con->execute($insReq)) {
 455              $this->setError('MySQL : '.$this->con->error(), 500);
 456              return false;
 457          }
 458  
 459  
 460          if (!$update) {
 461              include_once dirname(__FILE__).'/lib.auth.php';
 462              // As this user adds the site, give him root access to it
 463              $insReq = 'INSERT INTO '.$this->con->pfx.'grants SET
 464                                            website_id =\''.$this->con->escapeStr($id).'\',
 465                                            user_id    = \''.$this->con->escapeStr($this->user->_userid).'\',
 466                                            level      = \''.PX_AUTH_ADMIN.'\'';
 467  
 468              if (!$this->con->execute($insReq)) {
 469                  $this->setError('MySQL : '.$this->con->error(), 500);
 470                  return false;
 471              }
 472  
 473              // Add the root category
 474              $hp_title = __('Home Page');
 475              $hp_desc = __('Root category, that plays the role of homepage.');
 476              $hp_kw = __('homepage, index, default');
 477              $insReq='INSERT INTO '.$this->con->pfx.'categories SET
 478                                  website_id=\''.$this->con->escapeStr($id).'\',
 479                                  category_name=\''.$this->con->escapeStr($hp_title).'\',
 480                                  category_description=\''.$this->con->escapeStr($hp_desc).'\',
 481                                  category_keywords=\''.$this->con->escapeStr($hp_kw).'\',
 482                                  category_path=\'/\',
 483                                  category_publicationdate=\''.timestamp().'\',
 484                                  category_creationdate=\''.timestamp().'\',
 485                                  category_enddate=99991231235959,
 486                                  category_template=\'category_homepage.php\',
 487                                  category_type=\'default\',
 488                                  category_cachetime=86400';
 489              if (!$this->con->execute($insReq)) {
 490                  $this->setError('MySQL : '.$this->con->error(), 500);
 491                  return false;
 492              }
 493              if (false == ($catid = $this->con->getLastID())) {
 494                  $this->setError('MySQL : '.$this->con->error(), 500);
 495                  return false;
 496              }
 497              $updReq = 'UPDATE '.$this->con->pfx.'categories SET category_parentid=\''.$this->con->escapeStr($catid).'\'
 498                                          WHERE category_id = \''.$this->con->escapeStr($catid).'\'';
 499  
 500              if (!$this->con->execute($updReq)) {
 501                  $this->setError('MySQL : '.$this->con->error(), 500);
 502                  return false;
 503              }
 504              // Add 2 default subtypes
 505  
 506              if (false === $this->saveType('', 'articles', __('Article'), 'resource_article.php', 3600, '', '', $id)) {
 507                  return false;
 508              }
 509              if (false === $this->saveType('', 'news', __('News'), 'resource_news.php', 3600, '1', '', $id)) {
 510                  return false;
 511              }
 512                          
 513              // All the database related work is done. The creation is a success, we may have error to copy the 
 514              // files, but they are not erros, only "warnings".
 515              // 1- Create the xmedia/thumb folder
 516              // 2- Create the xmedia/theme folder
 517              // 3- Create the manager/templates/$id folder
 518              // 4- Copy folder manager/templates/_dist/default/theme into folder created in 2
 519              // 5- Copy folder manager/templates/_dist/default/templates into folder created in 3
 520              // 6- If id != 'default' copy from the 'default' document root config.php index.php prepend.php rss.php search.php
 521              //    into new document root
 522              // 7- Edit config.php for $_PX_config['manager_path'] and to load the good config file.
 523  
 524              include_once dirname(__FILE__).'/class.files.php';
 525              include_once dirname(__FILE__).'/class.checklist.php';
 526              $f = new files();
 527              $checklist = new checklist();
 528              // 1- Create the xmedia/thumb folder
 529              $checklist->addTest('thumb-folder', files::is_success($f->createfolder($xmedia_path.'/thumb', 0777)) ? 1 : 2,
 530                                  sprintf(__('Thumbnail folder %s created successfully.'), files::real_path($xmedia_path.'/thumb')),
 531                                  '' /* no error */,
 532                                  sprintf(__('Unable to create the thumbnail folder %s.'), $xmedia_path.'/thumb'));
 533  
 534              // 2- Create the xmedia/theme folder
 535              $checklist->addTest('theme-folder', files::is_success($f->createfolder($xmedia_path.'/theme', 0777)) ? 1 : 2,
 536                                  sprintf(__('Theme folder %s created successfully.'), files::real_path($xmedia_path.'/theme')),
 537                                  '' /* no error */,
 538                                  sprintf(__('Unable to create the theme folder %s.'), $xmedia_path.'/theme'));
 539  
 540              // 3- Create the manager/templates/$id folder
 541              $checklist->addTest('template-folder', files::is_success($f->createfolder(files::real_path(dirname(__FILE__).'/../templates/'.$id), 0777)) ? 1 : 2,
 542                                  sprintf(__('Template folder %s created successfully.'), files::real_path(dirname(__FILE__).'/../templates/'.$id)),
 543                                  '' /* no error */,
 544                                  sprintf(__('Unable to create the template folder %s.'), dirname(__FILE__).'/../templates/'.$id));
 545  
 546              // 4- Copy folder manager/templates/_dist/default/theme into folder created in 2
 547              $checklist->addTest('content-theme-folder',
 548                                  files::is_success($f->copyfolder(files::real_path(dirname(__FILE__).'/../templates/_dist/default/theme'),
 549                                                                   files::real_path($xmedia_path.'/theme'))) ? 1 : 2,
 550                                  sprintf(__('Theme files successfully copied from %s to the theme folder.'), files::real_path(dirname(__FILE__).'/../templates/_dist/default/theme')),
 551                                  '' /* no error */,
 552                                  sprintf(__('Unable to copy the theme files from %s to the theme folder.'), files::real_path(dirname(__FILE__).'/../templates/_dist/default/theme')));
 553  
 554              // 5- Copy folder manager/templates/_dist/default/templates into folder created in 3
 555              $checklist->addTest('content-template-folder',
 556                                  files::is_success($f->copyfolder(files::real_path(dirname(__FILE__).'/../templates/_dist/default/templates'),
 557                                                                   files::real_path(dirname(__FILE__).'/../templates/'.$id))) ? 1 : 2,
 558                                  sprintf(__('Templates files successfully copied from %s to the template folder.'), files::real_path(dirname(__FILE__).'/../templates/_dist/default/templates')),
 559                                  '' /* no error */,
 560                                  sprintf(__('Unable to copy the templates files from %s to the template folder.'), files::real_path(dirname(__FILE__).'/../templates/_dist/default/templates')));
 561  
 562              // 6- If id != 'default' copy from the 'default' document root config.php index.php prepend.php rss.php search.php
 563              //    into new document root
 564              if ('default' != $id) {
 565                  $checklist->addTest('config-php',
 566                                      files::is_success($f->copyfile(files::real_path(dirname(__FILE__).'/../../config.php'), $website_path.'/config.php')) ? 1 : 2,
 567                                      sprintf(__('Config file successfully copied from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../config.php') ),
 568                                      '' /* no error */,
 569                                      sprintf(__('Unable to copy the config file from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../config.php') ));
 570  
 571                  $checklist->addTest('index-php',
 572                                      files::is_success($f->copyfile(files::real_path(dirname(__FILE__).'/../../index.php'), $website_path.'/index.php')) ? 1 : 2,
 573                                      sprintf(__('Index file successfully copied from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../index.php') ),
 574                                      '' /* no error */,
 575                                      sprintf(__('Unable to copy the index file from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../index.php') ));
 576  
 577                  $checklist->addTest('prepend-php',
 578                                      files::is_success($f->copyfile(files::real_path(dirname(__FILE__).'/../../prepend.php'), $website_path.'/prepend.php')) ? 1 : 2,
 579                                      sprintf(__('Prepend file successfully copied from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../prepend.php') ),
 580                                      '' /* no error */,
 581                                      sprintf(__('Unable to copy the prepend file from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../prepend.php') ));
 582  
 583                  $checklist->addTest('rss-php',
 584                                      files::is_success($f->copyfile(files::real_path(dirname(__FILE__).'/../../rss.php'), $website_path.'/rss.php')) ? 1 : 2,
 585                                      sprintf(__('Rss file successfully copied from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../rss.php') ),
 586                                      '' /* no error */,
 587                                      sprintf(__('Unable to copy the rss file from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../rss.php') ));
 588  
 589                  $checklist->addTest('search-php',
 590                                      files::is_success($f->copyfile(files::real_path(dirname(__FILE__).'/../../search.php'), $website_path.'/search.php')) ? 1 : 2,
 591                                      sprintf(__('Search file successfully copied from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../search.php') ),
 592                                      '' /* no error */,
 593                                      sprintf(__('Unable to copy the search file from %s to the document root folder.'), files::real_path(dirname(__FILE__).'/../../search.php') ));
 594  
 595                  // 7- Edit config.php for $_PX_config['manager_path'] and to load the good config file.
 596                  // open file for edition of the data
 597                  $cfg = new configfile($website_path.'/config.php');
 598                  $cfg->prefix = '_PX_config';
 599                  $cfg->editVar('manager_path',    (string) files::real_path($_PX_config['manager_path']));
 600                  $edit_config_success = 1;
 601                  if (!$cfg->saveFile()) {
 602                      $edit_config_success = 2;
 603                  } else {
 604                      if (!file_exists($website_path.'/config.php') or !is_writable($website_path.'/config.php')) {
 605                          $edit_config_success = 2;
 606                      } else {
 607                          $config_file = @join('', @file($website_path.'/config.php'));
 608                          $config_file = preg_replace('/configweb\_([A-Za-z0-9]+)\.php/', 'configweb_'.$id.'.php', $config_file);
 609                          $open = @fopen($website_path.'/config.php', 'w');
 610                          @fwrite($open, $config_file);
 611                          @fclose($open);
 612                      }
 613                  }
 614                  $checklist->addTest('edit-config-php', $edit_config_success,
 615                                      sprintf(__('Config file %s successfully updated.'), files::real_path($website_path.'/config.php') ),
 616                                      '' /* no error */,
 617                                      sprintf(__('Unable to update the config file %s.'), files::real_path($website_path.'/config.php') ));
 618  
 619              } //end of if not 'default'
 620              $path = ('default' != $id) ? 'themes/'.$GLOBALS['_px_theme'].'/images' : '../themes/default/images';
 621              $log_new_site = $checklist->getHtml($path);
 622  
 623          }
 624  
 625          return true;
 626  
 627      }
 628  
 629      function delSite($id)
 630      {
 631          if (preg_match('/[^A-Za-z0-9]/', $id)) {
 632              $this->setError( __('Error: Invalid id, it must contain only letters and digits.'),400);
 633              return false;
 634          }
 635  
 636          // get the website with this id
 637          $site = $this->getSites($id);
 638          if ($site->nbRow() == 0) {
 639              $this->setError( __('This site is not available.') , 400);
 640              return false;
 641          }
 642          $date = $this->getEarlierDate('m', '', '', $id);
 643          if (strlen($date) == 14) {
 644              $this->setError( __('Error: The site can only be deleted if empty.') , 400);
 645              return false;
 646          }
 647  
 648  
 649          if (     !file_exists(dirname(__FILE__).'/../conf/configweb_'.$id.'.php')
 650                   || !is_writable(dirname(__FILE__).'/../conf/configweb_'.$id.'.php')) {
 651  
 652              $this->setError(sprintf( __('Error: The configuration file %s is not writeable.'),
 653                                       files::real_path(dirname(__FILE__).'/../conf/').'/configweb_'.$id.'.php'), 500);
 654              return false;
 655          }
 656  
 657  
 658          $delReq = 'DELETE FROM '.$this->con->pfx.'websites WHERE website_id =\''.$this->con->escapeStr($id).'\'';
 659          if (!$this->con->execute($delReq)) {
 660              $this->setError('MySQL : '.$this->con->error(), 500);
 661              return false;
 662          }
 663          $delReq = 'DELETE FROM '.$this->con->pfx.'grants WHERE website_id =\''.$this->con->escapeStr($id).'\'';
 664          if (!$this->con->execute($delReq)) {
 665              $this->setError('MySQL : '.$this->con->error(), 500);
 666              return false;
 667          }
 668          $delReq = 'DELETE FROM '.$this->con->pfx.'userprefs WHERE website_id =\''.$this->con->escapeStr($id).'\'';
 669          if (!$this->con->execute($delReq)) {
 670              $this->setError('MySQL : '.$this->con->error(), 500);
 671              return false;
 672          }
 673          @unlink(dirname(__FILE__).'/../conf/configweb_'.$id.'.php');
 674          return true;
 675      }
 676  
 677  
 678  }
 679  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics