File: common.php

package info (click to toggle)
bamboo 1.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 580 kB
  • ctags: 1,338
  • sloc: php: 4,061; makefile: 44; sh: 36
file content (132 lines) | stat: -rw-r--r-- 3,091 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php

##
## common functions which all code needs access to.
##

##################################################################
## GLOBAL URL FUNCTIONS

function deurlize($name) {
	if (preg_match('#^index\.\w{2,3}$#',$name))
		$title = basename(dirname($name));
	else
		$title = basename($name);

	# remove query string, underscore with space,
	# dash with space, Erase tilde
	
	$title = preg_replace(
		array("/(\?.*)/", "/_/", "/--/", "/-/", "/~/"),
		array("",         " ",   "&ndash;",    " ",   ""),
		$title
	);
	$title = preg_replace("/&ndash;/", "-",$title);
	
	# remove leading or trailing space
	$title = trim($title);
	
	# Capitalize All Words 
	$title = ucwords($title);
	
	return $title;
}

function urlize($title) {
	$name = strtolower($title);
	$name = preg_replace(
		array('/&.{2,4};/','/-/','/\s+/','/[^a-z0-9-]/'),
		array('','--','-',''),
		$name
	);
	return $name;
}

function alink($path,$label,$tags='') {
	global $root;
	if ($path == '' || $path{0}=='?')
		return "<a href=\"" . preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']) . "$path\" $tags>$label</a>";
	elseif ($path{0} == '/')
		return "<a href=\"$root$path\" $tags>$label</a>";
	else
		return "<a href=\"$path\" $tags>$label</a>";
}

/**
 * magic quotes are stupid, and there is no easy way to turn them off.
 * (set_magic_quotes_runtime doesn't always work).
 **/

function &get($prop, $default='', $raw=false) {
	if (!isset($_REQUEST[$prop])) 
		return $default;
		
	$prop = $_REQUEST[$prop];
	if (!is_array($prop)) {
		if(get_magic_quotes_gpc() || ini_get('magic_quotes_gpc')) {
			$prop = stripslashes($prop);
		}
		if (!$raw)
			$prop = htmlspecialchars($prop,ENT_QUOTES);
	}
	else {
		if(get_magic_quotes_gpc()) {
			$prop = array_map("stripslashes", $prop);
		}
		if (!$raw)
			$prop = array_map("htmlspecialchars", $prop);
	}
	return $prop;
}

function &getraw($prop, $default='') {
	return get($prop, $default, true);
}

##################################################################
## GLOBAL ERROR FUNCTIONS

#error_reporting (E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);
function errors($errno='', $errstr='', $errfile='', $errline='') {
	static $_errors = array();
	
	if ($errno == '') {
		return join('',$_errors);
	}
	else {
		switch ($errno) {
			case E_USER_ERROR:
			case E_ERROR:
				$etype = 'ERROR'; break;
			case E_USER_WARNING:
			case E_WARNING:
				$etype = 'WARNING'; break;
			case E_USER_NOTICE:
			case E_NOTICE:
				#if ( ! (ini_get('error_reporting')&E_NOTICE) ) return;
				$etype = 'NOTICE'; break;
			case E_STRICT:
				#if ( ! (ini_get('error_reporting')&E_STRICT) ) return;
				$etype = 'STRICT'; break;

		}
		$_errors[] = "<p><b>$etype</b>: $errstr <br /><i>$errfile: $errline</i></p>";
	}
}
set_error_handler("errors");


/**
 * return a copy of $path which safe to pass to a shell command.
 **/
function safepath($path) {
	global $docroot;
	if (strpos($path,$docroot) != 0)
		die("path must be absolute and under site's docroot: $path");
	if (strpos($path,'..') !== false)
		die("path cannot have .. in it");
	return escapeshellarg($path);
}

return;
?>