* ';
$FORM_NOT_REQUIRED_ITEM = ' ';
$PER_SOCKET_SEND = 50;
// used by the editor pages - autoresponders, compose, templates - to fix up improper characters.
$BAD_ENCODED_CHARS = array('•');
$PROPER_ENCODED_CHARS = array('');
$safe_mode = ini_get('safe_mode');
if ($safe_mode == 'off') $safe_mode = 0;
if ($safe_mode == 'on') $safe_mode = 1;
define('SAFE_MODE', $safe_mode);
if (defined('SENDSTUDIO_VERSION') && SENDSTUDIO_VERSION == 2004) {
function DisplayDate($Date){
GLOBAL $DateFormat;
return date($DateFormat, $Date);
}
}
function DisplayStrfDate($Date) {
GLOBAL $StrDateFormat;
return strftime($StrDateFormat, $Date);
}
function TableExists($tablename='') {
global $TABLEPREFIX;
if (!$tablename) return false;
$qry = "SHOW TABLES LIKE '" . $TABLEPREFIX . $tablename . "'";
$result = mysql_query($qry);
if (mysql_num_rows($result) > 0) return true;
return false;
}
function LicenseCheck($die=true) {
$LicenseError = "";
ssQmz44Rtt($LicenseError);
// if this is defined, we should be doing the check (we're using a new license).
// otherwise we're in the middle of an upgrade - forget the check!
if (defined('SENDSTUDIO_VERSION') && SENDSTUDIO_VERSION == '2004') {
if($LicenseError != "")
{
$GLOBALS['LicenseError'] = $LicenseError;
if ($die) {
OutputPageHeader(false);
?>
|
Click here to update your license key.");
?>
|
0){
$PageOut=$ROOTURL."admin/index.php?p=" . str_replace('?', '&', $Page) . "&SSID=$SSID";
}else{
$PageOut=$ROOTURL."admin/index.php?p=$Page&SSID=$SSID";
}
return $PageOut;
}
function FinishOutput(){
GLOBAL $OUTPUT, $ROOTDIR;
include $ROOTDIR."admin/includes/admin.inc.php";
}
/*
This function is used by the email importer and bounce processor.
*/
function ConnectEmail($hostname='', $username='', $password='', $emailport='110') {
if (!$hostname || !$username || !$password || !$emailport) return array(false, "Please provide login information");
$inbox = @imap_open('{' . addslashes($hostname) . ':' . addslashes($emailport).'/pop3/notls}INBOX', urlencode(stripslashes($username)), stripslashes($password));
if (!$inbox) {
return array(false, imap_last_error());
}
return array(true, $inbox);
}
if (!function_exists('array_fill')) {
function array_fill($iStart, $iLen, $vValue) {
$aResult = array();
for ($iCount = $iStart; $iCount < $iLen + $iStart; $iCount++) {
$aResult[$iCount] = $vValue;
}
return $aResult;
}
}
/*
Used by view-archive page.
*/
function RetrieveArchive($archivedir='', $member=array()) {
if (!$archivedir || !is_array($member)) return false;
if (!is_dir($archivedir)) return false;
$format = $member['Format'];
if ($format == 1) {
$filetype = 'txt';
$newsformat = 'TEXT';
} else {
$filetype = 'html';
$newsformat = strtoupper($filetype);
}
$archivefile = $html_archivefile = false;
$files = list_files($archivedir);
foreach($files as $file) {
$ext = substr($file, (strrpos($file, '.')+1));
if ($ext == 'html') $html_archivefile = $file;
if ($ext == $filetype) {
$archivefile = $file;
}
}
// default to the html archive file if there is one..
// this is the one most people will want to see anyway.
if ($html_archivefile) $archivefile = $html_archivefile;
// default to the html newsletter if we can't find the proper one.
if (!$archivefile) $archivefile = $html_archivefile;
if ($archivefile) {
// read in the file.
ob_start();
readfile($archivedir . '/' . $archivefile);
$contents = ob_get_contents();
ob_end_clean();
}
return array($newsformat, $contents);
}
/*
Used by createemails.inc.php and compose.php (for previews).
*/
function add_attachments($attachments=array(), $boundary='') {
if (empty($attachments) || $boundary == '') return '';
global $TABLEPREFIX;
$EmailBody = '';
$basedir = dirname(dirname(__FILE__));
foreach($attachments as $attachmentid) {
if ($attachmentid == '') continue;
$attachment_filename_result = mysql_query("SELECT AttachmentName, AttachmentFilename FROM " . $TABLEPREFIX . "attachments WHERE AttachmentID='".addslashes($attachmentid)."'");
if (mysql_num_rows($attachment_filename_result) < 1) {
continue;
}
$attachment_row = mysql_fetch_assoc($attachment_filename_result);
$GLOBALS['AttachmentDetails'][$attachmentid] = array(
'AttachmentName' => $attachment_row['AttachmentName'],
'AttachmentFilename' => $attachment_row['AttachmentFilename']
);
$attachment_row = stripslashes_array($attachment_row);
$attachmentfile = $basedir . '/' . $attachment_row['AttachmentFilename'];
if (!is_file($attachmentfile)) continue;
$EmailBody .= "--" . $boundary . "\n";
$EmailBody .= "Content-type: application/octet-stream;\n";
$EmailBody .= "Content-Disposition: attachment;";
$EmailBody .= " filename=\"" . $attachment_row['AttachmentName'] . "\"\n";
$EmailBody .= "Content-Transfer-Encoding: base64\n\n";
$fp = fopen($attachmentfile, 'rb');
$filedata = fread($fp, filesize($attachmentfile));
fclose($fp);
$EmailBody .= chunk_split(base64_encode($filedata)) . "\n" . "\n";
}
return $EmailBody;
}
// recursive function to remove slashes from an array or single keyword.
function stripslashes_array($array) {
if (is_array($array)) {
$return = array();
foreach($array as $key => $value) {
$key = stripslashes($key);
if (is_array($value)) {
$return[$key] = stripslashes_array($value);
continue;
}
$return[$key] = stripslashes($value);
}
} else {
$return = stripslashes($array);
}
return $return;
}
function remove_directory($directory='') {
if (!is_dir($directory)) return true;
if (!$handle = opendir($directory)) {
return false;
}
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') continue;
$f = $directory . '/' . $file;
if (is_dir($f)) {
remove_directory($directory . '/' . $f);
}
if (is_file($f)) {
if (!unlink($f)) {
closedir($handle);
return false;
}
}
}
closedir($handle);
return true;
}
/*
Used by newsletters and mailing lists to clean up after themselves when deleted.
*/
function remove_newsletter_archives($id, $type='list') {
global $ROOTDIR;
$type = strtolower($type);
$status = false;
if ($type == 'list') {
$status = remove_directory('../archive/' . $id);
}
if ($type == 'compose') {
global $TABLEPREFIX;
$query = "SELECT ListID FROM " . $TABLEPREFIX . "sends WHERE ComposedID='" . addslashes($id) . "'";
$result = mysql_query($query);
if (mysql_num_rows($result) < 1) return true;
while($row = mysql_fetch_assoc($result)) {
$status = remove_directory($ROOTDIR . '/archive/' . $row['ListID'] . '/' . $id);
}
}
return $status;
}
/*
Mainly used by the importer functions.
*/
function list_files($dir='', $skip_files = null) {
if (empty($dir) || !is_dir($dir)) return false;
$file_list = array();
if (!$handle = opendir($dir)) {
return false;
}
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') continue;
if (is_file($dir.'/'.$file)) {
if (empty($skip_files)) {
$file_list[] = $file;
continue;
}
if (!empty($skip_files)) {
if (is_array($skip_files) && !in_array($file, $skip_files)) {
$file_list[] = $file;
}
if (!is_array($skip_files) && $file != $skip_files) {
$file_list[] = $file;
}
}
}
}
closedir($handle);
return $file_list;
}
/*
This is used by the database importer.
*/
function MySQLConnect($hostname='', $username='', $password='', $database='') {
if ($hostname == '' || $username == '' || $database == '') return array(false, 'Either your hostname, username or database name are missing.
Please try again.');
$new_connection = ($password) ? mysql_connect($hostname, $username, $password) : mysql_connect($hostname, $username);
if (!$new_connection) return array(false, mysql_error());
$select_db = mysql_select_db($database, $new_connection);
if (!$select_db) return array(false, mysql_error());
return array(true, $new_connection);
}
/*
This is used by the file importer.
*/
function ParseImportFile($ImportID, $JustHeaders=false, $importfile = false) {
GLOBAL $ROOTDIR;
GLOBAL $data, $MaxFields, $headers, $t;
GLOBAL $C, $OUTPUT;
GLOBAL $TABLEPREFIX;
$imp = mysql_fetch_assoc(mysql_query("SELECT * FROM " . $TABLEPREFIX . "imports WHERE ImportID='".addslashes($ImportID)."'"));
$file = $ROOTDIR.'/temp/'.$ImportID;
if ($importfile) $file = $ROOTDIR.'/'.$importfile;
$recdim = str_replace("NEWLINE","\n",$imp['RecordDelim']);
$feidim = str_replace("NEWLINE","\n",$imp['FieldDelim']);
$feidim = str_replace("TAB","\t",$imp['FieldDelim']);
if(!$f = fopen($file,'r')) {
return '';
}
while(!feof($f)) {
$data .= fread($f, 10240);
if ($JustHeaders) break;
}
fclose($f);
// in case it's a Mac file...
$data = str_replace("\r", "\n", $data);
$lines = explode($recdim,$data);
$foundheaders = false;
foreach($lines as $line) {
if($imp['Headers']==1 && !$foundheaders) {
$foundheaders = true;
$headers=$line;
} else {
$DataLines[]=$line;
}
//maximum fields!
$numf=substr_count($line,$feidim)+1;
if($numf>$MaxFields) {
$MaxFields=$numf;
}
}
//headers!
if(!$headers) {
for($r=1;$r<=$MaxFields;$r++) {
$H[$r]="Field $r";
}
} else {
$fields=explode($feidim,$headers);
$x=0;
foreach($fields as $f) {
$x++;
$f=trim($f);
$H[$x]=$f;
}
}
//data
if($DataLines) {
foreach($DataLines as $dl) {
$i=1;
$t++;
$fields=explode($feidim,$dl);
foreach($fields as $f) {
$D[$t][$H[$i]]=trim($f);
$i++;
}
}
}
$all['Headers']=$H;
$all['Data']=$D;
return $all;
}
function load_member($memberid=0, $listid=0) {
if ($memberid <= 0) return false;
global $TABLEPREFIX;
$member_query = "SELECT * FROM " . $TABLEPREFIX . "members WHERE MemberID='" . addslashes($memberid) . "'";
if ($listid) $member_query .= " AND ListID='" . addslashes($listid) . "'";
$member_result = mysql_query($member_query);
$member = stripslashes_array(mysql_fetch_assoc($member_result));
return $member;
}
function getmicrotime() {
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function timedifference($timedifference) {
if ($timedifference < 60) {
$timechange = number_format($timedifference, 0) . ' second';
if ($timedifference > 1) $timechange .= 's';
}
if ($timedifference >= 60 && $timedifference < 3600) {
$num_mins = floor($timedifference / 60);
$timechange = number_format($num_mins, 0) . ' minute';
if ($num_mins > 1) $timechange .= 's';
}
if ($timedifference >= 3600) {
$hours = floor($timedifference/3600);
$mins = floor($timedifference % 3600) / 60;
$timechange = number_format($hours, 0) . ' hour';
if ($hours > 1) $timechange .= 's';
$timechange .= ' and ' . number_format($mins, 0) . ' minute';
if ($mins > 1) $timechange .= 's';
}
return $timechange;
}
/*
Used by the scheduler and the send popup to send an email if you're sending through an SMTP server.
*/
function SendEmail($to, $from, $msg, $server, $port=25) {
if ($port <= 0) $port = 25;
$username = $password = false;
if (strpos($server, ';') !== false) {
list($servername, $username, $password) = explode(';', str_replace(' ', '', $server));
$server = $servername;
}
$timeout = 10;
$crlf = "\r\n";
if (!isset($GLOBALS['EMAIL_SOCKET']) || !is_resource($GLOBALS['EMAIL_SOCKET'])) {
$socket = fsockopen($server, $port, $errno, $errstr, $timeout);
if (!$socket) {
return array(false, 'Unable to connect to email server');
}
sleep(1);
$response = get_lines($socket);
$responsecode = substr($response, 0, 3);
// connecting too frequently? put in a random sleep.
if ($responsecode == '450') {
sleep(rand(1, 10));
return array(false, 'Mail server not accepting our connections: ' . $response);
}
// not connecting too frequently? Just log the error and return.
if ($responsecode != '220') {
return array(false, 'Mail server not accepting our connections: ' . $response);
}
$GLOBALS['EMAIL_SOCKET'] = $socket;
// say hi!
$data = 'EHLO ' . $server . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data (EHLO) - no bytes written');
}
$response = get_lines($GLOBALS['EMAIL_SOCKET']);
$responses = explode($crlf, $response);
$requireauth = false;
if ($username && $password) {
foreach($responses as $line) {
if (preg_match('%250-auth(.*?)login%i', $line)) $requireauth = true;
}
}
sleep(1);
if ($requireauth) {
$data = "AUTH LOGIN" . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data (AUTH LOGIN) - no bytes written');
}
$response = get_lines($GLOBALS['EMAIL_SOCKET']);
$responsecode = substr($response, 0, 3);
if ($responsecode != '334') {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Email server doesn\'t support "AUTH LOGIN" authentication');
}
$data = base64_encode($username) . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data (USERNAME) - no bytes written');
}
$response = get_lines($GLOBALS['EMAIL_SOCKET']);
$responsecode = substr($response, 0, 3);
if ($responsecode != '334') {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server replied strangely when providing the username (' . $response . ')');
}
$data = base64_encode($password) . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data (PASSWORD) - no bytes written');
}
$response = get_lines($GLOBALS['EMAIL_SOCKET']);
$responsecode = substr($response, 0, 3);
if ($responsecode != '235') {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Invalid login details when connecting to smtp server');
}
}
} else {
sleep(1);
}
$data = "MAIL FROM: <" . $from . ">" . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data (MAIL FROM) - no bytes written');
}
$response = get_lines($GLOBALS['EMAIL_SOCKET']);
$responsecode = substr($response, 0, 3);
if ($responsecode != '250') {
return array(false, 'Server doesn\'t support MAIL FROM (' . $response . ')');
}
$data = "RCPT TO: <" . $to . ">" . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data (RCPT TO) - no bytes written');
}
$response = get_lines($GLOBALS['EMAIL_SOCKET']);
$responsecode = substr($response, 0, 3);
if ($responsecode != '250') {
return array(false, 'Server doesn\'t support RCPT TO (' . $response . ')');
}
$data = "DATA" . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data (DATA) - no bytes written');
}
$response = get_lines($GLOBALS['EMAIL_SOCKET']);
$responsecode = substr($response, 0, 3);
if ($responsecode != '354') {
return array(false, 'Server doesn\'t support DATA (' . $response . ')');
}
$msg = str_replace("\r\n","\n",$msg);
$msg = str_replace("\r","\n",$msg);
$lines = explode("\n",$msg);
foreach($lines as $no => $line) {
$data = $line . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data (CONTENT) - no bytes written');
}
}
$data = $crlf . "." . $crlf;
if (!fputs($GLOBALS['EMAIL_SOCKET'], $data, strlen($data))) {
unset($GLOBALS['EMAIL_SOCKET']);
return array(false, 'Server not accepting data ( . - END OF MESSAGE ) - no bytes written');
}
$response = get_lines($GLOBALS['EMAIL_SOCKET']);
$responsecode = substr($response, 0, 3);
if ($responsecode != '250') {
return array(false, 'Message not queued (' . $response . ')');
}
return array(true, false);
}
function get_lines($socket=false) {
if (!$socket) return;
$data = "";
while($str = fgets($socket,515)) {
$data .= $str;
# if the 4th character is a space then we are done reading
# so just break the loop
if(substr($str,3,1) == " ") { break; }
}
return trim($data);
}
/*
This is used by the 'manage members' and 'stats' pages. It turns an array into a urlencoded string.
*/
function EncodeFields($Fields=array(), $prefix='Fields') {
$urldata = '';
if($Fields)
{
foreach($Fields as $FID=>$FVAL)
{
if (is_array($FVAL)) {
$FVAL = serialize($FVAL);
}
$urldata .= $prefix . '[' . $FID . ']=' . urlencode(stripslashes($FVAL)) . '&';
}
}
return $urldata;
}
function ReplaceLinksAndImages($Content, $Format)
{
global $CURRENTADMIN;
global $ROOTURL;
global $TABLEPREFIX;
if (TableExists('images')) {
//images
if($CURRENTADMIN["Manager"] == 1)
{
$images=mysql_query("SELECT * FROM " . $TABLEPREFIX . "images");
}
else
{
$images=mysql_query("SELECT * FROM " . $TABLEPREFIX . "images WHERE AdminID='" . addslashes($CURRENTADMIN['AdminID']) . "'");
}
while($i = mysql_fetch_assoc($images))
{
$i = stripslashes_array($i);
if($Format == "html")
{
$tv = '
';
}
else
{
$tv = $ROOTURL . '/temp/images/' . $i["ImageID"] . "." . $i["ImageType"];
}
$protocol = substr($ROOTURL, 0, strpos($ROOTURL, ':'));
$tv = str_replace($protocol.':/', $protocol.'://', str_replace('//', '/', $tv));
$Content = str_replace('%IMAGE:' . $i['ImageID'] . '%', $tv, $Content);
}
}
if (TableExists('links')) {
//links!
if($CURRENTADMIN['Manager'] == 1)
{
$links = mysql_query("SELECT * FROM " . $TABLEPREFIX . "links");
}
else
{
$links = mysql_query("SELECT * FROM " . $TABLEPREFIX . "links WHERE AdminID='" . addslashes($CURRENTADMIN["AdminID"]) . "'");
}
while($l = mysql_fetch_assoc($links))
{
$l = stripslashes_array($l);
if($Format == 'html')
{
$tv = '' . $ROOTURL . 'users/link.php?Link=' . $l['LinkID'] . '&UserID=' . '';
}
else
{
$tv = $ROOTURL . 'users/link.php?LinkID=' . $l["LinkID"] . '&UserID=';
}
$Content = str_replace('%LINK:' . $l['LinkID'] . '%', $tv, $Content);
}
}
return $Content;
}
/*******************************************************************************************
*
*
* DEV FUNCTIONS BELOW
*
*
*******************************************************************************************/
########################################################
# Recursively prints array contents - works goodly on
# associative arrays
#########################################################
function array_contents(&$array, $max_depth=0, $depth=0, $ignore_ints=false) {
$string = $indent = "";
for ($i = 0; $i < $depth; $i++) $indent .= "\t";
if (!empty($max_depth) && $depth >= $max_depth) {
return $indent."[Max Depth Reached]\n";
}
if (empty($array)) return $indent."[Empty]\n";
reset($array);
while ( list($key,$value) = each($array) ) {
$print_key = str_replace("\n","\\n",str_replace("\r","\\r",str_replace("\t","\\t",addslashes($key))));
if ($ignore_ints && gettype($key) == "integer") continue;
$type = gettype($value);
if ($type == "array" || $type == "object") {
$string .= $indent
. ((is_string($key)) ? "\"$print_key\"": $key) . " => "
. (($type == "array")?"array (\n":"")
. (($type == "object")?"new ".get_class($value)." Object (\n":"");
$string .= array_contents($value, $max_depth, $depth + 1, $ignore_ints);
$string .= $indent . "),\n";
} else {
if (is_string($value)) $value = str_replace("\n","\\n",str_replace("\r","\\r",str_replace("\t","\\t",addslashes($value))));
$string .= $indent
. ((is_string($key)) ? "\"$print_key\"": $key) . " => "
. ((is_string($value)) ? "\"$value\"": $value) . ",\n";
}
}
$string[ strlen($string) - 2 ] = " ";
return $string;
}
# alias for pre_echo
function bam($x='BAM!', $max_depth=0, $style='') {
pre_echo($x, $max_depth, $style);
}
#################################################################################
# take any kind of variable and tries to print it out
###############################################################################
function pre_echo($x='BAM!', $max_depth=0, $style='') {
?>