You are here: Re: Need a simple database for name and email only « All PHP « IT news, forums, messages
Re: Need a simple database for name and email only

Posted by Steve on 03/24/07 21:45

this script is a general function script included by the header.inc.php
script.

======= functions.inc.php

<?
require_once 'relative.path.php';
require_once $relativePath . 'site.cfg.php';

function accountingDate($date)
{
$date = strtotime($date);
$newDate = mktime(0, 0, 0, date('m', $date), date('d', $date) - 1,
date('Y', $date));
if (date('Hi', $date) < '0630') { $date = $newDate; }
return strtotime(date('m/d/Y', $date));
}

function dateDiff($firstDate, $secondDate, $interval = 'd')
{
$diff = abs($firstDate - $secondDate);
switch ($interval)
{
case 'w': return floor($diff / 604800); break;
case 'd': return floor($diff / 86400); break;
case 'h': return floor($diff / 3600); break;
case 'n': return floor($diff / 60); break;
case 's': return $diff; break;
}
}

function formatBytes($bytes)
{
if (!is_numeric($bytes)){ $bytes = 0; }
if ($bytes < 0){ $bytes = 0; }
$format = array( 'B', 'KB', 'MB', 'GB', 'TB');
$values = array( 0, 1024, 1048576, 1073741824, 1099511627776);
$i = floor(log($bytes)/6.9314718055994530941723212145818);
if ($values[$i] == 0){ return '0 B'; }
return number_format(round($bytes / $values[$i])) . ' ' . $format[$i];
}

function getMultipleSegments($segment, $xml)
{
$pattern = "/<(" . $segment . ")>(.*?)<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[2] as $content)
{
$output[] = $content;
}
return $output;
}

function getMultipleSegmentNames($xml)
{
$output = array();
$pattern = "/<([^>]+)>.*?<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[1] as $content)
{
$output[] = $content;
}
return $output;
}

function getSegmentValue($xml, $emptyDefault = '')
{
$pattern = "/<([^>]+)>(.*?)<\/\\1>/si";
preg_match($pattern, $xml, $match);
$value = $match[2];
if ($value == ''){ $value = $emptyDefault; }
return htmlDecode($value);
}

function getSetting($db, $scope, $context, $label)
{
$sql = "
SELECT Value
FROM settings
WHERE LOWER(Scope) = LOWER('" .
$db->prepare($scope) . "')
AND LOWER(Context) = LOWER('" .
$db->prepare($context) . "')
AND LOWER(Label) = LOWER('" .
$db->prepare($label) . "')
";
unset($records);
$records = $db->execute($sql);
return $records[0]['VALUE'];
}

function getSingleSegment($segment, $xml)
{
$output = '';
$pattern = "/<(" . $segment . ")>(.*?)<\/\\1>/si";
preg_match_all($pattern, $xml, $matches);
foreach ($matches[0] as $content)
{
$output .= $content;
}
return $output;
}

function getSingleSegmentName($xml)
{
$output = '';
$pattern = "/<([^>]+)>.*?<\/\\1>/si";
preg_match($pattern, $xml, $match);
return $match[1];
}

function getXml($appId, $company, $client, $xml)
{
$params = array(
'appid' => $appId,
'company' => $company,
'records' => $xml
);
$client->call('sendData', $params);
return getSingleSegment("ROOT", htmlDecode($client->response));
}

function htmlDecode($string)
{
$translation = get_html_translation_table(HTML_ENTITIES);
$translation = array_flip($translation);
$string = strtr($string, $translation);
return $string;
}

function htmlEncode($string)
{
$translation = get_html_translation_table(HTML_ENTITIES);
$string = strtr($string, $translation);
return $string;
}

function isEmail($email)
{
if (!$email){ return false; }
$pattern =
"/^((\"[^\"]*?\")|([^\(\)\<\>\@\,\;\:\\\"\[\]\s\*\/]+))@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$/si";
return preg_match($pattern, $email);
}

function isSupportedImage($description)
{
$description = strtolower($description);
$supportedExtensions = array (
'bmp' ,
'gif' ,
'jpg' ,
'jpeg' ,
'png' ,
'tif' ,
'tiff'
);
foreach ($supportedExtensions as $extension)
{
if (substr($description, -1 * strlen($extension)) == $extension){ return
true; }
}
return false;
}

function isSupportedMedia($description)
{
$description = strtolower($description);
$supportedExtensions = array (
'aif' ,
'aifc' ,
'aiff' ,
'asf' ,
'au' ,
'avi' ,
'cda' ,
'dvr-ms' ,
'm1v' ,
'mid' ,
'midi' ,
'mpa' ,
'mpe' ,
'mpeg' ,
'mpg' ,
'mp2' ,
'mp3' ,
'rmi' ,
'snd' ,
'vob' ,
'wav' ,
'wm' ,
'wma' ,
'wmv'
);
foreach ($supportedExtensions as $extension)
{
if (substr($description, -1 * strlen($extension)) == $extension){ return
true; }
}
return false;
}

function permission($string)
{
$permission = array(
'USER' => array(
'READ' => false ,
'WRITE' => false
),
'GROUP' => array(
'READ' => false ,
'WRITE' => false
),
'OTHER' => array(
'READ' => false ,
'WRITE' => false
)
);
$string = str_pad($string, 8, '-');
$permission['USER']['READ'] = @substr($string, 0, 1) == 'r' ? true :
false;
$permission['USER']['WRITE'] = @substr($string, 1, 1) == 'w' ? true :
false;
$permission['GROUP']['READ'] = @substr($string, 3, 1) == 'r' ? true :
false;
$permission['GROUP']['WRITE'] = @substr($string, 4, 1) == 'w' ? true :
false;
$permission['OTHER']['READ'] = @substr($string, 6, 1) == 'r' ? true :
false;
$permission['OTHER']['WRITE'] = @substr($string, 7, 1) == 'w' ? true :
false;
return $permission;
}

function prepare($string)
{
htmlEncode($string);
$string = str_replace("'", "''", $string);
return $string;
}

function siteTracking($page, $user)
{
$ip = '';
if (!$ip = $_SERVER['HTTP_CLIENT_IP'])
{
if (!$ip = $_SERVER['HTTP_X_FORWARDED_FOR'])
{
if (!$ip = $_SERVER['REMOTE_ADDR']){ $ip = 'UNKNOWN'; }
}
}
$sql = "
INSERT INTO siteTracking
(
Page ,
IpAddress ,
UserName ,
Stamp
)
VALUES
(
'" . $page . "' ,
'" . $ip . "' ,
'" . $user . "' ,
'" . date('Y-m-d H:i:s') . "'
)
";
db::execute($sql);
}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация