Skip to content

Commit

Permalink
Testing internet connection in mail now only happens in debug mode. i…
Browse files Browse the repository at this point in the history
…s_connected now outputs a html comment error.
  • Loading branch information
balupton committed Nov 11, 2010
1 parent 80d2511 commit 47be2a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
11 changes: 9 additions & 2 deletions lib/Bal/Bootstrap.php
Expand Up @@ -48,15 +48,20 @@ protected function _initMail ( ) {

# Prepare Options
$use_mail = delve($applicationConfig, 'mail.send_email', true);
if ( !$use_mail ) return false;
elseif ( !is_connected() ) return false;
if ( !$use_mail ) {
return false;
} elseif ( DEBUG_MODE && !is_connected() ) {
return false;
}

# Fetch
$smtp_host = delve($applicationConfig, 'mail.transport.smtp.host', 'localhost');
$smtp_config = delve($applicationConfig, 'mail.transport.smtp.config');
if ( empty($smtp_config) )
$smtp_config = array();

var_dump($smtp_host, $smtp_config);

# Apply
$Transport = new Zend_Mail_Transport_Smtp($smtp_host, $smtp_config);
Zend_Mail::setDefaultTransport($Transport);
Expand Down Expand Up @@ -231,6 +236,7 @@ protected function _initRoutes ( ) {
* @return
*/
protected function _initAutoload ( ) {
$_args = func_get_args(); Bootstrapr::log(__FILE__,__LINE__,__CLASS__,__FUNCTION__,$_args); unset($_args);
# Initialise Zend's Autoloader, used for plugins etc
$Autoloader = Zend_Loader_Autoloader::getInstance();
$Autoloader->registerNamespace('Bal_');
Expand Down Expand Up @@ -325,6 +331,7 @@ protected function _initApp ( ) {
$this->bootstrap('mail'); // we require mailing in case something goes wrong
$this->bootstrap('log'); // we require logging in various areas


# Load
$FrontController = Zend_Controller_Front::getInstance();

Expand Down
30 changes: 16 additions & 14 deletions lib/core/functions/_url.funcs.php
Expand Up @@ -128,21 +128,23 @@ function regen_url ( $params = NULL, $amp = '&' ) {
if ( function_compare('is_connected', 2, true, __FILE__, __LINE__) ) {

/**
* Checks internet connection
* @author http://www.weberdev.com/get_example-4025.html
* @copyright Unknown
* @version 1, February 24, 2010
* Checks internet connection. Used to detect whether or not we can send emails.
* @version 1.1, November 11, 2010
* @since 1, February 24, 2010
* @param string $url [optional]
* @return string
* @todo figure out what the hell this does
*/
function is_connected ( ) {
$result = false;
$connected = @fsockopen('www.google.com', 80);
if ( $connected ){
$result = true;
fclose($connected);
}
return $result;
*/
function is_connected ( $url = 'www.google.com' ) {
$result = false;
$connected = fsockopen($url, 80, $errno, $errstr, 1);
if ( $connected ){
$result = true;
fclose($connected);
}
elseif ( $errstr ) {
echo "<!--[$errstr ($errno)]-->\n";
}
return $result;
}
}

Expand Down

0 comments on commit 47be2a1

Please sign in to comment.