/**
  * Quick translated sending
  * 
  * @param string $translation_id
  * @param mixed $to recipient / guest / email
  * @param mixed ... additionnal translation variables
  */
 public static function quickSend($translation_id, $to)
 {
     // Get additionnal arguments
     $vars = array_slice(func_get_args(), 2);
     // Manage recipient if object given, get language if possible
     $lang = null;
     if (is_object($to)) {
         array_unshift($vars, $to);
         if ($to instanceof User) {
             $lang = $to->lang;
             $to = $to->email;
         }
         if ($to instanceof Recipient) {
             $lang = $to->transfer->lang;
         }
     }
     // Translate email and replace variables
     $tr = Lang::translateEmail($translation_id, $lang);
     if ($vars) {
         $tr = call_user_func_array(array($tr, 'replace'), $vars);
     }
     // Create email and send it right away
     $mail = new self($tr);
     $mail->to($to);
     $mail->send();
 }
Example #2
0
 /**
  * Processes update e-mails for all users
  */
 public static function processCron($controller)
 {
     // Detect the mailing interval we're in
     $interval = 0;
     if (Yii::$app->controller->action->id == 'hourly') {
         $interval = self::INTERVAL_HOURY;
     } elseif (Yii::$app->controller->action->id == 'daily') {
         $interval = self::INTERVAL_DAILY;
     } else {
         throw new \yii\console\Exception('Invalid mail update interval!');
     }
     // Get users
     $users = User::find()->distinct()->joinWith(['httpSessions', 'profile'])->where(['user.status' => User::STATUS_ENABLED]);
     $totalUsers = $users->count();
     $processed = 0;
     Console::startProgress($processed, $totalUsers, 'Sending update e-mails to users... ', false);
     $mailsSent = 0;
     foreach ($users->each() as $user) {
         $mailSender = new self();
         $mailSender->user = $user;
         $mailSender->interval = $interval;
         if ($mailSender->send()) {
             $mailsSent++;
         }
         Console::updateProgress(++$processed, $totalUsers);
     }
     Console::endProgress(true);
     $controller->stdout('done - ' . $mailsSent . ' email(s) sent.' . PHP_EOL, Console::FG_GREEN);
     // Switch back to system language
     self::switchLanguage();
 }
Example #3
0
 /**
  * Quick translated sending
  * 
  * @param string $translation_id
  * @param mixed ... additionnal translation variables
  */
 public static function quickSend($translation_id)
 {
     $vars = array_slice(func_get_args(), 1);
     $tr = Lang::translateEmail($translation_id);
     if ($vars) {
         $tr = call_user_func_array(array($tr, 'replace'), $vars);
     }
     $mail = new self($tr);
     $mail->send();
 }
Example #4
0
 /**
  * @param string $url
  * @param array $post
  * @param wfWAFHTTP $request
  * @return wfWAFHTTPResponse|bool
  * @throws wfWAFHTTPTransportException
  */
 public static function post($url, $post = array(), $request = null)
 {
     if (!$request) {
         $request = new self();
     }
     $request->setUrl($url);
     $request->setMethod('POST');
     $request->setBody($post);
     $request->setTransport(wfWAFHTTPTransport::getInstance());
     return $request->send();
 }
Example #5
0
 public static function validate(User $user)
 {
     $email = new self();
     $email->headers = "From: " . self::$from . "\r\n";
     $email->headers .= "MIME-Version: 1.0\r\n";
     $email->headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
     $email->to = $user->email;
     $email->subject = "AOD Division Tracker - Email verification";
     $email->message .= "<h1><strong>{$user->username}</strong>,</h1>";
     $email->message .= "<p>This email was used by someone with the IP {$_SERVER['REMOTE_ADDR']} to create an account on the AOD Division Tracker. Please verify that it was you by clicking the link provided below, or copy-paste the URL into your browser's address bar.</p>";
     $email->message .= "<p>http://aodwebhost.site.nfoservers.com/tracker/authenticate?id={$user->validation}\r\n\r\n</p>";
     $email->message .= "<p><small>If you believe you have received this email in error, or the account was not created by you, please let us know by sending an email to admin@aodwebhost.site.nfoservers.com</small></p>";
     $email->message .= "<p><small>PLEASE DO NOT REPLY TO THIS E-MAIL</small></p>";
     $email->send();
 }
Example #6
0
 /**
  * Launch the whole job
  *
  * @param $scenario
  *
  * @throws \Exception
  */
 public static function launch($scenario)
 {
     // add autoloader
     static::register();
     $scenario = __DIR__ . '/../scenario/' . $scenario;
     // check the given scenario
     if (is_readable($scenario)) {
         $scenario = json_decode(file_get_contents($scenario), true);
         if (!is_null($scenario) && static::isValid($scenario)) {
             try {
                 $scenario = new self($scenario);
                 $scenario->send();
             } catch (\Exception $e) {
                 throw $e;
             }
             exit;
         }
         throw new \Exception('invalid scenario.');
     }
     throw new \Exception('scenario not found.');
 }
Example #7
0
 public static function sendMail($mail, $servers = [], $mailingto = null)
 {
     $recipients = [];
     foreach (Mail::parseAddressList(($mailing = $mailingto !== null) ? $mailingto : "{$mail->to},{$mail->cc},{$mail->bcc}") as $address) {
         stripos($address[1], Mail::INTERNAL_HOST) === false and $recipients[strtolower("{$address['0']}@{$address['1']}")] = true;
     }
     if ($recipients) {
         if (!$servers) {
             throw new \Exception('SMTP: No servers available');
         }
         $recipients = array_keys($recipients);
         $rawmessage = $mail->createMessage($mailing ? 2 : 1);
         foreach ($servers as $server) {
             try {
                 list($host, $port, $security) = extractServer($server[0], 25);
                 $smtp = new self($host, $port, $security);
                 $server[1] == '' || $smtp->auth($server[1], $server[2]);
                 $smtp->send($mail->sender_email, $recipients, $rawmessage);
                 $smtp->close();
                 return;
             } catch (\Exception $e) {
                 $msg = "SMTP {$server['0']}: " . $e->getMessage();
             }
         }
         throw new \Exception($msg);
     }
 }
Example #8
0
 public function send($data = null)
 {
     if ($this->ready_state !== 1) {
         self::throw_error('Invalid state; Cannot send unopened request', E_RECOVERABLE_ERROR);
     }
     // Build the data string
     if (!is_string($data) && $data !== null) {
         if (is_array($data)) {
             $data_arr = '';
             foreach ($data as $name => $value) {
                 $data_arr[] = urlencode($name) . ' = ' . urlencode($value);
             }
             $data = implode('&', $data_arr);
         } else {
             self::throw_error('Invalid data parameter given; Expects string, array, or NULL', E_RECOVERABLE_ERROR);
         }
     }
     // Build the request
     $request = $this->method . ' ' . $this->url_info['path'] . ' HTTP/1.1' . CRLF;
     $request .= 'Host: ' . $this->url_info['host'] . CRLF;
     foreach ($this->headers as $name => $value) {
         $request .= $name . ': ' . $value . CRLF;
     }
     $request .= CRLF . $data;
     // Send the request
     $response = '';
     fputs($this->fh, $request);
     while (!feof($this->fh)) {
         $response .= fgets($this->fh, 128);
     }
     fclose($this->fh);
     // Seperate the response
     $response = explode(CRLF . CRLF, $response, 2);
     $headers = explode(CRLF, $response[0]);
     $this->response_body = $response[1];
     // Parse the response status
     $http = array_shift($headers);
     preg_match('/^HTTP\\/[0-9.]+ ([0-9]{3}) (.*)$/', $http, $match);
     $this->status = (int) $match[1];
     $this->status_text = $match[2];
     // Parse the headers
     $parsed_headers = array();
     foreach ($headers as $header) {
         $header = explode(': ', $header, 2);
         $parsed_headers[$header[0]] = $header[1];
     }
     $this->response_headers = $parsed_headers;
     // Check for a location header
     if (isset($this->response_headers['Location'])) {
         $location = $this->response_headers;
         $sub_request = new self();
         $sub_request->__is_redirect($this->redirect_stack);
         $sub_request->open($this->method, $location);
         if ($sub_request->error_code) {
             $this->error_code = $sub_request->error_code;
             return false;
         }
         foreach ($this->headers as $name => $value) {
             $sub_request->set_request_header($name, $value);
         }
         $sub_request->send($data);
         $this->response_text = $sub_request->response_text;
         $this->response_headers = $sub_request->get_all_response_headers();
         $this->status_code = $sub_request->status_code;
         $this->status_text = $sub_request->status_text;
     }
     // All done
     $this->ready_state = 4;
     return $this;
 }
Example #9
0
 public static function mail($to, $subject, $message)
 {
     $mail = new self($to, $subject, $message);
     $mail->send();
 }
 static function sendSMS($arr_numbers, $smscontent)
 {
     try {
         if (!is_array($arr_numbers)) {
             $arr_numbers = array($arr_numbers);
         }
         if (count($arr_numbers) == 0) {
             throw new Exception('Please specify Mobile Phone');
         }
         if (empty($smscontent)) {
             throw new Exception('Please specify SMS content');
         }
         $obj_SMS = new self(self::CONST_USERNAME, self::CONST_PASSWORD, self::CONST_SENDERID);
         foreach ($arr_numbers as $mobile_num) {
             $obj_SMS->appendMobileNum($mobile_num);
         }
         $obj_SMS->setMessage($smscontent);
         $ret_message = $obj_SMS->send();
         if (strstr($ret_message, 'MsgID') === false) {
             throw new Exception($ret_message);
         }
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
Example #11
0
 /**
  * Run a self test of the Zmsg class.
  *
  * @return boolean
  * @todo See if assert returns
  */
 public static function test()
 {
     $result = true;
     $context = new ZMQContext();
     $output = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
     $output->bind("inproc://zmsg_selftest");
     $input = new ZMQSocket($context, ZMQ::SOCKET_ROUTER);
     $input->connect("inproc://zmsg_selftest");
     //  Test send and receive of single-part message
     $zmsgo = new self($output);
     $zmsgo->body_set("Hello");
     $result &= assert($zmsgo->body() == "Hello");
     $zmsgo->send();
     $zmsgi = new self($input);
     $zmsgi->recv();
     $result &= assert($zmsgi->parts() == 2);
     $result &= assert($zmsgi->body() == "Hello");
     echo $zmsgi;
     //  Test send and receive of multi-part message
     $zmsgo = new self($output);
     $zmsgo->body_set("Hello");
     $zmsgo->wrap("address1", "");
     $zmsgo->wrap("address2");
     $result &= assert($zmsgo->parts() == 4);
     echo $zmsgo;
     $zmsgo->send();
     $zmsgi = new self($input);
     $zmsgi->recv();
     $result &= assert($zmsgi->parts() == 5);
     $zmsgi->unwrap();
     $result &= assert($zmsgi->unwrap() == "address2");
     $zmsgi->body_fmt("%s%s", 'W', "orld");
     $result &= assert($zmsgi->body() == "World");
     //  Pull off address 1, check that empty part was dropped
     $zmsgi->unwrap();
     $result &= assert($zmsgi->parts() == 1);
     //  Check that message body was correctly modified
     $part = $zmsgi->pop();
     $result &= assert($part == "World");
     $result &= assert($zmsgi->parts() == 0);
     // Test load and save
     $zmsg = new self();
     $zmsg->body_set("Hello");
     $zmsg->wrap("address1", "");
     $zmsg->wrap("address2");
     $result &= assert($zmsg->parts() == 4);
     $fh = fopen(sys_get_temp_dir() . "/zmsgtest.zmsg", 'w');
     $zmsg->save($fh);
     fclose($fh);
     $fh = fopen(sys_get_temp_dir() . "/zmsgtest.zmsg", 'r');
     $zmsg2 = new self();
     $zmsg2->load($fh);
     assert($zmsg2->last() == $zmsg->last());
     fclose($fh);
     $result &= assert($zmsg2->parts() == 4);
     echo $result ? "OK" : "FAIL", PHP_EOL;
     return $result;
 }
Example #12
0
 /**
  * Cron job to read mails from queue and send them out
  */
 public function cronMinute($item)
 {
     //! get real mailer backend ($core->mailer points to db queue backend)
     // @codeCoverageIgnoreStart
     if (empty(Core::$core->realmailer)) {
         Core::log('C', L('Real mailer backend not configured!'));
     }
     // @codeCoverageIgnoreEnd
     //! get items from database
     $lastId = 0;
     while ($row = DS::fetch('*', 'email_queue', 'id>?', '', 'id ASC', [$lastId])) {
         $email = new self($row['data']);
         $lastId = $row['id'];
         try {
             if (!$email->send(Core::$core->realmailer)) {
                 // @codeCoverageIgnoreStart
                 throw new \Exception('send() returned false');
             }
             DS::exec('DELETE FROM email_queue WHERE id=?;', [$row['id']]);
         } catch (\Exception $e) {
             Core::log('E', sprintf(L('Unable to send #%s from queue'), $row['id']) . ': ' . $e->getMessage());
         }
         // @codeCoverageIgnoreEnd
         sleep(1);
     }
 }
 public static function send_data()
 {
     global $DB, $CFG;
     $log = array();
     $me = new self();
     $curl = new curl();
     $courses;
     $users;
     $members;
     $permission_read = $DB->get_record('config', array('name' => 'atypaxreportscourseenable'));
     if ($permission_read->value == 1) {
         $xml_path = $DB->get_record('config', array('name' => 'atypaxreportscoursepath'));
         $xml = new SimpleXMLElement($me->prepare_path($xml_path->value, 'COFR'), NULL, TRUE);
         $categories = $me->prepare_xml($xml, "rootcategories");
         //print_r($categories);
         if (empty($categories['categories'])) {
             array_push($log, array('root_categories' => 'sin nuevas categorias de ciclo'));
         } else {
             array_push($log, array('root_categories' => $me->send($categories, "categorie", $curl)));
         }
         $categories = $me->prepare_xml($xml, "ciclocat");
         //print_r($categories);
         if (empty($categories['categories'])) {
             array_push($log, array('ciclo_categories' => 'sin nuevas categorias padre'));
         } else {
             array_push($log, array('ciclo_categories' => $me->send($categories, "categorie", $curl)));
         }
         $categories = $me->prepare_xml($xml, "categories");
         if (empty($categories['categories'])) {
             array_push($log, array('categories' => 'sin nuevas categorias'));
         } else {
             array_push($log, array('categories' => $me->send($categories, "categorie", $curl)));
         }
         //$temxml = new SimpleXMLElement($me->prepare_path($xml_path->value,'MEMB'), NULL, TRUE);
         $courses = $me->prepare_xml($xml, "course");
         if (empty($courses['courses'])) {
             array_push($log, array('courses' => 'sin cursos nuevos'));
         } else {
             array_push($log, array('courses' => $me->send($courses, "course", $curl)));
         }
         $xml = new SimpleXMLElement($me->prepare_path($xml_path->value, 'PRSN'), NULL, TRUE);
         $users = $me->prepare_xml($xml, "user");
         if (empty($users['users'])) {
             array_push($log, array('users' => 'sin usuarios nuevos'));
         } else {
             array_push($log, array('users' => $me->send($users, "user", $curl)));
         }
         $xml = new SimpleXMLElement($me->prepare_path($xml_path->value, 'MEMB'), NULL, TRUE);
         $members = $me->prepare_xml($xml, "member");
         if (empty($members)) {
             array_push($log, array('members' => 'Sin nuevas matriculas'));
         } else {
             foreach ($members as $member) {
                 if ($log['members'] == null) {
                     array_push($log, array('members' => $me->send($member, "member", $curl)));
                 } else {
                     $log['members'] = array_merge($log['members'], $me->send($member, "member", $curl));
                 }
             }
         }
     }
     return $log;
 }
Example #14
0
 public static function end(ResponseBuilder &$res)
 {
     $helper = new self();
     $helper->send($res);
     exit(0);
 }
Example #15
0
 public static function newSeries($serial, $series)
 {
     $users = FavoritesModel::model()->where("`video_id`='{$serial->id}'")->findAll();
     $to = "";
     if (!$users) {
         return False;
     }
     foreach ($users as $user) {
         $model = UsersModel::model()->where("`id`='{$user->user_id}'")->findRow();
         if ($model->email) {
             $to .= $model->email . ", ";
         }
     }
     $to = trim($to, ", ");
     $mail = new self();
     $mail->to = $to;
     $mail->nameTo = "Everybody";
     $mail->subject = "Новая серия " . $serial->en_name;
     $mail->text = $mail->loadTemplate("new_series", array("serial_name" => $serial->en_name, "href" => "http://" . $_SERVER['HTTP_HOST'] . "/serials/" . $serial->seo_url, "series_name" => $series->name));
     $mail->send();
 }
Example #16
0
 /**
  * Send a simple DELETE request 
  *
  * @param  string $url
  * @return Sopha_Http_Response
  */
 public static function delete($url)
 {
     $request = new self($url, self::DELETE);
     return $request->send();
 }
Example #17
0
 public static function TRANSACTION($type, $recipient, $message)
 {
     $instance = new self();
     $instance->send($recipient, $instance->transactions[$type], $message);
 }
Example #18
0
 /**
  * Makes a request to a specified URL and returns the response.
  *
  * @param  string $url The URL to which the request is to be sent.
  * @param  reference $success **OPTIONAL. OUTPUT.** After the method is called, the value of this parameter tells
  * whether the request was successful.
  * @param  int $timeoutSeconds **OPTIONAL. Default is** *no timeout*. The number of seconds after which the
  * request should time out.
  *
  * @return CUStringObject The response that was received for the request.
  */
 public static function read($url, &$success = null, $timeoutSeconds = null)
 {
     assert('is_cstring($url) && (!isset($timeoutSeconds) || is_int($timeoutSeconds))', vs(isset($this), get_defined_vars()));
     $inetRequest = new self($url);
     if (isset($timeoutSeconds)) {
         $inetRequest->setRequestTimeout($timeoutSeconds);
     }
     $content = $inetRequest->send($success);
     if (!$success) {
         $content = "";
     }
     return $content;
 }
Example #19
0
 public static function test()
 {
     $context = new ZMQContext();
     $output = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
     //$output->setSockOpt(ZMQ::SOCKOPT_IDENTITY,"identity");
     $output->bind("inproc://kvmsg_selftest");
     $input = new ZMQSocket($context, ZMQ::SOCKET_ROUTER);
     $input->connect("inproc://kvmsg_selftest");
     $kvmsg = new self(123);
     $kvmsg->set_key('key');
     //$kvmsg->set_sequence(1);
     $kvmsg->set_uuid();
     $kvmsg->set_prop("prop1", "value1");
     $kvmsg->set_body('body');
     $kvmsg->dump();
     $kvmsg->send($output);
     $kvmsg_2 = new self(2);
     $kvmsg_2->route_recv($input);
     $kvmsg_2->dump();
 }
 public static function send_data()
 {
     global $DB, $CFG;
     $log = array();
     $me = new self();
     $curl = new curl();
     $courses;
     $users;
     $members;
     $permission_read = $DB->get_record('config', array('name' => 'wspeoplesoftcourseenable'));
     if ($permission_read->value == 1) {
         $xml_path = $DB->get_record('config', array('name' => 'wspeoplesoftcoursepath'));
         $xml = new SimpleXMLElement($me->prepare_path($xml_path->value), NULL, TRUE);
         $categories = $me->prepare_xml($xml, "rootcategories");
         if (empty($categories['categories']) || empty($categories)) {
             array_push($log, array('root_categories' => 'sin nuevas categorias de ciclo'));
         } else {
             array_push($log, array('root_categories' => $me->send($categories, "categorie", $curl)));
         }
         $categories = $me->prepare_xml($xml, "ciclocat");
         if (empty($categories['categories']) || empty($categories)) {
             array_push($log, array('ciclo_categories' => 'sin nuevas categorias padre'));
         } else {
             array_push($log, array('ciclo_categories' => $me->send($categories, "categorie", $curl)));
         }
         $categories = $me->prepare_xml($xml, "categories");
         if (empty($categories['categories']) || empty($categories)) {
             array_push($log, array('categories' => 'sin nuevas categorias'));
         } else {
             array_push($log, array('categories' => $me->send($categories, "categorie", $curl)));
         }
         $courses = $me->prepare_xml($xml, "course");
         if (empty($courses['courses']) || empty($courses)) {
             array_push($log, array('courses' => 'sin cursos nuevos'));
         } else {
             array_push($log, array('courses' => $me->send($courses, "course", $curl)));
         }
     }
     $permission_read = $DB->get_record('config', array('name' => 'wspeoplesoftuserenable'));
     if ($permission_read->value == 1) {
         $xml_path = $DB->get_record('config', array('name' => 'wspeoplesoftuserpath'));
         $xml = new SimpleXMLElement($me->prepare_path($xml_path->value), NULL, TRUE);
         $users = $me->prepare_xml($xml, "user");
         if (empty($users['users']) || empty($users)) {
             array_push($log, array('users' => 'sin usuarios nuevos'));
         } else {
             array_push($log, array('users' => $me->send($users, "user", $curl)));
         }
     }
     $permission_read = $DB->get_record('config', array('name' => 'wspeoplesoftmemberenable'));
     if ($permission_read->value == 1) {
         $xml_path = $DB->get_record('config', array('name' => 'wspeoplesoftmemberpath'));
         $xml = new SimpleXMLElement($me->prepare_path($xml_path->value), NULL, TRUE);
         $members = $me->prepare_xml($xml, "member");
         if (empty($members['enrolments']) || empty($members)) {
             array_push($log, array('members' => 'Sin nuevas matriculas'));
         } else {
             array_push($log, array('members' => $me->send($members, "member", $curl)));
         }
     }
     return $log;
 }
Example #21
0
 /**
  * Static method to send all details to the API in one call
  *
  * @param ClientContract $client
  * @param ProductContract|null $product
  * @param AppointmentContract|null $appointment
  * @param $urn
  * @param $url
  * @param EncryptContract|null $encryptor
  * @return \Guzzle\Http\Message\Response
  */
 public static function request(ClientContract $client, ProductContract $product = null, AppointmentContract $appointment = null, $urn, $url, EncryptContract $encryptor = null)
 {
     $remote = new self($urn, $url, $encryptor);
     return $remote->send($client, $product, $appointment);
 }
Example #22
0
 static function sendAll()
 {
     $me = new self();
     return $me->send();
 }
Example #23
0
 static function wikiView()
 {
     $me = new self();
     $me->send();
 }
Example #24
0
File: Yo.php Project: edoceo/radix
 /**
 	Static Helper
 	@param $yoak Yo API Key
 	@param $user User to Yo to, Null for All
 	@param $link Optional Link
 */
 public static function yo($yoak, $user = null, $link = null)
 {
     $x = new self($yoak);
     return $x->send($user, $link);
 }
Example #25
0
 /**
  * Creates a JsonResponse instance and sends the output to the browser.
  * This is just a short hand method for creating a new JsonResponse instance and then calling the "send" method.
  *
  * @param string|array|ArrayObject $content Json content.
  * @param array                    $headers Headers to attach to the response.
  */
 public static function sendJson($content, $headers = [])
 {
     $response = new self($content, $headers);
     $response->send();
 }