| 1 |
<?php |
| 2 |
|
| 3 |
namespace EventPost; |
| 4 |
/* |
| 5 |
* @package event-post |
| 6 |
*/ |
| 7 |
|
| 8 |
|
| 9 |
class DashIcons{ |
| 10 |
public $icons; |
| 11 |
public $icons_html_entities; |
| 12 |
public $transient_name; |
| 13 |
public $transient_name_html_entities; |
| 14 |
|
| 15 |
function __construct(){ |
| 16 |
$this->icons = []; |
| 17 |
$this->icons_html_entities = []; |
| 18 |
$this->transient_name = "dashicons_list"; |
| 19 |
$this->transient_name_html_entities = "dashicons_list_html_entities"; |
| 20 |
add_action('init', array(&$this,'init_icons')); |
| 21 |
} |
| 22 |
function init_icons() { |
| 23 |
if(get_transient($this->transient_name) && get_transient($this->transient_name_html_entities)){ |
| 24 |
$this->icons = get_transient($this->transient_name); |
| 25 |
$this->icons_html_entities = get_transient($this->transient_name_html_entities); |
| 26 |
}else{ |
| 27 |
$css_file = file_get_contents(ABSPATH. 'wp-includes/css/dashicons.css'); |
| 28 |
$css_array = explode('}',$css_file); |
| 29 |
foreach ($css_array as $rule) { |
| 30 |
$matches = []; |
| 31 |
if(preg_match( "/\.dashicons-((?:\w+-?)+\w+):before {\s*content:\s*[\"\']\\\(\w+)[\"\'];/m", |
| 32 |
$rule, |
| 33 |
$matches)) |
| 34 |
{ |
| 35 |
if(isset($matches[1]) && isset($matches[2])){ |
| 36 |
$this->icons[$matches[1]] = $matches[2]; |
| 37 |
$this->icons_html_entities[$matches[1]] = '&#x'.$matches[2].'; '.$matches[1]; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
set_transient($this->transient_name , $this->icons, MONTH_IN_SECONDS ); |
| 42 |
set_transient($this->transient_name_html_entities , $this->icons_html_entities, MONTH_IN_SECONDS ); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
} |
| 47 |
|