Example #1
0
 /**
  * https://eu-west-1.console.aws.amazon.com/ses/home?region=eu-west-1#verified-senders-domain
  */
 function send(array $params = [], &$error_message = '')
 {
     require_php_lib('aws_sdk_v3');
     $error_message = null;
     try {
         $ses = Aws\Ses\SesClient::factory(['credentials' => new Aws\Credentials\Credentials($this->key, $this->secret), 'version' => 'latest', 'region' => $this->region]);
         $request = [];
         #			$request['Source'] = urlencode($params['name_from']).'<'.$params['email_from'].'>';
         $request['Source'] = $params['email_from'];
         $request['Destination']['ToAddresses'] = [urlencode($params['name_to']) . ' <' . $params['email_to'] . '>'];
         #			$request['Destination']['ToAddresses'] = [$params['email_to']];
         $request['Message']['Subject']['Data'] = $params['subject'];
         $request['Message']['Body']['Text']['Data'] = $params['text'];
         $request['Message']['Body']['Html']['Data'] = $params['html'];
         # TODO			'attachment'
         $result = $ses->sendEmail($request);
         $msg_id = $result->get('MessageId');
     } catch (Exception $e) {
         $error_message = 'SES error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
     }
     if (@$error_message && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) {
         trigger_error($error_message, E_USER_WARNING);
     }
     if (is_callable($params['on_after_send'])) {
         $callback = $params['on_after_send'];
         $callback($mail, $params, $result, $error_message, $this->PARENT);
     }
     $this->PARENT->_last_error_message = $error_message;
     return $result && !$error_message ? true : false;
 }
 /**
  */
 public function apply($in, $params = [])
 {
     require_php_lib('jsqueeze');
     !isset($params['single_line']) && ($params['single_line'] = true);
     !isset($params['keep_important_comments']) && ($params['keep_important_comments'] = true);
     !isset($params['special_var_rx']) && ($params['special_var_rx'] = \JSqueeze::SPECIAL_VAR_RX);
     $parser = new \JSqueeze();
     return $parser->squeeze($in, $params['single_line'], $params['keep_important_comments'], $params['special_var_rx']);
 }
 /**
  */
 public function apply($in, $params = [])
 {
     require_php_lib('cssmin');
     if (!class_exists('\\CssMin')) {
         throw new Exception('Assets: class \\CssMin not found');
         return $in;
     }
     return \CssMin::minify($in);
 }
 /**
  */
 public function apply($in, $params = [])
 {
     require_php_lib('jsminplus');
     if (!class_exists('\\JSMinPlus')) {
         throw new Exception('Assets: class \\JSMinPlus not found');
         return $in;
     }
     return \JSMinPlus::minify($in);
 }
Example #5
0
 /**
  */
 function _init()
 {
     require_php_lib('smarty');
     $smarty = new Smarty();
     $smarty->setTemplateDir(YF_PATH . tpl()->TPL_PATH);
     $smarty->setCompileDir(STORAGE_PATH . 'templates_c/');
     $smarty->setCacheDir(STORAGE_PATH . 'smarty_cache/');
     #		$smarty->setConfigDir(STORAGE_PATH.'smarty_configs/');
     $this->smarty = $smarty;
 }
Example #6
0
 /**
  */
 function connect($params = [])
 {
     if (!$this->_connection) {
         if ($params) {
             $this->conf($params);
         }
         require_php_lib('php_amqplib');
         $this->_connection = new \PhpAmqpLib\Connection\AMQPConnection($this->host, $this->port, $this->login, $this->pswd);
     }
     return $this->_connection;
 }
Example #7
0
 /**
  */
 function init()
 {
     if (!extension_loaded('mcrypt')) {
         $this->USE_MCRYPT = false;
     }
     if ($this->USE_MCRYPT == true) {
         $this->_mcrypt_cipher = constant('MCRYPT_' . $this->_avail_ciphers[$this->USE_CIPHER]);
     } else {
         /*if ($this->_cur_cipher_id !== $this->USE_CIPHER) {*/
         require_php_lib('phpcrypt');
         $cipher_id_to_name = [0 => PHP_Crypt\PHP_Crypt::CIPHER_CAST_128, 4 => PHP_Crypt\PHP_Crypt::CIPHER_CAST_256];
         $this->_cur_cipher = new PHP_Crypt\PHP_Crypt($this->_secret_key, $cipher_id_to_name[$this->USE_CIPHER], PHP_Crypt\PHP_Crypt::MODE_CBC);
     }
 }
Example #8
0
 /**
  * Framework constructor
  */
 function _init()
 {
     if (!$this->DRIVER) {
         $this->DRIVER = 'phpseclib';
     }
     if ($this->DRIVER == 'phpseclib') {
         require_php_lib('phpseclib');
     }
     if ($this->DRIVER == 'phpseclib' && !class_exists('Net_SSH2')) {
         trigger_error('phpseclib Net_SSH2 not found', E_USER_WARNING);
         return false;
     } elseif ($this->DRIVER == 'pecl_ssh2' && !function_exists('ssh2_connect')) {
         trigger_error('function ssh2_connect does not exist', E_USER_WARNING);
         return false;
     } else {
         $this->_INIT_OK = true;
     }
 }
Example #9
0
 /**
  */
 function connect($params = [])
 {
     if ($this->_connection) {
         return $this->_connection;
     }
     $this->host = $this->_get_conf('REDIS_HOST', '127.0.0.1', $params);
     $this->port = (int) $this->_get_conf('REDIS_PORT', '6379', $params);
     $this->prefix = $this->_get_conf('REDIS_PREFIX', '', $params);
     $this->prefix = $this->prefix ? $this->prefix . ':' : '';
     $redis = null;
     if ($this->driver == 'phpredis') {
         $redis = new Redis();
         $redis->connect($this->host, (int) $this->port);
         $redis->setOption(Redis::OPT_PREFIX, $this->prefix);
     } elseif ($this->driver == 'predis') {
         require_php_lib('predis');
         $redis = new Predis\Client(['scheme' => 'tcp', 'host' => $this->host, 'port' => (int) $this->port]);
     }
     $this->_connection = $redis;
     return $this->_connection;
 }
Example #10
0
 /**
  * https://github.com/sendgrid/sendgrid-php/blob/master/examples/helpers/mail/example.php
  */
 function send(array $params = [], &$error_message = '')
 {
     require_php_lib('sendgrid');
     $error_message = null;
     try {
         $sg = new \SendGrid($this->key);
         $from = new SendGrid\Email($params['name_from'], $params['email_from']);
         $subject = $params['subject'];
         $to = new SendGrid\Email($params['name_to'], $params['email_to']);
         $text_content = new SendGrid\Content('text/plain', $params['text']);
         $mail = new SendGrid\Mail($from, $subject, $to, $text_content);
         $html_content = new SendGrid\Content('text/html', $params['html']);
         $mail->addContent($html_content);
         if ($params['reply_to']) {
             $reply_to = new SendGrid\ReplyTo($params['reply_to']);
             $mail->setReplyTo($reply_to);
         }
         if ($this->PARENT->ALLOW_ATTACHMENTS) {
             foreach ((array) $params['attaches'] as $name => $file) {
                 $attachment = new SendGrid\Attachment();
                 $attachment->setContent(file_get_contents($file));
                 $attachment->setFilename($name);
                 $mail->addAttachment($attachment);
             }
         }
         $response = $sg->client->mail()->send()->post($mail);
     } catch (Exception $e) {
         $error_message = 'A sendgrid error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
     }
     if (@$error_message && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) {
         trigger_error($error_message, E_USER_WARNING);
     }
     if (is_callable($params['on_after_send'])) {
         $callback = $params['on_after_send'];
         $callback($mail, $params, $result, $error_message, $this->PARENT);
     }
     $this->PARENT->_last_error_message = $error_message;
     return $response && !$error_message ? true : false;
 }
Example #11
0
 /**
  * https://documentation.mailgun.com/api-sending.html#examples
  */
 function send(array $params = [], &$error_message = '')
 {
     require_php_lib('mailgun');
     $error_message = null;
     try {
         $mg = new Mailgun\Mailgun($this->key);
         $opts = $this->PARENT->ALLOW_ATTACHMENTS ? ['attachment' => array_values($params['attaches'])] : [];
         // Now, compose and send your message.
         $result = $mg->sendMessage($this->domain, ['from' => $params['email_from'], 'to' => $params['email_to'], 'subject' => $params['subject'], 'text' => $params['text'], 'html' => $params['html']], $opts);
     } catch (Exception $e) {
         $error_message = 'A mailgun error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
     }
     if (@$error_message && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) {
         trigger_error($error_message, E_USER_WARNING);
     }
     if (is_callable($params['on_after_send'])) {
         $callback = $params['on_after_send'];
         $callback($mail, $params, $result, $error_message, $this->PARENT);
     }
     $this->PARENT->_last_error_message = $error_message;
     return $result && !$error_message ? true : false;
 }
 /**
  * https://github.com/mailin-api/mailin-api-php/tree/master/src/Sendinblue
  */
 function send(array $params = [], &$error_message = '')
 {
     require_php_lib('sendinblue');
     $error_message = null;
     try {
         $sb = new Sendinblue\Mailin('https://api.sendinblue.com/v2.0', $this->key);
         $data = ['to' => [$params['email_to'] => $params['name_to']], 'from' => [$params['email_from'], $params['name_from']], 'subject' => $params['subject'], 'text' => $params['text'], 'html' => $params['html']];
         $result = $sb->send_email($data);
         if ($result['code'] != 'success') {
             $error_message = $result['message'];
         }
     } catch (Exception $e) {
         $error_message = 'A sendinblue error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
     }
     if (@$error_message && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) {
         trigger_error($error_message, E_USER_WARNING);
     }
     if (is_callable($params['on_after_send'])) {
         $callback = $params['on_after_send'];
         $callback($mail, $params, $result, $error_message, $this->PARENT);
     }
     $this->PARENT->_last_error_message = $error_message;
     return $result && $result['code'] == 'success' && !$error_message ? true : false;
 }
Example #13
0
 function __construct()
 {
     #		$this->module_path = YF_PATH.'libs/php-diff/lib/';
     require_php_lib('php_diff');
     $this->diff_types = ['side_by_side' => 'SideBySide', 'inline' => 'Inline', 'unified' => 'Unified', 'context' => 'Context'];
 }
Example #14
0
 /**
  * Do get data from given feed
  */
 function _get_rss_feed_array($rss_url = '', $feed_ttl = 3600, $num_items = 15)
 {
     require_php_lib('yf_domit');
     // Prepare cache params
     if ($this->USE_ARRAY_CACHE) {
         $_url_hash = md5($rss_url);
         $_obj_cache_path = $this->AGGR_CACHE_PATH . 'array_' . $_url_hash;
     }
     // Check if we can use array cache instead of loading domit library
     if (!empty($_obj_cache_path) && @file_exists($_obj_cache_path) && @filemtime($_obj_cache_path) > time() - $feed_ttl) {
         return @unserialize(file_get_contents($_obj_cache_path));
     } else {
         $rssDoc = new xml_domit_rss_document($rss_url, $this->AGGR_CACHE_PATH);
     }
     $success = (bool) $rssDoc;
     // Stop here if no document parsed
     if (!$success) {
         return false;
     }
     $output = ['channel' => null, 'items' => null];
     $totalChannels = $rssDoc->getChannelCount();
     // special handling for feed encoding
     $this->_decode_func = $this->_feed_encoding($rssDoc);
     // Process only first channel
     $cur_channel =& $rssDoc->getChannel(0);
     if (empty($cur_channel)) {
         return false;
     }
     $cur_ch_image = $cur_channel->getImage();
     $_ch_image = [];
     if (is_object($cur_ch_image)) {
         $_ch_image = ['title' => $this->_decode_text($cur_ch_image->getTitle()), 'link' => $this->_decode_text($cur_ch_image->getLink()), 'url' => $this->_decode_text($cur_ch_image->getUrl()), 'width' => intval($cur_ch_image->getWidth())];
     }
     $output['channel'] = ['url' => $cur_channel->getLink(), 'title' => $this->_decode_text($cur_channel->getTitle()), 'desc' => $this->_decode_text($cur_channel->getDescription()), 'webmaster' => $this->_decode_text($cur_channel->getWebMaster()), 'image' => $_ch_image];
     // Get number of items
     $actual_items = $cur_channel->getItemCount();
     $total_items = $num_items > $actual_items ? $actual_items : $num_items;
     // Process items
     for ($j = 0; $j < $total_items; $j++) {
         $currItem = $cur_channel->getItem($j);
         $cur_enc = $currItem->getEnclosure();
         $_enclosure = [];
         if (is_object($cur_enc)) {
             $_enclosure = ['url' => $this->_decode_text($cur_enc->getUrl()), 'length' => intval($cur_enc->getLength()), 'type' => $this->_decode_text($cur_enc->getType())];
         }
         $output['items'][$j] = ['url' => $currItem->getLink(), 'title' => $this->_decode_text($currItem->getTitle()), 'text' => $this->_decode_text($currItem->getDescription()), 'pub_date' => $currItem->getPubDate(), 'author' => $this->_decode_text($currItem->getAuthor()), 'comments' => $this->_decode_text($currItem->getComments()), 'enclosure' => $_enclosure];
     }
     // Do cache array
     if ($this->USE_ARRAY_CACHE) {
         file_put_contents($_obj_cache_path, serialize($output));
     }
     return $output;
 }
 public function load__cashex_xml($options = null)
 {
     // import options
     is_array($options) && extract($options, EXTR_PREFIX_ALL | EXTR_REFS, '');
     // var
     $api = $this->api;
     $payment_api = $this->payment_api;
     // prepare request options
     $url = 'http://api.cashex.com.ua/XmlApi.ashx';
     $request_options = ['is_redirect' => true, 'is_response_raw' => true];
     @$_request_options && ($request_options = array_replace_recursive($request_options, $_request_options));
     $result = $api->_request($url, null, $request_options);
     list($status, $response) = $result;
     if (empty($status)) {
         return $result;
     }
     require_php_lib('sf_dom_crawler');
     $crawler = new \Symfony\Component\DomCrawler\Crawler($response);
     $table = $crawler->filter('element');
     $count = $table->count();
     if ($count < 1) {
         return null;
     }
     $currencies = $payment_api->currencies;
     $data = [];
     $table->each(function ($node, $i) use(&$currencies, &$data) {
         $currency_id = $node->filter('currency')->text();
         if (empty($currencies[$currency_id])) {
             return;
         }
         $buy = $node->filter('buy')->text();
         $sale = $node->filter('sale')->text();
         $data[] = ['from' => $currency_id, 'to' => 'UAH', 'from_value' => 1, 'to_value' => $buy];
         $data[] = ['from' => 'UAH', 'to' => $currency_id, 'from_value' => $sale, 'to_value' => 1];
     });
     return $data;
 }
 function _init()
 {
     require_php_lib('pheanstalk');
 }
Example #17
0
 /**
  * https://mandrillapp.com/api/docs/messages.php.html
  */
 function send(array $params = [], &$error_message = '')
 {
     require_php_lib('mandrill');
     try {
         $message = ['html' => $params['html'], 'text' => $params['text'], 'subject' => $params['subject'], 'from_email' => $params['email_from'], 'from_name' => $params['name_from'], 'headers' => ['Reply-To' => $params['reply_to'] ?: $params['from']]];
         if (is_array($params['email_to'])) {
             foreach ($params['email_to'] as $name => $email) {
                 $message['to'][] = ['email' => $email, 'name' => $name, 'type' => 'to'];
             }
         } else {
             $message['to'][] = ['email' => $params['email_to'], 'name' => $params['name_to'], 'type' => 'to'];
         }
         if ($this->PARENT->ALLOW_ATTACHMENTS) {
             foreach ((array) $params['attaches'] as $name => $file) {
                 $file_name = is_string($name) ? $name : '';
                 $message['attachments'][] = ['type' => mime_content_type($file), 'name' => $file_name, 'content' => file_get_contents($file)];
             }
         }
         $async = false;
         $mandrill = new Mandrill($this->key);
         // $ip_pool = 'Main Pool'; // Ip pool name to use for sending
         // $send_at = 'example send_at'; // Datetime
         $result = $mandrill->messages->send($message, $async = true, $params['mandrill_ip_pool'], $params['mandrill_send_at']);
         // Example response: $result = [
         //		[
         //			[email] => recipient.email@example.com
         //			[status] => sent
         //			[reject_reason] => hard-bounce
         //			[_id] => abc123abc123abc123abc123abc123
         //		]
         //	]
     } catch (Mandrill_Error $e) {
         $error_message = 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
     }
     if (@$error_message && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) {
         trigger_error($error_message, E_USER_WARNING);
     }
     if (is_callable($params['on_after_send'])) {
         $callback = $params['on_after_send'];
         $callback($mail, $params, $result, $error_message, $this->PARENT);
     }
     $this->PARENT->_last_error_message = $error_message;
     return $result ? $result['status'] == 'sent' : false;
 }
Example #18
0
 /**
  */
 public function get_coffee_content($params = [])
 {
     $out = [];
     $content = $this->get_content('coffee');
     if (empty($content)) {
         return [];
     }
     require_php_lib('coffeescript_php');
     foreach ((array) $content as $md5 => $v) {
         $v['content'] = \CoffeeScript\Compiler::compile($v['content'], ['header' => false]);
         $out[$md5] = $v;
     }
     return $out;
 }
Example #19
0
 /**
  */
 function is_mobile()
 {
     if (isset($this->_is_mobile)) {
         return $this->_is_mobile;
     }
     $this->_is_mobile = false;
     if (!$this->is_console()) {
         try {
             require_php_lib('mobile_detect');
             $detect = new Mobile_Detect([], strtolower($_SERVER['HTTP_USER_AGENT']));
             $this->_is_mobile = (bool) $detect->isMobile();
         } catch (Exception $e) {
         }
     }
     return $this->_is_mobile;
 }
Example #20
0
<?php

require_php_lib('jquery-file-upload');
#require_once( YF_PATH . 'libs/jquery-file-upload/server/php/UploadHandler.php' );
class yf_upload_handler extends UploadHandler
{
    protected $options_default = [];
    protected $url;
    public $image_width = 1920;
    public $image_height = 1080;
    public $image_types = ['jpg' => true, 'jpeg' => true, 'png' => true];
    function __construct($options = null)
    {
        parent::__construct(null, false, null);
        $this->options_default = $this->options;
    }
    function _init($options = null)
    {
        $this->reset($options);
    }
    protected function get_url($force = false)
    {
        if ($this->url && !$force) {
            return $this->url;
        }
        $base = $this->get_full_url();
        $object = input()->get('object');
        $action = input()->get('action');
        $uri_object = $object ? 'object=' . $object : '';
        $uri_action = $action ? 'action=' . $action : '';
        $uri_and = $uri_object && $uri_action ? '&' : '';
Example #21
0
 /**
  */
 public function _init()
 {
     require_php_lib('php_sql_parser');
     $this->parser = new \PHPSQLParser\PHPSQLParser();
 }
Example #22
0
 /**
  */
 function _css_to_inline_styles($html = '', $extra = [])
 {
     if (!strlen($html) || false === strpos($html, '<')) {
         return $html;
     }
     if (false === strpos($html, '<html') && false === strpos($html, '<body')) {
         $need_raw = true;
         $html = '<!DOCTYPE html><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta charset="utf-8"></head><body>' . $html . '</body></html>';
     }
     require_php_lib('css_to_inline_styles');
     $cti = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($html);
     $cti->setEncoding('UTF-8');
     $cti->setUseInlineStylesBlock();
     // $cti->setHTML($html);
     // $cti->setCSS($css);
     $result = $cti->convert();
     $result = preg_replace('~<style[^>]*?>.+?</style>~ims', '', $result);
     $result = preg_replace('~<script[^>]*?>.+?</script>~ims', '', $result);
     if ($need_raw) {
         preg_match('|<body.*>(.*)</body>|isU', $result, $matches);
         $result = $matches[1] ?: $result;
     }
     return $result;
 }
Example #23
0
    /**
     */
    function jade()
    {
        require_php_lib('jade_php');
        $raw = '
div
  address
  i
  strong
';
        $dumper = new \Everzet\Jade\Dumper\PHPDumper();
        $parser = new \Everzet\Jade\Parser(new \Everzet\Jade\Lexer\Lexer());
        $jade = new \Everzet\Jade\Jade($parser, $dumper);
        $out = $jade->render($raw);
        return 'JADE: <pre>' . _prepare_html($raw) . '</pre>' . PHP_EOL . '<br \\>HTML: <pre>' . _prepare_html($out) . '</pre>';
    }
 /**
  */
 function send(array $params = [], &$error_message = '')
 {
     require_php_lib('phpmailer');
     $mail = new PHPMailer(true);
     // defaults to using php 'mail()'
     try {
         $mail->CharSet = $params['charset'] ?: conf('charset') ?: $this->PARENT->DEFAULT_CHARSET ?: 'utf-8';
         $mail->From = $params['email_from'];
         $mail->FromName = $params['name_from'];
         if (DEBUG_MODE && $this->PARENT->MAIL_DEBUG) {
             $mail->SMTPDebug = 1;
             $mail->Debugoutput = $params['phpmailer_debug_output'] ?: 'error_log';
         }
         if (is_array($params['email_to'])) {
             list($name, $email) = each($params['email_to']);
             array_shift($params['email_to']);
             $mail->AddAddress($email, $name);
         } else {
             $mail->AddAddress($params['email_to'], $params['name_to']);
         }
         $mail->Subject = $params['subject'];
         if (empty($params['html'])) {
             $mail->Body = $params['text'];
         } else {
             $mail->IsHTML(true);
             $mail->Body = $params['html'];
             $mail->AltBody = $params['text'];
         }
         if ($this->PARENT->ALLOW_ATTACHMENTS) {
             foreach ((array) $params['attaches'] as $name => $file) {
                 $file_name = is_string($name) ? $name : '';
                 $mail->AddAttachment($file, $file_name);
             }
         }
         $smtp = $params['smtp'];
         if ($smtp['smtp_host']) {
             $mail->IsSMTP();
             $mail->Host = $smtp['smtp_host'];
             $mail->Port = $smtp['smtp_port'];
             $mail->SMTPAuth = $smtp['smtp_auth'];
             $mail->Username = $smtp['smtp_user_name'];
             $mail->Password = $smtp['smtp_password'];
             $mail->SMTPSecure = $smtp['smtp_secure'] ?: false;
         }
         if (is_callable($params['on_before_send'])) {
             $callback = $params['on_before_send'];
             $callback($mail, $params, $this->PARENT);
         }
         $result = $mail->Send();
         if (is_array($params['email_to']) && !empty($params['email_to'])) {
             foreach ($params['email_to'] as $name => $email) {
                 $mail->clearAddresses();
                 $mail->AddAddress($email, $name);
                 $r = $mail->Send();
                 $result = $result && $r;
             }
         }
     } catch (phpmailerException $e) {
         $error_message .= $e->errorMessage();
         // Pretty error messages from PHPMailer
     } catch (Exception $e) {
         $error_message .= $e->getMessage();
         // Boring error messages from anything else!
     }
     if (!$result) {
         $error_message .= $mail->ErrorInfo;
     }
     if (is_callable($params['on_after_send'])) {
         $callback = $params['on_after_send'];
         $callback($mail, $params, $result, $error_message, $this->PARENT);
     }
     if (@$error_message && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) {
         trigger_error($error_message, E_USER_WARNING);
     }
     $this->PARENT->_last_error_message = $error_message;
     return $result;
 }
Example #25
0
 /**
  */
 function _init()
 {
     require_php_lib('fenom');
     $this->fenom = Fenom::factory('.', '/tmp', Fenom::AUTO_ESCAPE);
     // TODO: fenom configuration
 }
Example #26
0
 /**
  */
 function _init()
 {
     require_php_lib('twig');
     $this->twig = new Twig_Environment(new Twig_Loader_String());
     // TODO: configure twig
 }