Skip to content

Commit ee609ea

Browse files
authored
Merge for release v 2.2.0
Merge for release v 2.2.0
2 parents 7fe2711 + a7a1ebb commit ee609ea

34 files changed

+3415
-1606
lines changed

build/shortpixel/PackageLoader.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
namespace ReThumbAdvanced\Build;
3+
4+
class PackageLoader
5+
{
6+
public $dir;
7+
8+
public function getComposerFile()
9+
{
10+
return json_decode(file_get_contents($this->dir."/composer.json"), 1);
11+
}
12+
13+
public function load($dir)
14+
{
15+
$this->dir = $dir;
16+
$composer = $this->getComposerFile();
17+
18+
19+
if(isset($composer["autoload"]["psr-4"])){
20+
$this->loadPSR4($composer['autoload']['psr-4']);
21+
}
22+
if(isset($composer["autoload"]["psr-0"])){
23+
$this->loadPSR0($composer['autoload']['psr-0']);
24+
}
25+
if(isset($composer["autoload"]["files"])){
26+
$this->loadFiles($composer["autoload"]["files"]);
27+
}
28+
}
29+
30+
public function loadFiles($files){
31+
foreach($files as $file){
32+
$fullpath = $this->dir."/".$file;
33+
if(file_exists($fullpath)){
34+
include_once($fullpath);
35+
}
36+
}
37+
}
38+
39+
public function loadPSR4($namespaces)
40+
{
41+
$this->loadPSR($namespaces, true);
42+
}
43+
44+
public function loadPSR0($namespaces)
45+
{
46+
$this->loadPSR($namespaces, false);
47+
}
48+
49+
public function loadPSR($namespaces, $psr4)
50+
{
51+
$dir = $this->dir;
52+
// Foreach namespace specified in the composer, load the given classes
53+
foreach ($namespaces as $namespace => $classpaths) {
54+
if (!is_array($classpaths)) {
55+
$classpaths = array($classpaths);
56+
}
57+
spl_autoload_register(function ($classname) use ($namespace, $classpaths, $dir, $psr4) {
58+
// Check if the namespace matches the class we are looking for
59+
if (preg_match("#^".preg_quote($namespace)."#", $classname)) {
60+
// Remove the namespace from the file path since it's psr4
61+
if ($psr4) {
62+
$classname = str_replace($namespace, "", $classname);
63+
}
64+
65+
// $filename = preg_replace("#\\\\#", "", $classname).".php";
66+
// This is fix for nested classes which were losing a /
67+
$filename = ltrim($classname .'.php', '\\');
68+
$filename = str_replace('\\','/', $filename);
69+
70+
foreach ($classpaths as $classpath) {
71+
$fullpath = trailingslashit($dir) . trailingslashit($classpath) .$filename;
72+
if (file_exists($fullpath)) {
73+
include_once $fullpath;
74+
}
75+
}
76+
}
77+
});
78+
}
79+
}
80+
}

build/shortpixel/autoload.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
require_once (dirname(__FILE__) . "/PackageLoader.php");
3+
$loader = new ReThumbAdvanced\Build\PackageLoader();
4+
$loader->load(__DIR__);
5+

build/shortpixel/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"ReThumbAdvanced\/shortpixelmodules","description":"ShortPixel submodules","type":"function","autoload":{"psr-4":{"ReThumbAdvanced\\ShortPixelLogger":"log\/src","ReThumbAdvanced\\Notices":"notices\/src"}}}

build/shortpixel/log/composer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "shortpixel/log",
3+
"description": "ShortPixel Logging",
4+
"version": "1.1.3",
5+
"type": "library",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Bas",
10+
"email": "bas@weblogmechanic.com"
11+
}
12+
],
13+
"minimum-stability": "dev",
14+
"require": {},
15+
"autoload": {
16+
"psr-4": { "ShortPixel\\ShortPixelLogger\\" : "src" }
17+
}
18+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
// The data models.
3+
namespace ReThumbAdvanced\ShortPixelLogger;
4+
5+
6+
class DebugItem
7+
{
8+
protected $time;
9+
protected $level;
10+
protected $message;
11+
protected $data = array();
12+
protected $caller = false; // array when filled
13+
14+
protected $model;
15+
16+
const LEVEL_ERROR = 1;
17+
const LEVEL_WARN = 2;
18+
const LEVEL_INFO = 3;
19+
const LEVEL_DEBUG = 4;
20+
21+
public function __construct($message, $args)
22+
{
23+
$this->level = $args['level'];
24+
$data = $args['data'];
25+
26+
$this->message = $message;
27+
$this->time = microtime(true);
28+
29+
$this->setCaller();
30+
31+
// Add message to data if it seems to be some debug variable.
32+
if (is_object($this->message) || is_array($this->message))
33+
{
34+
$data[] = $this->message;
35+
$this->message = __('[Data]');
36+
}
37+
if (is_array($data) && count($data) > 0)
38+
{
39+
$dataType = $this->getDataType($data);
40+
if ($dataType == 1) // singular
41+
{
42+
$this->data[] = print_r($data, true);
43+
}
44+
if ($dataType == 2) //array
45+
{
46+
foreach($data as $index => $item)
47+
{
48+
if (is_object($item) || is_array($item))
49+
{
50+
$this->data[] = print_r($item, true);
51+
}
52+
}
53+
}
54+
} // if
55+
elseif (! is_array($data)) // this leaves out empty default arrays
56+
{
57+
$this->data[] = print_r($data, true);
58+
}
59+
}
60+
61+
public function getData()
62+
{
63+
return array('time' => $this->time, 'level' => $this->level, 'message' => $this->message, 'data' => $this->data, 'caller' => $this->caller);
64+
}
65+
66+
/** Test Data Array for possible values
67+
*
68+
* Data can be a collection of several debug vars, a single var, or just an normal array. Test if array has single types,
69+
* which is a sign the array is not a collection.
70+
*/
71+
protected function getDataType($data)
72+
{
73+
$single_type = array('integer', 'boolean', 'string');
74+
if (in_array(gettype(reset($data)), $single_type))
75+
{
76+
return 1;
77+
}
78+
else
79+
{
80+
return 2;
81+
}
82+
}
83+
84+
public function getForFormat()
85+
{
86+
$data = $this->getData();
87+
switch($this->level)
88+
{
89+
case self::LEVEL_ERROR:
90+
$level = 'ERR';
91+
$color = "\033[31m";
92+
break;
93+
case self::LEVEL_WARN:
94+
$level = 'WRN';
95+
$color = "\033[33m";
96+
break;
97+
case self::LEVEL_INFO:
98+
$level = 'INF';
99+
$color = "\033[37m";
100+
break;
101+
case self::LEVEL_DEBUG:
102+
$level = 'DBG';
103+
$color = "\033[37m";
104+
break;
105+
106+
}
107+
$color_end = "\033[0m";
108+
109+
$data['color'] = $color;
110+
$data['color_end'] = $color_end;
111+
$data['level'] = $level;
112+
113+
return $data;
114+
115+
//return array('time' => $this->time, 'level' => $level, 'message' => $this->message, 'data' => $this->data, 'color' => $color, 'color_end' => $color_end, 'caller' => $this->caller);
116+
117+
}
118+
119+
protected function setCaller()
120+
{
121+
if(PHP_VERSION_ID < 50400) {
122+
$debug=debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
123+
} else {
124+
$debug=debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,5);
125+
}
126+
127+
$i = 4;
128+
if (isset($debug[$i]))
129+
{
130+
$info = $debug[$i];
131+
$line = isset($info['line']) ? $info['line'] : 'Line unknown';
132+
$file = isset($info['file']) ? basename($info['file']) : 'File not set';
133+
134+
$this->caller = array('line' => $line, 'file' => $file, 'function' => $info['function']);
135+
}
136+
137+
138+
}
139+
140+
141+
}

0 commit comments

Comments
 (0)