From 05c9f37e18ad79fce1262d53ff728e3a38d40381 Mon Sep 17 00:00:00 2001 From: optipic Date: Wed, 21 Jul 2021 20:29:31 +0300 Subject: [PATCH] v1.19.1 --- optipic/classes/ImgUrlConverter.php | 389 +++++++++++++++------------- optipic/config.xml | 2 +- optipic/config_ru.xml | 13 - optipic/optipic.php | 9 +- optipic/views/index.php | 11 + optipic/views/js/index.php | 11 + optipic/{ => views}/js/settings.js | 11 + 7 files changed, 249 insertions(+), 197 deletions(-) delete mode 100644 optipic/config_ru.xml create mode 100644 optipic/views/index.php create mode 100644 optipic/views/js/index.php rename optipic/{ => views}/js/settings.js (66%) diff --git a/optipic/classes/ImgUrlConverter.php b/optipic/classes/ImgUrlConverter.php index eeef2e1..192cc37 100644 --- a/optipic/classes/ImgUrlConverter.php +++ b/optipic/classes/ImgUrlConverter.php @@ -1,17 +1,17 @@ 0) { + public function __construct($config = array()) + { + if (is_array($config) && count($config)>0) { self::loadConfig($config); } } @@ -62,7 +63,8 @@ public function __construct($config=array()) { /** * Convert whole HTML-block contains image urls */ - public static function convertHtml($content) { + public static function convertHtml($content) + { $timeStart = microtime(true); @@ -71,144 +73,144 @@ public static function convertHtml($content) { $content = self::removeBomFromUtf($content); // try auto load config from __DIR__.'config.php' - if(empty(self::$siteId)) { + if (empty(self::$siteId)) { self::loadConfig(); } - if(empty(self::$siteId)) { + if (empty(self::$siteId)) { return $content; } - if(!self::isEnabled()) { + if (!self::isEnabled()) { return $content; } $gziped = false; - if(self::isGz($content)) { - if($contentUngzip = gzdecode($content)) { + if (self::isGz($content)) { + if ($contentUngzip = gzdecode($content)) { $gziped = true; $content = $contentUngzip; } } self::$baseUrl = self::getBaseUrlFromHtml($content); - if(self::$baseUrl) { + if (self::$baseUrl) { self::$baseUrl = parse_url(self::$baseUrl, PHP_URL_PATH); } - //if(self::isBinary($content)) { + //if (self::isBinary($content)) { // return $content; //} /*$domains = self::$domains; - if(!is_array($domains)) { + if (!is_array($domains)) { $domains = array(); } $domains = array_merge(array(''), $domains); - + $hostsForRegexp = array(); - foreach($domains as $domain) { + foreach ($domains as $domain) { //$domain = str_replace(".", "\.", $domain); - if($domain && stripos($domain, 'http://')!==0 && stripos($domain, 'https://')!==0) { + if ($domain && stripos($domain, 'http://')!==0 && stripos($domain, 'https://')!==0) { $hostsForRegexp[] = 'http://'.$domain; $hostsForRegexp[] = 'https://'.$domain; } else { $hostsForRegexp[] = $domain; } - + }*/ - //foreach($hostsForRegexp as $host) { + //foreach ($hostsForRegexp as $host) { /*$firstPartsOfUrl = array(); - foreach(self::$whitelistImgUrls as $whiteImgUrl) { - if(self::substr($whiteImgUrl, -1, 1)=='/') { + foreach (self::$whitelistImgUrls as $whiteImgUrl) { + if (self::substr($whiteImgUrl, -1, 1)=='/') { $whiteImgUrl = self::substr($whiteImgUrl, 0, -1); } $firstPartsOfUrl[] = preg_quote($host.$whiteImgUrl, '#'); } - if(count($firstPartsOfUrl)==0) { + if (count($firstPartsOfUrl)==0) { $firstPartsOfUrl[] = preg_quote($host, '#'); } //var_dump($firstPartsOfUrl); //$host = preg_quote($host, '#'); //var_dump(self::$whitelistImgUrls); - + $host = implode('|', $firstPartsOfUrl); var_dump($host);*/ /*$firstPartsOfUrl = array(); - foreach(self::$whitelistImgUrls as $whiteImgUrl) { + foreach (self::$whitelistImgUrls as $whiteImgUrl) { $firstPartsOfUrl[] = preg_quote($whiteImgUrl, '#'); } - if(empty($firstPartsOfUrl)) { + if (empty($firstPartsOfUrl)) { $firstPartsOfUrl = array('/'); } - + $firstPartOfUrl = implode('|', $firstPartsOfUrl); */ - //$host = preg_quote($host, '#'); - $host = ''; - - //$firstPartOfUrl = '/'; - $firstPartOfUrl = ''; - - // -------------------------------------------- - // - // @see https://developer.mozilla.org/ru/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images - if(!empty(self::$srcsetAttrs)) { - // srcset|data-srcset|data-wpfc-original-srcset - $srcSetAttrsRegexp = array(); - foreach(self::$srcsetAttrs as $attr) { - $srcSetAttrsRegexp[] = preg_quote($attr, '#'); - } - $srcSetAttrsRegexp = implode('|', $srcSetAttrsRegexp); - //$content = preg_replace_callback('#<(?P[^\s]+)(?P.*?)\s+(?P'.$srcSetAttrsRegexp.')=(?P"|\')(?P[^"]+?)(?P"|\')(?P[^>]*?)>#siS', array(__NAMESPACE__ .'\ImgUrlConverter', 'callbackForPregReplaceSrcset'), $content); - $contentAfterReplace = preg_replace_callback('#<(?Psource|img|picture)(?P[^>]*)\s+(?P'.$srcSetAttrsRegexp.')=(?P"|\')(?P[^"\']+?)(?P"|\')(?P[^>]*)>#siS', array(__NAMESPACE__ .'\ImgUrlConverter', 'callbackForPregReplaceSrcset'), $content); - if(!empty($contentAfterReplace)) { - $content = $contentAfterReplace; - } + //$host = preg_quote($host, '#'); + $host = ''; + + //$firstPartOfUrl = '/'; + $firstPartOfUrl = ''; + + // -------------------------------------------- + // + // @see https://developer.mozilla.org/ru/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images + if (!empty(self::$srcsetAttrs)) { + // srcset|data-srcset|data-wpfc-original-srcset + $srcSetAttrsRegexp = array(); + foreach (self::$srcsetAttrs as $attr) { + $srcSetAttrsRegexp[] = preg_quote($attr, '#'); } - // -------------------------------------------- - - //$regexp = '#("|\'|\()'.$host.'('.$firstPartOfUrl.'[^/"\'\s]{1}[^"\']*\.(png|jpg|jpeg){1}(\?.*?)?)("|\'|\))#siS'; - - // from 1.10 version - //$regexp = '#("|\'|\()'.$host.'('.$firstPartOfUrl.'[^"|\'|\)\(]+\.(png|jpg|jpeg){1}(\?.*?)?)("|\'|\))#siS'; - - $urlBorders = array( - array('"', '"'), // "" - array('\'', '\''), // '' - array('\(', '\)'), // () - ); - - $cdnDomains = array( - 'cdn.optipic.io', - ); - - $cdnDomains[] = self::$cdnDomain; - $cdnDomains = array_unique($cdnDomains); - - $cdnDomainsForRegexp = array(); - foreach($cdnDomains as $cdnDomain) { - $cdnDomainsForRegexp[] = '\/\/'.preg_quote($cdnDomain, '#'); - } - $cdnDomainsForRegexp = implode("|", $cdnDomainsForRegexp); - - $regexp = array(); - foreach($urlBorders as $border) { - $regexp[] = '#('.$border[0].')'.$host.'('.$firstPartOfUrl.'(?!'.$cdnDomainsForRegexp.')[^'.$border[1].']+\.(png|jpg|jpeg){1}(\?[^"\'\s]*?)?)('.$border[1].')#siS'; - } - //var_dump($regexp);exit; - - //$regexp = str_replace('//', '/'); - - //$content = preg_replace($regexp, '${1}//cdn.optipic.io/site-'.self::$siteId.'${2}${5}', $content); - $contentAfterReplace = preg_replace_callback($regexp, array(__NAMESPACE__ .'\ImgUrlConverter', 'callbackForPregReplace'), $content); - if(!empty($contentAfterReplace)) { + $srcSetAttrsRegexp = implode('|', $srcSetAttrsRegexp); + //$content = preg_replace_callback('#<(?P[^\s]+)(?P.*?)\s+(?P'.$srcSetAttrsRegexp.')=(?P"|\')(?P[^"]+?)(?P"|\')(?P[^>]*?)>#siS', array(__NAMESPACE__ .'\ImgUrlConverter', 'callbackForPregReplaceSrcset'), $content); + $contentAfterReplace = preg_replace_callback('#<(?Psource|img|picture)(?P[^>]*)\s+(?P'.$srcSetAttrsRegexp.')=(?P"|\')(?P[^"\']+?)(?P"|\')(?P[^>]*)>#siS', array(__NAMESPACE__ .'\ImgUrlConverter', 'callbackForPregReplaceSrcset'), $content); + if (!empty($contentAfterReplace)) { $content = $contentAfterReplace; } + } + // -------------------------------------------- + + //$regexp = '#("|\'|\()'.$host.'('.$firstPartOfUrl.'[^/"\'\s]{1}[^"\']*\.(png|jpg|jpeg){1}(\?.*?)?)("|\'|\))#siS'; + + // from 1.10 version + //$regexp = '#("|\'|\()'.$host.'('.$firstPartOfUrl.'[^"|\'|\)\(]+\.(png|jpg|jpeg){1}(\?.*?)?)("|\'|\))#siS'; + + $urlBorders = array( + array('"', '"'), // "" + array('\'', '\''), // '' + array('\(', '\)'), // () + ); + + $cdnDomains = array( + 'cdn.optipic.io', + ); + + $cdnDomains[] = self::$cdnDomain; + $cdnDomains = array_unique($cdnDomains); + + $cdnDomainsForRegexp = array(); + foreach ($cdnDomains as $cdnDomain) { + $cdnDomainsForRegexp[] = '\/\/'.preg_quote($cdnDomain, '#'); + } + $cdnDomainsForRegexp = implode("|", $cdnDomainsForRegexp); + + $regexp = array(); + foreach ($urlBorders as $border) { + $regexp[] = '#('.$border[0].')'.$host.'('.$firstPartOfUrl.'(?!'.$cdnDomainsForRegexp.')[^'.$border[1].']+\.(png|jpg|jpeg){1}(\?[^"\'\s]*?)?)('.$border[1].')#siS'; + } + //var_dump($regexp);exit; + + //$regexp = str_replace('//', '/'); + + //$content = preg_replace($regexp, '${1}//cdn.optipic.io/site-'.self::$siteId.'${2}${5}', $content); + $contentAfterReplace = preg_replace_callback($regexp, array(__NAMESPACE__ .'\ImgUrlConverter', 'callbackForPregReplace'), $content); + if (!empty($contentAfterReplace)) { + $content = $contentAfterReplace; + } //} @@ -216,12 +218,12 @@ public static function convertHtml($content) { $content = str_replace('', '' . PHP_EOL . self::getPreloadTags(), $content); - if($gziped) { + if ($gziped) { $content = gzencode($content); // modify Content-Length if it's already sent $headersList = self::getResponseHeadersList(); - if(is_array($headersList) && !empty($headersList['Content-Length'])) { + if (is_array($headersList) && !empty($headersList['Content-Length'])) { header('Content-Length: ' . self::strlen($content)); } } @@ -234,33 +236,35 @@ public static function convertHtml($content) { - public static function getPreloadTags() { + public static function getPreloadTags() + { return '' . PHP_EOL . ''; } - public static function trimList($list) { + public static function trimList($list) + { $trimmed = array(); - foreach ($list as $ind => $item) { + foreach ($list as $item) { $item = trim(str_replace(array("\r\n", "\n", "\r"), '', $item)); - if(!empty($item)) { + if (!empty($item)) { $trimmed[] = $item; } } return $trimmed; } - public static function textToArray($data) { - if(is_array($data)) { + public static function textToArray($data) + { + if (is_array($data)) { $array = $data; - } - else { - $array = explode("\n", $data); + } else { + $array = explode("\n", $data); } - if(!is_array($array)) { + if (!is_array($array)) { $array = array(); } $array = self::trimList($array); @@ -274,12 +278,13 @@ public static function textToArray($data) { /** * Load config from file or array */ - public static function loadConfig($source=false) { - if($source===false) { - $source = __DIR__ . '/config.php'; + public static function loadConfig($source = false) + { + if ($source===false) { + $source = dirname(__FILE__) . '/config.php'; } - if(is_array($source)) { + if (is_array($source)) { self::$siteId = $source['site_id']; self::$domains = self::textToArray($source['domains']); @@ -290,23 +295,22 @@ public static function loadConfig($source=false) { self::$srcsetAttrs = self::textToArray($source['srcset_attrs']); - if(isset($source['admin_key'])) { + if (isset($source['admin_key'])) { self::$adminKey = $source['admin_key']; } - if(isset($source['log'])) { - if($source['log']) { + if (isset($source['log'])) { + if ($source['log']) { self::$enableLog = true; } } - if(!empty($source['cdn_domain'])) { + if (!empty($source['cdn_domain'])) { self::$cdnDomain = $source['cdn_domain']; } - } - elseif(file_exists($source)) { + } elseif (file_exists($source)) { $config = require($source); - if(is_array($config)) { + if (is_array($config)) { self::$configFullPath = $source; self::loadConfig($config); } @@ -316,16 +320,17 @@ public static function loadConfig($source=false) { /** * Check if convertation enabled on current URL */ - public static function isEnabled() { + public static function isEnabled() + { $url = $_SERVER['REQUEST_URI']; - if(in_array($url, self::$exclusionsUrl)) { + if (in_array($url, self::$exclusionsUrl)) { return false; } // check rules with mask - foreach(self::$exclusionsUrl as $exclUrl) { - if(self::substr($exclUrl, -1)=='*') { + foreach (self::$exclusionsUrl as $exclUrl) { + if (self::substr($exclUrl, -1)=='*') { $regexp = "#^".self::substr($exclUrl, 0, -1)."#i"; - if(preg_match($regexp, $url)) { + if (preg_match($regexp, $url)) { return false; } } @@ -336,12 +341,13 @@ public static function isEnabled() { /** * Callback-function for preg_replace() to replace image URLs */ - public static function callbackForPregReplace($matches) { + public static function callbackForPregReplace($matches) + { self::log($matches, 'callbackForPregReplace -> $matches'); $replaceWithoutOptiPic = $matches[0]; // skip images from json (json-encoded) - if(stripos($replaceWithoutOptiPic, "\\/")!==false) { + if (stripos($replaceWithoutOptiPic, "\\/")!==false) { return $replaceWithoutOptiPic; } @@ -349,21 +355,21 @@ public static function callbackForPregReplace($matches) { $parseUrl = parse_url($urlOriginal); - if(!empty($parseUrl['host'])) { - if(!in_array($parseUrl['host'], self::$domains)) { + if (!empty($parseUrl['host'])) { + if (!in_array($parseUrl['host'], self::$domains)) { self::log($urlOriginal, 'callbackForPregReplace -> url original:'); self::log($replaceWithoutOptiPic, 'callbackForPregReplace -> url with optipic:'); return $replaceWithoutOptiPic; } } - $ext = strtolower(pathinfo($parseUrl['path'], PATHINFO_EXTENSION)); - if(!in_array($ext, array('png', 'jpg', 'jpeg'))) { - return $replaceWithoutOptiPic; + $ext = self::strtolower(pathinfo($parseUrl['path'], PATHINFO_EXTENSION)); + if (!in_array($ext, array('png', 'jpg', 'jpeg'))) { + return $replaceWithoutOptiPic; } $urlOriginal = $parseUrl['path']; - if(!empty($parseUrl['query'])) { + if (!empty($parseUrl['query'])) { $urlOriginal .= '?'.$parseUrl['query']; } $urlOriginal = self::getUrlFromRelative($urlOriginal, self::$baseUrl); @@ -374,73 +380,74 @@ public static function callbackForPregReplace($matches) { self::log($urlOriginal, 'callbackForPregReplace -> url original:'); self::log($replaceWithOptiPic, 'callbackForPregReplace -> url with optipic:'); - if(self::substr($urlOriginal, 0, 7)=='http://') { + if (self::substr($urlOriginal, 0, 7)=='http://') { return $replaceWithoutOptiPic; } - if(self::substr($urlOriginal, 0, 8)=='https://') { + if (self::substr($urlOriginal, 0, 8)=='https://') { return $replaceWithoutOptiPic; } - if(self::substr($urlOriginal, 0, 2)=='//') { + if (self::substr($urlOriginal, 0, 2)=='//') { return $replaceWithoutOptiPic; } - if(empty(self::$whitelistImgUrls)) { + if (empty(self::$whitelistImgUrls)) { return $replaceWithOptiPic; } - if(in_array($urlOriginal, self::$whitelistImgUrls)) { + if (in_array($urlOriginal, self::$whitelistImgUrls)) { return $replaceWithOptiPic; } - foreach(self::$whitelistImgUrls as $whiteUrl) { - if(strpos($urlOriginal, $whiteUrl)===0) { + foreach (self::$whitelistImgUrls as $whiteUrl) { + if (strpos($urlOriginal, $whiteUrl)===0) { return $replaceWithOptiPic; } } return $replaceWithoutOptiPic; - } /** * Callback-function for preg_replace() to replace "srcset" attributes */ - public static function callbackForPregReplaceSrcset($matches) { + public static function callbackForPregReplaceSrcset($matches) + { $isConverted = false; $originalContent = $matches[0]; $listConverted = array(); $list = explode(",", $matches['set']); - foreach($list as $item) { + foreach ($list as $item) { $source = preg_split("/[\s,]+/siS", trim($item)); $url = trim($source[0]); $size = (isset($source[1]))? trim($source[1]): ''; $toConvertUrl = "(".$url.")"; $convertedUrl = self::convertHtml($toConvertUrl); - if($toConvertUrl!=$convertedUrl) { + if ($toConvertUrl!=$convertedUrl) { $isConverted = true; $listConverted[] = trim(self::substr($convertedUrl, 1, -1).' '.$size); } } - if($isConverted) { + if ($isConverted) { return '<'.$matches['tag'].$matches['prefix'].' '.$matches['attr'].'='.$matches['quote1'].implode(", ", $listConverted).$matches['quote2'].$matches['suffix'].'>'; - } - else { + } else { return $originalContent; } } - /*public static function isBinary($str) { + /*public static function isBinary($str) + { return preg_match('~[^\x20-\x7E\t\r\n]~', $str) > 0; }*/ /** * Remove UTF-8 BOM-symbol from text */ - public static function removeBomFromUtf($text) { - $bom = pack('H*','EFBBBF'); + public static function removeBomFromUtf($text) + { + $bom = pack('H*', 'EFBBBF'); $text = preg_replace("/^$bom/", '', $text); return $text; } @@ -448,24 +455,28 @@ public static function removeBomFromUtf($text) { /** * Check if gziped data */ - public static function isGz($str) { - if (self::strlen($str) < 2) return false; + public static function isGz($str) + { + if (self::strlen($str) < 2) { + return false; + } return (ord(self::substr($str, 0, 1)) == 0x1f && ord(self::substr($str, 1, 1)) == 0x8b); } - public static function getUrlFromRelative($relativeUrl, $baseUrl=false) { - if(stripos($relativeUrl, '../')!==false) { + public static function getUrlFromRelative($relativeUrl, $baseUrl = false) + { + if (stripos($relativeUrl, '../')!==false) { $relativeUrl = self::resolveFilename($relativeUrl); } - if(self::substr($relativeUrl, 0, 1)=='/') { + if (self::substr($relativeUrl, 0, 1)=='/') { return $relativeUrl; } - if(self::substr($relativeUrl, 0, 2)=='\/') { // for json-encoded urls when / --> \/ + if (self::substr($relativeUrl, 0, 2)=='\/') { // for json-encoded urls when / --> \/ return $relativeUrl; } - if(!$baseUrl) { + if (!$baseUrl) { //$baseUrl = pathinfo($_SERVER['REQUEST_URI'], PATHINFO_DIRNAME); $baseUrl = self::getBaseDirOfUrl($_SERVER['REQUEST_URI']); } @@ -477,12 +488,15 @@ public static function getUrlFromRelative($relativeUrl, $baseUrl=false) { - public static function resolveFilename($filename) { + public static function resolveFilename($filename) + { $filename = str_replace('//', '/', $filename); $parts = explode('/', $filename); $out = array(); - foreach ($parts as $part){ - if ($part == '.') continue; + foreach ($parts as $part) { + if ($part == '.') { + continue; + } if ($part == '..') { array_pop($out); continue; @@ -499,25 +513,26 @@ public static function resolveFilename($filename) { * * https://domain.com/catalog/catalog.php --> https://domain.com/catalog/ */ - public static function getBaseDirOfUrl($url) { + public static function getBaseDirOfUrl($url) + { $urlParsed = parse_url($url); - if(empty($urlParsed['path'])) { + if (empty($urlParsed['path'])) { return '/'; } $urlPath = $urlParsed['path']; $baseUrl = $urlPath; $pathinfo = pathinfo($urlPath); - if(!empty($pathinfo['extension'])) { + if (!empty($pathinfo['extension'])) { $baseUrl = $pathinfo['dirname']; } - if(stripos($url, $baseUrl.'/')!==false) { + if (stripos($url, $baseUrl.'/')!==false) { $baseUrl .= '/'; } - if(self::substr($baseUrl, -1)!='/') { + if (self::substr($baseUrl, -1)!='/') { $pathinfo = pathinfo($baseUrl); - if(!empty($pathinfo['dirname'])) { + if (!empty($pathinfo['dirname'])) { $baseUrl = $pathinfo['dirname']; } } @@ -525,27 +540,29 @@ public static function getBaseDirOfUrl($url) { return $baseUrl; } - public static function getBaseUrlFromHtml($html) { + public static function getBaseUrlFromHtml($html) + { preg_match('#(?P[^>]*)\s+href=(?P[^>\s]+)#isS', $html, $matches); $baseUrl = false; - if(!empty($matches['base_url'])) { + if (!empty($matches['base_url'])) { $baseUrl = trim($matches['base_url'], '"/'); $baseUrl = trim($baseUrl, "'"); $baseUrl = self::getBaseDirOfUrl($baseUrl); - /*if(self::strlen($baseUrl)>0 && self::substr($baseUrl, -1, 1)!='/') { + /*if (self::strlen($baseUrl)>0 && self::substr($baseUrl, -1, 1)!='/') { $baseUrl .= '/'; }*/ } return $baseUrl; } - public static function getResponseHeadersList() { + public static function getResponseHeadersList() + { $list = array(); $headersList = headers_list(); - if(is_array($headersList)) { - foreach($headersList as $row) { + if (is_array($headersList)) { + foreach ($headersList as $row) { list($headerKey, $headerValue) = explode(":", $row); $headerKey = trim($headerKey); $headerValue = trim($headerValue); @@ -561,44 +578,46 @@ public static function getResponseHeadersList() { /** * Log debug info into file */ - public static function log($data, $comment='') { - if(!self::$enableLog) { + public static function log($data, $comment = '') + { + if (!self::$enableLog) { return; } $date = \DateTime::createFromFormat('U.u', microtime(true)); - if(!$date) { + if (!$date) { $date = new \DateTime(); } $dateFormatted = $date->format("Y-m-d H:i:s u"); $line = "[$dateFormatted] {$_SERVER['REQUEST_URI']}\n"; - if($comment) { + if ($comment) { $line .= "# ".$comment."\n"; } $line .= var_export($data, true)."\n"; - file_put_contents(__DIR__ . '/log.txt', $line, FILE_APPEND); + file_put_contents(dirname(__FILE__) . '/log.txt', $line, FILE_APPEND); } - public static function getDefaultSettings($settingKey=false) { + public static function getDefaultSettings($settingKey = false) + { $settings = array( 'srcset_attrs' => array( - 'srcset', + 'srcset', 'data-srcset', ), 'domains' => array(), ); - if($currentDomain = self::getCurrentDomain(true)) { + if ($currentDomain = self::getCurrentDomain(true)) { $settings['domains'] = array( $currentDomain, 'www.'.$currentDomain, ); } - if($settingKey) { + if ($settingKey) { return (!empty($settings[$settingKey]))? $settings[$settingKey]: ''; } @@ -606,15 +625,16 @@ public static function getDefaultSettings($settingKey=false) { } - public static function getCurrentDomain($trimWww=false) { - if(empty($_SERVER['HTTP_HOST'])) { + public static function getCurrentDomain($trimWww = false) + { + if (empty($_SERVER['HTTP_HOST'])) { return false; } $currentHost = explode(":", $_SERVER['HTTP_HOST']); $currentHost = trim($currentHost[0]); - if($trimWww) { - if(stripos($currentHost, 'www.')===0) { + if ($trimWww) { + if (stripos($currentHost, 'www.')===0) { $currentHost = self::substr($currentHost, 4); } } @@ -623,16 +643,29 @@ public static function getCurrentDomain($trimWww=false) { } - public static function strlen($str) { + public static function strlen($str) + { + //return strlen($str); + return \Tools::strlen($str); } - public static function substr($string, $offset, $length = null) { - if(is_null($length)) { + public static function substr($string, $offset, $length = null) + { + //return substr($string, $offset, $length); + + if (is_null($length)) { $length = false; } return \Tools::substr($string, $offset, $length); } + + + public static function strtolower($str) + { + //return strtolower($str); + + return \Tools::strtolower($str); + } } -?> \ No newline at end of file diff --git a/optipic/config.xml b/optipic/config.xml index 8284a08..c2deb53 100644 --- a/optipic/config.xml +++ b/optipic/config.xml @@ -2,7 +2,7 @@ optipic - + diff --git a/optipic/config_ru.xml b/optipic/config_ru.xml deleted file mode 100644 index d9c44e0..0000000 --- a/optipic/config_ru.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - optipic - - - - - - - 1 - 0 - - \ No newline at end of file diff --git a/optipic/optipic.php b/optipic/optipic.php index ad1e7e7..c7ae666 100644 --- a/optipic/optipic.php +++ b/optipic/optipic.php @@ -29,7 +29,7 @@ class Optipic extends Module public function __construct() { $this->name = 'optipic'; - $this->version = '1.19.0'; + $this->version = '1.19.1'; $this->author = 'Optipic.io'; $this->tab = 'seo'; $this->need_instance = 0; @@ -219,11 +219,11 @@ public function displayForm() - if(empty($helper->fields_value[self::SRCSET_ATTRS])) { + if (empty($helper->fields_value[self::SRCSET_ATTRS])) { $helper->fields_value[self::SRCSET_ATTRS] = implode(PHP_EOL, \optipic\cdn\ImgUrlConverter::getDefaultSettings('srcset_attrs')); } - if(empty($helper->fields_value[self::DOMAINS])) { + if (empty($helper->fields_value[self::DOMAINS])) { $helper->fields_value[self::DOMAINS] = implode(PHP_EOL, \optipic\cdn\ImgUrlConverter::getDefaultSettings('domains')); } @@ -277,14 +277,13 @@ public function hookDisplayBackOfficeHeader(array $params = []) $settings = $this->getSettings(); if ($currentHost) { - Media::addJsDef(array( 'optipicCurrentHost' => $currentHost, 'optipicSid' => $settings['site_id'], 'optipicVersion' => $this->version, )); - $this->context->controller->addJS(_MODULE_DIR_ . $this->name . '/js/settings.js'); + $this->context->controller->addJS(_MODULE_DIR_ . $this->name . '/views/js/settings.js'); } } } diff --git a/optipic/views/index.php b/optipic/views/index.php new file mode 100644 index 0000000..53128f9 --- /dev/null +++ b/optipic/views/index.php @@ -0,0 +1,11 @@ + +* @copyright 2007-2021 OptiPic +* @license http://www.opensource.org/licenses/mit-license.html MIT License +*/ (function() { if(