Cheetah
ChWsbMenuSimple.php
Go to the documentation of this file.
1 <?php
2 
22  {
23  var $sName;
24  var $sDbTable;
26 
28  var $aItems;
29 
31 
32  function __construct()
33  {
34  $this->sName = 'bottom';
35  $this->sDbTable = 'sys_menu_bottom';
36  $this->sCacheKey = 'sys_menu_bottom';
37 
38  $this->aMenuInfo = array();
39  if(isMember()) {
40  $this->aMenuInfo['memberID'] = getLoggedId();
41  $this->aMenuInfo['memberNick'] = getNickName($this->aMenuInfo['memberID']);
42  $this->aMenuInfo['memberPass'] = getPassword($this->aMenuInfo['memberID']);
43  $this->aMenuInfo['memberLink'] = getProfileLink($this->aMenuInfo['memberID']);
44  $this->aMenuInfo['visible'] = 'memb';
45  } else {
46  $this->aMenuInfo['memberID'] = 0;
47  $this->aMenuInfo['memberNick'] = '';
48  $this->aMenuInfo['memberPass'] = '';
49  $this->aMenuInfo['memberLink'] = '';
50  $this->aMenuInfo['visible'] = 'non';
51  }
52  $this->aItems = array();
53 
54  $this->oPermalinks = new ChWsbPermalinks();
55  }
56 
57  function load()
58  {
59  $oCache = $GLOBALS['MySQL']->getDbCacheObject();
60  $this->aItems = $oCache->getData($GLOBALS['MySQL']->genDbCacheKey($this->sCacheKey));
61 
62  if($this->aItems === null) {
63  if(!$this->compile())
64  return false;
65 
66  $this->aItems = $oCache->getData($GLOBALS['MySQL']->genDbCacheKey($this->sCacheKey));
67  }
68 
69  if(!$this->aItems || !is_array($this->aItems)) {
70  echo '<b>Warning!</b> Cannot evaluate ' . $this->sName . ' menu cache.';
71  return false;
72  }
73 
74  return true;
75  }
76 
77  function compile()
78  {
79  $sEval = "return array(\n";
80  $aFields = array('Caption', 'Name', 'Icon', 'Link', 'Script', 'Target', 'Order', 'Visible');
81 
82  $sQuery = "SELECT `ID`, `" . implode('`, `', $aFields ) . "` FROM `" . $this->sDbTable . "` WHERE `Active`='1' ORDER BY `Order`";
83  $rMenu = db_res($sQuery);
84 
85  while($aItem = $rMenu->fetch()) {
86  $sEval .= " " . str_pad( $aItem['ID'], 2 ) . " => array(\n";
87 
88  foreach( $aFields as $sKey => $sField ) {
89  $sCont = $aItem[$sField];
90 
91  $sCont = str_replace( '\\', '\\\\', $sCont );
92  $sCont = str_replace( '"', '\\"', $sCont );
93  $sCont = str_replace( '$', '\\$', $sCont );
94 
95  $sCont = str_replace( "\n", '', $sCont );
96  $sCont = str_replace( "\r", '', $sCont );
97  $sCont = str_replace( "\t", '', $sCont );
98 
99  $sEval .= " " . str_pad( "'$sField'", 11 ) . " => \"$sCont\",\n";
100  }
101 
102  $sEval .= " ),\n";
103  }
104 
105  $sEval .= ");\n";
106  $aResult = eval($sEval);
107 
108  $oCache = $GLOBALS['MySQL']->getDbCacheObject();
109  return $oCache->setData ($GLOBALS['MySQL']->genDbCacheKey($this->sCacheKey), $aResult);
110  }
111 
112  function checkToShow( $aItem )
113  {
114  if(!$this->checkVisible($aItem['Visible']))
115  return false;
116 
117  return true;
118  }
119 
120  function checkVisible( $sVisible )
121  {
122  return strpos($sVisible, $this->aMenuInfo['visible']) !== false;
123  }
124 
125  function replaceMetas($sData)
126  {
127  foreach($this->aMenuInfo as $k => $v)
128  $sData = str_replace('{'.$k.'}', $v, $sData);
129 
130  return $sData;
131  }
132  }
ChWsbMenuSimple\compile
compile()
Definition: ChWsbMenuSimple.php:77
$aResult
$aResult
Definition: index.php:19
$sCont
$sCont
Definition: get_rss_feed.php:36
ChWsbMenuSimple\$sCacheKey
$sCacheKey
Definition: ChWsbMenuSimple.php:25
getPassword
getPassword( $ID='')
Definition: profiles.inc.php:475
ChWsbMenuSimple\$aItems
$aItems
Definition: ChWsbMenuSimple.php:28
php
ChWsbMenuSimple\__construct
__construct()
Definition: ChWsbMenuSimple.php:32
$oCache
$oCache
Definition: prof.inc.php:10
$aFields
$aFields
Definition: preValues.php:19
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
ChWsbMenuSimple
Definition: ChWsbMenuSimple.php:22
ChWsbMenuSimple\checkToShow
checkToShow( $aItem)
Definition: ChWsbMenuSimple.php:112
ChWsbMenuSimple\load
load()
Definition: ChWsbMenuSimple.php:57
getProfileLink
getProfileLink( $iID, $sLinkAdd='')
Definition: profiles.inc.php:484
ChWsbMenuSimple\checkVisible
checkVisible( $sVisible)
Definition: ChWsbMenuSimple.php:120
ChWsbMenuSimple\replaceMetas
replaceMetas($sData)
Definition: ChWsbMenuSimple.php:125
ChWsbMenuSimple\$aMenuInfo
$aMenuInfo
Definition: ChWsbMenuSimple.php:27
ChWsbMenuSimple\$oPermalinks
$oPermalinks
Definition: ChWsbMenuSimple.php:30
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
ChWsbMenuSimple\$sDbTable
$sDbTable
Definition: ChWsbMenuSimple.php:24
ChWsbMenuSimple\$sName
$sName
Definition: ChWsbMenuSimple.php:23
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
isMember
isMember($iId=0)
Definition: profiles.inc.php:44