Skip to content
Browse files

Testing internet connection in mail now only happens in debug mode. i…

…s_connected now outputs a html comment error.
  • Loading branch information...
1 parent 80d2511 commit 47be2a163a9c26e5ce9ff80d4e744df27a9ceec0 @balupton balupton committed Nov 11, 2010
Showing with 25 additions and 16 deletions.
  1. +9 −2 lib/Bal/Bootstrap.php
  2. +16 −14 lib/core/functions/_url.funcs.php
View
11 lib/Bal/Bootstrap.php
@@ -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);
@@ -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_');
@@ -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();
View
30 lib/core/functions/_url.funcs.php
@@ -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;
}
}

0 comments on commit 47be2a1

Please sign in to comment.
Something went wrong with that request. Please try again.