Account
2 weeks ago
Cache
2 weeks ago
Contracts
2 weeks ago
Core
2 weeks ago
Http
2 weeks ago
Notices
2 weeks ago
Storage
2 weeks ago
Analyst.php
2 weeks ago
ApiRequestor.php
2 weeks ago
ApiResponse.php
2 weeks ago
Collector.php
2 weeks ago
Mutator.php
2 weeks ago
helpers.php
2 weeks ago
helpers.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 | |
| 5 | if (! function_exists('analyst_assets_path')) { |
| 6 | /** |
| 7 | * Generates path to file in assets folder |
| 8 | * |
| 9 | * @param $file |
| 10 | * @return string |
| 11 | */ |
| 12 | function analyst_assets_path($file) |
| 13 | { |
| 14 | $path = sprintf('%s/assets/%s', realpath(__DIR__ . '/..'), trim($file, '/')); |
| 15 | |
| 16 | return wp_normalize_path($path); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | |
| 21 | if (! function_exists('analyst_assets_url')) { |
| 22 | /** |
| 23 | * Generates url to file in assets folder |
| 24 | * |
| 25 | * @param $file |
| 26 | * @return string |
| 27 | */ |
| 28 | function analyst_assets_url($file) |
| 29 | { |
| 30 | $absolutePath = analyst_assets_path($file); |
| 31 | |
| 32 | // We can always rely on WP_PLUGIN_DIR, because that's where |
| 33 | // wordpress install it's plugin's. So we remove last segment |
| 34 | // of that path to get the content dir AKA directly where |
| 35 | // plugins are installed and make the magic... |
| 36 | $contentDir = is_link(WP_PLUGIN_DIR) ? |
| 37 | dirname(wp_normalize_path(readlink(WP_PLUGIN_DIR))) : |
| 38 | dirname(wp_normalize_path(WP_PLUGIN_DIR)); |
| 39 | |
| 40 | $relativePath = str_replace( $contentDir, '', $absolutePath); |
| 41 | |
| 42 | return content_url(wp_normalize_path($relativePath)); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if (! function_exists('analyst_templates_path')) { |
| 47 | /** |
| 48 | * Generates path to file in templates folder |
| 49 | * |
| 50 | * @param $file |
| 51 | * @return string |
| 52 | */ |
| 53 | function analyst_templates_path($file) |
| 54 | { |
| 55 | $path = sprintf('%s/templates/%s', realpath(__DIR__ . '/..'), trim($file, '/')); |
| 56 | |
| 57 | return wp_normalize_path($path); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if (! function_exists('analyst_require_template')) { |
| 62 | /** |
| 63 | * Require certain template with data |
| 64 | * |
| 65 | * @param $file |
| 66 | * @param array $data |
| 67 | */ |
| 68 | function analyst_require_template($file, $data = []) |
| 69 | { |
| 70 | // Extract data to current scope table |
| 71 | extract($data); |
| 72 | |
| 73 | require analyst_templates_path($file); |
| 74 | } |
| 75 | } |
| 76 |