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.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 / ui.php
media-cleaner Last commit date
common 7 years ago parsers 7 years ago scripts 7 years ago views 7 years ago admin.php 7 years ago api.php 7 years ago core.php 7 years ago engine.php 7 years ago media-cleaner.php 7 years ago parsers.php 7 years ago readme.txt 7 years ago ui.php 7 years ago
ui.php
153 lines
1 <?php
2
3 class Meow_WPMC_UI {
4
5 private $core = null;
6 private $admin = null;
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 "PAGE BUILDER" => "Found in Page Builder.",
13 "GALLERY" => "Found in gallery.",
14 "META" => "Found in meta.",
15 "META (ID)" => "Found in meta (as an ID).",
16 "META (URL)" => "Found in meta (as an URL).",
17 "META ACF (ID)" => "Found in meta (as an URL).",
18 "META ACF (URL)" => "Found in meta (as an URL).",
19 "WIDGET" => "Found in widget.",
20 "ACF WIDGET (ID)" => "Found in ACF Widget (as an ID).",
21 "ACF WIDGET (URL)" => "Found in ACF Widget (as an URL).",
22 "ATTACHMENT (ID)" => "Found in Attachment (as an ID).",
23 "METASLIDER (ID)" => "Found in MetaSlider (as an ID).",
24 "MY CALENDAR (URL)" => "Found in My Calendar (as an URL).",
25 "MAX MEGA MENU (URL)" => "Found in Max Mega Menu (as an URL).",
26 "SITE ICON" => "Found in Site Icon."
27 );
28
29 function __construct( $core, $admin ) {
30 $this->core = $core;
31 $this->admin = $admin;
32 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
33 add_action( 'admin_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
34 add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ) );
35 add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) );
36 add_filter( 'media_row_actions', array( $this, 'media_row_actions' ), 10, 2 );
37 }
38
39 /**
40 * Renders a view within the views directory.
41 * @param string $view The name of the view to render
42 * @param array $data
43 * An associative array of variables to bind to the view.
44 * Each key turns into a variable name.
45 * @return string Rendered view
46 */
47 function render_view( $view, $data = null ) {
48 ob_start();
49 if ( is_array( $data ) ) extract( $data );
50 include( __DIR__ . "/views/$view.php" );
51 return ob_get_clean();
52 }
53
54 function admin_menu() {
55 //load_plugin_textdomain( 'media-cleaner', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
56 add_media_page( 'Media Cleaner', 'Cleaner', 'manage_options', 'media-cleaner', array( $this, 'wpmc_screen' ) );
57 }
58
59 function wpmc_screen() {
60 global $wpdb, $wplr;
61 echo $this->render_view( 'menu-screen', array(
62 'wpdb' => $wpdb,
63 'wplr' => $wplr,
64 'ui' => $this,
65 'core' => $this->core,
66 'admin' => $this->admin
67 ) );
68 }
69
70 function wp_enqueue_scripts() {
71 wp_enqueue_style( 'wp-jquery-ui-dialog' );
72 wp_enqueue_script( 'jquery-ui-dialog' );
73 wp_enqueue_style( 'media-cleaner-css', plugins_url( '/scripts/style.css', __FILE__ ) );
74
75 $screen = get_current_screen();
76 global $wpmc_version;
77 switch ( $screen->id ) {
78 case 'media_page_media-cleaner': // Media > Cleaner
79 wp_enqueue_script( 'media-cleaner', plugins_url( '/scripts/dashboard.js', __FILE__ ), array( 'jquery', 'jquery-ui-dialog' ),
80 $wpmc_version, true );
81 break;
82 case 'meow-apps_page_wpmc_settings-menu': // Meow Apps > Media Cleaner (Settings)
83 wp_enqueue_script( 'media-cleaner-settings', plugins_url( '/scripts/settings.js', __FILE__ ), array( 'jquery' ),
84 $wpmc_version, true );
85 break;
86 }
87 }
88
89 /**
90 *
91 * DASHBOARD
92 *
93 */
94
95 function admin_inline_js() {
96 echo "<script type='text/javascript'>\n";
97 echo 'var wpmc_cfg = {
98 timeout: ' . ( (int) $this->core->get_max_execution_time() ) * 1000 . ',
99 delay: ' . get_option( 'wpmc_delay', 100 ) . ',
100 postsBuffer:' . get_option( 'wpmc_posts_buffer', 5 ) . ',
101 mediasBuffer:' . get_option( 'wpmc_medias_buffer', 100 ) . ',
102 analysisBuffer: ' . get_option( 'wpmc_analysis_buffer', 50 ) . ',
103 isPro: ' . ( $this->admin->is_registered() ? '1' : '0') . ',
104 scanFiles: ' . ( ( get_option( 'wpmc_method', 'media' ) == 'files' && $this->admin->is_registered() ) ? '1' : '0' ) . ',
105 scanMedia: ' . ( get_option( 'wpmc_method', 'media' ) == 'media' ? '1' : '0' ) . ' };';
106 echo "\n</script>";
107 }
108
109 /*******************************************************************************
110 * METABOX FOR USAGE
111 ******************************************************************************/
112
113 function add_metabox() {
114 add_meta_box( 'mfrh_media_usage_box', 'Media Cleaner', array( $this, 'display_metabox' ), 'attachment', 'side', 'default' );
115 }
116
117 function display_metabox( $post ) {
118 $this->core->log( "Media Edit > Checking Media #{$post->ID}" );
119 $success = $this->core->check_media( $post->ID, true );
120 $this->core->log( "Success $success\n" );
121 if ( $success ) {
122 if ( array_key_exists( $this->core->last_analysis, $this->foundTypes ) )
123 echo $this->foundTypes[ $this->core->last_analysis ];
124 else
125 echo "It seems to be used as: " . $this->core->last_analysis;
126 }
127 else {
128 echo "Doesn't seem to be used.";
129 }
130 }
131
132 function media_row_actions( $actions, $post ) {
133 global $current_screen;
134 if ( 'upload' != $current_screen->id )
135 return $actions;
136 global $wpdb;
137 $table_name = $wpdb->prefix . "mclean_scan";
138 $res = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE postId = %d", $post->ID ) );
139 if ( !empty( $res ) && isset( $actions['delete'] ) )
140 $actions['delete'] = "<a href='?page=media-cleaner&view=deleted'>" .
141 __( 'Delete with Media Cleaner', 'media-cleaner' ) . "</a>";
142 if ( !empty( $res ) && isset( $actions['trash'] ) )
143 $actions['trash'] = "<a href='?page=media-cleaner'>" .
144 __( 'Trash with Media Cleaner', 'media-cleaner' ) . "</a>";
145 if ( !empty( $res ) && isset( $actions['untrash'] ) ) {
146 $actions['untrash'] = "<a href='?page=media-cleaner&view=deleted'>" .
147 __( 'Restore with Media Cleaner', 'media-cleaner' ) . "</a>";
148 }
149 return $actions;
150 }
151
152 }
153