File: //proc/self/cwd/nueva/modules/roja45quotationsprofree/classes/RojaFortyFiveQuotationsProCore.php
<?php
/**
* RojaFortyFiveCore.
*
* @author Roja45
* @copyright 2016 Roja45
* @license license.txt
* @category RojaFortyFiveCore
*
* 2016 ROJA45 - All rights reserved.
*
* DISCLAIMER
* Changing this file will render any support provided by us null and void.
*/
/**
* RojaFortyFiveCore.
*
* @author Roja45
* @copyright 2016 Roja45
* @license license.txt
* @category Class
*
* 2016 ROJA45.COM - All rights reserved.
*
* DISCLAIMER
* Changing this file will render any support provided by us null and void.
*/
class RojaFortyFiveQuotationsProCore
{
protected $html = '';
public static function renderHeader($module)
{
if (version_compare(_PS_VERSION_, '1.7', '>=') == true) {
return self::displayTemplate(
$module,
'displayBackOfficeHeader',
array(),
'hookRoja45Header.tpl'
);
}
}
public static function renderFooter($module)
{
return self::displayTemplate(
$module,
'displayBackOfficeFooter',
array(),
'hookRoja45Footer.tpl'
);
}
public static function sendHeartbeat($params) {
foreach ($params as $key => &$val) {
if (is_array($val)) {
$val = implode(',', $val);
}
$post_params[] = $key.'='.urlencode($val);
}
$post_string = implode(' & ', $post_params);
$parts = parse_url(hex2bin('746c733a2f2f7777772e726f6a6134352e636f6d2f75706461746573')); // tls
//$parts = parse_url(hex2bin('687474703a2f2f726f6a6134352e6c6f63616c2f75706461746573')); // Local
if ($parts['scheme']=='ssl' || $parts['scheme']=='tls') {
$parts['port'] = 443;
} else {
$parts['port'] = 80;
}
$fp = fsockopen(
$parts['scheme'].'://'.$parts['host'],
isset($parts['port']) ? $parts['port'] : 80,
$errno, $errstr, 30
);
$out = "POST " . $parts['path'] . " HTTP/1.1\r\n";
$out .= "Host: " . $parts['host'] . "\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: " . strlen($post_string) . "\r\n";
$out .= "Connection: Close\r\n\r\n";
if (isset($post_string)) {
$out .= $post_string;
}
fwrite($fp, $out);
$res = fread($fp, 26);
fclose($fp);
}
public static function validateUpdate($module_name, $module_version, $module_source, $order_ref)
{
if (Configuration::get('ROJA45_UPDATE_' . $module_name) < (date("U") - 86400)) {
$data = array(
'module_name' => $module_name,
'module_version' => $module_version,
'module_source' => $module_source,
'order_ref' => ($order_ref) ? $order_ref : 'TBC',
'host' => $_SERVER['HTTP_HOST'],
'email' => Configuration::get('PS_SHOP_EMAIL')
);
$data_encoded = bin2hex(Tools::jsonEncode($data));
$params = array(
'p' => $data_encoded
);
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
self::sendHeartbeat($params);
}
Configuration::updateValue('ROJA45_UPDATE_' . $module_name, date('U'));
}
}
public static function addJs($controller, $uri, $check_path = true)
{
if (version_compare(_PS_VERSION_, '1.7', '<') == true) {
$controller->addJs($uri.'.js', $check_path);
} else {
$controller->addJs($uri.'17.js', $check_path);
}
}
public static function removeJs($controller, $js_uri, $check_path = true)
{
if (version_compare(_PS_VERSION_, '1.7', '<') == true) {
$controller->addJs($js_uri, $check_path);
} else {
}
}
public static function addCss($controller, $css_uri, $css_media_type = 'all', $offset = null, $check_path = true)
{
if (version_compare(_PS_VERSION_, '1.7', '<') == true) {
$controller->addCss($css_uri, $css_media_type, $offset, $check_path);
} else {
}
}
public function removeCss($controller, $css_uri, $css_media_type = 'all', $check_path = true)
{
if (version_compare(_PS_VERSION_, '1.7', '<') == true) {
$controller->addCss($css_uri, $css_media_type, $check_path);
} else {
}
}
public static function displayTemplate($module, $hook_name, $params, $template, $cache_id = null)
{
if (version_compare(_PS_VERSION_, '1.7', '<') == true) {
return $module->display($module->name.'.php', $template, $cache_id);
} else {
return $module->renderWidget($hook_name, $params);
}
}
public static function createTemplate($module, $template)
{
if (version_compare(_PS_VERSION_, '1.7', '>=') == true) {
$template = 'PS17_'.$template;
}
if (file_exists(_PS_THEME_DIR_.'modules/'.$module.'/views/templates/hook/'.$template.'.tpl')) {
return Context::getContext()->smarty->createTemplate(_PS_THEME_DIR_.'modules/'.$module.'/views/templates/hook/'.$template.'.tpl');
} elseif (file_exists(_PS_ROOT_DIR_.'/modules/'.$module.'/views/templates/hook/'.$template.'.tpl')) {
return Context::getContext()->smarty->createTemplate(_PS_ROOT_DIR_.'/modules/'.$module.'/views/templates/hook/'.$template.'.tpl');
}
}
public static function setFrontControllerTemplate($controller, $template)
{
if (version_compare(_PS_VERSION_, '1.7', '<') == true) {
$controller->setTemplate($template);
} else {
$controller->setTemplate('module:'.$controller->module->name.'/views/templates/front/PS17_'.$template);
}
}
public static function getIncludedTemplate($controller, $template)
{
if (version_compare(_PS_VERSION_, '1.7', '<') == true) {
return Context::getContext()->smarty->createTemplate($controller->getTemplatePath('booking-page-totals.tpl'));
} else {
//return $controller->getTemplateFile('module:'.$controller->module->name.'/views/templates/_partials/PS17_'.$template);
return Context::getContext()->smarty->createTemplate('module:'.$controller->module->name.'/views/templates/front/PS17_'.$template);
}
}
public static function getLocalTranslation($module, $key, $lang)
{
if ($translation = Cache::getInstance()->get('local.'.$lang['iso_code'])) {
return $translation[$key];
} else {
if (file_exists(_PS_MODULE_DIR_ . $module->name . '/translations/local.' . $lang['iso_code'])) {
$data = file(_PS_MODULE_DIR_ . $module->name . '/translations/local.' . $lang['iso_code']);
} elseif (file_exists(_PS_MODULE_DIR_ . $module->name . '/translations/local.en')) {
$data = file(_PS_MODULE_DIR_ . $module->name . '/translations/local.en');
}
$returnArray = array();
foreach ($data as $line) {
$explode = explode("=", $line);
$returnArray[$explode[0]] = trim(preg_replace('/\s+/', ' ', $explode[1]));
}
Cache::getInstance()->store('local.'.$lang['iso_code'], $returnArray);
return $returnArray[$key];
}
}
public static function isValidDateTimeString($str_dt, $str_dateformat)
{
$date = DateTime::createFromFormat($str_dateformat, $str_dt);
return $date && $date->format($str_dateformat) == $str_dt;
}
public static function convertDateFormat($php_format)
{
$SYMBOLS_MATCHING = array(
// Day
'd' => 'dd',
'D' => 'D',
'j' => 'd',
'l' => 'DD',
'N' => '',
'S' => '',
'w' => '',
'z' => 'o',
// Week
'W' => '',
// Month
'F' => 'MM',
'm' => 'mm',
'M' => 'M',
'n' => 'm',
't' => '',
// Year
'L' => '',
'o' => '',
'Y' => 'yy',
'y' => 'y',
// Time
'a' => '',
'A' => '',
'B' => '',
'g' => '',
'G' => '',
'h' => '',
'H' => '',
'i' => '',
's' => '',
'u' => ''
);
$jqueryui_format = "";
$escaping = false;
for ($i = 0; $i < Tools::strlen($php_format); $i++) {
$char = $php_format[$i];
if ($char === '\\') {
$i++;
if ($escaping) {
$jqueryui_format .= $php_format[$i];
} else {
$jqueryui_format .= '\'' . $php_format[$i];
}
$escaping = true;
} else {
if ($escaping) {
$jqueryui_format .= "'";
$escaping = false;
}
if (isset($SYMBOLS_MATCHING[$char])) {
$jqueryui_format .= $SYMBOLS_MATCHING[$char];
} else {
$jqueryui_format .= $char;
}
}
}
return $jqueryui_format;
}
public static function saveCustomerRequirements($requirements)
{
foreach ($requirements as $key => $requirement) {
Context::getContext()->cookie->__set($key, $requirement);
}
}
public static function saveCustomerRequirement($requirement, $value)
{
return Context::getContext()->cookie->__set($requirement, $value);
}
public static function getCustomerRequirement($requirement)
{
return Context::getContext()->cookie->__get($requirement);
}
public static function getCustomerRequirements($family)
{
return Context::getContext()->cookie->getFamily($family);
}
public static function clearCustomerRequirement($requirement)
{
return Context::getContext()->cookie->__unset($requirement);
}
public static function clearCustomerRequirements($requirements)
{
foreach ($requirements as $requirement) {
Context::getContext()->cookie->__unset($requirement);
}
}
public static function clearAllCustomerRequirements($family)
{
Context::getContext()->cookie->unsetFamily($family);
}
}