Annotation of /mambo/branches/4.6/administrator/includes/admin.php
Parent Directory
|
Revision Log
Revision 117 - (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 : | * @param string THe template position | ||
| 15 : | */ | ||
| 16 : | function mosCountAdminModules( $position='left' ) { | ||
| 17 : | global $database, $my, $Itemid; | ||
| 18 : | |||
| 19 : | $query = "SELECT COUNT(m.id)" | ||
| 20 : | . "\nFROM #__modules AS m" | ||
| 21 : | . "\nWHERE m.published='1' AND m.position='$position' AND m.client_id='1'"; | ||
| 22 : | |||
| 23 : | $database->setQuery( $query ); | ||
| 24 : | return $database->loadResult(); | ||
| 25 : | } | ||
| 26 : | /** | ||
| 27 : | * Loads admin modules via module position | ||
| 28 : | * @param string The position | ||
| 29 : | * @param int 0 = no style, 1 = tabbed | ||
| 30 : | */ | ||
| 31 : | function mosLoadAdminModules( $position='left', $style=0 ) { | ||
| 32 : | global $database, $my, $acl; | ||
| 33 : | |||
| 34 : | $cache =& mosCache::getCache( 'com_content' ); | ||
| 35 : | |||
| 36 : | $query = "SELECT id, title, module, position, content, showtitle, params" | ||
| 37 : | . "\n FROM #__modules AS m" | ||
| 38 : | . "\n WHERE m.published = '1'" | ||
| 39 : | . "\n AND m.position='$position'" | ||
| 40 : | . "\n AND (m.client_id = 1)" | ||
| 41 : | . "\n ORDER BY m.ordering"; | ||
| 42 : | |||
| 43 : | $database->setQuery( $query ); | ||
| 44 : | $modules = $database->loadObjectList(); | ||
| 45 : | if($database->getErrorNum()) { | ||
| 46 : | echo "MA ".$database->stderr(true); | ||
| 47 : | return; | ||
| 48 : | } | ||
| 49 : | if (!$modules) $modules = array(); | ||
| 50 : | |||
| 51 : | switch ($style) { | ||
| 52 : | case 0: | ||
| 53 : | default: | ||
| 54 : | foreach ($modules as $module) { | ||
| 55 : | $params =& new mosParameters( $module->params ); | ||
| 56 : | if ( $module->module == '' ) { | ||
| 57 : | mosLoadCustomModule( $module, $params ); | ||
| 58 : | } else { | ||
| 59 : | mosLoadAdminModule( substr( $module->module, 4 ), $params ); | ||
| 60 : | } | ||
| 61 : | } | ||
| 62 : | break; | ||
| 63 : | |||
| 64 : | case 1: | ||
| 65 : | // Tabs | ||
| 66 : | $tabs = new mosTabs(1); | ||
| 67 : | $tabs->startPane( 'modules-' . $position ); | ||
| 68 : | foreach ($modules as $module) { | ||
| 69 : | $params =& new mosParameters( $module->params ); | ||
| 70 : | $editAllComponents = $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ); | ||
| 71 : | // $authoriser = new mosAuthoriser($database); | ||
| 72 : | // $editAllComponents = $authoriser->checkPermission('mosUser', $my->id, 'edit', 'editAllComponents', 0); | ||
| 73 : | // special handling for components module | ||
| 74 : | if ( $module->module != 'mod_components' || ( $module->module == 'mod_components' && $editAllComponents ) ) { | ||
| 75 : | $tabs->startTab( $module->title, 'module' . $module->id ); | ||
| 76 : | if ( $module->module == '' ) { | ||
| 77 : | mosLoadCustomModule( $module, $params ); | ||
| 78 : | } else { | ||
| 79 : | mosLoadAdminModule( substr( $module->module, 4 ), $params ); | ||
| 80 : | } | ||
| 81 : | $tabs->endTab(); | ||
| 82 : | } | ||
| 83 : | } | ||
| 84 : | $tabs->endPane(); | ||
| 85 : | break; | ||
| 86 : | |||
| 87 : | case 2: | ||
| 88 : | // Div'd | ||
| 89 : | foreach ($modules as $module) { | ||
| 90 : | $params =& new mosParameters( $module->params ); | ||
| 91 : | echo '<div>'; | ||
| 92 : | if ( $module->module == '' ) { | ||
| 93 : | mosLoadCustomModule( $module, $params ); | ||
| 94 : | } else { | ||
| 95 : | mosLoadAdminModule( substr( $module->module, 4 ), $params ); | ||
| 96 : | } | ||
| 97 : | echo '</div>'; | ||
| 98 : | } | ||
| 99 : | break; | ||
| 100 : | } | ||
| 101 : | } | ||
| 102 : | /** | ||
| 103 : | * Loads an admin module | ||
| 104 : | */ | ||
| 105 : | function mosLoadAdminModule( $name, $params=NULL ) { | ||
| 106 : | global $mosConfig_absolute_path, $mosConfig_live_site; | ||
| 107 : | global $database, $my, $mainframe, $option, $acl; | ||
| 108 : | |||
| 109 : | $task = mosGetParam( $_REQUEST, 'task', '' ); | ||
| 110 : | // legacy support for $act | ||
| 111 : | $act = mosGetParam( $_REQUEST, 'act', '' ); | ||
| 112 : | |||
| 113 : | $name = str_replace( '/', '', $name ); | ||
| 114 : | $name = str_replace( '\\', '', $name ); | ||
| 115 : | $path = "$mosConfig_absolute_path/administrator/modules/mod_$name.php"; | ||
| 116 : | if (file_exists( $path )) { | ||
| 117 : | require $path; | ||
| 118 : | } | ||
| 119 : | } | ||
| 120 : | |||
| 121 : | function mosLoadCustomModule( &$module, &$params ) { | ||
| 122 : | global $mosConfig_absolute_path; | ||
| 123 : | |||
| 124 : | $rssurl = $params->get( 'rssurl', '' ); | ||
| 125 : | $rssitems = $params->get( 'rssitems', '' ); | ||
| 126 : | $rssdesc = $params->get( 'rssdesc', '' ); | ||
| 127 : | $moduleclass_sfx = $params->get( 'moduleclass_sfx', '' ); | ||
| 128 : | |||
| 129 : | echo '<table cellpadding="0" cellspacing="0" class="moduletable' . $moduleclass_sfx . '">'; | ||
| 130 : | |||
| 131 : | if ($module->content) { | ||
| 132 : | echo '<tr>'; | ||
| 133 : | echo '<td>' . $module->content . '</td>'; | ||
| 134 : | echo '</tr>'; | ||
| 135 : | } | ||
| 136 : | |||
| 137 : | // feed output | ||
| 138 : | if ( $rssurl ) { | ||
| 139 : | $cacheDir = $mosConfig_absolute_path .'/cache/'; | ||
| 140 : | if (!is_writable( $cacheDir )) { | ||
| 141 : | echo '<tr>'; | ||
| 142 : | echo '<td>Please make cache directory writable.</td>'; | ||
| 143 : | echo '</tr>'; | ||
| 144 : | } else { | ||
| 145 : | $LitePath = $mosConfig_absolute_path .'/includes/Cache/Lite.php'; | ||
| 146 : | require_once( $mosConfig_absolute_path .'/includes/domit/xml_domit_rss_lite.php'); | ||
| 147 : | $rssDoc =& new xml_domit_rss_document_lite(); | ||
| 148 : | $rssDoc->useCacheLite(true, $LitePath, $cacheDir, 3600); | ||
| 149 : | $rssDoc->loadRSS( $rssurl ); | ||
| 150 : | $totalChannels = $rssDoc->getChannelCount(); | ||
| 151 : | |||
| 152 : | for ($i = 0; $i < $totalChannels; $i++) { | ||
| 153 : | $currChannel =& $rssDoc->getChannel($i); | ||
| 154 : | echo '<tr>'; | ||
| 155 : | echo '<td><strong><a href="'. $currChannel->getLink() .'" target="_child">'; | ||
| 156 : | echo $currChannel->getTitle() .'</a></strong></td>'; | ||
| 157 : | echo '</tr>'; | ||
| 158 : | if ($rssdesc) { | ||
| 159 : | echo '<tr>'; | ||
| 160 : | echo '<td>'. $currChannel->getDescription() .'</td>'; | ||
| 161 : | echo '</tr>'; | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | $actualItems = $currChannel->getItemCount(); | ||
| 165 : | $setItems = $rssitems; | ||
| 166 : | |||
| 167 : | if ($setItems > $actualItems) { | ||
| 168 : | $totalItems = $actualItems; | ||
| 169 : | } else { | ||
| 170 : | $totalItems = $setItems; | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | for ($j = 0; $j < $totalItems; $j++) { | ||
| 174 : | $currItem =& $currChannel->getItem($j); | ||
| 175 : | |||
| 176 : | echo '<tr>'; | ||
| 177 : | echo '<td><strong><a href="'. $currItem->getLink() .'" target="_child">'; | ||
| 178 : | echo $currItem->getTitle() .'</a></strong> - '. $currItem->getDescription() .'</td>'; | ||
| 179 : | echo '</tr>'; | ||
| 180 : | } | ||
| 181 : | } | ||
| 182 : | } | ||
| 183 : | } | ||
| 184 : | echo '</table>'; | ||
| 185 : | } | ||
| 186 : | |||
| 187 : | function mosShowSource( $filename, $withLineNums=false ) { | ||
| 188 : | ini_set('highlight.html', '000000'); | ||
| 189 : | ini_set('highlight.default', '#800000'); | ||
| 190 : | ini_set('highlight.keyword','#0000ff'); | ||
| 191 : | ini_set('highlight.string', '#ff00ff'); | ||
| 192 : | ini_set('highlight.comment','#008000'); | ||
| 193 : | |||
| 194 : | if (!($source = @highlight_file( $filename, true ))) { | ||
| 195 : | return 'Operation Failed'; | ||
| 196 : | } | ||
| 197 : | $source = explode("<br />", $source); | ||
| 198 : | |||
| 199 : | $ln = 1; | ||
| 200 : | |||
| 201 : | $txt = ''; | ||
| 202 : | foreach( $source as $line ) { | ||
| 203 : | $txt .= "<code>"; | ||
| 204 : | if ($withLineNums) { | ||
| 205 : | $txt .= "<font color=\"#aaaaaa\">"; | ||
| 206 : | $txt .= str_replace( ' ', ' ', sprintf( "%4d:", $ln ) ); | ||
| 207 : | $txt .= "</font>"; | ||
| 208 : | } | ||
| 209 : | $txt .= "$line<br /><code>"; | ||
| 210 : | $ln++; | ||
| 211 : | } | ||
| 212 : | return $txt; | ||
| 213 : | } | ||
| 214 : | |||
| 215 : | function mosIsChmodable($file) | ||
| 216 : | { | ||
| 217 : | $perms = fileperms($file); | ||
| 218 : | if ($perms !== FALSE) | ||
| 219 : | if (@chmod($file, $perms ^ 0001)) { | ||
| 220 : | @chmod($file, $perms); | ||
| 221 : | return TRUE; | ||
| 222 : | } // if | ||
| 223 : | return FALSE; | ||
| 224 : | } // mosIsChmodable | ||
| 225 : | |||
| 226 : | /** | ||
| 227 : | * @param string An existing base path | ||
| 228 : | * @param string A path to create from the base path | ||
| 229 : | * @param int Directory permissions | ||
| 230 : | * @return boolean True if successful | ||
| 231 : | */ | ||
| 232 : | function mosMakePath($base, $path='', $mode = NULL) | ||
| 233 : | { | ||
| 234 : | global $mosConfig_dirperms; | ||
| 235 : | |||
| 236 : | // convert windows paths | ||
| 237 : | $path = str_replace( '\\', '/', $path ); | ||
| 238 : | $path = str_replace( '//', '/', $path ); | ||
| 239 : | |||
| 240 : | // check if dir exists | ||
| 241 : | if (file_exists( $base . $path )) return true; | ||
| 242 : | |||
| 243 : | // set mode | ||
| 244 : | $origmask = NULL; | ||
| 245 : | if (isset($mode)) { | ||
| 246 : | $origmask = @umask(0); | ||
| 247 : | } else { | ||
| 248 : | if ($mosConfig_dirperms=='') { | ||
| 249 : | // rely on umask | ||
| 250 : | $mode = 0777; | ||
| 251 : | } else { | ||
| 252 : | $origmask = @umask(0); | ||
| 253 : | $mode = octdec($mosConfig_dirperms); | ||
| 254 : | } // if | ||
| 255 : | } // if | ||
| 256 : | |||
| 257 : | $parts = explode( '/', $path ); | ||
| 258 : | $n = count( $parts ); | ||
| 259 : | $ret = true; | ||
| 260 : | if ($n < 1) { | ||
| 261 : | $ret = @mkdir($base, $mode); | ||
| 262 : | } else { | ||
| 263 : | $path = $base; | ||
| 264 : | for ($i = 0; $i < $n; $i++) { | ||
| 265 : | $path .= $parts[$i] . '/'; | ||
| 266 : | if (!file_exists( $path )) { | ||
| 267 : | if (!@mkdir( $path, $mode )) { | ||
| 268 : | $ret = false; | ||
| 269 : | break; | ||
| 270 : | } | ||
| 271 : | } | ||
| 272 : | } | ||
| 273 : | } | ||
| 274 : | if (isset($origmask)) @umask($origmask); | ||
| 275 : | return $ret; | ||
| 276 : | } | ||
| 277 : | |||
| 278 : | function &checkAdminSession (&$database) { | ||
| 279 : | // restore some session variables | ||
| 280 : | $my = new mosUser( $database ); | ||
| 281 : | $my->id = mosGetParam( $_SESSION, 'session_user_id', '' ); | ||
| 282 : | $my->username = mosGetParam( $_SESSION, 'session_username', '' ); | ||
| 283 : | $my->usertype = mosGetParam( $_SESSION, 'session_usertype', '' ); | ||
| 284 : | $my->gid = mosGetParam( $_SESSION, 'session_gid', '' ); | ||
| 285 : | |||
| 286 : | $session_id = mosGetParam( $_SESSION, 'session_id', '' ); | ||
| 287 : | $logintime = mosGetParam( $_SESSION, 'session_logintime', '' ); | ||
| 288 : | |||
| 289 : | // check against db record of session | ||
| 290 : | if ($session_id == md5( $my->id.$my->username.$my->usertype.$logintime )) { | ||
| 291 : | $database->setQuery( "SELECT * FROM #__session" | ||
| 292 : | . "\nWHERE session_id='$session_id'" | ||
| 293 : | . " AND username = '" . $database->getEscaped( $my->username ) . "'" | ||
| 294 : | . " AND userid = " . intval( $my->id ) | ||
| 295 : | ); | ||
| 296 : | if (!$result = $database->query()) { | ||
| 297 : | echo $database->stderr(); | ||
| 298 : | } | ||
| 299 : | if ($database->getNumRows( $result ) <> 1) $my = null; | ||
| 300 : | } | ||
| 301 : | else $my = null; | ||
| 302 : | |||
| 303 : | if ($my) { | ||
| 304 : | // update session timestamp | ||
| 305 : | $current_time = time(); | ||
| 306 : | $database->setQuery("UPDATE #__session SET time='$current_time' WHERE session_id='$session_id'"); | ||
| 307 : | $database->query(); | ||
| 308 : | // timeout old sessions | ||
| 309 : | $past = time()-1800; | ||
| 310 : | $database->setQuery( "DELETE FROM #__session WHERE time < '$past'" ); | ||
| 311 : | $database->query(); | ||
| 312 : | } | ||
| 313 : | return $my; | ||
| 314 : | } | ||
| 315 : | |||
| 316 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

