Changeset 2469780
- Timestamp:
- 02/05/2021 08:25:08 PM (5 years ago)
- Location:
- display-metadata/trunk
- Files:
-
- 13 edited
-
Metabox/class-metabox-factory.php (modified) (2 diffs)
-
Metabox/class-metabox.php (modified) (2 diffs)
-
Metabox/class-metadata-iterator.php (modified) (1 diff)
-
Metabox/class-none.php (modified) (1 diff)
-
Metabox/class-post.php (modified) (2 diffs)
-
Metabox/class-term.php (modified) (2 diffs)
-
assets/display_metadata.css (modified) (3 diffs)
-
assets/display_metadata.js (modified) (1 diff)
-
class-plugin.php (modified) (2 diffs)
-
display-metadata.php (modified) (2 diffs)
-
readme.txt (modified) (6 diffs)
-
views/assets.php (modified) (1 diff)
-
views/meta_list.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
display-metadata/trunk/Metabox/class-metabox-factory.php
r2443918 r2469780 9 9 10 10 private const NONE_ID = 0; 11 11 12 private const DEFAULT_METABOX = __NAMESPACE__ . '\None'; 13 12 14 private const METABOX_TYPES_BY_SCREEN_VAR_KEY = [ 13 15 'post' => __NAMESPACE__ . '\Post', 14 16 'tag_ID' => __NAMESPACE__ . '\Term', 15 17 'user_id' => __NAMESPACE__ . '\User', 18 'c' => __NAMESPACE__ . '\Comment', 16 19 ]; 17 20 … … 23 26 * @return Metabox 24 27 */ 25 final public static function get_current_metabox( array $screen_vars ): Metabox { 28 final public static function get_current_metabox( array $screen_vars ): Metabox 29 { 26 30 $screen_vars = array_filter( $screen_vars, 'is_numeric' ); 27 31 28 32 foreach ( self::METABOX_TYPES_BY_SCREEN_VAR_KEY as $item_id_key => $metabox_type ) { 29 30 if ( empty( $screen_vars[ $item_id_key ] ) || ! is_a( $metabox_type, Metabox::class, $allow_string = true ) ) { 33 if ( empty( $screen_vars[ $item_id_key ] ) || !is_a( $metabox_type, Metabox::class, $allow_string = true ) ) { 31 34 continue; 32 35 } 33 36 34 $item_id = absint( $screen_vars[ $item_id_key ] );37 $item_id = absint( $screen_vars[ $item_id_key ] ); 35 38 36 39 return $metabox_type::from_item_id( $item_id ); -
display-metadata/trunk/Metabox/class-metabox.php
r2443918 r2469780 4 4 5 5 use Trasweb\Plugins\DisplayMetadata\Plugin; 6 6 7 use const Trasweb\Plugins\DisplayMetadata\PLUGIN_NAME; 7 8 … … 11 12 abstract class Metabox { 12 13 13 protected const METABOX_FILE = Plugin::VIEWS_PATH . '/metabox.php'; 14 protected const ASSETS_FILE = Plugin::VIEWS_PATH . '/assets.php'; 15 protected const HEADER_FILE = Plugin::VIEWS_PATH . '/header.php'; 16 protected const TITLE = ''; 17 protected const FOOTER_FILE = Plugin::VIEWS_PATH . '/footer.php'; 14 protected const METABOX_FILE = Plugin::VIEWS_PATH . '/metabox.php'; 18 15 19 /** 20 * @var string $item_id ID from user, post or term. 21 */ 22 protected $item_id; 16 protected const ASSETS_FILE = Plugin::VIEWS_PATH . '/assets.php'; 23 17 24 private function __construct() { 25 //not direct instance, please 26 } 18 protected const HEADER_FILE = Plugin::VIEWS_PATH . '/header.php'; 27 19 28 private function __clone() { 29 //not cloning please 30 } 20 protected const TITLE = ''; 31 21 32 /** 33 * Named constructor. Create an instance from an item id. 34 * 35 * @param int $item_id 36 * 37 * @return static 38 */ 39 final public static function from_item_id( int $item_id ): self { 40 $metabox = new static(); 41 $metabox->item_id = $item_id; 22 protected const FOOTER_FILE = Plugin::VIEWS_PATH . '/footer.php'; 42 23 43 return $metabox; 44 } 24 /** 25 * @var string $item_id ID from user, post or term. 26 */ 27 protected $item_id; 45 28 46 /** 47 * Register a metabox in order to display it later. 48 * 49 * @return void 50 */ 51 abstract public function register(): void; 29 private function __construct() 30 { 31 // not direct instance, please 32 } 52 33 53 /** 54 * Check if a metabox can be registered 55 * 56 * @return bool 57 */ 58 abstract protected function can_be_registered(): bool; 34 private function __clone() 35 { 36 // not cloning please 37 } 59 38 60 /** 61 * Retrieve item properties/fields. E.g: ID, post_title, ... 62 * 63 * @return array 64 */ 65 abstract protected function get_item_properties(): array; 39 /** 40 * Named constructor. Create an instance from an item id. 41 * 42 * @param integer $item_id 43 * 44 * @return static 45 */ 46 final public static function from_item_id( int $item_id ): self 47 { 48 $metabox = new static(); 49 $metabox->item_id = $item_id; 66 50 67 /** 68 * Retrieve item metaata. E.g: 69 * 70 * @return array 71 */ 72 abstract protected function get_item_metadata(): array; 51 return $metabox; 52 } 73 53 74 /** 75 * Display metadata metabox. 76 * 77 * @return void 78 */ 79 final public function display(): void { 80 $metabox_title = __( static::TITLE, PLUGIN_NAME ); 54 /** 55 * Register a metabox in order to display it later. 56 * 57 * @return void 58 */ 59 abstract public function register(): void; 81 60 82 $item_properties = $this->get_item_properties(); 83 $item_metadata = $this->get_item_metadata(); 61 /** 62 * Check if a metabox can be registered 63 * 64 * @return boolean 65 */ 66 abstract protected function can_be_registered(): bool; 84 67 85 $item_vars = [ 86 __( 'Properties', PLUGIN_NAME ) => $item_properties, 87 __( 'Metadata', PLUGIN_NAME ) => $item_metadata, 88 ]; 68 /** 69 * Retrieve item properties/fields. E.g: ID, post_title, ... 70 * 71 * @return array 72 */ 73 abstract protected function get_item_properties(): array; 89 74 90 $metadata_list = Metadata_Iterator::from_vars_list( $item_vars ); 75 /** 76 * Retrieve item metaata. E.g: 77 * 78 * @return array 79 */ 80 abstract protected function get_item_metadata(): array; 91 81 92 require static::METABOX_FILE; 93 } 82 /** 83 * Display metadata metabox. 84 * 85 * @return void 86 */ 87 final public function display(): void 88 { 89 $metabox_title = __( static::TITLE, PLUGIN_NAME ); 90 91 $item_properties = $this->get_item_properties(); 92 $item_metadata = $this->get_item_metadata(); 93 94 $item_vars = [ 95 __( 'Properties', PLUGIN_NAME ) => $item_properties, 96 __( 'Metadata', PLUGIN_NAME ) => $item_metadata, 97 ]; 98 99 $metadata_list = Metadata_Iterator::from_vars_list( $item_vars ); 100 101 include static::METABOX_FILE; 102 } 94 103 } -
display-metadata/trunk/Metabox/class-metadata-iterator.php
r2443918 r2469780 13 13 class Metadata_Iterator extends ArrayIterator { 14 14 15 protected const META_LIST_VIEW = Plugin::VIEWS_PATH . '/meta_list.php';15 protected const META_LIST_VIEW = Plugin::VIEWS_PATH . '/meta_list.php'; 16 16 17 private $depth;17 private $depth; 18 18 19 /** 20 * Named constructor. 21 * 22 * @param array $vars_list List of vars. 23 * @param int $depth Current depth for these vars. 24 * 25 * @return static 26 */ 27 public static function from_vars_list( array $vars_list, int $depth = 1 ): self { 28 $iterator = new self( $vars_list, ArrayIterator::STD_PROP_LIST ); 29 $iterator->depth = $depth; 19 /** 20 * Named constructor. 21 * 22 * @param array $vars_list List of vars. 23 * @param integer $depth Current depth for these vars. 24 * 25 * @return static 26 */ 27 public static function from_vars_list( array $vars_list, int $depth = 1 ): self 28 { 29 $iterator = new self( $vars_list, ArrayIterator::STD_PROP_LIST ); 30 $iterator->depth = $depth; 30 31 31 return $iterator;32 }32 return $iterator; 33 } 33 34 34 /** 35 * Retrieve current value of current meta. 36 * 37 * @return $this|mixed|string 38 */ 39 public function current() { 40 $meta_value = maybe_unserialize( parent::current() ); 35 /** 36 * Retrieve current value of current meta. 37 * 38 * @return $this|mixed|string 39 */ 40 public function current() 41 { 42 $meta_value = maybe_unserialize( parent::current() ); 41 43 42 //Sometimes, unserialize returns objects43 if ( \is_object( $meta_value ) ) {44 $meta_value = \json_decode( \json_encode( $meta_value ), true );45 }44 // Sometimes, unserialize returns objects 45 if ( \is_object( $meta_value ) ) { 46 $meta_value = \json_decode( \json_encode( $meta_value ), true ); 47 } 46 48 47 if ( is_array( $meta_value ) ) {48 ksort( $meta_value );49 if ( is_array( $meta_value ) ) { 50 ksort( $meta_value ); 49 51 50 return Metadata_Iterator::from_vars_list( $meta_value, $this->depth + 1 );51 }52 return Metadata_Iterator::from_vars_list( $meta_value, $this->depth + 1 ); 53 } 52 54 53 if ( is_null( $meta_value ) ) {54 return 'NULL';55 }55 if ( is_null( $meta_value ) ) { 56 return 'NULL'; 57 } 56 58 57 return htmlentities( (string) $meta_value);58 }59 return make_clickable( htmlentities( (string)$meta_value ) ); 60 } 59 61 60 /** 61 * Current depth. 62 * 63 * @return integer 64 */ 65 public function get_depth(): int { 66 return (int) $this->depth; 67 } 62 public function get_attributes(): string 63 { 64 $attrs[] = ( 1 === $this->get_depth() ) ? 'meta_headers' : 'meta_item'; 65 $attrs[] = 'depth_' . $this->get_depth(); 66 $attrs[] = ( is_array( parent::current() ) && empty( parent::current() ) ) ? 'meta_empty_array' : ''; 68 67 69 /** 70 * Genererate a view for current metadata list. 71 * 72 * @return string 73 */ 74 public function __toString() { 75 $metadata_list = $this; 68 if ( '' !== parent::current() ) { 69 $attrs[] = ( ! is_array( parent::current() ) && ! is_serialized( parent::current() ) ) ? 'meta_scalar' : 'meta_array'; 70 } 76 71 77 ob_start(); 78 ( static function () use ( $metadata_list ) { 79 include static::META_LIST_VIEW; 80 } )(); 72 return implode( ' ', $attrs ); 73 } 81 74 82 return \ob_get_clean() ?: ''; 83 } 75 /** 76 * Current depth. 77 * 78 * @return integer 79 */ 80 private function get_depth(): int 81 { 82 return (int)$this->depth; 83 } 84 85 /** 86 * Genererate a view for current metadata list. 87 * 88 * @return string 89 */ 90 public function __toString() 91 { 92 ob_start(); 93 ( static function ( Metadata_Iterator $metadata_list ) { 94 include static::META_LIST_VIEW; 95 } )( $this ); 96 97 return \ob_get_clean() ?: ''; 98 } 84 99 } -
display-metadata/trunk/Metabox/class-none.php
r2443918 r2469780 7 7 */ 8 8 class None extends Metabox { 9 /** 10 * Nothing to do. 11 */ 12 public function register(): void 13 { 14 // None 15 } 9 16 10 /** 11 * Nothing to do. 12 */ 13 public function register(): void { 14 //None 15 } 17 /** 18 * cannot can se registered 19 * 20 * @return array 21 */ 22 protected function can_be_registered(): bool 23 { 24 return false; 25 } 16 26 17 /** 18 * cannot can se registered 19 * 20 * @return array 21 */ 22 protected function can_be_registered(): bool { 23 return false; 24 } 27 /** 28 * Retrieve none 29 * 30 * @return array 31 */ 32 protected function get_item_properties(): array 33 { 34 return []; 35 } 25 36 26 /** 27 * Retrieve none 28 * 29 * @return array 30 */ 31 protected function get_item_properties(): array { 32 return []; 33 } 34 35 /** 36 * Retrieve none 37 * 38 * @return array 39 */ 40 protected function get_item_metadata(): array { 41 return []; 42 } 37 /** 38 * Retrieve none 39 * 40 * @return array 41 */ 42 protected function get_item_metadata(): array 43 { 44 return []; 45 } 43 46 } -
display-metadata/trunk/Metabox/class-post.php
r2443918 r2469780 4 4 5 5 use Trasweb\Plugins\DisplayMetadata\Plugin; 6 6 7 use const ARRAY_A; 7 8 … … 11 12 final class Post extends Metabox { 12 13 13 protected const TITLE = 'Post information'; 14 protected const HEADER_FILE = Plugin::VIEWS_PATH . '/nothing.php'; 15 protected const FOOTER_FILE = Plugin::VIEWS_PATH . '/nothing.php'; 14 protected const TITLE = 'Post information'; 16 15 17 /** 18 * Register a metabox in order to display it later. 19 * 20 * @return void 21 */ 22 public function register(): void { 23 if ( !$this->can_be_registered() ) { 24 return; 25 } 16 protected const HEADER_FILE = Plugin::VIEWS_PATH . '/nothing.php'; 26 17 27 add_meta_box( 28 'trasweb_metadata_metabox', // Unique ID 29 static::TITLE, // Box title 30 [ $this, 'display' ], // Content callback 31 $this->get_accepted_cpt() // Post type 32 ); 33 } 18 protected const FOOTER_FILE = Plugin::VIEWS_PATH . '/nothing.php'; 34 19 35 /** 36 * Check if a metabox can be registered 37 * 38 * @return bool 39 */ 40 protected function can_be_registered(): bool { 41 $current_screen = Plugin::get_current_screen(); 20 /** 21 * Register a metabox in order to display it later. 22 * 23 * @return void 24 */ 25 public function register(): void 26 { 27 if ( ! $this->can_be_registered() ) { 28 return; 29 } 42 30 43 return 'post' === $current_screen->slug; 44 } 31 add_meta_box( 'trasweb_metadata_metabox', // Unique ID 32 static::TITLE, // Box title 33 [ $this, 'display' ], // Content callback 34 $this->get_accepted_cpt() // Post type 35 ); 36 } 45 37 46 /**47 * Helepr: Retrieve list of post type with show-ui. This cpt are where the metabox will be displayed. 48 *49 * @return array 50 */51 protected function get_accepted_cpt(): array { 52 return array_values( get_post_types( [ 'show_ui' => true ] ) ?: [] ); 53 } 38 /** 39 * Check if a metabox can be registered 40 * 41 * @return boolean 42 */ 43 protected function can_be_registered(): bool 44 { 45 $current_screen = Plugin::get_current_screen(); 54 46 55 /** 56 * Retrieve item properties/fields. E.g: ID, post_title, ... 57 * 58 * @return array 59 */ 60 protected function get_item_properties(): array { 61 return get_post( $this->item_id, ARRAY_A ) ?: []; 62 } 47 return 'post' === $current_screen->slug; 48 } 63 49 64 /** 65 * Retrieve item metaata. E.g: _edit_lock 66 * 67 * @return array 68 */ 69 protected function get_item_metadata(): array { 70 return array_map( 'array_shift', get_post_meta( $this->item_id ) ?: [] ); 71 } 50 /** 51 * Helepr: Retrieve list of post type with show-ui. This cpt are where the metabox will be displayed. 52 * 53 * @return array 54 */ 55 protected function get_accepted_cpt(): array 56 { 57 return array_values( get_post_types( [ 'show_ui' => true ] ) ?: [] ); 58 } 59 60 /** 61 * Retrieve item properties/fields. E.g: ID, post_title, ... 62 * 63 * @return array 64 */ 65 protected function get_item_properties(): array 66 { 67 return get_post( $this->item_id, ARRAY_A ) ?: []; 68 } 69 70 /** 71 * Retrieve item metaata. E.g: _edit_lock 72 * 73 * @return array 74 */ 75 protected function get_item_metadata(): array 76 { 77 return array_map( 'array_shift', get_post_meta( $this->item_id ) ?: [] ); 78 } 72 79 } -
display-metadata/trunk/Metabox/class-term.php
r2443918 r2469780 4 4 5 5 use Trasweb\Plugins\DisplayMetadata\Plugin; 6 6 7 use const ARRAY_A; 7 8 … … 11 12 final class Term extends Metabox { 12 13 13 protected const TITLE = 'Term information';14 protected const TITLE = 'Term information'; 14 15 15 /** 16 * Register a metabox in order to display it later. 17 * 18 * @return void 19 */ 20 public function register(): void { 21 if ( !$this->can_be_registered() ) { 22 return; 23 } 16 /** 17 * Register a metabox in order to display it later. 18 * 19 * @return void 20 */ 21 public function register(): void 22 { 23 if ( ! $this->can_be_registered() ) { 24 return; 25 } 24 26 25 $term = $this->get_item_properties();27 $term = $this->get_item_properties(); 26 28 27 if ( empty( $term[ 'term_id' ] ) ) {28 return;29 }29 if ( empty( $term[ 'term_id' ] ) ) { 30 return; 31 } 30 32 31 add_action( $term[ 'taxonomy' ] . '_edit_form', [ $this, 'display' ] );32 }33 add_action( $term[ 'taxonomy' ] . '_edit_form', [ $this, 'display' ] ); 34 } 33 35 34 /** 35 * Check if a metabox can be registered 36 * 37 * @return bool 38 */ 39 protected function can_be_registered(): bool { 40 $current_screen = Plugin::get_current_screen(); 36 /** 37 * Check if a metabox can be registered 38 * 39 * @return boolean 40 */ 41 protected function can_be_registered(): bool 42 { 43 $current_screen = Plugin::get_current_screen(); 41 44 42 return 'term' === $current_screen->slug;43 }45 return 'term' === $current_screen->slug; 46 } 44 47 45 /** 46 * Retrieve item properties/fields. E.g: term_id, name, ... 47 * 48 * @return array 49 */ 50 protected function get_item_properties(): array { 51 return get_term( $this->item_id, '', ARRAY_A ) ?: []; 52 } 48 /** 49 * Retrieve item properties/fields. E.g: term_id, name, ... 50 * 51 * @return array 52 */ 53 protected function get_item_properties(): array 54 { 55 return get_term( $this->item_id, '', ARRAY_A ) ?: []; 56 } 53 57 54 /** 55 * Retrieve item metaata. 56 * 57 * @return array 58 */ 59 protected function get_item_metadata(): array { 60 return array_map( 'array_shift', get_term_meta( $this->item_id ) ?: [] ); 61 } 58 /** 59 * Retrieve item metaata. 60 * 61 * @return array 62 */ 63 protected function get_item_metadata(): array 64 { 65 return array_map( 'array_shift', get_term_meta( $this->item_id ) ?: [] ); 66 } 62 67 } -
display-metadata/trunk/assets/display_metadata.css
r2443918 r2469780 29 29 } 30 30 31 #trasweb-metadata-metabox .meta_empty_array table { 32 border: 1px solid #7e8993; 33 box-sizing: border-box; 34 margin: 13px 6px; 35 } 36 31 37 #trasweb-metadata-metabox td.meta_value table { 32 38 box-sizing: border-box; … … 36 42 #trasweb-metadata-metabox td, #trasweb-metadata-metabox th { 37 43 border: 1px solid #7e8993; 38 font-size: 0.95em;44 font-size: 1em; 39 45 vertical-align: baseline; 40 46 padding: 4px 5px; 41 47 } 42 48 49 #trasweb-metadata-metabox .depth_2:hover td.meta_key, #trasweb-metadata-metabox .depth_2:hover td.meta_value { 50 background: #dbdbdb; 51 } 52 53 #trasweb-metadata-metabox .depth_1 > td.meta_key { 54 font-weight: bold; 55 font-size: 1.2em; 56 } 57 43 58 #trasweb-metadata-metabox td.meta_key { 44 background-color: #f 3f4f5;59 background-color: #f1f1f1; 45 60 font-weight: 600; 61 color: #000; 62 letter-spacing: 1px; 63 } 64 65 #trasweb-metadata-metabox .meta_item > td.meta_key:hover{ 66 position: relative; 67 background-clip: padding-box; /* fix bug with borders in position relative */ 68 } 69 70 /** label for copy */ 71 #trasweb-metadata-metabox .meta_item > td.meta_key:hover:after { 72 width: 100px; 73 height: 15px; 74 display: inline-block; 75 position: absolute; 76 content: "Click to copy key"; 77 background-color: #555; 78 color: #fff; 79 border-radius: 6px; 80 padding: 5px; 81 z-index: 1; 82 top: -30px; 83 left: 0; 84 text-align: center; 85 font-size: 10px; 46 86 } 47 87 … … 51 91 word-wrap: break-word; 52 92 width: 100%; 93 color: #333; 53 94 } 95 96 #trasweb-metadata-metabox .meta_scalar > td.meta_value:hover{ 97 position: relative; 98 background-clip: padding-box; /* fix bug with borders in position relative */ 99 } 100 101 /** Zebra style */ 102 #trasweb-metadata-metabox tr:nth-child(odd) > td.meta_value { 103 background-color: #f9f9f9; 104 } 105 106 /** label for copy */ 107 #trasweb-metadata-metabox .meta_scalar > td.meta_value:hover:after { 108 width: 100px; 109 height: 15px; 110 display: inline-block; 111 position: absolute; 112 content: "Click to copy value"; 113 background-color: #555; 114 color: #fff; 115 border-radius: 6px; 116 padding: 5px; 117 z-index: 1; 118 top: -34px; 119 left: 45%; 120 text-align: center; 121 font-size: 10px; 122 } 123 -
display-metadata/trunk/assets/display_metadata.js
r2443918 r2469780 1 trasweb_fit_metabox_width = function (){1 trasweb_fit_metabox_width = function () { 2 2 /* Avoid overflow */ 3 var metadata_container = document.getElementById('trasweb-metadata-metabox');3 var metadata_container = document.getElementById('trasweb-metadata-metabox'); 4 4 5 if ( 0 === metadata_container.clientWidth) {5 if (0 === metadata_container.clientWidth) { 6 6 /* Fix Gutenberg */ 7 7 setTimeout('trasweb_fit_metabox_width()', 100); 8 return ;8 return; 9 9 } 10 10 11 for ( var depth_i = 1; true; depth_i++) {11 for (var depth_i = 1; true; depth_i++) { 12 12 var main_tr_list = metadata_container.querySelectorAll('.depth_' + depth_i); 13 13 14 if ( main_tr_list.length <= 0) {14 if (main_tr_list.length <= 0) { 15 15 break; 16 16 } 17 17 18 for ( var i = 0; i < main_tr_list.length; i++) {19 var top_container = main_tr_list[i].parentElement.parentElement;18 for (var i = 0; i < main_tr_list.length; i++) { 19 var top_container = main_tr_list[i].parentElement.parentElement; 20 20 var td_key = main_tr_list[i].children[0]; 21 var td_value = main_tr_list[i].children[1];21 var td_value = main_tr_list[i].children[1]; 22 22 23 if ( ( td_value.clientWidth + td_key.clientWidth ) > top_container.clientWidth) {24 td_value.style.maxWidth = ( top_container.clientWidth - td_key.clientWidth - 15 /* padding */) + 'px';23 if ((td_value.clientWidth + td_key.clientWidth) > top_container.clientWidth) { 24 td_value.style.maxWidth = (top_container.clientWidth - td_key.clientWidth - 15 /* padding */) + 'px'; 25 25 } 26 27 var event_data = { 'td_value': td_value, 'td_key': td_key, 'tr': main_tr_list[i] }; 28 var event = new CustomEvent("meta_element_loaded", {detail: event_data}); 29 30 metadata_container.dispatchEvent(event); 26 31 } 27 32 } 28 33 }; 29 34 35 36 30 37 /** 31 38 * Show/Hide metabox when click in 32 39 */ 33 document.addEventListener('DOMContentLoaded', function () {40 document.addEventListener('DOMContentLoaded', function () { 34 41 /* non post container */ 35 var container = document.getElementById('trasweb_metadata_metabox__container');42 var container = document.getElementById('trasweb_metadata_metabox__container'); 36 43 37 44 /* enable open/close */ 38 if ( null != container) {39 container.getElementsByTagName('h2')[0].addEventListener('click', function (event) {45 if (null != container) { 46 container.getElementsByTagName('h2')[0].addEventListener('click', function (event) { 40 47 this.classList.toggle('closed'); 41 48 }.bind(container)); 42 49 } 43 50 51 /** enable copy key / value */ 52 if (navigator.clipboard) { 53 var metadata_container = document.getElementById('trasweb-metadata-metabox'); 54 55 metadata_container.addEventListener('meta_element_loaded', function (e) { 56 e.detail.td_key.addEventListener('click', function () { 57 return navigator.clipboard.writeText(this.innerText); 58 }); 59 60 if(e.detail.tr.classList.contains( 'meta_scalar') ) { 61 e.detail.td_value.addEventListener('click', function () { 62 return navigator.clipboard.writeText(this.innerText); 63 }); 64 } 65 66 }); 67 } 68 69 /** enable fit width */ 44 70 trasweb_fit_metabox_width(); 45 71 }); -
display-metadata/trunk/class-plugin.php
r2443918 r2469780 4 4 5 5 use Trasweb\Plugins\DisplayMetadata\Metabox\Metabox_Factory; 6 6 7 use function define; 7 8 … … 11 12 final class Plugin { 12 13 13 public const PATH= __DIR__;14 public const NAMESPACE= __NAMESPACE__;15 public const VIEWS_PATH= self::PATH . '/views';16 public const ASSETS_PATH= self::PATH . '/assets';17 public const METABOX_FILE_PATTERN = self::PATH . '/Metabox/class-%s.php';18 public const NEEDED_CAPABILITY= 'display_metadata_metabox';14 public const PATH = __DIR__; 15 public const NAMESPACE = __NAMESPACE__; 16 public const VIEWS_PATH = self::PATH . '/views'; 17 public const ASSETS_PATH = self::PATH . '/assets'; 18 public const METABOX_FILE_PATTERN = self::PATH . '/Metabox/class-%s.php'; 19 public const NEEDED_CAPABILITY = 'display_metadata_metabox'; 19 20 20 private $screen_vars;21 private $screen_vars; 21 22 22 /** 23 * Plugin constructor. 24 * 25 * @param array $screen_vars Params( normally $_GET ) from current screen. 26 */ 27 public function __construct( array $screen_vars ) { 28 $this->screen_vars = $screen_vars; 29 } 23 /** 24 * Plugin constructor. 25 * 26 * @param array $screen_vars Params( normally $_GET ) from current screen. 27 */ 28 public function __construct( array $screen_vars ) 29 { 30 $this->screen_vars = $screen_vars; 31 } 30 32 31 /**32 * Plugin Starts 33 *34 * @return void 35 */36 public function __invoke(): void { 37 if ( !current_user_can( 'administrator' ) && !\current_user_can( self::NEEDED_CAPABILITY ) ){38 return;39 } 33 /** 34 * Retrieve current screen. 35 * 36 * @return \WP_Screen 37 */ 38 final public static function get_current_screen(): \WP_Screen 39 { 40 include_once ABSPATH . 'wp-admin/includes/post.php'; 41 include_once ABSPATH . 'wp-admin/includes/class-wp-screen.php'; 40 42 41 $this->bootstrap(); 43 $pagenow = self::get_page_now(); 44 $screen = \WP_Screen::get($pagenow); 42 45 43 $metabox = Metabox_Factory::get_current_metabox( $this->screen_vars );44 $metabox->register();45 } 46 $screen->slug = $screen->base ?: ''; 47 $screen->base = strtok($screen->slug, '-') ?: ''; 48 $screen->place = strtok('') ?: 'main'; 46 49 47 /** 48 * Define basic of plugin in order to can be loaded. 49 * 50 * @return void 51 */ 52 final private function bootstrap(): void { 53 define( self::NAMESPACE . '\PLUGIN_NAME', basename( self::PATH ) ); 54 define( self::NAMESPACE . '\PLUGIN_TITLE', __( 'Display metadata', PLUGIN_NAME ) ); 50 return $screen; 51 } 55 52 56 //Fix for profile admin pages 57 if ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) { 58 $this->screen_vars[ 'user_id' ] = get_current_user_id(); 59 } 53 /** 54 * Helper: Retrieve page now from request 55 * 56 * @return string 57 */ 58 final private static function get_page_now(): string 59 { 60 global $pagenow; 60 61 61 $this->register_metabox_autoload(); 62 } 62 if ( ! $pagenow ) { 63 unset($pagenow); 63 64 64 /** 65 * Register plugin autoload for metabo classes. 66 * 67 * @return void 68 */ 69 final private function register_metabox_autoload(): void { 70 spl_autoload_register( function ( $class_name ) { 71 if ( 0 !== strpos( $class_name, self::NAMESPACE ) ) { 72 return; 73 } 65 $current_base_url = parse_url($_SERVER[ 'REQUEST_URI' ], PHP_URL_PATH) ?: ''; 74 66 75 $file_name = strtolower( str_replace('_', '-', trim( strrchr( $class_name, '\\' ), '\\' ) ) ); 76 require sprintf( self::METABOX_FILE_PATTERN, $file_name ); 77 }, $throw_exception = false ); 78 } 67 $pagenow = strrchr($current_base_url, '/') ?: $current_base_url; 68 } 79 69 80 /** 81 * Retrieve current screen. 82 * 83 * @return \WP_Screen 84 */ 85 final public static function get_current_screen(): \WP_Screen { 86 include_once ABSPATH . 'wp-admin/includes/post.php'; 87 include_once ABSPATH . 'wp-admin/includes/class-wp-screen.php'; 70 return basename($pagenow, '.php'); 71 } 88 72 89 $pagenow = self::get_page_now(); 90 $screen = \WP_Screen::get( $pagenow ); 73 /** 74 * Plugin Starts 75 * 76 * @return void 77 */ 78 public function __invoke(): void 79 { 80 if ( ! current_user_can('administrator') && ! \current_user_can(self::NEEDED_CAPABILITY) ) { 81 return; 82 } 91 83 92 $screen->slug = $screen->base ?: ''; 93 $screen->base = strtok( $screen->slug, '-' ) ?: ''; 94 $screen->place = strtok( '' ) ?: 'main'; 84 $this->bootstrap(); 95 85 96 return $screen; 97 } 86 $metabox = Metabox_Factory::get_current_metabox($this->screen_vars); 87 $metabox->register(); 88 } 98 89 99 /** 100 * Helper: Retrieve page now from request 101 * 102 * @return string 103 */ 104 final private static function get_page_now(): string { 105 global $pagenow; 90 /** 91 * Define basic of plugin in order to can be loaded. 92 * 93 * @return void 94 */ 95 final private function bootstrap(): void 96 { 97 define(self::NAMESPACE . '\PLUGIN_NAME', basename(self::PATH)); 98 define(self::NAMESPACE . '\PLUGIN_TITLE', __('Display metadata', PLUGIN_NAME)); 106 99 107 if ( !$pagenow ) { 108 unset( $pagenow ); 100 // Fix for profile admin pages. 101 if ( defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE ) { 102 $this->screen_vars[ 'user_id' ] = get_current_user_id(); 103 } 109 104 110 $current_base_url = parse_url( $_SERVER[ 'REQUEST_URI' ], PHP_URL_PATH ) ?: ''; 105 $this->register_metabox_autoload(); 106 } 111 107 112 $pagenow = strrchr( $current_base_url, '/' ) ?: $current_base_url; 113 } 108 /** 109 * Register plugin autoload for metabo classes. 110 * 111 * @return void 112 */ 113 final private function register_metabox_autoload(): void 114 { 115 spl_autoload_register(static function ( $class_name ) { 116 if ( 0 !== strpos($class_name, self::NAMESPACE) ) { 117 return; 118 } 114 119 115 return basename( $pagenow, '.php' ); 116 } 120 $file_name = strtolower(str_replace('_', '-', trim(strrchr($class_name, '\\'), '\\'))); 121 include sprintf(self::METABOX_FILE_PATTERN, $file_name); 122 }, $throw_exception = false); 123 } 117 124 } -
display-metadata/trunk/display-metadata.php
r2443918 r2469780 6 6 * Plugin Name: Display Metadata 7 7 * Plugin URI: https://github.com/trasweb/DisplayMetadata 8 * Description: Shows meta data( fields, custom fields and protected metas ) in a metabox for posts( any CPT ), terms( any taxonomy )and users. Metadata are displayed for humans( organized and unserialized ). This metabox only will be displayed per either administrator users or users with `display_metadata_metabox` capability.9 * Version: 0. 18 * Description: Shows metas in a metabox for posts( any CPT ), terms( any taxonomy ), comments and users. Metadata are displayed for humans( organized and unserialized ). This metabox only will be displayed per either administrator users or users with `display_metadata_metabox` capability. 9 * Version: 0.2 10 10 * Author: Manuel Canga 11 11 * Author URI: https://manuelcanga.dev … … 16 16 */ 17 17 18 if ( ! defined( "ABSPATH") ) {19 die( "Hello, World!");18 if ( ! defined( 'ABSPATH' ) ) { 19 die( 'Hello, World!' ); 20 20 } 21 21 22 if ( ! is_admin() ) {23 return;22 if ( ! is_admin() ) { 23 return; 24 24 } 25 25 26 26 ( static function () { 27 require_once __DIR__ . '/class-plugin.php';27 include_once __DIR__ . '/class-plugin.php'; 28 28 29 ${'display-metadata'} = new Plugin( $_GET ?: [] );29 ${'display-metadata'} = new Plugin( $_GET ?: [] ); 30 30 31 add_action( 'admin_init', ${'display-metadata'} );31 add_action( 'admin_init', ${'display-metadata'} ); 32 32 } )(); -
display-metadata/trunk/readme.txt
r2443918 r2469780 5 5 Tested up to: 5.6 6 6 Requires PHP: 7.2 7 Stable tag: 0. 17 Stable tag: 0.2 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html 10 10 11 Shows metas( fields, custom fields and protected metas ) in a metabox for posts( any CPT ), terms( any taxonomy ) and users. Metas are displayed for humans( organized and unserialized ). This metabox only will be displayed per either administrator users or users with `display_metadata_metabox` capability.11 Shows metas( fields, custom fields and protected metas ) in a metabox for posts( any CPT ), terms( any taxonomy ), comments and users. Metas are displayed for humans( organized and unserialized ). This metabox only will be displayed per either administrator users or users with `display_metadata_metabox` capability. 12 12 13 13 == Description == … … 15 15 As a developer you normally need know about a value of some meta( or properties ) of a post, term o user. 16 16 17 As a sysadmin maybe you need know about which meta are created in posts/terms/ users in order to remove which are unnecessary.17 As a sysadmin maybe you need know about which meta are created in posts/terms/comments/users in order to remove which are unnecessary. 18 18 19 19 As a plugin author you need check if you plugin is adding meta rightly. … … 22 22 23 23 In all these cases( and others ), you can use Display Meta plugin. 24 25 == Thanks == 26 27 * Codection for [reviewing](https://codection.com/plugin-para-visualizar-metadatos-en-wordpress/) this plugin. 28 29 * [Javier Esteban – @nobnob](https://profiles.wordpress.org/nobnob/) and [Yordan Soares – @yordansoares](https://profiles.wordpress.org/yordansoares/) for theirs translations. 30 31 * This plugin is inspired on [David Navia's](https://profiles.wordpress.org/davidnaviaweb/) code, [Post Meta Viewer](https://es.wordpress.org/plugins/post-meta-viewer/) and [JS Morisset's](https://profiles.wordpress.org/jsmoriss/) plugins. 24 32 25 33 == Send me bugs or improvements == … … 30 38 31 39 1. You can see post( from any CPT ) properties, custom fields and protected meta from a post metabox. 32 2. Y u can see term( from any taxonoy ) properties, custom fields and protected meta.40 2. You can see term( from any taxonoy ) properties, custom fields and protected meta. 33 41 3. Finally, You also can see user properties, custom fields and protected meta. 34 42 … … 41 49 1. Click the *Install Now* link for this plugin. 42 50 1. Click the *Activate Plugin* button. 43 51 1. **Now, this plugin add a new metabox on editing form of posts( any CPT ), terms( any taxonomy ), comments and users**. 44 52 45 53 == Changelog == 46 54 More detailed changes in [Display Metadata GitHub Repository](https://github.com/trasweb/DisplayMetadata/). 47 55 48 = 0.1 / 2020-01-21 = 56 = 0.2 / 2021-02-05 57 58 * Support to comment metadata. 59 * Support to copy meta keys / values to clipboard. 60 * Make clickable links. 61 * Allow showing empty array. 62 63 = 0.1 / 2020-12-21 = 49 64 50 65 * Initial release. … … 53 68 54 69 = 0.1 = 70 55 71 First version. Install it -
display-metadata/trunk/views/assets.php
r2443918 r2469780 1 1 <?php 2 2 3 use Trasweb\Plugins\DisplayMetadata\Plugin; 4 3 5 ?> 4 6 5 7 <style> 6 <?= include Plugin::ASSETS_PATH.'/display_metadata.css' ?>8 <?= require Plugin::ASSETS_PATH . '/display_metadata.css' ?> 7 9 </style> 8 10 <script> 9 <?= include Plugin::ASSETS_PATH . '/display_metadata.js' ?>11 <?= require Plugin::ASSETS_PATH . '/display_metadata.js' ?> 10 12 </script> -
display-metadata/trunk/views/meta_list.php
r2443918 r2469780 3 3 <?php 4 4 foreach ( $metadata_list as $meta_key => $meta_value ): ?> 5 <tr class=" depth_<?= $metadata_list->get_depth() ?>">5 <tr class="<?= $metadata_list->get_attributes() ?>"> 6 6 <td class="meta_key"><?= $meta_key ?></td> 7 7 <td class="meta_value"><?= $meta_value ?></td> 8 8 </tr><?php 9 9 endforeach; 10 ?>10 ?> 11 11 </tbody> 12 12 </table>
Note: See TracChangeset
for help on using the changeset viewer.