📄 functions.php
字号:
global $db;
$ret = $db->getOne('select 1 from ! where countrycode = ? limit 1', array( ZIPCODES_TABLE, $cntry_code) );
if (isset($ret) && $ret > 0) return $ret;
return 0;
}
function mailSender ($hdr_from, $hdr_to, $email, $subject, $body, $attachment='') {
/*
This is a wrapper function for sending emails
$hdr_from - THe from address to be kept in the header
$hdr_to - The to name and address to be kept in the Header
$email - Email address to which the mail to be sent
$subject - Subject of the email
$body - The body of the email
$attachment - Mail Attachment
*/
/* Construct the header portion */
/* clear html injects Begin */
$hdr_from = stripslashes(clearPost($hdr_from));
$hdr_to = stripslashes(clearPost($hdr_to));
$email = clearPost($email);
$subject = clearPost($subject);
$body = clearPost($body);
/* Html inject removed */
include_once (PEAR_DIR.'Mail/mime.php');
$siteurl = HTTP_METHOD . $_SERVER['SERVER_NAME'] . DOC_ROOT;
global $bannerURL, $config, $t;
$crlf = chr(13);
$headers = array (
'From' => $hdr_from,
'Subject' => stripslashes($subject)
);
$mime = new Mail_mime($crlf);
/* modify the encoding in mine with what is given for chosen language */
$mime->_build_params['text_encoding'] = get_lang('mail_text_encoding');
$mime->_build_params['html_encoding'] = get_lang('mail_html_encoding');
$mime->_build_params['html_charset'] = get_lang('mail_html_charset');
$mime->_build_params['text_charset'] = get_lang('mail_text_charset');
$mime->_build_params['head_charset'] = get_lang('mail_head_charset');
if (strtolower(MAIL_FORMAT) == 'html') {
$body = str_replace('#email_hdr_left#', $t->fetch('email_hdr_left.tpl'), $body);
$t->assign('message',$body);
$body = $t->fetch('html_emails.tpl');
}
$body = str_replace('#AdminName#', $config['admin_name'], $body);
$siteurl = str_replace('cronjobs/','',HTTP_METHOD . $_SERVER['SERVER_NAME'] . DOC_ROOT) ;
$body = str_replace('#link#', $siteurl,$body);
$body = str_replace('#SiteUrl#', $siteurl,$body);
$body = str_replace('#SkinName#', $config['skin_name'],$body);
$body = str_replace('#siteName#', $config['site_name'], $body);
$body = str_replace('#SiteName#', $config['site_name'], $body);
$body = str_replace('#AdminEmail#', $config['admin_email'], $body);
if (MAIL_FORMAT == 'text') {
$body = str_replace('<br>',$crlf,$body);
$body = str_replace('<br />',$crlf,$body);
$body = str_replace('<br/>',$crlf,$body);
// replace site link with full URL
global $config;
$body = str_replace('#SiteUrlLogin#', $siteurl.'login.php',str_replace("#AdminEmail#",$config['admin_email'],get_lang('mail','hdr_text'))).$body;
/* $site_name = $config['site_name'];
$site_url = 'http://' . $_SERVER['SERVER_NAME'] . DOC_ROOT;
$site_link = '<a href="' . $site_url . '">' . $site_name . '</a>';
$body = str_replace( $site_link, $site_url, $body );
*/
// remove any final tags
$body = strip_tags( $body );
$mime->setTXTBody($body);
} else {
$body = str_replace("#SiteUrlLogin#",$siteurl.'login.php',str_replace("MAIL_HDR",str_replace("#AdminEmail#",$config['admin_email'],get_lang('mail','hdr_html')),$body));
/* Add banner advertisement if set in configuration settings */
if (($config['banner_in_emails'] == 'Y' || $config['banner_in_emails'] == '1') && $bannerURL != '') {
$body = $body.'<font style="font-size: 9px;"><br>Advertisement</font><br>'.str_replace('banclick.php',$siteurl.'banclick.php',$bannerURL);
}
$parserfile = INC_DIR.'internal/css_parser.php';
require_once($parserfile);
$cssparser = & new cssParser();
//$css is css stylesheet string
//$cssparser->ParseStr($css);
$cssfile = ROOT_DIR.'templates/'.$config['skin_name'].'/email.css';
$cssparser->parseFile($cssfile);
$htmlholder =& new htmlholder($body);
$htmlholder->replaceCSS($cssparser->codestr_holder);
$page = $htmlholder->out();
$page = str_replace('#SiteUrl#', $siteurl,$page);
$page = str_replace('#SkinName#', $config['skin_name'],$page);
$mime->setHTMLBody($page);
}
if (!is_array($attachment) ) {
$attach_files = explode(',',$attachment);
} else {
$attach_files = $attachment;
}
if (count($attach_files) > 0) {
foreach ($attach_files as $file) {
if ($file != '') {
$mime->addAttachment("../emailimages/".$file);
}
}
}
$body = $mime->get();
$hdrs = $mime->headers($headers);
$params = false;
if (MAIL_TYPE == 'smtp') {
$params['host'] = SMTP_HOST;
$params['port'] = SMTP_PORT;
$params['auth'] = (SMTP_AUTH=='1') ? true : false ;
$params['username'] = SMTP_USER;
$params['password'] = SMTP_PASS;
}
if ( trim( MAIL_TYPE ) == '' ) {
$mail_type = 'mail';
}
else {
$mail_type = MAIL_TYPE;
}
$mail_object =& Mail::factory( $mail_type, $params );
return($mail_object->send( $email, $hdrs, $body ) );
}
function process_payment_info($params) {
global $db;
// get the user information for this transaction
$trnrec=$db->getRow('select * from ! where id = ? ', array(TRANSACTIONS_TABLE, $params['pay_txn_id'] ));
$user_id = $trnrec['user_id'];
$user_level = $trnrec['to_membership'];
$levelvars = $db->getRow( 'select activedays, name from ! where roleid = ?', array( MEMBERSHIP_TABLE, $user_level ) );
$activedays = $levelvars['activedays'];
$level_name = $levelvars['name'];
if ( $params['valid'] && $trnrec['payment_status'] != 'Completed') {
$sql = 'update ! set payment_email = ?, amount_paid = ?, txn_id = ?, txn_date = ?, payment_vars = ?, payment_status=? where id = ?';
$db->query( $sql, array( TRANSACTIONS_TABLE, $params['email'], $params['amount'], $params['txn_id'], date('Y-m-d'), $params['vars'], $params['payment_status'], $params['pay_txn_id'] ) );
// determine when this user's membership was to expire, then extend it by $activedays days
if (trim($params['payment_status']) == 'Completed') {
$curlevel = $db->getRow( 'select levelend, level from ! where id = ?', array( USER_TABLE, $user_id ) );
$levelend = $curlevel['levelend'];
if ( $levelend < time() ) {
$levelend = time();
}
// new expiration date for this member
if ($curlevel['level'] != $user_level) {
$levelend = strtotime( "+$activedays day", time() );
} else {
$levelend = strtotime( "+$activedays day", $levelend );
}
$sql = 'UPDATE ! SET level = ?, levelend = ? WHERE id = ?';
$db->query( $sql, array( USER_TABLE, $user_level, $levelend, $user_id ) );
}
}
return $level_name;
}
function getTplFile ($resource_type, $resource_name, &$template_source, &$template_timestamp, &$smarty_obj)
{
global $skin_name;
if ( !is_readable ( $resource_name )) {
// create the template file, return contents.
$new_resource = str_replace('/templates/'.$skin_name.'/','/templates/default/',$smarty_obj->template_dir).$resource_name;
$template_timestamp = filemtime($new_resource);
$template_source = file_get_contents($new_resource);
return true;
}
}
## clear html injects Begin ##
function clearPost($post_val) // remove email headder injects
{
$injection_strings = array(
"'apparently-to' i",
"'bcc:' i",
"'cc:' i",
"'to:' i",
"'boundary=' i",
"'charset:' i",
"'content-disposition' i",
"'content-type' i",
"'content-transfer-encoding' i",
"'errors-to' i",
"'in-reply-to' i",
"'message-id' i",
"'mime-version' i",
"'multipart/mixed' i",
"'multipart/alternative' i",
"'multipart/related' i",
"'reply-to:' i",
"'x-mailer' i",
"'x-sender' i",
"'x-uidl' i"
);
$replace_strings = array(
"apparently_to",
"bcc_:",
"cc_:",
"to_:",
"boundary_=",
"charset_:",
"content_disposition",
"content_type",
"content_transfer_encoding",
"errors_to",
"in_reply_to",
"message_id",
"mime_version",
"multipart_mixed",
"multipart_alternative",
"multipart_related",
"reply_to:",
"x_mailer",
"x_sender",
"x_uidl"
);
$post_val = preg_replace($injection_strings, $replace_strings, $post_val);
return $post_val;
} //function clearPost
function DeleteCacheFiles($fromdir, $tm, $recursed = 1 ) {
if ($fromdir == "" or !is_dir($fromdir)) {
echo ('Invalid directory');
return false;
}
$filelist = array();
$dir = opendir($fromdir);
while($file = readdir($dir)) {
if($file == "." || $file == ".." || $file == 'readme.txt' || $file == 'index.html' || $file == 'index.htm' || $file == 'lasttime.dat' ) {
continue;
} elseif (is_dir($fromdir."/".$file)) {
if ($recursed == 1) {
$temp = DeleteCacheFiles($fromdir."/".$file, $recursed);
}
} elseif (file_exists($fromdir."/".$file) && filemtime($fromdir."/".$file) < $tm) {
unlink($fromdir."/".$file);
}
}
closedir($dir);
return true;
}
function deleteCache() {
global $config;
/* This function will delete cache files.. */
$tm = time() - $config['time_cache_expiry']*60;
$lasttime = 0;
if (is_readable(CACHE_DIR.'lasttime.dat')) {
$lt = file(CACHE_DIR.'lasttime.dat');
$lasttime = trim($lt[0]);
}
if ($lasttime < $tm) {
DeleteCacheFiles(CACHE_DIR,$tm);
$fp = @fopen(CACHE_DIR.'lasttime.dat','wb');
if ($fp) {
fwrite($fp, time());
fclose($fp);
}
}
}
function updateLoadedPicturesCnt($userid) {
/* This function will update teh User Table for the loaded picture count */
$picscnt = $GLOBALS['db']->getOne('select count(*) from ! where userid = ?',array(USER_SNAP_TABLE, $userid));
$GLOBALS['db']->query('update ! set pictures_cnt = ? where id = ?',array(USER_TABLE, $picscnt, $userid));
}
function updateLoadedVideosCnt($userid) {
/* This function will update teh User Table for the loaded picture count */
$vdscnt = $GLOBALS['db']->getOne('select count(*) from ! where userid = ?',array(USER_VIDEOS_TABLE, $userid));
$GLOBALS['db']->query('update ! set videos_cnt = ? where id = ?',array(USER_TABLE, $vdscnt, $userid));
}
function stripEmails( $instring )
{
/* Thanks to premiumMatch for providing this function code */
$replacementString = " = email Address Removed = ";
// normal email format
$instring = preg_replace( "/[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}/i", $replacementString, $instring );
// "at dot" format
$instring = preg_replace( "/[A-Z0-9._%-]+ at [A-Z0-9._%-]+ dot [A-Z]{2,6}/i", $replacementString, $instring );
return $instring;
}
function deleteUser($userId) {
/* Delete profile routine */
global $db, $config;
$rec = $db->getRow('select * from ! where id = ?', array( USER_TABLE, $userId) );
$username = $rec['username'];
$delsql = 'delete from ! where userid=?';
$db->query('delete from ! where username = ? or ref_username = ?', array(BUDDY_BAN_TABLE, $username, $username) );
$db->query($delsql, array(FEATURED_PROFILES_TABLE, $userId ) );
$db->query('delete from ! where senderid = ? or recipientid = ?', array(INSTANT_MESSAGE_TABLE, $userId, $userId) );
$db->query('delete from ! where senderid = ? or recipientid = ?', array(MAILBOX_TABLE, $userId, $userId) );
$db->query($delsql, array(ONLINE_USERS_TABLE, $userId ) );
$db->query('delete from ! where userid = ? or profileid = ?', array(USER_RATING_TABLE, $userId, $userId ) );
$db->query($delsql, array(USER_SEARCH_TABLE, $userId ) );
/* Now delete all picture files */
$pic_recs = $db->getAll('select * from ! where userid=?',array(USER_SNAP_TABLE,$userid) );
if (count($pic_recs) > 0) {
foreach ($pic_recs as $row) {
if (substr_count($row['picture'], 'file:' )>0 ) {
$imgfile = ltrim(rtrim(str_replace('file:','',$row['picture'] ) ) );
@unlink(USER_IMAGE_DIR.$imgfile);
}
if (substr_count($row['tnpicture'],'file:' )>0 ) {
$imgfile = ltrim(rtrim(str_replace('file:','',$row['tnpicture'] ) ) );
@unlink(USER_IMAGE_DIR.$imgfile);
}
$db->query('delete from ! where id=?', array(USER_SNAP_TABLE, $row['id']) );
}
}
$db->query($delsql, array(USER_VIDEOS_TABLE, $userId ) );
$db->query('delete from ! where username = ? ', array(USERALBUMS_TABLE, $username) );
$db->query('delete from ! where userid = ? or ref_userid = ?', array(VIEWS_WINKS_TABLE, $userId, $userId) );
$db->query('delete from ! where id = ?', array(USER_TABLE, $userId ) );
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -