File: /var/www/vhosts/creativefellows.nl/test.creativefellows.nl/oudlondon.nl/includes/main.inc.php
<?php
session_start();
require_once 'config.ini.php';
require_once 'cassette.front.php';
# default functions
function e($escape){return mysql_real_escape_string($escape);}
function esc($escape){return mysql_real_escape_string($escape);}
function dp($post){return preg_replace("/-/"," ",$post);}
function vl($url){
$pattern = array("/ä/","/Ä/","/ö/","/Ö/","/ü/","/Ü/","/ß/");
$replace = array("ae","Ae","oe","Oe","ue","Ue","ss");
$valid_german = preg_replace($pattern,$replace,$url);
return preg_replace("/[-]+/","-",preg_replace("/[^0-9a-zA-Z-#\/]/",'-', trim($valid_german)));
//return preg_replace("/[-]+/","-",preg_replace("/[^0-9a-zA-Z-#\/]/",'-', trim($url)));
}
function reverse_vl($url){
$pattern = array("/ae/","/Ae/","/oe/","/Oe/","/ue/","/Ue/","/ss/");
$replace = array("ä","Ä","ö","Ö","ü","Ü","ß");
return $valid_german = preg_replace($pattern,$replace,$url);
// return preg_replace("/[-]+/","-",preg_replace("/[^0-9a-zA-Z-#\/]/",'-', trim($url)));
}
function vl2($url){return urlencode(preg_replace("/ /","-",$url));}
function vn($url){return preg_replace("/[^0-9a-zA-Z- ]/",'_', trim($url));}
function formatDate($string){return strftime('%d %b %Y',strtotime($string));}
function makeIntro($text,$length=null,$addParagraphtags=null,$sign=null){
$text = preg_replace('/<(h1|h2|h3|h4)[^>]*>([\s\S]*?)<\/(h1|h2|h3|h4)[^>]*>/', '', $text);
$sign = ($sign == null) ? " [..]" : $sign;
$textlen = strlen(strip_tags($text));
if($textlen < $length && $length!=null) $return = strip_tags($text);
else{
$cropAfter = ($length != null) ? $length : 115;
$intro = substr(strip_tags($text), 0, $cropAfter);
$ls = strrpos($intro, " ");
$return = substr($intro, 0, $ls).$sign;
}
$return = ($addParagraphtags == null) ? $return : "<p>".$return."</p>";
return $return;
}
function css($str){
return preg_replace("/ /","",strtolower($str));
}
function testImage($w=400,$h=250){
return '<img src="http://placehold.it/400x250/'.random_color().'/000000/">';
}
function random_color_part() {
return str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT);
}
function random_color() {
return random_color_part() . random_color_part() . random_color_part();
}
function is_odd($number) {
return $number & 1; // 0 = even, 1 = odd
}
function formatTime($string,$type){
switch($type){
case 'h':
$date = strftime('%e %B %Y',strtotime($string));
break;
}
// return date and time
return ucfirst($date);
}
function d($str){
echo "<pre>";
print_r($str);
echo "</pre>";
}
function login_check($login_table) {
// Check if all session variables are set
if (isset($_SESSION['user_id'], $_SESSION['username'], $_SESSION['login_string'])) {
$user_id = $_SESSION['user_id'];
$login_string = $_SESSION['login_string'];
$username = $_SESSION['username'];
// Get the user-agent string of the user.
$user_browser = $_SERVER['HTTP_USER_AGENT'];
$q = mysql_query("SELECT * FROM `$login_table` WHERE `unique_id` = '".e($user_id)."'")or die(mysql_error());
$r = mysql_fetch_array($q);
$login_check = hash('sha512', $r["wachtwoord"] . $user_browser);
if ($login_check == $login_string) {
// Logged In!!!!
return true;
}else{
// Not logged in
return false;
}
}else return false;
}
function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = SECURE;
// This stops JavaScript being able to access the session id.
$httponly = true;
// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === FALSE) {
exit();
}
// Gets current cookies params.
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$secure,
$httponly);
// Sets the session name to the one set above.
session_name($session_name);
session_start(); // Start the PHP session
session_regenerate_id(true); // regenerated the session, delete the old one.
}
function outputSafe($string){
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
}
?>