Ignore:
Timestamp:
02/10/08 16:01:38 (4 years ago)
Author:
hverton
Message:

added M2F configuration to the admin module, removed the old m2f_config.php file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/common/mail2forum/php-files/modules/mail2forum/m2f_smtp.php

    r1238 r1257  
    1414} 
    1515 
    16 /*---------------------------------------------------+ 
    17 | Read the user configuration 
    18 +----------------------------------------------------*/ 
    19  
    20 require "m2f_config.php"; 
    21  
    2216// find the webroot, so we can load the core functions 
    2317$webroot = ""; 
     
    2620    if (strlen($webroot)>100) die('Unable to find the ExiteCMS document root!');  
    2721} 
     22require_once $webroot."includes/core_functions.php"; 
    2823 
    2924// make sure the host is known 
    30 $_SERVER['HTTP_HOST'] = M2F_HOST; 
    31  
    32 require_once $webroot."includes/core_functions.php"; 
     25$_SERVER['HTTP_HOST'] = $settings['m2f_host']; 
    3326 
    3427locale_load("modules.mail2forum"); 
     
    4942function logentry($task="", $message="", $abort=false, $exitcode=0) { 
    5043 
    51     global $processor; 
    52      
    53     $handle = fopen(M2F_LOGFILE.'/M2F_process.log', 'a'); 
     44    global $processor, $settings; 
     45     
     46    $handle = fopen($settings['m2f_logfile'].'/M2F_process.log', 'a'); 
    5447    fwrite($handle, date("Ymd").";".date("His").";".$processor.";".$task.";".$message.chr(10)); 
    5548    fclose($handle); 
     
    6154function logdebug($task="", $message="") { 
    6255 
    63     global $processor; 
    64      
    65     $handle = fopen(M2F_LOGFILE.'/'.$processor.'.debug.log', 'a'); 
     56    global $processor, $settings; 
     57     
     58    $handle = fopen($settings['m2f_logfile'].'/'.$processor.'.debug.log', 'a'); 
    6659    fwrite($handle, date("Ymd").";".date("His").";".$task.";".$message.chr(10)); 
    6760    fclose($handle); 
     
    7265    global $mail, $locale, $settings; 
    7366 
    74     if (M2F_SMTP_DEBUG) $mail->SMTPDebug = 2; 
     67    if ($settings['m2f_smtp_debug']) $mail->SMTPDebug = 2; 
    7568 
    7669    if (file_exists(PATH_INCLUDES."languages/phpmailer.lang-".$settings['phpmailer_locale'].".php")) { 
     
    10598 
    10699// log the start 
    107 if (M2F_PROCESS_LOG) logentry('INIT', 'Program start'); 
     100if ($settings['m2f_process_log']) logentry('INIT', 'Program start'); 
    108101 
    109102// get the last modified timestamp of this module 
    110103$module_lastmod = filemtime('m2f_smtp.php'); 
    111104 
    112 // get the last modified timestamp of the config file 
    113 $config_lastmod = filemtime('m2f_config.php'); 
     105// get the last modified timestamp of the config 
     106$data = dbarray(dbquery("SELECT MAX(cfg_timestamp) AS lastmod FROM ".$db_prefix."configuration WHERE cfg_name LIKE 'm2f_%'")); 
     107$config_lastmod = $data['lastmod']; 
    114108 
    115109// check if the Mail2Forum module is installed 
    116110$result = dbquery("SELECT * FROM ".$db_prefix."modules WHERE mod_title = '".$locale['m2f100']."'"); 
    117111if (dbrows($result) == 0) { 
    118     if (M2F_PROCESS_LOG) logentry('INIT', $locale['m2f999'].' '.$locale['m2f110'], true, 1); 
    119     die('Mail2Forum is not infused'); 
     112    if ($settings['m2f_process_log']) logentry('INIT', $locale['m2f999'].' NOT_INSTALLED', true, 1); 
     113    die($locale['m2f110']); 
    120114} 
    121115 
     
    131125    $lastpoll = time(); 
    132126    $result = dbquery("INSERT INTO ".$db_prefix."M2F_status (m2f_lastpoll) VALUES ('".$lastpoll."')"); 
    133     if (M2F_PROCESS_LOG) logentry("INIT", sprintf($locale['m2f800'], $processor)); 
     127    if ($settings['m2f_process_log']) logentry("INIT", sprintf($locale['m2f800'], $processor)); 
    134128} else { 
    135129    if ($data = dbarray($result)) { 
     
    138132            die($processor.': LastPoll time is invalid. Use the admin module to correct this'); 
    139133        } 
    140         if ((time() - $data['m2f_lastpoll']) > M2F_POLL_THRESHOLD) { 
     134        if ((time() - $data['m2f_lastpoll']) > $settings['m2f_poll_threshold']) { 
    141135            $result = dbquery("UPDATE ".$db_prefix."M2F_status SET m2f_lastpoll = 0"); 
    142             if (M2F_PROCESS_LOG) logentry('INIT', $locale['m2f999'].' '.$locale['m2f801'], true, 1); 
    143             die($processor.': More than a week has passed since the last run! Use the admin module to correct this'); 
     136            if ($settings['m2f_process_log']) logentry('INIT', $locale['m2f999'].' '.$locale['m2f801'], true, 1); 
     137            die($processor.': More time has passed since the last run then the threshold allows! Use the admin module to correct this'); 
    144138        } 
    145139        $lastpoll = $data['m2f_lastpoll']+1; 
    146140    } else { 
    147         if (M2F_PROCESS_LOG) logentry('INIT', $locale['m2f999'].' '.$locale['m2f802'], true, 1); 
     141        if ($settings['m2f_process_log']) logentry('INIT', $locale['m2f999'].' '.$locale['m2f802'], true, 1); 
    148142        die('This should never happen'); 
    149143    } 
     
    271265    // Insert a marker in the log every hour to show we're still alive 
    272266    if (isset($marker) && $marker <> date("H")) 
    273         if (M2F_PROCESS_LOG) logentry("MARKER", "---"); 
     267        if ($settings['m2f_process_log']) logentry("MARKER", "---"); 
    274268    $marker = date("H"); 
    275269 
     
    280274        // get all posts in the selected interval 
    281275        while($postrecord = dbarray($result)) { 
    282             if (M2F_SMTP_DEBUG) logdebug('POSTRECORD', print_r($postrecord, true)); 
     276            if ($settings['m2f_smtp_debug']) logdebug('POSTRECORD', print_r($postrecord, true)); 
    283277 
    284278            $new_post = ($postrecord['post_datestamp'] >= $lastpoll && $postrecord['post_datestamp'] <= $polltime); 
    285279            $edit_post = ($postrecord['post_edittime'] >= $lastpoll && $postrecord['post_edittime'] <= $polltime); 
    286280 
    287             if (M2F_SMTP_DEBUG) logdebug('POST_STATE', ($new_post?"ADD":"").($new_post&&$edit_post?"-":"").($edit_post?"EDIT":"")); 
     281            if ($settings['m2f_smtp_debug']) logdebug('POST_STATE', ($new_post?"ADD":"").($new_post&&$edit_post?"-":"").($edit_post?"EDIT":"")); 
    288282 
    289283            // if a new post was edited within one poll cycle, don't mark it as edited 
     
    293287            $result2 = dbquery("SELECT m.m2f_email, f.forum_name FROM ".$db_prefix."M2F_forums m, ".$db_prefix."forums f WHERE m.m2f_active = '1' AND m.m2f_forumid = '".$postrecord['forum_id']."' AND m.m2f_forumid = f.forum_id"); 
    294288            if (!$result2) { 
    295                 if (M2F_PROCESS_LOG) logentry('ERROR', $locale['m2f999'].' '.$locale['m2f803'].$postrecord['forum_id'], true, 1); 
     289                if ($settings['m2f_process_log']) logentry('ERROR', $locale['m2f999'].' '.$locale['m2f803'].$postrecord['forum_id'], true, 1); 
    296290                die($locale['m2f803']); 
    297291            } else { 
    298292                // get sender information            
    299293                $sender = dbarray($result2); 
    300                 if (M2F_SMTP_DEBUG) logdebug('SENDER', print_r($sender, true)); 
     294                if ($settings['m2f_smtp_debug']) logdebug('SENDER', print_r($sender, true)); 
    301295                 
    302296                // get all subscribed users for this forum 
     
    304298                    WHERE s.m2f_forumid = '".$postrecord['forum_id']."' AND s.m2f_subscribed = '1' AND u.user_status = 0 AND u.user_bad_email = 0 AND u.user_id = s.m2f_userid AND u.user_id = c.m2f_userid"); 
    305299                while ($recipient = dbarray($result2)) { 
    306                     if (M2F_SMTP_DEBUG) logdebug('RECIPIENT', print_r($recipient, true)); 
     300                    if ($settings['m2f_smtp_debug']) logdebug('RECIPIENT', print_r($recipient, true)); 
    307301                     
    308302                    // get the senders profile (need the email address and the email-hidden flag) 
     
    322316                        } 
    323317                    } 
    324                     if (M2F_SMTP_DEBUG) logdebug('POSTER', print_r($poster, true)); 
     318                    if ($settings['m2f_smtp_debug']) logdebug('POSTER', print_r($poster, true)); 
    325319                     
    326320                    // check if the poster wants his email address hidden. If so, use the forum address as sender 
    327                     if (M2F_USE_FORUM_EMAIL || $poster['user_hide_email']) 
     321                    if ($settings['m2f_use_forum_email'] || $poster['user_hide_email']) 
    328322                        $poster['user_email'] = $sender['m2f_email']; 
    329323 
     
    359353                            // although PHP-Fusion does not support multiple attachments, we do... ;-) 
    360354                            while ($attachment = dbarray($res_att)) { 
    361                                 if (M2F_SMTP_DEBUG) logdebug('ATTACHMENT', print_r($attachment, true)); 
     355                                if ($settings['m2f_smtp_debug']) logdebug('ATTACHMENT', print_r($attachment, true)); 
    362356                                $attachURL = $settings['siteurl']."getfile.php?type=a&file_id=".$attachment['attach_id']; 
    363357                                if ($recipient['m2f_html'] == 1) { 
     
    385379                                            case 1: 
    386380                                                // check the size of the attachments, don't send it out if it's to big 
    387                                                 if (filesize(PATH_ATTACHMENTS.$attachment['attach_name']) < M2F_MAX_ATTACH_SIZE) { 
     381                                                if (filesize(PATH_ATTACHMENTS.$attachment['attach_name']) < $settings['m2f_max_attach_size']) { 
    388382                                                    // attach the attachments to the email 
    389383                                                    $mail->AddAttachment(PATH_ATTACHMENTS.$attachment['attach_name']); 
     
    405399                                        case 1: 
    406400                                            // check the size of the attachments, don't send it out if it's to big 
    407                                             if (filesize(PATH_ATTACHMENTS.$attachment['attach_name']) < M2F_MAX_ATTACH_SIZE) { 
     401                                            if (filesize(PATH_ATTACHMENTS.$attachment['attach_name']) < $settings['m2f_max_attach_size']) { 
    408402                                                // attach the attachments to the email 
    409403                                                $mail->AddAttachment(PATH_ATTACHMENTS.$attachment['attach_name']); 
     
    443437                    // send the post to the user 
    444438                    if(!$mail->Send()) { 
    445                         if (M2F_PROCESS_LOG) logentry('SEND', 'ERROR! From:'.$poster['user_email'].' To:'.$recipient['user_email'].' -> '.$mail->ErrorInfo); 
     439                        if ($settings['m2f_process_log']) logentry('SEND', 'ERROR! From:'.$poster['user_email'].' To:'.$recipient['user_email'].' -> '.$mail->ErrorInfo); 
    446440                        unset($mail); 
    447441                        $mail = new PHPMailer(); 
     
    449443                    } else { 
    450444                        $result4 = dbquery("UPDATE ".$db_prefix."M2F_forums SET m2f_sent = m2f_sent + 1 WHERE m2f_forumid = '".$postrecord['forum_id']."' "); 
    451                         if (M2F_PROCESS_LOG) logentry('SEND', 'From:'.$poster['user_email'].' To:'.$recipient['user_email'].' -> '.$subject); 
     445                        if ($settings['m2f_process_log']) logentry('SEND', 'From:'.$poster['user_email'].' To:'.$recipient['user_email'].' -> '.$subject); 
    452446                    } 
    453447 
     
    466460        } 
    467461    } else { 
    468         if (M2F_PROCESS_LOG) logentry('POLL', 'no new posts'); 
     462        if ($settings['m2f_process_log']) logentry('POLL', 'no new posts'); 
    469463    } 
    470464 
     
    475469    clearstatcache(); 
    476470    if (filemtime('m2f_smtp.php') != $module_lastmod) { 
    477         if (M2F_PROCESS_LOG) logentry('EXIT', 'Restart due to module code update'); 
     471        if ($settings['m2f_process_log']) logentry('EXIT', 'Restart due to module code update'); 
    478472        exit(99); 
    479473    } 
    480     // if the config has been modified, exit so it can be reloaded 
    481     if (filemtime('m2f_config.php') != $config_lastmod) { 
    482         if (M2F_PROCESS_LOG) logentry('EXIT', 'Restart due to configuration change'); 
     474    // get the last modified timestamp of the config 
     475    $data = dbarray(dbquery("SELECT MAX(cfg_timestamp) AS lastmod FROM ".$db_prefix."configuration WHERE cfg_name LIKE 'm2f_%'")); 
     476    if ($data['lastmod'] != $config_lastmod) { 
     477        if ($settings['m2f_process_log']) logentry('EXIT', 'Restart due to a configuration change'); 
    483478        exit(99); 
    484479    } 
    485480 
    486481    // calculate the next interval. Log a warning if we can't process quick enough 
    487     $interval = $polltime + M2F_INTERVAL - time(); 
     482    $interval = $polltime + $settings['m2f_interval'] - time(); 
    488483    if ($interval < 0) { 
    489         if (M2F_PROCESS_LOG) logentry('SLEEP', $locale['m2f999'].' '.$locale['m2f804']); 
     484        if ($settings['m2f_process_log']) logentry('SLEEP', $locale['m2f999'].' '.$locale['m2f804']); 
    490485    } else { 
    491486        sleep($interval); 
     
    496491    if ($data = dbarray($result)) { 
    497492        if ($data['m2f_abort'] == 1) { 
    498             if (M2F_PROCESS_LOG) logentry('WAKE-UP', $locale['m2f999'].' '.$locale['m2f805'], true, 1); 
     493            if ($settings['m2f_process_log']) logentry('WAKE-UP', $locale['m2f999'].' '.$locale['m2f805'], true, 1); 
    499494            die($locale['m2f805']); 
    500495        } 
    501496        $lastpoll = $data['m2f_lastpoll']+1; 
    502497    } else { 
    503         if (M2F_PROCESS_LOG) logentry('WAKE-UP', $locale['m2f999'].' '.$locale['m2f802'], true, 1); 
     498        if ($settings['m2f_process_log']) logentry('WAKE-UP', $locale['m2f999'].' '.$locale['m2f802'], true, 1); 
    504499        die($locale['m2f802']); 
    505500    } 
Note: See TracChangeset for help on using the changeset viewer.