Example #1
0
 /**
  * Main shell function
  */
 function main()
 {
     $queue = $this->QueuedEmail->find('all', array('limit' => $this->settings['limit']));
     if (empty($queue)) {
         exit;
     }
     $this->CronMailer->_set($this->settings);
     foreach ($queue as $email) {
         $this->CronMailer->to = $email['QueuedEmail']['to'];
         $this->CronMailer->from = $email['QueuedEmail']['from'];
         $this->CronMailer->replyTo = $email['QueuedEmail']['replyTo'];
         $this->CronMailer->readReceipt = $email['QueuedEmail']['readReceipt'];
         $this->CronMailer->return = $email['QueuedEmail']['return'];
         $this->CronMailer->headers = unserialize($email['QueuedEmail']['headers']);
         $this->CronMailer->additionalParams = unserialize($email['QueuedEmail']['additionalParams']);
         $this->CronMailer->attachments = unserialize($email['QueuedEmail']['attachments']);
         $this->CronMailer->subject = $email['QueuedEmail']['subject'];
         $this->CronMailer->htmlContent = $email['QueuedEmail']['htmlMessage'];
         $this->CronMailer->textContent = $email['QueuedEmail']['textMessage'];
         $this->CronMailer->template = 'dummy';
         // required to trigger the _render function in the CronMailerComponent
         if ($this->CronMailer->send()) {
             $this->QueuedEmail->delete($email['QueuedEmail']['id']);
         }
         $this->CronMailer->reset();
     }
 }
Example #2
0
 /**
  * Render template in site theme
  * @param string $templatePath path to template without extension
  * @param array $data data to insert in template
  * @return string
  */
 public function renderTemplate($templatePath, $data)
 {
     $this->signal->send($this, 'renderTemplate', $data);
     $data = $this->applyFilter($data);
     if (is_array($data)) {
         extract($data);
     }
     ob_start();
     require $this->themePath . $templatePath . ".php";
     $output = ob_get_clean();
     return $output;
 }
Example #3
0
 /**
  * Cache a search into the database.
  *
  * @param string $sSearch Search value.
  * @param array $aIds ARRAY of value IDs.
  * @param array $aExtraParams Extra params you want to store in the database.
  * @return mixed If the 2nd argument is empty we return FALSE, otherwise we return NULL.
  */
 public function cacheResults($sSearch, $aIds, $aExtraParams = null)
 {
     if (!count($aIds)) {
         Phpfox::getLib('session')->set('search_fail', true);
         $this->_oUrl->send($this->getFormUrl());
     }
     unset($this->_aSearch['submit']);
     $aInsert = array('user_id' => Phpfox::getUserId(), 'search_array' => serialize($this->_aSearch), 'search_ids' => implode(',', $aIds), 'time_stamp' => PHPFOX_TIME);
     if (is_array($sSearch)) {
         $aSearches = array();
         foreach ($sSearch as $sKeySearch) {
             if ($sCacheSearch = $this->_getVar($sKeySearch)) {
                 $aSearches[] = $sCacheSearch;
             }
         }
         if (count($aSearches)) {
             $aInsert['search_query'] = serialize($aSearches);
         }
     } else {
         if ($sSearch = $this->_getVar($sSearch)) {
             $aInsert['search_query'] = $sSearch;
         }
     }
     $iSearchIds = Phpfox_Database::instance()->insert(Phpfox::getT('search'), $aInsert);
     $this->_oUrl->setParam('search-id', $iSearchIds);
     if ($aExtraParams !== null && is_array($aExtraParams)) {
         foreach ($aExtraParams as $sKey => $sValue) {
             $this->_oUrl->setParam($sKey, $sValue);
         }
     }
     $this->_oUrl->forward($this->_oUrl->getFullUrl());
 }
Example #4
0
 /**
  * Display the given exception to the user.
  *
  * @param   object  $exception
  * @return  void
  */
 public function render(Exception $error)
 {
     $status = $error->getCode() ? $error->getCode() : 500;
     $status = $status < 100 || $status >= 600 ? 500 : $status;
     $content = new \StdClass();
     $content->message = $error->getMessage();
     $content->code = $status;
     if ($this->debug) {
         $content->trace = array();
         $backtrace = $error->getTrace();
         if (is_array($backtrace)) {
             $backtrace = array_reverse($backtrace);
             for ($i = count($backtrace) - 1; $i >= 0; $i--) {
                 if (isset($backtrace[$i]['class'])) {
                     $line = "[{$i}] " . sprintf("%s %s %s()", $backtrace[$i]['class'], $backtrace[$i]['type'], $backtrace[$i]['function']);
                 } else {
                     $line = "[{$i}] " . sprintf("%s()", $backtrace[$i]['function']);
                 }
                 if (isset($backtrace[$i]['file'])) {
                     $line .= sprintf(' @ %s:%d', str_replace(PATH_ROOT, '', $backtrace[$i]['file']), $backtrace[$i]['line']);
                 }
                 $content->trace[] = $line;
             }
         }
     }
     $this->response->setStatusCode($content->code);
     $this->response->setContent($content);
     $this->response->send();
     exit;
 }
 /**
  * Initializes the webservice.
  *
  * @access public
  * @return void
  */
 public function run()
 {
     $strPath = trim(preg_replace('#' . TL_PATH . '/interface#', '', \Environment::get('requestUri'), 1), '/');
     if (!is_array($GLOBALS['RESTFUL_WEBSERVICES']['ROUTING']) || count($GLOBALS['RESTFUL_WEBSERVICES']['ROUTING']) < 1) {
         $this->response->sendError(404);
     }
     // Go through each defined routing item
     foreach ($GLOBALS['RESTFUL_WEBSERVICES']['ROUTING'] as $k => $v) {
         // Handle params
         if (!$this->handleParams($strPath, $v['pattern'], $v['requirements'])) {
             continue;
         }
         // Check methods
         if (!$this->checkMethods($v['methods'])) {
             continue;
         }
         // Check tokens
         if (!$this->checkTokens($v['tokens'])) {
             continue;
         }
         // Check allowed ip addresses
         if (!$this->checkIps($v['ips'])) {
             continue;
         }
         // Check allowed CORS hosts
         $this->checkCors($v['cors']);
         // Call webservice class method
         $this->callClassMethod($this->getClass($k), $this->getMethod());
         // Send response
         $this->response->send();
         exit;
     }
     // Throw error
     $this->response->sendError(404);
 }
Example #6
0
 /**
  * Envoi via la classe smtp
  * 
  * @param string $address  Adresses des destinataires
  * @param string $message  Corps de l'email
  * @param string $headers  Entêtes de l'email
  * @param string $Rpath    Adresse d'envoi (définit le return-path)
  * 
  * @access private
  * @return boolean
  */
 function smtpmail($address, $message, $headers, $Rpath)
 {
     if (!is_resource($this->smtp->connect_id) || !$this->smtp->noop()) {
         if (!$this->smtp->connect()) {
             $this->error($this->smtp->msg_error);
             return false;
         }
     }
     if (!$this->smtp->mail_from($Rpath)) {
         $this->error($this->smtp->msg_error);
         return false;
     }
     foreach ($address as $email) {
         if (!$this->smtp->rcpt_to($email)) {
             $this->error($this->smtp->msg_error);
             return false;
         }
     }
     if (!$this->smtp->send($headers, $message)) {
         $this->error($this->smtp->msg_error);
         return false;
     }
     //
     // Apparamment, les commandes ne sont réellement effectuées qu'après la fermeture proprement
     // de la connexion au serveur SMTP. On quitte donc la connexion courante si l'option de connexion
     // persistante n'est pas activée.
     //
     if (!$this->persistent_connection) {
         $this->smtp->quit();
     }
     return true;
 }
 /**
  * Send the mail
  *
  * @access public
  * @param  void
  * @return bool	Mailer_result
  * 
  **/
 public function send()
 {
     if ($this->message === NULL) {
         $this->setup();
     }
     $this->connect($this->config);
     try {
         //should we batch send or not?
         if (!$this->batch_send) {
             //Send the message
             $this->result = $this->_mailer->send($this->message);
         } else {
             $this->result = $this->_mailer->batchSend($this->message);
         }
     } catch (Exception $e) {
         return false;
         if (self::$debug) {
             throw new JsonApiApplication_Exception('Server is not responding');
         } else {
             return false;
         }
     }
     $this->after();
     return $this->result;
 }
 /**
  * onClose($clientId) closing a connection to the server
  * @param int $clientId connect identifier
  * @access public
  */
 public function onClose($clientId)
 {
     // get client ip
     $ip = long2ip($this->_server->clients[$clientId][6]);
     // send a user left notice to everyone in the room
     foreach ($this->_server->clients as $id => $client) {
         $this->_server->send($id, "User {$clientId} ({$ip}) has left the room.");
     }
 }
Example #9
0
 /**
  * Default expand method
  *
  * All of the URL shortening services, for the most part, do a 301 redirect
  * using the Location header. Rather than implement this over and over we
  * provide it here and assume others who need non-normal expansion will
  * override this method.
  *
  * @param string $url The URL to expand
  *
  * @throws Services_ShortURL_Exception_CouldNotExpand on non-300's.
  * @return string $url The expanded URL
  */
 public function expand($url)
 {
     $this->req->setUrl($url);
     $this->req->setMethod('GET');
     $result = $this->req->send();
     if (intval(substr($result->getStatus(), 0, 1)) != 3) {
         throw new Services_ShortURL_Exception_CouldNotExpand('Non-300 code returned', $result->getStatus());
     }
     return trim($result->getHeader('Location'));
 }
Example #10
0
 /**
  * send off the request to Shopify, encoding the data as JSON
  *
  * @param  string $method
  * @param  string $page
  * @param  array  $data
  *
  * @return array
  */
 private function makeRequest($method, $page, $data = [])
 {
     $r = $this->client->createRequest($method, $page, $data);
     if ($data && $method != 'GET') {
         $r->setBody(json_encode($data), 'application/json');
     }
     if ($method == 'GET' && !empty($data)) {
         /*$query = $r->getQuery();
           foreach ($data as $key => $val) {
               $query->set($key, $val);
           }*/
     }
     try {
         $response = $this->client->send($r);
         return $response->json();
     } catch (ClientErrorResponseException $e) {
         return ['error' => $e->getMessage(), 'url' => $e->getRequest()->getUrl(), 'request' => $e->getRequest(), 'status' => $e->getResponse()->getStatusCode(), 'response' => $e->getResponse()];
     } catch (BadResponseException $e) {
         return ['error' => $e->getMessage(), 'url' => $e->getRequest()->getUrl(), 'request' => $e->getRequest(), 'status' => $e->getResponse()->getStatusCode(), 'response' => $e->getResponse()];
     }
 }
Example #11
0
 /**
  * Generic Post request
  * 
  * @param  [type] $resource [description]
  * @param  array  $params   [description]
  * @return [type]           [description]
  */
 private function _postRequest($resource, $params = array())
 {
     // init post request
     $request = $this->client->createRequest('POST', $this->url . DS . $resource);
     // set post fields
     foreach ($params as $key => $value) {
         $request->getQuery()->set($key, $value);
     }
     // add our auth header
     $request->addHeader('PRIVATE-TOKEN', $this->token);
     // send and return response
     $response = $this->client->send($request);
     return $response->json();
 }
Example #12
0
 /**
  * 运行指定API控制器的方法, 并统一处理响应结果
  *
  * @param object $api     API资源控制器对象
  * @param string $method  调用的请求方法
  * @param array  $params  参数
  */
 public static function run($api, $method, $params = array())
 {
     /** @var \Itslove\Passport\Core\LogProvider $log */
     try {
         call_user_func_array(array($api, $method), $params);
         $api->send();
         $log = $api->log and $log['api_access']->info("资源请求成功, 客户端 {$_SERVER['REMOTE_ADDR']} 访问资源 {$_SERVER['REQUEST_URI']}");
     } catch (ResourceException $e) {
         $response = new Response();
         $response->setStatusCode($e->getCode(), $e->getMessage());
         switch ($e->getCode()) {
             case 404:
                 $response->setContent('这个资源不存在');
                 $log = $api->log and $log['api_error']->warning("资源请求失败, 客户端 {$_SERVER['REMOTE_ADDR']} 访问资源 {$_SERVER['REQUEST_URI']}: 资源不存在");
                 break;
             case 409:
                 $response->setContent('条件判断失败');
                 $log = $api->log and $log['api_error']->warning("资源请求失败, 客户端 {$_SERVER['REMOTE_ADDR']} 访问资源 {$_SERVER['REQUEST_URI']}: 资源不存在");
                 break;
             case 500:
                 $response->setContent('服务器错误');
                 $log = $api->log and $log['api_error']->error("资源请求失败, 客户端 {$_SERVER['REMOTE_ADDR']} 访问资源 {$_SERVER['REQUEST_URI']}: 服务器错误");
                 break;
             default:
                 $response->setContent('未知错误');
                 $log = $api->log and $log['api_error']->error("资源请求失败, 客户端 {$_SERVER['REMOTE_ADDR']} 访问资源 {$_SERVER['REQUEST_URI']}: 未知错误");
                 break;
         }
         $response->send();
     } catch (ValidationException $e) {
         $response = new Response();
         $response->setStatusCode(409, 'Conflict');
         $response->setContent('提供的数据格式未通过校验');
         $response->send();
         $log = $api->log and $log['api_error']->warning("资源请求失败, 客户端 {$_SERVER['REMOTE_ADDR']} 访问资源 {$_SERVER['REQUEST_URI']}: 提供的数据格式未通过校验");
     } catch (RuntimeException $e) {
         $response = new Response();
         $response->setStatusCode(500, 'Internal Server Error');
         $response->setContent('服务器错误');
         $response->send();
         $log = $api->log and $log['api_error']->error("资源请求失败, 客户端 {$_SERVER['REMOTE_ADDR']} 访问资源 {$_SERVER['REQUEST_URI']}: 服务器异常");
     } catch (Exception $e) {
         $response = new Response();
         $response->setStatusCode(500, 'Internal Server Error');
         $response->setContent('服务器错误');
         $response->send();
         $log = $api->log and $log['api_error']->error("资源请求失败, 客户端 {$_SERVER['REMOTE_ADDR']} 访问资源 {$_SERVER['REQUEST_URI']}: 服务器异常");
     }
 }
 /**
  * Sends a new random password to a user
  *
  * @param object $user        The user object to send to.
  * @param string $newPassword The raw new password (use user->generateRandomPassword()).
  *
  * @return integer Returns number of sent mails (1 or 0)
  */
 public static function sendNewPasswordMail($user, $newPassword)
 {
     if (self::$_me === null) {
         self::$_me = new self();
     }
     $substituteEntities = array('newPassword' => $newPassword);
     self::$_me->set('subject', Texter::get('newPasswordMail|subject'));
     self::$_me->set('to', $user->get('mail'));
     self::$_me->set('body', self::$_me->processHTMLTemplate('newPassword.mail', $substituteEntities), 'text/html');
     self::$_me->send();
     if (self::$_me->result == 1) {
         Logging::log(101, $user);
     }
     return self::$_me->result;
 }
Example #14
0
 /**
  * Authenticate
  *
  * @param  string Username
  * @param  string Password
  * @return bool   true on success, false on reject
  */
 function fetchData($username, $password, $challenge = null)
 {
     $this->log('Auth_Container_RADIUS::fetchData() called.', AUTH_LOG_DEBUG);
     switch ($this->authtype) {
         case 'CHAP_MD5':
         case 'MSCHAPv1':
             if (isset($challenge)) {
                 $this->radius->challenge = $challenge;
                 $this->radius->chapid = 1;
                 $this->radius->response = pack('H*', $password);
             } else {
                 require_once 'Crypt/CHAP.php';
                 $classname = 'Crypt_' . $this->authtype;
                 $crpt = new $classname();
                 $crpt->password = $password;
                 $this->radius->challenge = $crpt->challenge;
                 $this->radius->chapid = $crpt->chapid;
                 $this->radius->response = $crpt->challengeResponse();
             }
             break;
         case 'MSCHAPv2':
             require_once 'Crypt/CHAP.php';
             $crpt = new Crypt_MSCHAPv2();
             $crpt->username = $username;
             $crpt->password = $password;
             $this->radius->challenge = $crpt->authChallenge;
             $this->radius->peerChallenge = $crpt->peerChallenge;
             $this->radius->chapid = $crpt->chapid;
             $this->radius->response = $crpt->challengeResponse();
             break;
         default:
             $this->radius->password = $password;
             break;
     }
     $this->radius->username = $username;
     $this->radius->putAuthAttributes();
     $result = $this->radius->send();
     if (PEAR::isError($result)) {
         return false;
     }
     $this->radius->getAttributes();
     //      just for debugging
     //      $this->radius->dumpAttributes();
     return $result;
 }
Example #15
0
		/**
		 * Send request to server
		 *
		 * @access private
		 * @param string $command Commend
		 * @param object $params PEAR Params object
		 */
		private function Request($command, $params, $ignorerewrite = false)
		{
			$msg = new XML_RPC_Message($command, $params);
			
			$cache = $this->CacheGet($msg->serialize(), $ignorerewrite);
			if (!$cache)
			{	
				$this->RPClient->setDebug(0);
				$response = $this->RPClient->send($msg);
				
				if (!$response || !$response->faultCode()) 
				{
					try
					{
				    	$val = $response->value();
				    
				    	$retval = XML_RPC_decode($val);
				    	$this->CachePut($msg->serialize(), $retval);
				    }
					catch(Exception $e)
					{
						return false;
					}
					
				    return $retval;
				} 
				else 
				{
				    /*
				     * Display problems that have been gracefully cought and
				     * reported by the xmlrpc.php script
				     */			    
				    throw new Exception(_("RPC Fail")."(".$response->faultCode().") ".$response->faultString());
				}
			}
			else 
				return $cache;
		}
Example #16
0
 /**
  * Call API method
  *
  * @param string $name Name of the method to call
  * @param string $params Parameters for the method.
  * @return array The response from API method
  * @access public
  */
 function call_method($name, $params)
 {
     $this->errors = array();
     if (!$this->token) {
         $token_params = array(new xmlrpcval($this->account, 'string'), new xmlrpcval($this->password, 'string'));
         $xmlrpc_message = new xmlrpcmsg('get_token', $token_params);
         $xmlrpc_response = $this->xmlrpc_client->send($xmlrpc_message);
         $this->token = $this->validate_response($xmlrpc_response);
         unset($xmlrpc_message);
         unset($xmlrpc_response);
     }
     $params = array_merge(array($this->token), $params);
     foreach ($params as $param) {
         $xmlrpc_val[] = php_xmlrpc_encode($param);
     }
     $xmlrpc_message = new xmlrpcmsg($name, $xmlrpc_val);
     $xmlrpc_response = $this->xmlrpc_client->send($xmlrpc_message);
     $validate_response = $this->validate_response($xmlrpc_response);
     if (!$validate_response) {
         $this->errors['xmlrpc_message'] = $xmlrpc_message;
     }
     return $validate_response;
 }
Example #17
0
 /**
  * Send message back to client(s)
  *
  * @param mixed $data Data to send
  * @param mixed $recipient Set of clients to respond to
  * @return A_Socket_Message_Abstract
  */
 protected function _reply($data, $recipient)
 {
     if ($recipient == self::SENDER) {
         $this->client->send($data);
     } elseif ($recipient == self::ALL) {
         foreach ($this->clients as $client) {
             $client->send($data);
         }
     } elseif ($recipient == self::OTHERS) {
         foreach ($this->clients as $client) {
             if ($client != $this->client) {
                 $client->send($data);
             }
         }
     } elseif (is_callable($recipient)) {
         foreach ($this->clients as $client) {
             if (call_user_func($recipient, $client->getSession())) {
                 $client->send($data);
             }
         }
     }
     return $this;
 }
Example #18
0
 /**
  * Send mail from MailBody object
  *
  * @param object  MailBody object
  * @return mixed  True on success else pear error class
  *
  * @access public
  */
 function sendMail($mail)
 {
     $recipient = $mail->getRecipient();
     $hdrs = $mail->getHeaders();
     $body = $mail->getBody();
     if (empty($this->send_mail)) {
         $this->factorySendMail();
     }
     //echo $body;
     return $this->send_mail->send($recipient, $hdrs, $body);
 }
Example #19
0
 /**
  * Actually sends the request to the CSS Validator service
  *
  * @return bool TRUE if request was sent successfully, FALSE otherwise
  */
 protected function sendRequest()
 {
     try {
         return $this->request->send();
     } catch (Exception $e) {
         throw new Exception('Error sending request', null, $e);
     }
 }
Example #20
0
 /**
  * Sends XML-RPC Request
  *
  * @return	bool
  */
 public function send_request()
 {
     $this->message = new XML_RPC_Message($this->method, $this->data);
     $this->message->debug = $this->debug;
     if (!($this->result = $this->client->send($this->message)) or !is_object($this->result->val)) {
         $this->error = $this->result->errstr;
         return FALSE;
     }
     $this->response = $this->result->decode();
     return TRUE;
 }
Example #21
0
 /**
  * Send the mailing
  *
  * @param object $mailer        A Mail object to send the messages
  * @return void
  * @access public
  */
 function deliver(&$mailer)
 {
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $mailing =& new CRM_Mailing_BAO_Mailing();
     $mailing->id = $this->mailing_id;
     $mailing->find(true);
     $eq =& new CRM_Mailing_Event_BAO_Queue();
     $eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
     $emailTable = CRM_Core_BAO_Email::getTableName();
     $contactTable = CRM_Contact_BAO_Contact::getTableName();
     $edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
     $ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $query = "  SELECT      {$eqTable}.id,\n                                {$emailTable}.email as email,\n                                {$eqTable}.contact_id,\n                                {$eqTable}.hash\n                    FROM        {$eqTable}\n                    INNER JOIN  {$emailTable}\n                            ON  {$eqTable}.email_id = {$emailTable}.id\n                    LEFT JOIN   {$edTable}\n                            ON  {$eqTable}.id = {$edTable}.event_queue_id\n                    LEFT JOIN   {$ebTable}\n                            ON  {$eqTable}.id = {$ebTable}.event_queue_id\n                    WHERE       {$eqTable}.job_id = " . $this->id . "\n                        AND     {$edTable}.id IS null\n                        AND     {$ebTable}.id IS null";
     $eq->query($query);
     while ($eq->fetch()) {
         /* Compose the mailing */
         $recipient = null;
         $message = $mailing->compose($this->id, $eq->id, $eq->hash, $eq->contact_id, $eq->email, $recipient);
         /* Send the mailing */
         $body = $message->get();
         $headers = $message->headers();
         /* TODO: when we separate the content generator from the delivery
          * engine, maybe we should dump the messages into a table */
         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
         $result = $mailer->send($recipient, $headers, $body);
         CRM_Core_Error::setCallback();
         $params = array('event_queue_id' => $eq->id, 'job_id' => $this->id, 'hash' => $eq->hash);
         if (is_a($result, PEAR_Error)) {
             /* Register the bounce event */
             require_once 'CRM/Mailing/BAO/BouncePattern.php';
             require_once 'CRM/Mailing/Event/BAO/Bounce.php';
             $params = array_merge($params, CRM_Mailing_BAO_BouncePattern::match($result->getMessage()));
             CRM_Mailing_Event_BAO_Bounce::create($params);
         } else {
             /* Register the delivery event */
             CRM_Mailing_Event_BAO_Delivered::create($params);
         }
     }
 }
Example #22
0
 /**
  * Write the correct HTTP headers
  *
  * @param string $filename Name of the downloaded file
  */
 function send($filename) {
     $this->pear_excel_workbook->send($filename);
 }
Example #23
0
 /**
  * Send mail from MailBody object
  *
  * @param object  MailBody object
  * @return mixed  True on success else pear error class
  * @param  bool   $set_as_sent
  *
  * @access public
  */
 function sendMail($mail, $set_as_sent = true)
 {
     $recipient = $mail->getRecipient();
     $hdrs = $mail->getHeaders();
     $body = $mail->getBody();
     if (empty($this->send_mail)) {
         $this->factorySendMail();
     }
     $sent = $this->send_mail->send($recipient, $hdrs, $body);
     if ($sent and $set_as_sent) {
         $this->container->setAsSent($mail);
     }
     return $sent;
 }
Example #24
0
 /**
  * Render the application.
  *
  * Rendering is the process of pushing the document buffers into the template
  * placeholders, retrieving data from the document and pushing it into
  * the JResponse buffer.
  *
  * @return  void
  */
 public function render()
 {
     //global $_HUBZERO_API_START;
     //$this->response->setHeader('X-Runtime: ' . (microtime(true) - $_HUBZERO_API_START));
     $this->response->send();
 }
Example #25
0
 /**
  * Actually sends the request to the HTML Validator service
  *
  * @throws Services_W3C_HTMLValidator_Exception
  * 
  * @return bool true | false
  */
 protected function sendRequest()
 {
     try {
         return $this->request->send();
     } catch (Exception $e) {
         include_once 'Services/W3C/HTMLValidator/Exception.php';
         if (version_compare(phpversion(), '5.3.0', '>')) {
             throw new Services_W3C_HTMLValidator_Exception('Error sending request to the validator', $e);
         }
         // Rethrow
         throw $e;
     }
 }
Example #26
0
 /**
  * Send mail from MailBody object
  *
  * @param object  MailBody object
  * @return mixed  True on success else pear error class
  * @param  bool   $set_as_sent
  *
  * @access public
  */
 function sendMail($mail, $set_as_sent = true)
 {
     $recipient = $mail->getRecipient();
     if (empty($recipient)) {
         return new Mail_Queue_Error('Recipient cannot be empty.', MAILQUEUE_ERROR_NO_RECIPIENT);
     }
     $hdrs = $mail->getHeaders();
     $body = $mail->getBody();
     if (empty($this->send_mail)) {
         $this->factorySendMail();
     }
     if (PEAR::isError($this->send_mail)) {
         return $this->send_mail;
     }
     $sent = $this->send_mail->send($recipient, $hdrs, $body);
     if (!PEAR::isError($sent) && $sent && $set_as_sent) {
         $this->container->setAsSent($mail);
     }
     return $sent;
 }
Example #27
0
File: Mail.php Project: mwyatt/core
 /**
  * inline html then send out the mail
  * @return bool
  */
 public function send($message)
 {
     return $this->swiftMailer->send($message);
 }
Example #28
0
 /**
  * Get e-mail addresses from an array, string or unlimited number of arguments and send the e-mail
  *
  * Friendly name portions (e.g. Leo <*****@*****.**>) are allowed.
  * @param mixed
  * @return boolean
  */
 public function sendTo()
 {
     $arrRecipients = $this->compileRecipients(func_get_args());
     if (!count($arrRecipients)) {
         return false;
     }
     $this->objMessage->setTo($arrRecipients);
     $this->objMessage->setCharset($this->strCharset);
     $this->objMessage->setPriority($this->intPriority);
     // Default subject
     if (empty($this->strSubject)) {
         $this->strSubject = 'No subject';
     }
     $this->objMessage->setSubject($this->strSubject);
     // HTML e-mail
     if (!empty($this->strHtml)) {
         // Embed images
         if ($this->blnEmbedImages) {
             if (!strlen($this->strImageDir)) {
                 $this->strImageDir = TL_ROOT . '/';
             }
             $arrMatches = array();
             preg_match_all('/src="([^"]+\\.(jpe?g|png|gif|bmp|tiff?|swf))"/Ui', $this->strHtml, $arrMatches);
             $strBase = Environment::getInstance()->base;
             // Check for internal images
             foreach (array_unique($arrMatches[1]) as $url) {
                 // Try to remove the base URL
                 $src = str_replace($strBase, '', $url);
                 // Embed the image if the URL is now relative
                 if (!preg_match('@^https?://@', $src) && file_exists($this->strImageDir . $src)) {
                     $cid = $this->objMessage->embed(Swift_EmbeddedFile::fromPath($this->strImageDir . $src));
                     $this->strHtml = str_replace('src="' . $url . '"', 'src="' . $cid . '"', $this->strHtml);
                 }
             }
         }
         $this->objMessage->setBody($this->strHtml, 'text/html');
     }
     // Text content
     if (!empty($this->strText)) {
         if (!empty($this->strHtml)) {
             $this->objMessage->addPart($this->strText, 'text/plain');
         } else {
             $this->objMessage->setBody($this->strText, 'text/plain');
         }
     }
     // Add the administrator e-mail as default sender
     if ($this->strSender == '') {
         list($this->strSenderName, $this->strSender) = $this->splitFriendlyName($GLOBALS['TL_CONFIG']['adminEmail']);
     }
     // Sender
     if ($this->strSenderName != '') {
         $this->objMessage->setFrom(array($this->strSender => $this->strSenderName));
     } else {
         $this->objMessage->setFrom($this->strSender);
     }
     // Send e-mail
     $intSent = self::$objMailer->send($this->objMessage, $this->arrFailures);
     // Log failures
     if (!empty($this->arrFailures)) {
         log_message('E-mail address rejected: ' . implode(', ', $this->arrFailures), $this->strLogFile);
     }
     // Return if no e-mails have been sent
     if ($intSent < 1) {
         return false;
     }
     // Add log entry
     $strMessage = 'An e-mail has been sent to ' . implode(', ', array_keys($this->objMessage->getTo()));
     if (count($this->objMessage->getCc()) > 0) {
         $strMessage .= ', CC to ' . implode(', ', array_keys($this->objMessage->getCc()));
     }
     if (count($this->objMessage->getBcc()) > 0) {
         $strMessage .= ', BCC to ' . implode(', ', array_keys($this->objMessage->getBcc()));
     }
     log_message($strMessage, $this->strLogFile);
     return true;
 }
Example #29
0
File: Queue.php Project: roojs/pear
 /**
  * Send mail from {@link Mail_Queue_Body} object
  *
  * @param object  Mail_Queue_Body object
  * @return mixed  True on success else pear error class
  * @param  bool   $set_as_sent
  *
  * @access public
  * @see    self::sendMailById()
  */
 function sendMail($mail, $set_as_sent = true)
 {
     if (!is_a($mail, 'Mail_Queue_Body')) {
         if (is_a($mail, 'Mail_Queue_Error')) {
             return $mail;
         }
         return Mail_Queue_Error("Unknown object/type: " . get_class($mail), MAILQUEUE_ERROR_UNEXPECTED);
     }
     $recipient = $mail->getRecipient();
     if (empty($recipient)) {
         return new Mail_Queue_Error('Recipient cannot be empty.', MAILQUEUE_ERROR_NO_RECIPIENT);
     }
     $hdrs = $mail->getHeaders();
     $body = $mail->getBody();
     if (empty($this->send_mail)) {
         $this->factorySendMail();
     }
     if (PEAR::isError($this->send_mail)) {
         return $this->send_mail;
     }
     //print_r($hdrs);exit;
     $sent = $this->send_mail->send($recipient, $hdrs, $body);
     if (!PEAR::isError($sent) && $sent && $set_as_sent) {
         $this->container->setAsSent($mail);
     }
     if (isset($this->send_mail->queued_as)) {
         $this->queued_as = $this->send_mail->queued_as;
     }
     if (isset($this->send_mail->greeting)) {
         $this->greeting = $this->send_mail->greeting;
     }
     return $sent;
 }
Example #30
0
 /**
  * Method to send out the email.
  * Checks: 
  * 		(message || to) === null -> return false;
  * 		(sFromName || sFromEmail) === null -> getParam(core.
  * 		(Notification) assumes to is an array of integers, otherwise return false
  *
  * @example Phpfox::getLib('mail')->to('*****@*****.**')->subject('Test Subject')->message('This is a test message')->send();
  * @example Phpfox::getLib('mail')->to(array('*****@*****.**', '*****@*****.**', '*****@*****.**')->subject('Test Subject')->message('This is a test message')->send()
  * @return boolean
  */
 public function send($bDoCheck = false)
 {
     if (defined('PHPFOX_SKIP_MAIL')) {
         return true;
     }
     // turn into an array
     if (!is_array($this->_mTo)) {
         $this->_mTo = array($this->_mTo);
     }
     // check if the mail(s) are valid
     if ($bDoCheck && $this->checkEmail($this->_mTo) == false) {
         return false;
     }
     if ($this->_aMessage === null || $this->_mTo === null) {
         return false;
     }
     if ($this->_sFromName === null) {
         $this->_sFromName = Phpfox::getParam('core.mail_from_name');
     }
     if ($this->_sFromEmail === null) {
         $this->_sFromEmail = Phpfox::getParam('core.email_from_email');
     }
     $this->_sFromName = html_entity_decode($this->_sFromName, null, 'UTF-8');
     $sIds = '';
     $sEmails = '';
     if (!empty($this->_aUsers)) {
         foreach ($this->_aUsers as $aUser) {
             if (isset($aUser['user_id']) && !empty($aUser['user_id'])) {
                 $sIds .= (int) $aUser['user_id'] . ',';
             }
         }
     } else {
         foreach ($this->_mTo as $mTo) {
             if (strpos($mTo, '@')) {
                 $sEmails .= $mTo . ',';
             } else {
                 $sIds .= (int) $mTo . ',';
             }
         }
     }
     $sIds = rtrim($sIds, ',');
     $sEmails = rtrim($sEmails, ',');
     $bIsSent = true;
     if (!empty($sIds)) {
         if ($this->_sNotification !== null) {
             Phpfox::getLib('database')->select('un.user_notification, ')->leftJoin(Phpfox::getT('user_notification'), 'un', "un.user_id = u.user_id AND un.user_notification = '" . Phpfox::getLib('database')->escape($this->_sNotification) . "'");
         }
         ($sPlugin = Phpfox_Plugin::get('mail_send_query')) ? eval($sPlugin) : false;
         if ($this->_aUsers === null) {
             $aUsers = Phpfox::getLib('database')->select('u.user_id, u.email, u.language_id, u.full_name, u.user_group_id')->from(Phpfox::getT('user'), 'u')->where('u.user_id IN(' . $sIds . ')')->execute('getSlaveRows');
         } else {
             $aUsers = $this->_aUsers;
         }
         if (!empty($aUsers) && count($aUsers) > 0) {
             foreach ($aUsers as $aUser) {
                 // User is banned, lets not send them any emails
                 if (isset($aUser['user_group_id']) && Phpfox::getService('user.group.setting')->getGroupParam($aUser['user_group_id'], 'core.user_is_banned')) {
                     continue;
                 }
                 // Lets not send out an email to myself
                 if ($this->_bSendToSelf === false && $aUser['user_id'] == Phpfox::getUserId()) {
                     continue;
                 }
                 $bCanSend = true;
                 if ($this->_sNotification !== null && $aUser['user_notification']) {
                     $bCanSend = false;
                 }
                 if ($bCanSend === true) {
                     // load the messages in their language
                     $aUser['language_id'] = $aUser['language_id'] == null || empty($aUser['language_id']) ? Phpfox::getParam('core.default_lang_id') : $aUser['language_id'];
                     if (is_array($this->_aMessage)) {
                         $sMessage = Phpfox::getPhrase($this->_aMessage[0], isset($this->_aMessage[1]) ? array_merge($aUser, $this->_aMessage[1]) : $aUser, false, null, $aUser['language_id']);
                     } else {
                         $sMessage = Phpfox::getLib('locale')->getPhraseHistory($this->_aMessage, $aUser['language_id']);
                     }
                     if (is_array($this->_aMessagePlain)) {
                         $sMessagePlain = Phpfox::getPhrase($this->_aMessagePlain[0], isset($this->_aMessagePlain[1]) ? array_merge($aUser, $this->_aMessagePlain[1]) : $aUser, false, null, $aUser['language_id']);
                     } else {
                         $sMessagePlain = Phpfox::getLib('locale')->getPhraseHistory($this->_aMessagePlain, $aUser['language_id']);
                     }
                     $sMessage = preg_replace('/' . preg_quote(Phpfox::getLib('url')->makeUrl(''), '/') . '/is', str_replace('mobile/', '', Phpfox::getLib('url')->makeUrl('')), $sMessage);
                     $sMessagePlain = preg_replace('/' . preg_quote(Phpfox::getLib('url')->makeUrl(''), '/') . '/is', str_replace('mobile/', '', Phpfox::getLib('url')->makeUrl('')), $sMessagePlain);
                     if (is_array($this->_aSubject)) {
                         $sSubject = Phpfox::getPhrase($this->_aSubject[0], isset($this->_aSubject[1]) ? array_merge($aUser, $this->_aSubject[1]) : $aUser, false, null, $aUser['language_id']);
                     } else {
                         $sSubject = Phpfox::getLib('locale')->getPhraseHistory($this->_aSubject, $aUser['language_id']);
                     }
                     $sMessage = preg_replace('/\\{setting var=\'(.*)\'\\}/ise', "'' . Phpfox::getParam('\\1') . ''", $sMessage);
                     $sMessage = preg_replace('/\\{phrase var=\'(.*)\'\\}/ise', "'' . Phpfox::getPhrase('\\1',{$this->_sArray}, false, null, '" . $aUser['language_id'] . "') . ''", $sMessage);
                     $sMessagePlain = preg_replace('/\\{phrase var=\'(.*)\'\\}/ise', "'' . Phpfox::getPhrase('\\1',{$this->_sArray}, false, null, '" . $aUser['language_id'] . "') . ''", $sMessagePlain);
                     $sMessagePlain = preg_replace('/\\{setting var=\'(.*)\'\\}/ise', "'' . Phpfox::getParam('\\1') . ''", $sMessagePlain);
                     $sSubject = preg_replace('/\\{setting var=\'(.*)\'\\}/ise', "'' . Phpfox::getParam('\\1') . ''", $sSubject);
                     $sSubject = preg_replace('/\\{phrase var=\'(.*)\'\\}/ise', "'' . Phpfox::getPhrase('\\1',{$this->_sArray}, false, null, '" . $aUser['language_id'] . "') . ''", $sSubject);
                     $sSubject = html_entity_decode($sSubject, null, 'UTF-8');
                     // http://www.phpfox.com/tracker/view/10392/
                     $sSubject = str_replace(array('&#039;', '&#0039;'), "'", $sSubject);
                     // http://www.phpfox.com/tracker/view/15051/
                     $sEmailSig = preg_replace('/\\{phrase var=\'(.*)\'\\}/ise', "'' . Phpfox::getPhrase('\\1',{$this->_sArray}, false, null, '" . $aUser['language_id'] . "') . ''", Phpfox::getParam('core.mail_signature'));
                     // Load plain text template
                     $sTextPlain = Phpfox::getLib('template')->assign(array('sName' => $aUser['full_name'], 'bHtml' => false, 'sMessage' => $this->_aMessagePlain !== null ? $sMessagePlain : $sMessage, 'sEmailSig' => $sEmailSig, 'bMessageHeader' => $this->_bMessageHeader, 'sMessageHello' => Phpfox::getPhrase('core.hello_name', array('name' => $aUser['full_name']), false, null, $aUser['language_id'])))->getLayout('email', true);
                     // Load HTML text template
                     $sTextHtml = Phpfox::getLib('template')->assign(array('sName' => $aUser['full_name'], 'bHtml' => true, 'sMessage' => str_replace("\n", "<br />", $sMessage), 'sEmailSig' => str_replace("\n", "<br />", $sEmailSig), 'bMessageHeader' => $this->_bMessageHeader, 'sMessageHello' => Phpfox::getPhrase('core.hello_name', array('name' => $aUser['full_name']), false, null, $aUser['language_id'])))->getLayout('email', true);
                     if (defined('PHPFOX_DEFAULT_OUT_EMAIL')) {
                         $aUser['email'] = PHPFOX_DEFAULT_OUT_EMAIL;
                     }
                     ($sPlugin = Phpfox_Plugin::get('mail_send_call')) ? eval($sPlugin) : false;
                     if (empty($aUser['email'])) {
                         continue;
                     }
                     if (!isset($bSkipMailSend)) {
                         $bIsSent = defined('PHPFOX_CACHE_MAIL') ? $this->_cache($aUser['email'], $sSubject, $sTextPlain, $sTextHtml, $this->_sFromName, $this->_sFromEmail) : $this->_oMail->send($aUser['email'], $sSubject, $sTextPlain, $sTextHtml, $this->_sFromName, $this->_sFromEmail);
                     }
                 }
             }
         }
     }
     if ($sPlugin = Phpfox_Plugin::get('mail_send_call_2')) {
         eval($sPlugin);
     }
     if (!empty($sEmails)) {
         $aEmails = explode(',', $sEmails);
         foreach ($aEmails as $sEmail) {
             $sEmail = trim($sEmail);
             if (is_array($this->_aMessage)) {
                 $sMessage = Phpfox::getPhrase($this->_aMessage[0], $this->_aMessage[1], false, null, Phpfox::getParam('core.default_lang_id'));
             } else {
                 $sMessage = $this->_aMessage;
             }
             if (is_array($this->_aMessagePlain)) {
                 $sMessagePlain = Phpfox::getPhrase($this->_aMessagePlain[0], $this->_aMessagePlain[1], false, null, Phpfox::getParam('core.default_lang_id'));
             } else {
                 $sMessagePlain = $this->_aMessagePlain;
             }
             if (is_array($this->_aSubject)) {
                 $sSubject = Phpfox::getPhrase($this->_aSubject[0], $this->_aSubject[1], false, null, Phpfox::getParam('core.default_lang_id'));
             } else {
                 $sSubject = $this->_aSubject;
             }
             $sEmailSig = preg_replace('/\\{phrase var=\'(.*)\'\\}/ise', "'' . Phpfox::getPhrase('\\1', {$this->_sArray}, false, null, '" . Phpfox::getParam('core.default_lang_id') . "') . ''", Phpfox::getParam('core.mail_signature'));
             $sMessagePlain = preg_replace('/\\{phrase var=\'(.*)\'\\}/ise', "'' . Phpfox::getPhrase('\\1', {$this->_sArray}, false, null, '" . Phpfox::getParam('core.default_lang_id') . "') . ''", $sMessagePlain);
             $sMessage = preg_replace('/\\{phrase var=\'(.*)\'\\}/ise', "'' . Phpfox::getPhrase('\\1', {$this->_sArray}, false, null, '" . Phpfox::getParam('core.default_lang_id') . "') . ''", $sMessage);
             $sSubject = preg_replace('/\\{phrase var=\'(.*)\'\\}/ise', "'' . Phpfox::getPhrase('\\1', {$this->_sArray}, false, null, '" . Phpfox::getParam('core.default_lang_id') . "') . ''", $sSubject);
             $sSubject = html_entity_decode($sSubject, null, 'UTF-8');
             // Load plain text template
             $sTextPlain = Phpfox::getLib('template')->assign(array('bHtml' => false, 'sMessage' => $this->_aMessagePlain !== null ? $sMessagePlain : $sMessage, 'sEmailSig' => $sEmailSig, 'bMessageHeader' => $this->_bMessageHeader))->getLayout('email', true);
             // Load HTML text template
             $sTextHtml = Phpfox::getLib('template')->assign(array('bHtml' => true, 'sMessage' => str_replace("\n", "<br />", $sMessage), 'sEmailSig' => str_replace("\n", "<br />", $sEmailSig), 'bMessageHeader' => $this->_bMessageHeader))->getLayout('email', true);
             if ($sPlugin = Phpfox_Plugin::get('mail_send_call_3')) {
                 eval($sPlugin);
             }
             if (empty($sEmail)) {
                 continue;
             }
             $bIsSent = defined('PHPFOX_CACHE_MAIL') ? $this->_cache($sEmail, $sSubject, $sTextPlain, $sTextHtml, $this->_sFromName, $this->_sFromEmail) : $this->_oMail->send($sEmail, $sSubject, $sTextPlain, $sTextHtml, $this->_sFromName, $this->_sFromEmail);
         }
     }
     $this->_aUsers = null;
     if ($sPlugin = Phpfox_Plugin::get('mail_send_call_4')) {
         eval($sPlugin);
     }
     return $bIsSent;
 }