PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wp-retina-2x/wr2x_retina-dashboard.php

https://gitlab.com/adwait.rise/guruautolines
PHP | 329 lines | 276 code | 41 blank | 12 comment | 41 complexity | aae11d4a7c489629e86f924033497ea8 MD5 | raw file
  1. <?php
  2. add_action( 'admin_menu', 'wr2x_admin_menu_dashboard' );
  3. /**
  4. *
  5. * RETINA DASHBOARD
  6. *
  7. */
  8. function wr2x_admin_menu_dashboard () {
  9. $refresh = isset ( $_GET[ 'refresh' ] ) ? $_GET[ 'refresh' ] : 0;
  10. $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0;
  11. $ignore = isset ( $_GET[ 'ignore' ] ) ? $_GET[ 'ignore' ] : false;
  12. if ( $ignore ) {
  13. if ( !wr2x_is_pro() ) {
  14. echo "<div class='error' style='margin-top: 20px;'><p>";
  15. _e( "Ignore is a Pro feature.", 'wp-retina-2x' );
  16. echo "</p></div>";
  17. }
  18. else
  19. wr2x_add_ignore( $ignore );
  20. }
  21. if ( $refresh ) {
  22. wr2x_calculate_issues();
  23. }
  24. if ( $clearlogs ) {
  25. if ( file_exists( plugin_dir_path( __FILE__ ) . '/wp-retina-2x.log' ) ) {
  26. unlink( plugin_dir_path( __FILE__ ) . '/wp-retina-2x.log' );
  27. }
  28. }
  29. $flagged = count( wr2x_get_issues() );
  30. $warning_title = __( "Retina images", 'wp-retina-2x' );
  31. $menu_label = sprintf( __( 'Retina %s' ), "<span class='update-plugins count-$flagged' title='$warning_title'><span class='update-count'>" . number_format_i18n( $flagged ) . "</span></span>" );
  32. add_media_page( 'Retina', $menu_label, 'manage_options', 'wp-retina-2x', 'wpr2x_wp_retina_2x' );
  33. }
  34. function wpr2x_wp_retina_2x() {
  35. $hide_ads = wr2x_getoption( 'hide_ads', 'wr2x_advanced', false );
  36. $view = isset ( $_GET[ 'view' ] ) ? $_GET[ 'view' ] : 'issues';
  37. $paged = isset ( $_GET[ 'paged' ] ) ? $_GET[ 'paged' ] : 1;
  38. $s = isset( $_GET[ 's' ] ) && !empty( $_GET[ 's' ] ) ? sanitize_text_field( $_GET[ 's' ] ) : null;
  39. $issues = $count = 0;
  40. $posts_per_page = 15; // TODO: HOW TO GET THE NUMBER OF MEDIA PER PAGES? IT IS NOT get_option('posts_per_page');
  41. $issues = wr2x_get_issues();
  42. $ignored = wr2x_get_ignores();
  43. echo '<div class="wrap">';
  44. $hide_ads ? "" : jordy_meow_donation(true);
  45. echo "<h1>Retina";
  46. by_jordy_meow( $hide_ads );
  47. echo "</h1>";
  48. if ( wr2x_is_pro() && $view == 'issues' ) {
  49. global $wpdb;
  50. $totalcount = $wpdb->get_var( $wpdb->prepare( "
  51. SELECT COUNT(*)
  52. FROM $wpdb->posts p
  53. WHERE post_status = 'inherit'
  54. AND post_type = 'attachment'" . wr2x_create_sql_if_wpml_original() . "
  55. AND post_title LIKE %s
  56. AND ( post_mime_type = 'image/jpeg' OR
  57. post_mime_type = 'image/png' OR
  58. post_mime_type = 'image/gif' )
  59. ", '%' . $s . '%' ) );
  60. $postin = count( $issues ) < 1 ? array( -1 ) : $issues;
  61. $query = new WP_Query(
  62. array(
  63. 'post_status' => 'inherit',
  64. 'post_type' => 'attachment',
  65. 'post__in' => $postin,
  66. 'paged' => $paged,
  67. 'posts_per_page' => $posts_per_page,
  68. 's' => $s
  69. )
  70. );
  71. }
  72. else if ( wr2x_is_pro() && $view == 'ignored' ) {
  73. global $wpdb;
  74. $totalcount = $wpdb->get_var( $wpdb->prepare( "
  75. SELECT COUNT(*)
  76. FROM $wpdb->posts p
  77. WHERE post_status = 'inherit'
  78. AND post_type = 'attachment'" . wr2x_create_sql_if_wpml_original() . "
  79. AND post_title LIKE %s
  80. AND ( post_mime_type = 'image/jpeg' OR
  81. post_mime_type = 'image/jpg' OR
  82. post_mime_type = 'image/png' OR
  83. post_mime_type = 'image/gif' )
  84. ", '%' . $s . '%' ) );
  85. $postin = count( $ignored ) < 1 ? array( -1 ) : $ignored;
  86. $query = new WP_Query(
  87. array(
  88. 'post_status' => 'inherit',
  89. 'post_type' => 'attachment',
  90. 'post__in' => $postin,
  91. 'paged' => $paged,
  92. 'posts_per_page' => $posts_per_page,
  93. 's' => $s
  94. )
  95. );
  96. }
  97. else {
  98. $query = new WP_Query(
  99. array(
  100. 'post_status' => 'inherit',
  101. 'post_type' => 'attachment',
  102. 'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png',
  103. 'paged' => $paged,
  104. 'posts_per_page' => $posts_per_page,
  105. 's' => $s
  106. )
  107. );
  108. //$s
  109. $totalcount = $query->found_posts;
  110. }
  111. $issues_count = count( $issues );
  112. // If 'search', then we need to clean-up the issues count
  113. if ( $s && $issues_count > 0 ) {
  114. global $wpdb;
  115. $issues_count = $wpdb->get_var( $wpdb->prepare( "
  116. SELECT COUNT(*)
  117. FROM $wpdb->posts p
  118. WHERE id IN ( " . implode( ',', $issues ) . " )" . wr2x_create_sql_if_wpml_original() . "
  119. AND post_title LIKE %s
  120. ", '%' . $s . '%' ) );
  121. }
  122. $results = array();
  123. $count = $query->found_posts;
  124. $pagescount = $query->max_num_pages;
  125. foreach ( $query->posts as $post ) {
  126. $info = wr2x_retina_info( $post->ID );
  127. array_push( $results, array( 'post' => $post, 'info' => $info ) );
  128. }
  129. ?>
  130. <div style='background: #FFF; padding: 5px; border-radius: 4px; height: 28px; box-shadow: 0px 0px 6px #C2C2C2;'>
  131. <!-- REFRESH -->
  132. <a id='wr2x_refresh' href='?page=wp-retina-2x&view=issues&refresh=true' class='button' style='float: left;'><img style='position: relative; top: 3px; left: -2px; margin-right: 3px; width: 16px; height: 16px;' src='<?php echo plugin_dir_url( __FILE__ ); ?>img/refresh.png' /><?php _e("Refresh", 'wp-retina-2x'); ?></a>
  133. <!-- SEARCH -->
  134. <form id="posts-filter" action="upload.php" method="get">
  135. <p class="search-box" style='margin-left: 5px; float: left;'>
  136. <input type="search" name="s" value="<?php echo $s ? $s : ""; ?>">
  137. <input type="hidden" name="page" value="wp-retina-2x">
  138. <input type="hidden" name="view" value="<?php echo $view; ?>">
  139. <input type="hidden" name="paged" value="<?php echo $paged; ?>">
  140. <input type="submit" class="button" value="Search">
  141. </p>
  142. </form>
  143. <!-- REMOVE BUTTON ALL -->
  144. <a id='wr2x_remove_button_all' onclick='wr2x_delete_all()' class='button button-red' style='float: right;'><img style='position: relative; top: 3px; left: -2px; margin-right: 3px; width: 16px; height: 16px;' src='<?php echo plugin_dir_url( __FILE__ ); ?>img/burn.png' /><?php _e("Bulk Delete", 'wp-retina-2x'); ?></a>
  145. <!-- GENERATE ALL -->
  146. <a id='wr2x_generate_button_all' onclick='wr2x_generate_all()' class='button-primary' style='float: right; margin-right: 5px;'><img style='position: relative; top: 3px; left: -2px; margin-right: 3px; width: 16px; height: 16px;' src='<?php echo plugin_dir_url( __FILE__ ); ?>img/photo-album--plus.png' /><?php _e("Bulk Generate", 'wp-retina-2x'); ?></a>
  147. <!-- PROGRESS -->
  148. <span style='margin-left: 12px; font-size: 13px; top: 5px; position: relative; color: #24547C; font-weight: bold;' id='wr2x_progression'></span>
  149. </div>
  150. <?php
  151. if (isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0) {
  152. echo "<div class='updated' style='margin-top: 20px;'><p>";
  153. _e( "The logs have been cleared.", 'wp-retina-2x' );
  154. echo "</p></div>";
  155. }
  156. $active_sizes = wr2x_get_active_image_sizes();
  157. $full_size_needed = wr2x_getoption( "full_size", "wr2x_basics", false );
  158. $max_width = 0;
  159. $max_height = 0;
  160. foreach ( $active_sizes as $name => $active_size ) {
  161. if ( $active_size['height'] != 9999 && $active_size['height'] > $max_height ) {
  162. $max_height = $active_size['height'];
  163. }
  164. if ( $active_size['width'] != 9999 && $active_size['width'] > $max_width ) {
  165. $max_width = $active_size['width'];
  166. }
  167. }
  168. $max_width = $max_width * 2;
  169. $max_height = $max_height * 2;
  170. $upload_max_size = wr2x_get_max_filesize();
  171. ?>
  172. <p>
  173. <?php printf( __( 'The full-size images should have a resolution of <b>%d×%d</b> at least for the plugin to be able generate the <b>%d retina images</b> required by your website.', 'wp-retina-2x' ), $max_width, $max_height, count( $active_sizes ) ); ?>
  174. <?php if ( $full_size_needed ) printf( __( "You <b>also need</b> to upload a retina image for the Full-Size image (might be <b>%d×%d</b>).", 'wp-retina-2x' ), $max_width * 2, $max_height * 2 ); ?>
  175. <?php _e("You can upload or replace the images by drag & drop.", 'wp-retina-2x' ); ?>
  176. <?php printf( __( "Your PHP configuration allows uploads of <b>%dMB</b> maximum.", 'wp-retina-2x'), $upload_max_size / 1000000 ); ?>
  177. <?php
  178. if ( file_exists( plugin_dir_path( __FILE__ ) . '/wp-retina-2x.log' ) ) {
  179. printf( __( 'The <a target="_blank" href="%s/wp-retina-2x.log">log file</a> is available. You can also <a href="?page=wp-retina-2x&view=issues&clearlogs=true">clear</a> it.', 'wp-retina-2x' ), plugin_dir_url( __FILE__ ) );
  180. }
  181. ?>
  182. </p>
  183. <!--
  184. It is activated through a serial key that you can buy here: <a href='http://apps.meow.fr/wp-retina-2x/'>Meow Apps</a>. -->
  185. <?php
  186. if ( !wr2x_is_pro() && !$hide_ads ) {
  187. echo '<div class="updated"><p>';
  188. echo __( '<b>Only Pro users have access to the features of this dashboard.</b> As a standard user, the dashboard allow you to Bulk Generate, Bulk Delete and access the Retina Logs. If you wish to stay a standard user and never see this dashboard aver again, you can hide it in the settings.<br /><br />The Pro version of the plugin allows you to <b>replace directly an image already uploaded in the Media Library</b> by a simple drag & drop, upload a <b>retina image for a full-size image</b>, use <b>lazy-loading</b> to load your images (for better performance) and, more importantly, <b>supports the developer</b> :) The serial key for the Pro has to be inserted in your Settings > Retina > Pro tab. Thank you :)<br /><br /><a class="button-primary" href="http://apps.meow.fr/wp-retina-2x/" target="_blank">Get the serial key for the Pro</a>', 'wp-retina-2x' );
  189. echo '</p></div>';
  190. }
  191. ?>
  192. <div id='wr2x-pages'>
  193. <?php
  194. echo paginate_links(array(
  195. 'base' => '?page=wp-retina-2x&s=' . urlencode($s) . '&view=' . $view . '%_%',
  196. 'current' => $paged,
  197. 'format' => '&paged=%#%',
  198. 'total' => $pagescount,
  199. 'prev_next' => false
  200. ));
  201. ?>
  202. </div>
  203. <ul class="subsubsub">
  204. <li class="all"><a <?php if ( $view == 'all' ) echo "class='current'"; ?> href='?page=wp-retina-2x&s=<?php echo $s; ?>&view=all'><?php _e( "All", 'wp-retina-2x' ); ?></a><span class="count">(<?php echo $totalcount; ?>)</span></li> |
  205. <?php if ( wr2x_is_pro() ): ?>
  206. <li class="all"><a <?php if ( $view == 'issues' ) echo "class='current'"; ?> href='?page=wp-retina-2x&s=<?php echo $s; ?>&view=issues'><?php _e( "Issues", 'wp-retina-2x' ); ?></a><span class="count">(<?php echo $issues_count; ?>)</span></li> |
  207. <li class="all"><a <?php if ( $view == 'ignored' ) echo "class='current'"; ?> href='?page=wp-retina-2x&s=<?php echo $s; ?>&view=ignored'><?php _e( "Ignored", 'wp-retina-2x' ); ?></a><span class="count">(<?php echo count( $ignored ); ?>)</span></li>
  208. <?php else: ?>
  209. <li class="all"><span><?php _e( "Issues", 'wp-retina-2x' ); ?></span> <span class="count">(<?php echo $issues_count; ?>)</span></li> |
  210. <li class="all"><span><?php _e( "Ignored", 'wp-retina-2x' ); ?></span> <span class="count">(<?php echo count( $ignored ); ?>)</span></li>
  211. <?php endif; ?>
  212. </ul>
  213. <table class='wp-list-table widefat fixed media wr2x-table'>
  214. <thead><tr>
  215. <?php
  216. echo "<th style='width: 56px;'>Thumbnail</th>";
  217. echo "<th style=' width: 360px;'>" . __( "Base image", 'wp-retina-2x' ) . "</th>";
  218. echo "<th style=''>" . __( "Media Sizes<br />Retina-ized", 'wp-retina-2x' ) . "</th>";
  219. echo "<th style=''>" . __( "Full-Size<br/><b>Replace</b>", 'wp-retina-2x' ) . "</th>";
  220. echo "<th style=''>" . __( "Full-Size Retina", 'wp-retina-2x' ) . "</th>";
  221. echo "<th style=''>" . __( "Full-Size Retina<br/><b>Upload</b>", 'wp-retina-2x' ) . "</th>";
  222. ?>
  223. </tr></thead>
  224. <tbody>
  225. <?php
  226. foreach ($results as $index => $attr) {
  227. $post = $attr['post'];
  228. $info = $attr['info'];
  229. $meta = wp_get_attachment_metadata( $post->ID );
  230. // Let's clean the issues status
  231. if ( $view != 'issues' ) {
  232. wr2x_update_issue_status( $post->ID, $issues, $info );
  233. }
  234. if ( isset( $meta ) && isset( $meta['width'] ) ) {
  235. $original_width = $meta['width'];
  236. $original_height = $meta['height'];
  237. }
  238. $attachmentsrc = wp_get_attachment_image_src( $post->ID, 'thumbnail' );
  239. echo "<tr class='wr2x-file-row' postId='" . $post->ID . "'>";
  240. echo "<td class='wr2x-image wr2x-info-thumbnail'><img src='" . $attachmentsrc[0] . "' /></td>";
  241. echo "<td class='wr2x-title'><a href='media.php?attachment_id=" . $post->ID . "&action=edit'>" . ( $post->post_title ? $post->post_title : '<i>Untitled</i>' ) . '</a><br />' .
  242. "<span class='resolution'>Full-Size: <span class='" . ( $original_width < $max_width ? "red" : "" ) . "'>" . $original_width . "</span>×<span class='" . ( $original_height < $max_height ? "red" : "" ) . "'>" . $original_height . "</span></span>";
  243. echo "<div class='actions'>";
  244. echo "<a style='position: relative;' onclick='wr2x_generate(" . $post->ID . ", true)' id='wr2x_generate_button_" . $post->ID . "' class='wr2x-button'>" . __( "GENERATE", 'wp-retina-2x' ) . "</a>";
  245. if ( !wr2x_is_ignore( $post->ID ) )
  246. echo " <a href='?page=wp-retina-2x&view=" . $view . "&paged=" . $paged . "&ignore=" . $post->ID . "' id='wr2x_generate_button_" . $post->ID . "' class='wr2x-button wr2x-button-ignore'>" . __( "IGNORE", 'wp-retina-2x' ) . "</a>";
  247. echo " <a style='position: relative;' class='wr2x-button wr2x-button-view'>" . __( "DETAILS", 'wp-retina-2x' ) . "</a>";
  248. echo "</div></td>";
  249. // Media Sizes Retina-ized
  250. echo '<td id="wr2x-info-' . $post->ID . '" style="padding-top: 10px;" class="wr2x-info">';
  251. echo wpr2x_html_get_basic_retina_info( $post, $info );
  252. echo "</td>";
  253. if ( wr2x_is_pro() ) {
  254. // Full-Size Replace
  255. echo "<td class='wr2x-fullsize-replace'><div class='wr2x-dragdrop'></div>";
  256. echo "</td>";
  257. // Full-Size Retina
  258. echo '<td id="wr2x-info-full-' . $post->ID . '" class="wr2x-image wr2x-info-full">';
  259. echo wpr2x_html_get_basic_retina_info_full( $post->ID, $info );
  260. echo "</td>";
  261. // Full-Size Retina Upload
  262. echo "<td class='wr2x-fullsize-retina-upload'>";
  263. echo "<div class='wr2x-dragdrop'></div>";
  264. echo "</td>";
  265. }
  266. else
  267. echo "<td colspan='3' style='text-align: center; background: #F9F9F9;'><small><br />PRO VERSION ONLY</small></td>";
  268. echo "</tr>";
  269. }
  270. ?>
  271. </tbody>
  272. </table>
  273. </div>
  274. <div id="wr2x-modal-info-backdrop" style="display: none;">
  275. </div>
  276. <div id="wr2x-modal-info" style="display: none;" tabindex="1">
  277. <div class="close">X</div>
  278. <h2 style="margin-top: 0px;">Retina Details</h2>
  279. <div class="loading">
  280. <img src="<?php echo plugin_dir_url( __FILE__ ); ?>img/loading.gif" />
  281. </div>
  282. <div class="content">
  283. </div>
  284. </div>
  285. <?php
  286. jordy_meow_footer();
  287. }
  288. ?>