]*href=(\"??)' . $base_exp . '([^\" >]*?)\\1[^>]*>(.*)<\/a>';
$isMultiLanguageActivated = Language::isMultiLanguageActivated();
if (preg_match_all("/$regexp/siU", $html, $matches, PREG_SET_ORDER)) {
// The links array will help us to remove duplicates
foreach ($matches as $match) {
// $match[2] = link address
// $match[3] = link text
// Insert backlinks that correspond to a possibily cached page into the database
$url = $match[2];
// Add leading /
if (strpos($url, "/") > 0 || strpos($url, "/") === false) {
$url = "/" . $url;
}
// Remove language part if any
$url_without_lang = $url;
if ($isMultiLanguageActivated && preg_match('#^/([a-z]{2})(?:/.*)?$#', $url, $m)) {
$url_without_lang = Tools::substr($url, 3);
}
$anchorPos = strpos($url_without_lang, '#');
if ($anchorPos !== false) {
$url_without_lang = Tools::substr($url_without_lang, 0, $anchorPos);
}
$bl_controller = JprestaUtilsDispatcher::getPageCacheInstance()->getControllerFromURL($url_without_lang);
if ($bl_controller === false) {
if (Module::isEnabled('smartseourl')) {
$bl_controller = self::getControllerFromURLSmartseourl($url_without_lang);
}
else {
// To avoid re-installation of override we have this workaround
$bl_controller = JprestaUtilsDispatcher::getPageCacheInstance()->getControllerFromURL('en' . $url_without_lang);
}
}
if (in_array($bl_controller, $managedControllers)) {
$links[$match[2]] = $base_relative . $match[2];
}
}
}
return $links;
}
}
/**
* @param string $url
* @param int $curl_timeout
* @param array $opts
*
* @return bool|string
*
* @throws Exception
*/
public static function file_get_contents_curl(
$url,
$curl_timeout,
$opts
) {
$content = false;
if (function_exists('curl_init')) {
if (method_exists('Tools', 'refreshCACertFile')) {
// Does not exist in some PS1.6
Tools::refreshCACertFile();
}
$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, $curl_timeout);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_CAINFO, _PS_CACHE_CA_CERT_FILE_);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
if ($opts != null) {
if (isset($opts['http']['method']) && Tools::strtolower($opts['http']['method']) == 'post') {
curl_setopt($curl, CURLOPT_POST, true);
if (isset($opts['http']['content'])) {
//parse_str($opts['http']['content'], $post_data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $opts['http']['content']);
}
}
}
$content = curl_exec($curl);
if (false === $content && _PS_MODE_DEV_) {
$errorMessage = sprintf('file_get_contents_curl failed to download %s : (error code %d) %s',
$url,
curl_errno($curl),
curl_error($curl)
);
throw new \Exception($errorMessage);
}
curl_close($curl);
}
return $content;
}
public static function getControllerFromURLSmartseourl($url)
{
static $smartseourl = null;
if ($smartseourl === null) {
$smartseourl = Module::getInstanceByName('smartseourl');
}
if (!file_exists($smartseourl->path_cache)) {
$smartseourl->createCacheFolders();
}
$request_uri = $url;
$rewrite = trim($request_uri, '/');
if (strpos($rewrite, '.html') > 0) {
$rewrite = explode('.html', $rewrite);
$rewrite = $rewrite[0];
}
$is_cache = $smartseourl->getDirectoryTree($smartseourl->path_cache, md5($rewrite));
if ($is_cache) {
if ($is_cache['type'] === 'cms_category') {
$is_cache['type'] = 'cms';
}
return $is_cache['type'];
} else {
$context = Context::getContext();
$result = SSURewriteClass::getBy($rewrite, null, $context->language->id, $context->shop->id);
if ($result) {
return $result['table_type'];
}
}
return false;
}
public static function decodeConfiguration($value) {
if ($value) {
$value = str_replace('<', '<', $value);
}
return $value;
}
public static function encodeConfiguration($value) {
if ($value) {
$value = str_replace('<', '<', $value);
}
return $value;
}
public static function parseCSS($html, $base) {
$links = array();
$base_exp = preg_replace('/([^a-zA-Z0-9])/', '\\\\$1', $base);
$regexp = ']*href=(\"??)[^\" >]*' . $base_exp . '([^\" >]*?)\\1[^>]*>';
if(preg_match_all("/$regexp/siU", $html, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
$links[] = $match[2];
}
}
return $links;
}
public static function parseJS($html, $base) {
$links = array();
$base_exp = preg_replace('/([^a-zA-Z0-9])/', '\\\\$1', $base);
$regexp = '