| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: |
|
| 18: |
|
| 19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
| 20: |
|
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: |
|
| 29: | class XoopsTplfile extends XoopsObject
|
| 30: | {
|
| 31: |
|
| 32: | public $tpl_id;
|
| 33: | public $tpl_refid;
|
| 34: | public $tpl_tplset;
|
| 35: | public $tpl_file;
|
| 36: | public $tpl_desc;
|
| 37: | public $tpl_lastmodified;
|
| 38: | public $tpl_lastimported;
|
| 39: | public $tpl_module;
|
| 40: | public $tpl_type;
|
| 41: | public $tpl_source;
|
| 42: |
|
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: |
|
| 48: | public function __construct()
|
| 49: | {
|
| 50: | parent::__construct();
|
| 51: | $this->initVar('tpl_id', XOBJ_DTYPE_INT, null, false);
|
| 52: | $this->initVar('tpl_refid', XOBJ_DTYPE_INT, 0, false);
|
| 53: | $this->initVar('tpl_tplset', XOBJ_DTYPE_OTHER, null, false);
|
| 54: | $this->initVar('tpl_file', XOBJ_DTYPE_TXTBOX, null, true, 100);
|
| 55: | $this->initVar('tpl_desc', XOBJ_DTYPE_TXTBOX, null, false, 100);
|
| 56: | $this->initVar('tpl_lastmodified', XOBJ_DTYPE_INT, 0, false);
|
| 57: | $this->initVar('tpl_lastimported', XOBJ_DTYPE_INT, 0, false);
|
| 58: | $this->initVar('tpl_module', XOBJ_DTYPE_OTHER, null, false);
|
| 59: | $this->initVar('tpl_type', XOBJ_DTYPE_OTHER, null, false);
|
| 60: | $this->initVar('tpl_source', XOBJ_DTYPE_SOURCE, null, false);
|
| 61: | }
|
| 62: |
|
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: |
|
| 68: | public function id($format = 'N')
|
| 69: | {
|
| 70: | return $this->getVar('tpl_id', $format);
|
| 71: | }
|
| 72: |
|
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: |
|
| 78: | public function tpl_id($format = '')
|
| 79: | {
|
| 80: | return $this->getVar('tpl_id', $format);
|
| 81: | }
|
| 82: |
|
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: |
|
| 88: | public function tpl_refid($format = '')
|
| 89: | {
|
| 90: | return $this->getVar('tpl_refid', $format);
|
| 91: | }
|
| 92: |
|
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: |
|
| 98: | public function tpl_tplset($format = '')
|
| 99: | {
|
| 100: | return $this->getVar('tpl_tplset', $format);
|
| 101: | }
|
| 102: |
|
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: |
|
| 108: | public function tpl_file($format = '')
|
| 109: | {
|
| 110: | return $this->getVar('tpl_file', $format);
|
| 111: | }
|
| 112: |
|
| 113: | |
| 114: | |
| 115: | |
| 116: | |
| 117: |
|
| 118: | public function tpl_desc($format = '')
|
| 119: | {
|
| 120: | return $this->getVar('tpl_desc', $format);
|
| 121: | }
|
| 122: |
|
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: |
|
| 128: | public function tpl_lastmodified($format = '')
|
| 129: | {
|
| 130: | return $this->getVar('tpl_lastmodified', $format);
|
| 131: | }
|
| 132: |
|
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: |
|
| 138: | public function tpl_lastimported($format = '')
|
| 139: | {
|
| 140: | return $this->getVar('tpl_lastimported', $format);
|
| 141: | }
|
| 142: |
|
| 143: | |
| 144: | |
| 145: | |
| 146: | |
| 147: |
|
| 148: | public function tpl_module($format = '')
|
| 149: | {
|
| 150: | return $this->getVar('tpl_module', $format);
|
| 151: | }
|
| 152: |
|
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: |
|
| 158: | public function tpl_type($format = '')
|
| 159: | {
|
| 160: | return $this->getVar('tpl_type', $format);
|
| 161: | }
|
| 162: |
|
| 163: | |
| 164: | |
| 165: | |
| 166: | |
| 167: |
|
| 168: | public function tpl_source($format = '')
|
| 169: | {
|
| 170: | return $this->getVar('tpl_source', $format);
|
| 171: | }
|
| 172: |
|
| 173: | |
| 174: | |
| 175: | |
| 176: | |
| 177: |
|
| 178: | public function getSource()
|
| 179: | {
|
| 180: | return $this->getVar('tpl_source');
|
| 181: | }
|
| 182: |
|
| 183: | |
| 184: | |
| 185: | |
| 186: | |
| 187: |
|
| 188: | public function getLastModified()
|
| 189: | {
|
| 190: | return $this->getVar('tpl_lastmodified');
|
| 191: | }
|
| 192: | }
|
| 193: |
|
| 194: | |
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: | |
| 201: | |
| 202: | |
| 203: |
|
| 204: | class XoopsTplfileHandler extends XoopsObjectHandler
|
| 205: | {
|
| 206: | |
| 207: | |
| 208: | |
| 209: | |
| 210: | |
| 211: | |
| 212: |
|
| 213: | public function create($isNew = true)
|
| 214: | {
|
| 215: | $tplfile = new XoopsTplfile();
|
| 216: | if ($isNew) {
|
| 217: | $tplfile->setNew();
|
| 218: | }
|
| 219: |
|
| 220: | return $tplfile;
|
| 221: | }
|
| 222: |
|
| 223: | |
| 224: | |
| 225: | |
| 226: | |
| 227: | |
| 228: | |
| 229: | |
| 230: | |
| 231: | |
| 232: |
|
| 233: | public function get($id, $getsource = false)
|
| 234: | {
|
| 235: | $tplfile = false;
|
| 236: | $id = (int)$id;
|
| 237: | if ($id > 0) {
|
| 238: | if (!$getsource) {
|
| 239: | $sql = 'SELECT * FROM ' . $this->db->prefix('tplfile') . ' WHERE tpl_id=' . $id;
|
| 240: | } else {
|
| 241: | $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;
|
| 242: | }
|
| 243: | $result = $this->db->query($sql);
|
| 244: | if (!$this->db->isResultSet($result)) {
|
| 245: | return $tplfile;
|
| 246: | }
|
| 247: | $numrows = $this->db->getRowsNum($result);
|
| 248: | if ($numrows == 1) {
|
| 249: | $tplfile = new XoopsTplfile();
|
| 250: | $tplfile->assignVars($this->db->fetchArray($result));
|
| 251: | }
|
| 252: | }
|
| 253: |
|
| 254: | return $tplfile;
|
| 255: | }
|
| 256: |
|
| 257: | |
| 258: | |
| 259: | |
| 260: | |
| 261: | |
| 262: | |
| 263: |
|
| 264: | public function loadSource(XoopsObject $tplfile)
|
| 265: | {
|
| 266: | $className = 'XoopsTplfile';
|
| 267: | if (!($tplfile instanceof $className)) {
|
| 268: | return false;
|
| 269: | }
|
| 270: |
|
| 271: | if (!$tplfile->getVar('tpl_source')) {
|
| 272: | $sql = 'SELECT tpl_source FROM ' . $this->db->prefix('tplsource') . ' WHERE tpl_id=' . $tplfile->getVar('tpl_id');
|
| 273: | $result = $this->db->query($sql);
|
| 274: | if (!$this->db->isResultSet($result)) {
|
| 275: | return false;
|
| 276: | }
|
| 277: |
|
| 278: | $myrow = $this->db->fetchArray($result);
|
| 279: | $tplfile->assignVar('tpl_source', $myrow['tpl_source']);
|
| 280: | }
|
| 281: |
|
| 282: | return true;
|
| 283: | }
|
| 284: |
|
| 285: | |
| 286: | |
| 287: | |
| 288: | |
| 289: | |
| 290: | |
| 291: |
|
| 292: | public function insert(XoopsObject $tplfile)
|
| 293: | {
|
| 294: | $className = 'XoopsTplfile';
|
| 295: | if (!($tplfile instanceof $className)) {
|
| 296: | return false;
|
| 297: | }
|
| 298: | if (!$tplfile->isDirty()) {
|
| 299: | return true;
|
| 300: | }
|
| 301: | if (!$tplfile->cleanVars()) {
|
| 302: | return false;
|
| 303: | }
|
| 304: | foreach ($tplfile->cleanVars as $k => $v) {
|
| 305: | ${$k} = $v;
|
| 306: | }
|
| 307: | if ($tplfile->isNew()) {
|
| 308: | $tpl_id = $this->db->genId('tpltpl_file_id_seq');
|
| 309: | $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));
|
| 310: | if (!$result = $this->db->query($sql)) {
|
| 311: | return false;
|
| 312: | }
|
| 313: | if (empty($tpl_id)) {
|
| 314: | $tpl_id = $this->db->getInsertId();
|
| 315: | }
|
| 316: | if (isset($tpl_source) && $tpl_source != '') {
|
| 317: | $sql = sprintf('INSERT INTO %s (tpl_id, tpl_source) VALUES (%u, %s)', $this->db->prefix('tplsource'), $tpl_id, $this->db->quoteString($tpl_source));
|
| 318: | if (!$result = $this->db->query($sql)) {
|
| 319: | $this->db->query(sprintf('DELETE FROM %s WHERE tpl_id = %u', $this->db->prefix('tplfile'), $tpl_id));
|
| 320: |
|
| 321: | return false;
|
| 322: | }
|
| 323: | }
|
| 324: | $tplfile->assignVar('tpl_id', $tpl_id);
|
| 325: | } else {
|
| 326: | $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);
|
| 327: | if (!$result = $this->db->query($sql)) {
|
| 328: | return false;
|
| 329: | }
|
| 330: | if (isset($tpl_source) && $tpl_source != '') {
|
| 331: | $sql = sprintf('UPDATE %s SET tpl_source = %s WHERE tpl_id = %u', $this->db->prefix('tplsource'), $this->db->quoteString($tpl_source), $tpl_id);
|
| 332: | if (!$result = $this->db->query($sql)) {
|
| 333: | return false;
|
| 334: | }
|
| 335: | }
|
| 336: | }
|
| 337: |
|
| 338: | return true;
|
| 339: | }
|
| 340: |
|
| 341: | |
| 342: | |
| 343: | |
| 344: | |
| 345: | |
| 346: |
|
| 347: | public function forceUpdate(XoopsTplfile $tplfile)
|
| 348: | {
|
| 349: | $className = 'XoopsTplfile';
|
| 350: | if (!($tplfile instanceof $className)) {
|
| 351: | return false;
|
| 352: | }
|
| 353: | if (!$tplfile->isDirty()) {
|
| 354: | return true;
|
| 355: | }
|
| 356: | if (!$tplfile->cleanVars()) {
|
| 357: | return false;
|
| 358: | }
|
| 359: | foreach ($tplfile->cleanVars as $k => $v) {
|
| 360: | ${$k} = $v;
|
| 361: | }
|
| 362: | if (!$tplfile->isNew()) {
|
| 363: | $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);
|
| 364: | if (!$result = $this->db->queryF($sql)) {
|
| 365: | return false;
|
| 366: | }
|
| 367: | if (isset($tpl_source) && $tpl_source != '') {
|
| 368: | $sql = sprintf('UPDATE %s SET tpl_source = %s WHERE tpl_id = %u', $this->db->prefix('tplsource'), $this->db->quoteString($tpl_source), $tpl_id);
|
| 369: | if (!$result = $this->db->queryF($sql)) {
|
| 370: | return false;
|
| 371: | }
|
| 372: | }
|
| 373: |
|
| 374: | return true;
|
| 375: | } else {
|
| 376: | return false;
|
| 377: | }
|
| 378: | }
|
| 379: |
|
| 380: | |
| 381: | |
| 382: | |
| 383: | |
| 384: | |
| 385: | |
| 386: |
|
| 387: | public function delete(XoopsObject $tplfile)
|
| 388: | {
|
| 389: | $className = 'XoopsTplfile';
|
| 390: | if (!($tplfile instanceof $className)) {
|
| 391: | return false;
|
| 392: | }
|
| 393: | $id = $tplfile->getVar('tpl_id');
|
| 394: | $sql = sprintf('DELETE FROM %s WHERE tpl_id = %u', $this->db->prefix('tplfile'), $id);
|
| 395: | if (!$result = $this->db->query($sql)) {
|
| 396: | return false;
|
| 397: | }
|
| 398: | $sql = sprintf('DELETE FROM %s WHERE tpl_id = %u', $this->db->prefix('tplsource'), $id);
|
| 399: | $this->db->query($sql);
|
| 400: |
|
| 401: | return true;
|
| 402: | }
|
| 403: |
|
| 404: | |
| 405: | |
| 406: | |
| 407: | |
| 408: | |
| 409: | |
| 410: |
|
| 411: | public function getObjects(CriteriaElement $criteria = null, $getsource = false, $id_as_key = false)
|
| 412: | {
|
| 413: | $ret = array();
|
| 414: | $limit = $start = 0;
|
| 415: | if ($getsource) {
|
| 416: | $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';
|
| 417: | } else {
|
| 418: | $sql = 'SELECT * FROM ' . $this->db->prefix('tplfile');
|
| 419: | }
|
| 420: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
| 421: | $sql .= ' ' . $criteria->renderWhere() . ' ORDER BY tpl_refid';
|
| 422: | $limit = $criteria->getLimit();
|
| 423: | $start = $criteria->getStart();
|
| 424: | }
|
| 425: | $result = $this->db->query($sql, $limit, $start);
|
| 426: | if (!$this->db->isResultSet($result)) {
|
| 427: | return $ret;
|
| 428: | }
|
| 429: |
|
| 430: | while (false !== ($myrow = $this->db->fetchArray($result))) {
|
| 431: | $tplfile = new XoopsTplfile();
|
| 432: | $tplfile->assignVars($myrow);
|
| 433: | if (!$id_as_key) {
|
| 434: | $ret[] =& $tplfile;
|
| 435: | } else {
|
| 436: | $ret[$myrow['tpl_id']] =& $tplfile;
|
| 437: | }
|
| 438: | unset($tplfile);
|
| 439: | }
|
| 440: |
|
| 441: | return $ret;
|
| 442: | }
|
| 443: |
|
| 444: | |
| 445: | |
| 446: | |
| 447: | |
| 448: | |
| 449: |
|
| 450: | public function getCount(CriteriaElement $criteria = null)
|
| 451: | {
|
| 452: | $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('tplfile');
|
| 453: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
| 454: | $sql .= ' ' . $criteria->renderWhere();
|
| 455: | }
|
| 456: | $result = $this->db->query($sql);
|
| 457: | if (!$this->db->isResultSet($result)) {
|
| 458: | return 0;
|
| 459: | }
|
| 460: | list($count) = $this->db->fetchRow($result);
|
| 461: |
|
| 462: | return (int)$count;
|
| 463: | }
|
| 464: |
|
| 465: | |
| 466: | |
| 467: | |
| 468: | |
| 469: | |
| 470: |
|
| 471: | public function getModuleTplCount($tplset)
|
| 472: | {
|
| 473: | $ret = array();
|
| 474: | $sql = 'SELECT tpl_module, COUNT(tpl_id) AS count FROM ' . $this->db->prefix('tplfile') . " WHERE tpl_tplset='" . $tplset . "' GROUP BY tpl_module";
|
| 475: | $result = $this->db->query($sql);
|
| 476: | if (!$this->db->isResultSet($result)) {
|
| 477: | return $ret;
|
| 478: | }
|
| 479: |
|
| 480: | while (false !== ($myrow = $this->db->fetchArray($result))) {
|
| 481: | if ($myrow['tpl_module'] != '') {
|
| 482: | $ret[$myrow['tpl_module']] = $myrow['count'];
|
| 483: | }
|
| 484: | }
|
| 485: |
|
| 486: | return $ret;
|
| 487: | }
|
| 488: |
|
| 489: | |
| 490: | |
| 491: | |
| 492: | |
| 493: | |
| 494: | |
| 495: | |
| 496: | |
| 497: | |
| 498: | |
| 499: |
|
| 500: | public function find($tplset = null, $type = null, $refid = null, $module = null, $file = null, $getsource = false)
|
| 501: | {
|
| 502: | $criteria = new CriteriaCompo();
|
| 503: | if (isset($tplset)) {
|
| 504: | $criteria->add(new Criteria('tpl_tplset', $tplset));
|
| 505: | }
|
| 506: | if (isset($module)) {
|
| 507: | $criteria->add(new Criteria('tpl_module', $module));
|
| 508: | }
|
| 509: | if (isset($refid)) {
|
| 510: | $criteria->add(new Criteria('tpl_refid', $refid));
|
| 511: | }
|
| 512: | if (isset($file)) {
|
| 513: | $criteria->add(new Criteria('tpl_file', $file));
|
| 514: | }
|
| 515: | if (isset($type)) {
|
| 516: | if (is_array($type)) {
|
| 517: | $criteria2 = new CriteriaCompo();
|
| 518: | foreach ($type as $t) {
|
| 519: | $criteria2->add(new Criteria('tpl_type', $t), 'OR');
|
| 520: | }
|
| 521: | $criteria->add($criteria2);
|
| 522: | } else {
|
| 523: | $criteria->add(new Criteria('tpl_type', $type));
|
| 524: | }
|
| 525: | }
|
| 526: |
|
| 527: | return $this->getObjects($criteria, $getsource, false);
|
| 528: | }
|
| 529: |
|
| 530: | |
| 531: | |
| 532: | |
| 533: | |
| 534: | |
| 535: | |
| 536: |
|
| 537: | public function templateExists($tplname, $tplset_name)
|
| 538: | {
|
| 539: | $criteria = new CriteriaCompo(new Criteria('tpl_file', trim($tplname)));
|
| 540: | $criteria->add(new Criteria('tpl_tplset', trim($tplset_name)));
|
| 541: | return $this->getCount($criteria) > 0;
|
| 542: | }
|
| 543: | }
|
| 544: | |