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
 /**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     $this->display_column_left = false;
     parent::initContent();
     if (!$this->isTokenValid()) {
         die($this->module->l($this->module->displayName . ' Error: (invalid token)'));
     }
     $cart = $this->context->cart;
     $address = new Address((int) $cart->id_address_invoice);
     $customer = new Customer((int) $cart->id_customer);
     $currency = $this->context->currency;
     $country = new Country((int) $address->id_country);
     if (!Configuration::get('SOFORTBANKING_USER_ID')) {
         die($this->module->l($this->module->displayName . ' Error: (invalid or undefined userId)'));
     }
     if (!Configuration::get('SOFORTBANKING_PROJECT_ID')) {
         die($this->module->l($this->module->displayName . ' Error: (invalid or undefined projectId)'));
     }
     if (!Validate::isLoadedObject($address) || !Validate::isLoadedObject($customer) || !Validate::isLoadedObject($currency)) {
         die($this->module->l($this->module->displayName . ' Error: (invalid address or customer)'));
     }
     $parameters = array('user_id' => Configuration::get('SOFORTBANKING_USER_ID'), 'project_id' => Configuration::get('SOFORTBANKING_PROJECT_ID'), 'sender_holder' => '', '', '', 'sender_country_id' => $country->iso_code, 'amount' => number_format($cart->getOrderTotal(), 2, '.', ''), 'currency_id' => $currency->iso_code, 'reason_1' => time() . '-' . (int) $cart->id, 'reason_2' => $customer->firstname . ' ' . Tools::ucfirst(Tools::strtolower($customer->lastname)), 'user_variable_0' => $customer->secure_key, 'user_variable_1' => (int) $cart->id, 'user_variable_2' => '', 'user_variable_3' => '', 'user_variable_4' => '', 'user_variable_5' => '', 'project_password' => Configuration::get('SOFORTBANKING_PROJECT_PW'));
     $this->context->smarty->assign(array('this_path' => $this->module->getPathUri(), 'nbProducts' => $cart->nbProducts(), 'total' => $cart->getOrderTotal(), 'version' => _PS_VERSION_, 'hash' => sha1(implode('|', $parameters)), 'gateway' => 'https://www.sofortueberweisung.de/payment/start', 'cprotect' => Configuration::get('SOFORTBANKING_CPROTECT'), 'parameters' => $parameters, 'mod_lang' => $this->isSupportedLang()));
     $this->setTemplate(Configuration::get('SOFORTBANKING_REDIRECT') == 'Y' ? 'payment_redirect.tpl' : 'payment_execution.tpl');
 }
Example #3
0
        public function productSort()
	{
		// $this->orderBy = Tools::getProductsOrder('by', Tools::getValue('orderby'));
		// $this->orderWay = Tools::getProductsOrder('way', Tools::getValue('orderway'));
		// 'orderbydefault' => Tools::getProductsOrder('by'),
		// 'orderwayposition' => Tools::getProductsOrder('way'), // Deprecated: orderwayposition
		// 'orderwaydefault' => Tools::getProductsOrder('way'),

		$stock_management = Configuration::get('PS_STOCK_MANAGEMENT') ? true : false; // no display quantity order if stock management disabled
		$order_by_values = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 
                4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference',8=>'bestsale');
		$order_way_values = array(0 => 'asc', 1 => 'desc');
		$this->orderBy = Tools::strtolower(Tools::getValue('orderby', $order_by_values[(int)Configuration::get('PS_PRODUCTS_ORDER_BY')]));
		$this->orderWay = Tools::strtolower(Tools::getValue('orderway', $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')]));
		if (!in_array($this->orderBy, $order_by_values))
			$this->orderBy = $order_by_values[0];
		if (!in_array($this->orderWay, $order_way_values))
			$this->orderWay = $order_way_values[0];

		$this->context->smarty->assign(array(
			'orderby' => $this->orderBy,
			'orderway' => $this->orderWay,
			'orderbydefault' => $order_by_values[(int)Configuration::get('PS_PRODUCTS_ORDER_BY')],
			'orderwayposition' => $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')], // Deprecated: orderwayposition
			'orderwaydefault' => $order_way_values[(int)Configuration::get('PS_PRODUCTS_ORDER_WAY')],
			'stock_management' => (int)$stock_management));
	}
 /**
  * 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');
 }
 public function _showWidgetsSetting()
 {
     $this->context->controller->addJS(__PS_BASE_URI__ . 'modules/leomanagewidgets/assets/admin/jquery-validation-1.9.0/jquery.validate.js');
     $this->context->controller->addCSS(__PS_BASE_URI__ . 'modules/leomanagewidgets/assets/admin/jquery-validation-1.9.0/screen.css');
     $this->context->controller->addJS(__PS_BASE_URI__ . 'modules/leomanagewidgets/assets/admin/show.js');
     $tpl = $this->createTemplate('widget.tpl');
     $disabled = false;
     $form = '';
     $widget_selected = '';
     $id = (int) Tools::getValue('id_leowidgets');
     $key = (int) Tools::getValue('key');
     if (Tools::getValue('id_leowidgets')) {
         $model = new LeoTempcpWidget((int) Tools::getValue('id_leowidgets'));
     } else {
         $model = $this->widget;
     }
     $model->loadEngines();
     $model->id_shop = Context::getContext()->shop->id;
     $types = $model->getTypes();
     if ($key) {
         $widget_data = $model->getWidetByKey($key, Context::getContext()->shop->id);
     } else {
         $widget_data = $model->getWidetById($id);
     }
     $id = (int) $widget_data['id'];
     $widget_selected = trim(Tools::strtolower(Tools::getValue('wtype')));
     if ($widget_data['type']) {
         $widget_selected = $widget_data['type'];
         $disabled = true;
     }
     $form = $model->getForm($widget_selected, $widget_data);
     $tpl->assign(array('types' => $types, 'form' => $form, 'widget_selected' => $widget_selected, 'table' => $this->table, 'max_size' => Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE'), 'PS_ALLOW_ACCENTED_CHARS_URL' => Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'), 'action' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token));
     //echo "die"; die();
     return $tpl->fetch();
 }
 public function renderList()
 {
     $this->toolbar_title = $this->l('Products list');
     $prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this)));
     if (Tools::isSubmit('stockOrderby')) {
         $stockOrderby = Tools::getValue('stockOrderby');
         $_GET[$prefix . 'stockOrderby'] = $stockOrderby;
         $_GET['stockOrderby'] = $stockOrderby;
     }
     if (Tools::isSubmit('stockOrderway')) {
         $stockOrderway = Tools::getValue('stockOrderway');
         $_GET[$prefix . 'stockOrderway'] = $stockOrderway;
         $_GET['stockOrderway'] = $stockOrderway;
     }
     $this->processFilter();
     $this->getCurrentValue('stockOrderway');
     $this->getCurrentValue('stockOrderby');
     //sidebar
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     $this->tpl_list_vars['erp_feature'] = ErpFeature::getFeaturesWithToken($this->context->language->iso_code);
     $this->tpl_list_vars['template_path'] = $this->template_path;
     $advanced_stock_token = Tools::getAdminToken('AdminAdvancedStock' . (int) Tab::getIdFromClassName('AdminAdvancedStock') . (int) $this->context->employee->id);
     $this->tpl_list_vars['advanced_stock_token'] = $advanced_stock_token;
     return parent::renderList();
 }
 protected function copyFromPost(&$object, $table)
 {
     parent::copyFromPost($object, $table);
     if (get_class($object) != 'Product') {
         return;
     }
     /* Additional fields */
     $languages = Language::getLanguages(false);
     foreach ($languages as $language) {
         if (isset($_POST['meta_keywords_' . $language['id_lang']])) {
             $_POST['meta_keywords_' . $language['id_lang']] = $this->_cleanMetaKeywords(Tools::strtolower($_POST['meta_keywords_' . $language['id_lang']]));
             // preg_replace('/ *,? +,* /', ',', strtolower($_POST['meta_keywords_'.$language['id_lang']]));
             $object->meta_keywords[$language['id_lang']] = $_POST['meta_keywords_' . $language['id_lang']];
         }
     }
     $_POST['width'] = empty($_POST['width']) ? '0' : str_replace(',', '.', $_POST['width']);
     $_POST['height'] = empty($_POST['height']) ? '0' : str_replace(',', '.', $_POST['height']);
     $_POST['depth'] = empty($_POST['depth']) ? '0' : str_replace(',', '.', $_POST['depth']);
     $_POST['weight'] = empty($_POST['weight']) ? '0' : str_replace(',', '.', $_POST['weight']);
     if ($_POST['unit_price'] != NULL) {
         $object->unit_price = str_replace(',', '.', $_POST['unit_price']);
     }
     if (array_key_exists('ecotax', $_POST) && $_POST['ecotax'] != NULL) {
         $object->ecotax = str_replace(',', '.', $_POST['ecotax']);
     }
     $object->available_for_order = (int) Tools::isSubmit('available_for_order');
     $object->show_price = $object->available_for_order ? 1 : (int) Tools::isSubmit('show_price');
     $object->on_sale = Tools::isSubmit('on_sale');
     $object->online_only = Tools::isSubmit('online_only');
 }
Example #8
0
 function hookHeader($params)
 {
     global $smarty, $cookie;
     $id_category = intval(Tools::getValue('id_category'));
     if (!$id_category) {
         if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
             if (isset($regs[2]) and is_numeric($regs[2])) {
                 $id_category = intval($regs[2]);
             } elseif (isset($regs[5]) and is_numeric($regs[5])) {
                 $id_category = intval($regs[5]);
             }
         } elseif ($id_product = intval(Tools::getValue('id_product'))) {
             $product = new Product($id_product);
             $id_category = $product->id_category_default;
         }
     }
     $category = new Category($id_category);
     $orderByValues = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity');
     $orderWayValues = array(0 => 'ASC', 1 => 'DESC');
     $orderBy = Tools::strtolower(Tools::getValue('orderby', $orderByValues[intval(Configuration::get('PS_PRODUCTS_ORDER_BY'))]));
     $orderWay = Tools::strtoupper(Tools::getValue('orderway', $orderWayValues[intval(Configuration::get('PS_PRODUCTS_ORDER_WAY'))]));
     if (!in_array($orderBy, $orderByValues)) {
         $orderBy = $orderByValues[0];
     }
     if (!in_array($orderWay, $orderWayValues)) {
         $orderWay = $orderWayValues[0];
     }
     $smarty->assign(array('feedUrl' => 'http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/rss.php?id_category=' . $id_category . '&amp;orderby=' . $orderBy . '&amp;orderway=' . $orderWay));
     return $this->display(__FILE__, 'feederHeader.tpl');
 }
Example #9
0
 /**
  * Send a mail
  *
  * @param string $subject
  * @param string $content
  * @return bool|string false is everything was fine, or error string
  */
 public function send($subject, $content)
 {
     try {
         // Test with custom SMTP connection
         if ($this->smtp_checked) {
             // Retrocompatibility
             if (Tools::strtolower($this->encryption) === 'off') {
                 $this->encryption = false;
             }
             $smtp = Swift_SmtpTransport::newInstance($this->server, $this->port, $this->encryption);
             $smtp->setUsername($this->login);
             $smtp->setpassword($this->password);
             $smtp->setTimeout(5);
             $swift = Swift_Mailer::newInstance($smtp);
         } else {
             // Test with normal PHP mail() call
             $swift = Swift_Mailer::newInstance(Swift_MailTransport::newInstance());
         }
         $message = Swift_Message::newInstance();
         $message->setFrom($this->email)->setTo('no-reply@' . Tools::getHttpHost(false, false, true))->setSubject($subject)->setBody($content);
         $message = new Swift_Message($subject, $content, 'text/html');
         if (@$swift->send($message)) {
             $result = true;
         } else {
             $result = 'Could not send message';
         }
         $swift->disconnect();
     } catch (Swift_SwiftException $e) {
         $result = $e->getMessage();
     }
     return $result;
 }
Example #10
0
 public static function getPages($exclude_filled = false, $add_page = false)
 {
     $selected_pages = array();
     if (!($files = Tools::scandir(_PS_ROOT_DIR_ . '/controllers/front/', 'php', '', true))) {
         die(Tools::displayError('Cannot scan root directory'));
     }
     // Exclude pages forbidden
     $exlude_pages = array('category', 'changecurrency', 'cms', 'footer', 'header', 'pagination', 'product', 'product-sort', 'statistics');
     foreach ($files as $file) {
         if ($file != 'index.php' && !in_array(strtolower(str_replace('Controller.php', '', $file)), $exlude_pages)) {
             $class_name = str_replace('.php', '', $file);
             if (class_exists($class_name)) {
                 $reflection = new ReflectionClass(str_replace('.php', '', $file));
             }
             if (isset($reflection) && $reflection) {
                 $properties = $reflection->getDefaultProperties();
             }
             if (isset($properties['php_self'])) {
                 $selected_pages[$properties['php_self']] = $properties['php_self'];
             } else {
                 if (preg_match('/^[a-z0-9_.-]*\\.php$/i', $file)) {
                     $selected_pages[strtolower(str_replace('Controller.php', '', $file))] = strtolower(str_replace('Controller.php', '', $file));
                 } else {
                     if (preg_match('/^([a-z0-9_.-]*\\/)?[a-z0-9_.-]*\\.php$/i', $file)) {
                         $selected_pages[strtolower(sprintf(Tools::displayError('%2$s (in %1$s)'), dirname($file), str_replace('Controller.php', '', basename($file))))] = strtolower(str_replace('Controller.php', '', basename($file)));
                     }
                 }
             }
         }
     }
     // Add modules controllers to list (this function is cool !)
     foreach (glob(_PS_MODULE_DIR_ . '*/controllers/front/*.php') as $file) {
         $filename = Tools::strtolower(basename($file, '.php'));
         if ($filename == 'index') {
             continue;
         }
         $module = Tools::strtolower(basename(dirname(dirname(dirname($file)))));
         $selected_pages[$module . ' - ' . $filename] = 'module-' . $module . '-' . $filename;
     }
     // Exclude page already filled
     if ($exclude_filled) {
         $metas = Meta::getMetas();
         foreach ($metas as $meta) {
             if (in_array($meta['page'], $selected_pages)) {
                 unset($selected_pages[array_search($meta['page'], $selected_pages)]);
             }
         }
     }
     // Add selected page
     if ($add_page) {
         $name = $add_page;
         if (preg_match('#module-([a-z0-9_-]+)-([a-z0-9]+)$#i', $add_page, $m)) {
             $add_page = $m[1] . ' - ' . $m[2];
         }
         $selected_pages[$add_page] = $name;
         asort($selected_pages);
     }
     return $selected_pages;
 }
 public function preProcess()
 {
     parent::preProcess();
     $customer = new Customer((int) self::$cookie->id_customer);
     if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days'])) {
         $customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
     }
     if (Tools::isSubmit('submitIdentity')) {
         if (Module::getInstanceByName('blocknewsletter')->active) {
             if (!isset($_POST['optin'])) {
                 $customer->optin = 0;
             }
             if (!isset($_POST['newsletter'])) {
                 $customer->newsletter = 0;
             }
         }
         if (!isset($_POST['id_gender'])) {
             $_POST['id_gender'] = 9;
         }
         if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '')) {
             $this->errors[] = Tools::displayError('Invalid date of birth');
         } else {
             $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
             $id_customer_exists = (int) Customer::customerExists(Tools::getValue('email'), true, false);
             if ($id_customer_exists && $id_customer_exists != (int) self::$cookie->id_customer) {
                 $this->errors[] = Tools::displayError('An account is already registered with this e-mail.');
             }
             $_POST['old_passwd'] = trim($_POST['old_passwd']);
             if (empty($_POST['old_passwd']) || Tools::encrypt($_POST['old_passwd']) != self::$cookie->passwd) {
                 $this->errors[] = Tools::displayError('Your password is incorrect.');
             } elseif ($_POST['passwd'] != $_POST['confirmation']) {
                 $this->errors[] = Tools::displayError('Password and confirmation do not match');
             } else {
                 $prev_id_default_group = $customer->id_default_group;
                 $this->errors = array_unique(array_merge($this->errors, $customer->validateController(true, true)));
             }
             if (!count($this->errors)) {
                 $customer->id_default_group = (int) $prev_id_default_group;
                 $customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname));
                 if (Tools::getValue('passwd')) {
                     self::$cookie->passwd = $customer->passwd;
                 }
                 if ($customer->update()) {
                     self::$cookie->customer_lastname = $customer->lastname;
                     self::$cookie->customer_firstname = $customer->firstname;
                     self::$smarty->assign('confirmation', 1);
                 } else {
                     $this->errors[] = Tools::displayError('Cannot update information');
                 }
             }
         }
     } else {
         $_POST = array_map('stripslashes', $customer->getFields());
     }
     $birthday = $customer->birthday ? explode('-', $customer->birthday) : array('-', '-', '-');
     /* Generate years, months and days */
     self::$smarty->assign(array('years' => Tools::dateYears(), 'sl_year' => $birthday[0], 'months' => Tools::dateMonths(), 'sl_month' => $birthday[1], 'days' => Tools::dateDays(), 'sl_day' => $birthday[2], 'errors' => $this->errors));
     self::$smarty->assign('newsletter', (int) Module::getInstanceByName('blocknewsletter')->active);
 }
 public function testUninstall()
 {
     $module = Module::getInstanceByName(Tools::strtolower($this->getClass()));
     if (!$module->id) {
         $module->install();
     }
     $this->assertTrue($module->uninstall());
 }
Example #13
0
 function getContent()
 {
     $ebay_country = EbayCountrySpec::getInstanceByKey($this->ebay_profile->getConfiguration('EBAY_COUNTRY_DEFAULT'));
     $help_file = dirname(__FILE__) . '/../../help/help-' . Tools::strtolower($ebay_country->getDocumentationLang()) . '.html';
     if (!file_exists($help_file)) {
         $help_file = dirname(__FILE__) . '/../../help/help-en.html';
     }
     return Tools::file_get_contents($help_file);
 }
 public static function webalize($string)
 {
     $string = preg_replace('~[^\\pL0-9_]+~u', '-', $string);
     $string = trim($string, '-');
     $string = iconv('utf-8', 'us-ascii//TRANSLIT', $string);
     $string = Tools::strtolower($string);
     $string = preg_replace('~[^-a-z0-9_]+~', '', $string);
     return $string;
 }
Example #15
0
 public static function sanitize($string, $id_lang, $indexation = false)
 {
     $string = Tools::strtolower(strip_tags($string));
     $string = html_entity_decode($string, ENT_NOQUOTES, 'utf-8');
     $string = preg_replace('/([' . PREG_CLASS_NUMBERS . ']+)[' . PREG_CLASS_PUNCTUATION . ']+(?=[' . PREG_CLASS_NUMBERS . '])/u', '\\1', $string);
     $words = explode(' ', $string);
     $processed_words = array();
     foreach ($words as &$word) {
         $alias = new Alias(null, $word);
         if (Validate::isLoadedObject($alias)) {
             $word = $alias->search;
             $processed_words[] = $word;
         }
     }
     $string = preg_replace('/[' . PREG_CLASS_SEARCH_EXCLUDE . ']+/u', ' ', $string);
     if ($indexation) {
         $string = preg_replace('/[._-]+/', '', $string);
     } else {
         $string = preg_replace('/[._]+/', '', $string);
         $string = ltrim(preg_replace('/([^ ])-/', '$1', ' ' . $string));
         $string = preg_replace('/[._]+/', '', $string);
         $string = preg_replace('/[^\\s]-+/', '', $string);
     }
     $blacklist = Configuration::get('PS_SEARCH_BLACKLIST', (int) $id_lang);
     if (!empty($blacklist)) {
         $string = preg_replace('/(?<=\\s)(' . $blacklist . ')(?=\\s)/Su', '', $string);
         $string = preg_replace('/^(' . $blacklist . ')(?=\\s)/Su', '', $string);
         $string = preg_replace('/(?<=\\s)(' . $blacklist . ')$/Su', '', $string);
         $string = preg_replace('/^(' . $blacklist . ')$/Su', '', $string);
     }
     if (!$indexation) {
         // search for aliases for each word of the query
         foreach ($words as $word) {
             if (!in_array($word, $processed_words)) {
                 $alias = new Alias(null, $word);
                 if (Validate::isLoadedObject($alias)) {
                     $processed_words[] = $alias->search;
                 } else {
                     $processed_words[] = $word;
                 }
             }
         }
         $string = implode(' ', $processed_words);
     }
     if ($indexation) {
         $minWordLen = (int) Configuration::get('PS_SEARCH_MINWORDLEN');
         if ($minWordLen > 1) {
             $minWordLen -= 1;
             $string = preg_replace('/(?<=\\s)[^\\s]{1,' . $minWordLen . '}(?=\\s)/Su', ' ', $string);
             $string = preg_replace('/^[^\\s]{1,' . $minWordLen . '}(?=\\s)/Su', '', $string);
             $string = preg_replace('/(?<=\\s)[^\\s]{1,' . $minWordLen . '}$/Su', '', $string);
             $string = preg_replace('/^[^\\s]{1,' . $minWordLen . '}$/Su', '', $string);
         }
     }
     $string = trim(preg_replace('/\\s+/', ' ', $string));
     return $string;
 }
 public function preProcess()
 {
     parent::preProcess();
     $customer = new Customer((int) self::$cookie->id_customer);
     if (sizeof($_POST)) {
         $exclusion = array('secure_key', 'old_passwd', 'passwd', 'active', 'date_add', 'date_upd', 'last_passwd_gen', 'newsletter_date_add', 'id_default_group');
         $fields = $customer->getFields();
         foreach ($fields as $key => $value) {
             if (!in_array($key, $exclusion)) {
                 $customer->{$key} = key_exists($key, $_POST) ? trim($_POST[$key]) : 0;
             }
         }
     }
     if (isset($_POST['years']) and isset($_POST['months']) and isset($_POST['days'])) {
         $customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
     }
     if (Tools::isSubmit('submitIdentity')) {
         if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) and !(Tools::getValue('months') == '' and Tools::getValue('days') == '' and Tools::getValue('years') == '')) {
             $this->errors[] = Tools::displayError('Invalid date of birth');
         } else {
             $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
             $_POST['old_passwd'] = trim($_POST['old_passwd']);
             if (empty($_POST['old_passwd']) or Tools::encrypt($_POST['old_passwd']) != self::$cookie->passwd) {
                 $this->errors[] = Tools::displayError('Your password is incorrect.');
             } elseif ($_POST['passwd'] != $_POST['confirmation']) {
                 $this->errors[] = Tools::displayError('Password and confirmation do not match');
             } else {
                 $prev_id_default_group = $customer->id_default_group;
                 $this->errors = $customer->validateControler();
             }
             if (!sizeof($this->errors)) {
                 $customer->id_default_group = (int) $prev_id_default_group;
                 $customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname));
                 if (Tools::getValue('passwd')) {
                     self::$cookie->passwd = $customer->passwd;
                 }
                 if ($customer->update()) {
                     self::$cookie->customer_lastname = $customer->lastname;
                     self::$cookie->customer_firstname = $customer->firstname;
                     self::$smarty->assign('confirmation', 1);
                 } else {
                     $this->errors[] = Tools::displayError('Cannot update information');
                 }
             }
         }
     } else {
         $_POST = array_map('stripslashes', $customer->getFields());
     }
     if ($customer->birthday) {
         $birthday = explode('-', $customer->birthday);
     } else {
         $birthday = array('-', '-', '-');
     }
     /* Generate years, months and days */
     self::$smarty->assign(array('years' => Tools::dateYears(), 'sl_year' => $birthday[0], 'months' => Tools::dateMonths(), 'sl_month' => $birthday[1], 'days' => Tools::dateDays(), 'sl_day' => $birthday[2], 'errors' => $this->errors));
     self::$smarty->assign('newsletter', (int) Module::getInstanceByName('blocknewsletter')->active);
 }
 public function __construct($params, $object)
 {
     $this->Expeditions = $params['Expeditions'];
     $this->_mondialrelay = $object;
     $this->_webServiceKey = $this->_mondialrelay->account_shop['MR_KEY_WEBSERVICE'];
     $this->_markCode = $this->_mondialrelay->account_shop['MR_CODE_MARQUE'];
     $this->class_name = Tools::strtolower($this->class_name);
     $this->_webserviceURL = MondialRelay::MR_URL . 'webservice/Web_Services.asmx?WSDL';
 }
Example #18
0
    public function hookTop($params)
    {
        if (!isset($_SERVER['HTTP_REFERER']) || strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost(false, false))) {
            return;
        }
        if ($keywords = $this->getKeywords($_SERVER['HTTP_REFERER'])) {
            Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'sekeyword` (`keyword`, `date_add`, `id_shop`, `id_shop_group`)
										VALUES (\'' . pSQL(Tools::strtolower(trim($keywords))) . '\', NOW(), ' . (int) $this->context->shop->id . ', ' . (int) $this->context->shop->id_shop_group . ')');
        }
    }
Example #19
0
 private function getallheaders()
 {
     $headers = '';
     foreach ($_SERVER as $name => $value) {
         if (Tools::substr($name, 0, 5) == 'HTTP_') {
             $headers[str_replace(' ', '-', ucwords(Tools::strtolower(str_replace('_', ' ', Tools::substr($name, 5)))))] = $value;
         }
     }
     return $headers;
 }
Example #20
0
 /**
  * Get tab id
  * Using tab mapper for getting current features tab
  * @remark There is no in prestashop one point, where tab fetched from query_string
  * Here, probably, better to use global variable $tab instead of repeat fetched this query_string 
  *
  * @return integer tab id
  */
 public static function getCurrentTabId()
 {
     $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
         SELECT `id_tab` FROM `' . _DB_PREFIX_ . 'tab` WHERE LOWER(class_name)=\'' . pSQL(Tools::strtolower(self::exfeaturesMap(Tools::getValue('tab')))) . '\'
     ');
     if ($result) {
         return $result['id_tab'];
     }
     return -1;
 }
 /**
  * set a property
  * @param string $name property's name (case insensitive)
  * @param mixed $value property's value
  */
 public function __set($name, $value)
 {
     $setter = 'set' . $name;
     if (method_exists($this, $setter)) {
         $this->{$setter}($value);
     } else {
         $name = Tools::strtolower($name);
         $this->_properties[$name] = $value;
     }
 }
 public function initContent()
 {
     if (!Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) {
         // You can uncomment these lines if you want to force https even from localhost and automatically redirect
         // header('HTTP/1.1 301 Moved Permanently');
         // header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']);
         // exit();
         $clientIsMaintenanceOrLocal = in_array(Tools::getRemoteAddr(), array_merge(array('127.0.0.1'), explode(',', Configuration::get('PS_MAINTENANCE_IP'))));
         // If ssl is enabled, https protocol is required. Exception for maintenance and local (127.0.0.1) IP
         if ($clientIsMaintenanceOrLocal) {
             $warningSslMessage = Tools::displayError('SSL is activated. However, your IP is allowed to enter unsecure mode for maintenance or local IP issues.');
         } else {
             $url = 'https://' . Tools::safeOutput(Tools::getServerName()) . Tools::safeOutput($_SERVER['REQUEST_URI']);
             $warningSslMessage = sprintf(Translate::ppTags(Tools::displayError('SSL is activated. Please connect using the following link to [1]log into secure mode (https://)[/1]', false), array('<a href="%s">')), $url);
         }
         $this->context->smarty->assign('warningSslMessage', $warningSslMessage);
     }
     if (file_exists(_PS_ADMIN_DIR_ . '/../install')) {
         $this->context->smarty->assign('wrong_install_name', true);
     }
     if (basename(_PS_ADMIN_DIR_) == 'admin' && file_exists(_PS_ADMIN_DIR_ . '/../admin/')) {
         $rand = 'admin' . sprintf('%03d', rand(0, 999)) . Tools::strtolower(Tools::passwdGen(6)) . '/';
         if (@rename(_PS_ADMIN_DIR_ . '/../admin/', _PS_ADMIN_DIR_ . '/../' . $rand)) {
             Tools::redirectAdmin('../' . $rand);
         } else {
             $this->context->smarty->assign(array('wrong_folder_name' => true));
         }
     } else {
         $rand = basename(_PS_ADMIN_DIR_) . '/';
     }
     $this->context->smarty->assign(array('randomNb' => $rand, 'adminUrl' => Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . __PS_BASE_URI__ . $rand));
     // Redirect to admin panel
     if (Tools::isSubmit('redirect') && Validate::isControllerName(Tools::getValue('redirect'))) {
         $this->context->smarty->assign('redirect', Tools::getValue('redirect'));
     } else {
         $tab = new Tab((int) $this->context->employee->default_tab);
         $this->context->smarty->assign('redirect', $this->context->link->getAdminLink($tab->class_name));
     }
     if ($nb_errors = count($this->errors)) {
         $this->context->smarty->assign(array('errors' => $this->errors, 'nbErrors' => $nb_errors, 'shop_name' => Tools::safeOutput(Configuration::get('PS_SHOP_NAME')), 'disableDefaultErrorOutPut' => true));
     }
     if ($email = Tools::getValue('email')) {
         $this->context->smarty->assign('email', $email);
     }
     if ($password = Tools::getValue('password')) {
         $this->context->smarty->assign('password', $password);
     }
     $this->setMedia();
     $this->initHeader();
     parent::initContent();
     $this->initFooter();
     //force to disable modals
     $this->context->smarty->assign('modals', null);
 }
Example #23
0
 public function hookPayment()
 {
     if (!$this->active) {
         return;
     }
     $cart = $this->context->cart;
     $stripe = array('secret_key' => (string) Configuration::get('STRIPE_SECRET_KEY'), 'publishable_key' => (string) Configuration::get('STRIPE_PUBLISHABLE_KEY'));
     \Stripe\Stripe::setApiKey((string) Configuration::get('STRIPE_SECRET_KEY'));
     $this->context->smarty->assign(array('stripe_key' => $stripe['publishable_key'], 'currency' => Tools::strtolower($this->context->currency->iso_code), 'total_amount' => (int) ($cart->getOrderTotal(true, CART::BOTH) * 100)));
     return $this->display(__FILE__, 'payment.tpl');
 }
 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;
     }
 }
Example #25
0
    public function hookTop($params)
    {
        if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], Tools::getHttpHost(false, false) == 0)) {
            return;
        }
        if ($keywords = $this->getKeywords($_SERVER['HTTP_REFERER'])) {
            Db::getInstance()->Execute('
			INSERT INTO `' . _DB_PREFIX_ . 'sekeyword` (`keyword`, `date_add`)
			VALUES (\'' . pSQL(Tools::strtolower(trim($keywords))) . '\', NOW())');
        }
    }
Example #26
0
 public function renderForm($data)
 {
     $helper = $this->getFormHelper();
     $fields = array();
     foreach (self::$networks as $network) {
         $fields[] = array('type' => 'switch', 'label' => $network, 'name' => 'PS_SC_' . Tools::strtoupper($network), 'values' => array(array('id' => Tools::strtolower($network) . '_active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => Tools::strtolower($network) . '_active_off', 'value' => 0, 'label' => $this->l('Disabled'))));
     }
     $this->fields_form[1]['form'] = array('legend' => array('title' => $this->l('Widget Separator Form.')), 'input' => $fields, 'submit' => array('title' => $this->l('Save'), 'class' => 'button'));
     $default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
     $helper->tpl_vars = array('fields_value' => $this->getConfigFieldsValues($data), 'languages' => Context::getContext()->controller->getLanguages(), 'id_language' => $default_lang);
     return $helper->generateForm($this->fields_form);
 }
 public function __construct($params, $object)
 {
     $this->_orderListId = $params['orderIdList'];
     $this->_totalOrder = $params['totalOrder'];
     $this->_weightList = $params['weightList'];
     $this->_insuranceList = isset($params['insuranceList']) ? $params['insuranceList'] : '';
     $this->_mondialrelay = $object;
     $this->_webServiceKey = $this->_mondialrelay->account_shop['MR_KEY_WEBSERVICE'];
     $this->_markCode = $this->_mondialrelay->account_shop['MR_CODE_MARQUE'];
     $this->class_name = Tools::strtolower($this->class_name);
     $this->_webserviceURL = MondialRelay::MR_URL . 'webservice/Web_Services.asmx?WSDL';
 }
Example #28
0
 public function renderForm($args, $data)
 {
     $helper = $this->getFormHelper();
     $align = array(array('id' => 'separator_align_center', 'name' => $this->l('Align center')), array('id' => 'separator_align_left', 'name' => $this->l('Align left')), array('id' => 'separator_align_right', 'name' => $this->l('Align right')));
     $fields = array();
     foreach (self::$networks as $network) {
         $fields[] = array('type' => 'switch', 'label' => $network, 'name' => 'PS_SC_' . Tools::strtoupper($network), 'values' => array(array('id' => Tools::strtolower($network) . '_active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => Tools::strtolower($network) . '_active_off', 'value' => 0, 'label' => $this->l('Disabled'))));
     }
     $this->fields_form[1]['form'] = array('legend' => array('title' => $this->l('Widget Separator Form.')), 'input' => $fields, 'submit' => array('title' => $this->l('Save'), 'class' => 'button'));
     $default_lang = (int) $this->config->get('config_language_id');
     $helper->tpl_vars = array('fields_value' => $this->getConfigFieldsValues($data), 'id_language' => $default_lang);
     return $helper->generateForm($this->fields_form);
 }
 /**
  * Creating another new report is allowed only on this conditions
  * @return boolean
  */
 public function canCreateNew()
 {
     if (!$this->exists()) {
         return true;
     }
     $status = $this->getStatus();
     if (Tools::strtolower($status) == 'terminated') {
         return true;
     }
     if ($status == 'Problem reported') {
         return true;
     }
     return false;
 }
 /**
  * Start forms process
  * @see FrontController::postProcess()
  */
 public function postProcess()
 {
     $origin_newsletter = (bool) $this->customer->newsletter;
     if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days'])) {
         $this->customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
     }
     if (Tools::isSubmit('submitIdentity')) {
         if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '')) {
             $this->errors[] = Tools::displayError('Invalid date of birth.');
         } else {
             $email = trim(Tools::getValue('email'));
             $this->customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
             if (isset($_POST['old_passwd'])) {
                 $_POST['old_passwd'] = trim($_POST['old_passwd']);
             }
             if (!Validate::isEmail($email)) {
                 $this->errors[] = Tools::displayError('This email address is not valid');
             } elseif ($this->customer->email != $email && Customer::customerExists($email, true)) {
                 $this->errors[] = Tools::displayError('An account using this email address has already been registered.');
             } elseif (!isset($_POST['old_passwd']) || empty($_POST['old_passwd']) || Tools::encrypt($_POST['old_passwd']) != $this->context->cookie->passwd) {
                 $this->errors[] = Tools::displayError('The password you entered is incorrect.');
             } elseif ($_POST['passwd'] != $_POST['confirmation']) {
                 $this->errors[] = Tools::displayError('The password and confirmation do not match.');
             } else {
                 $prev_id_default_group = $this->customer->id_default_group;
                 // Merge all errors of this file and of the Object Model
                 $this->errors = array_merge($this->errors, $this->customer->validateController());
             }
             if (!count($this->errors)) {
                 $this->customer->id_default_group = (int) $prev_id_default_group;
                 $this->customer->firstname = Tools::ucfirst(Tools::strtolower($this->customer->firstname));
                 if (!isset($_POST['newsletter'])) {
                     $this->customer->newsletter = 0;
                 } elseif (!$origin_newsletter && isset($_POST['newsletter'])) {
                     if ($module_newsletter = Module::getInstanceByName('blocknewsletter')) {
                         if ($module_newsletter->active) {
                             $module_newsletter->confirmSubscription($this->customer->email);
                         }
                     }
                 }
                 if (!isset($_POST['optin'])) {
                     $this->customer->optin = 0;
                 }
                 if (Tools::getValue('passwd')) {
                     $this->context->cookie->passwd = $this->customer->passwd;
                 }
                 if ($this->customer->update()) {
                     $this->context->cookie->customer_lastname = $this->customer->lastname;
                     $this->context->cookie->customer_firstname = $this->customer->firstname;
                     $this->context->smarty->assign('confirmation', 1);
                 } else {
                     $this->errors[] = Tools::displayError('The information cannot be updated.');
                 }
             }
         }
     } else {
         $_POST = array_map('stripslashes', $this->customer->getFields());
     }
     return $this->customer;
 }