<?php
/**
* iF.SVNAdmin
* Copyright (c) 2010 by Manuel Freiholz
* http://www.insanefactory.com/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.
*/
/**
* Scans the given array for emtpy values and removes them.
*
* @param $arr The array to be scanned.
* @return array The array with no more emtpy values.
*/
function if_array_remove_empty_values(&$arr)
{
$removeCount = 0;
$arrCount = count($arr);
for ($i=0; $i<$arrCount; $i++)
{
if (empty($arr[$i]))
{
unset($arr[$i]);
$removeCount++;
}
}
if ($removeCount > 0)
$arr = array_values($arr);
return $arr;
}
/**
* Checks whether the variable is set and not empty.
* @param(optional) reference to scalar, will be set to 'get' or 'post'
* @return bool
*/
function check_request_var( $varname, &$method = NULL )
{
if( isset($_POST[$varname]) && !empty($_POST[$varname]) )
{
$method = 'post';
return TRUE;
}
else if( isset($_GET[$varname]) && !empty($_GET[$varname]) )
{
$method = 'get';
return TRUE;
}
return FALSE;
}
function get_request_var( $varname )
{
$method = NULL;
if( check_request_var($varname,$method) )
{
switch($method)
{
case 'get': return $_GET[$varname];
case 'post': return $_POST[$varname];
}
}
return FALSE;
}
function remove_item_by_value( &$arr, $value, $preserve = false )
{
foreach( $arr as $key=>&$val )
{
if( $val == $value )
{
unset( $arr[$key] );
}
}
if( $preserve )
{
return array_values( $arr );
}
return $arr;
}
function if_array_remove_object_element(&$arr, $obj, $compare_property)
{
foreach ($arr as $key => &$val)
{
if (is_object($val))
{
if (property_exists($val, $compare_property))
{
if ($obj->$compare_property == $val->$compare_property)
{
unset($arr[$key]);
}
}
else
{
// The object doesn't have the compare_property.
// ..
}
}
else
{
// Element is no object.
continue;
}
}
}
function checkPHPVersion($minimumVersion)
{
$phpVersion = phpversion();
$phpVersionParts = explode(".", $phpVersion);
$minVersionParts = explode(".", $minimumVersion);
$minVersionPartsCount = count($minVersionParts);
$check = true;
if ($minVersionPartsCount >= 1)
if ($phpVersionParts[0] < $minVersionParts[0])
$check = false;
if ($minVersionPartsCount >= 2)
if ($phpVersionParts[1] < $minVersionParts[1])
$check = false;
if ($minVersionPartsCount >= 3)
if ($phpVersionParts[2] < $minVersionParts[2])
$check = false;
return $check;
}
function currentScriptFileName()
{
$parts = explode("/", $_SERVER["SCRIPT_NAME"]);
return $parts[count($parts)-1];
}
function tr($text, $args=null)
{
global $appTR;
return $appTR->tr($text, $args);
}
?>