table_common_diy_data.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: table_common_diy_data.php 27827 2012-02-15 07:03:43Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_diy_data extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_diy_data';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function fetch($targettplname, $tpldirectory) {
  19. return !empty($targettplname) ? DB::fetch_first('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('targettplname', $targettplname).' AND '.DB::field('tpldirectory', $tpldirectory)) : array();
  20. }
  21. public function delete($targettplname, $tpldirectory = null) {
  22. foreach($this->fetch_all($targettplname, $tpldirectory) as $value) {
  23. $file = ($value['tpldirectory'] ? $value['tpldirectory'].'/' : '').$value['targettplname'];
  24. @unlink(DISCUZ_ROOT.'./data/diy/'.$file.'.htm');
  25. @unlink(DISCUZ_ROOT.'./data/diy/'.$file.'.htm.bak');
  26. @unlink(DISCUZ_ROOT.'./data/diy/'.$file.'_diy_preview.htm');
  27. }
  28. return DB::delete($this->_table, DB::field('targettplname', $targettplname).($tpldirectory !== null ? ' AND '.DB::field('tpldirectory', $tpldirectory) : ''));
  29. }
  30. public function update($targettplname, $tpldirectory, $data) {
  31. if(!empty($targettplname) && !empty($data) && is_array($data)) {
  32. return DB::update($this->_table, $data, DB::field('targettplname', $targettplname).' AND '.DB::field('tpldirectory', $tpldirectory));
  33. }
  34. return false;
  35. }
  36. public function fetch_all($targettplname, $tpldirectory = null) {
  37. return !empty($targettplname) ? DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('targettplname', $targettplname).($tpldirectory !== null ? ' AND '.DB::field('tpldirectory', $tpldirectory) : '')) : array();
  38. }
  39. public function count_by_where($wheresql) {
  40. $wheresql = $wheresql ? ' WHERE '.$wheresql : '';
  41. return DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).$wheresql);
  42. }
  43. public function fetch_all_by_where($wheresql, $ordersql, $start, $limit) {
  44. $wheresql = $wheresql ? ' WHERE '.$wheresql : '';
  45. return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).$wheresql.' '.$ordersql.DB::limit($start, $limit), null, $this->_pk ? $this->_pk : '');
  46. }
  47. }
  48. ?>