| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 define ('JA_TOOL_COLOR', 'ja_color'); 3 define ('JA_TOOL_SCREEN', 'ja_screen'); 4 define ('JA_TOOL_FONT', 'ja_font'); 5 define ('JA_TOOL_MENU', 'ja_menu'); 6 7 class JA_Tools { 8 var $_params_cookie = null; //Params will store in cookie for user select. Default: store all params 9 var $_tpl = null; 10 var $template = ''; 11 12 function JA_Tools ($template, $_params_cookie=null) { 13 $this->_tpl = $template; 14 $this->template = $template->template; 15 16 if(!$_params_cookie) { 17 $this->_params_cookie = $this->_tpl->params->toArray(); 18 } else { 19 foreach ($_params_cookie as $k) { 20 $this->_params_cookie[$k] = $this->_tpl->params->get($k); 21 } 22 } 23 24 $this->getUserSetting(); 25 } 26 27 function getUserSetting(){ 28 $exp = time() + 60*60*24*355; 29 if (isset($_COOKIE[$this->template.'_tpl']) && $_COOKIE[$this->template.'_tpl'] == $this->template){ 30 foreach($this->_params_cookie as $k=>$v) { 31 $kc = $this->template."_".$k; 32 if (JRequest::getVar($k, null, 'GET') !== null) { 33 $v = preg_replace('/[\x00-\x1F\x7F<>;\/\"\'%()]/', '', JRequest::getString($k, '', 'GET')); 34 setcookie ($kc, $v, $exp, '/'); 35 }else{ 36 if (isset($_COOKIE[$kc])){ 37 $v = $_COOKIE[$kc]; 38 } 39 } 40 $this->setParam($k, $v); 41 } 42 43 }else{ 44 setcookie ($this->template.'_tpl', $this->template, $exp, '/'); 45 } 46 return $this; 47 } 48 49 function getParam ($param, $default='') { 50 if (isset($this->_params_cookie[$param])) { 51 return preg_replace('/[\x00-\x1F\x7F<>;\/\"\'%()]/', '', $this->_params_cookie[$param]); 52 } 53 return preg_replace('/[\x00-\x1F\x7F<>;\/\"\'%()]/', '', $this->_tpl->params->get($param, $default)); 54 } 55 56 function setParam ($param, $value) { 57 $this->_params_cookie[$param] = $value; 58 } 59 60 function getCurrentURL(){ 61 $cururl = JRequest::getURI(); 62 if(($pos = strpos($cururl, "index.php"))!== false){ 63 $cururl = substr($cururl,$pos); 64 } 65 $cururl = JRoute::_($cururl, true, 0); 66 return $cururl; 67 } 68 69 function genToolMenu($_array_tools=null, $imgext = 'gif'){ 70 if(!is_array($_array_tools)) $_array_tools = array($_array_tools); 71 if(!$_array_tools) $_array_tools = array_keys($this->_params_cookie); 72 if (in_array(JA_TOOL_FONT, $_array_tools)){//show font tools 73 ?> 74 <ul class="ja-usertools-font"> 75 <li><img style="cursor: pointer;" title="<?php echo JText::_('Increase font size');?>" src="<?php echo $this->templateurl();?>/images/user-increase.<?php echo $imgext;?>" alt="<?php echo JText::_('Increase font size');?>" id="ja-tool-increase" onclick="switchFontSize('<?php echo $this->template."_".JA_TOOL_FONT;?>','inc'); return false;" /></li> 76 <li><img style="cursor: pointer;" title="<?php echo JText::_('Default font size');?>" src="<?php echo $this->templateurl();?>/images/user-reset.<?php echo $imgext;?>" alt="<?php echo JText::_('Default font size');?>" id="ja-tool-reset" onclick="switchFontSize('<?php echo $this->template."_".JA_TOOL_FONT;?>',<?php echo $this->_tpl->params->get(JA_TOOL_FONT);?>); return false;" /></li> 77 <li><img style="cursor: pointer;" title="<?php echo JText::_('Decrease font size');?>" src="<?php echo $this->templateurl();?>/images/user-decrease.<?php echo $imgext;?>" alt="<?php echo JText::_('Decrease font size');?>" id="ja-tool-decrease" onclick="switchFontSize('<?php echo $this->template."_".JA_TOOL_FONT;?>','dec'); return false;" /></li> 78 </ul> 79 <script type="text/javascript">var CurrentFontSize=parseInt('<?php echo $this->getParam(JA_TOOL_FONT);?>');</script> 80 <?php 81 } 82 } 83 84 function getCurrentMenuIndex(){ 85 $Itemid = JRequest::getInt( 'Itemid'); 86 $database =& JFactory::getDBO(); 87 $id = $Itemid; 88 $menutype = 'mainmenu'; 89 $ordering = '0'; 90 while (1){ 91 $sql = "select parent, menutype, ordering from #__menu where id = $id limit 1"; 92 $database->setQuery($sql); 93 $row = null; 94 $row = $database->loadObject(); 95 if ($row) { 96 $menutype = $row->menutype; 97 $ordering = $row->ordering; 98 if ($row->parent > 0) 99 { 100 $id = $row->parent; 101 }else break; 102 }else break; 103 } 104 105 $user =& JFactory::getUser(); 106 $sql = 'SELECT count(*) FROM #__menu AS m' 107 . ' WHERE menutype=' . $database -> Quote($menutype) 108 . ' AND published=1 AND parent=0 and ordering < ' . $ordering 109 ; 110 if (isset($user)) { 111 $aid = $user->get('aid', 0); 112 $sql .= " AND access <= '$aid'"; 113 } 114 $database->setQuery($sql); 115 116 return $database->loadResult(); 117 } 118 119 function calSpotlight ($spotlight, $totalwidth=100, $firstwidth=0) { 120 121 /******************************************** 122 $spotlight = array ('position1', 'position2',...) 123 *********************************************/ 124 $modules = array(); 125 $modules_s = array(); 126 foreach ($spotlight as $position) { 127 if( $this->_tpl->countModules ($position) ){ 128 $modules_s[] = $position; 129 } 130 $modules[$position] = array('class'=>'-full', 'width'=>$totalwidth); 131 } 132 133 if (!count($modules_s)) return null; 134 135 if ($firstwidth) { 136 if (count($modules_s)>1) { 137 $width = round(($totalwidth-$firstwidth)/(count($modules_s)-1),1) . "%"; 138 $firstwidth = $firstwidth . "%"; 139 }else{ 140 $firstwidth = $totalwidth . "%"; 141 } 142 }else{ 143 $width = round($totalwidth/(count($modules_s)),1) . "%"; 144 $firstwidth = $width; 145 } 146 147 if (count ($modules_s) > 1){ 148 $modules[$modules_s[0]]['class'] = "-left"; 149 $modules[$modules_s[0]]['width'] = $firstwidth; 150 $modules[$modules_s[count ($modules_s) - 1]]['class'] = "-right"; 151 $modules[$modules_s[count ($modules_s) - 1]]['width'] = $width; 152 for ($i=1; $i<count ($modules_s) - 1; $i++){ 153 $modules[$modules_s[$i]]['class'] = "-center"; 154 $modules[$modules_s[$i]]['width'] = $width; 155 } 156 } 157 return $modules; 158 } 159 160 function isIE6 () { 161 return $this->browser() == 'IE6'; 162 } 163 164 function baseurl(){ 165 return JURI::base(); 166 } 167 168 function templateurl(){ 169 return JURI::base()."templates/".$this->template; 170 } 171 172 function getRandomImage ($img_folder) { 173 $imglist=array(); 174 175 mt_srand((double)microtime()*1000); 176 177 //use the directory class 178 $imgs = dir($img_folder); 179 180 //read all files from the directory, checks if are images and ads them to a list (see below how to display flash banners) 181 while ($file = $imgs->read()) { 182 if (preg_match("#gif#i", $file) || preg_match("#jpg#i", $file) || preg_match("#png#i", $file)) 183 $imglist[] = $file; 184 } 185 closedir($imgs->handle); 186 187 if(!count($imglist)) return ''; 188 189 //generate a random number between 0 and the number of images 190 $random = mt_rand(0, count($imglist)-1); 191 $image = $imglist[$random]; 192 193 return $image; 194 } 195 196 function isFrontPage(){ 197 return (JRequest::getCmd( 'view' ) == 'frontpage') ; 198 } 199 200 function sitename() { 201 $config = new JConfig(); 202 return $config->sitename; 203 } 204 205 function browser () { 206 $agent = $_SERVER['HTTP_USER_AGENT']; 207 if ( strpos($agent, 'Gecko') ) 208 { 209 if ( strpos($agent, 'Netscape') ) 210 { 211 $browser = 'NS'; 212 } 213 else if ( strpos($agent, 'Firefox') ) 214 { 215 $browser = 'FF'; 216 } 217 else 218 { 219 $browser = 'Moz'; 220 } 221 } 222 else if ( strpos($agent, 'MSIE') && !preg_match('/opera/i',$agent) ) 223 { 224 $msie='/msie\s(7\.[0-9]).*(win)/i'; 225 if (preg_match($msie,$agent)) $browser = 'IE7'; 226 else $browser = 'IE6'; 227 } 228 else if ( preg_match('/opera/i',$agent) ) 229 { 230 $browser = 'OPE'; 231 } 232 else 233 { 234 $browser = 'Others'; 235 } 236 return $browser; 237 } 238 } 239 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |