Initial commit
This commit is contained in:
1
core/vendor/ptachoire/cssembed/.gitignore
vendored
Normal file
1
core/vendor/ptachoire/cssembed/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.idea
|
||||
7
core/vendor/ptachoire/cssembed/.travis.yml
vendored
Normal file
7
core/vendor/ptachoire/cssembed/.travis.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
|
||||
script: phpunit
|
||||
19
core/vendor/ptachoire/cssembed/LICENSE
vendored
Normal file
19
core/vendor/ptachoire/cssembed/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 Pierre Tachoire <pierre.tachoire@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
28
core/vendor/ptachoire/cssembed/autoload.php.dist
vendored
Normal file
28
core/vendor/ptachoire/cssembed/autoload.php.dist
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
spl_autoload_register(
|
||||
function ($className) {
|
||||
$className = ltrim($className, '\\');
|
||||
if (0 != strpos($className, 'CssEmbed\\Tests')) {
|
||||
return false;
|
||||
}
|
||||
$fileName = '';
|
||||
$namespace = '';
|
||||
if ($lastNsPos = strrpos($className, '\\')) {
|
||||
$namespace = substr($className, 0, $lastNsPos);
|
||||
$className = substr($className, $lastNsPos + 1);
|
||||
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$fileName = __DIR__ . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . $fileName . $className . '.php';
|
||||
if (is_file($fileName)) {
|
||||
require $fileName;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
// Use the bundled autoloader
|
||||
require_once __DIR__.'/src/autoload.php';
|
||||
20
core/vendor/ptachoire/cssembed/composer.json
vendored
Normal file
20
core/vendor/ptachoire/cssembed/composer.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "ptachoire/cssembed",
|
||||
"type": "library",
|
||||
"description": "Css url embed library.",
|
||||
"keywords": ["css", "url"],
|
||||
"homepage": "https://github.com/krichprollsch/phpCssEmbed",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Pierre Tachoire",
|
||||
"email": "pierre.tachoire@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "CssEmbed": "src/" }
|
||||
}
|
||||
}
|
||||
23
core/vendor/ptachoire/cssembed/phpunit.xml.dist
vendored
Normal file
23
core/vendor/ptachoire/cssembed/phpunit.xml.dist
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="PhpCssEmbed Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./src/CssEmbed/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
33
core/vendor/ptachoire/cssembed/readme.md
vendored
Normal file
33
core/vendor/ptachoire/cssembed/readme.md
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
PhpCssEmbed
|
||||
====
|
||||
|
||||
**PhpCssEmbed** embed data uri in css part
|
||||
|
||||
[](https://travis-ci.org/krichprollsch/phpCssEmbed)
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Use embed css with a file
|
||||
|
||||
<?php
|
||||
$pce = new \CssEmbed\CssEmbed();
|
||||
echo $pce->embedCss( $css_file );
|
||||
|
||||
Or directly with css content
|
||||
|
||||
<?php
|
||||
$pce = new \CssEmbed\CssEmbed();
|
||||
$pce->setRootDir( '/path/to/files' );
|
||||
echo $pce->embedString( $css_content );
|
||||
|
||||
Unit Tests
|
||||
----------
|
||||
|
||||
phpunit
|
||||
|
||||
Thanks
|
||||
------
|
||||
|
||||
Files structure inspired by [Geocoder](https://github.com/willdurand/Geocoder)
|
||||
from [William Durand](https://github.com/willdurand)
|
||||
109
core/vendor/ptachoire/cssembed/src/CssEmbed/CssEmbed.php
vendored
Normal file
109
core/vendor/ptachoire/cssembed/src/CssEmbed/CssEmbed.php
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* 08/08/12 15:22
|
||||
*/
|
||||
|
||||
namespace CssEmbed;
|
||||
|
||||
/**
|
||||
* CssEmbed
|
||||
*
|
||||
* @author Pierre Tachoire <pierre.tachoire@gmail.com>
|
||||
*/
|
||||
class CssEmbed
|
||||
{
|
||||
|
||||
const SEARCH_PATTERN = "%url\\(['\" ]*((?!data:|//)[^'\"#\?: ]+)['\" ]*\\)%U";
|
||||
const URI_PATTERN = "url(data:%s;base64,%s)";
|
||||
|
||||
protected $root_dir;
|
||||
|
||||
/**
|
||||
* @param $root_dir
|
||||
*/
|
||||
public function setRootDir($root_dir)
|
||||
{
|
||||
$this->root_dir = $root_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $css_file
|
||||
* @return null|string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function embedCss($css_file)
|
||||
{
|
||||
$this->setRootDir(dirname($css_file));
|
||||
$return = null;
|
||||
$handle = fopen($css_file, "r");
|
||||
if ($handle === false) {
|
||||
throw new \InvalidArgumentException(sprintf('Cannot read file %s', $css_file));
|
||||
}
|
||||
while (($line = fgets($handle)) !== false) {
|
||||
$return .= $this->embedString($line);
|
||||
}
|
||||
fclose($handle);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $content
|
||||
* @return mixed
|
||||
*/
|
||||
public function embedString($content)
|
||||
{
|
||||
return preg_replace_callback(self::SEARCH_PATTERN, array($this, 'replace'), $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $matches
|
||||
* @return string
|
||||
*/
|
||||
protected function replace($matches)
|
||||
{
|
||||
return $this->embedFile($this->root_dir . DIRECTORY_SEPARATOR . $matches[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $file
|
||||
* @return string
|
||||
*/
|
||||
protected function embedFile($file)
|
||||
{
|
||||
return sprintf(self::URI_PATTERN, $this->mimeType($file), $this->base64($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $file
|
||||
* @return string
|
||||
*/
|
||||
protected function mimeType($file)
|
||||
{
|
||||
if (function_exists('mime_content_type')) {
|
||||
return mime_content_type($file);
|
||||
}
|
||||
|
||||
if ($info = @getimagesize($file)) {
|
||||
return($info['mime']);
|
||||
}
|
||||
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $file
|
||||
* @return string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function base64($file)
|
||||
{
|
||||
if (is_file($file) == false || is_readable($file) == false) {
|
||||
throw new \InvalidArgumentException(sprintf('Cannot read file %s', $file));
|
||||
}
|
||||
|
||||
return base64_encode(file_get_contents($file));
|
||||
}
|
||||
}
|
||||
32
core/vendor/ptachoire/cssembed/src/autoload.php
vendored
Normal file
32
core/vendor/ptachoire/cssembed/src/autoload.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Simple autoloader that follow the PHP Standards Recommendation #0 (PSR-0)
|
||||
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md for more informations.
|
||||
*
|
||||
* Code inspired from the SplClassLoader RFC
|
||||
* @see https://wiki.php.net/rfc/splclassloader#example_implementation
|
||||
*/
|
||||
spl_autoload_register(
|
||||
function ($className) {
|
||||
$className = ltrim($className, '\\');
|
||||
if (0 != strpos($className, 'CssEmbed')) {
|
||||
return false;
|
||||
}
|
||||
$fileName = '';
|
||||
$namespace = '';
|
||||
if ($lastNsPos = strrpos($className, '\\')) {
|
||||
$namespace = substr($className, 0, $lastNsPos);
|
||||
$className = substr($className, $lastNsPos + 1);
|
||||
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php';
|
||||
if (is_file($fileName)) {
|
||||
require $fileName;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
64
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/CssEmbedTest.php
vendored
Normal file
64
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/CssEmbedTest.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
* 11/05/12 17:20
|
||||
*/
|
||||
namespace CssEmbed\Tests;
|
||||
|
||||
use CssEmbed\CssEmbed;
|
||||
|
||||
/**
|
||||
* @author Pierre Tachoire <pierre.tachoire@gmail.com>
|
||||
*/
|
||||
class CssEmbedTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEmbedCss()
|
||||
{
|
||||
$origin = __DIR__.'/rsc/test.css';
|
||||
$expected = file_get_contents(__DIR__.'/rsc/expected.css');
|
||||
|
||||
$cssEmbed = new CssEmbed();
|
||||
$tested = $cssEmbed->embedCss($origin);
|
||||
|
||||
$this->assertEquals($expected, $tested);
|
||||
}
|
||||
|
||||
public function testEmbedString()
|
||||
{
|
||||
$origin = file_get_contents(__DIR__.'/rsc/test.css');
|
||||
$expected = file_get_contents(__DIR__.'/rsc/expected.css');
|
||||
|
||||
$cssEmbed = new CssEmbed();
|
||||
$cssEmbed->setRootDir(__DIR__.'/rsc');
|
||||
$tested = $cssEmbed->embedString($origin);
|
||||
|
||||
$this->assertEquals($expected, $tested);
|
||||
}
|
||||
|
||||
public function mimeTypeProvider()
|
||||
{
|
||||
return array(
|
||||
array('application/octet-stream', 'binary.file'),
|
||||
array('image/gif', 'php.gif')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mimeTypeProvider
|
||||
*/
|
||||
public function testMimeType($expected, $file)
|
||||
{
|
||||
$cssEmbed = new CssEmbedTestable();
|
||||
$file = __DIR__.'/rsc/'.$file;
|
||||
$this->assertEquals($expected, $cssEmbed->mimeType($file));
|
||||
}
|
||||
}
|
||||
|
||||
class CssEmbedTestable extends CssEmbed
|
||||
{
|
||||
public function mimeType($file)
|
||||
{
|
||||
return parent::mimeType($file);
|
||||
}
|
||||
}
|
||||
BIN
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/rsc/binary.file
vendored
Normal file
BIN
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/rsc/binary.file
vendored
Normal file
Binary file not shown.
16
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/rsc/expected.css
vendored
Normal file
16
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/rsc/expected.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/rsc/php.gif
vendored
Normal file
BIN
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/rsc/php.gif
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
16
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/rsc/test.css
vendored
Normal file
16
core/vendor/ptachoire/cssembed/tests/Tests/CssEmbed/rsc/test.css
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/* Css file to test phpCssEmbed **/
|
||||
|
||||
.this-is a#css-selector {
|
||||
background: url('//google.com/test.gif');
|
||||
background: url('http://google.com/test.gif');
|
||||
background: url('test.gif?http_param=1');
|
||||
background: url('php.gif');
|
||||
background: url("php.gif");
|
||||
background: url( 'php.gif' );
|
||||
background: url( php.gif );
|
||||
background: url(php.gif);
|
||||
background: url(../rsc/php.gif);
|
||||
background: url(php.gif);background: url(php.gif);background: url(php.gif);
|
||||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=);
|
||||
x-foo: url(binary.file);
|
||||
}
|
||||
7
core/vendor/ptachoire/cssembed/tests/bootstrap.php
vendored
Normal file
7
core/vendor/ptachoire/cssembed/tests/bootstrap.php
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
if (file_exists($file = __DIR__.'/../autoload.php')) {
|
||||
require_once $file;
|
||||
} elseif (file_exists($file = __DIR__.'/../autoload.php.dist')) {
|
||||
require_once $file;
|
||||
}
|
||||
Reference in New Issue
Block a user