* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class HelpAccessCore { const URL = 'http://help.prestashop.com'; protected static $_images = array(0 => 'none', 1 => 'help2.png', 2 => 'help-new.png'); public static function trackClick($label, $version) { Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'help_access` (`label`, `version`) VALUES (\''.pSQL($label).'\',\''.pSQL($version).'\') ON DUPLICATE KEY UPDATE `version` = \''.pSQL($version).'\' '); } public static function getVersion($label) { return Db::getInstance()->getValue(' SELECT `version` FROM `'._DB_PREFIX_.'help_access` WHERE `label` = \''.pSQL($label).'\' '); } public static function retrieveInfos($label, $iso_lang, $country, $version) { $image = self::$_images[0]; $tooltip = ''; $url = HelpAccess::URL.'/documentation/renderIcon?label='.$label.'&iso_lang='.$iso_lang.'&country='.$country.'&version='.$version; $ctx = stream_context_create(array( 'http' => array( 'timeout' => 10 ) )); $res = @file_get_contents($url, 0, $ctx); $infos = preg_split('/\|/', $res); if (sizeof($infos) > 0) { $version = trim($infos[0]); if (!empty($version)) { $image = self::$_images[1]; if (sizeof($infos) > 1) $tooltip = trim('|'.$infos[1]); } } $last_version = HelpAccess::getVersion($label); if (!empty($version) && $version != $last_version) $image = self::$_images[2]; return array('version' => $version, 'image' => $image, 'tooltip' => $tooltip); } public static function displayHelp($label, $iso_lang, $country, $ps_version) { $infos = HelpAccess::retrieveInfos($label, $iso_lang, $country, $ps_version); if (array_key_exists('image', $infos) && $infos['image'] != 'none') { echo ' '.Tools::displayError('HELP').' '; if (!empty($infos['tooltip'])) echo ' '; } } }