[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/kernel/ -> block.php (source)

   1  <?php
   2  // $Id: block.php 922 2007-08-04 07:06:50Z phppp $

   3  //  ------------------------------------------------------------------------ //

   4  //                XOOPS - PHP Content Management System                      //

   5  //                    Copyright (c) 2000 XOOPS.org                           //

   6  //                       <http://www.xoops.org/>                             //

   7  //  ------------------------------------------------------------------------ //

   8  //  This program 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  //  You may not change or alter any portion of this comment or credits       //

  14  //  of supporting developers from this source code or any supporting         //

  15  //  source code which is considered copyrighted (c) material of the          //

  16  //  original comment or credit authors.                                      //

  17  //                                                                           //

  18  //  This program is distributed in the hope that it will be useful,          //

  19  //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //

  20  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //

  21  //  GNU General Public License for more details.                             //

  22  //                                                                           //

  23  //  You should have received a copy of the GNU General Public License        //

  24  //  along with this program; if not, write to the Free Software              //

  25  //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //

  26  //  ------------------------------------------------------------------------ //

  27  // Author: Kazumi Ono (AKA onokazu)                                          //

  28  // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //

  29  // Project: The XOOPS Project                                                //

  30  // ------------------------------------------------------------------------- //

  31  
  32  if (!defined('XOOPS_ROOT_PATH')) {
  33      exit();
  34  }
  35  
  36  /**

  37   * @author  Kazumi Ono <onokazu@xoops.org>

  38   * @copyright copyright (c) 2000 XOOPS.org

  39   **/
  40  
  41  /**

  42   * A block

  43   * 

  44   * @author Kazumi Ono <onokazu@xoops.org>

  45   * @copyright copyright (c) 2000 XOOPS.org

  46   * 

  47   * @package kernel

  48   **/
  49  class XoopsBlock extends XoopsObject
  50  {
  51  
  52      /**

  53       * constructor

  54       *  

  55       * @param mixed $id

  56       **/
  57      function XoopsBlock($id = null)
  58      {
  59          $this->initVar('bid', XOBJ_DTYPE_INT, null, false);
  60          $this->initVar('mid', XOBJ_DTYPE_INT, 0, false);
  61          $this->initVar('func_num', XOBJ_DTYPE_INT, 0, false);
  62          $this->initVar('options', XOBJ_DTYPE_TXTBOX, null, false, 255);
  63          $this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 150);
  64          //$this->initVar('position', XOBJ_DTYPE_INT, 0, false);

  65          $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 150);
  66          $this->initVar('content', XOBJ_DTYPE_TXTAREA, null, false);
  67          $this->initVar('side', XOBJ_DTYPE_INT, 0, false);
  68          $this->initVar('weight', XOBJ_DTYPE_INT, 0, false);
  69          $this->initVar('visible', XOBJ_DTYPE_INT, 0, false);
  70          $this->initVar('block_type', XOBJ_DTYPE_OTHER, null, false);
  71          $this->initVar('c_type', XOBJ_DTYPE_OTHER, null, false);
  72          $this->initVar('isactive', XOBJ_DTYPE_INT, null, false);
  73          $this->initVar('dirname', XOBJ_DTYPE_TXTBOX, null, false, 50);
  74          $this->initVar('func_file', XOBJ_DTYPE_TXTBOX, null, false, 50);
  75          $this->initVar('show_func', XOBJ_DTYPE_TXTBOX, null, false, 50);
  76          $this->initVar('edit_func', XOBJ_DTYPE_TXTBOX, null, false, 50);
  77          $this->initVar('template', XOBJ_DTYPE_OTHER, null, false);
  78          $this->initVar('bcachetime', XOBJ_DTYPE_INT, 0, false);
  79          $this->initVar('last_modified', XOBJ_DTYPE_INT, 0, false);
  80  
  81          // for backward compatibility

  82          if (isset($id)) {
  83              if (is_array($id)) {
  84                  $this->assignVars($id);
  85              } else {
  86                  $blkhandler =& xoops_gethandler('block');
  87                  $obj =& $blkhandler->get($id);
  88                  foreach (array_keys($obj->getVars() ) as $i) {
  89                      $this->assignVar($obj->getVar($i, 'n') );
  90                  }
  91              }
  92          }
  93      }
  94  
  95      /**

  96       * return the content of the block for output

  97       * 

  98       * @param string $format

  99       * @param string $c_type type of content<br>

 100       * Legal value for the type of content<br>

 101       * <ul><li>H : custom HTML block

 102       * <li>P : custom PHP block

 103       * <li>S : use text sanitizater (smilies enabled)

 104       * <li>T : use text sanitizater (smilies disabled)</ul>

 105       * @return string content for output

 106       **/
 107      function getContent($format = 'S', $c_type = 'T')
 108      {
 109          switch ( $format ) {
 110          case 'S':
 111              if ( $c_type == 'H' ) {
 112                  return str_replace('{X_SITEURL}', XOOPS_URL.'/', $this->getVar('content', 'N'));
 113              } elseif ( $c_type == 'P' ) {
 114                  ob_start();
 115                  echo eval($this->getVar('content', 'N'));
 116                  $content = ob_get_contents();
 117                  ob_end_clean();
 118                  return str_replace('{X_SITEURL}', XOOPS_URL.'/', $content);
 119              } elseif ( $c_type == 'S' ) {
 120                  $myts =& MyTextSanitizer::getInstance();
 121                  $content = str_replace('{X_SITEURL}', XOOPS_URL.'/', $this->getVar('content', 'N'));
 122                  return $myts->displayTarea($content, 0, 1);
 123              } else {
 124                  $myts =& MyTextSanitizer::getInstance();
 125                  $content = str_replace('{X_SITEURL}', XOOPS_URL.'/', $this->getVar('content', 'N'));
 126                  return $myts->displayTarea($content, 0, 0);
 127              }
 128              break;
 129          case 'E':
 130              return $this->getVar('content', 'E');
 131              break;
 132          default:
 133              return $this->getVar('content', 'N');
 134              break;
 135          }
 136      }
 137  
 138      /**

 139       * (HTML-) form for setting the options of the block

 140       * 

 141       * @return string HTML for the form, FALSE if not defined for this block 

 142       **/
 143      function getOptions()
 144      {
 145          if ($this->getVar('block_type') != 'C') {
 146              $edit_func = $this->getVar('edit_func');
 147              if (!$edit_func) {
 148                  return false;
 149              }
 150              if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file'))) {
 151                  if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/language/'.$GLOBALS['xoopsConfig']['language'].'/blocks.php')) {
 152                      include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/language/'.$GLOBALS['xoopsConfig']['language'].'/blocks.php';
 153                  } elseif (file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/language/english/blocks.php')) {
 154                      include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/language/english/blocks.php';
 155                  }
 156                  include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file');
 157                  $options = explode('|', $this->getVar('options'));
 158                  $edit_form = $edit_func($options);
 159                  if (!$edit_form) {
 160                      return false;
 161                  }
 162                  return $edit_form;
 163              } else {
 164                  return false;
 165              }
 166          } else {
 167              return false;
 168          }
 169      }
 170  }
 171  
 172  
 173  /**

 174   * XOOPS block handler class. (Singelton)

 175   * 

 176   * This class is responsible for providing data access mechanisms to the data source 

 177   * of XOOPS block class objects. 

 178   *

 179   * @author  Kazumi Ono <onokazu@xoops.org>

 180   * @copyright copyright (c) 2000 XOOPS.org

 181   * @package kernel

 182   * @subpackage block

 183  */
 184  class XoopsBlockHandler extends XoopsObjectHandler
 185  {
 186  
 187      /**

 188       * create a new block

 189       * 

 190       * @see XoopsBlock

 191       * @param bool $isNew is the new block new??

 192       * @return object XoopsBlock reference to the new block 

 193       **/
 194      function &create($isNew = true)
 195      {
 196          $block = new XoopsBlock();
 197          if ($isNew) {
 198              $block->setNew();
 199          }
 200          return $block;
 201      }
 202  
 203      /**

 204       * retrieve a specific {@link XoopsBlock}

 205       * 

 206       * @see XoopsBlock

 207       * @param int $id bid of the block to retrieve

 208       * @return object XoopsBlock reference to the block 

 209       **/
 210      function &get($id)
 211      {
 212          $block = false;
 213          $id = intval($id);
 214          if ($id > 0) {
 215              $sql = 'SELECT * FROM '.$this->db->prefix('newblocks').' WHERE bid='.$id;
 216              if ( $result = $this->db->query($sql) ) {
 217                  $numrows = $this->db->getRowsNum($result);
 218                  if ($numrows == 1) {
 219                      $block = new XoopsBlock();
 220                      $block->assignVars($this->db->fetchArray($result));
 221                  }
 222              }
 223          }
 224          return $block;
 225      }
 226  
 227      /**

 228       * write a new block into the database

 229       * 

 230       * @param object XoopsBlock $block reference to the block to insert

 231       * @return bool TRUE if succesful

 232       **/
 233      function insert(&$block)
 234      {
 235          if (strtolower(get_class($block)) != 'xoopsblock') {
 236              return false;
 237          }
 238          if (!$block->isDirty()) {
 239              return true;
 240          }
 241          if (!$block->cleanVars()) {
 242              return false;
 243          }
 244          foreach ($block->cleanVars as $k => $v) {
 245              ${$k} = $v;
 246          }
 247          if ($block->isNew()) {
 248              $bid = $this->db->genId('newblocks_bid_seq');
 249              $sql = sprintf("INSERT INTO %s (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES (%u, %u, %u, '%s', '%s', '%s', '%s', %u, %u, %u, '%s', '%s', %u, '%s', '%s', '%s', '%s', '%s', %u, %u)", $this->db->prefix('newblocks'), $bid, $mid, $func_num, $options, $name, $title, $content, $side, $weight, $visible, $block_type, $c_type, 1, $dirname, $func_file, $show_func, $edit_func, $template, $bcachetime, time());
 250          } else {
 251              $sql = sprintf("UPDATE %s SET func_num = %u, options = '%s', name = '%s', title = '%s', content = '%s', side = %u, weight = %u, visible = %u, c_type = '%s', isactive = %u, func_file = '%s', show_func = '%s', edit_func = '%s', template = '%s', bcachetime = %u, last_modified = %u WHERE bid = %u", $this->db->prefix('newblocks'), $func_num, $options, $name, $title, $content, $side, $weight, $visible, $c_type, $isactive, $func_file, $show_func, $edit_func, $template, $bcachetime, time(), $bid);
 252          }
 253          if (!$result = $this->db->query($sql)) {
 254              return false;
 255          }
 256          if (empty($bid)) {
 257              $bid = $this->db->getInsertId();
 258          }
 259          $block->assignVar('bid', $bid);
 260          return true;
 261      }
 262  
 263      /**

 264       * delete a block from the database

 265       * 

 266       * @param object XoopsBlock $block reference to the block to delete 

 267       * @return bool TRUE if succesful

 268       **/
 269      function delete(&$block)
 270      {
 271          if (strtolower(get_class($block)) != 'xoopsblock') {
 272              return false;
 273          }
 274          $id = $block->getVar('bid');
 275          $sql = sprintf("DELETE FROM %s WHERE bid = %u", $this->db->prefix('newblocks'), $id);
 276          if (!$result = $this->db->query($sql)) {
 277              return false;
 278          }
 279          $sql = sprintf("DELETE FROM %s WHERE block_id = %u", $this->db->prefix('block_module_link'), $id);
 280          $this->db->query($sql);
 281          return true;
 282      }
 283  
 284      /**

 285       * retrieve array of {@link XoopsBlock}s meeting certain conditions

 286       * @param object $criteria {@link CriteriaElement} with conditions for the blocks

 287       * @param bool $id_as_key should the blocks' bid be the key for the returned array?

 288       * @return array {@link XoopsBlock}s matching the conditions

 289       **/
 290      function getObjects($criteria = null, $id_as_key = false)
 291      {
 292          $ret = array();
 293          $limit = $start = 0;
 294          $sql = 'SELECT DISTINCT(b.*) FROM '.$this->db->prefix('newblocks').' b LEFT JOIN '.$this->db->prefix('block_module_link').' l ON b.bid=l.block_id';
 295          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 296              $sql .= ' '.$criteria->renderWhere();
 297              $limit = $criteria->getLimit();
 298              $start = $criteria->getStart();
 299          }
 300          $result = $this->db->query($sql, $limit, $start);
 301          if (!$result) {
 302              return $ret;
 303          }
 304          while ($myrow = $this->db->fetchArray($result)) {
 305              $block = new XoopsBlock();
 306              $block->assignVars($myrow);
 307              if (!$id_as_key) {
 308                  $ret[] =& $block;
 309              } else {
 310                  $ret[$myrow['bid']] =& $block;
 311              }
 312              unset($block);
 313          }
 314          return $ret;
 315      }
 316  
 317      /**

 318       * get a list of blocks matchich certain conditions

 319       * 

 320       * @param string $criteria conditions to match

 321       * @return array array of blocks matching the conditions 

 322       **/
 323      function getList($criteria = null)
 324      {
 325          $blocks =& $this->getObjects($criteria, true);
 326          $ret = array();
 327          foreach (array_keys($blocks) as $i) {
 328              $name = ($blocks[$i]->getVar('block_type') != 'C') ? $blocks[$i]->getVar('name') : $blocks[$i]->getVar('title');
 329              $ret[$i] = $name;
 330          }
 331          return $ret;
 332      }
 333  }
 334  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics