| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Determines the location of an asset within the SEO plugin. |
| 10 |
*/ |
| 11 |
final class WPSEO_Admin_Asset_SEO_Location implements WPSEO_Admin_Asset_Location { |
| 12 |
|
| 13 |
/** |
| 14 |
* Path to the plugin file. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $plugin_file; |
| 19 |
|
| 20 |
/** |
| 21 |
* Whether or not to add the file suffix to the asset. |
| 22 |
* |
| 23 |
* @var bool |
| 24 |
*/ |
| 25 |
protected $add_suffix = true; |
| 26 |
|
| 27 |
/** |
| 28 |
* The plugin file to base the asset location upon. |
| 29 |
* |
| 30 |
* @param string $plugin_file The plugin file string. |
| 31 |
* @param bool $add_suffix Optional. Whether or not a file suffix should be added. |
| 32 |
*/ |
| 33 |
public function __construct( $plugin_file, $add_suffix = true ) { |
| 34 |
$this->plugin_file = $plugin_file; |
| 35 |
$this->add_suffix = $add_suffix; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Determines the URL of the asset on the dev server. |
| 40 |
* |
| 41 |
* @param WPSEO_Admin_Asset $asset The asset to determine the URL for. |
| 42 |
* @param string $type The type of asset. Usually JS or CSS. |
| 43 |
* |
| 44 |
* @return string The URL of the asset. |
| 45 |
*/ |
| 46 |
public function get_url( WPSEO_Admin_Asset $asset, $type ) { |
| 47 |
$path = $this->get_path( $asset, $type ); |
| 48 |
if ( empty( $path ) ) { |
| 49 |
return ''; |
| 50 |
} |
| 51 |
|
| 52 |
return plugins_url( $path, $this->plugin_file ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Determines the path relative to the plugin folder of an asset. |
| 57 |
* |
| 58 |
* @param WPSEO_Admin_Asset $asset The asset to determine the path for. |
| 59 |
* @param string $type The type of asset. |
| 60 |
* |
| 61 |
* @return string The path to the asset file. |
| 62 |
*/ |
| 63 |
protected function get_path( WPSEO_Admin_Asset $asset, $type ) { |
| 64 |
$relative_path = ''; |
| 65 |
$rtl_suffix = ''; |
| 66 |
|
| 67 |
switch ( $type ) { |
| 68 |
case WPSEO_Admin_Asset::TYPE_JS: |
| 69 |
$relative_path = 'js/dist/' . $asset->get_src(); |
| 70 |
if ( $this->add_suffix ) { |
| 71 |
$relative_path .= $asset->get_suffix() . '.js'; |
| 72 |
} |
| 73 |
break; |
| 74 |
|
| 75 |
case WPSEO_Admin_Asset::TYPE_CSS: |
| 76 |
// Path and suffix for RTL stylesheets. |
| 77 |
if ( is_rtl() && $asset->has_rtl() ) { |
| 78 |
$rtl_suffix = '-rtl'; |
| 79 |
} |
| 80 |
$relative_path = 'css/dist/' . $asset->get_src() . $rtl_suffix . $asset->get_suffix() . '.css'; |
| 81 |
break; |
| 82 |
} |
| 83 |
|
| 84 |
return $relative_path; |
| 85 |
} |
| 86 |
} |
| 87 |
|