[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  // $Id: tplfile.php 506 2006-05-26 23:10:37Z skalpa $

   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  if (!defined('XOOPS_ROOT_PATH')) {
  32      exit();
  33  }
  34  class XoopsTplfile extends XoopsObject
  35  {
  36  
  37  	function XoopsTplfile()
  38      {
  39          $this->XoopsObject();
  40          $this->initVar('tpl_id', XOBJ_DTYPE_INT, null, false);
  41          $this->initVar('tpl_refid', XOBJ_DTYPE_INT, 0, false);
  42          $this->initVar('tpl_tplset', XOBJ_DTYPE_OTHER, null, false);
  43          $this->initVar('tpl_file', XOBJ_DTYPE_TXTBOX, null, true, 100);
  44          $this->initVar('tpl_desc', XOBJ_DTYPE_TXTBOX, null, false, 100);
  45          $this->initVar('tpl_lastmodified', XOBJ_DTYPE_INT, 0, false);
  46          $this->initVar('tpl_lastimported', XOBJ_DTYPE_INT, 0, false);
  47          $this->initVar('tpl_module', XOBJ_DTYPE_OTHER, null, false);
  48          $this->initVar('tpl_type', XOBJ_DTYPE_OTHER, null, false);
  49          $this->initVar('tpl_source', XOBJ_DTYPE_SOURCE, null, false);
  50      }
  51  
  52  	function getSource()
  53      {
  54          return $this->getVar('tpl_source');
  55      }
  56  
  57  	function getLastModified()
  58      {
  59          return $this->getVar('tpl_lastmodified');
  60      }
  61  }
  62  
  63  /**

  64  * XOOPS template file handler class.  

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

  66  * of XOOPS template file class objects.

  67  *

  68  *

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

  70  */
  71  
  72  class XoopsTplfileHandler extends XoopsObjectHandler
  73  {
  74  
  75      function &create($isNew = true)
  76      {
  77          $tplfile = new XoopsTplfile();
  78          if ($isNew) {
  79              $tplfile->setNew();
  80          }
  81          return $tplfile;
  82      }
  83  
  84      function &get($id, $getsource = false)
  85      {
  86          $tplfile = false;
  87          $id = intval($id);
  88          if ($id > 0) {
  89              if (!$getsource) {
  90                  $sql = 'SELECT * FROM '.$this->db->prefix('tplfile').' WHERE tpl_id='.$id;
  91              } else {
  92                  $sql = 'SELECT f.*, s.tpl_source FROM '.$this->db->prefix('tplfile').' f LEFT JOIN '.$this->db->prefix('tplsource').' s  ON s.tpl_id=f.tpl_id WHERE f.tpl_id='.$id;
  93              }
  94              if (!$result = $this->db->query($sql)) {
  95                  return $tplfile;
  96              }
  97              $numrows = $this->db->getRowsNum($result);
  98              if ($numrows == 1) {
  99                  $tplfile = new XoopsTplfile();
 100                  $tplfile->assignVars($this->db->fetchArray($result));
 101              }
 102          }
 103          return $tplfile;
 104      }
 105  
 106      function loadSource(&$tplfile)
 107      {
 108          if (strtolower(get_class($tplfile)) != 'xoopstplfile') {
 109              return false;
 110          }
 111          if (!$tplfile->getVar('tpl_source')) {
 112              $sql = 'SELECT tpl_source FROM '.$this->db->prefix('tplsource').' WHERE tpl_id='.$tplfile->getVar('tpl_id');
 113              if (!$result = $this->db->query($sql)) {
 114                  return false;
 115              }
 116              $myrow = $this->db->fetchArray($result);
 117              $tplfile->assignVar('tpl_source', $myrow['tpl_source']);
 118          }
 119          return true;
 120      }
 121  
 122      function insert(&$tplfile)
 123      {
 124          if (strtolower(get_class($tplfile)) != 'xoopstplfile') {
 125              return false;
 126          }
 127          if (!$tplfile->isDirty()) {
 128              return true;
 129          }
 130          if (!$tplfile->cleanVars()) {
 131              return false;
 132          }
 133          foreach ($tplfile->cleanVars as $k => $v) {
 134              ${$k} = $v;
 135          }
 136          if ($tplfile->isNew()) {
 137              $tpl_id = $this->db->genId('tpltpl_file_id_seq');
 138              $sql = sprintf("INSERT INTO %s (tpl_id, tpl_module, tpl_refid, tpl_tplset, tpl_file, tpl_desc, tpl_lastmodified, tpl_lastimported, tpl_type) VALUES (%u, %s, %u, %s, %s, %s, %u, %u, %s)", $this->db->prefix('tplfile'), $tpl_id, $this->db->quoteString($tpl_module), $tpl_refid, $this->db->quoteString($tpl_tplset), $this->db->quoteString($tpl_file), $this->db->quoteString($tpl_desc), $tpl_lastmodified, $tpl_lastimported, $this->db->quoteString($tpl_type));
 139              if (!$result = $this->db->query($sql)) {
 140                  return false;
 141              }
 142              if (empty($tpl_id)) {
 143                  $tpl_id = $this->db->getInsertId();
 144              }
 145              if (isset($tpl_source) && $tpl_source != '') {
 146                  $sql = sprintf("INSERT INTO %s (tpl_id, tpl_source) VALUES (%u, %s)", $this->db->prefix('tplsource'), $tpl_id, $this->db->quoteString($tpl_source));
 147                  if (!$result = $this->db->query($sql)) {
 148                      $this->db->query(sprintf("DELETE FROM %s WHERE tpl_id = %u", $this->db->prefix('tplfile'), $tpl_id));
 149                      return false;
 150                  }
 151              }
 152              $tplfile->assignVar('tpl_id', $tpl_id);
 153          } else {
 154              $sql = sprintf("UPDATE %s SET tpl_tplset = %s, tpl_file = %s, tpl_desc = %s, tpl_lastimported = %u, tpl_lastmodified = %u WHERE tpl_id = %u", $this->db->prefix('tplfile'), $this->db->quoteString($tpl_tplset), $this->db->quoteString($tpl_file), $this->db->quoteString($tpl_desc), $tpl_lastimported, $tpl_lastmodified, $tpl_id);
 155              if (!$result = $this->db->query($sql)) {
 156                  return false;
 157              }
 158              if (isset($tpl_source) && $tpl_source != '') {
 159                  $sql = sprintf("UPDATE %s SET tpl_source = %s WHERE tpl_id = %u", $this->db->prefix('tplsource'), $this->db->quoteString($tpl_source), $tpl_id);
 160                  if (!$result = $this->db->query($sql)) {
 161                      return false;
 162                  }
 163              }
 164          }
 165          return true;
 166      }
 167  
 168      function forceUpdate(&$tplfile)
 169      {
 170          if (strtolower(get_class($tplfile)) != 'xoopstplfile') {
 171              return false;
 172          }
 173          if (!$tplfile->isDirty()) {
 174              return true;
 175          }
 176          if (!$tplfile->cleanVars()) {
 177              return false;
 178          }
 179          foreach ($tplfile->cleanVars as $k => $v) {
 180              ${$k} = $v;
 181          }
 182          if (!$tplfile->isNew()) {
 183              $sql = sprintf("UPDATE %s SET tpl_tplset = %s, tpl_file = %s, tpl_desc = %s, tpl_lastimported = %u, tpl_lastmodified = %u WHERE tpl_id = %u", $this->db->prefix('tplfile'), $this->db->quoteString($tpl_tplset), $this->db->quoteString($tpl_file), $this->db->quoteString($tpl_desc), $tpl_lastimported, $tpl_lastmodified, $tpl_id);
 184              if (!$result = $this->db->queryF($sql)) {
 185                  return false;
 186              }
 187              if (isset($tpl_source) && $tpl_source != '') {
 188                  $sql = sprintf("UPDATE %s SET tpl_source = %s WHERE tpl_id = %u", $this->db->prefix('tplsource'), $this->db->quoteString($tpl_source), $tpl_id);
 189                  if (!$result = $this->db->queryF($sql)) {
 190                      return false;
 191                  }
 192              }
 193              return true;
 194          } else {
 195              return false;
 196          }
 197      }
 198  
 199      function delete(&$tplfile)
 200      {
 201          if (strtolower(get_class($tplfile)) != 'xoopstplfile') {
 202              return false;
 203          }
 204          $id = $tplfile->getVar('tpl_id');
 205          $sql = sprintf("DELETE FROM %s WHERE tpl_id = %u", $this->db->prefix('tplfile'), $id);
 206          if (!$result = $this->db->query($sql)) {
 207              return false;
 208          }
 209          $sql = sprintf("DELETE FROM %s WHERE tpl_id = %u", $this->db->prefix('tplsource'), $id);
 210          $this->db->query($sql);
 211          return true;
 212      }
 213  
 214      function getObjects($criteria = null, $getsource = false, $id_as_key = false)
 215      {
 216          $ret = array();
 217          $limit = $start = 0;
 218          if ($getsource) {
 219              $sql = 'SELECT f.*, s.tpl_source FROM '.$this->db->prefix('tplfile').' f LEFT JOIN '.$this->db->prefix('tplsource').' s ON s.tpl_id=f.tpl_id';
 220          } else {
 221              $sql = 'SELECT * FROM '.$this->db->prefix('tplfile');
 222          }
 223          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 224              $sql .= ' '.$criteria->renderWhere().' ORDER BY tpl_refid';
 225              $limit = $criteria->getLimit();
 226              $start = $criteria->getStart();
 227          }
 228          $result = $this->db->query($sql, $limit, $start);
 229          if (!$result) {
 230              return $ret;
 231          }
 232          while ($myrow = $this->db->fetchArray($result)) {
 233              $tplfile = new XoopsTplfile();
 234              $tplfile->assignVars($myrow);
 235              if (!$id_as_key) {
 236                  $ret[] =& $tplfile;
 237              } else {
 238                  $ret[$myrow['tpl_id']] =& $tplfile;
 239              }
 240              unset($tplfile);
 241          }
 242          return $ret;
 243      }
 244  
 245      function getCount($criteria = null)
 246      {
 247          $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('tplfile');
 248          if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
 249              $sql .= ' '.$criteria->renderWhere();
 250          }
 251          if (!$result =& $this->db->query($sql)) {
 252              return 0;
 253          }
 254          list($count) = $this->db->fetchRow($result);
 255          return $count;
 256      }
 257  
 258      function getModuleTplCount($tplset)
 259      {
 260          $ret = array();
 261          $sql = "SELECT tpl_module, COUNT(tpl_id) AS count FROM ".$this->db->prefix('tplfile')." WHERE tpl_tplset='".$tplset."' GROUP BY tpl_module";
 262          $result = $this->db->query($sql);
 263          if (!$result) {
 264              return $ret;
 265          }
 266          while ($myrow = $this->db->fetchArray($result)) {
 267              if ($myrow['tpl_module'] != '') {
 268                  $ret[$myrow['tpl_module']] = $myrow['count'];
 269              }
 270          }
 271          return $ret;
 272      }
 273  
 274      function find($tplset = null, $type = null, $refid = null, $module = null, $file = null, $getsource = false)
 275      {
 276          $criteria = new CriteriaCompo();
 277          if (isset($tplset)) {
 278              $criteria->add(new Criteria('tpl_tplset', $tplset));
 279          }
 280          if (isset($module)) {
 281              $criteria->add(new Criteria('tpl_module', $module));
 282          }
 283          if (isset($refid)) {
 284              $criteria->add(new Criteria('tpl_refid', $refid));
 285          }
 286          if (isset($file)) {
 287              $criteria->add(new Criteria('tpl_file', $file));
 288          }
 289          if (isset($type)) {
 290              if (is_array($type)) {
 291                  $criteria2 = new CriteriaCompo();
 292                  foreach ($type as $t) {
 293                      $criteria2->add(new Criteria('tpl_type', $t), 'OR');
 294                  }
 295                  $criteria->add($criteria2);
 296              } else {
 297                  $criteria->add(new Criteria('tpl_type', $type));
 298              }
 299          }
 300          return $this->getObjects($criteria, $getsource, false);
 301      }
 302  
 303      function templateExists($tplname, $tplset_name)
 304      {
 305          $criteria = new CriteriaCompo(new Criteria('tpl_file', trim($tplname)));
 306          $criteria->add(new Criteria('tpl_tplset', trim($tplset_name)));
 307          if ($this->getCount($criteria) > 0) {
 308              return true;
 309          }
 310          return false;
 311      }
 312  }
 313  ?>


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