-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8053523
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="true" | ||
backupStaticAttributes="false" | ||
bootstrap="./tests/bootstrap.php" | ||
colors="false" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="false" | ||
convertWarningsToExceptions="true" | ||
forceCoversAnnotation="false" | ||
|
||
processIsolation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
|
||
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader" | ||
verbose="false"> | ||
<testsuites> | ||
<testsuite name="Client"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<blacklist> | ||
<directory>vendor</directory> | ||
</blacklist> | ||
</filter> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
namespace Soukicz\UrlToLink; | ||
|
||
class Processor { | ||
/** | ||
* @param string $html | ||
* @return string | ||
*/ | ||
public function convertUrlToLinksInHtml($html) { | ||
$html = preg_replace_callback('~(<a .*?>.*?</a>)~i', function (array $match) { | ||
return '<<<a<' . base64_encode($match[0]) . '>>>>'; | ||
}, $html); | ||
|
||
$html = preg_replace_callback('~(<img .*?>)~i', function (array $match) { | ||
return '<<<i<' . base64_encode($match[0]) . '>>>>'; | ||
}, $html); | ||
|
||
$html = preg_replace_callback('~https?://[a-z0-9/.\?&=%#\[\]_+\-]+~i', function (array $match) { | ||
return '<a href="' . $match[0] . '">' . $match[0] . '</a>'; | ||
}, $html); | ||
|
||
$html = preg_replace_callback('~<<<[ai]<(.*?)>>>>~', function (array $match) { | ||
return base64_decode($match[1]); | ||
}, $html); | ||
|
||
return $html; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
namespace Soukicz\TestUrlToLink; | ||
|
||
|
||
use Soukicz\UrlToLink\Processor; | ||
|
||
class ProcessorTest extends \PHPUnit_Framework_TestCase { | ||
function testDecodeSizes() { | ||
$link = new Processor(); | ||
|
||
$this->assertEquals( | ||
'abc <a href="https://www.jadi.cz/Damska-obuv/Kotnickova-obuv/Podzim-zima/?f[v][]=40&f[p][313][]=571&f[cena_do]=3170">https://www.jadi.cz/Damska-obuv/Kotnickova-obuv/Podzim-zima/?f[v][]=40&f[p][313][]=571&f[cena_do]=3170</a> def <a href="https://jadi.cz">https://jadi.cz</a>', | ||
$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 <a href="https://jadi.cz">https://jadi.cz</a>') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
error_reporting(E_ALL); | ||
ini_set("display_errors", 1); | ||
if(file_exists(__DIR__ . '/../vendor/autoload.php')) { | ||
// dependencies were installed via composer - this is the main project | ||
$classLoader = require __DIR__ . '/../vendor/autoload.php'; | ||
} elseif(file_exists(__DIR__ . '/../../../../../autoload.php')) { | ||
// installed as a dependency in `vendor` | ||
$classLoader = require __DIR__ . '/../../../../../autoload.php'; | ||
} else { | ||
throw new Exception('Can\'t find autoload.php. Did you install dependencies via composer?'); | ||
} |