<?php
/**
================================================================================
LISENCE
================================================================================
This file is part of php4dvd.
php4dvd 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, either version 3 of the License, or
(at your option) any later version.
php4dvd 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 php4dvd. If not, see <http://www.gnu.org/licenses/>.
**/
/**
* Detect the php4dvd version.
*
* @param $file of the version
* @return the version number
*/
function getVersion($file) {
// No file, probably version 0.1
if(!file_exists($file))
return "0.1";
// Open file and read its version
$handle = fopen($file, "r");
$contents = @fread($handle, filesize($file)) or die("Can't read the contents of <tt>".$file."</tt>.");
fclose($handle);
$match = array();
preg_match("/define\('VERSION', '([0-9](\.[0-9])?)'/", $contents, $match);
if(count($match) != 3) {
echo "Version could not be found in <tt>".$file."</tt>.";
exit();
}
// Return full match of version
return $match[1];
}
/**
* Connect to server. Return if succesful
*
* @param $server,$user,$pass
* @return successful, boolean value
*/
function getConnection($server,$user,$pass) {
if (@mysql_connect($server,$user,$pass))
return true;
return false;
}
/**
* Check if db exists. Return if succesful
*
* @param $db
* @return successful, boolean value
*/
function getDb($db) {
if (@mysql_select_db($db))
return true;
return false;
}
/**
* Import config file, return true if successful
*
* @param $filename
* @return successful, boolean value
*/
function loadConfig() {
if (file_exists('../config/config.php')) {
return '../config/config.php';
} elseif (file_exists('../config.php')) {
return '../config.php';
}
return '';
}
?>