Skip to content

Commit 7a6fca2

Browse files
authored
Release version 2.3.0 (#4)
Merge pull request #4 from short-pixel-optimizer/queue
2 parents ee609ea + 469462a commit 7a6fca2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3447
-1301
lines changed

build/shortpixel/PackageLoader.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@
44
class PackageLoader
55
{
66
public $dir;
7+
public $composerFile = false;
78

8-
public function getComposerFile()
9+
public function __construct()
910
{
10-
return json_decode(file_get_contents($this->dir."/composer.json"), 1);
11+
12+
}
13+
14+
public function setComposerFile($filePath)
15+
{
16+
$this->composerFile = json_decode(file_get_contents($filePath),1);
17+
}
18+
19+
public function getComposerFile($filePath = false )
20+
{
21+
if (! $this->composerFile)
22+
$this->composerFile = json_decode(file_get_contents($this->dir."/composer.json"), 1);
23+
24+
return $this->composerFile;
1125
}
1226

1327
public function load($dir)
1428
{
1529
$this->dir = $dir;
1630
$composer = $this->getComposerFile();
17-
18-
1931
if(isset($composer["autoload"]["psr-4"])){
2032
$this->loadPSR4($composer['autoload']['psr-4']);
2133
}
@@ -49,11 +61,13 @@ public function loadPSR0($namespaces)
4961
public function loadPSR($namespaces, $psr4)
5062
{
5163
$dir = $this->dir;
64+
5265
// Foreach namespace specified in the composer, load the given classes
5366
foreach ($namespaces as $namespace => $classpaths) {
5467
if (!is_array($classpaths)) {
5568
$classpaths = array($classpaths);
5669
}
70+
5771
spl_autoload_register(function ($classname) use ($namespace, $classpaths, $dir, $psr4) {
5872
// Check if the namespace matches the class we are looking for
5973
if (preg_match("#^".preg_quote($namespace)."#", $classname)) {
@@ -62,6 +76,7 @@ public function loadPSR($namespaces, $psr4)
6276
$classname = str_replace($namespace, "", $classname);
6377
}
6478

79+
6580
// $filename = preg_replace("#\\\\#", "", $classname).".php";
6681
// This is fix for nested classes which were losing a /
6782
$filename = ltrim($classname .'.php', '\\');

build/shortpixel/composer.json

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

build/shortpixel/log/src/ShortPixelLogger.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ public static function addDebug($message, $args = array())
250250
$log->addLog($message, $level, $args);
251251
}
252252

253+
/** These should be removed every release. They are temporary only for d'bugging the current release */
254+
public static function addTemp($message, $args = array())
255+
{
256+
self::addDebug($message, $args);
257+
}
258+
253259
public static function logLevel($level)
254260
{
255261
$log = self::getInstance();

build/shortpixel/notices/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "shortpixel/notices",
33
"description": "ShortPixel WordPress Notice System",
4-
"version": "1.3",
4+
"version": "1.5",
55
"type": "library",
66
"license": "MIT",
77
"authors": [

build/shortpixel/notices/src/NoticeController.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ protected function loadNotices()
6565
{
6666
$notices = get_option($this->notice_option, false);
6767
$cnotice = (is_array($notices)) ? count($notices) : 0;
68-
if ($cnotice > 0)
69-
Log::addDebug('Notice Control - #num notices' . $cnotice);
7068

7169
if ($notices !== false && is_array($notices))
7270
{
@@ -90,7 +88,7 @@ protected function addNotice($message, $code, $unique)
9088
foreach(self::$notices as $nitem)
9189
{
9290
if ($nitem->message == $notice->message && $nitem->code == $notice->code) // same message.
93-
return $notice; // return the notice with the same message.
91+
return $nitem; // return the notice with the same message.
9492
}
9593
}
9694
self::$notices[] = $notice;
@@ -141,6 +139,7 @@ public function getNotices()
141139
public function getNoticesForDisplay()
142140
{
143141
$newNotices = array();
142+
144143
foreach(self::$notices as $notice)
145144
{
146145
if ($notice->isDismissed()) // dismissed never displays.
@@ -266,7 +265,23 @@ public static function addSuccess($message, $unique = false)
266265

267266
}
268267

269-
public static function makePersistent($notice, $key, $suppress = -1)
268+
public static function addDetail($notice, $detail)
269+
{
270+
$noticeController = self::getInstance();
271+
$notice->addDetail($detail);
272+
273+
// $notice_id = spl_object_id($notice);
274+
275+
$noticeController->update();
276+
}
277+
278+
/** Make a regular notice persistent across multiple page loads
279+
* @param $notice NoticeModel The Notice to make Persistent
280+
* @param $key String Identifier of the persistent notice.
281+
* @param $suppress Int When dismissed, time to stay dismissed
282+
* @param $callback Function Callable function
283+
*/
284+
public static function makePersistent($notice, $key, $suppress = -1, $callback = null)
270285
{
271286
$noticeController = self::getInstance();
272287
$existing = $noticeController->getNoticeByID($key);
@@ -291,7 +306,7 @@ public static function makePersistent($notice, $key, $suppress = -1)
291306
}
292307
else
293308
{
294-
$notice->setPersistent($key, $suppress); // set this notice persistent.
309+
$notice->setPersistent($key, $suppress, $callback); // set this notice persistent.
295310
}
296311

297312
$noticeController->update();

build/shortpixel/notices/src/NoticeModel.php

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class NoticeModel //extends ShortPixelModel
55
{
66
public $message; // The message we want to convey.
7+
public $details = array(); // extra details, like the files involved. Something could be hideable in the future.
78
public $code;
89

910
private $id = null; // used for persistent messages.
@@ -16,6 +17,7 @@ class NoticeModel //extends ShortPixelModel
1617
public $messageType = self::NOTICE_NORMAL;
1718

1819
public $notice_action; // empty unless for display. Ajax action to talk back to controller.
20+
protected $callback; // empty unless callback is needed
1921

2022
public static $icons = array();
2123

@@ -82,16 +84,33 @@ public function setDismissedUntil($timestamp)
8284
$this->suppress_until = $timestamp;
8385
}
8486

87+
/** Support for extra information beyond the message.
88+
* Can help to not overwhelm users w/ the same message but different file /circumstances.
89+
*/
90+
public function addDetail($detail, $clean = false)
91+
{
92+
if ($clean)
93+
$this->details = array();
94+
95+
if (! in_array($detail, $this->details) )
96+
$this->details[] = $detail;
97+
}
98+
99+
85100

86101
/** Set a notice persistent. Meaning it shows every page load until dismissed.
87102
* @param $key Unique Key of this message. Required
88103
* @param $suppress When dismissed do not show this message again for X amount of time. When -1 it will just be dropped from the Notices and not suppressed
89104
*/
90-
public function setPersistent($key, $suppress = -1)
105+
public function setPersistent($key, $suppress = -1, $callback = null)
91106
{
92107
$this->id = $key;
93108
$this->is_persistent = true;
94109
$this->suppress_period = $suppress;
110+
if ( ! is_null($callback) && is_callable($callback))
111+
{
112+
$this->callback = $callback;
113+
}
95114
}
96115

97116
public static function setIcon($notice_type, $icon)
@@ -122,6 +141,13 @@ public function getForDisplay()
122141

123142
$icon = '';
124143

144+
if ($this->callback)
145+
{
146+
$return = call_user_func($this->callback, $this);
147+
if ($return === false) // don't display is callback returns false explicitly.
148+
return;
149+
}
150+
125151
switch($this->messageType)
126152
{
127153
case self::NOTICE_ERROR:
@@ -158,9 +184,24 @@ public function getForDisplay()
158184
$class .= 'is-persistent ';
159185
}
160186

161-
$id = ! is_null($this->id) ? 'id="' . $this->id . '"' : '';
187+
$id = ! is_null($this->id) ? $this->id : uniqid();
188+
//'id="' . $this->id . '"'
189+
$output = "<div id='$id' class='$class'><span class='icon'> " . $icon . "</span> <span class='content'>" . $this->message;
190+
if ($this->hasDetails())
191+
{
192+
$output .= '<div class="details-wrapper">
193+
<input type="checkbox" name="detailhider" id="check-' . $id .'">
194+
<label for="check-' . $id . '" class="show-details"><span>' . __('See Details', 'shortpixel-image-optimiser') . '</span>
195+
</label>';
196+
197+
$output .= "<div class='detail-content-wrapper'><p class='detail-content'>" . $this->parseDetails() . "</p></div>";
198+
$output .= '<label for="check-' . $id . '" class="hide-details"><span>' . __('Hide Details', 'shortpixel-image-optimiser') . '</span></label>';
199+
200+
$output .= '</div>'; // detail rapper
201+
202+
}
203+
$output .= "</span></div>";
162204

163-
$output = "<div $id class='$class'><span class='icon'> " . $icon . "</span> <span class='content'>" . $this->message . "</span></div>";
164205
if ($this->is_persistent && $this->is_removable)
165206
{
166207
$output .= "<script type='text/javascript'>\n" . $this->getDismissJS() . "\n</script>";
@@ -169,6 +210,19 @@ public function getForDisplay()
169210

170211
}
171212

213+
protected function hasDetails()
214+
{
215+
if (is_array($this->details) && count($this->details) > 0)
216+
return true;
217+
else
218+
return false;
219+
}
220+
221+
protected function parseDetails()
222+
{
223+
return implode('<BR>', $this->details);
224+
}
225+
172226
private function getDismissJS()
173227
{
174228
$url = wp_json_encode(admin_url('admin-ajax.php'));
@@ -179,7 +233,7 @@ private function getDismissJS()
179233

180234
// $data_string = "{action:'$this->notice_action'}";
181235

182-
$js = "jQuery(document).on('click','#$this->id button',
236+
$js = "jQuery(document).on('click','#$this->id button.notice-dismiss',
183237
function() {
184238
var data = $data;
185239
var url = $url;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "shortpixel/shortq",
3+
"description": "Simple Queue",
4+
"version": 0.5,
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\\ShortQ\\" : "src" }
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
namespace ReThumbAdvanced\ShortQ\DataProvider;
3+
use ReThumbAdvanced\ShortQ\Item as Item;
4+
5+
6+
/* DataProvider handles where the data is stored, and retrieval upon queue request
7+
*
8+
* DataProvider is responsible for creating it's own environment, and cleanup when uninstall is being called.
9+
*
10+
*/
11+
interface DataProvider
12+
{
13+
14+
function __construct($pluginSlug, $queueName);
15+
16+
//function add($items);
17+
function enqueue($items);
18+
function dequeue($args); // @return Items removed from queue and set to status. Returns Item Object
19+
function alterqueue($args); // @return Item Count / Boolean . Mass alteration of queue.
20+
function itemUpdate(Item $item, $new_status);
21+
22+
// Returns number of items left in Queue.
23+
function itemCount($mode = 'waiting');
24+
25+
function install();
26+
function uninstall();
27+
}

0 commit comments

Comments
 (0)