Annotation of /mambo/branches/4.6/administrator/includes/admin.php
Parent Directory
|
Revision Log
Revision 138 - (view) (download)
| 1 : | mambo | 117 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: admin.php,v 1.1 2005/07/22 01:53:54 eddieajau Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * Mambo is Free Software | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | /** ensure this file is being included by a parent file */ | ||
| 11 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 12 : | |||
| 13 : | /** | ||
| 14 : | csouza | 129 | * Basic XML parsing of installation files |
| 15 : | ***/ | ||
| 16 : | |||
| 17 : | class mosBasicXML { | ||
| 18 : | var $opentags = array(); | ||
| 19 : | var $opencount; | ||
| 20 : | var $accept = array(); | ||
| 21 : | var $mosinstall = false; | ||
| 22 : | var $type; | ||
| 23 : | var $terminalError = false; | ||
| 24 : | var $errors = array(); | ||
| 25 : | csouza | 138 | var $mosParameter = null; |
| 26 : | var $name = ''; | ||
| 27 : | csouza | 129 | |
| 28 : | csouza | 138 | function mosBasicXML ($file, $mosParameter=null, $name='params') { |
| 29 : | |||
| 30 : | $this->modParameter = $mosParameter; | ||
| 31 : | $this->name = $name; | ||
| 32 : | csouza | 129 | $this->setTree(); |
| 33 : | $parser = xml_parser_create(); | ||
| 34 : | csouza | 138 | xml_set_element_handler ($parser, array ($this, 'start_element'), array ($this, 'end_element')); |
| 35 : | xml_set_character_data_handler ($parser, array ($this, 'character_data')); | ||
| 36 : | |||
| 37 : | csouza | 129 | $fp = fopen($file, 'rb'); |
| 38 : | while ($data = fread($fp, 4096) AND !$this->terminalError) { | ||
| 39 : | $data = str_replace('&', ' ampersand ', $data); | ||
| 40 : | $ret = xml_parse($parser, $data, feof($fp)) or die (sprintf('XML ERROR: %s at line %d', | ||
| 41 : | xml_error_string(xml_get_error_code($parser)), | ||
| 42 : | xml_get_current_line_number($parser))); | ||
| 43 : | } | ||
| 44 : | if (count($this->opentags) != 0) { | ||
| 45 : | $tags = implode (', ', $this->opentags); | ||
| 46 : | trigger_error ("XML error - unclosed tag(s) ($tags) at end of file"); | ||
| 47 : | } | ||
| 48 : | xml_parser_free($parser); | ||
| 49 : | if (count($this->errors)) var_dump ($this->errors); | ||
| 50 : | } | ||
| 51 : | |||
| 52 : | function setTree () { | ||
| 53 : | $this->accept['MOSINSTALL'] = array ('NAME', 'CREATIONDATE', 'AUTHOR', 'COPYRIGHT', | ||
| 54 : | 'LICENSE', 'AUTHOREMAIL', 'AUTHORURL', 'VERSION', 'DESCRIPTION', 'FILES', 'GROUP', | ||
| 55 : | 'PARAMS', 'INSTALL', 'UNINSTALL', 'INSTALLFILE', 'UNINSTALLFILE', 'ADMINISTRATION', | ||
| 56 : | 'IMAGES', 'CSS'); | ||
| 57 : | $this->accept['PARAMS'] = array ('PARAM'); | ||
| 58 : | $this->accept['PARAM'] = array ('OPTION'); | ||
| 59 : | $this->accept['FILES'] = array ('FILENAME'); | ||
| 60 : | $this->accept['INSTALL'] = array ('QUERIES'); | ||
| 61 : | $this->accept['UNINSTALL'] = array ('QUERIES'); | ||
| 62 : | $this->accept['QUERIES'] = array ('QUERY'); | ||
| 63 : | $this->accept['ADMINISTRATION'] = array ('FILES', 'IMAGES', 'MENU'); | ||
| 64 : | $this->accept['IMAGES'] = array ('FILENAME'); | ||
| 65 : | $this->accept['MENU'] = array ('SUBMENU'); | ||
| 66 : | $this->accept['SUBMENU'] = array('MENU'); | ||
| 67 : | $this->accept['CSS'] = array('FILENAME'); | ||
| 68 : | } | ||
| 69 : | |||
| 70 : | function start_element ($parser, $element_name, $element_attrs) { | ||
| 71 : | if ($this->terminalError) return; | ||
| 72 : | $method = 'element_'.$element_name; | ||
| 73 : | csouza | 138 | |
| 74 : | csouza | 129 | $specific = array ($this, $method); |
| 75 : | if (is_callable($specific)) $this->$method($element_attrs); | ||
| 76 : | if ($this->mosinstall) { | ||
| 77 : | $container = $this->opentags[0]; | ||
| 78 : | if (!isset($this->accept[$container]) OR !is_array($this->accept[$container])) trigger_error ("XML error $container is not a valid containing element"); | ||
| 79 : | if (!in_array($element_name, $this->accept[$container])) trigger_error ("XML error $element_name not permitted within $container"); | ||
| 80 : | } | ||
| 81 : | if ($this->mosinstall OR $element_name == 'MOSINSTALL') { | ||
| 82 : | $this->opencount = array_unshift ($this->opentags, $element_name); | ||
| 83 : | csouza | 138 | dump($this->opentags); |
| 84 : | csouza | 129 | $setdata = array ($this, 'set_data'); |
| 85 : | if (is_callable($setdata)) $this->set_data($element_attrs); | ||
| 86 : | $this->mosinstall = true; | ||
| 87 : | } | ||
| 88 : | else trigger_error ("XML expected MOSINSTALL but found $element_name"); | ||
| 89 : | // echo '<br />Start of '.$element_name; | ||
| 90 : | } | ||
| 91 : | |||
| 92 : | function end_element ($parser, $element_name) { | ||
| 93 : | if ($this->terminalError) return; | ||
| 94 : | $check = array_shift ($this->opentags); | ||
| 95 : | csouza | 138 | dump($this); |
| 96 : | csouza | 129 | if ($check != $element_name) { |
| 97 : | $this->opencount = array_unshift ($this->opentags, $check); | ||
| 98 : | trigger_error("XML last open tag was $check, but found end of $element_name"); | ||
| 99 : | } | ||
| 100 : | else $this->opencount--; | ||
| 101 : | csouza | 138 | $method = 'end_element_'.$element_name; |
| 102 : | $specific = array ($this, $method); | ||
| 103 : | if (is_callable($specific)) $this->$method(); | ||
| 104 : | csouza | 129 | // echo '<br />End of '.$element_name; |
| 105 : | } | ||
| 106 : | |||
| 107 : | function character_data ($parser, $data) { | ||
| 108 : | // Should be overridden by inheriting class | ||
| 109 : | $this->errors[] = 'XML handler error - no method provided to deal with character data'; | ||
| 110 : | $this->terminalError = true; | ||
| 111 : | } | ||
| 112 : | |||
| 113 : | function element_mosinstall ($attrs) { | ||
| 114 : | if (isset($attrs['TYPE'])) $this->type = $attrs['TYPE']; | ||
| 115 : | else trigger_error ("XML error - mosinstall does not have type attribute"); | ||
| 116 : | } | ||
| 117 : | |||
| 118 : | function getType () { | ||
| 119 : | return $this->type; | ||
| 120 : | } | ||
| 121 : | |||
| 122 : | } | ||
| 123 : | |||
| 124 : | /** | ||
| 125 : | * Extend basic parser to extract the description for a type of install file | ||
| 126 : | **/ | ||
| 127 : | |||
| 128 : | class mosXMLDescription extends mosBasicXML { | ||
| 129 : | var $values = array(); | ||
| 130 : | |||
| 131 : | function character_data ($parser, $data) { | ||
| 132 : | if ($this->terminalError) return; | ||
| 133 : | csouza | 138 | $this->topLevelCharacterData($data); |
| 134 : | } | ||
| 135 : | |||
| 136 : | function topLevelCharacterData ($data) { | ||
| 137 : | if ($data = trim($data)) { | ||
| 138 : | csouza | 129 | if (isset($this->opentags[1]) AND $this->opentags[1] == 'MOSINSTALL') $this->values[$this->opentags[0]] = $data; |
| 139 : | } | ||
| 140 : | } | ||
| 141 : | |||
| 142 : | function getDescription ($type) { | ||
| 143 : | if ($type == $this->type AND isset($this->values['DESCRIPTION'])) return $this->values['DESCRIPTION']; | ||
| 144 : | else return ''; | ||
| 145 : | } | ||
| 146 : | |||
| 147 : | function getName ($type) { | ||
| 148 : | if ($type == $this->type AND isset($this->values['NAME'])) return $this->values['NAME']; | ||
| 149 : | else return ''; | ||
| 150 : | } | ||
| 151 : | |||
| 152 : | function getGroup ($type) { | ||
| 153 : | if ($type == $this->type AND isset($this->values['GROUP'])) return $this->values['GROUP']; | ||
| 154 : | else return ''; | ||
| 155 : | } | ||
| 156 : | |||
| 157 : | function getCreationDate ($type) { | ||
| 158 : | if ($type == $this->type AND isset($this->values['CREATIONDATE'])) return $this->values['CREATIONDATE']; | ||
| 159 : | else return ''; | ||
| 160 : | } | ||
| 161 : | |||
| 162 : | function getAuthor ($type) { | ||
| 163 : | if ($type == $this->type AND isset($this->values['AUTHOR'])) return $this->values['AUTHOR']; | ||
| 164 : | else return ''; | ||
| 165 : | } | ||
| 166 : | |||
| 167 : | function getCopyright ($type) { | ||
| 168 : | if ($type == $this->type AND isset($this->values['COPYRIGHT'])) return $this->values['COPYRIGHT']; | ||
| 169 : | else return ''; | ||
| 170 : | } | ||
| 171 : | |||
| 172 : | function getAuthorEmail ($type) { | ||
| 173 : | if ($type == $this->type AND isset($this->values['AUTHOREMAIL'])) return $this->values['AUTHOREMAIL']; | ||
| 174 : | else return ''; | ||
| 175 : | } | ||
| 176 : | |||
| 177 : | function getAuthorUrl ($type) { | ||
| 178 : | if ($type == $this->type AND isset($this->values['AUTHORURL'])) return $this->values['AUTHORURL']; | ||
| 179 : | else return ''; | ||
| 180 : | } | ||
| 181 : | |||
| 182 : | function getVersion ($type) { | ||
| 183 : | if ($type == $this->type AND isset($this->values['VERSION'])) return $this->values['VERSION']; | ||
| 184 : | else return ''; | ||
| 185 : | } | ||
| 186 : | |||
| 187 : | } | ||
| 188 : | |||
| 189 : | csouza | 138 | class mosXMLParams extends mosXMLDescription { |
| 190 : | var $options = array(); | ||
| 191 : | var $optvalue = ''; | ||
| 192 : | var $optdata = ''; | ||
| 193 : | var $paramattrs = array(); | ||
| 194 : | var $paramcount = 0; | ||
| 195 : | var $html = array(); | ||
| 196 : | |||
| 197 : | function element_params ($attrs) { | ||
| 198 : | $this->html[] = '<table class="paramlist">'; | ||
| 199 : | if (isset($attrs['NAME'])) { | ||
| 200 : | $pname = $attrs['NAME']; | ||
| 201 : | $this->html[] = "<tr><td colspan='3'>$pname</td></tr>"; | ||
| 202 : | } | ||
| 203 : | } | ||
| 204 : | |||
| 205 : | function element_param ($attrs) { | ||
| 206 : | $this->paramattrs = $attrs; | ||
| 207 : | } | ||
| 208 : | |||
| 209 : | function element_option ($attrs) { | ||
| 210 : | if (isset($attrs['VALUE'])) $optvalue = $attrs['VALUE']; | ||
| 211 : | } | ||
| 212 : | |||
| 213 : | function character_data ($parser, $data) { | ||
| 214 : | if ($this->terminalError) return; | ||
| 215 : | $this->topLevelCharacterData($data); | ||
| 216 : | if ($this->opentags[0] == 'OPTION') $this->optdata = $data; | ||
| 217 : | } | ||
| 218 : | |||
| 219 : | function end_element_option () { | ||
| 220 : | $this->options[] = mosHTML::makeOption($this->optvalue, $this->optdata); | ||
| 221 : | $this->optdata = ''; | ||
| 222 : | $this->optvalue = ''; | ||
| 223 : | } | ||
| 224 : | |||
| 225 : | function end_element_param () { | ||
| 226 : | $type = mosGetParam ($this->paramattrs, 'TYPE', ''); | ||
| 227 : | $name = mosGetParam ($this->paramattrs, 'NAME', ''); | ||
| 228 : | $label = mosGetParam ($this->paramattrs, 'LABEL', $name); | ||
| 229 : | $default = mosGetParam ($this->paramattrs, 'DEFAULT', ''); | ||
| 230 : | if ($description = mosGetParam ($this->paramattrs, 'DESCRIPTION', '')) $tooltip = mosToolTip($description, $name); | ||
| 231 : | else $tooltip = ''; | ||
| 232 : | if (is_object($this->mosParameter)) $value = $this->mosParameter->get($name, $default); | ||
| 233 : | else $value = $default; | ||
| 234 : | $this->html[] = '<tr>'; | ||
| 235 : | if ($label == '@spacer') $label = '<hr />'; | ||
| 236 : | elseif ($label) $label .= ':'; | ||
| 237 : | $this->html[] = '<td width="35%" align="right" valign="top">'.$label.'</td>'; | ||
| 238 : | $controlname = $this->name; | ||
| 239 : | switch ($type) { | ||
| 240 : | case 'text': | ||
| 241 : | $size = mosGetParam ($this->paramattrs, 'SIZE', 0); | ||
| 242 : | $controlstring = '<input type="text" name="'.$this->name.'['.$name.']" value="'.$value.'" class="text_area" size="'.$size.'" />'; | ||
| 243 : | break; | ||
| 244 : | case 'list': | ||
| 245 : | $controlstring = mosHTML::selectList($this->options, "$controlname[$name]", 'class="inputbox"', 'value', 'text', $value); | ||
| 246 : | break; | ||
| 247 : | case 'radio': | ||
| 248 : | $controlstring = mosHTML::radioList($this->options, "$controlname[$name]", $value); | ||
| 249 : | break; | ||
| 250 : | case 'imagelist': | ||
| 251 : | $directory = new mosDirectory (mamboCore::get('mosConfig_absolute_path').mosGetParam($this->paramattrs, 'DIRECTORY', '')); | ||
| 252 : | $files = $directory->listFiles ('\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$'); | ||
| 253 : | $options = array(); | ||
| 254 : | foreach ($files as $file) $options[] = mosHTML::makeOption($file, $file); | ||
| 255 : | if (!isset($this->paramattrs['HIDE_NONE'])) array_unshift($options, mosHTML::makeOption('-1', '- Do not use an image -' )); | ||
| 256 : | if (!isset($this->paramattrs['HIDE_DEFAULT'])) array_unshift($options, mosHTML::makeOption('', '- Use Default image -')); | ||
| 257 : | $controlstring = mosHTML::selectList ($options, "$controlname[$name]", 'class="inputbox"', 'value', 'text', $value); | ||
| 258 : | break; | ||
| 259 : | case 'textarea': | ||
| 260 : | $rows = mosGetParam ($this->paramattrs, 'ROWS', 0); | ||
| 261 : | $cols = mosGetParam ($this->paramattrs, 'COLS', 0); | ||
| 262 : | $value = str_replace ('<br /', "\n", $value); | ||
| 263 : | $controlstring = "<textarea name='params[$name]' cols='$cols' rows='$rows' class='text_area'>$value</textarea>"; | ||
| 264 : | break; | ||
| 265 : | case 'spacer': | ||
| 266 : | $controlstring = $value ? $value : '<hr />'; | ||
| 267 : | break; | ||
| 268 : | case 'mos_section': | ||
| 269 : | $controlstring = _form_mos_section($name, $value, $controlname); | ||
| 270 : | break; | ||
| 271 : | case 'mos_category': | ||
| 272 : | $controlstring = _form_mos_category($name, $value, $controlname); | ||
| 273 : | break; | ||
| 274 : | case 'mos_menu': | ||
| 275 : | default: | ||
| 276 : | $controlstring = _HANDLER.'='.$type; | ||
| 277 : | } | ||
| 278 : | // $this->html[] = "<td>$type</td>"; | ||
| 279 : | $this->html[] = "<td>$controlstring</td>"; | ||
| 280 : | $this->html[] = "<td width='10%' align='left' valign='top'>$tooltip</td>"; | ||
| 281 : | $this->html[] = '</tr>'; | ||
| 282 : | $this->options = array(); | ||
| 283 : | $this->paramattrs = array(); | ||
| 284 : | $this->paramcount++; | ||
| 285 : | } | ||
| 286 : | |||
| 287 : | function end_element_params () { | ||
| 288 : | $this->html[] = '</table>'; | ||
| 289 : | if ($this->paramcount == 0) $this->html[] = '<tr><td colspan="2"><i>'._NO_PARAMS.'</i></td></tr>'; | ||
| 290 : | $this->paramcount = 0; | ||
| 291 : | } | ||
| 292 : | /** | ||
| 293 : | * @param string The name of the form element | ||
| 294 : | * @param string The value of the element | ||
| 295 : | * @param object The xml element for the parameter | ||
| 296 : | * @param string The control name | ||
| 297 : | * @return string The html for the element | ||
| 298 : | */ | ||
| 299 : | function _form_mos_section( $name, $value, $control_name ) { | ||
| 300 : | $database = mamboDatabase::getInstance(); | ||
| 301 : | $query = "SELECT id AS value, title AS text" | ||
| 302 : | . "\n FROM #__sections" | ||
| 303 : | . "\n WHERE published='1' AND scope='content'" | ||
| 304 : | . "\n ORDER BY title" | ||
| 305 : | ; | ||
| 306 : | $database->setQuery( $query ); | ||
| 307 : | $options = $database->loadObjectList(); | ||
| 308 : | array_unshift($options, mosHTML::makeOption( '0', '- Select Content Section -' )); | ||
| 309 : | return mosHTML::selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value ); | ||
| 310 : | } | ||
| 311 : | /** | ||
| 312 : | * @param string The name of the form element | ||
| 313 : | * @param string The value of the element | ||
| 314 : | * @param object The xml element for the parameter | ||
| 315 : | * @param string The control name | ||
| 316 : | * @return string The html for the element | ||
| 317 : | */ | ||
| 318 : | function _form_mos_category( $name, $value, $control_name ) { | ||
| 319 : | $database = mamboDatabase::getInstance(); | ||
| 320 : | $query = "SELECT c.id AS value, CONCAT_WS( '/',s.title, c.title ) AS text" | ||
| 321 : | . "\n FROM #__categories AS c" | ||
| 322 : | . "\n LEFT JOIN #__sections AS s ON s.id=c.section" | ||
| 323 : | . "\n WHERE c.published='1' AND s.scope='content'" | ||
| 324 : | . "\n ORDER BY c.title" | ||
| 325 : | ; | ||
| 326 : | $database->setQuery( $query ); | ||
| 327 : | $options = $database->loadObjectList(); | ||
| 328 : | array_unshift($options, mosHTML::makeOption('0', '- Select Content Category -')); | ||
| 329 : | return mosHTML::selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value ); | ||
| 330 : | } | ||
| 331 : | /** | ||
| 332 : | * @param string The name of the form element | ||
| 333 : | * @param string The value of the element | ||
| 334 : | * @param object The xml element for the parameter | ||
| 335 : | * @param string The control name | ||
| 336 : | * @return string The html for the element | ||
| 337 : | */ | ||
| 338 : | // function _form_mos_menu( $name, $value, &$node, $control_name ) { | ||
| 339 : | // global $database; | ||
| 340 : | // | ||
| 341 : | // $menuTypes = $mainframe->menutypes(); | ||
| 342 : | // | ||
| 343 : | // foreach($menuTypes as $menutype ) { | ||
| 344 : | // $options[] = mosHTML::makeOption( $menutype, $menutype ); | ||
| 345 : | // } | ||
| 346 : | // array_unshift( $options, mosHTML::makeOption( '', '- Select Menu -' ) ); | ||
| 347 : | // | ||
| 348 : | // return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value ); | ||
| 349 : | // } | ||
| 350 : | } | ||
| 351 : | |||
| 352 : | csouza | 129 | /** |
| 353 : | csouza | 138 | * Parameters handler |
| 354 : | * @package Mambo | ||
| 355 : | */ | ||
| 356 : | class mosAdminParameters extends mosParameters { | ||
| 357 : | /** @var string Path to the xml setup file */ | ||
| 358 : | var $_path = null; | ||
| 359 : | /** @var string The type of setup file */ | ||
| 360 : | var $_type = null; | ||
| 361 : | /** @var object The xml params element */ | ||
| 362 : | var $_xmlElem = null; | ||
| 363 : | /** | ||
| 364 : | * Constructor | ||
| 365 : | * @param string The raw parms text | ||
| 366 : | * @param string Path to the xml setup file | ||
| 367 : | * @var string The type of setup file | ||
| 368 : | */ | ||
| 369 : | function mosAdminParameters( $text, $path='', $type='component' ) { | ||
| 370 : | $this->_params = $this->parse( $text ); | ||
| 371 : | $this->_raw = $text; | ||
| 372 : | $this->_path = $path; | ||
| 373 : | $this->_type = $type; | ||
| 374 : | } | ||
| 375 : | |||
| 376 : | /** | ||
| 377 : | * @param string The name of the control, or the default text area if a setup file is not found | ||
| 378 : | * @return string HTML | ||
| 379 : | */ | ||
| 380 : | function render( $name='params' ) { | ||
| 381 : | $parser = new mosXMLParams ($this->_path, $this, $name); | ||
| 382 : | if (count($parser->html)) return implode("\n", $parser->html); | ||
| 383 : | else { | ||
| 384 : | $raw = $this->_raw; | ||
| 385 : | return "<textarea name='$name' cols='40' rows='10' class='text_area'$raw</textarea>"; | ||
| 386 : | } | ||
| 387 : | } | ||
| 388 : | |||
| 389 : | } | ||
| 390 : | /** | ||
| 391 : | mambo | 117 | * @param string THe template position |
| 392 : | */ | ||
| 393 : | function mosCountAdminModules( $position='left' ) { | ||
| 394 : | global $database, $my, $Itemid; | ||
| 395 : | |||
| 396 : | $query = "SELECT COUNT(m.id)" | ||
| 397 : | . "\nFROM #__modules AS m" | ||
| 398 : | . "\nWHERE m.published='1' AND m.position='$position' AND m.client_id='1'"; | ||
| 399 : | |||
| 400 : | $database->setQuery( $query ); | ||
| 401 : | return $database->loadResult(); | ||
| 402 : | } | ||
| 403 : | /** | ||
| 404 : | * Loads admin modules via module position | ||
| 405 : | * @param string The position | ||
| 406 : | * @param int 0 = no style, 1 = tabbed | ||
| 407 : | */ | ||
| 408 : | function mosLoadAdminModules( $position='left', $style=0 ) { | ||
| 409 : | global $database, $my, $acl; | ||
| 410 : | |||
| 411 : | $cache =& mosCache::getCache( 'com_content' ); | ||
| 412 : | |||
| 413 : | $query = "SELECT id, title, module, position, content, showtitle, params" | ||
| 414 : | . "\n FROM #__modules AS m" | ||
| 415 : | . "\n WHERE m.published = '1'" | ||
| 416 : | . "\n AND m.position='$position'" | ||
| 417 : | . "\n AND (m.client_id = 1)" | ||
| 418 : | . "\n ORDER BY m.ordering"; | ||
| 419 : | |||
| 420 : | $database->setQuery( $query ); | ||
| 421 : | $modules = $database->loadObjectList(); | ||
| 422 : | if($database->getErrorNum()) { | ||
| 423 : | echo "MA ".$database->stderr(true); | ||
| 424 : | return; | ||
| 425 : | } | ||
| 426 : | if (!$modules) $modules = array(); | ||
| 427 : | |||
| 428 : | switch ($style) { | ||
| 429 : | case 0: | ||
| 430 : | default: | ||
| 431 : | foreach ($modules as $module) { | ||
| 432 : | $params =& new mosParameters( $module->params ); | ||
| 433 : | if ( $module->module == '' ) { | ||
| 434 : | mosLoadCustomModule( $module, $params ); | ||
| 435 : | } else { | ||
| 436 : | mosLoadAdminModule( substr( $module->module, 4 ), $params ); | ||
| 437 : | } | ||
| 438 : | } | ||
| 439 : | break; | ||
| 440 : | |||
| 441 : | case 1: | ||
| 442 : | // Tabs | ||
| 443 : | $tabs = new mosTabs(1); | ||
| 444 : | $tabs->startPane( 'modules-' . $position ); | ||
| 445 : | foreach ($modules as $module) { | ||
| 446 : | $params =& new mosParameters( $module->params ); | ||
| 447 : | $editAllComponents = $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ); | ||
| 448 : | // $authoriser = new mosAuthoriser($database); | ||
| 449 : | // $editAllComponents = $authoriser->checkPermission('mosUser', $my->id, 'edit', 'editAllComponents', 0); | ||
| 450 : | // special handling for components module | ||
| 451 : | if ( $module->module != 'mod_components' || ( $module->module == 'mod_components' && $editAllComponents ) ) { | ||
| 452 : | $tabs->startTab( $module->title, 'module' . $module->id ); | ||
| 453 : | if ( $module->module == '' ) { | ||
| 454 : | mosLoadCustomModule( $module, $params ); | ||
| 455 : | } else { | ||
| 456 : | mosLoadAdminModule( substr( $module->module, 4 ), $params ); | ||
| 457 : | } | ||
| 458 : | $tabs->endTab(); | ||
| 459 : | } | ||
| 460 : | } | ||
| 461 : | $tabs->endPane(); | ||
| 462 : | break; | ||
| 463 : | |||
| 464 : | case 2: | ||
| 465 : | // Div'd | ||
| 466 : | foreach ($modules as $module) { | ||
| 467 : | $params =& new mosParameters( $module->params ); | ||
| 468 : | echo '<div>'; | ||
| 469 : | if ( $module->module == '' ) { | ||
| 470 : | mosLoadCustomModule( $module, $params ); | ||
| 471 : | } else { | ||
| 472 : | mosLoadAdminModule( substr( $module->module, 4 ), $params ); | ||
| 473 : | } | ||
| 474 : | echo '</div>'; | ||
| 475 : | } | ||
| 476 : | break; | ||
| 477 : | } | ||
| 478 : | } | ||
| 479 : | /** | ||
| 480 : | * Loads an admin module | ||
| 481 : | */ | ||
| 482 : | function mosLoadAdminModule( $name, $params=NULL ) { | ||
| 483 : | global $mosConfig_absolute_path, $mosConfig_live_site; | ||
| 484 : | global $database, $my, $mainframe, $option, $acl; | ||
| 485 : | |||
| 486 : | $task = mosGetParam( $_REQUEST, 'task', '' ); | ||
| 487 : | // legacy support for $act | ||
| 488 : | $act = mosGetParam( $_REQUEST, 'act', '' ); | ||
| 489 : | |||
| 490 : | $name = str_replace( '/', '', $name ); | ||
| 491 : | $name = str_replace( '\\', '', $name ); | ||
| 492 : | $path = "$mosConfig_absolute_path/administrator/modules/mod_$name.php"; | ||
| 493 : | if (file_exists( $path )) { | ||
| 494 : | require $path; | ||
| 495 : | } | ||
| 496 : | } | ||
| 497 : | |||
| 498 : | function mosLoadCustomModule( &$module, &$params ) { | ||
| 499 : | global $mosConfig_absolute_path; | ||
| 500 : | |||
| 501 : | $rssurl = $params->get( 'rssurl', '' ); | ||
| 502 : | $rssitems = $params->get( 'rssitems', '' ); | ||
| 503 : | $rssdesc = $params->get( 'rssdesc', '' ); | ||
| 504 : | $moduleclass_sfx = $params->get( 'moduleclass_sfx', '' ); | ||
| 505 : | |||
| 506 : | echo '<table cellpadding="0" cellspacing="0" class="moduletable' . $moduleclass_sfx . '">'; | ||
| 507 : | |||
| 508 : | if ($module->content) { | ||
| 509 : | echo '<tr>'; | ||
| 510 : | echo '<td>' . $module->content . '</td>'; | ||
| 511 : | echo '</tr>'; | ||
| 512 : | } | ||
| 513 : | |||
| 514 : | // feed output | ||
| 515 : | if ( $rssurl ) { | ||
| 516 : | $cacheDir = $mosConfig_absolute_path .'/cache/'; | ||
| 517 : | if (!is_writable( $cacheDir )) { | ||
| 518 : | echo '<tr>'; | ||
| 519 : | echo '<td>Please make cache directory writable.</td>'; | ||
| 520 : | echo '</tr>'; | ||
| 521 : | } else { | ||
| 522 : | $LitePath = $mosConfig_absolute_path .'/includes/Cache/Lite.php'; | ||
| 523 : | require_once( $mosConfig_absolute_path .'/includes/domit/xml_domit_rss_lite.php'); | ||
| 524 : | $rssDoc =& new xml_domit_rss_document_lite(); | ||
| 525 : | $rssDoc->useCacheLite(true, $LitePath, $cacheDir, 3600); | ||
| 526 : | $rssDoc->loadRSS( $rssurl ); | ||
| 527 : | $totalChannels = $rssDoc->getChannelCount(); | ||
| 528 : | |||
| 529 : | for ($i = 0; $i < $totalChannels; $i++) { | ||
| 530 : | $currChannel =& $rssDoc->getChannel($i); | ||
| 531 : | echo '<tr>'; | ||
| 532 : | echo '<td><strong><a href="'. $currChannel->getLink() .'" target="_child">'; | ||
| 533 : | echo $currChannel->getTitle() .'</a></strong></td>'; | ||
| 534 : | echo '</tr>'; | ||
| 535 : | if ($rssdesc) { | ||
| 536 : | echo '<tr>'; | ||
| 537 : | echo '<td>'. $currChannel->getDescription() .'</td>'; | ||
| 538 : | echo '</tr>'; | ||
| 539 : | } | ||
| 540 : | |||
| 541 : | $actualItems = $currChannel->getItemCount(); | ||
| 542 : | $setItems = $rssitems; | ||
| 543 : | |||
| 544 : | if ($setItems > $actualItems) { | ||
| 545 : | $totalItems = $actualItems; | ||
| 546 : | } else { | ||
| 547 : | $totalItems = $setItems; | ||
| 548 : | } | ||
| 549 : | |||
| 550 : | for ($j = 0; $j < $totalItems; $j++) { | ||
| 551 : | $currItem =& $currChannel->getItem($j); | ||
| 552 : | |||
| 553 : | echo '<tr>'; | ||
| 554 : | echo '<td><strong><a href="'. $currItem->getLink() .'" target="_child">'; | ||
| 555 : | echo $currItem->getTitle() .'</a></strong> - '. $currItem->getDescription() .'</td>'; | ||
| 556 : | echo '</tr>'; | ||
| 557 : | } | ||
| 558 : | } | ||
| 559 : | } | ||
| 560 : | } | ||
| 561 : | echo '</table>'; | ||
| 562 : | } | ||
| 563 : | |||
| 564 : | function mosShowSource( $filename, $withLineNums=false ) { | ||
| 565 : | ini_set('highlight.html', '000000'); | ||
| 566 : | ini_set('highlight.default', '#800000'); | ||
| 567 : | ini_set('highlight.keyword','#0000ff'); | ||
| 568 : | ini_set('highlight.string', '#ff00ff'); | ||
| 569 : | ini_set('highlight.comment','#008000'); | ||
| 570 : | |||
| 571 : | if (!($source = @highlight_file( $filename, true ))) { | ||
| 572 : | return 'Operation Failed'; | ||
| 573 : | } | ||
| 574 : | $source = explode("<br />", $source); | ||
| 575 : | |||
| 576 : | $ln = 1; | ||
| 577 : | |||
| 578 : | $txt = ''; | ||
| 579 : | foreach( $source as $line ) { | ||
| 580 : | $txt .= "<code>"; | ||
| 581 : | if ($withLineNums) { | ||
| 582 : | $txt .= "<font color=\"#aaaaaa\">"; | ||
| 583 : | $txt .= str_replace( ' ', ' ', sprintf( "%4d:", $ln ) ); | ||
| 584 : | $txt .= "</font>"; | ||
| 585 : | } | ||
| 586 : | $txt .= "$line<br /><code>"; | ||
| 587 : | $ln++; | ||
| 588 : | } | ||
| 589 : | return $txt; | ||
| 590 : | } | ||
| 591 : | |||
| 592 : | function mosIsChmodable($file) | ||
| 593 : | { | ||
| 594 : | $perms = fileperms($file); | ||
| 595 : | if ($perms !== FALSE) | ||
| 596 : | if (@chmod($file, $perms ^ 0001)) { | ||
| 597 : | @chmod($file, $perms); | ||
| 598 : | return TRUE; | ||
| 599 : | } // if | ||
| 600 : | return FALSE; | ||
| 601 : | } // mosIsChmodable | ||
| 602 : | |||
| 603 : | /** | ||
| 604 : | * @param string An existing base path | ||
| 605 : | * @param string A path to create from the base path | ||
| 606 : | * @param int Directory permissions | ||
| 607 : | * @return boolean True if successful | ||
| 608 : | */ | ||
| 609 : | function mosMakePath($base, $path='', $mode = NULL) | ||
| 610 : | { | ||
| 611 : | global $mosConfig_dirperms; | ||
| 612 : | |||
| 613 : | // convert windows paths | ||
| 614 : | $path = str_replace( '\\', '/', $path ); | ||
| 615 : | $path = str_replace( '//', '/', $path ); | ||
| 616 : | |||
| 617 : | // check if dir exists | ||
| 618 : | if (file_exists( $base . $path )) return true; | ||
| 619 : | |||
| 620 : | // set mode | ||
| 621 : | $origmask = NULL; | ||
| 622 : | if (isset($mode)) { | ||
| 623 : | $origmask = @umask(0); | ||
| 624 : | } else { | ||
| 625 : | if ($mosConfig_dirperms=='') { | ||
| 626 : | // rely on umask | ||
| 627 : | $mode = 0777; | ||
| 628 : | } else { | ||
| 629 : | $origmask = @umask(0); | ||
| 630 : | $mode = octdec($mosConfig_dirperms); | ||
| 631 : | } // if | ||
| 632 : | } // if | ||
| 633 : | |||
| 634 : | $parts = explode( '/', $path ); | ||
| 635 : | $n = count( $parts ); | ||
| 636 : | $ret = true; | ||
| 637 : | if ($n < 1) { | ||
| 638 : | $ret = @mkdir($base, $mode); | ||
| 639 : | } else { | ||
| 640 : | $path = $base; | ||
| 641 : | for ($i = 0; $i < $n; $i++) { | ||
| 642 : | $path .= $parts[$i] . '/'; | ||
| 643 : | if (!file_exists( $path )) { | ||
| 644 : | if (!@mkdir( $path, $mode )) { | ||
| 645 : | $ret = false; | ||
| 646 : | break; | ||
| 647 : | } | ||
| 648 : | } | ||
| 649 : | } | ||
| 650 : | } | ||
| 651 : | if (isset($origmask)) @umask($origmask); | ||
| 652 : | return $ret; | ||
| 653 : | } | ||
| 654 : | |||
| 655 : | function &checkAdminSession (&$database) { | ||
| 656 : | // restore some session variables | ||
| 657 : | $my = new mosUser( $database ); | ||
| 658 : | $my->id = mosGetParam( $_SESSION, 'session_user_id', '' ); | ||
| 659 : | $my->username = mosGetParam( $_SESSION, 'session_username', '' ); | ||
| 660 : | $my->usertype = mosGetParam( $_SESSION, 'session_usertype', '' ); | ||
| 661 : | $my->gid = mosGetParam( $_SESSION, 'session_gid', '' ); | ||
| 662 : | |||
| 663 : | $session_id = mosGetParam( $_SESSION, 'session_id', '' ); | ||
| 664 : | $logintime = mosGetParam( $_SESSION, 'session_logintime', '' ); | ||
| 665 : | |||
| 666 : | // check against db record of session | ||
| 667 : | if ($session_id == md5( $my->id.$my->username.$my->usertype.$logintime )) { | ||
| 668 : | $database->setQuery( "SELECT * FROM #__session" | ||
| 669 : | . "\nWHERE session_id='$session_id'" | ||
| 670 : | . " AND username = '" . $database->getEscaped( $my->username ) . "'" | ||
| 671 : | . " AND userid = " . intval( $my->id ) | ||
| 672 : | ); | ||
| 673 : | if (!$result = $database->query()) { | ||
| 674 : | echo $database->stderr(); | ||
| 675 : | } | ||
| 676 : | if ($database->getNumRows( $result ) <> 1) $my = null; | ||
| 677 : | } | ||
| 678 : | else $my = null; | ||
| 679 : | |||
| 680 : | if ($my) { | ||
| 681 : | // update session timestamp | ||
| 682 : | $current_time = time(); | ||
| 683 : | $database->setQuery("UPDATE #__session SET time='$current_time' WHERE session_id='$session_id'"); | ||
| 684 : | $database->query(); | ||
| 685 : | // timeout old sessions | ||
| 686 : | $past = time()-1800; | ||
| 687 : | $database->setQuery( "DELETE FROM #__session WHERE time < '$past'" ); | ||
| 688 : | $database->query(); | ||
| 689 : | } | ||
| 690 : | return $my; | ||
| 691 : | } | ||
| 692 : | |||
| 693 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

