bouffeatulm/inc/functions.php

144 lines
3.9 KiB
PHP
Raw Normal View History

2013-08-12 09:52:50 +02:00
<?php
function logout() {
setcookie('bouffeatulm_staySignedIn', FALSE, 0, WEB_PATH);
if(isset($_COOKIE['bouffeatulm_login']))
setcookie('bouffeatulm_login', $_COOKIE['bouffeatulm_login'], 0, WEB_PATH);
session_destroy();
}
2013-08-12 09:52:50 +02:00
function getNotice() {
if(!file_exists('data/notice')) {
file_put_contents('data/notice');
}
return file_get_contents('data/notice');
}
function setNotice($notice) {
return file_put_contents('data/notice', $notice);
}
2013-08-26 21:21:52 +02:00
function secureDisplay($unsecured) {
$return = NULL;
if(is_array($unsecured)) {
$return = array();
foreach($unsecured as $key=>$unsecured_item) {
$return[$key] = secureDisplay($unsecured_item);
}
}
elseif(is_object($unsecured)) {
$return = $unsecured->secureDisplay();
}
elseif(is_numeric($unsecured)) {
if(intval($unsecured) == floatval($unsecured))
$return = (int) $unsecured;
else
$return = (float) $unsecured;
}
elseif(is_bool($unsecured)) {
$return = (bool) $unsecured;
}
else {
$return = htmlspecialchars($unsecured);
}
return $return;
}
2013-08-30 20:07:52 +02:00
function ampm2int($date) {
if($date == 'am')
return 0;
else
return 1;
}
function int2ampm($hour) {
if($hour == 0)
return 6;
else
return 18;
}
2013-09-05 20:09:03 +02:00
function listTemplates($dir='tpl/') {
2013-09-05 20:09:03 +02:00
if(strrpos($dir, '/') !== strlen($dir) - 1) {
$dir .= '/';
}
$return = array();
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && $entry != 'json' && is_dir($dir.$entry)) {
2014-08-30 23:21:27 +02:00
$return[] = array('value'=>$entry.'/', 'option'=>$entry);
2013-09-05 20:09:03 +02:00
}
}
closedir($handle);
}
return $return;
}
function listLangs($dir='i18n/') {
if(strrpos($dir, '/') !== strlen($dir) - 1) {
$dir .= '/';
}
$return = array();
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && is_file($dir.$entry)) {
$trad = file($dir.$entry);
foreach ($trad as $line) {
if (strstr($line, '// Provided lang')) {
$lang = explode('=', $line);
$lang = trim($lang[1]);
$return[] = array('value'=>$entry, 'option'=>$lang);
break;
}
}
}
}
closedir($handle);
2013-09-05 20:09:03 +02:00
}
return $return;
}
2013-09-06 23:07:35 +02:00
function TwoDArrayToOneD($array, $key) {
$return = array();
foreach($array as $value) {
$return[] = $value[$key];
}
return $return;
}
// Sendmail function by Bronco
function sendmail($to, $subject = '[Bouffe@Ulm]', $msg, $from = null, $format = 'text/plain') {
$r = "\r\n";
$header = '';
$msg = wordwrap ($msg, 70, $r);
if ($format != 'text/plain') {
$msg = htmlspecialchars ($msg);
}
if (!empty ($from)) {
$header .= 'From: '.$from.$r;
}
$header =
'Content-Type: text/plain; charset="utf-8"'.$r.
'Content-Transfer-Encoding: 8bit'.$r.$header;
return mail ($to, $subject, $msg, $header);
}
// Function to sort an array by abs desc
function sort_array_abs($a, $b) {
if(abs($a) == abs($b))
return 0;
return (abs($a) < abs($b)) ? 1 : -1;
}