@@ -18,8 +18,8 @@ class CSS extends Base
18
18
const TYPE_CLEAR_Q_CCSS = 'clear_q_ccss ' ;
19
19
20
20
protected $ _summary ;
21
+ private $ _ccss_whitelist ;
21
22
private $ _queue ;
22
- private $ _endts ;
23
23
24
24
/**
25
25
* Init
@@ -29,6 +29,8 @@ class CSS extends Base
29
29
public function __construct ()
30
30
{
31
31
$ this ->_summary = self ::get_summary ();
32
+
33
+ add_filter ('litespeed_ccss_whitelist ' , array ($ this ->cls ('Data ' ), 'load_ccss_whitelist ' ));
32
34
}
33
35
34
36
/**
@@ -206,22 +208,11 @@ private function _cron_handler($type, $continue)
206
208
}
207
209
208
210
$ i = 0 ;
209
- $ timeoutLimit = ini_get ('max_execution_time ' );
210
- $ this ->_endts = time () + $ timeoutLimit ;
211
211
foreach ($ this ->_queue as $ k => $ v ) {
212
212
if (!empty ($ v ['_status ' ])) {
213
213
continue ;
214
214
}
215
215
216
- if (function_exists ('set_time_limit ' )) {
217
- $ this ->_endts += 120 ;
218
- set_time_limit (120 );
219
- }
220
- if ($ this ->_endts - time () < 10 ) {
221
- // self::debug("🚨 End loop due to timeout limit reached " . $timeoutLimit . "s");
222
- // return;
223
- }
224
-
225
216
Debug2::debug ('[ ' . $ type_tag . '] cron job [tag] ' . $ k . ' [url] ' . $ v ['url ' ] . ($ v ['is_mobile ' ] ? ' 📱 ' : '' ) . ' [UA] ' . $ v ['user_agent ' ]);
226
217
227
218
if ($ type == 'ccss ' && empty ($ v ['url_tag ' ])) {
@@ -291,6 +282,8 @@ private function _send_req($request_url, $queue_k, $uid, $user_agent, $vary, $ur
291
282
return 'out_of_quota ' ;
292
283
}
293
284
285
+ set_time_limit (120 );
286
+
294
287
// Update css request status
295
288
$ this ->_summary ['curr_request_ ' . $ type ] = time ();
296
289
self ::save_summary ();
@@ -306,7 +299,8 @@ private function _send_req($request_url, $queue_k, $uid, $user_agent, $vary, $ur
306
299
list ($ css , $ html ) = $ this ->prepare_css ($ html , $ is_webp );
307
300
308
301
if (!$ css ) {
309
- Debug2::debug ('[UCSS] ❌ No combined css ' );
302
+ $ type_tag = strtoupper ($ type );
303
+ Debug2::debug ('[ ' . $ type_tag . '] ❌ No combined css ' );
310
304
return false ;
311
305
}
312
306
@@ -320,6 +314,10 @@ private function _send_req($request_url, $queue_k, $uid, $user_agent, $vary, $ur
320
314
'html ' => $ html ,
321
315
'css ' => $ css ,
322
316
);
317
+ if (!isset ($ this ->_ccss_whitelist )) {
318
+ $ this ->_ccss_whitelist = $ this ->_filter_whitelist ();
319
+ }
320
+ $ data ['whitelist ' ] = $ this ->_ccss_whitelist ;
323
321
324
322
self ::debug ('Generating: ' , $ data );
325
323
@@ -526,6 +524,83 @@ public function prepare_css($html, $is_webp = false, $dryrun = false)
526
524
return array ($ css , $ html );
527
525
}
528
526
527
+ /**
528
+ * Filter the comment content, add quotes to selector from whitelist. Return the json
529
+ *
530
+ * @since 7.1
531
+ */
532
+ private function _filter_whitelist ()
533
+ {
534
+ $ whitelist = array ();
535
+ $ list = apply_filters ('litespeed_ccss_whitelist ' , $ this ->conf (self ::O_OPTM_CCSS_SELECTOR_WHITELIST ));
536
+ foreach ($ list as $ v ) {
537
+ if (substr ($ v , 0 , 2 ) === '// ' ) {
538
+ continue ;
539
+ }
540
+ $ whitelist [] = $ v ;
541
+ }
542
+
543
+ return $ whitelist ;
544
+ }
545
+
546
+ /**
547
+ * Notify finished from server
548
+ * @since 7.1
549
+ */
550
+ public function notify ()
551
+ {
552
+ $ post_data = \json_decode (file_get_contents ('php://input ' ), true );
553
+ if (is_null ($ post_data )) {
554
+ $ post_data = $ _POST ;
555
+ }
556
+ self ::debug ('notify() data ' , $ post_data );
557
+
558
+ $ this ->_queue = $ this ->load_queue ('ccss ' );
559
+
560
+ list ($ post_data ) = $ this ->cls ('Cloud ' )->extract_msg ($ post_data , 'ccss ' );
561
+
562
+ $ notified_data = $ post_data ['data ' ];
563
+ if (empty ($ notified_data ) || !is_array ($ notified_data )) {
564
+ self ::debug ('❌ notify exit: no notified data ' );
565
+ return Cloud::err ('no notified data ' );
566
+ }
567
+
568
+ // Check if its in queue or not
569
+ $ valid_i = 0 ;
570
+ foreach ($ notified_data as $ v ) {
571
+ if (empty ($ v ['request_url ' ])) {
572
+ self ::debug ('❌ notify bypass: no request_url ' , $ v );
573
+ continue ;
574
+ }
575
+ if (empty ($ v ['queue_k ' ])) {
576
+ self ::debug ('❌ notify bypass: no queue_k ' , $ v );
577
+ continue ;
578
+ }
579
+
580
+ if (empty ($ this ->_queue [$ v ['queue_k ' ]])) {
581
+ self ::debug ('❌ notify bypass: no this queue [q_k] ' . $ v ['queue_k ' ]);
582
+ continue ;
583
+ }
584
+
585
+ // Save data
586
+ if (!empty ($ v ['data_ccss ' ])) {
587
+ $ is_mobile = $ this ->_queue [$ v ['queue_k ' ]]['is_mobile ' ];
588
+ $ is_webp = $ this ->_queue [$ v ['queue_k ' ]]['is_webp ' ];
589
+ $ this ->_save_con ('ccss ' , $ v ['data_ccss ' ], $ v ['queue_k ' ], $ is_mobile , $ is_webp );
590
+
591
+ $ valid_i ++;
592
+ }
593
+
594
+ unset($ this ->_queue [$ v ['queue_k ' ]]);
595
+ self ::debug ('notify data handled, unset queue [q_k] ' . $ v ['queue_k ' ]);
596
+ }
597
+ $ this ->save_queue ('ccss ' , $ this ->_queue );
598
+
599
+ self ::debug ('notified ' );
600
+
601
+ return Cloud::ok (array ('count ' => $ valid_i ));
602
+ }
603
+
529
604
/**
530
605
* Handle all request actions from main cls
531
606
*
0 commit comments