| @@ -64,7 +64,7 @@ discard block | ||
| 64 | 64 | * | 
| 65 | 65 | * @param string $url URL to transform. | 
| 66 | 66 | * | 
| 67 | - * @return bool|string | |
| 67 | + * @return false|string | |
| 68 | 68 | */ | 
| 69 | 69 | public function getpath( $url ) | 
| 70 | 70 |      { | 
| @@ -610,7 +610,7 @@ discard block | ||
| 610 | 610 | /** | 
| 611 | 611 | * Logs given `$data` for debugging purposes (when debug logging is on). | 
| 612 | 612 | * | 
| 613 | - * @param mixed $data Data to log. | |
| 613 | + * @param string $data Data to log. | |
| 614 | 614 | * | 
| 615 | 615 | * @return void | 
| 616 | 616 | */ | 
| @@ -632,7 +632,7 @@ discard block | ||
| 632 | 632 | * | 
| 633 | 633 | * @param string $filepath Filepath. | 
| 634 | 634 | * | 
| 635 | - * @return bool|string to be minified code or false. | |
| 635 | + * @return false|string to be minified code or false. | |
| 636 | 636 | */ | 
| 637 | 637 | protected function prepare_minify_single( $filepath ) | 
| 638 | 638 |      { | 
| @@ -412,7 +412,7 @@ | ||
| 412 | 412 | * First element is the filepath, second is the md5 hash of contents | 
| 413 | 413 | * the filepath had when it was being processed. | 
| 414 | 414 | * If we don't have those, we'll bail out early. | 
| 415 | - */ | |
| 415 | + */ | |
| 416 | 416 | $filepath = null; | 
| 417 | 417 | $filehash = null; | 
| 418 | 418 | |
| @@ -434,7 +434,7 @@ | ||
| 434 | 434 | * size = total filesize (in bytes) of found files | 
| 435 | 435 | * timestamp = unix timestamp when the scan was last performed/finished. | 
| 436 | 436 | * | 
| 437 | - * @return array | |
| 437 | + * @return integer[] | |
| 438 | 438 | */ | 
| 439 | 439 | protected static function stats_scan() | 
| 440 | 440 |      { | 
| @@ -418,6 +418,10 @@ discard block | ||
| 418 | 418 | } | 
| 419 | 419 | |
| 420 | 420 | // Checks against the white- and blacklists | 
| 421 | + | |
| 422 | + /** | |
| 423 | + * @param string $tag | |
| 424 | + */ | |
| 421 | 425 | private function ismergeable($tag) | 
| 422 | 426 |      { | 
| 423 | 427 |          if ( ! $this->aggregate ) { | 
| @@ -457,6 +461,10 @@ discard block | ||
| 457 | 461 | } | 
| 458 | 462 | |
| 459 | 463 | // Checks agains the blacklist | 
| 464 | + | |
| 465 | + /** | |
| 466 | + * @param string $tag | |
| 467 | + */ | |
| 460 | 468 | private function ismovable($tag) | 
| 461 | 469 |      { | 
| 462 | 470 |          if ( true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) { | 
| @@ -538,7 +546,7 @@ discard block | ||
| 538 | 546 | * @param string $filepath Filepath. | 
| 539 | 547 | * @param bool $cache_miss Optional. Force a cache miss. Default false. | 
| 540 | 548 | * | 
| 541 | - * @return bool|string Url pointing to the minified js file or false. | |
| 549 | + * @return false|string Url pointing to the minified js file or false. | |
| 542 | 550 | */ | 
| 543 | 551 | public function minify_single( $filepath, $cache_miss = false ) | 
| 544 | 552 |      { | 
| @@ -2,9 +2,9 @@ discard block | ||
| 2 | 2 | |
| 3 | 3 | //Check everything exists before using it | 
| 4 | 4 | if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) | 
| 5 | - $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; | |
| 5 | + $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; | |
| 6 | 6 | if(!isset($_SERVER['HTTP_USER_AGENT'])) | 
| 7 | - $_SERVER['HTTP_USER_AGENT'] = ''; | |
| 7 | + $_SERVER['HTTP_USER_AGENT'] = ''; | |
| 8 | 8 | |
| 9 | 9 | // Determine supported compression method | 
| 10 | 10 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); | 
| @@ -15,30 +15,30 @@ discard block | ||
| 15 | 15 | |
| 16 | 16 | // Check for buggy versions of Internet Explorer | 
| 17 | 17 | if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && | 
| 18 | -	preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) | |
| 18 | +    preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) | |
| 19 | 19 |  { | 
| 20 | - $version = floatval($matches[1]); | |
| 20 | + $version = floatval($matches[1]); | |
| 21 | 21 | |
| 22 | - if ($version < 6) | |
| 23 | - $encoding = 'none'; | |
| 22 | + if ($version < 6) | |
| 23 | + $encoding = 'none'; | |
| 24 | 24 | |
| 25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) | |
| 26 | - $encoding = 'none'; | |
| 25 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) | |
| 26 | + $encoding = 'none'; | |
| 27 | 27 | } | 
| 28 | 28 | |
| 29 | 29 | //Some servers compress the output of PHP - Don't break in those cases | 
| 30 | 30 |  if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) | 
| 31 | - $encoding = 'none'; | |
| 31 | + $encoding = 'none'; | |
| 32 | 32 | |
| 33 | 33 | $iscompressed = file_exists(__FILE__.'.'.$encoding); | 
| 34 | 34 | if($encoding != 'none' && $iscompressed == false) | 
| 35 | 35 |  { | 
| 36 | - $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); | |
| 37 | - $code = file_get_contents(__FILE__.'.none'); | |
| 38 | - $contents = gzencode($code,9,$flag); | |
| 36 | + $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); | |
| 37 | + $code = file_get_contents(__FILE__.'.none'); | |
| 38 | + $contents = gzencode($code,9,$flag); | |
| 39 | 39 |  }else{ | 
| 40 | - //Get data | |
| 41 | - $contents = file_get_contents(__FILE__.'.'.$encoding); | |
| 40 | + //Get data | |
| 41 | + $contents = file_get_contents(__FILE__.'.'.$encoding); | |
| 42 | 42 | } | 
| 43 | 43 | |
| 44 | 44 | // first check if we have to send 304 | 
| @@ -52,36 +52,36 @@ discard block | ||
| 52 | 52 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); | 
| 53 | 53 | |
| 54 | 54 |  if (($modTimeMatch)||($eTagMatch)) { | 
| 55 | -	header('HTTP/1.1 304 Not Modified'); | |
| 56 | -	header('Connection: close'); | |
| 55 | +    header('HTTP/1.1 304 Not Modified'); | |
| 56 | +    header('Connection: close'); | |
| 57 | 57 |  } else { | 
| 58 | - // send all sorts of headers | |
| 59 | - $expireTime=60*60*24*355; // 1y max according to RFC | |
| 60 | -	if ($encoding != 'none') { | |
| 61 | -		header('Content-Encoding: '.$encoding); | |
| 62 | - } | |
| 63 | -	header('Vary: Accept-Encoding'); | |
| 64 | -	header('Content-Length: '.strlen($contents)); | |
| 65 | -	header('Content-type: %%CONTENT%%; charset=utf-8'); | |
| 66 | -	header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); | |
| 67 | -	header('Cache-Control: max-age='.$expireTime.', public, immutable'); | |
| 68 | -	header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); | |
| 69 | -	header('ETag: ' . $eTag); | |
| 70 | -	header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); | |
| 58 | + // send all sorts of headers | |
| 59 | + $expireTime=60*60*24*355; // 1y max according to RFC | |
| 60 | +    if ($encoding != 'none') { | |
| 61 | +        header('Content-Encoding: '.$encoding); | |
| 62 | + } | |
| 63 | +    header('Vary: Accept-Encoding'); | |
| 64 | +    header('Content-Length: '.strlen($contents)); | |
| 65 | +    header('Content-type: %%CONTENT%%; charset=utf-8'); | |
| 66 | +    header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); | |
| 67 | +    header('Cache-Control: max-age='.$expireTime.', public, immutable'); | |
| 68 | +    header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); | |
| 69 | +    header('ETag: ' . $eTag); | |
| 70 | +    header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); | |
| 71 | 71 | |
| 72 | - // send output | |
| 73 | - echo $contents; | |
| 72 | + // send output | |
| 73 | + echo $contents; | |
| 74 | 74 | |
| 75 | - //And write to filesystem cache if not done yet | |
| 76 | - if($encoding != 'none' && $iscompressed == false) | |
| 77 | -	{ | |
| 78 | - //Write the content we sent | |
| 79 | - file_put_contents(__FILE__.'.'.$encoding,$contents); | |
| 75 | + //And write to filesystem cache if not done yet | |
| 76 | + if($encoding != 'none' && $iscompressed == false) | |
| 77 | +    { | |
| 78 | + //Write the content we sent | |
| 79 | + file_put_contents(__FILE__.'.'.$encoding,$contents); | |
| 80 | 80 | |
| 81 | - //And write the new content | |
| 82 | - $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); | |
| 83 | - $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); | |
| 84 | - $contents = gzencode($code,9,$flag); | |
| 85 | - file_put_contents(__FILE__.'.'.$ext,$contents); | |
| 86 | - } | |
| 81 | + //And write the new content | |
| 82 | + $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); | |
| 83 | + $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); | |
| 84 | + $contents = gzencode($code,9,$flag); | |
| 85 | + file_put_contents(__FILE__.'.'.$ext,$contents); | |
| 86 | + } | |
| 87 | 87 | } | 
| @@ -282,7 +282,7 @@ discard block | ||
| 282 | 282 | * be inlined into a data: URI. Defaults to 4096, passed through | 
| 283 | 283 | * `autoptimize_filter_css_datauri_maxsize` filter. | 
| 284 | 284 | * | 
| 285 | - * @return mixed | |
| 285 | + * @return integer|null | |
| 286 | 286 | */ | 
| 287 | 287 | private function get_datauri_maxsize() | 
| 288 | 288 |      { | 
| @@ -303,6 +303,9 @@ discard block | ||
| 303 | 303 | return $max_size; | 
| 304 | 304 | } | 
| 305 | 305 | |
| 306 | + /** | |
| 307 | + * @param false|string $url | |
| 308 | + */ | |
| 306 | 309 | private function check_datauri_exclude_list( $url ) | 
| 307 | 310 |      { | 
| 308 | 311 | static $exclude_list = null; | 
| @@ -328,6 +331,9 @@ discard block | ||
| 328 | 331 | return $matched; | 
| 329 | 332 | } | 
| 330 | 333 | |
| 334 | + /** | |
| 335 | + * @param false|string $path | |
| 336 | + */ | |
| 331 | 337 | private function build_or_get_datauri_image( $path ) | 
| 332 | 338 |      { | 
| 333 | 339 | /** | 
| @@ -746,6 +752,11 @@ discard block | ||
| 746 | 752 | return true; | 
| 747 | 753 | } | 
| 748 | 754 | |
| 755 | + /** | |
| 756 | + * @param string $code | |
| 757 | + * | |
| 758 | + * @return string | |
| 759 | + */ | |
| 749 | 760 | public function run_minifier_on( $code ) | 
| 750 | 761 |      { | 
| 751 | 762 |          if ( ! $this->alreadyminified ) { | 
| @@ -945,6 +956,9 @@ discard block | ||
| 945 | 956 | return $code; | 
| 946 | 957 | } | 
| 947 | 958 | |
| 959 | + /** | |
| 960 | + * @param string $tag | |
| 961 | + */ | |
| 948 | 962 | private function ismovable( $tag ) | 
| 949 | 963 |      { | 
| 950 | 964 |          if ( ! $this->aggregate ) { | 
| @@ -1005,7 +1019,7 @@ discard block | ||
| 1005 | 1019 | * @param string $filepath Filepath. | 
| 1006 | 1020 | * @param bool $cache_miss Optional. Force a cache miss. Default false. | 
| 1007 | 1021 | * | 
| 1008 | - * @return bool|string Url pointing to the minified css file or false. | |
| 1022 | + * @return false|string Url pointing to the minified css file or false. | |
| 1009 | 1023 | */ | 
| 1010 | 1024 | public function minify_single( $filepath, $cache_miss = false ) | 
| 1011 | 1025 |      { | 
| @@ -1057,6 +1071,9 @@ discard block | ||
| 1057 | 1071 | $this->options = $options; | 
| 1058 | 1072 | } | 
| 1059 | 1073 | |
| 1074 | + /** | |
| 1075 | + * @param string $name | |
| 1076 | + */ | |
| 1060 | 1077 | public function setOption( $name, $value ) | 
| 1061 | 1078 |      { | 
| 1062 | 1079 | $this->options[$name] = $value; | 
| @@ -14,7 +14,7 @@ discard block | ||
| 14 | 14 | * | 
| 15 | 15 | * @param bool|null $override Allows overriding the decision. | 
| 16 | 16 | * | 
| 17 | - * @return bool | |
| 17 | + * @return boolean|null | |
| 18 | 18 | */ | 
| 19 | 19 | public static function mbstring_available( $override = null ) | 
| 20 | 20 |      { | 
| @@ -130,7 +130,7 @@ discard block | ||
| 130 | 130 | * | 
| 131 | 131 | * @param bool $override Allows overriding the decision when needed. | 
| 132 | 132 | * | 
| 133 | - * @return bool | |
| 133 | + * @return boolean|null | |
| 134 | 134 | */ | 
| 135 | 135 | public static function siteurl_not_root( $override = null ) | 
| 136 | 136 |      { | 
| @@ -128,6 +128,9 @@ | ||
| 128 | 128 | parent::tearDown(); | 
| 129 | 129 | } | 
| 130 | 130 | |
| 131 | + /** | |
| 132 | + * @return string | |
| 133 | + */ | |
| 131 | 134 | protected function get_test_markup() | 
| 132 | 135 |      { | 
| 133 | 136 | $siteurl = $this->get_urls()['siteurl']; | 
| @@ -29,131 +29,131 @@ | ||
| 29 | 29 | * Exit if called directly. | 
| 30 | 30 | */ | 
| 31 | 31 |  if ( ! defined( 'ABSPATH' ) ) { | 
| 32 | - die; | |
| 32 | + die; | |
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 |  if ( ! class_exists( 'PAnD' ) ) { | 
| 36 | 36 | |
| 37 | - /** | |
| 38 | - * Class PAnD | |
| 39 | - */ | |
| 40 | -	class PAnD { | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * Init hooks. | |
| 44 | - */ | |
| 45 | -		public static function init() { | |
| 46 | - add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) ); | |
| 47 | - add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) ); | |
| 48 | - } | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * Enqueue javascript and variables. | |
| 52 | - */ | |
| 53 | -		public static function load_script() { | |
| 54 | - | |
| 55 | -			if ( is_customize_preview() ) { | |
| 56 | - return; | |
| 57 | - } | |
| 58 | - | |
| 59 | - wp_enqueue_script( | |
| 60 | - 'dismissible-notices', | |
| 61 | - plugins_url( 'dismiss-notice.js', __FILE__ ), | |
| 62 | - array( 'jquery', 'common' ), | |
| 63 | - false, | |
| 64 | - true | |
| 65 | - ); | |
| 66 | - | |
| 67 | - wp_localize_script( | |
| 68 | - 'dismissible-notices', | |
| 69 | - 'dismissible_notice', | |
| 70 | - array( | |
| 71 | - 'nonce' => wp_create_nonce( 'dismissible-notice' ), | |
| 72 | - ) | |
| 73 | - ); | |
| 74 | - } | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * Handles Ajax request to persist notices dismissal. | |
| 78 | - * Uses check_ajax_referer to verify nonce. | |
| 79 | - */ | |
| 80 | -		public static function dismiss_admin_notice() { | |
| 81 | - $option_name = sanitize_text_field( $_POST['option_name'] ); | |
| 82 | - $dismissible_length = sanitize_text_field( $_POST['dismissible_length'] ); | |
| 83 | - | |
| 84 | -			if ( 'forever' != $dismissible_length ) { | |
| 85 | - // If $dismissible_length is not an integer default to 1 | |
| 86 | - $dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length; | |
| 87 | - $dismissible_length = strtotime( absint( $dismissible_length ) . ' days' ); | |
| 88 | - } | |
| 89 | - | |
| 90 | - check_ajax_referer( 'dismissible-notice', 'nonce' ); | |
| 91 | - self::set_admin_notice_cache( $option_name, $dismissible_length ); | |
| 92 | - wp_die(); | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * Is admin notice active? | |
| 97 | - * | |
| 98 | - * @param string $arg data-dismissible content of notice. | |
| 99 | - * | |
| 100 | - * @return bool | |
| 101 | - */ | |
| 102 | -		public static function is_admin_notice_active( $arg ) { | |
| 103 | - $array = explode( '-', $arg ); | |
| 104 | - $length = array_pop( $array ); | |
| 105 | - $option_name = implode( '-', $array ); | |
| 106 | - $db_record = self::get_admin_notice_cache( $option_name ); | |
| 107 | -			if ( 'forever' == $db_record ) { | |
| 108 | - return false; | |
| 109 | -			} elseif ( absint( $db_record ) >= time() ) { | |
| 110 | - return false; | |
| 111 | -			} else { | |
| 112 | - return true; | |
| 113 | - } | |
| 114 | - } | |
| 115 | - | |
| 116 | - /** | |
| 117 | - * Returns admin notice cached timeout. | |
| 118 | - * | |
| 119 | - * @access public | |
| 120 | - * | |
| 121 | - * @param string|bool $id admin notice name or false. | |
| 122 | - * | |
| 123 | - * @return array|bool The timeout. False if expired. | |
| 124 | - */ | |
| 125 | -		public static function get_admin_notice_cache( $id = false ) { | |
| 126 | -			if ( ! $id ) { | |
| 127 | - return false; | |
| 128 | - } | |
| 129 | - $cache_key = 'pand-' . md5( $id ); | |
| 130 | - $timeout = get_site_option( $cache_key ); | |
| 131 | - $timeout = 'forever' === $timeout ? time() + 60 : $timeout; | |
| 132 | - | |
| 133 | -			if ( empty( $timeout ) || time() > $timeout ) { | |
| 134 | - return false; | |
| 135 | - } | |
| 136 | - | |
| 137 | - return $timeout; | |
| 138 | - } | |
| 139 | - | |
| 140 | - /** | |
| 141 | - * Sets admin notice timeout in site option. | |
| 142 | - * | |
| 143 | - * @access public | |
| 144 | - * | |
| 145 | - * @param string $id Data Identifier. | |
| 146 | - * @param string|bool $timeout Timeout for admin notice. | |
| 147 | - * | |
| 148 | - * @return bool | |
| 149 | - */ | |
| 150 | -		public static function set_admin_notice_cache( $id, $timeout ) { | |
| 151 | - $cache_key = 'pand-' . md5( $id ); | |
| 152 | - update_site_option( $cache_key, $timeout ); | |
| 153 | - | |
| 154 | - return true; | |
| 155 | - } | |
| 156 | - | |
| 157 | - } | |
| 37 | + /** | |
| 38 | + * Class PAnD | |
| 39 | + */ | |
| 40 | +    class PAnD { | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Init hooks. | |
| 44 | + */ | |
| 45 | +        public static function init() { | |
| 46 | + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) ); | |
| 47 | + add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) ); | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Enqueue javascript and variables. | |
| 52 | + */ | |
| 53 | +        public static function load_script() { | |
| 54 | + | |
| 55 | +            if ( is_customize_preview() ) { | |
| 56 | + return; | |
| 57 | + } | |
| 58 | + | |
| 59 | + wp_enqueue_script( | |
| 60 | + 'dismissible-notices', | |
| 61 | + plugins_url( 'dismiss-notice.js', __FILE__ ), | |
| 62 | + array( 'jquery', 'common' ), | |
| 63 | + false, | |
| 64 | + true | |
| 65 | + ); | |
| 66 | + | |
| 67 | + wp_localize_script( | |
| 68 | + 'dismissible-notices', | |
| 69 | + 'dismissible_notice', | |
| 70 | + array( | |
| 71 | + 'nonce' => wp_create_nonce( 'dismissible-notice' ), | |
| 72 | + ) | |
| 73 | + ); | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * Handles Ajax request to persist notices dismissal. | |
| 78 | + * Uses check_ajax_referer to verify nonce. | |
| 79 | + */ | |
| 80 | +        public static function dismiss_admin_notice() { | |
| 81 | + $option_name = sanitize_text_field( $_POST['option_name'] ); | |
| 82 | + $dismissible_length = sanitize_text_field( $_POST['dismissible_length'] ); | |
| 83 | + | |
| 84 | +            if ( 'forever' != $dismissible_length ) { | |
| 85 | + // If $dismissible_length is not an integer default to 1 | |
| 86 | + $dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length; | |
| 87 | + $dismissible_length = strtotime( absint( $dismissible_length ) . ' days' ); | |
| 88 | + } | |
| 89 | + | |
| 90 | + check_ajax_referer( 'dismissible-notice', 'nonce' ); | |
| 91 | + self::set_admin_notice_cache( $option_name, $dismissible_length ); | |
| 92 | + wp_die(); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Is admin notice active? | |
| 97 | + * | |
| 98 | + * @param string $arg data-dismissible content of notice. | |
| 99 | + * | |
| 100 | + * @return bool | |
| 101 | + */ | |
| 102 | +        public static function is_admin_notice_active( $arg ) { | |
| 103 | + $array = explode( '-', $arg ); | |
| 104 | + $length = array_pop( $array ); | |
| 105 | + $option_name = implode( '-', $array ); | |
| 106 | + $db_record = self::get_admin_notice_cache( $option_name ); | |
| 107 | +            if ( 'forever' == $db_record ) { | |
| 108 | + return false; | |
| 109 | +            } elseif ( absint( $db_record ) >= time() ) { | |
| 110 | + return false; | |
| 111 | +            } else { | |
| 112 | + return true; | |
| 113 | + } | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * Returns admin notice cached timeout. | |
| 118 | + * | |
| 119 | + * @access public | |
| 120 | + * | |
| 121 | + * @param string|bool $id admin notice name or false. | |
| 122 | + * | |
| 123 | + * @return array|bool The timeout. False if expired. | |
| 124 | + */ | |
| 125 | +        public static function get_admin_notice_cache( $id = false ) { | |
| 126 | +            if ( ! $id ) { | |
| 127 | + return false; | |
| 128 | + } | |
| 129 | + $cache_key = 'pand-' . md5( $id ); | |
| 130 | + $timeout = get_site_option( $cache_key ); | |
| 131 | + $timeout = 'forever' === $timeout ? time() + 60 : $timeout; | |
| 132 | + | |
| 133 | +            if ( empty( $timeout ) || time() > $timeout ) { | |
| 134 | + return false; | |
| 135 | + } | |
| 136 | + | |
| 137 | + return $timeout; | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * Sets admin notice timeout in site option. | |
| 142 | + * | |
| 143 | + * @access public | |
| 144 | + * | |
| 145 | + * @param string $id Data Identifier. | |
| 146 | + * @param string|bool $timeout Timeout for admin notice. | |
| 147 | + * | |
| 148 | + * @return bool | |
| 149 | + */ | |
| 150 | +        public static function set_admin_notice_cache( $id, $timeout ) { | |
| 151 | + $cache_key = 'pand-' . md5( $id ); | |
| 152 | + update_site_option( $cache_key, $timeout ); | |
| 153 | + | |
| 154 | + return true; | |
| 155 | + } | |
| 156 | + | |
| 157 | + } | |
| 158 | 158 | |
| 159 | 159 | } | 
| @@ -798,6 +798,9 @@ discard block | ||
| 798 | 798 | return $preload_onload; | 
| 799 | 799 | } | 
| 800 | 800 | |
| 801 | + /** | |
| 802 | + * @param string $key | |
| 803 | + */ | |
| 801 | 804 | public function get( $key ) | 
| 802 | 805 |      { | 
| 803 | 806 |          if ( ! is_array( $this->config ) ) { | 
| @@ -824,6 +827,9 @@ discard block | ||
| 824 | 827 | return false; | 
| 825 | 828 | } | 
| 826 | 829 | |
| 830 | + /** | |
| 831 | + * @param string $url | |
| 832 | + */ | |
| 827 | 833 |      private function get_futtta_feeds( $url ) { | 
| 828 | 834 |          if ( $this->settings_screen_do_remote_http ) { | 
| 829 | 835 | $rss = fetch_feed( $url ); |