return true;
}
+/**
+ * util_check_url() - determines if given URL is valid.
+ *
+ * Currently, test is very basic, only the protocol is
+ * checked, allowed values are: http, https, ftp.
+ *
+ * @param string The URL
+ * @return boolean true if valid, false if not valid.
+ */
+function util_check_url($url) {
+ return (preg_match('/^(http|https|ftp):\/\//', $url) > 0);
+}
+
/**
* util_send_message() - Send email
* This function should be used in place of the PHP mail() function
global $sys_bcc_all_email_address,$sys_sendmail_path;
if (!$to) {
- $to='noreply@'.$GLOBALS['sys_default_domain'];
+ $to='noreply@'.forge_get_config('web_host');
}
if (!$from) {
- $from='noreply@'.$GLOBALS['sys_default_domain'];
+ $from='noreply@'.forge_get_config('web_host');
}
*/
function util_is_valid_filename ($file) {
//bad char test
- $invalidchars = eregi_replace("[-A-Z0-9+_\.]","",$file);
+ $invalidchars = eregi_replace("[-A-Z0-9+_\. ]","",$file);
if (!empty($invalidchars)) {
return false;
return false;
}
+ ob_start () ;
while (!feof($handle)) {
- $buffer = fread($handle, $chunksize);
- echo $buffer;
- ob_flush() ;
- flush () ;
- if ($returnBytes) {
- $byteCounter += strlen($buffer);
- }
+ $buffer = fread($handle, $chunksize);
+ echo $buffer;
+ ob_flush() ;
+ flush () ;
+ if ($returnBytes) {
+ $byteCounter += strlen($buffer);
+ }
}
+ ob_end_flush () ;
$status = fclose($handle);
if ($returnBytes && $status) {
return $byteCounter; // return num. bytes delivered like readfile() does.
return utf8_encode($find);
}
+/**
+ * Constructs the forge's URL prefix out of $GLOBALS['sys_urlprefix']
+ *
+ * @return string
+ */
function normalized_urlprefix () {
$prefix = $GLOBALS['sys_urlprefix'] ;
$prefix = ereg_replace ("^/", "", $prefix) ;
return $prefix ;
}
+/**
+ * Construct full URL from a relative path
+ *
+ * @param string $path
+ * @return string URL
+ */
function util_make_url ($path) {
if ($GLOBALS['sys_use_ssl'])
$url = "https://" ;
else
$url = "http://" ;
- $url .= $GLOBALS['sys_default_domain'] ;
+ $url .= forge_get_config('web_host') ;
$url .= util_make_uri ($path) ;
return $url ;
}
+/**
+ * Construct proper (relative) URI (prepending prefix)
+ *
+ * @param string $path
+ * @return string URI
+ */
function util_make_uri ($path) {
$path = ereg_replace ("^/", "", $path) ;
$uri = normalized_urlprefix () ;
}
}
+/**
+ * Create an HTML link to a user's profile page
+ *
+ * @param string $username
+ * @param int $user_id
+ * @param string $text
+ * @return string
+ */
function util_make_link_u ($username, $user_id,$text) {
return '<a href="' . util_make_url_u ($username, $user_id) . '">' . $text . '</a>' ;
}
+/**
+ * Create URL for user's profile page
+ *
+ * @param string $username
+ * @param int $user_id
+ * @return string URL
+ */
function util_make_url_u ($username, $user_id) {
if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
return util_make_url ("/developer/?user_id=$user_id");
}
}
+/**
+ * Create a HTML link to a project's page
+ * @param string $groupame
+ * @param int $group_id
+ * @param string $text
+ * @return string
+ */
function util_make_link_g ($groupame, $group_id,$text) {
return '<a href="' . util_make_url_g ($groupame, $group_id) . '">' . $text . '</a>' ;
}
+/**
+ * Create URL for a project's page
+ *
+ * @param string $groupame
+ * @param int $group_id
+ * @return string
+ */
function util_make_url_g ($groupame, $group_id) {
if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
return util_make_url ("/project/?group_id=$group_id");
return true;
}
+// array_replace_recursive only appeared in PHP 5.3.0
+if (!function_exists('array_replace_recursive')) {
+ function array_replace_recursive ($a1, $a2) {
+ $result = $a1 ;
+
+ if (!is_array ($a2)) {
+ return $a2 ;
+ }
+
+ foreach ($a2 as $k => $v) {
+ if (!is_array ($v) ||
+ !isset ($result[$k]) || !is_array ($result[$k])) {
+ $result[$k] = $v ;
+ }
+
+ $result[$k] = array_replace_recursive ($result[$k],
+ $v) ;
+ }
+
+ return $result ;
+ }
+}
+
// Local Variables:
// mode: php
// c-file-style: "bsd"