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.9.7 6.9.8 6.9.9 7.0.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6 7.0.7
media-cleaner / classes / ui.php
media-cleaner / classes Last commit date
parsers 1 month ago admin.php 1 month ago core.php 1 month ago engine.php 1 month ago init.php 9 months ago mcp.php 1 month ago parsers.php 1 month ago rest.php 1 month ago runs.php 1 month ago support.php 1 month ago ui.php 1 month ago
ui.php
146 lines
1 <?php
2
3 class Meow_WPMC_UI {
4
5 private $core = null;
6 private $schema_ready = null;
7
8 private $foundTypes = array(
9 "CONTENT" => "Found in content.",
10 "CONTENT (ID)" => "Found in content (as an ID).",
11 "CONTENT (URL)" => "Found in content (as an URL).",
12 "THEME" => "Found in theme.",
13 "THEME (ID)" => "Found in theme (as an ID).",
14 "THEME (URL)" => "Found in theme (as an URL).",
15 "PAGE BUILDER" => "Found in Page Builder.",
16 "PAGE BUILDER (ID)" => "Found in Page Builder (as an ID).",
17 "PAGE BUILDER (URL)" => "Found in Page Builder (as an URL).",
18 "GALLERY" => "Found in gallery.",
19 "PORTFOLIO (ID)" => "Found in a portfolio (as an ID).",
20 "PORTFOLIO (URL)" => "Found in a portfolio (as an URL).",
21 "META" => "Found in meta.",
22 "META (ID)" => "Found in meta (as an ID).",
23 "META (URL)" => "Found in meta (as an URL).",
24 "META ACF (ID)" => "Found in meta (as an URL).",
25 "META ACF (URL)" => "Found in meta (as an URL).",
26 "WIDGET" => "Found in widget.",
27 "ACF WIDGET (ID)" => "Found in ACF Widget (as an ID).",
28 "ACF WIDGET (URL)" => "Found in ACF Widget (as an URL).",
29 "ATTACHMENT (ID)" => "Found in Attachment (as an ID).",
30 "SLIDER (ID)" => "Found in slider (as an ID).",
31 "SLIDER (URL)" => "Found in slider (as an URL).",
32 "CALENDAR (URL)" => "Found in calendar (as an URL).",
33 "MENU (URL)" => "Found in menu (as an URL).",
34 "SITE ICON" => "Found as a Site Icon."
35 );
36
37 function __construct( $core ) {
38 $this->core = $core;
39 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
40 add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) );
41 add_filter( 'media_row_actions', array( $this, 'media_row_actions' ), 10, 2 );
42 }
43
44 function admin_menu() {
45 if ( !$this->core->can_access_features() ) {
46 return;
47 }
48 add_media_page( 'Media Cleaner Dashboard', __( 'Cleaner', 'media-file-renamer' ), 'read',
49 'wpmc_dashboard', array( $this, 'cleaner_dashboard' ), 1 );
50 }
51
52 public function cleaner_dashboard() {
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 private function ensure_schema() {
65 if ( $this->schema_ready !== null ) return $this->schema_ready;
66 if ( !$this->core->runs ) {
67 $this->core->runs = new Meow_WPMC_Runs( $this->core );
68 }
69 $this->schema_ready = $this->core->runs->maybe_upgrade();
70 return $this->schema_ready;
71 }
72
73 function display_metabox( $post ) {
74 if ( !$this->ensure_schema() ) {
75 echo esc_html__( 'Media Cleaner could not prepare its database tables. Open the Cleaner dashboard for details.', 'media-cleaner' );
76 return;
77 }
78 // Search the references to the ID
79 $originType = $this->core->reference_exists( null, $post->ID );
80
81 // Search the references to the files
82 if ( !$originType ) {
83 $originType = "";
84 $paths = $this->core->get_paths_from_attachment( $post->ID );
85 foreach ( $paths as $path ) {
86 $originType = $this->core->reference_exists( $path, null );
87 if ( $originType ) {
88 break;
89 }
90 }
91 }
92
93 if ( $originType ) {
94 $id = $originType;
95 $originType = preg_replace( '/\s*\[.*\]/', '', $originType );
96 $id = str_replace( $originType, '', $id );
97 $id = trim( $id, '[' );
98 echo "Used as: " . $originType . "<br />";
99 if ( array_key_exists( $originType, $this->foundTypes ) ) {
100 echo "Meaning: " . $this->foundTypes[ $originType ] . "<br />";
101 }
102 if ( !empty( $id ) ) {
103 $id = trim( $id, ' []' );
104 $post = get_post( $id );
105 if ( $post ) {
106 echo "Used in: <a href='" . get_permalink( $id ) . "' target='_blank'>" . $post->post_title . "</a>";
107 echo " (<a href='" . get_edit_post_link( $id ) . "'>edit</a>)";
108 }
109 }
110 return;
111 }
112
113 $issue = $this->core->get_issue_for_postId( $post->ID );
114 if ( $issue ) {
115 $this->core->echo_issue( $issue->issue );
116 return;
117 }
118
119 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.";
120 }
121
122 function media_row_actions( $actions, $post ) {
123 global $current_screen;
124 if ( !$current_screen || 'upload' != $current_screen->id )
125 return $actions;
126 if ( !$this->ensure_schema() ) return $actions;
127 global $wpdb;
128 $table_name = $wpdb->prefix . "mclean_scan";
129 $run_id = $this->core->get_run_id();
130 $res = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $table_name WHERE run_id = %d AND postId = %d LIMIT 1", $run_id, $post->ID ) );
131 $dashboard_url = esc_url( admin_url( 'upload.php?page=wpmc_dashboard' ) );
132 if ( !empty( $res ) && isset( $actions['delete'] ) )
133 $actions['delete'] = "<a href='{$dashboard_url}'>" .
134 __( 'Delete with Media Cleaner', 'media-cleaner' ) . "</a>";
135 if ( !empty( $res ) && isset( $actions['trash'] ) )
136 $actions['trash'] = "<a href='{$dashboard_url}'>" .
137 __( 'Trash with Media Cleaner', 'media-cleaner' ) . "</a>";
138 if ( !empty( $res ) && isset( $actions['untrash'] ) ) {
139 $actions['untrash'] = "<a href='{$dashboard_url}'>" .
140 __( 'Restore with Media Cleaner', 'media-cleaner' ) . "</a>";
141 }
142 return $actions;
143 }
144
145 }
146