class-ga-view-core.php
45 lines
| 1 | <?php |
| 2 | /** |
| 3 | * GoogleAnalytics View Core. |
| 4 | * |
| 5 | * @package GoogleAnalytics |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * View Core class. |
| 10 | */ |
| 11 | class Ga_View_Core { |
| 12 | |
| 13 | /** |
| 14 | * Name of the view folder. |
| 15 | */ |
| 16 | const PATH = 'view'; |
| 17 | |
| 18 | /** |
| 19 | * Loads given view file and it's data. |
| 20 | * Displays view or returns HTML code. |
| 21 | * |
| 22 | * @param string $view Filename string. |
| 23 | * @param array $data_array Data array. |
| 24 | * @param bool $html Whether to display or return HTML code. |
| 25 | * |
| 26 | * @return string |
| 27 | */ |
| 28 | public static function load( $view, $data_array = array(), $html = false ) { |
| 29 | if ( ! empty( $view ) ) { |
| 30 | foreach ( $data_array as $k => $v ) { |
| 31 | $$k = $v; |
| 32 | } |
| 33 | |
| 34 | ob_start(); |
| 35 | include GA_PLUGIN_DIR . '/' . self::PATH . '/' . $view . '.php'; |
| 36 | if ( $html ) { |
| 37 | return ob_get_clean(); |
| 38 | } else { |
| 39 | // Note: this gets escaped elsewhere. |
| 40 | echo ob_get_clean(); // phpcs:ignore |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 |