ajgkqsldxvkqsldkqs
azelfkqsmkqsmlkdqsmld
azmlekdqmskdmlqskd
nkldsfkqsmldkqsmdmlskd
' . "\r\n";
ini_set("sendmail_from", "");
if(mail($to, $subject, $content, $headers))
{
return true;
}else{
return false;
}
}
function valPhone($phone){
$phone = str_replace(' ','',$phone);
if(strlen($phone)==10){
$first_char = substr($phone,0,1);
if(!($first_char=="0")){
return false;
}else if(!ctype_digit($phone)){
return false;
}else{
return true;
}
}else if(strlen($phone)==13){
$country_code = substr($phone,0,4);
$other_parts = explode("+233",$phone);
if(!($country_code=="+233")){
return false;
}else if(!ctype_digit($other_parts[1])){
return false;
}else if(!(strlen($other_parts[1])==9)){
return false;
}else{
return true;
}
}else if(strlen($phone)==14){
$country_code = substr($phone,0,5);
$other_parts = explode("00233",$phone);
if(!($country_code=="00233")){
return false;
}else if(!ctype_digit($other_parts[1])){
return false;
}else if(!(strlen($other_parts[1])==9)){
return false;
}else{
return true;
}
}else{
return false;
}
}
function db_phone_format($phone){
$phone = str_replace(' ','',$phone);
if(strlen($phone)==10){
$phone = "+233".substr($phone,1,10);
}else if(strlen($phone)==13){
$phone = $phone;
}else if(strlen($phone)==14){
$other_parts = explode("00233",$phone);
$phone = "+233".$other_parts[1];
}
return $phone;
}
function valFloat($value){
if(is_numeric($value)){
return true;
}else{
return false;
}
}
function valInt($value){
if(!ctype_digit($value)){
return false;
}else{
return true;
}
}
function encryptPassword($password)
{
return sha1(sha1(md5(md5($password))));
}
function controlpanel_timeout(){
return "3600000";
}
function username($fn,$ln){
return ucfirst(strtolower($fn))." ".ucfirst(strtolower($ln));
}
function plural($count){
if($count>1){
return "s";
}else{
return "";
}
}
function validatePassword($password)
{
/*/Password length must be greater than 10 for security reasons*/
if(strlen($password)<4)
{
return false;
}
else
{
return true;
}
}
function valusername($username){
/* Must be either numbers, letters or mixed and not less than 4 characters */
if(strlen($username)<4){
return false;
}else if(!ctype_alnum($username)){
return false;
}else if(strlen($username)>28){
return false;
}else{
return true;
}
/*
if ( !preg_match('/^[a-z0-9][a-z0-9_]{3,28}[a-z0-9]$/', $username) ){
return false;
}else{
return true;
}
*/
}
function validateDate($date)
{
/*/split the date to check if all are numbers */
$atoms = explode('-',$date);
$day = $atoms[2];
$month = $atoms[1];
$year = $atoms[0];
if((is_numeric($day))&&(is_numeric($month))&&(is_numeric($year)))
{
if (checkdate($month, $day, $year))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
function shortenwords($string,$length)
{
$truncated = (strlen($string) > $length) ? substr($string, 0, $length) . '...' : $string;
return $truncated;
}
function sanitize($text)
{
/*$text = htmlspecialchars($text, ENT_QUOTES);*/
$text = str_replace("\n\r","\n",$text);
$text = str_replace("\r\n","\n",$text);
$text = str_replace("\n","
",$text);
return $text;
}
function _make_url_clickable_cb($matches) {
$ret = '';
$url = $matches[2];
if ( empty($url) )
return $matches[0];
// removed trailing [.,;:] from URL
if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) {
$ret = substr($url, -1);
$url = substr($url, 0, strlen($url)-1);
}
return $matches[1] . "$url" . $ret;
}
function _make_web_ftp_clickable_cb($matches) {
$ret = '';
$dest = $matches[2];
$dest = 'http://' . $dest;
if ( empty($dest) )
return $matches[0];
// removed trailing [,;:] from URL
if ( in_array(substr($dest, -1), array('.', ',', ';', ':')) === true ) {
$ret = substr($dest, -1);
$dest = substr($dest, 0, strlen($dest)-1);
}
return $matches[1] . "$dest" . $ret;
}
function _make_email_clickable_cb($matches) {
$email = $matches[2] . '@' . $matches[3];
return $matches[1] . "$email";
}
function make_clickable($ret) {
$ret = ' ' . $ret;
// in testing, using arrays here was found to be faster
$ret = preg_replace_callback('#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret);
$ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret);
$ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
// this one is not in an array because we need it to run last, for cleanup of accidental links within links
$ret = preg_replace("#(]+?>|>))]+?>([^>]+?)#i", "$1$3", $ret);
$ret = trim($ret);
return $ret;
}
function unsanitize($text){
return strip_tags($text);
}
function optionSelected($comp,$value){
if($comp==$value){
return "selected";
}else{
return "";
}
}
function option_checked($comp,$value){
if($comp==$value){
return "checked";
}else{
return "";
}
}
function is_checked($comp,$value){
if($comp==$value){
return correct_mark();
}else{
return "";
}
}
function generateToken() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 20; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
function generateShortToken() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 10; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
function generateLongToken(){
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 40; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
function slugify($string){
/*$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
return $slug;*/
$slug = trim($string); /* trim the string */
$slug= preg_replace('/[^a-zA-Z0-9 -]/','',$slug ); /* only take alphanumerical characters, but keep the spaces and dashes too... */
$slug= str_replace(' ','-', $slug); /* replace spaces by dashes */
$slug= strtolower($slug); /* make it lowercase */
return $slug;
}
function url_slug($url){
$path = parse_url($url, PHP_URL_PATH);
$pathFragments = explode('/', $path);
$end = end($pathFragments);
return $end;
}
function get_url_slug(){
$url = $_SERVER['REQUEST_URI'];
$slug = url_slug($url);
return $slug;
}
function create_folder($name){
/* create the folder and return the name of the folder */
$folder_ok = 0;
$attempt = 0;
$folder = "";
while($folder_ok==0){
if($attempt==0){
$slug = slugify(trim($name));
}else{
$slug = slugify(trim($name))."-".$attempt;
}
$folder = strtolower($slug);
$path = dirname(__FILE__)."/{$folder}/";
if (!is_dir($path)) {
if(mkdir($path, 0777)){
$folder_ok = 1;
}
}
$attempt++;
}
return $folder;
}
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
/*throw new InvalidArgumentException("$dirPath must be a directory");*/
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
function page_not_found(){
return "
The requested page can not be found
"; } function correct_mark(){ return "✔"; } function wrong_mark(){ return "✖"; } function has_dupes($array) { $duplicate = 0; $container = array(); for($i=0;$i
Loc: Adjacent Teshie Krobor 1 Sch.
Tel: +233 20 6930 402
Website: kuulchatmedia.com