| 1 |
<?php |
| 2 |
|
| 3 |
class VP_Option_Depsloader |
| 4 |
{ |
| 5 |
|
| 6 |
/** |
| 7 |
* The VP_Option_Set object! |
| 8 |
*/ |
| 9 |
private $things; |
| 10 |
|
| 11 |
public function __construct($things) |
| 12 |
{ |
| 13 |
$this->things = $things; |
| 14 |
} |
| 15 |
|
| 16 |
public function build() |
| 17 |
{ |
| 18 |
|
| 19 |
$set = $this->things; |
| 20 |
|
| 21 |
$result = array( |
| 22 |
'scripts' => array(), |
| 23 |
'styles' => array(), |
| 24 |
'localize_name' => 'vp_opt', |
| 25 |
'localize_default' => array( |
| 26 |
'nonce', 'impexp_msg' |
| 27 |
), |
| 28 |
'localize' => array( |
| 29 |
'name' => 'vpt_option' |
| 30 |
), |
| 31 |
'use_upload' => false, |
| 32 |
'use_new_media_upload' => false, |
| 33 |
'main_js' => array( |
| 34 |
'name' => 'vp-option', |
| 35 |
'path' => VP_PUBLIC_URL . '/js/option.min.js', |
| 36 |
), |
| 37 |
'main_css' => array( |
| 38 |
'name' => 'vp-option', |
| 39 |
'path' => VP_PUBLIC_URL . '/css/option.min.css' |
| 40 |
), |
| 41 |
); |
| 42 |
|
| 43 |
$result['scripts'] = VP_Util_Config::instance()->load('dependencies', 'scripts.always'); |
| 44 |
$result['styles'] = VP_Util_Config::instance()->load('dependencies', 'styles.always'); |
| 45 |
|
| 46 |
$scripts = VP_Util_Config::instance()->load('dependencies', 'scripts.paths'); |
| 47 |
$styles = VP_Util_Config::instance()->load('dependencies', 'styles.paths'); |
| 48 |
$rules = VP_Util_Config::instance()->load('dependencies', 'rules'); |
| 49 |
|
| 50 |
$fields = $set->get_fields(); |
| 51 |
foreach ($fields as $field) |
| 52 |
{ |
| 53 |
$type = VP_Util_Reflection::field_type_from_class(get_class($field)); |
| 54 |
if( array_key_exists($type, $rules) ) |
| 55 |
{ |
| 56 |
$result['scripts'] = array_merge($result['scripts'], $rules[$type]['js']); |
| 57 |
$result['styles'] = array_merge($result['styles'], $rules[$type]['css']); |
| 58 |
} |
| 59 |
// check if using upload button |
| 60 |
if( $type == 'upload' ) |
| 61 |
{ |
| 62 |
$result['use_upload'] = true; |
| 63 |
} |
| 64 |
} |
| 65 |
$result['scripts'] = array_unique($result['scripts']); |
| 66 |
$result['styles'] = array_unique($result['styles']); |
| 67 |
|
| 68 |
return $result; |
| 69 |
} |
| 70 |
|
| 71 |
public function can_output($hook_suffix = '') |
| 72 |
{ |
| 73 |
// if not in option page, don't load |
| 74 |
$menu_page_slug = VP_Util_Config::instance()->load('option', 'menu_page_slug'); |
| 75 |
if( $hook_suffix == ('appearance_page_' . $menu_page_slug) ) |
| 76 |
return true; |
| 77 |
return false; |
| 78 |
} |
| 79 |
|
| 80 |
} |