Admin
8 years ago
Column
8 years ago
Helper
8 years ago
ListScreen
8 years ago
Meta
8 years ago
Notice
8 years ago
Plugin
8 years ago
Relation
8 years ago
Settings
8 years ago
ThirdParty
8 years ago
API.php
8 years ago
Addon.php
8 years ago
Admin.php
8 years ago
Autoloader.php
8 years ago
Collection.php
8 years ago
Column.php
8 years ago
Groups.php
8 years ago
Helper.php
8 years ago
ListScreen.php
8 years ago
ListScreenPost.php
8 years ago
Plugin.php
8 years ago
PluginInformation.php
8 years ago
Preferences.php
8 years ago
Relation.php
8 years ago
TableScreen.php
8 years ago
View.php
8 years ago
ViewInterface.php
8 years ago
View.php
123 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | class AC_View |
| 8 | implements AC_ViewInterface { |
| 9 | |
| 10 | /** |
| 11 | * @var array |
| 12 | */ |
| 13 | private $data = array(); |
| 14 | |
| 15 | /** |
| 16 | * @var string |
| 17 | */ |
| 18 | private $template; |
| 19 | |
| 20 | public function __construct( array $data = array() ) { |
| 21 | $this->set_data( $data ); |
| 22 | } |
| 23 | |
| 24 | public function get( $key ) { |
| 25 | if ( ! isset( $this->data[ $key ] ) ) { |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | return $this->data[ $key ]; |
| 30 | } |
| 31 | |
| 32 | public function __get( $key ) { |
| 33 | return $this->get( $key ); |
| 34 | } |
| 35 | |
| 36 | public function __set( $key, $value ) { |
| 37 | return $this->set( $key, $value ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param $key |
| 42 | * @param $value |
| 43 | * |
| 44 | * @return $this |
| 45 | */ |
| 46 | public function set( $key, $value ) { |
| 47 | $this->data[ $key ] = $value; |
| 48 | |
| 49 | return $this; |
| 50 | } |
| 51 | |
| 52 | public function get_data() { |
| 53 | return $this->data; |
| 54 | } |
| 55 | |
| 56 | public function set_data( array $data ) { |
| 57 | foreach ( $data as $key => $value ) { |
| 58 | $this->set( $key, $value ); |
| 59 | } |
| 60 | |
| 61 | return $this; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Will try to resolve the current template to a file |
| 66 | * |
| 67 | * @return false|string |
| 68 | */ |
| 69 | private function resolve_template() { |
| 70 | |
| 71 | /** |
| 72 | * Returns the available template paths for column settings |
| 73 | * |
| 74 | * @param array $paths Template paths |
| 75 | * @param string $template Current template path |
| 76 | */ |
| 77 | $paths = apply_filters( 'ac/view/templates', array( AC()->get_plugin_dir() . 'templates' ), $this->template ); |
| 78 | |
| 79 | foreach ( $paths as $path ) { |
| 80 | $file = $path . '/' . $this->template . '.php'; |
| 81 | |
| 82 | if ( is_readable( $file ) ) { |
| 83 | include $file; |
| 84 | |
| 85 | return true; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | public function render() { |
| 93 | ob_start(); |
| 94 | |
| 95 | $this->resolve_template(); |
| 96 | |
| 97 | return ob_get_clean(); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @return string |
| 102 | */ |
| 103 | public function get_template() { |
| 104 | return $this->template; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @param string $template |
| 109 | * |
| 110 | * @return $this |
| 111 | */ |
| 112 | public function set_template( $template ) { |
| 113 | $this->template = $template; |
| 114 | |
| 115 | return $this; |
| 116 | } |
| 117 | |
| 118 | public function __toString() { |
| 119 | return $this->render(); |
| 120 | } |
| 121 | |
| 122 | } |
| 123 |