parsers
1 month ago
admin.php
7 months ago
core.php
1 month ago
engine.php
1 month ago
init.php
7 months ago
parsers.php
10 months ago
rest.php
1 month ago
support.php
1 month ago
ui.php
3 years ago
ui.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_WPMC_UI { |
| 4 | |
| 5 | private $core = null; |
| 6 | |
| 7 | private $foundTypes = array( |
| 8 | "CONTENT" => "Found in content.", |
| 9 | "CONTENT (ID)" => "Found in content (as an ID).", |
| 10 | "CONTENT (URL)" => "Found in content (as an URL).", |
| 11 | "THEME" => "Found in theme.", |
| 12 | "THEME (ID)" => "Found in theme (as an ID).", |
| 13 | "THEME (URL)" => "Found in theme (as an URL).", |
| 14 | "PAGE BUILDER" => "Found in Page Builder.", |
| 15 | "PAGE BUILDER (ID)" => "Found in Page Builder (as an ID).", |
| 16 | "PAGE BUILDER (URL)" => "Found in Page Builder (as an URL).", |
| 17 | "GALLERY" => "Found in gallery.", |
| 18 | "PORTFOLIO (ID)" => "Found in a portfolio (as an ID).", |
| 19 | "PORTFOLIO (URL)" => "Found in a portfolio (as an URL).", |
| 20 | "META" => "Found in meta.", |
| 21 | "META (ID)" => "Found in meta (as an ID).", |
| 22 | "META (URL)" => "Found in meta (as an URL).", |
| 23 | "META ACF (ID)" => "Found in meta (as an URL).", |
| 24 | "META ACF (URL)" => "Found in meta (as an URL).", |
| 25 | "WIDGET" => "Found in widget.", |
| 26 | "ACF WIDGET (ID)" => "Found in ACF Widget (as an ID).", |
| 27 | "ACF WIDGET (URL)" => "Found in ACF Widget (as an URL).", |
| 28 | "ATTACHMENT (ID)" => "Found in Attachment (as an ID).", |
| 29 | "SLIDER (ID)" => "Found in slider (as an ID).", |
| 30 | "SLIDER (URL)" => "Found in slider (as an URL).", |
| 31 | "CALENDAR (URL)" => "Found in calendar (as an URL).", |
| 32 | "MENU (URL)" => "Found in menu (as an URL).", |
| 33 | "SITE ICON" => "Found as a Site Icon." |
| 34 | ); |
| 35 | |
| 36 | function __construct( $core ) { |
| 37 | $this->core = $core; |
| 38 | add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
| 39 | add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) ); |
| 40 | add_filter( 'media_row_actions', array( $this, 'media_row_actions' ), 10, 2 ); |
| 41 | } |
| 42 | |
| 43 | function admin_menu() { |
| 44 | if ( !$this->core->can_access_features() ) { |
| 45 | return; |
| 46 | } |
| 47 | add_media_page( 'Media Cleaner Dashboard', __( 'Cleaner', 'media-file-renamer' ), 'read', |
| 48 | 'wpmc_dashboard', array( $this, 'cleaner_dashboard' ), 1 ); |
| 49 | } |
| 50 | |
| 51 | public function cleaner_dashboard() { |
| 52 | wpmc_check_database(); |
| 53 | echo '<div id="wpmc-dashboard"></div>'; |
| 54 | } |
| 55 | |
| 56 | /******************************************************************************* |
| 57 | * METABOX FOR USAGE |
| 58 | ******************************************************************************/ |
| 59 | |
| 60 | function add_metabox() { |
| 61 | add_meta_box( 'mfrh_media_usage_box', 'Media Cleaner', array( $this, 'display_metabox' ), 'attachment', 'side', 'default' ); |
| 62 | } |
| 63 | |
| 64 | function display_metabox( $post ) { |
| 65 | // Search the references to the ID |
| 66 | $originType = $this->core->reference_exists( null, $post->ID ); |
| 67 | |
| 68 | // Search the references to the files |
| 69 | if ( !$originType ) { |
| 70 | $originType = ""; |
| 71 | $paths = $this->core->get_paths_from_attachment( $post->ID ); |
| 72 | foreach ( $paths as $path ) { |
| 73 | $originType = $this->core->reference_exists( $path, null ); |
| 74 | if ( $originType ) { |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if ( $originType ) { |
| 81 | $id = $originType; |
| 82 | $originType = preg_replace( '/\s*\[.*\]/', '', $originType ); |
| 83 | $id = str_replace( $originType, '', $id ); |
| 84 | $id = trim( $id, '[' ); |
| 85 | echo "Used as: " . $originType . "<br />"; |
| 86 | if ( array_key_exists( $originType, $this->foundTypes ) ) { |
| 87 | echo "Meaning: " . $this->foundTypes[ $originType ] . "<br />"; |
| 88 | } |
| 89 | if ( !empty( $id ) ) { |
| 90 | $id = trim( $id, ' []' ); |
| 91 | $post = get_post( $id ); |
| 92 | if ( $post ) { |
| 93 | echo "Used in: <a href='" . get_permalink( $id ) . "' target='_blank'>" . $post->post_title . "</a>"; |
| 94 | echo " (<a href='" . get_edit_post_link( $id ) . "'>edit</a>)"; |
| 95 | } |
| 96 | } |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | $issue = $this->core->get_issue_for_postId( $post->ID ); |
| 101 | if ( $issue ) { |
| 102 | $this->core->echo_issue( $issue->issue ); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | echo "There is no information about this media in the Cleaner DB. It is either not in use, or the scan hasn't been ran."; |
| 107 | } |
| 108 | |
| 109 | function media_row_actions( $actions, $post ) { |
| 110 | wpmc_check_database(); |
| 111 | global $current_screen; |
| 112 | if ( 'upload' != $current_screen->id ) |
| 113 | return $actions; |
| 114 | global $wpdb; |
| 115 | $table_name = $wpdb->prefix . "mclean_scan"; |
| 116 | $res = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE postId = %d", $post->ID ) ); |
| 117 | if ( !empty( $res ) && isset( $actions['delete'] ) ) |
| 118 | $actions['delete'] = "<a href='?page=wpmc_dashboard'>" . |
| 119 | __( 'Delete with Media Cleaner', 'media-cleaner' ) . "</a>"; |
| 120 | if ( !empty( $res ) && isset( $actions['trash'] ) ) |
| 121 | $actions['trash'] = "<a href='?page=wpmc_dashboard'>" . |
| 122 | __( 'Trash with Media Cleaner', 'media-cleaner' ) . "</a>"; |
| 123 | if ( !empty( $res ) && isset( $actions['untrash'] ) ) { |
| 124 | $actions['untrash'] = "<a href='?page=wpmc_dashboard>" . |
| 125 | __( 'Restore with Media Cleaner', 'media-cleaner' ) . "</a>"; |
| 126 | } |
| 127 | return $actions; |
| 128 | } |
| 129 | |
| 130 | } |
| 131 |