Annotation of /mambo/branches/4.6/administrator/includes/admin.php
Parent Directory
|
Revision Log
Revision 151 - (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 : | csouza | 149 | var $xmlfile = ''; |
| 19 : | csouza | 129 | var $opentags = array(); |
| 20 : | var $opencount; | ||
| 21 : | var $accept = array(); | ||
| 22 : | var $mosinstall = false; | ||
| 23 : | var $type; | ||
| 24 : | var $terminalError = false; | ||
| 25 : | var $errors = array(); | ||
| 26 : | csouza | 138 | var $mosParameter = null; |
| 27 : | var $name = ''; | ||
| 28 : | csouza | 129 | |
| 29 : | csouza | 138 | function mosBasicXML ($file, $mosParameter=null, $name='params') { |
| 30 : | csouza | 149 | //echo $file.'<br />'; |
| 31 : | $this->xmlfile = $file; | ||
| 32 : | $this->mosParameter = $mosParameter; | ||
| 33 : | csouza | 138 | $this->name = $name; |
| 34 : | csouza | 129 | $this->setTree(); |
| 35 : | $parser = xml_parser_create(); | ||
| 36 : | csouza | 149 | $startfunc = array (&$this, 'start_element'); |
| 37 : | $endfunc = array (&$this, 'end_element'); | ||
| 38 : | $charfunc = array (&$this, 'character_data'); | ||
| 39 : | xml_set_element_handler ($parser, $startfunc, $endfunc); | ||
| 40 : | xml_set_character_data_handler ($parser, $charfunc); | ||
| 41 : | csouza | 151 | if ($fp = fopen($file, 'rb')) { |
| 42 : | while ($data = fread($fp, 4096) AND !$this->terminalError) { | ||
| 43 : | $data = str_replace('&', ' ampersand ', $data); | ||
| 44 : | $ret = xml_parse($parser, $data, feof($fp)) or die (sprintf('XML ERROR: %s at line %d', | ||
| 45 : | xml_error_string(xml_get_error_code($parser)), | ||
| 46 : | xml_get_current_line_number($parser))); | ||
| 47 : | } | ||
| 48 : | csouza | 129 | } |
| 49 : | csouza | 151 | else die ("Unable to open XML file $file"); |
| 50 : | csouza | 129 | if (count($this->opentags) != 0) { |
| 51 : | $tags = implode (', ', $this->opentags); | ||
| 52 : | trigger_error ("XML error - unclosed tag(s) ($tags) at end of file"); | ||
| 53 : | } | ||
| 54 : | xml_parser_free($parser); | ||
| 55 : | if (count($this->errors)) var_dump ($this->errors); | ||
| 56 : | } | ||
| 57 : | csouza | 149 | |
| 58 : | csouza | 129 | function setTree () { |
| 59 : | $this->accept['MOSINSTALL'] = array ('NAME', 'CREATIONDATE', 'AUTHOR', 'COPYRIGHT', | ||
| 60 : | csouza | 149 | 'LICENSE', 'AUTHOREMAIL', 'AUTHORURL', 'VERSION', 'DESCRIPTION', 'FILES', 'MEDIA', |
| 61 : | csouza | 129 | 'PARAMS', 'INSTALL', 'UNINSTALL', 'INSTALLFILE', 'UNINSTALLFILE', 'ADMINISTRATION', |
| 62 : | csouza | 151 | 'IMAGES', 'CSS', 'GROUP'); |
| 63 : | csouza | 129 | $this->accept['PARAMS'] = array ('PARAM'); |
| 64 : | $this->accept['PARAM'] = array ('OPTION'); | ||
| 65 : | $this->accept['FILES'] = array ('FILENAME'); | ||
| 66 : | $this->accept['INSTALL'] = array ('QUERIES'); | ||
| 67 : | $this->accept['UNINSTALL'] = array ('QUERIES'); | ||
| 68 : | $this->accept['QUERIES'] = array ('QUERY'); | ||
| 69 : | csouza | 149 | $this->accept['ADMINISTRATION'] = array ('FILES', 'IMAGES', 'MENU', 'SUBMENU'); |
| 70 : | csouza | 129 | $this->accept['IMAGES'] = array ('FILENAME'); |
| 71 : | $this->accept['SUBMENU'] = array('MENU'); | ||
| 72 : | csouza | 149 | $this->accept['MEDIA'] = array('FILENAME'); |
| 73 : | csouza | 129 | $this->accept['CSS'] = array('FILENAME'); |
| 74 : | } | ||
| 75 : | |||
| 76 : | function start_element ($parser, $element_name, $element_attrs) { | ||
| 77 : | if ($this->terminalError) return; | ||
| 78 : | if ($this->mosinstall) { | ||
| 79 : | $container = $this->opentags[0]; | ||
| 80 : | if (!isset($this->accept[$container]) OR !is_array($this->accept[$container])) trigger_error ("XML error $container is not a valid containing element"); | ||
| 81 : | if (!in_array($element_name, $this->accept[$container])) trigger_error ("XML error $element_name not permitted within $container"); | ||
| 82 : | } | ||
| 83 : | if ($this->mosinstall OR $element_name == 'MOSINSTALL') { | ||
| 84 : | $this->opencount = array_unshift ($this->opentags, $element_name); | ||
| 85 : | $this->mosinstall = true; | ||
| 86 : | csouza | 149 | $method = 'element_'.$element_name; |
| 87 : | $specific = array (&$this, $method); | ||
| 88 : | if (is_callable($specific)) $this->$method($element_attrs); | ||
| 89 : | csouza | 129 | } |
| 90 : | else trigger_error ("XML expected MOSINSTALL but found $element_name"); | ||
| 91 : | // echo '<br />Start of '.$element_name; | ||
| 92 : | } | ||
| 93 : | |||
| 94 : | function end_element ($parser, $element_name) { | ||
| 95 : | if ($this->terminalError) return; | ||
| 96 : | csouza | 149 | if ($this->opentags[0] != $element_name) { |
| 97 : | csouza | 129 | trigger_error("XML last open tag was $check, but found end of $element_name"); |
| 98 : | csouza | 149 | return; |
| 99 : | csouza | 129 | } |
| 100 : | csouza | 138 | $method = 'end_element_'.$element_name; |
| 101 : | csouza | 149 | $specific = array (&$this, $method); |
| 102 : | csouza | 138 | if (is_callable($specific)) $this->$method(); |
| 103 : | csouza | 149 | array_shift ($this->opentags); |
| 104 : | $this->opencount--; | ||
| 105 : | csouza | 129 | // echo '<br />End of '.$element_name; |
| 106 : | } | ||
| 107 : | |||
| 108 : | function character_data ($parser, $data) { | ||
| 109 : | // Should be overridden by inheriting class | ||
| 110 : | $this->errors[] = 'XML handler error - no method provided to deal with character data'; | ||
| 111 : | $this->terminalError = true; | ||
| 112 : | } | ||
| 113 : | csouza | 149 | |
| 114 : | csouza | 129 | function element_mosinstall ($attrs) { |
| 115 : | if (isset($attrs['TYPE'])) $this->type = $attrs['TYPE']; | ||
| 116 : | else trigger_error ("XML error - mosinstall does not have type attribute"); | ||
| 117 : | } | ||
| 118 : | |||
| 119 : | function getType () { | ||
| 120 : | return $this->type; | ||
| 121 : | } | ||
| 122 : | |||
| 123 : | } | ||
| 124 : | |||
| 125 : | /** | ||
| 126 : | * Extend basic parser to extract the description for a type of install file | ||
| 127 : | **/ | ||
| 128 : | |||
| 129 : | class mosXMLDescription extends mosBasicXML { | ||
| 130 : | var $values = array(); | ||
| 131 : | |||
| 132 : | function character_data ($parser, $data) { | ||
| 133 : | if ($this->terminalError) return; | ||
| 134 : | csouza | 138 | $this->topLevelCharacterData($data); |
| 135 : | } | ||
| 136 : | csouza | 149 | |
| 137 : | csouza | 138 | function topLevelCharacterData ($data) { |
| 138 : | if ($data = trim($data)) { | ||
| 139 : | csouza | 129 | if (isset($this->opentags[1]) AND $this->opentags[1] == 'MOSINSTALL') $this->values[$this->opentags[0]] = $data; |
| 140 : | } | ||
| 141 : | } | ||
| 142 : | |||
| 143 : | function getDescription ($type) { | ||
| 144 : | if ($type == $this->type AND isset($this->values['DESCRIPTION'])) return $this->values['DESCRIPTION']; | ||
| 145 : | else return ''; | ||
| 146 : | } | ||
| 147 : | |||
| 148 : | function getName ($type) { | ||
| 149 : | if ($type == $this->type AND isset($this->values['NAME'])) return $this->values['NAME']; | ||
| 150 : | else return ''; | ||
| 151 : | } | ||
| 152 : | |||
| 153 : | function getGroup ($type) { | ||
| 154 : | if ($type == $this->type AND isset($this->values['GROUP'])) return $this->values['GROUP']; | ||
| 155 : | else return ''; | ||
| 156 : | } | ||
| 157 : | |||
| 158 : | function getCreationDate ($type) { | ||
| 159 : | if ($type == $this->type AND isset($this->values['CREATIONDATE'])) return $this->values['CREATIONDATE']; | ||
| 160 : | else return ''; | ||
| 161 : | } | ||
| 162 : | |||
| 163 : | function getAuthor ($type) { | ||
| 164 : | if ($type == $this->type AND isset($this->values['AUTHOR'])) return $this->values['AUTHOR']; | ||
| 165 : | else return ''; | ||
| 166 : | } | ||
| 167 : | |||
| 168 : | function getCopyright ($type) { | ||
| 169 : | if ($type == $this->type AND isset($this->values['COPYRIGHT'])) return $this->values['COPYRIGHT']; | ||
| 170 : | else return ''; | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | function getAuthorEmail ($type) { | ||
| 174 : | if ($type == $this->type AND isset($this->values['AUTHOREMAIL'])) return $this->values['AUTHOREMAIL']; | ||
| 175 : | else return ''; | ||
| 176 : | } | ||
| 177 : | |||
| 178 : | function getAuthorUrl ($type) { | ||
| 179 : | if ($type == $this->type AND isset($this->values['AUTHORURL'])) return $this->values['AUTHORURL']; | ||
| 180 : | else return ''; | ||
| 181 : | } | ||
| 182 : | |||
| 183 : | function getVersion ($type) { | ||
| 184 : | if ($type == $this->type AND isset($this->values['VERSION'])) return $this->values['VERSION']; | ||
| 185 : | else return ''; | ||
| 186 : | } | ||
| 187 : | |||
| 188 : | } | ||
| 189 : | |||
| 190 : | csouza | 138 | class mosXMLParams extends mosXMLDescription { |
| 191 : | var $options = array(); | ||
| 192 : | var $optvalue = ''; | ||
| 193 : | var $optdata = ''; | ||
| 194 : | var $paramattrs = array(); | ||
| 195 : | var $paramcount = 0; | ||
| 196 : | var $html = array(); | ||
| 197 : | |||
| 198 : | function element_params ($attrs) { | ||
| 199 : | $this->html[] = '<table class="paramlist">'; | ||
| 200 : | if (isset($attrs['NAME'])) { | ||
| 201 : | $pname = $attrs['NAME']; | ||
| 202 : | $this->html[] = "<tr><td colspan='3'>$pname</td></tr>"; | ||
| 203 : | } | ||
| 204 : | } | ||
| 205 : | |||
| 206 : | function element_param ($attrs) { | ||
| 207 : | $this->paramattrs = $attrs; | ||
| 208 : | } | ||
| 209 : | |||
| 210 : | function element_option ($attrs) { | ||
| 211 : | csouza | 151 | if (isset($attrs['VALUE'])) $this->optvalue = $attrs['VALUE']; |
| 212 : | csouza | 138 | } |
| 213 : | |||
| 214 : | function character_data ($parser, $data) { | ||
| 215 : | if ($this->terminalError) return; | ||
| 216 : | $this->topLevelCharacterData($data); | ||
| 217 : | if ($this->opentags[0] == 'OPTION') $this->optdata = $data; | ||
| 218 : | } | ||
| 219 : | |||
| 220 : | function end_element_option () { | ||
| 221 : | $this->options[] = mosHTML::makeOption($this->optvalue, $this->optdata); | ||
| 222 : | $this->optdata = ''; | ||
| 223 : | $this->optvalue = ''; | ||
| 224 : | } | ||
| 225 : | |||
| 226 : | function end_element_param () { | ||
| 227 : | $type = mosGetParam ($this->paramattrs, 'TYPE', ''); | ||
| 228 : | $name = mosGetParam ($this->paramattrs, 'NAME', ''); | ||
| 229 : | $label = mosGetParam ($this->paramattrs, 'LABEL', $name); | ||
| 230 : | $default = mosGetParam ($this->paramattrs, 'DEFAULT', ''); | ||
| 231 : | if ($description = mosGetParam ($this->paramattrs, 'DESCRIPTION', '')) $tooltip = mosToolTip($description, $name); | ||
| 232 : | else $tooltip = ''; | ||
| 233 : | csouza | 151 | if (is_object($this->mosParameter)) { |
| 234 : | $mp = $this->mosParameter; | ||
| 235 : | $value = $mp->get($name, $default); | ||
| 236 : | } | ||
| 237 : | csouza | 138 | else $value = $default; |
| 238 : | $this->html[] = '<tr>'; | ||
| 239 : | if ($label == '@spacer') $label = '<hr />'; | ||
| 240 : | elseif ($label) $label .= ':'; | ||
| 241 : | $this->html[] = '<td width="35%" align="right" valign="top">'.$label.'</td>'; | ||
| 242 : | $controlname = $this->name; | ||
| 243 : | switch ($type) { | ||
| 244 : | case 'text': | ||
| 245 : | $size = mosGetParam ($this->paramattrs, 'SIZE', 0); | ||
| 246 : | $controlstring = '<input type="text" name="'.$this->name.'['.$name.']" value="'.$value.'" class="text_area" size="'.$size.'" />'; | ||
| 247 : | break; | ||
| 248 : | case 'list': | ||
| 249 : | csouza | 151 | $controlstring = mosHTML::selectList($this->options, $controlname.'['.$name.']', 'class="inputbox"', 'value', 'text', $value); |
| 250 : | csouza | 138 | break; |
| 251 : | case 'radio': | ||
| 252 : | csouza | 151 | $controlstring = mosHTML::radioList($this->options, $controlname.'['.$name.']', '', $value); |
| 253 : | csouza | 138 | break; |
| 254 : | case 'imagelist': | ||
| 255 : | $directory = new mosDirectory (mamboCore::get('mosConfig_absolute_path').mosGetParam($this->paramattrs, 'DIRECTORY', '')); | ||
| 256 : | $files = $directory->listFiles ('\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$'); | ||
| 257 : | $options = array(); | ||
| 258 : | foreach ($files as $file) $options[] = mosHTML::makeOption($file, $file); | ||
| 259 : | if (!isset($this->paramattrs['HIDE_NONE'])) array_unshift($options, mosHTML::makeOption('-1', '- Do not use an image -' )); | ||
| 260 : | if (!isset($this->paramattrs['HIDE_DEFAULT'])) array_unshift($options, mosHTML::makeOption('', '- Use Default image -')); | ||
| 261 : | $controlstring = mosHTML::selectList ($options, "$controlname[$name]", 'class="inputbox"', 'value', 'text', $value); | ||
| 262 : | break; | ||
| 263 : | case 'textarea': | ||
| 264 : | $rows = mosGetParam ($this->paramattrs, 'ROWS', 0); | ||
| 265 : | $cols = mosGetParam ($this->paramattrs, 'COLS', 0); | ||
| 266 : | $value = str_replace ('<br /', "\n", $value); | ||
| 267 : | $controlstring = "<textarea name='params[$name]' cols='$cols' rows='$rows' class='text_area'>$value</textarea>"; | ||
| 268 : | break; | ||
| 269 : | case 'spacer': | ||
| 270 : | $controlstring = $value ? $value : '<hr />'; | ||
| 271 : | break; | ||
| 272 : | case 'mos_section': | ||
| 273 : | $controlstring = _form_mos_section($name, $value, $controlname); | ||
| 274 : | break; | ||
| 275 : | case 'mos_category': | ||
| 276 : | $controlstring = _form_mos_category($name, $value, $controlname); | ||
| 277 : | break; | ||
| 278 : | case 'mos_menu': | ||
| 279 : | default: | ||
| 280 : | $controlstring = _HANDLER.'='.$type; | ||
| 281 : | } | ||
| 282 : | // $this->html[] = "<td>$type</td>"; | ||
| 283 : | $this->html[] = "<td>$controlstring</td>"; | ||
| 284 : | $this->html[] = "<td width='10%' align='left' valign='top'>$tooltip</td>"; | ||
| 285 : | $this->html[] = '</tr>'; | ||
| 286 : | $this->options = array(); | ||
| 287 : | $this->paramattrs = array(); | ||
| 288 : | $this->paramcount++; | ||
| 289 : | } | ||
| 290 : | |||
| 291 : | function end_element_params () { | ||
| 292 : | $this->html[] = '</table>'; | ||
| 293 : | if ($this->paramcount == 0) $this->html[] = '<tr><td colspan="2"><i>'._NO_PARAMS.'</i></td></tr>'; | ||
| 294 : | $this->paramcount = 0; | ||
| 295 : | } | ||
| 296 : | /** | ||
| 297 : | * @param string The name of the form element | ||
| 298 : | * @param string The value of the element | ||
| 299 : | * @param object The xml element for the parameter | ||
| 300 : | * @param string The control name | ||
| 301 : | * @return string The html for the element | ||
| 302 : | */ | ||
| 303 : | function _form_mos_section( $name, $value, $control_name ) { | ||
| 304 : | $database = mamboDatabase::getInstance(); | ||
| 305 : | $query = "SELECT id AS value, title AS text" | ||
| 306 : | . "\n FROM #__sections" | ||
| 307 : | . "\n WHERE published='1' AND scope='content'" | ||
| 308 : | . "\n ORDER BY title" | ||
| 309 : | ; | ||
| 310 : | $database->setQuery( $query ); | ||
| 311 : | $options = $database->loadObjectList(); | ||
| 312 : | array_unshift($options, mosHTML::makeOption( '0', '- Select Content Section -' )); | ||
| 313 : | return mosHTML::selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value ); | ||
| 314 : | } | ||
| 315 : | /** | ||
| 316 : | * @param string The name of the form element | ||
| 317 : | * @param string The value of the element | ||
| 318 : | * @param object The xml element for the parameter | ||
| 319 : | * @param string The control name | ||
| 320 : | * @return string The html for the element | ||
| 321 : | */ | ||
| 322 : | function _form_mos_category( $name, $value, $control_name ) { | ||
| 323 : | $database = mamboDatabase::getInstance(); | ||
| 324 : | $query = "SELECT c.id AS value, CONCAT_WS( '/',s.title, c.title ) AS text" | ||
| 325 : | . "\n FROM #__categories AS c" | ||
| 326 : | . "\n LEFT JOIN #__sections AS s ON s.id=c.section" | ||
| 327 : | . "\n WHERE c.published='1' AND s.scope='content'" | ||
| 328 : | . "\n ORDER BY c.title" | ||
| 329 : | ; | ||
| 330 : | $database->setQuery( $query ); | ||
| 331 : | $options = $database->loadObjectList(); | ||
| 332 : | array_unshift($options, mosHTML::makeOption('0', '- Select Content Category -')); | ||
| 333 : | return mosHTML::selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value ); | ||
| 334 : | } | ||
| 335 : | /** | ||
| 336 : | * @param string The name of the form element | ||
| 337 : | * @param string The value of the element | ||
| 338 : | * @param object The xml element for the parameter | ||
| 339 : | * @param string The control name | ||
| 340 : | * @return string The html for the element | ||
| 341 : | */ | ||
| 342 : | // function _form_mos_menu( $name, $value, &$node, $control_name ) { | ||
| 343 : | // global $database; | ||
| 344 : | // | ||
| 345 : | // $menuTypes = $mainframe->menutypes(); | ||
| 346 : | // | ||
| 347 : | // foreach($menuTypes as $menutype ) { | ||
| 348 : | // $options[] = mosHTML::makeOption( $menutype, $menutype ); | ||
| 349 : | // } | ||
| 350 : | // array_unshift( $options, mosHTML::makeOption( '', '- Select Menu -' ) ); | ||
| 351 : | // | ||
| 352 : | // return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value ); | ||
| 353 : | // } | ||
| 354 : | } | ||
| 355 : | |||
| 356 : | csouza | 129 | /** |
| 357 : | csouza | 138 | * Parameters handler |
| 358 : | * @package Mambo | ||
| 359 : | */ | ||
| 360 : | class mosAdminParameters extends mosParameters { | ||
| 361 : | /** @var string Path to the xml setup file */ | ||
| 362 : | var $_path = null; | ||
| 363 : | /** @var string The type of setup file */ | ||
| 364 : | var $_type = null; | ||
| 365 : | /** @var object The xml params element */ | ||
| 366 : | var $_xmlElem = null; | ||
| 367 : | /** | ||
| 368 : | * Constructor | ||
| 369 : | * @param string The raw parms text | ||
| 370 : | * @param string Path to the xml setup file | ||
| 371 : | * @var string The type of setup file | ||
| 372 : | */ | ||
| 373 : | function mosAdminParameters( $text, $path='', $type='component' ) { | ||
| 374 : | $this->_params = $this->parse( $text ); | ||
| 375 : | $this->_raw = $text; | ||
| 376 : | $this->_path = $path; | ||
| 377 : | $this->_type = $type; | ||
| 378 : | } | ||
| 379 : | |||
| 380 : | /** | ||
| 381 : | * @param string The name of the control, or the default text area if a setup file is not found | ||
| 382 : | * @return string HTML | ||
| 383 : | */ | ||
| 384 : | function render( $name='params' ) { | ||
| 385 : | csouza | 151 | if (is_file($this->_path)) { |
| 386 : | $parser = new mosXMLParams ($this->_path, $this, $name); | ||
| 387 : | if (count($parser->html)) return implode("\n", $parser->html); | ||
| 388 : | csouza | 138 | } |
| 389 : | csouza | 151 | $raw = $this->_raw; |
| 390 : | return "<textarea name='$name' cols='40' rows='10' class='text_area'$raw</textarea>"; | ||
| 391 : | csouza | 138 | } |
| 392 : | |||
| 393 : | } | ||
| 394 : | /** | ||
| 395 : | mambo | 117 | * @param string THe template position |
| 396 : | */ | ||
| 397 : | function mosCountAdminModules( $position='left' ) { | ||
| 398 : | csouza | 149 | $handler = mosModuleHandler::getInstance(); |
| 399 : | return $handler->mosCountModules($position, true); | ||
| 400 : | mambo | 117 | } |
| 401 : | /** | ||
| 402 : | * Loads admin modules via module position | ||
| 403 : | * @param string The position | ||
| 404 : | * @param int 0 = no style, 1 = tabbed | ||
| 405 : | */ | ||
| 406 : | function mosLoadAdminModules( $position='left', $style=0 ) { | ||
| 407 : | csouza | 149 | $handler = mosModuleHandler::getInstance(); |
| 408 : | return $handler->mosLoadAdminModules($position, $style); | ||
| 409 : | mambo | 117 | } |
| 410 : | /** | ||
| 411 : | * Loads an admin module | ||
| 412 : | */ | ||
| 413 : | function mosLoadAdminModule( $name, $params=NULL ) { | ||
| 414 : | global $mosConfig_absolute_path, $mosConfig_live_site; | ||
| 415 : | csouza | 149 | global $database, $acl, $my, $mainframe, $option; |
| 416 : | global $task, $act; | ||
| 417 : | |||
| 418 : | mambo | 117 | $name = str_replace( '/', '', $name ); |
| 419 : | $name = str_replace( '\\', '', $name ); | ||
| 420 : | csouza | 149 | $path = mamboCore::get('mosConfig_absolute_path')."/administrator/modules/mod_$name.php"; |
| 421 : | if (file_exists($path)) require $path; | ||
| 422 : | mambo | 117 | } |
| 423 : | |||
| 424 : | function mosLoadCustomModule( &$module, &$params ) { | ||
| 425 : | csouza | 151 | die ("The function mosLoadCustomModule has had its code removed as it appears unused"); |
| 426 : | mambo | 117 | } |
| 427 : | |||
| 428 : | function mosShowSource( $filename, $withLineNums=false ) { | ||
| 429 : | ini_set('highlight.html', '000000'); | ||
| 430 : | ini_set('highlight.default', '#800000'); | ||
| 431 : | ini_set('highlight.keyword','#0000ff'); | ||
| 432 : | ini_set('highlight.string', '#ff00ff'); | ||
| 433 : | ini_set('highlight.comment','#008000'); | ||
| 434 : | |||
| 435 : | if (!($source = @highlight_file( $filename, true ))) { | ||
| 436 : | return 'Operation Failed'; | ||
| 437 : | } | ||
| 438 : | $source = explode("<br />", $source); | ||
| 439 : | |||
| 440 : | $ln = 1; | ||
| 441 : | |||
| 442 : | $txt = ''; | ||
| 443 : | foreach( $source as $line ) { | ||
| 444 : | $txt .= "<code>"; | ||
| 445 : | if ($withLineNums) { | ||
| 446 : | $txt .= "<font color=\"#aaaaaa\">"; | ||
| 447 : | $txt .= str_replace( ' ', ' ', sprintf( "%4d:", $ln ) ); | ||
| 448 : | $txt .= "</font>"; | ||
| 449 : | } | ||
| 450 : | $txt .= "$line<br /><code>"; | ||
| 451 : | $ln++; | ||
| 452 : | } | ||
| 453 : | return $txt; | ||
| 454 : | } | ||
| 455 : | |||
| 456 : | function mosIsChmodable($file) | ||
| 457 : | { | ||
| 458 : | $perms = fileperms($file); | ||
| 459 : | if ($perms !== FALSE) | ||
| 460 : | if (@chmod($file, $perms ^ 0001)) { | ||
| 461 : | @chmod($file, $perms); | ||
| 462 : | return TRUE; | ||
| 463 : | } // if | ||
| 464 : | return FALSE; | ||
| 465 : | } // mosIsChmodable | ||
| 466 : | |||
| 467 : | /** | ||
| 468 : | * @param string An existing base path | ||
| 469 : | * @param string A path to create from the base path | ||
| 470 : | * @param int Directory permissions | ||
| 471 : | * @return boolean True if successful | ||
| 472 : | */ | ||
| 473 : | function mosMakePath($base, $path='', $mode = NULL) | ||
| 474 : | { | ||
| 475 : | global $mosConfig_dirperms; | ||
| 476 : | |||
| 477 : | // convert windows paths | ||
| 478 : | $path = str_replace( '\\', '/', $path ); | ||
| 479 : | $path = str_replace( '//', '/', $path ); | ||
| 480 : | |||
| 481 : | // check if dir exists | ||
| 482 : | if (file_exists( $base . $path )) return true; | ||
| 483 : | |||
| 484 : | // set mode | ||
| 485 : | $origmask = NULL; | ||
| 486 : | if (isset($mode)) { | ||
| 487 : | $origmask = @umask(0); | ||
| 488 : | } else { | ||
| 489 : | if ($mosConfig_dirperms=='') { | ||
| 490 : | // rely on umask | ||
| 491 : | $mode = 0777; | ||
| 492 : | } else { | ||
| 493 : | $origmask = @umask(0); | ||
| 494 : | $mode = octdec($mosConfig_dirperms); | ||
| 495 : | } // if | ||
| 496 : | } // if | ||
| 497 : | |||
| 498 : | $parts = explode( '/', $path ); | ||
| 499 : | $n = count( $parts ); | ||
| 500 : | $ret = true; | ||
| 501 : | if ($n < 1) { | ||
| 502 : | $ret = @mkdir($base, $mode); | ||
| 503 : | } else { | ||
| 504 : | $path = $base; | ||
| 505 : | for ($i = 0; $i < $n; $i++) { | ||
| 506 : | $path .= $parts[$i] . '/'; | ||
| 507 : | if (!file_exists( $path )) { | ||
| 508 : | if (!@mkdir( $path, $mode )) { | ||
| 509 : | $ret = false; | ||
| 510 : | break; | ||
| 511 : | } | ||
| 512 : | } | ||
| 513 : | } | ||
| 514 : | } | ||
| 515 : | if (isset($origmask)) @umask($origmask); | ||
| 516 : | return $ret; | ||
| 517 : | } | ||
| 518 : | |||
| 519 : | function &checkAdminSession (&$database) { | ||
| 520 : | // restore some session variables | ||
| 521 : | $my = new mosUser( $database ); | ||
| 522 : | $my->id = mosGetParam( $_SESSION, 'session_user_id', '' ); | ||
| 523 : | $my->username = mosGetParam( $_SESSION, 'session_username', '' ); | ||
| 524 : | $my->usertype = mosGetParam( $_SESSION, 'session_usertype', '' ); | ||
| 525 : | $my->gid = mosGetParam( $_SESSION, 'session_gid', '' ); | ||
| 526 : | |||
| 527 : | $session_id = mosGetParam( $_SESSION, 'session_id', '' ); | ||
| 528 : | $logintime = mosGetParam( $_SESSION, 'session_logintime', '' ); | ||
| 529 : | |||
| 530 : | // check against db record of session | ||
| 531 : | if ($session_id == md5( $my->id.$my->username.$my->usertype.$logintime )) { | ||
| 532 : | $database->setQuery( "SELECT * FROM #__session" | ||
| 533 : | . "\nWHERE session_id='$session_id'" | ||
| 534 : | . " AND username = '" . $database->getEscaped( $my->username ) . "'" | ||
| 535 : | . " AND userid = " . intval( $my->id ) | ||
| 536 : | ); | ||
| 537 : | if (!$result = $database->query()) { | ||
| 538 : | echo $database->stderr(); | ||
| 539 : | } | ||
| 540 : | if ($database->getNumRows( $result ) <> 1) $my = null; | ||
| 541 : | } | ||
| 542 : | else $my = null; | ||
| 543 : | |||
| 544 : | if ($my) { | ||
| 545 : | // update session timestamp | ||
| 546 : | $current_time = time(); | ||
| 547 : | $database->setQuery("UPDATE #__session SET time='$current_time' WHERE session_id='$session_id'"); | ||
| 548 : | $database->query(); | ||
| 549 : | // timeout old sessions | ||
| 550 : | $past = time()-1800; | ||
| 551 : | $database->setQuery( "DELETE FROM #__session WHERE time < '$past'" ); | ||
| 552 : | $database->query(); | ||
| 553 : | } | ||
| 554 : | return $my; | ||
| 555 : | } | ||
| 556 : | |||
| 557 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

