Example #1
1
 public function renderContent($args, $setting)
 {
     $t = array('name' => '', 'image_folder_path' => '', 'limit' => 12, 'columns' => 4);
     $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
     $url = Tools::htmlentitiesutf8($protocol . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__);
     $setting = array_merge($t, $setting);
     $oimages = array();
     if ($setting['image_folder_path']) {
         $path = _PS_ROOT_DIR_ . '/' . trim($setting['image_folder_path']) . '/';
         $path = str_replace("//", "/", $path);
         if (is_dir($path)) {
             $images = glob($path . '*.*');
             $exts = array('jpg', 'gif', 'png');
             foreach ($images as $cnt => $image) {
                 $ext = Tools::substr($image, Tools::strlen($image) - 3, Tools::strlen($image));
                 if (in_array(Tools::strtolower($ext), $exts)) {
                     if ($cnt < (int) $setting['limit']) {
                         $i = str_replace("\\", "/", '' . $setting['image_folder_path'] . "/" . basename($image));
                         $i = str_replace("//", "/", $i);
                         $oimages[] = $url . $i;
                     }
                 }
             }
         }
     }
     $images = array();
     $setting['images'] = $oimages;
     $output = array('type' => 'image', 'data' => $setting);
     return $output;
 }
Example #2
0
 private function SendSocketHTTP()
 {
     // init infos
     if (self::__TM4B_SMS_HTTP_METHOD__ == "GET") {
         $script = self::__TM4B_SMS_HTTP_SERVICE__ . '?' . $this->_httpQS;
     } else {
         $script = self::__TM4B_SMS_HTTP_SERVICE__;
     }
     // Build HTTP Header
     $header = self::__TM4B_SMS_HTTP_METHOD__ . " " . $script . " HTTP/1.1\r\n";
     $header .= "Host: " . self::__TM4B_SMS_HTTP_HOST__ . "\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . Tools::strlen($this->_httpQS) . "\r\n";
     $header .= "Connection: close\r\n\r\n";
     $header .= $this->_httpQS . "\r\n";
     // Socket connection
     $socket = fsockopen(self::__TM4B_SMS_HTTP_HOST__, 80, $errno, $errstr);
     if ($socket) {
         fputs($socket, $header);
         // Send header
         while (!feof($socket)) {
             $response[] = fgets($socket);
             // Grab return codes
         }
         fclose($socket);
     } else {
         $response = false;
     }
     return $response;
 }
 protected function validate(YousticeShopRegistration $registration)
 {
     if (Tools::strlen(trim($registration->getCompanyName())) == 0) {
         return 'company_name_required';
     }
     if (Tools::strlen(trim($registration->getFirstName())) == 0) {
         return 'first_name_required';
     }
     if (Tools::strlen(trim($registration->getLastName())) == 0) {
         return 'last_name_required';
     }
     if (!filter_var($registration->getEmail(), FILTER_VALIDATE_EMAIL)) {
         return 'email_invalid';
     }
     if (!filter_var($registration->getShopUrl(), FILTER_VALIDATE_URL)) {
         return 'shop_url_invalid';
     }
     if (Tools::strlen($registration->getPassword()) < 6) {
         return 'password_less_than_6_characters';
     }
     if ($registration->getPassword() !== $registration->getVerifyPasswordValue()) {
         return 'passwords_do_not_match';
     }
     return true;
 }
 public function loadFromRawBytes($image = '')
 {
     if (Tools::strlen($image) > 0) {
         $this->image = $this->resize($image, 300, 300);
     }
     return $this;
 }
 private function curlConnection($method, $url, $timeout, $charset, array $data = null)
 {
     if (Tools::strtoupper($method) === 'POST') {
         $postFields = $data ? http_build_query($data, '', '&') : "";
         $contentLength = "Content-length: " . Tools::strlen($postFields);
         $methodOptions = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields);
     } else {
         $contentLength = null;
         $methodOptions = array(CURLOPT_HTTPGET => true);
     }
     $options = array(CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded; charset=" . $charset, $contentLength, 'lib-description: php:' . PagSeguroLibrary::getVersion(), 'language-engine-description: php:' . PagSeguroLibrary::getPHPVersion()), CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => $timeout);
     if (!is_null(PagSeguroLibrary::getModuleVersion())) {
         array_push($options[CURLOPT_HTTPHEADER], 'module-description: ' . PagSeguroLibrary::getModuleVersion());
     }
     if (!is_null(PagSeguroLibrary::getCMSVersion())) {
         array_push($options[CURLOPT_HTTPHEADER], 'cms-description: ' . PagSeguroLibrary::getCMSVersion());
     }
     $options = $options + $methodOptions;
     $curl = curl_init();
     curl_setopt_array($curl, $options);
     $resp = curl_exec($curl);
     $info = curl_getinfo($curl);
     $error = curl_errno($curl);
     $errorMessage = curl_error($curl);
     curl_close($curl);
     $this->setStatus((int) $info['http_code']);
     $this->setResponse((string) $resp);
     if ($error) {
         throw new Exception("CURL can't connect: {$errorMessage}");
     } else {
         return true;
     }
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     header('HTTP/1.1 404 Not Found');
     header('Status: 404 Not Found');
     if (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('png', 'jpg', 'gif'))) {
         $this->context->cookie->disallowWriting();
         if ((bool) Configuration::get('PS_REWRITING_SETTINGS')) {
             preg_match('#([0-9]+)(\\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/(.+)\\.(png|jpg|gif)$#', $_SERVER['REQUEST_URI'], $matches);
         }
         if ((!isset($matches[2]) || empty($matches[2])) && !(bool) Configuration::get('PS_REWRITING_SETTINGS')) {
             preg_match('#/([0-9]+)(\\-[_a-zA-Z]*)\\.(png|jpg|gif)$#', $_SERVER['REQUEST_URI'], $matches);
         }
         if (is_array($matches) && !empty($matches[2]) && Tools::strtolower(substr($matches[2], -8)) != '_default' && is_numeric($matches[1])) {
             $matches[2] = substr($matches[2], 1, Tools::strlen($matches[2])) . '_default';
             if (!isset($matches[4])) {
                 $matches[4] = '';
             }
             header('Location: ' . $this->context->link->getImageLink($matches[4], $matches[1], $matches[2]), true, 302);
             exit;
         }
         header('Content-Type: image/gif');
         readfile(_PS_IMG_DIR_ . '404.gif');
         exit;
     } elseif (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('.js', 'css'))) {
         $this->context->cookie->disallowWriting();
         exit;
     }
     parent::initContent();
     $this->setTemplate(_PS_THEME_DIR_ . '404.tpl');
 }
Example #7
0
 public function __construct()
 {
     $this->name = 'payplug';
     $this->tab = 'payments_gateways';
     $this->version = '1.0.1';
     $this->author = 'PayPlug';
     $this->module_key = '1ee28a8fb5e555e274bd8c2e1c45e31a';
     parent::__construct();
     // For 1.6
     $this->bootstrap = true;
     // Backward compatibility
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         require _PS_MODULE_DIR_ . $this->name . '/backward_compatibility/backward.php';
     }
     // Add warning if prestashop is an older version than 1.4
     if (version_compare(_PS_VERSION_, '1.4', '<')) {
         $this->warning = $this->l('Sorry Payplug is not compatible with Prestashop for versions < 1.4. Please delete the payplug directory in the Prestashop modules directory for your Prestashop system to get back to normal.');
     }
     $this->currencies = true;
     $this->currencies_mode = 'checkbox';
     // Change descriptionn and display name
     $this->displayName = $this->l('PayPlug – Simple and secure online payments');
     $this->description = $this->l('The simplest online payment solution: no setup fees, no fixed fees, and no merchant account required!');
     $this->confirmUninstall = $this->l('Are you sure you wish to uninstall this module and delete your settings?');
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         $cookie_admin = new Cookie('psAdmin', Tools::substr($_SERVER['PHP_SELF'], Tools::strlen(__PS_BASE_URI__), -10));
         if (Tools::getValue('tab') == 'AdminPayment' && Tools::getValue('token') != Tools::getAdminTokenLite('AdminPayment')) {
             // Force admin status
             $this->context->cookie->profile = $cookie_admin->profile;
             $url = 'index.php?tab=AdminPayment';
             $url .= '&token=' . Tools::getAdminTokenLite('AdminPayment');
             Tools::redirectAdmin($url);
         }
     }
 }
 /**
  * Validate is short
  *
  * @param string $str_data;
  * @return bool
  */
 public static function isShort($str_data)
 {
     if (Tools::strlen($str_data) < 6) {
         return true;
     }
     return false;
 }
 public function getFirstProductStatus()
 {
     if (isset($this->data['products']) && count($this->data['products'])) {
         $status = $this->data['products'][0]['status'];
         return Tools::strlen($status) ? $status : 'Problem reported';
     }
     return '';
 }
Example #10
0
 function psmFindSignature($content, $start_signature, $end_signature)
 {
     if (($start = strpos($content, $start_signature)) !== false && ($end = strpos($content, $end_signature, $start)) !== false) {
         $length = Tools::strlen($start_signature);
         return Tools::substr($content, $start + $length, $end - $start - $length);
     }
     return false;
 }
 public static function idRandomGenerator()
 {
     $str = 'abcdefghijkmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     for ($i = 0, $idGenerated = ''; $i < 5; $i++) {
         $idGenerated .= Tools::substr($str, mt_rand(0, Tools::strlen($str) - 1), 1);
     }
     return $idGenerated;
 }
Example #12
0
 public function init()
 {
     parent::init();
     if (Tools::isSubmit('storedelivery') && (int) Tools::getValue('storedelivery') != 0) {
         //Save cookie only if previous id_adress wasn't a store
         $cookie = new Cookie('storedelivery');
         $cookie->__set('id_address_delivery', $this->context->cart->id_address_delivery);
         $store = new Store(Tools::getValue('storedelivery'));
         //Test if store address exist in address table
         Tools::strlen($store->name) > 32 ? $storeName = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($storeName = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
         $sql = 'SELECT id_address FROM ' . _DB_PREFIX_ . 'address WHERE alias=\'' . addslashes($storeName) . '\' AND address1=\'' . addslashes($store->address1) . '\' AND address2=\'' . addslashes($store->address2) . '\' AND postcode=\'' . $store->postcode . '\' AND city=\'' . addslashes($store->city) . '\' AND id_country=\'' . addslashes($store->id_country) . '\' AND active=1 AND deleted=0';
         $id_address = Db::getInstance()->getValue($sql);
         //Create store adress if not exist for this user
         if (empty($id_address)) {
             $country = new Country($store->id_country, $this->context->language->id);
             $address = new Address();
             $address->id_country = $store->id_country;
             $address->id_state = $store->id_state;
             $address->country = $country->name;
             Tools::strlen($store->name) > 32 ? $address->alias = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->alias = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             Tools::strlen($store->name) > 32 ? $address->lastname = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->lastname = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             $address->firstname = " ";
             $address->address1 = $store->address1;
             $address->address2 = $store->address2;
             $address->postcode = $store->postcode;
             $address->city = $store->city;
             $address->phone = $store->phone;
             $address->deleted = 0;
             //create an address non deleted to register them in order
             $address->add();
             $id_address = $address->id;
         }
         //Update cart info
         $cart = $this->context->cart;
         $cart->id_address_delivery = $id_address;
         $cart->update();
         //Change address of all product in cart else we are redirect on step Carrier because of function autostep or OrderController
         Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $id_address), $where = 'id_cart = ' . $this->context->cart->id);
         //Change post carrier option else bad default carrier is saved by fonction processCarrier of ParentOrderController
         $array = array_values(Tools::getValue('delivery_option'));
         $_POST['delivery_option'] = array($id_address => $array[0]);
     } else {
         $cookie = new Cookie('storedelivery');
         $id_address_delivery = $cookie->__get('id_address_delivery');
         if ($id_address_delivery != false && $this->context->cart->id_address_delivery != $id_address_delivery && Tools::isSubmit('storedelivery')) {
             $this->context->cart->id_address_delivery = $cookie->__get('id_address_delivery');
             $this->context->cart->update();
             //Change address of all product in cart else we are redirect on step Carrier because of function autostep or OrderController
             Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $cookie->__get('id_address_delivery')), $where = 'id_cart = ' . $this->context->cart->id);
             //Change post carrier option else bad default carrier is saved by fonction processCarrier of ParentOrderController
             $array = array_values(Tools::getValue('delivery_option'));
             $_POST['delivery_option'] = array($cookie->__get('id_address_delivery') => $array[0]);
             $cookie->__unset('id_address_delivery');
         }
     }
 }
Example #13
0
function smartyTruncate($params, &$smarty)
{
    $text = isset($params['strip']) ? strip_tags($params['text']) : $params['text'];
    $length = $params['length'];
    $sep = isset($params['sep']) ? $params['sep'] : '...';
    if (Tools::strlen($text) > $length + Tools::strlen($sep)) {
        $text = substr($text, 0, $length) . $sep;
    }
    return isset($params['encode']) ? Tools::htmlentitiesUTF8($text, ENT_NOQUOTES) : $text;
}
Example #14
0
 public function randomImageName()
 {
     $length = 6;
     $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
     $rand = '';
     for ($i = 0; $i < $length; $i++) {
         $rand = $rand . $characters[mt_rand(0, Tools::strlen($characters) - 1)];
     }
     return $rand;
 }
Example #15
0
 /**
  * Make a request to the Syspay API
  * @param  Syspay_Merchant_Request $request The request to send to the API
  * @return mixed The response to the request
  * @throws Syspay_Merchant_RequestException If the request could not be processed by the API
  */
 public function request(Syspay_Merchant_Request $request)
 {
     $this->body = $this->headers = $this->data = null;
     $headers = array('Accept: application/json', 'X-Wsse: ' . $this->generateAuthHeader($this->username, $this->secret));
     $url = rtrim($this->baseUrl, '/') . '/' . ltrim($request->getPath(), '/');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     // TODO: verify ssl and provide certificate in package
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $method = Tools::strtoupper($request->getMethod());
     // Per-method special handling
     switch ($method) {
         case 'PUT':
         case 'POST':
             $body = Tools::jsonEncode($request->getData());
             array_push($headers, 'Content-Type: application/json');
             array_push($headers, 'Content-Length: ' . Tools::strlen($body));
             curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
             break;
         case 'GET':
             $queryParams = $request->getData();
             if (is_array($queryParams)) {
                 $url .= '?' . http_build_query($queryParams);
             }
             break;
         case 'DELETE':
             break;
         default:
             throw new Exception('Unsupported method given: ' . $method);
     }
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     $response = curl_exec($ch);
     if ($response === false) {
         throw new Exception(curl_error($ch), curl_errno($ch));
     }
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     list($headers, $body) = explode("\r\n\r\n", $response, 2);
     $this->headers = $headers;
     $this->body = $body;
     if (!in_array($httpCode, array(200, 201))) {
         throw new Syspay_Merchant_RequestException($httpCode, $headers, $body);
     }
     $decoded = Tools::jsonDecode($body);
     if ($decoded instanceof stdClass && isset($decoded->data) && $decoded->data instanceof stdClass) {
         $this->data = $decoded->data;
         return $request->buildResponse($decoded->data);
     } else {
         throw new Syspay_Merchant_UnexpectedResponseException('Unable to decode response from json', $body);
     }
     return false;
 }
 public static function file_get_contents($url, $use_include_path = false, $stream_context = null)
 {
     if (in_array(ini_get('allow_url_fopen'), array('On', 'on', '1')) || !preg_match('/^https?:\\/\\//', $url)) {
         $response = @file_get_contents($url, $use_include_path, $stream_context);
         if (isset($http_response_header)) {
             $matches = array();
             preg_match('#HTTP/\\d+\\.\\d+ (\\d+)#', $http_response_header[0], $matches);
             $http_status_code = $matches[1];
             if ($http_status_code != 200 && $http_status_code != 201) {
                 throw new Exception('', $http_status_code);
             }
         }
         return $response;
     }
     if (function_exists('curl_init')) {
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_URL, $url);
         curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
         curl_setopt($curl, CURLOPT_TIMEOUT, 8);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         if ($stream_context != null) {
             $opts = stream_context_get_options($stream_context);
             $headers = array();
             //add headers from stream context
             if (isset($opts['http']['header'])) {
                 $_headers = explode("\r\n", $opts['http']['header']);
                 //remove last or empty
                 $_headers = array_filter($_headers, 'strlen');
                 array_merge($headers, $_headers);
             }
             //set POST fields
             if (isset($opts['http']['method']) && Tools::strtolower($opts['http']['method']) == 'post') {
                 curl_setopt($curl, CURLOPT_POST, true);
                 if (isset($opts['http']['content'])) {
                     $jsonData = $opts['http']['content'];
                     curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonData);
                     $headers[] = 'Content-Type: application/json';
                     $headers[] = 'Content-Length: ' . Tools::strlen($jsonData);
                 }
             }
             curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
         }
         $response = curl_exec($curl);
         $http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         if ($http_status_code != 200 && $http_status_code != 201) {
             throw new Exception('', $http_status_code);
         }
         curl_close($curl);
         return $response;
     } else {
         return false;
     }
 }
 public static function getResApi($url, $verb, $params = null)
 {
     if (is_null($url) || is_null($verb) || !in_array($verb, array('GET', 'POST'))) {
         // $this->_html .= $this->displayError($this->l('Error In Configuration Of The Api'));
         return false;
     }
     $url_api = $url;
     $params_string = null;
     if (count($params)) {
         if ($verb == 'GET') {
             $params_string = http_build_query($params);
             $url_api .= '?' . $params_string;
         } elseif ($verb == 'POST') {
             $params_string = Tools::jsonEncode($params);
         }
     }
     $curl_obj = curl_init();
     curl_setopt($curl_obj, CURLOPT_URL, $url_api);
     // if ($verb == 'POST' && count($params))
     // {
     //     curl_setopt($curl_obj, CURLOPT_POST, true);
     //     curl_setopt($curl_obj, CURLOPT_POSTFIELDS, $params_string);
     //     curl_setopt($curl_obj, CURLOPT_HTTPHEADER, array(
     //         'Content-Type: application/json',
     //         'Content-Length: ' . strlen($params_string)
     //     ));
     // }
     if ($verb == 'POST') {
         curl_setopt($curl_obj, CURLOPT_POST, true);
         if (count($params)) {
             curl_setopt($curl_obj, CURLOPT_POSTFIELDS, $params_string);
             curl_setopt($curl_obj, CURLOPT_HTTPHEADER, array('Source-Id: ks-prestashop-1-rc-1-10', 'Content-Type: application/json', 'Content-Length: ' . Tools::strlen($params_string)));
         } else {
             curl_setopt($curl_obj, CURLOPT_HTTPHEADER, array('Source-Id: ks-prestashop-1-rc-1-10', 'Content-Type: application/json', 'Content-Length: 0'));
         }
     } else {
         curl_setopt($curl_obj, CURLOPT_HTTPHEADER, array('Source-Id: ks-prestashop-1-rc-1-10'));
     }
     curl_setopt($curl_obj, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl_obj, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl_obj, CURLOPT_NOSIGNAL, true);
     curl_setopt($curl_obj, CURLOPT_CONNECTTIMEOUT, 30);
     curl_setopt($curl_obj, CURLOPT_TIMEOUT, 30);
     $res_exec = curl_exec($curl_obj);
     $curl_errno = curl_errno($curl_obj);
     //$curl_error = curl_error($curl_obj);
     curl_close($curl_obj);
     if ($curl_errno) {
         // $this->_html .= $this->displayError($this->l('Error In API ') . $url . strval($curl_errno) . ' : ' . $curl_error);
         return false;
     } else {
         return Tools::jsonDecode($res_exec, true);
     }
 }
Example #18
0
 function addStringToStringList($szExistingStringList, $szStringToAdd)
 {
     $szReturnString = '';
     $szCommaString = '';
     if (Tools::strlen($szStringToAdd) == 0) {
         $szReturnString = $szExistingStringList;
     } else {
         if (Tools::strlen($szExistingStringList) != 0) {
             $szCommaString = ', ';
         }
         $szReturnString = $szExistingStringList . $szCommaString . $szStringToAdd;
     }
     return $szReturnString;
 }
Example #19
0
function fireCurl($data, $url)
{
    $domain = Configuration::get('PS_SHOP_DOMAIN');
    $auth_token = Configuration::get('PS_AUTH_TOKEN');
    Tools::getValue('id_order');
    $data_string = Tools::jsonEncode($data);
    $hash_code = hash_hmac('sha256', $data_string, $auth_token);
    Logger::addLog('Riskified URL is ' . $url, 1);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $headers = array('Content-Type: application/json', 'Content-Length: ' . Tools::strlen($data_string), 'X_RISKIFIED_SHOP_DOMAIN:' . $domain, 'X_RISKIFIED_HMAC_SHA256:' . $hash_code);
    array_push($headers, 'X_RISKIFIED_SUBMIT_NOW:ok');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_getinfo($ch);
    $result = curl_exec($ch);
    $decoded_response = Tools::jsonDecode($result);
    $order_id = null;
    $status = null;
    if (!is_null($decoded_response) && isset($decoded_response->order)) {
        $order_id = $decoded_response->order->id;
        $status = $decoded_response->order->status;
        if ($status != 'captured' && $order_id) {
            switch ($status) {
                case 'approved':
                    echo 'Reviewed and approved by Riskified';
                    break;
                case 'declined':
                    echo 'Reviewed and declined by Riskified';
                    break;
                case 'submitted':
                    echo 'Order under review by Riskified';
                    break;
            }
        }
    } else {
        if (!is_null($decoded_response) && isset($decoded_response->error)) {
            $error_message = $decoded_response->error->message;
            Logger::addLog('Error occured when submitting an order to Riskified.');
            echo 'Error: ' . $error_message;
        } else {
            $error_message = print_r($decoded_response, true);
            echo 'Error occured: ' . $error_message;
            Logger::addLog('Error occured when submitting an order to Riskified.');
        }
    }
    die;
}
 public static function className($class)
 {
     // Useful for namespaces: Foo\Stripe_Charge
     if ($postfix = strrchr($class, '\\')) {
         $class = Tools::substr($postfix, 1);
     }
     /* PrestaShop */
     if (Tools::substr($class, 0, Tools::strlen('Stripe')) == 'Stripe') {
         $class = Tools::substr($class, Tools::strlen('Stripe'));
     }
     $class = str_replace('_', '', $class);
     $name = urlencode($class);
     $name = Tools::strtolower($name);
     return $name;
 }
Example #21
0
 public function init()
 {
     parent::init();
     if (Tools::isSubmit('storedelivery') && (int) Tools::getValue('storedelivery') != 0) {
         $cookie = new Cookie('storedelivery');
         $cookie->__set('id_address_delivery', $this->context->cart->id_address_delivery);
         $store = new Store(Tools::getValue('storedelivery'));
         Tools::strlen($store->name) > 32 ? $storeName = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($storeName = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
         $sql = 'SELECT id_address FROM ' . _DB_PREFIX_ . 'address WHERE alias=\'' . addslashes($storeName) . '\' AND address1=\'' . addslashes($store->address1) . '\' AND address2=\'' . addslashes($store->address2) . '\' AND postcode=\'' . $store->postcode . '\' AND city=\'' . addslashes($store->city) . '\' AND id_country=\'' . addslashes($store->id_country) . '\' AND active=1 AND deleted=0';
         $id_address = Db::getInstance()->getValue($sql);
         if (empty($id_address)) {
             $country = new Country($store->id_country, $this->context->language->id);
             $address = new Address();
             $address->id_country = $store->id_country;
             $address->id_state = $store->id_state;
             $address->country = $country->name;
             Tools::strlen($store->name) > 32 ? $address->alias = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->alias = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             Tools::strlen($store->name) > 32 ? $address->lastname = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->lastname = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             $address->firstname = " ";
             $address->address1 = $store->address1;
             $address->address2 = $store->address2;
             $address->postcode = $store->postcode;
             $address->city = $store->city;
             $address->phone = $store->phone;
             $address->deleted = 0;
             $address->add();
             $id_address = $address->id;
         }
         $cart = $this->context->cart;
         $cart->id_address_delivery = $id_address;
         $cart->update();
         Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $id_address), $where = 'id_cart = ' . $this->context->cart->id);
         $array = array_values(Tools::getValue('delivery_option'));
         $_POST['delivery_option'] = array($id_address => $array[0]);
     } else {
         $cookie = new Cookie('storedelivery');
         $id_address_delivery = $cookie->__get('id_address_delivery');
         if ($id_address_delivery != false && $this->context->cart->id_address_delivery != $id_address_delivery && Tools::isSubmit('storedelivery')) {
             $this->context->cart->id_address_delivery = $cookie->__get('id_address_delivery');
             $this->context->cart->update();
             Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $cookie->__get('id_address_delivery')), $where = 'id_cart = ' . $this->context->cart->id);
             $array = array_values(Tools::getValue('delivery_option'));
             $_POST['delivery_option'] = array($cookie->__get('id_address_delivery') => $array[0]);
             $cookie->__unset('id_address_delivery');
         }
     }
 }
/**
 * 2007-2015 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to http://www.prestashop.com for more information.
 *
 * @author    PrestaShop SA <*****@*****.**>
 * @copyright 2007-2015 PrestaShop SA
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 */
function ps1607_language_code_update()
{
    if (defined('_PS_VERSION_')) {
        $langs = Db::getInstance()->executeS('SELECT `id_lang`, `iso_code`, `language_code` FROM `' . _DB_PREFIX_ . 'lang`');
        if (is_array($langs) && $langs) {
            foreach ($langs as $lang) {
                if (Tools::strlen($lang['language_code']) == 2) {
                    $result = json_decode(Tools::file_get_contents('https://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . _PS_VERSION_ . '&iso_lang=' . Tools::strtolower($lang['iso_code'])));
                    if ($result && !isset($result->error) && Tools::strlen($result->language_code) > 2) {
                        Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'lang` SET `language_code` = \'' . pSQL($result->language_code) . '\' WHERE `id_lang` = ' . (int) $lang['id_lang']) . ' LIMIT 1';
                    }
                }
            }
        }
    }
    return true;
}
 private function getErrorFields()
 {
     $error_fields = array();
     $api = Configuration::get('PS_PRESTASTATS_API_KEY');
     $username = Configuration::get('PS_PRESTASTATS_USER_LOGIN');
     $password = Configuration::get('PS_PRESTASTATS_USER_PASSWORD');
     if (!ctype_alnum($api) || Tools::strlen($api) > 32) {
         $error_fields['api_error'] = $this->l('API value is not correct');
     }
     if (!$username || Tools::strlen($api) > 32) {
         $error_fields['username_error'] = $this->l('Username value is not correct');
     }
     if (!ctype_alnum($password) || Tools::strlen($api) > 32) {
         $error_fields['password_error'] = $this->l('Password value is not correct');
     }
     return $error_fields;
 }
 public static function sortData($text)
 {
     $token = preg_split('/[-,\\n]/', $text);
     for ($i = 0; $i < Tools::strlen($token[0]); $i++) {
         if (is_numeric(Tools::substr($token[0], $i, 1))) {
             return array(Tools::substr($token[0], 0, $i), Tools::substr($token[0], $i), $token[1]);
         }
     }
     $text = preg_replace('/\\s/', ' ', $text);
     $textlen = Tools::strlen($text);
     $find = Tools::substr($text, -$textlen);
     for ($i = 0; $i < Tools::strlen($text); $i++) {
         if (is_numeric(Tools::substr($find, $i, 1))) {
             return array(Tools::substr($text, 0, -Tools::strlen($text) + $i), Tools::substr($text, -Tools::strlen($text) + $i), '');
         }
     }
 }
Example #25
0
 public static function isLuhnNum($num, $length = null)
 {
     if (empty($length)) {
         $length = Tools::strlen($num);
     }
     $tot = 0;
     for ($i = $length - 1; $i >= 0; $i--) {
         $digit = Tools::substr($num, $i, 1);
         if (($length - $i) % 2 == 0) {
             $digit = $digit * 2;
             if ($digit > 9) {
                 $digit = $digit - 9;
             }
         }
         $tot += $digit;
     }
     return $tot % 10 == 0;
 }
 public function display()
 {
     global $cookie;
     if (isset($_GET['view' . $this->table]) and !empty($_GET['id_order']) and $_GET['id_order'] != '--') {
         Tools::redirectAdmin('index.php?tab=AdminOrders&id_order=' . intval($_GET['id_order']) . '&vieworder' . '&token=' . Tools::getAdminToken('AdminOrders' . intval(Tab::getIdFromClassName('AdminOrders')) . intval($cookie->id_employee)));
     } else {
         if (isset($_GET['id_order']) and (empty($_GET['id_order']) or $_GET['id_order'] == '--')) {
             echo '<p class="warning bold"><img src="../img/admin/warning.gif" alt="" class="middle" /> &nbsp;' . Tools::displayError('Cannot display this message because the customer has not finalized its order') . '</p>';
         }
         foreach ($this->_list as $k => $item) {
             if (Tools::strlen($item['last_message']) > 150 + Tools::strlen('...')) {
                 $this->_list[$k]['last_message'] = Tools::substr(html_entity_decode($item['last_message'], ENT_QUOTES, 'UTF-8'), 0, 150, 'UTF-8') . '...';
             }
         }
         $this->displayList();
         $this->displayOptionsList();
     }
 }
Example #27
0
 /**
  * Random password generator
  *
  * @param integer $length Desired length (optional)
  * @param string $flag Output type (NUMERIC, ALPHANUMERIC, NO_NUMERIC)
  * @return string Password
  */
 public static function passwdGen($length = 8, $flag = 'ALPHANUMERIC')
 {
     switch ($flag) {
         case 'NUMERIC':
             $str = '0123456789';
             break;
         case 'NO_NUMERIC':
             $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
             break;
         default:
             $str = 'abcdefghijkmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
             break;
     }
     for ($i = 0, $passwd = ''; $i < $length; $i++) {
         $passwd .= substr($str, mt_rand(0, Tools::strlen($str) - 1), 1);
     }
     return $passwd;
 }
 public function hookdisplayPayment($params)
 {
     if (!$this->active) {
         return;
     }
     //!$cart->OrderExists();
     $customer = new Customer($params['cart']->id_customer);
     $email_address = $customer->email;
     $currency = trim($this->getCurrency()->iso_code);
     $Amount = $params['cart']->getOrderTotal(true, 3) * 100;
     $cartId = $params['cart']->id;
     $address = new Address($params['cart']->id_address_invoice);
     $products = $params['cart']->getProducts();
     $quantity = '';
     $product_name = '';
     $product_count = count($products);
     for ($i = 0; $i < $product_count; $i++) {
         $quantity .= $products[$i]['cart_quantity'] . ',';
         $product_name .= $products[$i]['name'] . ',';
     }
     $product_name = Tools::strlen($product_name) > 100 ? Tools::substr($product_name, 0, 100) : $product_name;
     $complete_address = $address->address1 . ' ' . $address->address2;
     $complete_address = Tools::strlen($complete_address) > 100 ? Tools::substr($complete_address, 0, 100) : $complete_address;
     $module_version = Tools::strlen($module_version) > 20 ? Tools::substr($module_version, 0, 20) : $module_version;
     if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' && $_SERVER['HTTPS'] != 'OFF') {
         //TODO:: callback url, validate
         $redirect_url = 'https://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/instamojo/validation.php';
     } else {
         $redirect_url = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/instamojo/validation.php';
     }
     $imname = $address->firstname . ' ' . $address->lastname;
     $imemail = $email_address;
     $imphone = $address->phone_mobile;
     $imamount = $Amount;
     $imtid = $cartId . '||' . date('his');
     $this->smarty->assign('imname', $imname);
     $this->smarty->assign('imemail', $imemail);
     $this->smarty->assign('imphone', $imphone);
     $this->smarty->assign('imkey', $imkey);
     $this->smarty->assign('imtid', $imtid);
     $this->smarty->assign('imcustom', IM_Config::TXN_ID_NAME);
     $this->smarty->assign('imamount', $params['cart']->getOrderTotal(true, 3));
     return $this->display(__FILE__, '/views/templates/front/instamojo.tpl');
 }
 /**
  * Generate tmp order number
  *
  * @param void
  * @return string 23 digits
  */
 public static function getOrderNumber()
 {
     $number = date('ymd') . str_pad(rand(0, 999999), 6, '0', STR_PAD_LEFT) . time();
     $arr_weights = array(10, 8, 4, 5);
     $weight_limit = count($arr_weights);
     $j = 0;
     $sum = 0;
     $ck = 0;
     $strl_number = Tools::strlen($number);
     for ($i = 0; $i < $strl_number; $i++) {
         if ($j >= $weight_limit) {
             $j = 0;
         }
         $sum += $number[$i] * $arr_weights[$j];
         $j++;
         $ck = $sum % 10;
     }
     return (string) $number . $ck;
 }
 private function _generateMD5SecurityKey()
 {
     foreach ($this->_fieldsList as &$rootCase) {
         $concatenationValue = '';
         foreach ($rootCase['list'] as $paramName => &$valueDetailed) {
             if ($paramName != 'Texte' && $paramName != 'Security') {
                 $valueDetailed['value'] = Tools::strtoupper($valueDetailed['value']);
                 if (preg_match($valueDetailed['regexValidation'], $valueDetailed['value'], $matches)) {
                     $concatenationValue .= $valueDetailed['value'];
                 } elseif (!Tools::strlen($valueDetailed['value']) && $valueDetailed['required'] || Tools::strlen($valueDetailed['value'])) {
                     $error = $this->_mondialrelay->l('This key') . ' [' . $paramName . '] ' . $this->_mondialrelay->l('hasn\'t a valide value format') . ' : ' . $valueDetailed['value'];
                     $this->_resultList['error'][] = $error;
                 }
             }
         }
         $concatenationValue .= $this->_webServiceKey;
         $rootCase['list']['Security']['value'] = Tools::strtoupper(md5($concatenationValue));
     }
 }