Cheetah
ChSctrDb.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( CH_DIRECTORY_PATH_CLASSES . 'ChWsbModuleDb.php' );
9 
10 class ChSctrDb extends ChWsbModuleDb
11 {
12  var $_oConfig;
13  /*
14  * Constructor.
15  */
16  function __construct(&$oConfig)
17  {
18  parent::__construct($oConfig);
19 
20  $this->_oConfig = $oConfig;
21  }
22 
23  function getSite()
24  {
25  return $this->getRow("SELECT * FROM `" . $this->_sPrefix . "main` WHERE 1 LIMIT 1");
26  }
27 
28  function getSiteTmp()
29  {
30  $aStyle = $this->getSite();
31  if(!empty($aStyle))
32  return unserialize($aStyle['tmp']);
33 
34  return array();
35  }
36 
37  function getSiteCss()
38  {
39  $aStyle = $this->getSite();
40  if(!empty($aStyle))
41  return unserialize($aStyle['css']);
42 
43  return '';
44  }
45 
46  function updateSite($sStyle, $sType)
47  {
48  $aRow = $this->getSite();
49  if(empty($aRow))
50  return $this->query("INSERT INTO `" . $this->_sPrefix . "main` (`" . $sType . "`) VALUES('" . $sStyle . "')");
51  else
52  return $this->query("UPDATE `" . $this->_sPrefix . "main` SET `" . $sType . "`='" . $sStyle . "' WHERE 1 LIMIT 1");
53  }
54 
55  function saveSite()
56  {
57  return $this->query("UPDATE `" . $this->_sPrefix . "main` SET `css`=`tmp` WHERE 1 LIMIT 1");
58  }
59 
60  function updateSiteTmp($aTmp)
61  {
62  return $this->updateSite(serialize($aTmp), 'tmp');
63  }
64 
65  function updateSiteCss($aCss)
66  {
67  return $this->updateSite(serialize($aCss), 'css');
68  }
69 
70  function resetSite()
71  {
72  return $this->query("DELETE FROM `" . $this->_sPrefix . "main` WHERE 1 LIMIT 1");
73  }
74 
75  function getUnits()
76  {
77  $aResult = array();
78  $aRows = $this->getAll("SELECT `name`, `caption`, `css_name`, `type` FROM `" . $this->_sPrefix . "units`");
79 
80  foreach ($aRows as $aValue) {
81  $aResult[$aValue['type']][$aValue['name']] = array(
82  'name' => $aValue['caption'],
83  'css_name' => $aValue['css_name']
84  );
85  }
86 
87  return $aResult;
88  }
89 
90  function getUnitById($iUnitId)
91  {
92  return $this->getRow("SELECT * FROM `" . $this->_sPrefix . "units` WHERE `id` = ? LIMIT 1", [$iUnitId]);
93  }
94 
95  function deleteUnit($iUnitId)
96  {
97  return $this->query("DELETE FROM `" . $this->_sPrefix . "units` WHERE `id` = ?", [$iUnitId]);
98  }
99 
100  function getAllThemes()
101  {
102  return $this->getAll("SELECT * FROM `" . $this->_sPrefix . "themes` WHERE 1 ORDER BY `id`");
103  }
104 
105  function getSharedThemes()
106  {
107  return $this->getAll("SELECT * FROM `" . $this->_sPrefix . "themes` WHERE `ownerid` = ? ORDER BY `id`", [0]);
108  }
109 
111  {
112  return $this->getRow("SELECT * FROM `" . $this->_sPrefix . "themes` WHERE `name` = ? LIMIT 1", [$sName]);
113  }
114 
115  function getThemeById($iThemeId)
116  {
117  return $this->getRow("SELECT * FROM `" . $this->_sPrefix . "themes` WHERE `id` = ? LIMIT 1", [$iThemeId]);
118  }
119 
120  function getThemeStyle($iThemeId)
121  {
122  if ((int)$iThemeId) {
123  $aTheme = $this->getRow("SELECT * FROM `" . $this->_sPrefix . "themes` WHERE `id` = ? LIMIT 1", [$iThemeId]);
124 
125  if (!empty($aTheme))
126  return unserialize($aTheme['css']);
127  }
128 
129  return array();
130  }
131 
132  function addTheme($sName, $iOwnerId, $sCss)
133  {
134  if($this->query("INSERT INTO `" . $this->_sPrefix . "themes` (`name`, `ownerid`, `css`) VALUES(?, ?, ?)", [$sName, $iOwnerId, $sCss]))
135  return $this->lastId();
136 
137  return -1;
138  }
139 
140  function deleteTheme($iThemeId)
141  {
142  return $this->query("DELETE FROM `" . $this->_sPrefix . "themes` WHERE `id` = ?", [$iThemeId]);
143  }
144 
145  function addImage($sExt)
146  {
147  if (strlen($sExt) > 0 && $this->query("INSERT INTO `" . $this->_sPrefix . "images` (`ext`, `count`) VALUES(?, 1)", [$sExt]))
148  return $this->lastId() . '.' . $sExt;
149 
150  return '';
151  }
152 
153  function copyImage($sFileName)
154  {
155  if (strlen($sFileName) > 0) {
156  $sId = basename($sFileName, '.' . pathinfo($sFileName, PATHINFO_EXTENSION));
157  return strlen($sId) > 0 ? $this->query("UPDATE `" . $this->_sPrefix . "images` SET `count` = `count` + 1 WHERE `id` = ?", [$sId]) : 0;
158  }
159 
160  return 0;
161  }
162 
163  function deleteImage($sFileName)
164  {
165  $sResult = true;
166 
167  if (strlen($sFileName) > 0) {
168  $sId = basename($sFileName, '.' . pathinfo($sFileName, PATHINFO_EXTENSION));
169  if (strlen($sId) > 0 && $this->query("UPDATE `" . $this->_sPrefix . "images` SET `count` = `count` - 1 WHERE `id` = ?", [$sId])) {
170  $aRow = $this->getRow("SELECT * FROM `" . $this->_sPrefix . "images` WHERE `id` = $sId LIMIT 1");
171  if ($aRow['count'] < 1)
172  $this->query("DELETE FROM `" . $this->_sPrefix . "images` WHERE `id` = $sId");
173  else
174  $sResult = false;
175  }
176  }
177 
178  return $sResult;
179  }
180 
182  {
183  return $this->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name` = 'Profile Customizer' LIMIT 1");
184  }
185 }
ChSctrDb\updateSiteCss
updateSiteCss($aCss)
Definition: ChSctrDb.php:65
ChSctrDb\$_oConfig
$_oConfig
Definition: ChSctrDb.php:12
$sResult
$sResult
Definition: advanced_settings.php:26
ChSctrDb\getThemeByName
getThemeByName($sName)
Definition: ChSctrDb.php:110
ChSctrDb\getSiteTmp
getSiteTmp()
Definition: ChSctrDb.php:28
$aResult
$aResult
Definition: index.php:19
ChSctrDb\addImage
addImage($sExt)
Definition: ChSctrDb.php:145
php
ChSctrDb\__construct
__construct(&$oConfig)
Definition: ChSctrDb.php:16
ChWsbModuleDb
Definition: ChWsbModuleDb.php:12
ChWsbDb\getAll
getAll($sQuery, $aBindings=[], $iFetchType=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:206
$sExt
$sExt
Definition: get_file.php:14
ChSctrDb\getUnits
getUnits()
Definition: ChSctrDb.php:75
ChSctrDb\saveSite
saveSite()
Definition: ChSctrDb.php:55
ChSctrDb\getSiteCss
getSiteCss()
Definition: ChSctrDb.php:37
ChSctrDb\copyImage
copyImage($sFileName)
Definition: ChSctrDb.php:153
ChSctrDb\getThemeStyle
getThemeStyle($iThemeId)
Definition: ChSctrDb.php:120
ChWsbDb\getRow
getRow($sQuery, $aBindings=[], $iFetchStyle=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:225
$sType
$sType
Definition: actions.inc.php:11
ChSctrDb\getAllThemes
getAllThemes()
Definition: ChSctrDb.php:100
ChWsbDb\query
query($sQuery, $aBindings=[])
Definition: ChWsbDb.php:386
ChSctrDb\deleteImage
deleteImage($sFileName)
Definition: ChSctrDb.php:163
ChSctrDb\resetSite
resetSite()
Definition: ChSctrDb.php:70
ChSctrDb\getSharedThemes
getSharedThemes()
Definition: ChSctrDb.php:105
ChWsbDb\getOne
getOne($sQuery, $aBindings=[], $iIndex=0)
Definition: ChWsbDb.php:263
ChSctrDb\updateSite
updateSite($sStyle, $sType)
Definition: ChSctrDb.php:46
ChSctrDb\addTheme
addTheme($sName, $iOwnerId, $sCss)
Definition: ChSctrDb.php:132
ChSctrDb\updateSiteTmp
updateSiteTmp($aTmp)
Definition: ChSctrDb.php:60
ChSctrDb\getSettingsCategory
getSettingsCategory()
Definition: ChSctrDb.php:181
ChSctrDb\getSite
getSite()
Definition: ChSctrDb.php:23
$sId
$sId
Definition: actions.inc.php:8
ChSctrDb\getThemeById
getThemeById($iThemeId)
Definition: ChSctrDb.php:115
ChSctrDb\deleteUnit
deleteUnit($iUnitId)
Definition: ChSctrDb.php:95
ChSctrDb\getUnitById
getUnitById($iUnitId)
Definition: ChSctrDb.php:90
ChWsbDb\lastId
lastId()
Definition: ChWsbDb.php:449
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$sName
$sName
Definition: ChWsbAdminTools.php:853
ChSctrDb\deleteTheme
deleteTheme($iThemeId)
Definition: ChSctrDb.php:140
ChSctrDb
Definition: ChSctrDb.php:11