Location: PHPKode > projects > Exero CMS > upload/functions/functions.php
<?
/*========================================*\
| Exero CMS                                |
|==========================================|
|          http://ecms.getox.net           |
|https://sourceforge.net/projects/exerocms/|
|==========================================|
|     Exero CMS is released under the      |
|     GNU General Public License (GPL)     |
| opensource.org/licenses/gpl-license.php  |
\*========================================*/

/* Mod_Rewrite */
function modrewriteurl() {
	$uri = explode("?",$_SERVER['REQUEST_URI']);
	$uri = str_replace('/',',',$uri['0']);
	$uri = str_replace(",?".$_SERVER['QUERY_STRING'],',',$uri);
	$querystring = str_replace("index.php",'',$_SERVER['PHP_SELF']);
	$querystring = str_replace($querystring,'',$uri);
	$querystring = explode(",",$querystring);
	$rootdir = str_replace(array('index.php','/'),'',$_SERVER['PHP_SELF']);
	$array = array();
	$a = 0;
	foreach($querystring as $query) {
		if(!$query == "") {
			if($a == 0) {
				if($query != $rootdir) {
					$array['module'] = $query;
				} else {
				 $a--;
				}
			} else {
				$array['q'.$a] = $query;
			}
			$a++;
		}
	}
	return $array;
}
/* Compile the url */
function compileurl($module,$array,$echo='1') {
global $ecms;
	if(!$array == '') {
		$querys = implode(",",$array);
		$querys = explode(',',$querys);
	}
	$q = 1;
	$rootdir = str_replace(array('index.php','/'),'',$_SERVER['PHP_SELF']);

	if(!$ecms->settings['mod_rewrite']) {
		if(!$array == "") {
			foreach($querys as $thequery) {
				$query = $query."&q".$q."=".$thequery;
				$q++;
			}
		}
		if($module == "rooturl") {
			if($echo == "1") {
				echo $rootdir;
			} else {
				return $rootdir;
			}
		} else {
			if($echo == "1") {
				echo "index.php?module=$module".$query;
			} else {
				return "index.php?module=$module".$query;
			}
		}
	} else {
		if(!$array == "") {
			foreach($querys as $thequery) {
				$query = $query.$thequery."/";
				$q++;
			}
		}
		if($module == "rooturl") {
			if($echo == "1") {
				echo '/'.$rootdir;
			} else {
				return '/'.$rootdir;
			}
		} else if($module == "admincp") {
			if($echo == "1") {
				echo '/'.$rootdir.'admin';
			} else {
				return '/'.$rootdir.'admin';
			}		
		} else {
			if($echo == "1") {
				echo "/$rootdir/$module/".$query;
			} else {
				return "/$rootdir/$module/".$query;
			}
		}
	}

}

/* Get BG Class */
function get_bgclass()
{
	global $bgcounter;
	return ($bgcounter++ % 2) == 0 ? 'alt1' : 'alt2';
}

/* Get file extension */
function getfileextension($str) { 
	switch($str) {
		case "image/jpeg":
			return "jpg";
		break;
		case "image/png":
			return "png";
		break;
		case "image/gif":
			return "gif";
		break;
		case "image/bmp":
			return "bmp";
		break;
		default:
			return "Unknown";
		break;
	}
}
/* Other */
function iif($expression, $returntrue, $returnfalse = '')
{
	return ($expression ? $returntrue : $returnfalse);
}

/* Get Side Blocks */
function getsideblocks($side) {
global $ecms, $db, $theme, $user, $show;
	if($ecms->settings['siteactive']) {
		$moduleinfo = $db->query_first("SELECT * FROM ".TABLE_PREFIX."modules WHERE ident='".$ecms->thismodule."' LIMIT 1");
		$moduleinfo['blockshidden'] = explode(',',$moduleinfo['blockshidden']);
		$moduleinfo['blocksviewable'] = explode(',',$moduleinfo['blocksviewable']);
		
		$getsideblocks = $db->query("SELECT * FROM ".TABLE_PREFIX."blocks WHERE side='".$side."' AND active='1' ORDER BY displayorder ASC");
		while($sideblock = $db->fetch_array($getsideblocks)) {
			if($sideblock['status'] == 1 && !in_array($sideblock['id'],$moduleinfo['blockshidden'])) {
				$show['this'] = 1;
			}  else if($sideblock['status'] == 0 && in_array($sideblock['id'],$moduleinfo['blocksviewable'])) {
				$show['this'] = 1;
			} else if($sideblock['status'] == 0 or in_array($sideblock['id'],$moduleinfo['blockshidden'])) {
				$show['this'] = 0;
			}
			if($show['this']) {
				$groups = explode(',',$sideblock['groupaccess']);
				if(in_array($user->userinfo['groupid'],$groups)) {
					$itemcount[$side] = 0;
					if(!$sideblock['items'] == "") {
						$items = explode(',',$sideblock['items']);
						foreach($items as $item) {
							$itemcount[$side]++;
							$iteminfo[$itemcount[$side]] = $db->query_first("SELECT * FROM items WHERE id='".$item."' LIMIT 1");
							$iteminfo[$itemcount[$side]]['groupaccess'] = explode(',',$iteminfo[$itemcount[$side]]['groupaccess']);
							include("items/".$iteminfo[$itemcount[$side]]['itemfile'].".php");
						}
					}
					include("themes/$ecms->theme/sideblock.php");
				}
			}
		}
	}
}

/* Check if module is active */
function moduleactive($module) {
global $ecms, $db, $theme, $user, $show;
	$moduleinfo = $db->query_first("SELECT ident,active FROM modules WHERE ident='".$module."' LIMIT 1");
	return $moduleinfo['active'];
}
?>
Return current item: Exero CMS