diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0321eab --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +language: php +sudo: false +php: + - 5.6 + - 7.0 + - 7.1 + - hhvm + +cache: + directories: + - vendor + - $HOME/.composer/cache + +before_script: + - composer install + +script: vendor/bin/phpunit --coverage-clover=coverage.xml + +after_script: + - bash -c 'if [ "$TRAVIS_PHP_VERSION" == "5.6" ] ; then php ocular.phar code-coverage:upload --format=php-clover coverage.xml; fi;' diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..525cb71 --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "soukicz/urltolink", + "description": "Convert URLs in HTML to links", + "minimum-stability": "stable", + "license": "MIT", + "keywords": [], + "authors": [ + { + "name": "Petr Soukup", + "email": "soukup@simplia.cz" + } + ], + "require": { + "php": ">=5.6.0" + }, + "require-dev": { + "phpunit/phpunit": "~5.0" + }, + "autoload": { + "psr-4": { + "Soukicz\\UrlToLink\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Soukicz\\TestUrlToLink\\": "tests/" + } + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..de11982 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + ./tests/ + + + + + + vendor + + + + diff --git a/src/Processor.php b/src/Processor.php new file mode 100644 index 0000000..b542c95 --- /dev/null +++ b/src/Processor.php @@ -0,0 +1,28 @@ +.*?)~i', function (array $match) { + return '<<>>>'; + }, $html); + + $html = preg_replace_callback('~()~i', function (array $match) { + return '<<>>>'; + }, $html); + + $html = preg_replace_callback('~https?://[a-z0-9/.\?&=%#\[\]_+\-]+~i', function (array $match) { + return '' . $match[0] . ''; + }, $html); + + $html = preg_replace_callback('~<<<[ai]<(.*?)>>>>~', function (array $match) { + return base64_decode($match[1]); + }, $html); + + return $html; + } +} diff --git a/tests/ProcessorTest.php b/tests/ProcessorTest.php new file mode 100644 index 0000000..20daf69 --- /dev/null +++ b/tests/ProcessorTest.php @@ -0,0 +1,16 @@ +assertEquals( + 'abc https://www.jadi.cz/Damska-obuv/Kotnickova-obuv/Podzim-zima/?f[v][]=40&f[p][313][]=571&f[cena_do]=3170 def https://jadi.cz', + $link->convertUrlToLinksInHtml('abc https://www.jadi.cz/Damska-obuv/Kotnickova-obuv/Podzim-zima/?f[v][]=40&f[p][313][]=571&f[cena_do]=3170 def https://jadi.cz') + ); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..4fd7610 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,12 @@ +