Version Description
- New feature Added: Find and clean unused images in your WP media library.
- Fixed some bugs in the plugin code.
- Optimized the plugin code.
Download this release
Release Info
Developer | wpvivid |
Plugin | Migration, Backup, Staging – WPvivid |
Version | 0.9.45 |
Comparing to | |
See all releases |
Code changes from version 0.9.44 to 0.9.45
- admin/css/wpvivid-admin.css +13 -1
- admin/partials/wpvivid-backup-restore-page-display.php +2 -2
- includes/class-wpvivid-backup.php +4 -0
- includes/class-wpvivid-restore-database.php +1 -1
- includes/class-wpvivid.php +4 -5
- includes/customclass/class-wpvivid-base-s3.php +69 -1
- includes/customclass/class-wpvivid-s3.php +175 -3
- includes/upload-cleaner/class-wpvivid-isolate-files.php +384 -0
- includes/upload-cleaner/class-wpvivid-upload-cleaner-setting.php +1449 -0
- includes/upload-cleaner/class-wpvivid-uploads-cleaner.php +3281 -0
- includes/upload-cleaner/class-wpvivid-uploads-scanner.php +1531 -0
- readme.txt +30 -20
- wpvivid-backuprestore.php +2 -2
admin/css/wpvivid-admin.css
CHANGED
@@ -245,4 +245,16 @@
|
|
245 |
.wpvivid-export-import-block span{margin: 0;}
|
246 |
.export-import-block{width:100%; box-sizing:border-box;margin-right:10px; padding:10px;}
|
247 |
.export-import-block label{display:inline-block;}
|
248 |
-
.export-import-block a{text-decoration: none;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
.wpvivid-export-import-block span{margin: 0;}
|
246 |
.export-import-block{width:100%; box-sizing:border-box;margin-right:10px; padding:10px;}
|
247 |
.export-import-block label{display:inline-block;}
|
248 |
+
.export-import-block a{text-decoration: none;}
|
249 |
+
|
250 |
+
.quickbackup-addon{width:100%; box-sizing:border-box;margin-right:10px; padding:10px;}
|
251 |
+
.quickbackup-addon label{display:inline-block;}
|
252 |
+
@media screen and (max-width:1650px) {
|
253 |
+
.quickbackup-addon{
|
254 |
+
float:none;
|
255 |
+
width:100%;
|
256 |
+
}
|
257 |
+
}
|
258 |
+
.quickbackup-addon a{
|
259 |
+
text-decoration: none;
|
260 |
+
}
|
admin/partials/wpvivid-backup-restore-page-display.php
CHANGED
@@ -1556,7 +1556,7 @@ function wpvivid_backup_module_add_descript(){
|
|
1556 |
<div style="font-size: 14px; padding: 8px 12px; margin: 0; line-height: 1.4; font-weight: 600;">
|
1557 |
<span style="margin-right: 5px;"><?php _e( 'Back Up Manually','wpvivid-backuprestore'); ?></span>
|
1558 |
<span style="margin-right: 5px;">|</span>
|
1559 |
-
<span style="margin-right: 0;"><a href="<?php echo esc_url(admin_url().'admin.php?page=wpvivid-
|
1560 |
<span style="font-size: 10px; color: #FFA500; line-height: 10px;">(<?php _e('new feature', 'wpvivid-backuprestore'); ?>)</span>
|
1561 |
</div>
|
1562 |
<div class="quickstart-storage-setting">
|
@@ -1784,7 +1784,7 @@ function wpvivid_backup_module_add_exec(){
|
|
1784 |
function wpvivid_backup_module_add_tips(){
|
1785 |
?>
|
1786 |
<div class="custom-info" style="float:left; width:100%;">
|
1787 |
-
<strong><?php _e('
|
1788 |
</div>
|
1789 |
<?php
|
1790 |
}
|
1556 |
<div style="font-size: 14px; padding: 8px 12px; margin: 0; line-height: 1.4; font-weight: 600;">
|
1557 |
<span style="margin-right: 5px;"><?php _e( 'Back Up Manually','wpvivid-backuprestore'); ?></span>
|
1558 |
<span style="margin-right: 5px;">|</span>
|
1559 |
+
<span style="margin-right: 0;"><a href="<?php echo esc_url(admin_url().'admin.php?page=wpvivid-cleaner'); ?>" style="text-decoration: none;"><?php _e('Unused Image Cleaner', 'wpvivid-backuprestore'); ?></a></span>
|
1560 |
<span style="font-size: 10px; color: #FFA500; line-height: 10px;">(<?php _e('new feature', 'wpvivid-backuprestore'); ?>)</span>
|
1561 |
</div>
|
1562 |
<div class="quickstart-storage-setting">
|
1784 |
function wpvivid_backup_module_add_tips(){
|
1785 |
?>
|
1786 |
<div class="custom-info" style="float:left; width:100%;">
|
1787 |
+
<strong><?php _e('Tip:', 'wpvivid-backuprestore'); ?></strong> <?php _e('The settings are only for manual backup, which won\'t affect schedule settings.', 'wpvivid-backuprestore'); ?>
|
1788 |
</div>
|
1789 |
<?php
|
1790 |
}
|
includes/class-wpvivid-backup.php
CHANGED
@@ -80,6 +80,10 @@ class WPvivid_Backup_Task
|
|
80 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'backup', '/').'#';
|
81 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'Dropbox_Backup', '/').'#';
|
82 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'mysql.sql', '/').'#';//mysql
|
|
|
|
|
|
|
|
|
83 |
$upload_dir = wp_upload_dir();
|
84 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';
|
85 |
$exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
|
80 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'backup', '/').'#';
|
81 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'Dropbox_Backup', '/').'#';
|
82 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'mysql.sql', '/').'#';//mysql
|
83 |
+
if(defined('WPVIVID_UPLOADS_ISO_DIR'))
|
84 |
+
{
|
85 |
+
$exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR, '/').'#';
|
86 |
+
}
|
87 |
$upload_dir = wp_upload_dir();
|
88 |
$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';
|
89 |
$exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
|
includes/class-wpvivid-restore-database.php
CHANGED
@@ -1692,7 +1692,7 @@ class WPvivid_RestoreDB
|
|
1692 |
if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
|
1693 |
{
|
1694 |
if($max_allowed_packet[0][0]<16777216){
|
1695 |
-
$max_all_packet_warning = '
|
1696 |
}
|
1697 |
}
|
1698 |
}
|
1692 |
if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
|
1693 |
{
|
1694 |
if($max_allowed_packet[0][0]<16777216){
|
1695 |
+
$max_all_packet_warning = 'max_allowed_packet = '.size_format($max_allowed_packet[0][0]).' is too small. The recommended value is 16M or higher. Too small value could lead to a failure when importing a larger database.';
|
1696 |
}
|
1697 |
}
|
1698 |
}
|
includes/class-wpvivid.php
CHANGED
@@ -195,13 +195,15 @@ class WPvivid {
|
|
195 |
|
196 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-interface-mainwp.php';
|
197 |
|
|
|
|
|
198 |
$this->function_realize=new WPvivid_Function_Realize();
|
199 |
$this->migrate=new WPvivid_Migrate();
|
200 |
$this->backup_uploader=new Wpvivid_BackupUploader();
|
201 |
$this->interface_mainwp = new WPvivid_Interface_MainWP();
|
202 |
$send_to_site=new WPvivid_Send_to_site();
|
203 |
$export_import = new WPvivid_Export_Import();
|
204 |
-
|
205 |
}
|
206 |
|
207 |
public function init_pclzip_tmp_folder()
|
@@ -5745,12 +5747,9 @@ class WPvivid {
|
|
5745 |
// send the current file part to the browser
|
5746 |
print fread($file, round($download_rate * 1024));
|
5747 |
// flush the content to the browser
|
|
|
5748 |
flush();
|
5749 |
|
5750 |
-
if (ob_get_level())
|
5751 |
-
{
|
5752 |
-
ob_end_clean();
|
5753 |
-
}
|
5754 |
// sleep one second
|
5755 |
sleep(1);
|
5756 |
}
|
195 |
|
196 |
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-interface-mainwp.php';
|
197 |
|
198 |
+
include_once WPVIVID_PLUGIN_DIR . '/includes/upload-cleaner/class-wpvivid-uploads-cleaner.php';
|
199 |
+
|
200 |
$this->function_realize=new WPvivid_Function_Realize();
|
201 |
$this->migrate=new WPvivid_Migrate();
|
202 |
$this->backup_uploader=new Wpvivid_BackupUploader();
|
203 |
$this->interface_mainwp = new WPvivid_Interface_MainWP();
|
204 |
$send_to_site=new WPvivid_Send_to_site();
|
205 |
$export_import = new WPvivid_Export_Import();
|
206 |
+
$cleaner=new WPvivid_Uploads_Cleaner();
|
207 |
}
|
208 |
|
209 |
public function init_pclzip_tmp_folder()
|
5747 |
// send the current file part to the browser
|
5748 |
print fread($file, round($download_rate * 1024));
|
5749 |
// flush the content to the browser
|
5750 |
+
ob_flush();
|
5751 |
flush();
|
5752 |
|
|
|
|
|
|
|
|
|
5753 |
// sleep one second
|
5754 |
sleep(1);
|
5755 |
}
|
includes/customclass/class-wpvivid-base-s3.php
CHANGED
@@ -187,10 +187,13 @@ class WPvivid_Base_S3 extends Wpvivid_S3{
|
|
187 |
return $rest->response;
|
188 |
}
|
189 |
|
190 |
-
public function listObject($bucket, $path)
|
191 |
{
|
192 |
$rest = new WPvivid_S3Request('GET', $bucket, '', $this->endpoint, $this);
|
|
|
|
|
193 |
$rest->setParameter('prefix', $path);
|
|
|
194 |
//$rest->setParameter('delimiter', $path);
|
195 |
$response = $rest->getResponse();
|
196 |
if ($response->error === false && $response->code !== 200)
|
@@ -224,5 +227,70 @@ class WPvivid_Base_S3 extends Wpvivid_S3{
|
|
224 |
$ret['result']='success';
|
225 |
$ret['data']=$results;
|
226 |
return $ret;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
}
|
228 |
}
|
187 |
return $rest->response;
|
188 |
}
|
189 |
|
190 |
+
/*public function listObject($bucket, $path)
|
191 |
{
|
192 |
$rest = new WPvivid_S3Request('GET', $bucket, '', $this->endpoint, $this);
|
193 |
+
$rest->setParameter('list-type', 2);
|
194 |
+
//$rest->setParameter('max-keys', 2000);
|
195 |
$rest->setParameter('prefix', $path);
|
196 |
+
$rest->setParameter('start-after', 'wpvividbackuppro/pestcontrolcanberraarea_com_au\/2020_08_03_to_2020_08_10/pestcontrolcanberraarea.com.au_wpvivid-5f28895122706_2020-08-04-08-00_incremental_backup_all.zip');
|
197 |
//$rest->setParameter('delimiter', $path);
|
198 |
$response = $rest->getResponse();
|
199 |
if ($response->error === false && $response->code !== 200)
|
227 |
$ret['result']='success';
|
228 |
$ret['data']=$results;
|
229 |
return $ret;
|
230 |
+
}*/
|
231 |
+
|
232 |
+
public function listObject($bucket, $path)
|
233 |
+
{
|
234 |
+
$ret['result']='success';
|
235 |
+
$results = array();
|
236 |
+
$bcheck = true;
|
237 |
+
$bcontinue = false;
|
238 |
+
$continue_token = '';
|
239 |
+
$start_after = '';
|
240 |
+
$rest = new WPvivid_S3Request('GET', $bucket, '', $this->endpoint, $this);
|
241 |
+
while($bcheck){
|
242 |
+
$rest->unsetParameter($bucket);
|
243 |
+
$rest->setParameter('list-type', 2);
|
244 |
+
if($bcontinue) {
|
245 |
+
$rest->setParameter('start-after', $start_after);
|
246 |
+
}
|
247 |
+
else{
|
248 |
+
$rest->setParameter('prefix', $path);
|
249 |
+
}
|
250 |
+
$response = $rest->getResponse();
|
251 |
+
if ($response->error === false && $response->code !== 200)
|
252 |
+
{
|
253 |
+
$ret['result']='failed';
|
254 |
+
$ret['error']=$response['message'].' '.$response->code;
|
255 |
+
return $ret;
|
256 |
+
}
|
257 |
+
|
258 |
+
if ($response->error !== false)
|
259 |
+
{
|
260 |
+
$ret['result']='failed';
|
261 |
+
$ret['error']=sprintf("S3::getBucket(): [%s] %s", $response->error['code'], $response->error['message']);
|
262 |
+
return $ret;
|
263 |
+
}
|
264 |
+
|
265 |
+
if (isset($response->body, $response->body->Contents))
|
266 |
+
{
|
267 |
+
foreach ($response->body->Contents as $c)
|
268 |
+
{
|
269 |
+
$results[] = array(
|
270 |
+
'name' => (string)$c->Key,
|
271 |
+
'size' => (int)$c->Size,
|
272 |
+
);
|
273 |
+
$start_after = (string)$c->Key;
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
if(isset($response->body->NextContinuationToken)){
|
278 |
+
$bcontinue = true;
|
279 |
+
$continue_token = $response->body->NextContinuationToken;
|
280 |
+
$start_after = $start_after;
|
281 |
+
$bcheck = true;
|
282 |
+
}
|
283 |
+
else{
|
284 |
+
$bcontinue = false;
|
285 |
+
$continue_token = '';
|
286 |
+
$bcheck = false;
|
287 |
+
}
|
288 |
+
$ret['result']='success';
|
289 |
+
$ret['data']=$results;
|
290 |
+
if(!$bcheck){
|
291 |
+
break;
|
292 |
+
}
|
293 |
+
}
|
294 |
+
return $ret;
|
295 |
}
|
296 |
}
|
includes/customclass/class-wpvivid-s3.php
CHANGED
@@ -2154,7 +2154,6 @@ final class WPvivid_S3Request
|
|
2154 |
|
2155 |
private $s3;
|
2156 |
|
2157 |
-
|
2158 |
/**
|
2159 |
* Constructor
|
2160 |
*
|
@@ -2187,7 +2186,6 @@ final class WPvivid_S3Request
|
|
2187 |
$this->resource = $this->uri;
|
2188 |
}
|
2189 |
|
2190 |
-
|
2191 |
$this->headers['Date'] = gmdate('D, d M Y H:i:s T');
|
2192 |
$this->response = new STDClass;
|
2193 |
$this->response->error = false;
|
@@ -2208,6 +2206,20 @@ final class WPvivid_S3Request
|
|
2208 |
$this->parameters[$key] = $value;
|
2209 |
}
|
2210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2211 |
|
2212 |
/**
|
2213 |
* Set request header
|
@@ -2240,7 +2252,7 @@ final class WPvivid_S3Request
|
|
2240 |
*
|
2241 |
* @return object | false
|
2242 |
*/
|
2243 |
-
public function getResponse() {
|
2244 |
$query = '';
|
2245 |
if (sizeof($this->parameters) > 0) {
|
2246 |
$query = ('?' !== substr($this->uri, -1)) ? '?' : '&';
|
@@ -2391,6 +2403,166 @@ final class WPvivid_S3Request
|
|
2391 |
}
|
2392 |
}
|
2393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2394 |
// Clean up file resources
|
2395 |
// if (false !== $this->fp && is_resource($this->fp)) fclose($this->fp);
|
2396 |
return $this->response;
|
2154 |
|
2155 |
private $s3;
|
2156 |
|
|
|
2157 |
/**
|
2158 |
* Constructor
|
2159 |
*
|
2186 |
$this->resource = $this->uri;
|
2187 |
}
|
2188 |
|
|
|
2189 |
$this->headers['Date'] = gmdate('D, d M Y H:i:s T');
|
2190 |
$this->response = new STDClass;
|
2191 |
$this->response->error = false;
|
2206 |
$this->parameters[$key] = $value;
|
2207 |
}
|
2208 |
|
2209 |
+
public function unsetParameter($bucket)
|
2210 |
+
{
|
2211 |
+
if (sizeof($this->parameters) > 0) {
|
2212 |
+
foreach ($this->parameters as $key => $value){
|
2213 |
+
unset($this->parameters[$key]);
|
2214 |
+
}
|
2215 |
+
}
|
2216 |
+
$this->uri = '/';
|
2217 |
+
if ($bucket !== '')
|
2218 |
+
{
|
2219 |
+
$this->uri = '/'.$bucket.$this->uri;
|
2220 |
+
}
|
2221 |
+
}
|
2222 |
+
|
2223 |
|
2224 |
/**
|
2225 |
* Set request header
|
2252 |
*
|
2253 |
* @return object | false
|
2254 |
*/
|
2255 |
+
/*public function getResponse() {
|
2256 |
$query = '';
|
2257 |
if (sizeof($this->parameters) > 0) {
|
2258 |
$query = ('?' !== substr($this->uri, -1)) ? '?' : '&';
|
2403 |
}
|
2404 |
}
|
2405 |
|
2406 |
+
// Clean up file resources
|
2407 |
+
// if (false !== $this->fp && is_resource($this->fp)) fclose($this->fp);
|
2408 |
+
return $this->response;
|
2409 |
+
}*/
|
2410 |
+
public function getResponse() {
|
2411 |
+
$query = '';
|
2412 |
+
if (sizeof($this->parameters) > 0) {
|
2413 |
+
$query = ('?' !== substr($this->uri, -1)) ? '?' : '&';
|
2414 |
+
foreach ($this->parameters as $var => $value)
|
2415 |
+
if (null == $value || '' == $value) $query .= $var.'&';
|
2416 |
+
else if($var !== 'continuation-token'){
|
2417 |
+
$query .= $var.'='.rawurlencode($value).'&';
|
2418 |
+
}
|
2419 |
+
else{
|
2420 |
+
$query .= $var.'='.rawurlencode($value).'&';
|
2421 |
+
//$query .= $var.'='.$value.'&';
|
2422 |
+
}
|
2423 |
+
$query = substr($query, 0, -1);
|
2424 |
+
$this->uri .= $query;
|
2425 |
+
|
2426 |
+
if (array_key_exists('acl', $this->parameters) ||
|
2427 |
+
array_key_exists('location', $this->parameters) ||
|
2428 |
+
array_key_exists('torrent', $this->parameters) ||
|
2429 |
+
array_key_exists('logging', $this->parameters) ||
|
2430 |
+
array_key_exists('partNumber', $this->parameters) ||
|
2431 |
+
array_key_exists('uploads', $this->parameters) ||
|
2432 |
+
array_key_exists('uploadId', $this->parameters))
|
2433 |
+
$this->resource .= $query;
|
2434 |
+
}
|
2435 |
+
$url = ($this->s3->useSSL ? 'https://' : 'http://') . ('' !== $this->headers['Host'] ? $this->headers['Host'] : $this->endpoint) . $this->uri;
|
2436 |
+
//var_dump('bucket: ' . $this->bucket, 'uri: ' . $this->uri, 'resource: ' . $this->resource, 'url: ' . $url);
|
2437 |
+
|
2438 |
+
$curl = curl_init();
|
2439 |
+
curl_setopt($curl, CURLOPT_USERAGENT, 'S3/php');
|
2440 |
+
|
2441 |
+
if ($this->s3->useSSL) {
|
2442 |
+
// SSL Validation can now be optional for those with broken OpenSSL installations
|
2443 |
+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->s3->useSSLValidation ? 2 : 0);
|
2444 |
+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->s3->useSSLValidation ? 1 : 0);
|
2445 |
+
|
2446 |
+
if (null !== $this->s3->sslKey) curl_setopt($curl, CURLOPT_SSLKEY, $this->s3->sslKey);
|
2447 |
+
if (null !== $this->s3->sslCert) curl_setopt($curl, CURLOPT_SSLCERT, $this->s3->sslCert);
|
2448 |
+
if (null !== $this->s3->sslCACert) curl_setopt($curl, CURLOPT_CAINFO, $this->s3->sslCACert);
|
2449 |
+
}
|
2450 |
+
|
2451 |
+
curl_setopt($curl, CURLOPT_URL, $url);
|
2452 |
+
|
2453 |
+
// Headers
|
2454 |
+
$headers = array(); $amz = array();
|
2455 |
+
foreach ($this->amzHeaders as $header => $value)
|
2456 |
+
if (strlen($value) > 0) $headers[] = $header.': '.$value;
|
2457 |
+
foreach ($this->headers as $header => $value)
|
2458 |
+
if (strlen($value) > 0) $headers[] = $header . ': ' . $value;
|
2459 |
+
|
2460 |
+
// Collect AMZ headers for signature
|
2461 |
+
foreach ($this->amzHeaders as $header => $value)
|
2462 |
+
if (strlen($value) > 0) $amz[] = strtolower($header).':'.$value;
|
2463 |
+
|
2464 |
+
// AMZ headers must be sorted
|
2465 |
+
if (sizeof($amz) > 0) {
|
2466 |
+
//sort($amz);
|
2467 |
+
usort($amz, array(&$this, '__sortMetaHeadersCmp'));
|
2468 |
+
$amz = "\n".implode("\n", $amz);
|
2469 |
+
} else {
|
2470 |
+
$amz = '';
|
2471 |
+
}
|
2472 |
+
|
2473 |
+
if ($this->s3->hasAuth()) {
|
2474 |
+
// Authorization string (CloudFront stringToSign should only contain a date)
|
2475 |
+
if ('cloudfront.amazonaws.com' == $this->headers['Host']) {
|
2476 |
+
$headers[] = 'Authorization: ' . $this->s3->__getSignature($this->headers['Date']);
|
2477 |
+
} else {
|
2478 |
+
if ('v2' === $this->s3->signVer) {
|
2479 |
+
$headers[] = 'Authorization: ' . $this->s3->__getSignature(
|
2480 |
+
$this->verb."\n".
|
2481 |
+
$this->headers['Content-MD5']."\n".
|
2482 |
+
$this->headers['Content-Type']."\n".
|
2483 |
+
$this->headers['Date'].$amz."\n".
|
2484 |
+
$this->resource
|
2485 |
+
);
|
2486 |
+
} else {
|
2487 |
+
$amzHeaders = $this->s3->__getSignatureV4(
|
2488 |
+
$this->amzHeaders,
|
2489 |
+
$this->headers,
|
2490 |
+
$this->verb,
|
2491 |
+
$this->uri,
|
2492 |
+
$this->data
|
2493 |
+
);
|
2494 |
+
foreach ($amzHeaders as $k => $v) {
|
2495 |
+
$headers[] = $k . ': ' . $v;
|
2496 |
+
}
|
2497 |
+
}
|
2498 |
+
}
|
2499 |
+
}
|
2500 |
+
// if (false !== $this->s3->port) curl_setopt($curl, CURLOPT_PORT, $this->s3->port);
|
2501 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
2502 |
+
curl_setopt($curl, CURLOPT_HEADER, false);
|
2503 |
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
|
2504 |
+
curl_setopt($curl, CURLOPT_WRITEFUNCTION, array(&$this, '__responseWriteCallback'));
|
2505 |
+
curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this, '__responseHeaderCallback'));
|
2506 |
+
@curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
2507 |
+
|
2508 |
+
// Request types
|
2509 |
+
switch ($this->verb) {
|
2510 |
+
case 'GET': break;
|
2511 |
+
case 'PUT': case 'POST':
|
2512 |
+
if (false !== $this->fp) {
|
2513 |
+
curl_setopt($curl, CURLOPT_PUT, true);
|
2514 |
+
curl_setopt($curl, CURLOPT_INFILE, $this->fp);
|
2515 |
+
if ($this->size >= 0) {
|
2516 |
+
curl_setopt($curl, CURLOPT_INFILESIZE, $this->size);
|
2517 |
+
}
|
2518 |
+
} elseif (false !== $this->data) {
|
2519 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb);
|
2520 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data);
|
2521 |
+
curl_setopt($curl, CURLOPT_INFILESIZE, strlen($this->data));
|
2522 |
+
} else {
|
2523 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb);
|
2524 |
+
}
|
2525 |
+
break;
|
2526 |
+
case 'HEAD':
|
2527 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'HEAD');
|
2528 |
+
curl_setopt($curl, CURLOPT_NOBODY, true);
|
2529 |
+
break;
|
2530 |
+
case 'DELETE':
|
2531 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
2532 |
+
break;
|
2533 |
+
default: break;
|
2534 |
+
}
|
2535 |
+
|
2536 |
+
// Execute, grab errors
|
2537 |
+
if (curl_exec($curl))
|
2538 |
+
$this->response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
2539 |
+
else
|
2540 |
+
$this->response->error = array(
|
2541 |
+
'code' => curl_errno($curl),
|
2542 |
+
'message' => curl_error($curl),
|
2543 |
+
'resource' => $this->resource
|
2544 |
+
);
|
2545 |
+
|
2546 |
+
@curl_close($curl);
|
2547 |
+
|
2548 |
+
// Parse body into XML
|
2549 |
+
// The case in which there is not application/xml content-type header is to support a DreamObjects case seen, April 2018
|
2550 |
+
if (false === $this->response->error && isset($this->response->body) && ((isset($this->response->headers['type']) && 'application/xml' == $this->response->headers['type']) || (!isset($this->response->headers['type']) && 0 === strpos($this->response->body, '<?xml')))) {
|
2551 |
+
$this->response->body = simplexml_load_string($this->response->body);
|
2552 |
+
|
2553 |
+
// Grab S3 errors
|
2554 |
+
if (!in_array($this->response->code, array(200, 204, 206)) &&
|
2555 |
+
isset($this->response->body->Code)) {
|
2556 |
+
$this->response->error = array(
|
2557 |
+
'code' => (string)$this->response->body->Code,
|
2558 |
+
);
|
2559 |
+
$this->response->error['message'] = isset($this->response->body->Message) ? $this->response->body->Message : '';
|
2560 |
+
if (isset($this->response->body->Resource))
|
2561 |
+
$this->response->error['resource'] = (string)$this->response->body->Resource;
|
2562 |
+
unset($this->response->body);
|
2563 |
+
}
|
2564 |
+
}
|
2565 |
+
|
2566 |
// Clean up file resources
|
2567 |
// if (false !== $this->fp && is_resource($this->fp)) fclose($this->fp);
|
2568 |
return $this->response;
|
includes/upload-cleaner/class-wpvivid-isolate-files.php
ADDED
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('WPVIVID_PLUGIN_DIR'))
|
4 |
+
{
|
5 |
+
die;
|
6 |
+
}
|
7 |
+
|
8 |
+
class WPvivid_Isolate_Files
|
9 |
+
{
|
10 |
+
public function __construct()
|
11 |
+
{
|
12 |
+
|
13 |
+
}
|
14 |
+
|
15 |
+
public function check_folder()
|
16 |
+
{
|
17 |
+
if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR))
|
18 |
+
{
|
19 |
+
@mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR,0777,true);
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
public function isolate_files($files)
|
24 |
+
{
|
25 |
+
$upload_dir=wp_upload_dir();
|
26 |
+
$root_path=$upload_dir['basedir'].DIRECTORY_SEPARATOR;
|
27 |
+
|
28 |
+
if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR))
|
29 |
+
{
|
30 |
+
@mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR,0777,true);
|
31 |
+
}
|
32 |
+
|
33 |
+
$iso_dir=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR.DIRECTORY_SEPARATOR;
|
34 |
+
|
35 |
+
foreach ($files as $file)
|
36 |
+
{
|
37 |
+
$from=$root_path.$file;
|
38 |
+
|
39 |
+
$to=$iso_dir.$file;
|
40 |
+
|
41 |
+
if(file_exists($from))
|
42 |
+
{
|
43 |
+
if (!is_dir(dirname($to)))
|
44 |
+
{
|
45 |
+
mkdir(dirname($to), 0777, true);
|
46 |
+
}
|
47 |
+
@rename($from,$to);
|
48 |
+
}
|
49 |
+
}
|
50 |
+
$ret['result']='success';
|
51 |
+
return $ret;
|
52 |
+
}
|
53 |
+
|
54 |
+
public function init_isolate_task()
|
55 |
+
{
|
56 |
+
$task['start_time']=time();
|
57 |
+
$task['running_time']=time();
|
58 |
+
$task['status']='running';
|
59 |
+
$task['progress']=0;
|
60 |
+
$task['offset']=0;
|
61 |
+
|
62 |
+
update_option('init_isolate_task',$task);
|
63 |
+
}
|
64 |
+
|
65 |
+
public function get_isolate_task_offset()
|
66 |
+
{
|
67 |
+
$task=get_option('scan_unused_files_task',array());
|
68 |
+
if(empty($task))
|
69 |
+
{
|
70 |
+
return false;
|
71 |
+
}
|
72 |
+
|
73 |
+
if($task['status']=='finished')
|
74 |
+
{
|
75 |
+
return false;
|
76 |
+
}
|
77 |
+
|
78 |
+
return $task['offset'];
|
79 |
+
}
|
80 |
+
|
81 |
+
public function update_isolate_task($offset,$status='running',$progress=0)
|
82 |
+
{
|
83 |
+
$task=get_option('scan_unused_files_task',array());
|
84 |
+
|
85 |
+
$task['running_time']=time();
|
86 |
+
$task['status']=$status;
|
87 |
+
$task['progress']=$progress;
|
88 |
+
$task['offset']=$offset;
|
89 |
+
|
90 |
+
update_option('scan_unused_files_task',$task);
|
91 |
+
}
|
92 |
+
|
93 |
+
public function get_isolate_folder()
|
94 |
+
{
|
95 |
+
$root=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR;
|
96 |
+
$ret=$this->get_folder_list($root);
|
97 |
+
return $ret;
|
98 |
+
}
|
99 |
+
|
100 |
+
public function get_isolate_files($search='',$folder_ex='',$count=0)
|
101 |
+
{
|
102 |
+
$root=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR;
|
103 |
+
$ret=$this->get_folder_list($root,$search);
|
104 |
+
|
105 |
+
if(empty($folder_ex))
|
106 |
+
{
|
107 |
+
$result=$ret['files'];
|
108 |
+
foreach ($ret['folders'] as $folder)
|
109 |
+
{
|
110 |
+
$files=array();
|
111 |
+
$this->scan_list_uploaded_files($files,$root.DIRECTORY_SEPARATOR.$folder,$root,$folder,$search);
|
112 |
+
$result=array_merge($result,$files);
|
113 |
+
}
|
114 |
+
}
|
115 |
+
else if($folder_ex=='.')
|
116 |
+
{
|
117 |
+
$result=$ret['files'];
|
118 |
+
|
119 |
+
if($count>0&&sizeof($result)>$count)
|
120 |
+
{
|
121 |
+
$result=array_slice($result, 0, $count);
|
122 |
+
}
|
123 |
+
return $result;
|
124 |
+
}
|
125 |
+
else
|
126 |
+
{
|
127 |
+
$files=array();
|
128 |
+
$this->scan_list_uploaded_files($files,$root.DIRECTORY_SEPARATOR.$folder_ex,$root,$folder_ex,$search);
|
129 |
+
$result=$files;
|
130 |
+
}
|
131 |
+
|
132 |
+
if($count>0&&sizeof($result)>$count)
|
133 |
+
{
|
134 |
+
$result=array_slice($result, 0, $count);
|
135 |
+
}
|
136 |
+
|
137 |
+
return $result;
|
138 |
+
}
|
139 |
+
|
140 |
+
private function get_folder_list($root_path,$search='')
|
141 |
+
{
|
142 |
+
$result['folders']=array();
|
143 |
+
$result['folders'][]='root';
|
144 |
+
$result['files']=array();
|
145 |
+
if(!file_exists($root_path)){
|
146 |
+
@mkdir($root_path, 0755, true);
|
147 |
+
}
|
148 |
+
$handler = opendir($root_path);
|
149 |
+
if($handler!==false)
|
150 |
+
{
|
151 |
+
while (($filename = readdir($handler)) !== false)
|
152 |
+
{
|
153 |
+
if ($filename != "." && $filename != "..")
|
154 |
+
{
|
155 |
+
if (is_dir($root_path . DIRECTORY_SEPARATOR . $filename))
|
156 |
+
{
|
157 |
+
if(preg_match('#^\d{4}$#',$filename))
|
158 |
+
{
|
159 |
+
$result['folders']=array_merge( $result['folders'],$this->get_sub_folder($root_path . DIRECTORY_SEPARATOR . $filename,$filename));
|
160 |
+
}
|
161 |
+
else
|
162 |
+
{
|
163 |
+
$ret=scandir($root_path . DIRECTORY_SEPARATOR . $filename);
|
164 |
+
if($ret!==false&&count($ret)!=2)
|
165 |
+
{
|
166 |
+
$result['folders'][]=$filename;
|
167 |
+
}
|
168 |
+
|
169 |
+
}
|
170 |
+
|
171 |
+
} else {
|
172 |
+
|
173 |
+
if($filename=='.htaccess'||$filename=='index.php')
|
174 |
+
{
|
175 |
+
continue;
|
176 |
+
}
|
177 |
+
|
178 |
+
if(empty($search))
|
179 |
+
{
|
180 |
+
$file['path']=$filename;
|
181 |
+
$file['folder']='.';
|
182 |
+
$result['files'][] = $file;
|
183 |
+
}
|
184 |
+
else if(preg_match('#'.$search.'#',$filename))
|
185 |
+
{
|
186 |
+
$file['path']=$filename;
|
187 |
+
$file['folder']='.';
|
188 |
+
$result['files'][] = $file;
|
189 |
+
}
|
190 |
+
}
|
191 |
+
}
|
192 |
+
}
|
193 |
+
if($handler)
|
194 |
+
@closedir($handler);
|
195 |
+
}
|
196 |
+
|
197 |
+
return $result;
|
198 |
+
}
|
199 |
+
|
200 |
+
private function get_sub_folder($path,$root)
|
201 |
+
{
|
202 |
+
$folders=array();
|
203 |
+
$handler = opendir($path);
|
204 |
+
if($handler!==false)
|
205 |
+
{
|
206 |
+
while (($filename = readdir($handler)) !== false)
|
207 |
+
{
|
208 |
+
if ($filename != "." && $filename != "..")
|
209 |
+
{
|
210 |
+
if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
211 |
+
{
|
212 |
+
$ret=scandir($path . DIRECTORY_SEPARATOR . $filename);
|
213 |
+
if($ret!==false&&count($ret)!=2)
|
214 |
+
{
|
215 |
+
$folders[]=$root.DIRECTORY_SEPARATOR.$filename;
|
216 |
+
}
|
217 |
+
}
|
218 |
+
}
|
219 |
+
}
|
220 |
+
if($handler)
|
221 |
+
@closedir($handler);
|
222 |
+
}
|
223 |
+
return $folders;
|
224 |
+
}
|
225 |
+
|
226 |
+
private function scan_list_uploaded_files( &$files,$path,$root,$folder,$search='')
|
227 |
+
{
|
228 |
+
$count = 0;
|
229 |
+
if(is_dir($path))
|
230 |
+
{
|
231 |
+
$handler = opendir($path);
|
232 |
+
if($handler!==false)
|
233 |
+
{
|
234 |
+
while (($filename = readdir($handler)) !== false)
|
235 |
+
{
|
236 |
+
if ($filename != "." && $filename != "..")
|
237 |
+
{
|
238 |
+
$count++;
|
239 |
+
|
240 |
+
if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
241 |
+
{
|
242 |
+
$this->scan_list_uploaded_files($files, $path . DIRECTORY_SEPARATOR . $filename,$root,$folder,$search);
|
243 |
+
} else {
|
244 |
+
if(empty($search))
|
245 |
+
{
|
246 |
+
$file['path']=str_replace($root . DIRECTORY_SEPARATOR,'',$path . DIRECTORY_SEPARATOR . $filename);
|
247 |
+
$file['folder']=$folder;
|
248 |
+
$files[] = $file;
|
249 |
+
}
|
250 |
+
else if(preg_match('#'.$search.'#',$filename))
|
251 |
+
{
|
252 |
+
$file['path']=str_replace($root . DIRECTORY_SEPARATOR,'',$path . DIRECTORY_SEPARATOR . $filename);
|
253 |
+
$file['folder']=$folder;
|
254 |
+
$files[] = $file;
|
255 |
+
}
|
256 |
+
}
|
257 |
+
}
|
258 |
+
}
|
259 |
+
if($handler)
|
260 |
+
@closedir($handler);
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
return $files;
|
265 |
+
}
|
266 |
+
|
267 |
+
public function delete_files($files)
|
268 |
+
{
|
269 |
+
$root=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR;
|
270 |
+
$delete_media_when_delete_file=get_option('wpvivid_uc_delete_media_when_delete_file',false);
|
271 |
+
foreach ($files as $file)
|
272 |
+
{
|
273 |
+
@unlink($root.DIRECTORY_SEPARATOR.$file);
|
274 |
+
|
275 |
+
if($delete_media_when_delete_file)
|
276 |
+
{
|
277 |
+
$attachment_id=$this->find_media_id_from_file($file);
|
278 |
+
if($attachment_id)
|
279 |
+
{
|
280 |
+
wp_delete_attachment( $attachment_id, true );
|
281 |
+
}
|
282 |
+
}
|
283 |
+
}
|
284 |
+
|
285 |
+
|
286 |
+
|
287 |
+
}
|
288 |
+
|
289 |
+
public function delete_files_ex($files)
|
290 |
+
{
|
291 |
+
$root=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR;
|
292 |
+
$delete_media_when_delete_file=get_option('wpvivid_uc_delete_media_when_delete_file',false);
|
293 |
+
foreach ($files as $file)
|
294 |
+
{
|
295 |
+
@unlink($root.DIRECTORY_SEPARATOR.$file['path']);
|
296 |
+
|
297 |
+
if($delete_media_when_delete_file)
|
298 |
+
{
|
299 |
+
$attachment_id=$this->find_media_id_from_file($file['path']);
|
300 |
+
if($attachment_id)
|
301 |
+
{
|
302 |
+
wp_delete_attachment( $attachment_id, true );
|
303 |
+
}
|
304 |
+
}
|
305 |
+
}
|
306 |
+
}
|
307 |
+
|
308 |
+
public function find_media_id_from_file( $file )
|
309 |
+
{
|
310 |
+
global $wpdb;
|
311 |
+
|
312 |
+
$file=basename($file);
|
313 |
+
|
314 |
+
$sql = "SELECT post_id
|
315 |
+
FROM {$wpdb->postmeta}
|
316 |
+
WHERE meta_key = '_wp_attachment_metadata'
|
317 |
+
AND meta_value LIKE '%$file%'";
|
318 |
+
|
319 |
+
$ret = $wpdb->get_var( $sql );
|
320 |
+
|
321 |
+
if(!$ret)
|
322 |
+
{
|
323 |
+
$sql = $wpdb->prepare( "SELECT post_id
|
324 |
+
FROM {$wpdb->postmeta}
|
325 |
+
WHERE meta_key = '_wp_attached_file'
|
326 |
+
AND meta_value = %s", $file
|
327 |
+
);
|
328 |
+
$ret = $wpdb->get_var( $sql );
|
329 |
+
}
|
330 |
+
return $ret;
|
331 |
+
}
|
332 |
+
|
333 |
+
public function restore_files($files)
|
334 |
+
{
|
335 |
+
$upload_dir=wp_upload_dir();
|
336 |
+
|
337 |
+
$root_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR.DIRECTORY_SEPARATOR;
|
338 |
+
$upload_path=$upload_dir['basedir'].DIRECTORY_SEPARATOR;
|
339 |
+
|
340 |
+
foreach ($files as $file)
|
341 |
+
{
|
342 |
+
$from=$root_path.$file;
|
343 |
+
|
344 |
+
$to=$upload_path.$file;
|
345 |
+
|
346 |
+
if(file_exists($from))
|
347 |
+
{
|
348 |
+
if (!is_dir(dirname($to)))
|
349 |
+
{
|
350 |
+
mkdir(dirname($to), 0777, true);
|
351 |
+
}
|
352 |
+
@rename($from,$to);
|
353 |
+
}
|
354 |
+
}
|
355 |
+
$ret['result']='success';
|
356 |
+
return $ret;
|
357 |
+
}
|
358 |
+
|
359 |
+
public function restore_files_ex($files)
|
360 |
+
{
|
361 |
+
$upload_dir=wp_upload_dir();
|
362 |
+
|
363 |
+
$root_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR.DIRECTORY_SEPARATOR;
|
364 |
+
$upload_path=$upload_dir['basedir'].DIRECTORY_SEPARATOR;
|
365 |
+
|
366 |
+
foreach ($files as $file)
|
367 |
+
{
|
368 |
+
$from=$root_path.$file['path'];
|
369 |
+
|
370 |
+
$to=$upload_path.$file['path'];
|
371 |
+
|
372 |
+
if(file_exists($from))
|
373 |
+
{
|
374 |
+
if (!is_dir(dirname($to)))
|
375 |
+
{
|
376 |
+
mkdir(dirname($to), 0777, true);
|
377 |
+
}
|
378 |
+
@rename($from,$to);
|
379 |
+
}
|
380 |
+
}
|
381 |
+
$ret['result']='success';
|
382 |
+
return $ret;
|
383 |
+
}
|
384 |
+
}
|
includes/upload-cleaner/class-wpvivid-upload-cleaner-setting.php
ADDED
@@ -0,0 +1,1449 @@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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('WPVIVID_PLUGIN_DIR'))
|
3 |
+
{
|
4 |
+
die;
|
5 |
+
}
|
6 |
+
|
7 |
+
if ( ! class_exists( 'WP_List_Table' ) )
|
8 |
+
{
|
9 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
10 |
+
}
|
11 |
+
|
12 |
+
class WPvivid_Exclude_Files_List extends WP_List_Table
|
13 |
+
{
|
14 |
+
public $list;
|
15 |
+
public $type;
|
16 |
+
public $page_num;
|
17 |
+
public $parent;
|
18 |
+
|
19 |
+
public function __construct( $args = array() )
|
20 |
+
{
|
21 |
+
global $wpdb;
|
22 |
+
parent::__construct(
|
23 |
+
array(
|
24 |
+
'plural' => 'upload_files',
|
25 |
+
'screen' => 'upload_files',
|
26 |
+
)
|
27 |
+
);
|
28 |
+
}
|
29 |
+
|
30 |
+
public function set_parent($parent)
|
31 |
+
{
|
32 |
+
$this->parent=$parent;
|
33 |
+
}
|
34 |
+
|
35 |
+
public function set_list($list,$page_num=1)
|
36 |
+
{
|
37 |
+
$this->list=$list;
|
38 |
+
$this->page_num=$page_num;
|
39 |
+
}
|
40 |
+
|
41 |
+
protected function get_table_classes()
|
42 |
+
{
|
43 |
+
return array( 'widefat striped' );
|
44 |
+
}
|
45 |
+
|
46 |
+
public function print_column_headers( $with_id = true )
|
47 |
+
{
|
48 |
+
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
|
49 |
+
|
50 |
+
if (!empty($columns['cb']))
|
51 |
+
{
|
52 |
+
static $cb_counter = 1;
|
53 |
+
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
|
54 |
+
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>';
|
55 |
+
$cb_counter++;
|
56 |
+
}
|
57 |
+
|
58 |
+
foreach ( $columns as $column_key => $column_display_name )
|
59 |
+
{
|
60 |
+
|
61 |
+
$class = array( 'manage-column', "column-$column_key" );
|
62 |
+
|
63 |
+
if ( in_array( $column_key, $hidden ) )
|
64 |
+
{
|
65 |
+
$class[] = 'hidden';
|
66 |
+
}
|
67 |
+
|
68 |
+
|
69 |
+
if ( $column_key === $primary )
|
70 |
+
{
|
71 |
+
$class[] = 'column-primary';
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( $column_key === 'cb' )
|
75 |
+
{
|
76 |
+
$class[] = 'check-column';
|
77 |
+
}
|
78 |
+
$tag='th';
|
79 |
+
$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
|
80 |
+
$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
|
81 |
+
$id = $with_id ? "id='$column_key'" : '';
|
82 |
+
|
83 |
+
if ( ! empty( $class ) )
|
84 |
+
{
|
85 |
+
$class = "class='" . join( ' ', $class ) . "'";
|
86 |
+
}
|
87 |
+
|
88 |
+
echo "<$tag $scope $id $class>$column_display_name</$tag>";
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
public function get_columns()
|
93 |
+
{
|
94 |
+
$sites_columns = array(
|
95 |
+
'cb' => __( ' ' ),
|
96 |
+
'file_regex' => __( 'File Regex' )
|
97 |
+
);
|
98 |
+
|
99 |
+
return $sites_columns;
|
100 |
+
}
|
101 |
+
|
102 |
+
public function get_pagenum()
|
103 |
+
{
|
104 |
+
if($this->page_num=='first')
|
105 |
+
{
|
106 |
+
$this->page_num=1;
|
107 |
+
}
|
108 |
+
else if($this->page_num=='last')
|
109 |
+
{
|
110 |
+
$this->page_num=$this->_pagination_args['total_pages'];
|
111 |
+
}
|
112 |
+
$pagenum = $this->page_num ? $this->page_num : 0;
|
113 |
+
|
114 |
+
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
|
115 |
+
{
|
116 |
+
$pagenum = $this->_pagination_args['total_pages'];
|
117 |
+
}
|
118 |
+
|
119 |
+
return max( 1, $pagenum );
|
120 |
+
}
|
121 |
+
|
122 |
+
public function column_cb( $item )
|
123 |
+
{
|
124 |
+
$html='<input type="checkbox" name="regex_list" />';
|
125 |
+
echo $html;
|
126 |
+
}
|
127 |
+
|
128 |
+
public function column_file_regex( $item )
|
129 |
+
{
|
130 |
+
echo $item;
|
131 |
+
}
|
132 |
+
|
133 |
+
public function has_items()
|
134 |
+
{
|
135 |
+
return !empty($this->list);
|
136 |
+
}
|
137 |
+
|
138 |
+
public function prepare_items()
|
139 |
+
{
|
140 |
+
$columns = $this->get_columns();
|
141 |
+
$hidden = array();
|
142 |
+
$sortable = array();
|
143 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
144 |
+
|
145 |
+
$total_items =sizeof($this->list);
|
146 |
+
|
147 |
+
$this->set_pagination_args(
|
148 |
+
array(
|
149 |
+
'total_items' => $total_items,
|
150 |
+
'per_page' => 10,
|
151 |
+
)
|
152 |
+
);
|
153 |
+
}
|
154 |
+
|
155 |
+
public function display_rows()
|
156 |
+
{
|
157 |
+
$this->_display_rows( $this->list );
|
158 |
+
}
|
159 |
+
|
160 |
+
private function _display_rows( $list )
|
161 |
+
{
|
162 |
+
$page=$this->get_pagenum();
|
163 |
+
|
164 |
+
$page_list=$list;
|
165 |
+
$temp_page_list=array();
|
166 |
+
|
167 |
+
$count=0;
|
168 |
+
while ( $count<$page )
|
169 |
+
{
|
170 |
+
$temp_page_list = array_splice( $page_list, 0, 10);
|
171 |
+
$count++;
|
172 |
+
}
|
173 |
+
|
174 |
+
foreach ( $temp_page_list as $key=>$item)
|
175 |
+
{
|
176 |
+
$this->single_row($item);
|
177 |
+
}
|
178 |
+
}
|
179 |
+
|
180 |
+
public function single_row($item)
|
181 |
+
{
|
182 |
+
?>
|
183 |
+
<tr file_regex="<?php echo $item?>">
|
184 |
+
<?php $this->single_row_columns( $item ); ?>
|
185 |
+
</tr>
|
186 |
+
<?php
|
187 |
+
}
|
188 |
+
|
189 |
+
protected function pagination( $which )
|
190 |
+
{
|
191 |
+
if ( empty( $this->_pagination_args ) )
|
192 |
+
{
|
193 |
+
return;
|
194 |
+
}
|
195 |
+
|
196 |
+
$total_items = $this->_pagination_args['total_items'];
|
197 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
198 |
+
$infinite_scroll = false;
|
199 |
+
if ( isset( $this->_pagination_args['infinite_scroll'] ) )
|
200 |
+
{
|
201 |
+
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
|
202 |
+
}
|
203 |
+
|
204 |
+
if ( 'top' === $which && $total_pages > 1 )
|
205 |
+
{
|
206 |
+
$this->screen->render_screen_reader_content( 'heading_pagination' );
|
207 |
+
}
|
208 |
+
|
209 |
+
$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
|
210 |
+
|
211 |
+
$current = $this->get_pagenum();
|
212 |
+
|
213 |
+
$page_links = array();
|
214 |
+
|
215 |
+
$total_pages_before = '<span class="paging-input">';
|
216 |
+
$total_pages_after = '</span></span>';
|
217 |
+
|
218 |
+
$disable_first = $disable_last = $disable_prev = $disable_next = false;
|
219 |
+
|
220 |
+
if ( $current == 1 ) {
|
221 |
+
$disable_first = true;
|
222 |
+
$disable_prev = true;
|
223 |
+
}
|
224 |
+
if ( $current == 2 ) {
|
225 |
+
$disable_first = true;
|
226 |
+
}
|
227 |
+
if ( $current == $total_pages ) {
|
228 |
+
$disable_last = true;
|
229 |
+
$disable_next = true;
|
230 |
+
}
|
231 |
+
if ( $current == $total_pages - 1 ) {
|
232 |
+
$disable_last = true;
|
233 |
+
}
|
234 |
+
|
235 |
+
if ( $disable_first ) {
|
236 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>';
|
237 |
+
} else {
|
238 |
+
$page_links[] = sprintf(
|
239 |
+
"<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
240 |
+
__( 'First page' ),
|
241 |
+
'«'
|
242 |
+
);
|
243 |
+
}
|
244 |
+
|
245 |
+
if ( $disable_prev ) {
|
246 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>';
|
247 |
+
} else {
|
248 |
+
$page_links[] = sprintf(
|
249 |
+
"<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
250 |
+
$current,
|
251 |
+
__( 'Previous page' ),
|
252 |
+
'‹'
|
253 |
+
);
|
254 |
+
}
|
255 |
+
|
256 |
+
if ( 'bottom' === $which ) {
|
257 |
+
$html_current_page = $current;
|
258 |
+
$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
|
259 |
+
} else {
|
260 |
+
$html_current_page = sprintf(
|
261 |
+
"%s<input class='current-page' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
|
262 |
+
'<label class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
|
263 |
+
$current,
|
264 |
+
strlen( $total_pages )
|
265 |
+
);
|
266 |
+
}
|
267 |
+
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
|
268 |
+
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
|
269 |
+
|
270 |
+
if ( $disable_next ) {
|
271 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>';
|
272 |
+
} else {
|
273 |
+
$page_links[] = sprintf(
|
274 |
+
"<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
275 |
+
$current,
|
276 |
+
__( 'Next page' ),
|
277 |
+
'›'
|
278 |
+
);
|
279 |
+
}
|
280 |
+
|
281 |
+
if ( $disable_last ) {
|
282 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>';
|
283 |
+
} else {
|
284 |
+
$page_links[] = sprintf(
|
285 |
+
"<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
286 |
+
__( 'Last page' ),
|
287 |
+
'»'
|
288 |
+
);
|
289 |
+
}
|
290 |
+
|
291 |
+
$pagination_links_class = 'pagination-links';
|
292 |
+
if ( ! empty( $infinite_scroll ) ) {
|
293 |
+
$pagination_links_class .= ' hide-if-js';
|
294 |
+
}
|
295 |
+
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
|
296 |
+
|
297 |
+
if ( $total_pages ) {
|
298 |
+
$page_class = $total_pages < 2 ? ' one-page' : '';
|
299 |
+
} else {
|
300 |
+
$page_class = ' no-pages';
|
301 |
+
}
|
302 |
+
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
|
303 |
+
|
304 |
+
echo $this->_pagination;
|
305 |
+
}
|
306 |
+
|
307 |
+
protected function display_tablenav( $which ) {
|
308 |
+
$css_type = '';
|
309 |
+
if ( 'top' === $which ) {
|
310 |
+
wp_nonce_field( 'bulk-' . $this->_args['plural'] );
|
311 |
+
$css_type = 'margin: 0 0 10px 0';
|
312 |
+
}
|
313 |
+
else if( 'bottom' === $which ) {
|
314 |
+
$css_type = 'margin: 10px 0 0 0';
|
315 |
+
}
|
316 |
+
|
317 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
318 |
+
if ( $total_pages >1)
|
319 |
+
{
|
320 |
+
?>
|
321 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
|
322 |
+
<div class="alignleft actions bulkactions">
|
323 |
+
<label for="wpvivid_uc_exclude_regex_bulk_action" class="screen-reader-text">Select bulk action</label>
|
324 |
+
<select name="action" id="wpvivid_uc_exclude_regex_bulk_action">
|
325 |
+
<option value="remove_exclude_regex">Remove</option>
|
326 |
+
</select>
|
327 |
+
<input type="submit" class="button action" value="Apply">
|
328 |
+
</div>
|
329 |
+
<?php
|
330 |
+
$this->extra_tablenav( $which );
|
331 |
+
$this->pagination( $which );
|
332 |
+
?>
|
333 |
+
<br class="clear" />
|
334 |
+
</div>
|
335 |
+
<?php
|
336 |
+
}
|
337 |
+
else
|
338 |
+
{
|
339 |
+
?>
|
340 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
|
341 |
+
<div class="alignleft actions bulkactions">
|
342 |
+
<label for="wpvivid_uc_exclude_regex_bulk_action" class="screen-reader-text">Select bulk action</label>
|
343 |
+
<select name="action" id="wpvivid_uc_exclude_regex_bulk_action">
|
344 |
+
<option value="remove_exclude_regex">Remove</option>
|
345 |
+
</select>
|
346 |
+
<input type="submit" class="button action" value="Apply">
|
347 |
+
</div>
|
348 |
+
<br class="clear" />
|
349 |
+
</div>
|
350 |
+
<?php
|
351 |
+
}
|
352 |
+
}
|
353 |
+
|
354 |
+
public function display()
|
355 |
+
{
|
356 |
+
$singular = $this->_args['singular'];
|
357 |
+
|
358 |
+
$this->display_tablenav( 'top' );
|
359 |
+
|
360 |
+
$this->screen->render_screen_reader_content( 'heading_list' );
|
361 |
+
?>
|
362 |
+
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" >
|
363 |
+
<thead>
|
364 |
+
<tr>
|
365 |
+
<?php $this->print_column_headers(); ?>
|
366 |
+
</tr>
|
367 |
+
</thead>
|
368 |
+
|
369 |
+
<tbody id="the-list"
|
370 |
+
<?php
|
371 |
+
if ( $singular ) {
|
372 |
+
echo " data-wp-lists='list:$singular'";
|
373 |
+
}
|
374 |
+
?>
|
375 |
+
>
|
376 |
+
<?php $this->display_rows_or_placeholder(); ?>
|
377 |
+
</tbody>
|
378 |
+
|
379 |
+
<tfoot>
|
380 |
+
<tr>
|
381 |
+
<?php $this->print_column_headers( false ); ?>
|
382 |
+
</tr>
|
383 |
+
</tfoot>
|
384 |
+
|
385 |
+
</table>
|
386 |
+
<?php
|
387 |
+
}
|
388 |
+
}
|
389 |
+
|
390 |
+
class WPvivid_Post_Type_List extends WP_List_Table
|
391 |
+
{
|
392 |
+
public $list;
|
393 |
+
public $type;
|
394 |
+
public $page_num;
|
395 |
+
public $parent;
|
396 |
+
|
397 |
+
public function __construct( $args = array() )
|
398 |
+
{
|
399 |
+
global $wpdb;
|
400 |
+
parent::__construct(
|
401 |
+
array(
|
402 |
+
'plural' => 'upload_files',
|
403 |
+
'screen' => 'upload_files',
|
404 |
+
)
|
405 |
+
);
|
406 |
+
}
|
407 |
+
|
408 |
+
public function set_parent($parent)
|
409 |
+
{
|
410 |
+
$this->parent=$parent;
|
411 |
+
}
|
412 |
+
|
413 |
+
public function set_list($list,$page_num=1)
|
414 |
+
{
|
415 |
+
$this->list=$list;
|
416 |
+
$this->page_num=$page_num;
|
417 |
+
}
|
418 |
+
|
419 |
+
protected function get_table_classes()
|
420 |
+
{
|
421 |
+
return array( 'widefat striped' );
|
422 |
+
}
|
423 |
+
|
424 |
+
public function print_column_headers( $with_id = true )
|
425 |
+
{
|
426 |
+
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
|
427 |
+
|
428 |
+
if (!empty($columns['cb']))
|
429 |
+
{
|
430 |
+
static $cb_counter = 1;
|
431 |
+
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
|
432 |
+
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>';
|
433 |
+
$cb_counter++;
|
434 |
+
}
|
435 |
+
|
436 |
+
foreach ( $columns as $column_key => $column_display_name )
|
437 |
+
{
|
438 |
+
|
439 |
+
$class = array( 'manage-column', "column-$column_key" );
|
440 |
+
|
441 |
+
if ( in_array( $column_key, $hidden ) )
|
442 |
+
{
|
443 |
+
$class[] = 'hidden';
|
444 |
+
}
|
445 |
+
|
446 |
+
|
447 |
+
if ( $column_key === $primary )
|
448 |
+
{
|
449 |
+
$class[] = 'column-primary';
|
450 |
+
}
|
451 |
+
|
452 |
+
if ( $column_key === 'cb' )
|
453 |
+
{
|
454 |
+
$class[] = 'check-column';
|
455 |
+
}
|
456 |
+
$tag='th';
|
457 |
+
$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
|
458 |
+
$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
|
459 |
+
$id = $with_id ? "id='$column_key'" : '';
|
460 |
+
|
461 |
+
if ( ! empty( $class ) )
|
462 |
+
{
|
463 |
+
$class = "class='" . join( ' ', $class ) . "'";
|
464 |
+
}
|
465 |
+
|
466 |
+
echo "<$tag $scope $id $class>$column_display_name</$tag>";
|
467 |
+
}
|
468 |
+
}
|
469 |
+
|
470 |
+
public function get_columns()
|
471 |
+
{
|
472 |
+
$sites_columns = array(
|
473 |
+
'cb' => __( ' ' ),
|
474 |
+
'post_type' => __( 'Post Type' )
|
475 |
+
);
|
476 |
+
|
477 |
+
return $sites_columns;
|
478 |
+
}
|
479 |
+
|
480 |
+
public function get_pagenum()
|
481 |
+
{
|
482 |
+
if($this->page_num=='first')
|
483 |
+
{
|
484 |
+
$this->page_num=1;
|
485 |
+
}
|
486 |
+
else if($this->page_num=='last')
|
487 |
+
{
|
488 |
+
$this->page_num=$this->_pagination_args['total_pages'];
|
489 |
+
}
|
490 |
+
$pagenum = $this->page_num ? $this->page_num : 0;
|
491 |
+
|
492 |
+
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
|
493 |
+
{
|
494 |
+
$pagenum = $this->_pagination_args['total_pages'];
|
495 |
+
}
|
496 |
+
|
497 |
+
return max( 1, $pagenum );
|
498 |
+
}
|
499 |
+
|
500 |
+
public function column_cb( $item )
|
501 |
+
{
|
502 |
+
$html='<input type="checkbox" name="post_type" />';
|
503 |
+
echo $html;
|
504 |
+
}
|
505 |
+
|
506 |
+
public function column_post_type( $item )
|
507 |
+
{
|
508 |
+
echo $item;
|
509 |
+
}
|
510 |
+
|
511 |
+
public function has_items()
|
512 |
+
{
|
513 |
+
return !empty($this->list);
|
514 |
+
}
|
515 |
+
|
516 |
+
public function prepare_items()
|
517 |
+
{
|
518 |
+
$columns = $this->get_columns();
|
519 |
+
$hidden = array();
|
520 |
+
$sortable = array();
|
521 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
522 |
+
|
523 |
+
$total_items =sizeof($this->list);
|
524 |
+
|
525 |
+
$this->set_pagination_args(
|
526 |
+
array(
|
527 |
+
'total_items' => $total_items,
|
528 |
+
'per_page' => 10,
|
529 |
+
)
|
530 |
+
);
|
531 |
+
}
|
532 |
+
|
533 |
+
public function display_rows()
|
534 |
+
{
|
535 |
+
$this->_display_rows( $this->list );
|
536 |
+
}
|
537 |
+
|
538 |
+
private function _display_rows( $list )
|
539 |
+
{
|
540 |
+
$page=$this->get_pagenum();
|
541 |
+
|
542 |
+
$page_list=$list;
|
543 |
+
$temp_page_list=array();
|
544 |
+
|
545 |
+
$count=0;
|
546 |
+
while ( $count<$page )
|
547 |
+
{
|
548 |
+
$temp_page_list = array_splice( $page_list, 0, 10);
|
549 |
+
$count++;
|
550 |
+
}
|
551 |
+
|
552 |
+
foreach ( $temp_page_list as $key=>$item)
|
553 |
+
{
|
554 |
+
$this->single_row($item);
|
555 |
+
}
|
556 |
+
}
|
557 |
+
|
558 |
+
public function single_row($item)
|
559 |
+
{
|
560 |
+
?>
|
561 |
+
<tr post_type="<?php echo $item?>">
|
562 |
+
<?php $this->single_row_columns( $item ); ?>
|
563 |
+
</tr>
|
564 |
+
<?php
|
565 |
+
}
|
566 |
+
|
567 |
+
protected function pagination( $which )
|
568 |
+
{
|
569 |
+
if ( empty( $this->_pagination_args ) )
|
570 |
+
{
|
571 |
+
return;
|
572 |
+
}
|
573 |
+
|
574 |
+
$total_items = $this->_pagination_args['total_items'];
|
575 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
576 |
+
$infinite_scroll = false;
|
577 |
+
if ( isset( $this->_pagination_args['infinite_scroll'] ) )
|
578 |
+
{
|
579 |
+
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
|
580 |
+
}
|
581 |
+
|
582 |
+
if ( 'top' === $which && $total_pages > 1 )
|
583 |
+
{
|
584 |
+
$this->screen->render_screen_reader_content( 'heading_pagination' );
|
585 |
+
}
|
586 |
+
|
587 |
+
$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
|
588 |
+
|
589 |
+
$current = $this->get_pagenum();
|
590 |
+
|
591 |
+
$page_links = array();
|
592 |
+
|
593 |
+
$total_pages_before = '<span class="paging-input">';
|
594 |
+
$total_pages_after = '</span></span>';
|
595 |
+
|
596 |
+
$disable_first = $disable_last = $disable_prev = $disable_next = false;
|
597 |
+
|
598 |
+
if ( $current == 1 ) {
|
599 |
+
$disable_first = true;
|
600 |
+
$disable_prev = true;
|
601 |
+
}
|
602 |
+
if ( $current == 2 ) {
|
603 |
+
$disable_first = true;
|
604 |
+
}
|
605 |
+
if ( $current == $total_pages ) {
|
606 |
+
$disable_last = true;
|
607 |
+
$disable_next = true;
|
608 |
+
}
|
609 |
+
if ( $current == $total_pages - 1 ) {
|
610 |
+
$disable_last = true;
|
611 |
+
}
|
612 |
+
|
613 |
+
if ( $disable_first ) {
|
614 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>';
|
615 |
+
} else {
|
616 |
+
$page_links[] = sprintf(
|
617 |
+
"<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
618 |
+
__( 'First page' ),
|
619 |
+
'«'
|
620 |
+
);
|
621 |
+
}
|
622 |
+
|
623 |
+
if ( $disable_prev ) {
|
624 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>';
|
625 |
+
} else {
|
626 |
+
$page_links[] = sprintf(
|
627 |
+
"<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
628 |
+
$current,
|
629 |
+
__( 'Previous page' ),
|
630 |
+
'‹'
|
631 |
+
);
|
632 |
+
}
|
633 |
+
|
634 |
+
if ( 'bottom' === $which ) {
|
635 |
+
$html_current_page = $current;
|
636 |
+
$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
|
637 |
+
} else {
|
638 |
+
$html_current_page = sprintf(
|
639 |
+
"%s<input class='current-page' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
|
640 |
+
'<label class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
|
641 |
+
$current,
|
642 |
+
strlen( $total_pages )
|
643 |
+
);
|
644 |
+
}
|
645 |
+
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
|
646 |
+
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
|
647 |
+
|
648 |
+
if ( $disable_next ) {
|
649 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>';
|
650 |
+
} else {
|
651 |
+
$page_links[] = sprintf(
|
652 |
+
"<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
653 |
+
$current,
|
654 |
+
__( 'Next page' ),
|
655 |
+
'›'
|
656 |
+
);
|
657 |
+
}
|
658 |
+
|
659 |
+
if ( $disable_last ) {
|
660 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>';
|
661 |
+
} else {
|
662 |
+
$page_links[] = sprintf(
|
663 |
+
"<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
664 |
+
__( 'Last page' ),
|
665 |
+
'»'
|
666 |
+
);
|
667 |
+
}
|
668 |
+
|
669 |
+
$pagination_links_class = 'pagination-links';
|
670 |
+
if ( ! empty( $infinite_scroll ) ) {
|
671 |
+
$pagination_links_class .= ' hide-if-js';
|
672 |
+
}
|
673 |
+
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
|
674 |
+
|
675 |
+
if ( $total_pages ) {
|
676 |
+
$page_class = $total_pages < 2 ? ' one-page' : '';
|
677 |
+
} else {
|
678 |
+
$page_class = ' no-pages';
|
679 |
+
}
|
680 |
+
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
|
681 |
+
|
682 |
+
echo $this->_pagination;
|
683 |
+
}
|
684 |
+
|
685 |
+
protected function display_tablenav( $which ) {
|
686 |
+
$css_type = '';
|
687 |
+
if ( 'top' === $which ) {
|
688 |
+
wp_nonce_field( 'bulk-' . $this->_args['plural'] );
|
689 |
+
$css_type = 'margin: 0 0 10px 0';
|
690 |
+
}
|
691 |
+
else if( 'bottom' === $which ) {
|
692 |
+
$css_type = 'margin: 10px 0 0 0';
|
693 |
+
}
|
694 |
+
|
695 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
696 |
+
if ( $total_pages >1)
|
697 |
+
{
|
698 |
+
?>
|
699 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
|
700 |
+
<div class="alignleft actions bulkactions">
|
701 |
+
<label for="wpvivid_uc_post_type_bulk_action" class="screen-reader-text">Select bulk action</label>
|
702 |
+
<select name="action" id="wpvivid_uc_post_type_bulk_action">
|
703 |
+
<option value="remove_post_type">Remove</option>
|
704 |
+
</select>
|
705 |
+
<input type="submit" class="button action" value="Apply">
|
706 |
+
</div>
|
707 |
+
<?php
|
708 |
+
$this->extra_tablenav( $which );
|
709 |
+
$this->pagination( $which );
|
710 |
+
?>
|
711 |
+
<br class="clear" />
|
712 |
+
</div>
|
713 |
+
<?php
|
714 |
+
}
|
715 |
+
else
|
716 |
+
{
|
717 |
+
?>
|
718 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
|
719 |
+
<div class="alignleft actions bulkactions">
|
720 |
+
<label for="wpvivid_uc_post_type_bulk_action" class="screen-reader-text">Select bulk action</label>
|
721 |
+
<select name="action" id="wpvivid_uc_post_type_bulk_action">
|
722 |
+
<option value="remove_post_type">Remove</option>
|
723 |
+
</select>
|
724 |
+
<input type="submit" class="button action" value="Apply">
|
725 |
+
</div>
|
726 |
+
<br class="clear" />
|
727 |
+
</div>
|
728 |
+
<?php
|
729 |
+
}
|
730 |
+
}
|
731 |
+
|
732 |
+
public function display()
|
733 |
+
{
|
734 |
+
$singular = $this->_args['singular'];
|
735 |
+
|
736 |
+
$this->display_tablenav( 'top' );
|
737 |
+
|
738 |
+
$this->screen->render_screen_reader_content( 'heading_list' );
|
739 |
+
?>
|
740 |
+
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" >
|
741 |
+
<thead>
|
742 |
+
<tr>
|
743 |
+
<?php $this->print_column_headers(); ?>
|
744 |
+
</tr>
|
745 |
+
</thead>
|
746 |
+
|
747 |
+
<tbody id="the-list"
|
748 |
+
<?php
|
749 |
+
if ( $singular ) {
|
750 |
+
echo " data-wp-lists='list:$singular'";
|
751 |
+
}
|
752 |
+
?>
|
753 |
+
>
|
754 |
+
<?php $this->display_rows_or_placeholder(); ?>
|
755 |
+
</tbody>
|
756 |
+
|
757 |
+
<tfoot>
|
758 |
+
<tr>
|
759 |
+
<?php $this->print_column_headers( false ); ?>
|
760 |
+
</tr>
|
761 |
+
</tfoot>
|
762 |
+
|
763 |
+
</table>
|
764 |
+
<?php
|
765 |
+
}
|
766 |
+
}
|
767 |
+
|
768 |
+
class WPvivid_Uploads_Cleaner_Setting
|
769 |
+
{
|
770 |
+
public function __construct()
|
771 |
+
{
|
772 |
+
add_filter('wpvivid_add_setting_tab_page', array($this, 'add_setting_tab_page'), 10);
|
773 |
+
add_action('wpvivid_setting_add_uc_cell',array($this, 'add_uc_cell'),13);
|
774 |
+
add_filter('wpvivid_set_general_setting', array($this, 'set_general_setting'), 11, 3);
|
775 |
+
|
776 |
+
add_filter('wpvivid_pro_setting_tab', array($this, 'setting_tab'), 13);
|
777 |
+
|
778 |
+
add_action('wp_ajax_wpvivid_get_exclude_files_list',array($this, 'get_exclude_files_list'));
|
779 |
+
add_action('wp_ajax_wpvivid_delete_exclude_files',array($this, 'delete_exclude_files'));
|
780 |
+
|
781 |
+
add_action('wp_ajax_wpvivid_get_post_type_list',array($this, 'get_post_type_list'));
|
782 |
+
add_action('wp_ajax_wpvivid_delete_post_type',array($this, 'delete_post_type'));
|
783 |
+
}
|
784 |
+
|
785 |
+
public function setting_tab($tabs)
|
786 |
+
{
|
787 |
+
if(current_user_can('administrator'))
|
788 |
+
{
|
789 |
+
$tab['title']='Media Cleaner Settings';
|
790 |
+
$tab['slug']='upload_cleaner';
|
791 |
+
$tab['callback']= array($this, 'output_setting');
|
792 |
+
$args['is_parent_tab']=0;
|
793 |
+
$args['transparency']=1;
|
794 |
+
$tab['args']=$args;
|
795 |
+
$tabs[]=$tab;
|
796 |
+
}
|
797 |
+
return $tabs;
|
798 |
+
}
|
799 |
+
|
800 |
+
public function set_general_setting($setting_data, $setting, $options)
|
801 |
+
{
|
802 |
+
if(isset($setting['wpvivid_uc_scan_limit']))
|
803 |
+
$setting_data['wpvivid_uc_scan_limit'] = intval($setting['wpvivid_uc_scan_limit']);
|
804 |
+
|
805 |
+
if(isset($setting['wpvivid_uc_files_limit']))
|
806 |
+
$setting_data['wpvivid_uc_files_limit'] = intval($setting['wpvivid_uc_files_limit']);
|
807 |
+
|
808 |
+
if(isset($setting['wpvivid_uc_scan_file_types'])&&is_array($setting['wpvivid_uc_scan_file_types']))
|
809 |
+
$setting_data['wpvivid_uc_scan_file_types'] = $setting['wpvivid_uc_scan_file_types'];
|
810 |
+
|
811 |
+
if(isset($setting['wpvivid_uc_post_types'])&&is_array($setting['wpvivid_uc_post_types']))
|
812 |
+
$setting_data['wpvivid_uc_post_types'] = $setting['wpvivid_uc_post_types'];
|
813 |
+
|
814 |
+
if(isset($setting['wpvivid_uc_quick_scan']))
|
815 |
+
$setting_data['wpvivid_uc_quick_scan'] = boolval($setting['wpvivid_uc_quick_scan']);
|
816 |
+
|
817 |
+
if(isset($setting['wpvivid_uc_delete_media_when_delete_file']))
|
818 |
+
$setting_data['wpvivid_uc_delete_media_when_delete_file'] = boolval($setting['wpvivid_uc_delete_media_when_delete_file']);
|
819 |
+
|
820 |
+
if(isset($setting['wpvivid_uc_exclude_files_regex'])&&is_array($setting['wpvivid_uc_exclude_files_regex']))
|
821 |
+
$setting_data['wpvivid_uc_exclude_files_regex'] = $setting['wpvivid_uc_exclude_files_regex'];
|
822 |
+
|
823 |
+
return $setting_data;
|
824 |
+
}
|
825 |
+
|
826 |
+
public function add_setting_tab_page($setting_array)
|
827 |
+
{
|
828 |
+
$setting_array['uc_setting'] = array('index' => '3', 'tab_func' => array($this, 'wpvivid_settingpage_add_tab_uc'), 'page_func' => array($this, 'wpvivid_settingpage_add_page_uc'));
|
829 |
+
return $setting_array;
|
830 |
+
}
|
831 |
+
|
832 |
+
public function wpvivid_settingpage_add_tab_uc()
|
833 |
+
{
|
834 |
+
?>
|
835 |
+
<a href="#" id="wpvivid_tab_uc_setting" class="nav-tab setting-nav-tab" onclick="switchsettingTabs(event,'page-uc-setting')"><?php _e('Media Cleaner Settings', 'wpvivid-backuprestore'); ?></a>
|
836 |
+
<?php
|
837 |
+
}
|
838 |
+
|
839 |
+
public function wpvivid_settingpage_add_page_uc()
|
840 |
+
{
|
841 |
+
?>
|
842 |
+
<div class="setting-tab-content wpvivid_tab_uc_setting" id="page-uc-setting" style="margin-top: 10px; display: none;">
|
843 |
+
<?php do_action('wpvivid_setting_add_uc_cell'); ?>
|
844 |
+
</div>
|
845 |
+
<?php
|
846 |
+
}
|
847 |
+
|
848 |
+
public function output_setting()
|
849 |
+
{
|
850 |
+
?>
|
851 |
+
<div style="margin-top: 10px;">
|
852 |
+
<?php
|
853 |
+
$this->add_uc_cell();
|
854 |
+
?>
|
855 |
+
<div><input class="button-primary wpvivid_setting_general_save" type="submit" value="<?php esc_attr_e( 'Save Changes', 'wpvivid' ); ?>" /></div>
|
856 |
+
</div>
|
857 |
+
<?php
|
858 |
+
}
|
859 |
+
|
860 |
+
public function add_uc_cell()
|
861 |
+
{
|
862 |
+
$scan_limit=get_option('wpvivid_uc_scan_limit',20);
|
863 |
+
$files_limit=get_option('wpvivid_uc_files_limit',100);
|
864 |
+
|
865 |
+
$default_file_types=array();
|
866 |
+
$default_file_types[]='png';
|
867 |
+
$default_file_types[]='jpg';
|
868 |
+
$default_file_types[]='jpeg';
|
869 |
+
$scan_file_types=get_option('wpvivid_uc_scan_file_types',$default_file_types);
|
870 |
+
|
871 |
+
$quick_scan=get_option('wpvivid_uc_quick_scan',false);
|
872 |
+
|
873 |
+
if($quick_scan)
|
874 |
+
{
|
875 |
+
$quick_scan='checked';
|
876 |
+
}
|
877 |
+
else
|
878 |
+
{
|
879 |
+
$quick_scan='';
|
880 |
+
}
|
881 |
+
|
882 |
+
//$default_post_types=array();
|
883 |
+
//$default_post_types[]='attachment';
|
884 |
+
//$default_post_types[]='revision';
|
885 |
+
//$default_post_types[]='auto-draft';
|
886 |
+
//$default_post_types[]='nav_menu_item';
|
887 |
+
//$default_post_types[]='shop_order';
|
888 |
+
//$default_post_types[]='shop_order_refund';
|
889 |
+
//$default_post_types[]='oembed_cache';
|
890 |
+
//$post_types=get_option('wpvivid_uc_post_types',$default_post_types);
|
891 |
+
|
892 |
+
$delete_media_when_delete_file=get_option('wpvivid_uc_delete_media_when_delete_file',false);
|
893 |
+
|
894 |
+
if($delete_media_when_delete_file)
|
895 |
+
{
|
896 |
+
$delete_media_when_delete_file='checked';
|
897 |
+
}
|
898 |
+
else
|
899 |
+
{
|
900 |
+
$delete_media_when_delete_file='';
|
901 |
+
}
|
902 |
+
|
903 |
+
//$white_list=get_option('wpvivid_uc_exclude_files_regex',array());
|
904 |
+
?>
|
905 |
+
<div class="postbox schedule-tab-block setting-page-content">
|
906 |
+
<div class="wpvivid-element-space-bottom">
|
907 |
+
<label for="wpvivid_uc_scan_file_types">
|
908 |
+
<input style="margin: 4px;" id="wpvivid_uc_scan_file_types" type="checkbox" option="setting" name="wpvivid_uc_scan_file_types" <?php esc_attr_e($quick_scan); ?> />
|
909 |
+
<span><strong><?php _e('Enable Quick Scan', 'wpvivid-backuprestore'); ?></strong></span>
|
910 |
+
</label>
|
911 |
+
</div>
|
912 |
+
<div class="wpvivid-element-space-bottom">
|
913 |
+
<span><?php _e('Checking this option will speed up your scans but may produce lower accuracy.', 'wpvivid-backuprestore'); ?></span>
|
914 |
+
</div>
|
915 |
+
<div class="wpvivid-element-space-bottom">
|
916 |
+
<label for="wpvivid_uc_delete_media_when_delete_file">
|
917 |
+
<input style="margin: 4px;" id="wpvivid_uc_delete_media_when_delete_file" style="margin-right: 4px;" type="checkbox" option="setting" name="wpvivid_uc_delete_media_when_delete_file" <?php esc_attr_e($delete_media_when_delete_file); ?> />
|
918 |
+
<span><strong><?php _e('Delete Image URL', 'wpvivid-backuprestore'); ?></strong></span>
|
919 |
+
</label>
|
920 |
+
</div>
|
921 |
+
<div class="wpvivid-element-space-bottom">
|
922 |
+
<span><?php _e('With this option checked, when the image is deleted, the corresponding image url in the database that is not used anywhere on your website will also be deleted.', 'wpvivid-backuprestore'); ?></span>
|
923 |
+
</div>
|
924 |
+
</div>
|
925 |
+
|
926 |
+
<div class="postbox schedule-tab-block setting-page-content">
|
927 |
+
<div class="wpvivid-element-space-bottom"><strong><?php _e('Posts Quantity Processed Per Request', 'wpvivid-backuprestore'); ?></strong></div>
|
928 |
+
<div class="wpvivid-element-space-bottom">
|
929 |
+
<input style="margin: 0px;" type="text" placeholder="20" option="setting" name="wpvivid_uc_scan_limit" id="wpvivid_uc_scan_limit" class="all-options" value="<?php esc_attr_e($scan_limit, 'wpvivid-backuprestore'); ?>" onkeyup="value=value.replace(/\D/g,'')" />
|
930 |
+
</div>
|
931 |
+
<div class="wpvivid-element-space-bottom">
|
932 |
+
<?php _e( 'Set how many posts to process per request. The value should be set depending on your server performance and the recommended value is 20.', 'wpvivid-backuprestore' ); ?>
|
933 |
+
</div>
|
934 |
+
<div class="wpvivid-element-space-bottom"><strong><?php _e('Media Files Quantity Processed Per Request', 'wpvivid-backuprestore'); ?></strong></div>
|
935 |
+
<div class="wpvivid-element-space-bottom">
|
936 |
+
<input style="margin: 0px;" type="text" placeholder="100" option="setting" name="wpvivid_uc_files_limit" id="wpvivid_uc_files_limit" class="all-options" value="<?php esc_attr_e($files_limit, 'wpvivid-backuprestore'); ?>" onkeyup="value=value.replace(/\D/g,'')" />
|
937 |
+
</div>
|
938 |
+
<div class="wpvivid-element-space-bottom">
|
939 |
+
<?php _e( 'Set how many media files to process per request. The value should be set depending on your server performance and the recommended value is 100.', 'wpvivid-backuprestore' ); ?>
|
940 |
+
</div>
|
941 |
+
</div>
|
942 |
+
<?php
|
943 |
+
/*
|
944 |
+
<div class="postbox schedule-tab-block wpvivid-setting-addon" style="margin-bottom: 10px; padding-bottom: 0;">
|
945 |
+
<div style="margin-bottom: 20px;"><strong><?php _e('Files Filter ', 'wpvivid'); ?></strong></div>
|
946 |
+
<div>
|
947 |
+
<div class="wpvivid-element-space-bottom" style="float: left;">
|
948 |
+
<input type="text" option="setting" id="wpvivid_uc_exclude_files_regex" class="regular-text" />
|
949 |
+
</div>
|
950 |
+
<div class="wpvivid-element-space-bottom" style="float: left;">
|
951 |
+
<input class="button-secondary" id="wpvivid_uc_add_exclude_files_regex" type="submit" value="<?php esc_attr_e( 'Add File Regex', 'wpvivid' ); ?>"/>
|
952 |
+
</div>
|
953 |
+
<div style="clear: both;"></div>
|
954 |
+
</div>
|
955 |
+
<div class="wpvivid-element-space-bottom">
|
956 |
+
<div id="wpvivid_uc_add_exclude_files_regex_list">
|
957 |
+
<?php
|
958 |
+
$list = new WPvivid_Exclude_Files_List();
|
959 |
+
|
960 |
+
$list->set_list($white_list);
|
961 |
+
$list->prepare_items();
|
962 |
+
$list ->display();
|
963 |
+
?>
|
964 |
+
</div>
|
965 |
+
</div>
|
966 |
+
<script>
|
967 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex').click(function()
|
968 |
+
{
|
969 |
+
var file_exclude=jQuery('#wpvivid_uc_exclude_files_regex').val();
|
970 |
+
wpvivid_get_exclude_files_list('first',file_exclude);
|
971 |
+
});
|
972 |
+
|
973 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').on("click",'.first-page',function()
|
974 |
+
{
|
975 |
+
wpvivid_get_exclude_files_list('first');
|
976 |
+
});
|
977 |
+
|
978 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').on("click",'.prev-page',function()
|
979 |
+
{
|
980 |
+
var page=parseInt(jQuery(this).attr('value'));
|
981 |
+
wpvivid_get_exclude_files_list(page-1);
|
982 |
+
});
|
983 |
+
|
984 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').on("click",'.next-page',function()
|
985 |
+
{
|
986 |
+
var page=parseInt(jQuery(this).attr('value'));
|
987 |
+
wpvivid_get_exclude_files_list(page+1);
|
988 |
+
});
|
989 |
+
|
990 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').on("click",'.last-page',function()
|
991 |
+
{
|
992 |
+
wpvivid_get_exclude_files_list('last');
|
993 |
+
});
|
994 |
+
|
995 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').on("keypress", '.current-page', function()
|
996 |
+
{
|
997 |
+
if(event.keyCode === 13)
|
998 |
+
{
|
999 |
+
var page = jQuery(this).val();
|
1000 |
+
wpvivid_get_exclude_files_list(page);
|
1001 |
+
}
|
1002 |
+
});
|
1003 |
+
|
1004 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').on("click",'.action',function()
|
1005 |
+
{
|
1006 |
+
var selected=jQuery('#wpvivid_uc_exclude_regex_bulk_action').val();
|
1007 |
+
|
1008 |
+
if(selected=='remove_exclude_regex')
|
1009 |
+
{
|
1010 |
+
wpvivid_delete_exclude_files();
|
1011 |
+
}
|
1012 |
+
});
|
1013 |
+
|
1014 |
+
function wpvivid_get_exclude_files_list(page,file_exclude='')
|
1015 |
+
{
|
1016 |
+
var ajax_data = {
|
1017 |
+
'action': 'wpvivid_get_exclude_files_list',
|
1018 |
+
'page':page,
|
1019 |
+
'file_exclude':file_exclude
|
1020 |
+
};
|
1021 |
+
|
1022 |
+
wpvivid_post_request(ajax_data, function (data)
|
1023 |
+
{
|
1024 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').html('');
|
1025 |
+
try
|
1026 |
+
{
|
1027 |
+
var jsonarray = jQuery.parseJSON(data);
|
1028 |
+
if (jsonarray.result === 'success')
|
1029 |
+
{
|
1030 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').html(jsonarray.html);
|
1031 |
+
}
|
1032 |
+
else
|
1033 |
+
{
|
1034 |
+
alert(jsonarray.error);
|
1035 |
+
}
|
1036 |
+
}
|
1037 |
+
catch (err)
|
1038 |
+
{
|
1039 |
+
alert(err);
|
1040 |
+
}
|
1041 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1042 |
+
{
|
1043 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1044 |
+
alert(error_message);
|
1045 |
+
});
|
1046 |
+
}
|
1047 |
+
|
1048 |
+
function wpvivid_delete_exclude_files()
|
1049 |
+
{
|
1050 |
+
var json = {};
|
1051 |
+
json['selected']=Array();
|
1052 |
+
jQuery('input[name=regex_list][type=checkbox]').each(function(index, value)
|
1053 |
+
{
|
1054 |
+
if(jQuery(value).prop('checked'))
|
1055 |
+
{
|
1056 |
+
jQuery(value).closest('tr');
|
1057 |
+
var path = jQuery(this).closest('tr').attr('file_regex');
|
1058 |
+
json['selected'].push(path)
|
1059 |
+
}
|
1060 |
+
});
|
1061 |
+
var selected= JSON.stringify(json);
|
1062 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').find('.action').prop('disabled', true);
|
1063 |
+
|
1064 |
+
var ajax_data = {
|
1065 |
+
'action': 'wpvivid_delete_exclude_files',
|
1066 |
+
'selected':selected
|
1067 |
+
};
|
1068 |
+
wpvivid_post_request(ajax_data, function (data)
|
1069 |
+
{
|
1070 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').find('.action').prop('disabled', false);
|
1071 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').html('');
|
1072 |
+
try
|
1073 |
+
{
|
1074 |
+
var jsonarray = jQuery.parseJSON(data);
|
1075 |
+
if (jsonarray.result === 'success')
|
1076 |
+
{
|
1077 |
+
alert('success');
|
1078 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').html(jsonarray.html);
|
1079 |
+
}
|
1080 |
+
else
|
1081 |
+
{
|
1082 |
+
alert(jsonarray.error);
|
1083 |
+
}
|
1084 |
+
}
|
1085 |
+
catch (err)
|
1086 |
+
{
|
1087 |
+
alert(err);
|
1088 |
+
}
|
1089 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1090 |
+
{
|
1091 |
+
jQuery('#wpvivid_uc_add_exclude_files_regex_list').find('.action').prop('disabled', false);
|
1092 |
+
|
1093 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1094 |
+
alert(error_message);
|
1095 |
+
});
|
1096 |
+
}
|
1097 |
+
</script>
|
1098 |
+
</div>
|
1099 |
+
<div class="postbox schedule-tab-block wpvivid-setting-addon" style="margin-bottom: 10px; padding-bottom: 0;">
|
1100 |
+
<div style="margin-bottom: 20px;"><strong><?php _e('Post type', 'wpvivid'); ?></strong></div>
|
1101 |
+
<div>
|
1102 |
+
<div class="wpvivid-element-space-bottom" style="float: left;">
|
1103 |
+
<input type="text" option="setting" id="wpvivid_uc_post_type" class="regular-text" />
|
1104 |
+
</div>
|
1105 |
+
<div class="wpvivid-element-space-bottom" style="float: left;">
|
1106 |
+
<input class="button-secondary" id="wpvivid_uc_add_post_type" type="submit" value="<?php esc_attr_e( 'Add Post type', 'wpvivid' ); ?>"/>
|
1107 |
+
</div>
|
1108 |
+
<div style="clear: both;"></div>
|
1109 |
+
</div>
|
1110 |
+
<div class="wpvivid-element-space-bottom">
|
1111 |
+
<div id="wpvivid_uc_post_type_list">
|
1112 |
+
<?php
|
1113 |
+
$list = new WPvivid_Post_Type_List();
|
1114 |
+
|
1115 |
+
$list->set_list($post_types);
|
1116 |
+
$list->prepare_items();
|
1117 |
+
$list ->display();
|
1118 |
+
?>
|
1119 |
+
</div>
|
1120 |
+
</div>
|
1121 |
+
<script>
|
1122 |
+
jQuery('#wpvivid_uc_add_post_type').click(function()
|
1123 |
+
{
|
1124 |
+
var post_type=jQuery('#wpvivid_uc_post_type').val();
|
1125 |
+
wpvivid_get_post_type_list('first',post_type);
|
1126 |
+
});
|
1127 |
+
|
1128 |
+
jQuery('#wpvivid_uc_post_type_list').on("click",'.first-page',function()
|
1129 |
+
{
|
1130 |
+
wpvivid_get_post_type_list('first');
|
1131 |
+
});
|
1132 |
+
|
1133 |
+
jQuery('#wpvivid_uc_post_type_list').on("click",'.prev-page',function()
|
1134 |
+
{
|
1135 |
+
var page=parseInt(jQuery(this).attr('value'));
|
1136 |
+
wpvivid_get_post_type_list(page-1);
|
1137 |
+
});
|
1138 |
+
|
1139 |
+
jQuery('#wpvivid_uc_post_type_list').on("click",'.next-page',function()
|
1140 |
+
{
|
1141 |
+
var page=parseInt(jQuery(this).attr('value'));
|
1142 |
+
wpvivid_get_post_type_list(page+1);
|
1143 |
+
});
|
1144 |
+
|
1145 |
+
jQuery('#wpvivid_uc_post_type_list').on("click",'.last-page',function()
|
1146 |
+
{
|
1147 |
+
wpvivid_get_post_type_list('last');
|
1148 |
+
});
|
1149 |
+
|
1150 |
+
jQuery('#wpvivid_uc_post_type_list').on("keypress", '.current-page', function()
|
1151 |
+
{
|
1152 |
+
if(event.keyCode === 13)
|
1153 |
+
{
|
1154 |
+
var page = jQuery(this).val();
|
1155 |
+
wpvivid_get_post_type_list(page);
|
1156 |
+
}
|
1157 |
+
});
|
1158 |
+
|
1159 |
+
jQuery('#wpvivid_uc_post_type_list').on("click",'.action',function()
|
1160 |
+
{
|
1161 |
+
var selected=jQuery('#wpvivid_uc_post_type_bulk_action').val();
|
1162 |
+
|
1163 |
+
if(selected=='remove_post_type')
|
1164 |
+
{
|
1165 |
+
wpvivid_delete_post_type();
|
1166 |
+
}
|
1167 |
+
});
|
1168 |
+
|
1169 |
+
function wpvivid_get_post_type_list(page,post_type='')
|
1170 |
+
{
|
1171 |
+
var ajax_data = {
|
1172 |
+
'action': 'wpvivid_get_post_type_list',
|
1173 |
+
'page':page,
|
1174 |
+
'post_type':post_type
|
1175 |
+
};
|
1176 |
+
|
1177 |
+
wpvivid_post_request(ajax_data, function (data)
|
1178 |
+
{
|
1179 |
+
jQuery('#wpvivid_uc_post_type_list').html('');
|
1180 |
+
try
|
1181 |
+
{
|
1182 |
+
var jsonarray = jQuery.parseJSON(data);
|
1183 |
+
if (jsonarray.result === 'success')
|
1184 |
+
{
|
1185 |
+
jQuery('#wpvivid_uc_post_type_list').html(jsonarray.html);
|
1186 |
+
}
|
1187 |
+
else
|
1188 |
+
{
|
1189 |
+
alert(jsonarray.error);
|
1190 |
+
}
|
1191 |
+
}
|
1192 |
+
catch (err)
|
1193 |
+
{
|
1194 |
+
alert(err);
|
1195 |
+
}
|
1196 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1197 |
+
{
|
1198 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1199 |
+
alert(error_message);
|
1200 |
+
});
|
1201 |
+
}
|
1202 |
+
|
1203 |
+
function wpvivid_delete_post_type()
|
1204 |
+
{
|
1205 |
+
var json = {};
|
1206 |
+
json['selected']=Array();
|
1207 |
+
jQuery('input[name=post_type][type=checkbox]').each(function(index, value)
|
1208 |
+
{
|
1209 |
+
if(jQuery(value).prop('checked'))
|
1210 |
+
{
|
1211 |
+
jQuery(value).closest('tr');
|
1212 |
+
var path = jQuery(this).closest('tr').attr('post_type');
|
1213 |
+
json['selected'].push(path)
|
1214 |
+
}
|
1215 |
+
});
|
1216 |
+
var selected= JSON.stringify(json);
|
1217 |
+
jQuery('#wpvivid_uc_post_type_list').find('.action').prop('disabled', true);
|
1218 |
+
|
1219 |
+
var ajax_data = {
|
1220 |
+
'action': 'wpvivid_delete_post_type',
|
1221 |
+
'selected':selected
|
1222 |
+
};
|
1223 |
+
wpvivid_post_request(ajax_data, function (data)
|
1224 |
+
{
|
1225 |
+
jQuery('#wpvivid_uc_post_type_list').find('.action').prop('disabled', false);
|
1226 |
+
jQuery('#wpvivid_uc_post_type_list').html('');
|
1227 |
+
try
|
1228 |
+
{
|
1229 |
+
var jsonarray = jQuery.parseJSON(data);
|
1230 |
+
if (jsonarray.result === 'success')
|
1231 |
+
{
|
1232 |
+
alert('success');
|
1233 |
+
jQuery('#wpvivid_uc_post_type_list').html(jsonarray.html);
|
1234 |
+
}
|
1235 |
+
else
|
1236 |
+
{
|
1237 |
+
alert(jsonarray.error);
|
1238 |
+
}
|
1239 |
+
}
|
1240 |
+
catch (err)
|
1241 |
+
{
|
1242 |
+
alert(err);
|
1243 |
+
}
|
1244 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1245 |
+
{
|
1246 |
+
jQuery('#wpvivid_uc_post_type_list').find('.action').prop('disabled', false);
|
1247 |
+
|
1248 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1249 |
+
alert(error_message);
|
1250 |
+
});
|
1251 |
+
}
|
1252 |
+
</script>
|
1253 |
+
</div>
|
1254 |
+
*/
|
1255 |
+
}
|
1256 |
+
|
1257 |
+
public function get_exclude_files_list()
|
1258 |
+
{
|
1259 |
+
try
|
1260 |
+
{
|
1261 |
+
if(isset($_POST['file_exclude'])&&!empty($_POST['file_exclude']))
|
1262 |
+
{
|
1263 |
+
$file_exclude=$_POST['file_exclude'];
|
1264 |
+
$white_list=get_option('wpvivid_uc_exclude_files_regex',array());
|
1265 |
+
$white_list[]=$file_exclude;
|
1266 |
+
update_option('wpvivid_uc_exclude_files_regex',$white_list);
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
$white_list=get_option('wpvivid_uc_exclude_files_regex',array());
|
1270 |
+
$list=new WPvivid_Exclude_Files_List();
|
1271 |
+
|
1272 |
+
if(isset($_POST['page']))
|
1273 |
+
{
|
1274 |
+
$list->set_list($white_list,$_POST['page']);
|
1275 |
+
}
|
1276 |
+
else
|
1277 |
+
{
|
1278 |
+
$list->set_list($white_list);
|
1279 |
+
}
|
1280 |
+
|
1281 |
+
$list->prepare_items();
|
1282 |
+
ob_start();
|
1283 |
+
$list->display();
|
1284 |
+
$html = ob_get_clean();
|
1285 |
+
|
1286 |
+
$ret['result']='success';
|
1287 |
+
$ret['html']=$html;
|
1288 |
+
echo json_encode($ret);
|
1289 |
+
}
|
1290 |
+
catch (Exception $error)
|
1291 |
+
{
|
1292 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
1293 |
+
error_log($message);
|
1294 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
1295 |
+
}
|
1296 |
+
die();
|
1297 |
+
}
|
1298 |
+
|
1299 |
+
public function delete_exclude_files()
|
1300 |
+
{
|
1301 |
+
try
|
1302 |
+
{
|
1303 |
+
$json = $_POST['selected'];
|
1304 |
+
$json = stripslashes($json);
|
1305 |
+
$json = json_decode($json, true);
|
1306 |
+
|
1307 |
+
$files=$json['selected'];
|
1308 |
+
|
1309 |
+
$white_list=get_option('wpvivid_uc_exclude_files_regex',array());
|
1310 |
+
$white_list = array_diff($white_list, $files);
|
1311 |
+
|
1312 |
+
update_option('wpvivid_uc_exclude_files_regex',$white_list);
|
1313 |
+
|
1314 |
+
$white_list=get_option('wpvivid_uc_exclude_files_regex',array());
|
1315 |
+
$list=new WPvivid_Exclude_Files_List();
|
1316 |
+
|
1317 |
+
if(isset($_POST['page']))
|
1318 |
+
{
|
1319 |
+
$list->set_list($white_list,$_POST['page']);
|
1320 |
+
}
|
1321 |
+
else
|
1322 |
+
{
|
1323 |
+
$list->set_list($white_list);
|
1324 |
+
}
|
1325 |
+
|
1326 |
+
$list->prepare_items();
|
1327 |
+
ob_start();
|
1328 |
+
$list->display();
|
1329 |
+
$html = ob_get_clean();
|
1330 |
+
|
1331 |
+
$ret['result']='success';
|
1332 |
+
$ret['html']=$html;
|
1333 |
+
echo json_encode($ret);
|
1334 |
+
}
|
1335 |
+
catch (Exception $error)
|
1336 |
+
{
|
1337 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
1338 |
+
error_log($message);
|
1339 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
1340 |
+
}
|
1341 |
+
die();
|
1342 |
+
}
|
1343 |
+
|
1344 |
+
public function get_post_type_list()
|
1345 |
+
{
|
1346 |
+
try
|
1347 |
+
{
|
1348 |
+
$default_post_types=array();
|
1349 |
+
$default_post_types[]='attachment';
|
1350 |
+
$default_post_types[]='revision';
|
1351 |
+
$default_post_types[]='auto-draft';
|
1352 |
+
$default_post_types[]='nav_menu_item';
|
1353 |
+
$default_post_types[]='shop_order';
|
1354 |
+
$default_post_types[]='shop_order_refund';
|
1355 |
+
$default_post_types[]='oembed_cache';
|
1356 |
+
|
1357 |
+
if(isset($_POST['post_type'])&&!empty($_POST['post_type']))
|
1358 |
+
{
|
1359 |
+
$file_exclude=$_POST['post_type'];
|
1360 |
+
|
1361 |
+
$post_types=get_option('wpvivid_uc_post_types',$default_post_types);
|
1362 |
+
$post_types[]=$file_exclude;
|
1363 |
+
update_option('wpvivid_uc_post_types',$post_types);
|
1364 |
+
}
|
1365 |
+
|
1366 |
+
$post_types=get_option('wpvivid_uc_post_types',array());
|
1367 |
+
$list=new WPvivid_Post_Type_List();
|
1368 |
+
|
1369 |
+
if(isset($_POST['page']))
|
1370 |
+
{
|
1371 |
+
$list->set_list($post_types,$_POST['page']);
|
1372 |
+
}
|
1373 |
+
else
|
1374 |
+
{
|
1375 |
+
$list->set_list($post_types);
|
1376 |
+
}
|
1377 |
+
|
1378 |
+
$list->prepare_items();
|
1379 |
+
ob_start();
|
1380 |
+
$list->display();
|
1381 |
+
$html = ob_get_clean();
|
1382 |
+
|
1383 |
+
$ret['result']='success';
|
1384 |
+
$ret['html']=$html;
|
1385 |
+
echo json_encode($ret);
|
1386 |
+
}
|
1387 |
+
catch (Exception $error)
|
1388 |
+
{
|
1389 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
1390 |
+
error_log($message);
|
1391 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
1392 |
+
}
|
1393 |
+
die();
|
1394 |
+
}
|
1395 |
+
|
1396 |
+
public function delete_post_type()
|
1397 |
+
{
|
1398 |
+
try
|
1399 |
+
{
|
1400 |
+
$default_post_types=array();
|
1401 |
+
$default_post_types[]='attachment';
|
1402 |
+
$default_post_types[]='revision';
|
1403 |
+
$default_post_types[]='auto-draft';
|
1404 |
+
$default_post_types[]='nav_menu_item';
|
1405 |
+
$default_post_types[]='shop_order';
|
1406 |
+
$default_post_types[]='shop_order_refund';
|
1407 |
+
$default_post_types[]='oembed_cache';
|
1408 |
+
|
1409 |
+
$json = $_POST['selected'];
|
1410 |
+
$json = stripslashes($json);
|
1411 |
+
$json = json_decode($json, true);
|
1412 |
+
|
1413 |
+
$files=$json['selected'];
|
1414 |
+
|
1415 |
+
$post_types=get_option('wpvivid_uc_post_types',$default_post_types);
|
1416 |
+
$post_types = array_diff($post_types, $files);
|
1417 |
+
|
1418 |
+
update_option('wpvivid_uc_post_types',$post_types);
|
1419 |
+
|
1420 |
+
$post_types=get_option('wpvivid_uc_post_types',$default_post_types);
|
1421 |
+
$list=new WPvivid_Post_Type_List();
|
1422 |
+
|
1423 |
+
if(isset($_POST['page']))
|
1424 |
+
{
|
1425 |
+
$list->set_list($post_types,$_POST['page']);
|
1426 |
+
}
|
1427 |
+
else
|
1428 |
+
{
|
1429 |
+
$list->set_list($post_types);
|
1430 |
+
}
|
1431 |
+
|
1432 |
+
$list->prepare_items();
|
1433 |
+
ob_start();
|
1434 |
+
$list->display();
|
1435 |
+
$html = ob_get_clean();
|
1436 |
+
|
1437 |
+
$ret['result']='success';
|
1438 |
+
$ret['html']=$html;
|
1439 |
+
echo json_encode($ret);
|
1440 |
+
}
|
1441 |
+
catch (Exception $error)
|
1442 |
+
{
|
1443 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
1444 |
+
error_log($message);
|
1445 |
+
echo json_encode(array('result'=>'failed','error'=>$message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7 |
+
define('WPVIVID_UPLOADS_ISO_DIR','WPvivid_Uploads'.DIRECTORY_SEPARATOR.'Isolate');
|
8 |
+
|
9 |
+
if ( ! class_exists( 'WP_List_Table' ) )
|
10 |
+
{
|
11 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
12 |
+
}
|
13 |
+
|
14 |
+
class WPvivid_Unused_Upload_Files_List extends WP_List_Table
|
15 |
+
{
|
16 |
+
public $list;
|
17 |
+
public $type;
|
18 |
+
public $page_num;
|
19 |
+
public $parent;
|
20 |
+
|
21 |
+
public function __construct( $args = array() )
|
22 |
+
{
|
23 |
+
global $wpdb;
|
24 |
+
parent::__construct(
|
25 |
+
array(
|
26 |
+
'plural' => 'upload_files',
|
27 |
+
'screen' => 'upload_files',
|
28 |
+
)
|
29 |
+
);
|
30 |
+
}
|
31 |
+
|
32 |
+
public function set_parent($parent)
|
33 |
+
{
|
34 |
+
$this->parent=$parent;
|
35 |
+
}
|
36 |
+
|
37 |
+
public function set_list($list,$page_num=1)
|
38 |
+
{
|
39 |
+
$this->list=$list;
|
40 |
+
$this->page_num=$page_num;
|
41 |
+
}
|
42 |
+
|
43 |
+
protected function get_table_classes()
|
44 |
+
{
|
45 |
+
return array( 'widefat striped' );
|
46 |
+
}
|
47 |
+
|
48 |
+
public function print_column_headers( $with_id = true )
|
49 |
+
{
|
50 |
+
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
|
51 |
+
|
52 |
+
if (!empty($columns['cb']))
|
53 |
+
{
|
54 |
+
static $cb_counter = 1;
|
55 |
+
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
|
56 |
+
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>';
|
57 |
+
$cb_counter++;
|
58 |
+
}
|
59 |
+
|
60 |
+
foreach ( $columns as $column_key => $column_display_name )
|
61 |
+
{
|
62 |
+
|
63 |
+
$class = array( 'manage-column', "column-$column_key" );
|
64 |
+
|
65 |
+
if ( in_array( $column_key, $hidden ) )
|
66 |
+
{
|
67 |
+
$class[] = 'hidden';
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
if ( $column_key === $primary )
|
72 |
+
{
|
73 |
+
$class[] = 'column-primary';
|
74 |
+
}
|
75 |
+
|
76 |
+
if ( $column_key === 'cb' )
|
77 |
+
{
|
78 |
+
$class[] = 'check-column';
|
79 |
+
}
|
80 |
+
$tag='th';
|
81 |
+
$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
|
82 |
+
$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
|
83 |
+
$id = $with_id ? "id='$column_key'" : '';
|
84 |
+
|
85 |
+
if ( ! empty( $class ) )
|
86 |
+
{
|
87 |
+
$class = "class='" . join( ' ', $class ) . "'";
|
88 |
+
}
|
89 |
+
|
90 |
+
echo "<$tag $scope $id $class>$column_display_name</$tag>";
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
public function get_columns()
|
95 |
+
{
|
96 |
+
$sites_columns = array(
|
97 |
+
'cb' => __( ' ' ),
|
98 |
+
'thumb' =>__( 'Thumbnail' ),
|
99 |
+
'path' => __( 'Path' ),
|
100 |
+
//'folder' => __( 'Folder' ),
|
101 |
+
'size'=>__( 'Size' )
|
102 |
+
);
|
103 |
+
|
104 |
+
return $sites_columns;
|
105 |
+
}
|
106 |
+
|
107 |
+
public function get_pagenum()
|
108 |
+
{
|
109 |
+
if($this->page_num=='first')
|
110 |
+
{
|
111 |
+
$this->page_num=1;
|
112 |
+
}
|
113 |
+
else if($this->page_num=='last')
|
114 |
+
{
|
115 |
+
$this->page_num=$this->_pagination_args['total_pages'];
|
116 |
+
}
|
117 |
+
$pagenum = $this->page_num ? $this->page_num : 0;
|
118 |
+
|
119 |
+
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
|
120 |
+
{
|
121 |
+
$pagenum = $this->_pagination_args['total_pages'];
|
122 |
+
}
|
123 |
+
|
124 |
+
return max( 1, $pagenum );
|
125 |
+
}
|
126 |
+
|
127 |
+
public function column_cb( $item )
|
128 |
+
{
|
129 |
+
$html='<input type="checkbox" name="uploads" value="'.$item['id'].'" />';
|
130 |
+
echo $html;
|
131 |
+
}
|
132 |
+
|
133 |
+
public function column_thumb($item)
|
134 |
+
{
|
135 |
+
$supported_image = array(
|
136 |
+
'gif',
|
137 |
+
'jpg',
|
138 |
+
'jpeg',
|
139 |
+
'png'
|
140 |
+
);
|
141 |
+
|
142 |
+
$upload_dir=wp_upload_dir();
|
143 |
+
|
144 |
+
$path=$upload_dir['basedir'].DIRECTORY_SEPARATOR.$item['path'];
|
145 |
+
|
146 |
+
$ext = strtolower(pathinfo($item['path'], PATHINFO_EXTENSION));
|
147 |
+
if (in_array($ext, $supported_image)&&file_exists( $path ))
|
148 |
+
{
|
149 |
+
echo "<a target='_blank' href='" . $upload_dir['baseurl'].'/'.$item['path'] .
|
150 |
+
"'><img style='max-width: 48px; max-height: 48px;' src='" .
|
151 |
+
$upload_dir['baseurl'].'/'.$item['path'] . "' />";
|
152 |
+
}
|
153 |
+
else {
|
154 |
+
echo '<span class="dashicons dashicons-no-alt"></span>';
|
155 |
+
}
|
156 |
+
|
157 |
+
}
|
158 |
+
|
159 |
+
public function column_path( $item )
|
160 |
+
{
|
161 |
+
echo '...\uploads\\'.$item['path'];
|
162 |
+
}
|
163 |
+
|
164 |
+
public function column_folder( $item )
|
165 |
+
{
|
166 |
+
if($item['folder']=='.')
|
167 |
+
{
|
168 |
+
echo 'Uploads root';
|
169 |
+
}
|
170 |
+
else
|
171 |
+
{
|
172 |
+
echo $item['folder'];
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
public function column_size( $item )
|
177 |
+
{
|
178 |
+
$upload_dir=wp_upload_dir();
|
179 |
+
$file_name=$upload_dir['basedir'].DIRECTORY_SEPARATOR.$item['path'];
|
180 |
+
|
181 |
+
if(file_exists($file_name))
|
182 |
+
{
|
183 |
+
echo size_format(filesize($file_name),2);
|
184 |
+
}
|
185 |
+
else
|
186 |
+
{
|
187 |
+
echo 'file not found';
|
188 |
+
}
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
public function has_items()
|
193 |
+
{
|
194 |
+
return !empty($this->list);
|
195 |
+
}
|
196 |
+
|
197 |
+
public function prepare_items()
|
198 |
+
{
|
199 |
+
$columns = $this->get_columns();
|
200 |
+
$hidden = array();
|
201 |
+
$sortable = array();
|
202 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
203 |
+
|
204 |
+
$total_items =sizeof($this->list);
|
205 |
+
|
206 |
+
$this->set_pagination_args(
|
207 |
+
array(
|
208 |
+
'total_items' => $total_items,
|
209 |
+
'per_page' => 20,
|
210 |
+
)
|
211 |
+
);
|
212 |
+
}
|
213 |
+
|
214 |
+
public function display_rows()
|
215 |
+
{
|
216 |
+
$this->_display_rows( $this->list );
|
217 |
+
}
|
218 |
+
|
219 |
+
private function _display_rows( $list )
|
220 |
+
{
|
221 |
+
$page=$this->get_pagenum();
|
222 |
+
|
223 |
+
$page_list=$list;
|
224 |
+
$temp_page_list=array();
|
225 |
+
|
226 |
+
$count=0;
|
227 |
+
while ( $count<$page )
|
228 |
+
{
|
229 |
+
$temp_page_list = array_splice( $page_list, 0, 20);
|
230 |
+
$count++;
|
231 |
+
}
|
232 |
+
|
233 |
+
foreach ( $temp_page_list as $key=>$item)
|
234 |
+
{
|
235 |
+
$this->single_row($item);
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
public function single_row($item)
|
240 |
+
{
|
241 |
+
?>
|
242 |
+
<tr>
|
243 |
+
<?php $this->single_row_columns( $item ); ?>
|
244 |
+
</tr>
|
245 |
+
<?php
|
246 |
+
}
|
247 |
+
|
248 |
+
protected function pagination( $which )
|
249 |
+
{
|
250 |
+
if ( empty( $this->_pagination_args ) )
|
251 |
+
{
|
252 |
+
return;
|
253 |
+
}
|
254 |
+
|
255 |
+
$total_items = $this->_pagination_args['total_items'];
|
256 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
257 |
+
$infinite_scroll = false;
|
258 |
+
if ( isset( $this->_pagination_args['infinite_scroll'] ) )
|
259 |
+
{
|
260 |
+
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
|
261 |
+
}
|
262 |
+
|
263 |
+
if ( 'top' === $which && $total_pages > 1 )
|
264 |
+
{
|
265 |
+
$this->screen->render_screen_reader_content( 'heading_pagination' );
|
266 |
+
}
|
267 |
+
|
268 |
+
$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
|
269 |
+
|
270 |
+
$current = $this->get_pagenum();
|
271 |
+
|
272 |
+
$page_links = array();
|
273 |
+
|
274 |
+
$total_pages_before = '<span class="paging-input">';
|
275 |
+
$total_pages_after = '</span></span>';
|
276 |
+
|
277 |
+
$disable_first = $disable_last = $disable_prev = $disable_next = false;
|
278 |
+
|
279 |
+
if ( $current == 1 ) {
|
280 |
+
$disable_first = true;
|
281 |
+
$disable_prev = true;
|
282 |
+
}
|
283 |
+
if ( $current == 2 ) {
|
284 |
+
$disable_first = true;
|
285 |
+
}
|
286 |
+
if ( $current == $total_pages ) {
|
287 |
+
$disable_last = true;
|
288 |
+
$disable_next = true;
|
289 |
+
}
|
290 |
+
if ( $current == $total_pages - 1 ) {
|
291 |
+
$disable_last = true;
|
292 |
+
}
|
293 |
+
|
294 |
+
if ( $disable_first ) {
|
295 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>';
|
296 |
+
} else {
|
297 |
+
$page_links[] = sprintf(
|
298 |
+
"<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
299 |
+
__( 'First page' ),
|
300 |
+
'«'
|
301 |
+
);
|
302 |
+
}
|
303 |
+
|
304 |
+
if ( $disable_prev ) {
|
305 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>';
|
306 |
+
} else {
|
307 |
+
$page_links[] = sprintf(
|
308 |
+
"<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
309 |
+
$current,
|
310 |
+
__( 'Previous page' ),
|
311 |
+
'‹'
|
312 |
+
);
|
313 |
+
}
|
314 |
+
|
315 |
+
if ( 'bottom' === $which ) {
|
316 |
+
$html_current_page = $current;
|
317 |
+
$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
|
318 |
+
} else {
|
319 |
+
$html_current_page = sprintf(
|
320 |
+
"%s<input class='current-page' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
|
321 |
+
'<label class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
|
322 |
+
$current,
|
323 |
+
strlen( $total_pages )
|
324 |
+
);
|
325 |
+
}
|
326 |
+
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
|
327 |
+
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
|
328 |
+
|
329 |
+
if ( $disable_next ) {
|
330 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>';
|
331 |
+
} else {
|
332 |
+
$page_links[] = sprintf(
|
333 |
+
"<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
334 |
+
$current,
|
335 |
+
__( 'Next page' ),
|
336 |
+
'›'
|
337 |
+
);
|
338 |
+
}
|
339 |
+
|
340 |
+
if ( $disable_last ) {
|
341 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>';
|
342 |
+
} else {
|
343 |
+
$page_links[] = sprintf(
|
344 |
+
"<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
345 |
+
__( 'Last page' ),
|
346 |
+
'»'
|
347 |
+
);
|
348 |
+
}
|
349 |
+
|
350 |
+
$pagination_links_class = 'pagination-links';
|
351 |
+
if ( ! empty( $infinite_scroll ) ) {
|
352 |
+
$pagination_links_class .= ' hide-if-js';
|
353 |
+
}
|
354 |
+
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
|
355 |
+
|
356 |
+
if ( $total_pages ) {
|
357 |
+
$page_class = $total_pages < 2 ? ' one-page' : '';
|
358 |
+
} else {
|
359 |
+
$page_class = ' no-pages';
|
360 |
+
}
|
361 |
+
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
|
362 |
+
|
363 |
+
echo $this->_pagination;
|
364 |
+
}
|
365 |
+
|
366 |
+
protected function display_tablenav( $which ) {
|
367 |
+
$css_type = '';
|
368 |
+
if ( 'top' === $which ) {
|
369 |
+
wp_nonce_field( 'bulk-' . $this->_args['plural'] );
|
370 |
+
$css_type = 'margin: 0 0 10px 0';
|
371 |
+
}
|
372 |
+
else if( 'bottom' === $which ) {
|
373 |
+
$css_type = 'margin: 10px 0 0 0';
|
374 |
+
}
|
375 |
+
|
376 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
377 |
+
if ( $total_pages >1)
|
378 |
+
{
|
379 |
+
?>
|
380 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
|
381 |
+
<div class="alignleft actions bulkactions">
|
382 |
+
<label for="wpvivid_uc_bulk_action" class="screen-reader-text">Select bulk action</label>
|
383 |
+
<select name="action" id="wpvivid_uc_bulk_action">
|
384 |
+
<option value="-1">Bulk Actions</option>
|
385 |
+
<option value="wpvivid_isolate_selected_image">Isolate selected images</option>
|
386 |
+
<option value="wpvivid_isolate_list_image">Isolate all images</option>
|
387 |
+
</select>
|
388 |
+
<input type="submit" class="button action" value="Apply">
|
389 |
+
</div>
|
390 |
+
<?php
|
391 |
+
$this->extra_tablenav( $which );
|
392 |
+
$this->pagination( $which );
|
393 |
+
?>
|
394 |
+
|
395 |
+
<br class="clear" />
|
396 |
+
</div>
|
397 |
+
<?php
|
398 |
+
}
|
399 |
+
else
|
400 |
+
{
|
401 |
+
?>
|
402 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
|
403 |
+
<div class="alignleft actions bulkactions">
|
404 |
+
<label for="wpvivid_uc_bulk_action" class="screen-reader-text">Select bulk action</label>
|
405 |
+
<select name="action" id="wpvivid_uc_bulk_action">
|
406 |
+
<option value="-1">Bulk Actions</option>
|
407 |
+
<option value="wpvivid_isolate_selected_image">Isolate selected images</option>
|
408 |
+
<option value="wpvivid_isolate_list_image">Isolate all images</option>
|
409 |
+
</select>
|
410 |
+
<input type="submit" class="button action" value="Apply">
|
411 |
+
</div>
|
412 |
+
|
413 |
+
<br class="clear" />
|
414 |
+
</div>
|
415 |
+
<?php
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
public function display() {
|
420 |
+
$singular = $this->_args['singular'];
|
421 |
+
|
422 |
+
$this->display_tablenav( 'top' );
|
423 |
+
|
424 |
+
$this->screen->render_screen_reader_content( 'heading_list' );
|
425 |
+
?>
|
426 |
+
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" >
|
427 |
+
<thead>
|
428 |
+
<tr>
|
429 |
+
<?php $this->print_column_headers(); ?>
|
430 |
+
</tr>
|
431 |
+
</thead>
|
432 |
+
|
433 |
+
<tbody id="the-list"
|
434 |
+
<?php
|
435 |
+
if ( $singular ) {
|
436 |
+
echo " data-wp-lists='list:$singular'";
|
437 |
+
}
|
438 |
+
?>
|
439 |
+
>
|
440 |
+
<?php $this->display_rows_or_placeholder(); ?>
|
441 |
+
</tbody>
|
442 |
+
|
443 |
+
<tfoot>
|
444 |
+
<tr>
|
445 |
+
<?php $this->print_column_headers( false ); ?>
|
446 |
+
</tr>
|
447 |
+
</tfoot>
|
448 |
+
|
449 |
+
</table>
|
450 |
+
<?php
|
451 |
+
}
|
452 |
+
}
|
453 |
+
|
454 |
+
class WPvivid_Isolate_Files_List extends WP_List_Table
|
455 |
+
{
|
456 |
+
public $list;
|
457 |
+
public $type;
|
458 |
+
public $page_num;
|
459 |
+
public $parent;
|
460 |
+
|
461 |
+
public function __construct( $args = array() )
|
462 |
+
{
|
463 |
+
global $wpdb;
|
464 |
+
parent::__construct(
|
465 |
+
array(
|
466 |
+
'plural' => 'upload_files',
|
467 |
+
'screen' => 'upload_files',
|
468 |
+
)
|
469 |
+
);
|
470 |
+
}
|
471 |
+
|
472 |
+
public function set_parent($parent)
|
473 |
+
{
|
474 |
+
$this->parent=$parent;
|
475 |
+
}
|
476 |
+
|
477 |
+
public function set_list($list,$page_num=1)
|
478 |
+
{
|
479 |
+
$this->list=$list;
|
480 |
+
$this->page_num=$page_num;
|
481 |
+
}
|
482 |
+
|
483 |
+
protected function get_table_classes()
|
484 |
+
{
|
485 |
+
return array( 'widefat striped' );
|
486 |
+
}
|
487 |
+
|
488 |
+
public function print_column_headers( $with_id = true )
|
489 |
+
{
|
490 |
+
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
|
491 |
+
|
492 |
+
if (!empty($columns['cb']))
|
493 |
+
{
|
494 |
+
static $cb_counter = 1;
|
495 |
+
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
|
496 |
+
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>';
|
497 |
+
$cb_counter++;
|
498 |
+
}
|
499 |
+
|
500 |
+
foreach ( $columns as $column_key => $column_display_name )
|
501 |
+
{
|
502 |
+
|
503 |
+
$class = array( 'manage-column', "column-$column_key" );
|
504 |
+
|
505 |
+
if ( in_array( $column_key, $hidden ) )
|
506 |
+
{
|
507 |
+
$class[] = 'hidden';
|
508 |
+
}
|
509 |
+
|
510 |
+
|
511 |
+
if ( $column_key === $primary )
|
512 |
+
{
|
513 |
+
$class[] = 'column-primary';
|
514 |
+
}
|
515 |
+
|
516 |
+
if ( $column_key === 'cb' )
|
517 |
+
{
|
518 |
+
$class[] = 'check-column';
|
519 |
+
}
|
520 |
+
$tag='th';
|
521 |
+
$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
|
522 |
+
$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
|
523 |
+
$id = $with_id ? "id='$column_key'" : '';
|
524 |
+
|
525 |
+
if ( ! empty( $class ) )
|
526 |
+
{
|
527 |
+
$class = "class='" . join( ' ', $class ) . "'";
|
528 |
+
}
|
529 |
+
|
530 |
+
echo "<$tag $scope $id $class>$column_display_name</$tag>";
|
531 |
+
}
|
532 |
+
}
|
533 |
+
|
534 |
+
public function get_columns()
|
535 |
+
{
|
536 |
+
$sites_columns = array(
|
537 |
+
'cb' => __( ' ' ),
|
538 |
+
'thumb' =>__( 'Thumbnail' ),
|
539 |
+
'path' => __( 'Path' ),
|
540 |
+
//'folder' => __( 'Folder' ),
|
541 |
+
'size'=>__( 'Size' )
|
542 |
+
);
|
543 |
+
|
544 |
+
return $sites_columns;
|
545 |
+
}
|
546 |
+
|
547 |
+
public function get_pagenum()
|
548 |
+
{
|
549 |
+
if($this->page_num=='first')
|
550 |
+
{
|
551 |
+
$this->page_num=1;
|
552 |
+
}
|
553 |
+
else if($this->page_num=='last')
|
554 |
+
{
|
555 |
+
$this->page_num=$this->_pagination_args['total_pages'];
|
556 |
+
}
|
557 |
+
$pagenum = $this->page_num ? $this->page_num : 0;
|
558 |
+
|
559 |
+
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
|
560 |
+
{
|
561 |
+
$pagenum = $this->_pagination_args['total_pages'];
|
562 |
+
}
|
563 |
+
|
564 |
+
return max( 1, $pagenum );
|
565 |
+
}
|
566 |
+
|
567 |
+
public function column_cb( $item )
|
568 |
+
{
|
569 |
+
$html='<input type="checkbox" name="uploads" />';
|
570 |
+
echo $html;
|
571 |
+
}
|
572 |
+
|
573 |
+
public function column_thumb($item)
|
574 |
+
{
|
575 |
+
$supported_image = array(
|
576 |
+
'gif',
|
577 |
+
'jpg',
|
578 |
+
'jpeg',
|
579 |
+
'png'
|
580 |
+
);
|
581 |
+
|
582 |
+
|
583 |
+
|
584 |
+
$path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR.DIRECTORY_SEPARATOR.$item['path'];
|
585 |
+
|
586 |
+
$ext = strtolower(pathinfo($item['path'], PATHINFO_EXTENSION));
|
587 |
+
if (in_array($ext, $supported_image)&&file_exists( $path ))
|
588 |
+
{
|
589 |
+
echo "<a target='_blank' href='" . WP_CONTENT_URL.'/'.WPVIVID_UPLOADS_ISO_DIR.'/'.$item['path'] .
|
590 |
+
"'><img style='max-width: 48px; max-height: 48px;' src='" .
|
591 |
+
WP_CONTENT_URL.'/'.WPVIVID_UPLOADS_ISO_DIR.'/'.$item['path'] . "' />";
|
592 |
+
}
|
593 |
+
else {
|
594 |
+
echo '<span class="dashicons dashicons-no-alt"></span>';
|
595 |
+
}
|
596 |
+
|
597 |
+
}
|
598 |
+
|
599 |
+
public function column_path( $item )
|
600 |
+
{
|
601 |
+
echo '...\uploads\\'.$item['path'];
|
602 |
+
}
|
603 |
+
|
604 |
+
public function column_folder( $item )
|
605 |
+
{
|
606 |
+
if($item['folder']=='.')
|
607 |
+
{
|
608 |
+
echo 'Uploads root';
|
609 |
+
}
|
610 |
+
else
|
611 |
+
{
|
612 |
+
echo $item['folder'];
|
613 |
+
}
|
614 |
+
}
|
615 |
+
|
616 |
+
public function column_size( $item )
|
617 |
+
{
|
618 |
+
$file_name=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR.DIRECTORY_SEPARATOR.$item['path'];
|
619 |
+
|
620 |
+
if(file_exists($file_name))
|
621 |
+
{
|
622 |
+
echo size_format(filesize($file_name),2);
|
623 |
+
}
|
624 |
+
else
|
625 |
+
{
|
626 |
+
echo 'file not found';
|
627 |
+
}
|
628 |
+
|
629 |
+
}
|
630 |
+
|
631 |
+
public function has_items()
|
632 |
+
{
|
633 |
+
return !empty($this->list);
|
634 |
+
}
|
635 |
+
|
636 |
+
public function prepare_items()
|
637 |
+
{
|
638 |
+
$columns = $this->get_columns();
|
639 |
+
$hidden = array();
|
640 |
+
$sortable = array();
|
641 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
642 |
+
|
643 |
+
$total_items =sizeof($this->list);
|
644 |
+
|
645 |
+
$this->set_pagination_args(
|
646 |
+
array(
|
647 |
+
'total_items' => $total_items,
|
648 |
+
'per_page' => 20,
|
649 |
+
)
|
650 |
+
);
|
651 |
+
}
|
652 |
+
|
653 |
+
public function display_rows()
|
654 |
+
{
|
655 |
+
$this->_display_rows( $this->list );
|
656 |
+
}
|
657 |
+
|
658 |
+
private function _display_rows( $list )
|
659 |
+
{
|
660 |
+
$page=$this->get_pagenum();
|
661 |
+
|
662 |
+
$page_list=$list;
|
663 |
+
$temp_page_list=array();
|
664 |
+
|
665 |
+
$count=0;
|
666 |
+
while ( $count<$page )
|
667 |
+
{
|
668 |
+
$temp_page_list = array_splice( $page_list, 0, 20);
|
669 |
+
$count++;
|
670 |
+
}
|
671 |
+
|
672 |
+
foreach ( $temp_page_list as $key=>$item)
|
673 |
+
{
|
674 |
+
$this->single_row($item);
|
675 |
+
}
|
676 |
+
}
|
677 |
+
|
678 |
+
public function single_row($item)
|
679 |
+
{
|
680 |
+
?>
|
681 |
+
<tr path="<?php echo $item['path']?>">
|
682 |
+
<?php $this->single_row_columns( $item ); ?>
|
683 |
+
</tr>
|
684 |
+
<?php
|
685 |
+
}
|
686 |
+
|
687 |
+
protected function pagination( $which )
|
688 |
+
{
|
689 |
+
if ( empty( $this->_pagination_args ) )
|
690 |
+
{
|
691 |
+
return;
|
692 |
+
}
|
693 |
+
|
694 |
+
$total_items = $this->_pagination_args['total_items'];
|
695 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
696 |
+
$infinite_scroll = false;
|
697 |
+
if ( isset( $this->_pagination_args['infinite_scroll'] ) )
|
698 |
+
{
|
699 |
+
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
|
700 |
+
}
|
701 |
+
|
702 |
+
if ( 'top' === $which && $total_pages > 1 )
|
703 |
+
{
|
704 |
+
$this->screen->render_screen_reader_content( 'heading_pagination' );
|
705 |
+
}
|
706 |
+
|
707 |
+
$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
|
708 |
+
|
709 |
+
$current = $this->get_pagenum();
|
710 |
+
|
711 |
+
$page_links = array();
|
712 |
+
|
713 |
+
$total_pages_before = '<span class="paging-input">';
|
714 |
+
$total_pages_after = '</span></span>';
|
715 |
+
|
716 |
+
$disable_first = $disable_last = $disable_prev = $disable_next = false;
|
717 |
+
|
718 |
+
if ( $current == 1 ) {
|
719 |
+
$disable_first = true;
|
720 |
+
$disable_prev = true;
|
721 |
+
}
|
722 |
+
if ( $current == 2 ) {
|
723 |
+
$disable_first = true;
|
724 |
+
}
|
725 |
+
if ( $current == $total_pages ) {
|
726 |
+
$disable_last = true;
|
727 |
+
$disable_next = true;
|
728 |
+
}
|
729 |
+
if ( $current == $total_pages - 1 ) {
|
730 |
+
$disable_last = true;
|
731 |
+
}
|
732 |
+
|
733 |
+
if ( $disable_first ) {
|
734 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>';
|
735 |
+
} else {
|
736 |
+
$page_links[] = sprintf(
|
737 |
+
"<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
738 |
+
__( 'First page' ),
|
739 |
+
'«'
|
740 |
+
);
|
741 |
+
}
|
742 |
+
|
743 |
+
if ( $disable_prev ) {
|
744 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>';
|
745 |
+
} else {
|
746 |
+
$page_links[] = sprintf(
|
747 |
+
"<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
748 |
+
$current,
|
749 |
+
__( 'Previous page' ),
|
750 |
+
'‹'
|
751 |
+
);
|
752 |
+
}
|
753 |
+
|
754 |
+
if ( 'bottom' === $which ) {
|
755 |
+
$html_current_page = $current;
|
756 |
+
$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
|
757 |
+
} else {
|
758 |
+
$html_current_page = sprintf(
|
759 |
+
"%s<input class='current-page' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
|
760 |
+
'<label class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
|
761 |
+
$current,
|
762 |
+
strlen( $total_pages )
|
763 |
+
);
|
764 |
+
}
|
765 |
+
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
|
766 |
+
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
|
767 |
+
|
768 |
+
if ( $disable_next ) {
|
769 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>';
|
770 |
+
} else {
|
771 |
+
$page_links[] = sprintf(
|
772 |
+
"<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
773 |
+
$current,
|
774 |
+
__( 'Next page' ),
|
775 |
+
'›'
|
776 |
+
);
|
777 |
+
}
|
778 |
+
|
779 |
+
if ( $disable_last ) {
|
780 |
+
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>';
|
781 |
+
} else {
|
782 |
+
$page_links[] = sprintf(
|
783 |
+
"<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
784 |
+
__( 'Last page' ),
|
785 |
+
'»'
|
786 |
+
);
|
787 |
+
}
|
788 |
+
|
789 |
+
$pagination_links_class = 'pagination-links';
|
790 |
+
if ( ! empty( $infinite_scroll ) ) {
|
791 |
+
$pagination_links_class .= ' hide-if-js';
|
792 |
+
}
|
793 |
+
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
|
794 |
+
|
795 |
+
if ( $total_pages ) {
|
796 |
+
$page_class = $total_pages < 2 ? ' one-page' : '';
|
797 |
+
} else {
|
798 |
+
$page_class = ' no-pages';
|
799 |
+
}
|
800 |
+
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
|
801 |
+
|
802 |
+
echo $this->_pagination;
|
803 |
+
}
|
804 |
+
|
805 |
+
protected function display_tablenav( $which ) {
|
806 |
+
$css_type = '';
|
807 |
+
if ( 'top' === $which ) {
|
808 |
+
wp_nonce_field( 'bulk-' . $this->_args['plural'] );
|
809 |
+
$css_type = 'margin: 0 0 10px 0';
|
810 |
+
}
|
811 |
+
else if( 'bottom' === $which ) {
|
812 |
+
$css_type = 'margin: 10px 0 0 0';
|
813 |
+
}
|
814 |
+
|
815 |
+
$total_pages = $this->_pagination_args['total_pages'];
|
816 |
+
|
817 |
+
$admin_url = apply_filters('wpvivid_get_admin_url', '');
|
818 |
+
|
819 |
+
if ( $total_pages >1)
|
820 |
+
{
|
821 |
+
?>
|
822 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
|
823 |
+
<div class="alignleft actions bulkactions">
|
824 |
+
<label for="wpvivid_uc_iso_bulk_action" class="screen-reader-text">Select bulk action</label>
|
825 |
+
<select name="action" id="wpvivid_uc_iso_bulk_action">
|
826 |
+
<option value="-1">Bulk Actions</option>
|
827 |
+
<option value="wpvivid_restore_selected_image">Restore selected images</option>
|
828 |
+
<option value="wpvivid_restore_list_image">Restore all images</option>
|
829 |
+
<option value="wpvivid_delete_selected_image">Delete selected images</option>
|
830 |
+
<option value="wpvivid_delete_list_image">Delete all images</option>
|
831 |
+
</select>
|
832 |
+
<input type="submit" class="button action" value="Apply">
|
833 |
+
</div>
|
834 |
+
<div class="wpvivid-backup-tips" style="background: #fff; border: 1px solid #f1f1f1; border-radius: 6px; margin-top: 10px;margin-bottom: 10px">
|
835 |
+
<div style="float: left;">
|
836 |
+
<div style="padding: 10px;">
|
837 |
+
<strong><?php _e('Note: ', 'wpvivid'); ?></strong>
|
838 |
+
<?php _e('Once deleted, images will be lost permanently. The action cannot be undone, unless you have <a href="'. $admin_url . 'admin.php?page=WPvivid'.'">a backup</a> in place.', 'wpvivid'); ?>
|
839 |
+
</div>
|
840 |
+
</div>
|
841 |
+
<div style="clear: both;"></div>
|
842 |
+
</div>
|
843 |
+
|
844 |
+
<?php
|
845 |
+
$this->extra_tablenav( $which );
|
846 |
+
$this->pagination( $which );
|
847 |
+
?>
|
848 |
+
<br class="clear" />
|
849 |
+
</div>
|
850 |
+
<?php
|
851 |
+
}
|
852 |
+
else
|
853 |
+
{
|
854 |
+
?>
|
855 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
|
856 |
+
<div class="alignleft actions bulkactions">
|
857 |
+
<label for="wpvivid_uc_iso_bulk_action" class="screen-reader-text">Select bulk action</label>
|
858 |
+
<select name="action" id="wpvivid_uc_iso_bulk_action">
|
859 |
+
<option value="-1">Bulk Actions</option>
|
860 |
+
<option value="wpvivid_restore_selected_image">Restore selected images</option>
|
861 |
+
<option value="wpvivid_restore_list_image">Restore all images</option>
|
862 |
+
<option value="wpvivid_delete_selected_image">Delete selected images</option>
|
863 |
+
<option value="wpvivid_delete_list_image">Delete all images</option>
|
864 |
+
</select>
|
865 |
+
<input type="submit" class="button action" value="Apply">
|
866 |
+
</div>
|
867 |
+
<div class="wpvivid-backup-tips" style="background: #fff; border: 1px solid #f1f1f1; border-radius: 6px; margin-top: 10px;margin-bottom: 10px">
|
868 |
+
<div style="float: left;">
|
869 |
+
<div style="padding: 10px;">
|
870 |
+
<strong><?php _e('Note: ', 'wpvivid'); ?></strong>
|
871 |
+
<?php _e('Once deleted, images will be lost permanently. The action cannot be undone, unless you have <a href="'. $admin_url . 'admin.php?page=WPvivid'.'">a backup</a> in place.', 'wpvivid'); ?>
|
872 |
+
</div>
|
873 |
+
</div>
|
874 |
+
<div style="clear: both;"></div>
|
875 |
+
</div>
|
876 |
+
<br class="clear" />
|
877 |
+
</div>
|
878 |
+
<?php
|
879 |
+
}
|
880 |
+
}
|
881 |
+
|
882 |
+
public function display() {
|
883 |
+
$singular = $this->_args['singular'];
|
884 |
+
|
885 |
+
$this->display_tablenav( 'top' );
|
886 |
+
|
887 |
+
$this->screen->render_screen_reader_content( 'heading_list' );
|
888 |
+
?>
|
889 |
+
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" >
|
890 |
+
<thead>
|
891 |
+
<tr>
|
892 |
+
<?php $this->print_column_headers(); ?>
|
893 |
+
</tr>
|
894 |
+
</thead>
|
895 |
+
|
896 |
+
<tbody id="the-list"
|
897 |
+
<?php
|
898 |
+
if ( $singular ) {
|
899 |
+
echo " data-wp-lists='list:$singular'";
|
900 |
+
}
|
901 |
+
?>
|
902 |
+
>
|
903 |
+
<?php $this->display_rows_or_placeholder(); ?>
|
904 |
+
</tbody>
|
905 |
+
|
906 |
+
<tfoot>
|
907 |
+
<tr>
|
908 |
+
<?php $this->print_column_headers( false ); ?>
|
909 |
+
</tr>
|
910 |
+
</tfoot>
|
911 |
+
|
912 |
+
</table>
|
913 |
+
<?php
|
914 |
+
}
|
915 |
+
}
|
916 |
+
|
917 |
+
class WPvivid_Uploads_Cleaner
|
918 |
+
{
|
919 |
+
public $main_tab;
|
920 |
+
|
921 |
+
|
922 |
+
//public $screen_ids;
|
923 |
+
//public $version;
|
924 |
+
//public $plugin_name;
|
925 |
+
|
926 |
+
public function __construct()
|
927 |
+
{
|
928 |
+
//$this->version = WPVIVID_UPLOADS_CLEANER_VERSION;
|
929 |
+
//$this->plugin_name = WPVIVID_UPLOADS_CLEANER_SLUG;
|
930 |
+
//$this->screen_ids=array();
|
931 |
+
//$this->screen_ids[]='toplevel_page_'. $this->plugin_name;
|
932 |
+
//add_action('admin_enqueue_scripts',array( $this,'enqueue_styles'));
|
933 |
+
//add_action('admin_enqueue_scripts',array( $this,'enqueue_scripts'));
|
934 |
+
//add_action('admin_menu',array( $this,'add_plugin_admin_menu'));
|
935 |
+
//$plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . 'wpvivid-uploads-cleaner.php' );
|
936 |
+
//add_filter('plugin_action_links_' . $plugin_basename, array( $this,'add_action_links'));
|
937 |
+
|
938 |
+
add_filter('wpvivid_scan_post_types',array($this,'scan_post_types'),10);
|
939 |
+
|
940 |
+
add_action('wp_ajax_wpvivid_start_scan_uploads_files_task', array($this, 'start_scan_uploads_files_task'));
|
941 |
+
add_action('wp_ajax_wpvivid_scan_uploads_files_from_post',array($this, 'scan_uploads_files_from_post'));
|
942 |
+
|
943 |
+
add_action('wp_ajax_wpvivid_start_unused_files_task',array($this, 'start_unused_files_task'));
|
944 |
+
add_action('wp_ajax_wpvivid_unused_files_task',array($this, 'unused_files_task'));
|
945 |
+
|
946 |
+
add_action('wp_ajax_wpvivid_get_result_list',array($this, 'get_result_list'));
|
947 |
+
|
948 |
+
add_action('wp_ajax_wpvivid_isolate_selected_image',array($this, 'isolate_selected_image'));
|
949 |
+
add_action('wp_ajax_wpvivid_start_isolate_all_image',array($this, 'start_isolate_all_image'));
|
950 |
+
add_action('wp_ajax_wpvivid_isolate_all_image',array($this, 'isolate_all_image'));
|
951 |
+
//
|
952 |
+
add_action('wp_ajax_wpvivid_get_iso_list',array($this, 'get_iso_list'));
|
953 |
+
|
954 |
+
add_action('wp_ajax_wpvivid_delete_selected_image',array($this, 'delete_selected_image'));
|
955 |
+
add_action('wp_ajax_wpvivid_start_delete_all_image',array($this, 'delete_all_image'));
|
956 |
+
add_action('wp_ajax_wpvivid_delete_all_image',array($this, 'delete_all_image'));
|
957 |
+
|
958 |
+
add_action('wp_ajax_wpvivid_restore_selected_image',array($this, 'restore_selected_image'));
|
959 |
+
add_action('wp_ajax_wpvivid_start_restore_all_image',array($this, 'restore_all_image'));
|
960 |
+
add_action('wp_ajax_wpvivid_restore_all_image',array($this, 'restore_all_image'));
|
961 |
+
|
962 |
+
add_action('wp_ajax_wpvivid_uc_add_exclude_files',array($this, 'add_exclude_files'));
|
963 |
+
//
|
964 |
+
add_filter('wpvivid_uc_scan_include_files_regex',array($this,'scan_include_files_regex'),10);
|
965 |
+
add_filter('wpvivid_uc_scan_exclude_files_regex',array($this,'scan_exclude_files_regex'),10);
|
966 |
+
|
967 |
+
|
968 |
+
include_once WPVIVID_PLUGIN_DIR . '/includes/upload-cleaner/class-wpvivid-uploads-scanner.php';
|
969 |
+
include_once WPVIVID_PLUGIN_DIR . '/includes/upload-cleaner/class-wpvivid-isolate-files.php';
|
970 |
+
include_once WPVIVID_PLUGIN_DIR. '/includes/upload-cleaner/class-wpvivid-upload-cleaner-setting.php';
|
971 |
+
|
972 |
+
$scan=new WPvivid_Uploads_Scanner();
|
973 |
+
$scan->check_table_exist();
|
974 |
+
$scan->check_unused_uploads_files_table_exist();
|
975 |
+
$iso=new WPvivid_Isolate_Files();
|
976 |
+
$iso->check_folder();
|
977 |
+
|
978 |
+
$setting=new WPvivid_Uploads_Cleaner_Setting();
|
979 |
+
|
980 |
+
|
981 |
+
add_filter('wpvivid_get_toolbar_menus',array($this,'get_toolbar_menus'),22);
|
982 |
+
add_filter('wpvivid_get_admin_menus',array($this,'get_admin_menus'),22);
|
983 |
+
add_filter('wpvivid_get_screen_ids',array($this,'get_screen_ids'),12);
|
984 |
+
}
|
985 |
+
|
986 |
+
public function get_screen_ids($screen_ids)
|
987 |
+
{
|
988 |
+
$screen_ids[]=apply_filters('wpvivid_white_label_screen_id', 'wpvivid-backup_page_wpvivid-cleaner');
|
989 |
+
return $screen_ids;
|
990 |
+
}
|
991 |
+
|
992 |
+
public function get_toolbar_menus($toolbar_menus)
|
993 |
+
{
|
994 |
+
$admin_url = apply_filters('wpvivid_get_admin_url', '');
|
995 |
+
|
996 |
+
$menu['id']='wpvivid_admin_menu_cleaner';
|
997 |
+
$menu['parent']='wpvivid_admin_menu';
|
998 |
+
$menu['title']=__('Image Cleaner', 'wpvivid-backuprestore');
|
999 |
+
$menu['tab']= 'admin.php?page='.apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner');
|
1000 |
+
$menu['href']=$admin_url . 'admin.php?page='.apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner');
|
1001 |
+
$menu['capability']='administrator';
|
1002 |
+
$menu['index']=3;
|
1003 |
+
$toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
|
1004 |
+
return $toolbar_menus;
|
1005 |
+
}
|
1006 |
+
|
1007 |
+
public function get_admin_menus($submenus)
|
1008 |
+
{
|
1009 |
+
$submenu['parent_slug']=apply_filters('wpvivid_white_label_slug', WPVIVID_PLUGIN_SLUG);
|
1010 |
+
$submenu['page_title']= apply_filters('wpvivid_white_label_display', 'WPvivid Backup');
|
1011 |
+
$submenu['menu_title']=__('Image Cleaner', 'wpvivid-backuprestore');
|
1012 |
+
$submenu['capability']='administrator';
|
1013 |
+
$submenu['menu_slug']=strtolower(sprintf('%s-cleaner', apply_filters('wpvivid_white_label_slug', 'wpvivid')));
|
1014 |
+
$submenu['index']=3;
|
1015 |
+
$submenu['function']=array($this, 'display');
|
1016 |
+
$submenus[$submenu['menu_slug']]=$submenu;
|
1017 |
+
return $submenus;
|
1018 |
+
}
|
1019 |
+
|
1020 |
+
|
1021 |
+
private function transfer_path($path)
|
1022 |
+
{
|
1023 |
+
$path = str_replace('\\','/',$path);
|
1024 |
+
$values = explode('/',$path);
|
1025 |
+
return implode(DIRECTORY_SEPARATOR,$values);
|
1026 |
+
}
|
1027 |
+
|
1028 |
+
public function display()
|
1029 |
+
{
|
1030 |
+
$upload_dir=wp_upload_dir();
|
1031 |
+
|
1032 |
+
$path=$this->transfer_path($upload_dir['basedir']);
|
1033 |
+
|
1034 |
+
$path1=$this->transfer_path(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.'uploads');
|
1035 |
+
|
1036 |
+
if($path!==$path1)
|
1037 |
+
{
|
1038 |
+
echo '<div class="notice notice-error inline"><p>The current version does not support custom uploads directory</p></div>';
|
1039 |
+
return;
|
1040 |
+
}
|
1041 |
+
|
1042 |
+
?>
|
1043 |
+
<div class="wrap" style="max-width:1720px;">
|
1044 |
+
<h1>
|
1045 |
+
<?php
|
1046 |
+
echo __('WPvivid Image Cleaner', 'wpvivid');
|
1047 |
+
?>
|
1048 |
+
</h1>
|
1049 |
+
<?php
|
1050 |
+
|
1051 |
+
if(!class_exists('WPvivid_UC_Tab_Page_Container'))
|
1052 |
+
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-tab-page-container.php';
|
1053 |
+
|
1054 |
+
$args['is_parent_tab']=1;
|
1055 |
+
$this->main_tab=new WPvivid_Tab_Page_Container();
|
1056 |
+
$this->main_tab->add_tab('Scan Media','scan',array($this, 'output_scan'), $args);
|
1057 |
+
$this->main_tab->add_tab('Isolated Media','isolate',array($this, 'output_isolate'), $args);
|
1058 |
+
//$this->main_tab->add_tab('Database','database',array($this, 'output_database'), $args);
|
1059 |
+
$this->main_tab->display();
|
1060 |
+
|
1061 |
+
if (isset($_GET['tab']))
|
1062 |
+
{
|
1063 |
+
$tab=$_GET['tab'];
|
1064 |
+
?>
|
1065 |
+
<script>
|
1066 |
+
jQuery(document).ready(function($)
|
1067 |
+
{
|
1068 |
+
jQuery( document ).trigger( '<?php echo $this->main_tab->container_id ?>-show','<?php echo $tab?>');
|
1069 |
+
});
|
1070 |
+
</script>
|
1071 |
+
<?php
|
1072 |
+
}
|
1073 |
+
?>
|
1074 |
+
</div>
|
1075 |
+
<?php
|
1076 |
+
}
|
1077 |
+
|
1078 |
+
public function output_scan()
|
1079 |
+
{
|
1080 |
+
$scanner=new WPvivid_Uploads_Scanner();
|
1081 |
+
$count=$scanner->get_scan_result_count();
|
1082 |
+
$size=$scanner->get_scan_result_size();
|
1083 |
+
if($count===false)
|
1084 |
+
{
|
1085 |
+
$text='';
|
1086 |
+
}
|
1087 |
+
else
|
1088 |
+
{
|
1089 |
+
$text="<p style=\"margin-top: 10px; margin-bottom: 0px;\">Last Scan: Unused media file(s) found: <strong>$count</strong>. ";
|
1090 |
+
if($size!==false)
|
1091 |
+
{
|
1092 |
+
$text.='Total size: '.$size.' .';
|
1093 |
+
}
|
1094 |
+
$text.="</p>";
|
1095 |
+
}
|
1096 |
+
|
1097 |
+
$upload_dir=wp_upload_dir();
|
1098 |
+
|
1099 |
+
$path=$this->transfer_path($upload_dir['basedir']);
|
1100 |
+
$abs=$this->transfer_path(ABSPATH);
|
1101 |
+
|
1102 |
+
$path=str_replace($abs,'...'.DIRECTORY_SEPARATOR,$path);
|
1103 |
+
|
1104 |
+
$folders=$scanner->get_all_folder();
|
1105 |
+
$admin_url = apply_filters('wpvivid_get_admin_url', '');
|
1106 |
+
//Before running a scan, it is recommended to <a style="cursor:pointer;" href="<?php echo $admin_url . 'admin.php?page=WPvivid';">[make a full website backup]</a> to avoid losing images.
|
1107 |
+
$progress_bar='<div class="action-progress-bar"><div class="action-progress-bar-percent" style="height:24px;width:0%"></div></div> <div style="clear:both;"></div><div style="margin-left:10px; float: left; width:100%;"><p>Ready to scan</p></div> <div style="clear: both;"></div><div><div class="backup-log-btn"><input class="button-primary" id="wpvivid_uc_cancel" type="submit" value="Cancel" /></div></div><div style="clear: both;"></div>';
|
1108 |
+
?>
|
1109 |
+
<div class="postbox quickbackup-addon">
|
1110 |
+
<div style="margin-top: 10px;margin-bottom: 10px;">
|
1111 |
+
In the tab, you can scan your media folder (uploads) to find unused images and isolate specific or all unused images.
|
1112 |
+
</div>
|
1113 |
+
<div id="wpvivid_uc_scan">
|
1114 |
+
<div style="margin-top: 10px;margin-bottom: 10px;">
|
1115 |
+
Media path: <a><?php echo $path?></a>
|
1116 |
+
</div>
|
1117 |
+
<input class="button-primary" style="width: 200px; height: 50px; font-size: 20px;" id="wpvivid_start_scan" type="submit" value="<?php esc_attr_e('Scan', 'wpvivid'); ?>">
|
1118 |
+
<div style="clear: both;"></div>
|
1119 |
+
<div style="margin-top: 10px">
|
1120 |
+
<span>
|
1121 |
+
Clicking the 'Scan' button to find unused images in your media folder. Currently it only scans JPG and PNG images.
|
1122 |
+
</span>
|
1123 |
+
</div>
|
1124 |
+
<?php echo $text?>
|
1125 |
+
<div class="wpvivid-backup-tips" style="background: #fff; border: 1px solid #f1f1f1; border-radius: 6px; margin-top: 10px;">
|
1126 |
+
<div style="float: left;">
|
1127 |
+
<div style="padding: 10px;">
|
1128 |
+
<strong><?php _e('Note: ', 'wpvivid'); ?></strong>
|
1129 |
+
<?php _e('Please don\'t refresh the page while running a scan.', 'wpvivid'); ?>
|
1130 |
+
</div>
|
1131 |
+
</div>
|
1132 |
+
<div style="clear: both;"></div>
|
1133 |
+
</div>
|
1134 |
+
</div>
|
1135 |
+
<div id="wpvivid_uc_progress" style="display: none;">
|
1136 |
+
<?php echo $progress_bar;?>
|
1137 |
+
</div>
|
1138 |
+
<br/>
|
1139 |
+
</div>
|
1140 |
+
<div class="postbox quickbackup-addon">
|
1141 |
+
<p>
|
1142 |
+
<input id="wpvivid_result_list_search" type="search" name="s" value="" placeholder="Search">
|
1143 |
+
<select id="wpvivid_result_list_folder" style="margin-top: -5px;">
|
1144 |
+
<option selected="selected" value="0">All Folders</option>
|
1145 |
+
<?php
|
1146 |
+
if(!empty($folders))
|
1147 |
+
{
|
1148 |
+
foreach ($folders as $folder)
|
1149 |
+
{
|
1150 |
+
echo "<option value='$folder'>$folder</option>";
|
1151 |
+
}
|
1152 |
+
}
|
1153 |
+
?>
|
1154 |
+
</select>
|
1155 |
+
<input id="wpvivid_result_list_search_btn" type="submit" class="button" value="Search">
|
1156 |
+
</p>
|
1157 |
+
</div>
|
1158 |
+
<div class="postbox">
|
1159 |
+
|
1160 |
+
<div id="wpvivid_scan_result_list" style="margin: 10px;">
|
1161 |
+
<?php
|
1162 |
+
|
1163 |
+
$result=$scanner->get_scan_result('','');
|
1164 |
+
|
1165 |
+
$list = new WPvivid_Unused_Upload_Files_List();
|
1166 |
+
|
1167 |
+
$list->set_list($result);
|
1168 |
+
$list->prepare_items();
|
1169 |
+
$list ->display();
|
1170 |
+
?>
|
1171 |
+
</div>
|
1172 |
+
</div>
|
1173 |
+
<script>
|
1174 |
+
var wpvivid_result_list_search='';
|
1175 |
+
var wpvivid_result_list_folder='';
|
1176 |
+
|
1177 |
+
jQuery('#wpvivid_result_list_search_btn').click(function()
|
1178 |
+
{
|
1179 |
+
wpvivid_result_list_search=jQuery('#wpvivid_result_list_search').val();
|
1180 |
+
wpvivid_result_list_folder=jQuery('#wpvivid_result_list_folder').val();
|
1181 |
+
if(wpvivid_result_list_folder=='0')
|
1182 |
+
{
|
1183 |
+
wpvivid_result_list_folder='';
|
1184 |
+
}
|
1185 |
+
|
1186 |
+
if(wpvivid_result_list_folder=='root')
|
1187 |
+
{
|
1188 |
+
wpvivid_result_list_folder='.';
|
1189 |
+
}
|
1190 |
+
|
1191 |
+
wpvivid_get_result_list('first');
|
1192 |
+
});
|
1193 |
+
|
1194 |
+
function wpvivid_get_result_list(page)
|
1195 |
+
{
|
1196 |
+
var ajax_data = {
|
1197 |
+
'action': 'wpvivid_get_result_list',
|
1198 |
+
'page':page,
|
1199 |
+
'search':wpvivid_result_list_search,
|
1200 |
+
'folder':wpvivid_result_list_folder
|
1201 |
+
};
|
1202 |
+
wpvivid_post_request(ajax_data, function (data)
|
1203 |
+
{
|
1204 |
+
jQuery('#wpvivid_scan_result_list').html('');
|
1205 |
+
try
|
1206 |
+
{
|
1207 |
+
var jsonarray = jQuery.parseJSON(data);
|
1208 |
+
if (jsonarray.result === 'success')
|
1209 |
+
{
|
1210 |
+
jQuery('#wpvivid_scan_result_list').html(jsonarray.html);
|
1211 |
+
}
|
1212 |
+
else
|
1213 |
+
{
|
1214 |
+
alert(jsonarray.error);
|
1215 |
+
}
|
1216 |
+
}
|
1217 |
+
catch (err)
|
1218 |
+
{
|
1219 |
+
alert(err);
|
1220 |
+
}
|
1221 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1222 |
+
{
|
1223 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1224 |
+
alert(error_message);
|
1225 |
+
});
|
1226 |
+
}
|
1227 |
+
|
1228 |
+
jQuery('#wpvivid_scan_result_list').on("click",'.first-page',function()
|
1229 |
+
{
|
1230 |
+
wpvivid_get_result_list('first');
|
1231 |
+
});
|
1232 |
+
|
1233 |
+
jQuery('#wpvivid_scan_result_list').on("click",'.prev-page',function()
|
1234 |
+
{
|
1235 |
+
var page=parseInt(jQuery(this).attr('value'));
|
1236 |
+
wpvivid_get_result_list(page-1);
|
1237 |
+
});
|
1238 |
+
|
1239 |
+
jQuery('#wpvivid_scan_result_list').on("click",'.next-page',function()
|
1240 |
+
{
|
1241 |
+
var page=parseInt(jQuery(this).attr('value'));
|
1242 |
+
wpvivid_get_result_list(page+1);
|
1243 |
+
});
|
1244 |
+
|
1245 |
+
jQuery('#wpvivid_scan_result_list').on("click",'.last-page',function()
|
1246 |
+
{
|
1247 |
+
wpvivid_get_result_list('last');
|
1248 |
+
});
|
1249 |
+
|
1250 |
+
jQuery('#wpvivid_scan_result_list').on("keypress", '.current-page', function()
|
1251 |
+
{
|
1252 |
+
if(event.keyCode === 13){
|
1253 |
+
var page = jQuery(this).val();
|
1254 |
+
wpvivid_get_result_list(page);
|
1255 |
+
}
|
1256 |
+
});
|
1257 |
+
|
1258 |
+
jQuery('#wpvivid_scan_result_list').on("click",'.action',function()
|
1259 |
+
{
|
1260 |
+
var selected=jQuery('#wpvivid_uc_bulk_action').val();
|
1261 |
+
|
1262 |
+
if(selected=='wpvivid_isolate_selected_image')
|
1263 |
+
{
|
1264 |
+
wpvivid_isolate_selected_image();
|
1265 |
+
}
|
1266 |
+
else if(selected=='wpvivid_isolate_list_image')
|
1267 |
+
{
|
1268 |
+
wpvivid_start_isolate_all_image();
|
1269 |
+
}
|
1270 |
+
else if(selected=='wpvivid_ignore_selected_image')
|
1271 |
+
{
|
1272 |
+
wpvivid_ignore_selected_image();
|
1273 |
+
}
|
1274 |
+
|
1275 |
+
|
1276 |
+
});
|
1277 |
+
|
1278 |
+
function wpvivid_ignore_selected_image()
|
1279 |
+
{
|
1280 |
+
var json = {};
|
1281 |
+
json['selected']=Array();
|
1282 |
+
jQuery('input[name=uploads][type=checkbox]').each(function(index, value)
|
1283 |
+
{
|
1284 |
+
if(jQuery(value).prop('checked'))
|
1285 |
+
{
|
1286 |
+
json['selected'].push(jQuery(value).val())
|
1287 |
+
}
|
1288 |
+
});
|
1289 |
+
var selected= JSON.stringify(json);
|
1290 |
+
|
1291 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', true);
|
1292 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', true);
|
1293 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', true);
|
1294 |
+
|
1295 |
+
var ajax_data = {
|
1296 |
+
'action': 'wpvivid_uc_add_exclude_files',
|
1297 |
+
'selected':selected,
|
1298 |
+
'search':wpvivid_result_list_search,
|
1299 |
+
'folder':wpvivid_result_list_folder
|
1300 |
+
};
|
1301 |
+
wpvivid_post_request(ajax_data, function (data)
|
1302 |
+
{
|
1303 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1304 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1305 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1306 |
+
|
1307 |
+
jQuery('#wpvivid_scan_result_list').html('');
|
1308 |
+
try
|
1309 |
+
{
|
1310 |
+
var jsonarray = jQuery.parseJSON(data);
|
1311 |
+
if (jsonarray.result === 'success')
|
1312 |
+
{
|
1313 |
+
jQuery('#wpvivid_scan_result_list').html(jsonarray.html);
|
1314 |
+
}
|
1315 |
+
else
|
1316 |
+
{
|
1317 |
+
alert(jsonarray.error);
|
1318 |
+
}
|
1319 |
+
}
|
1320 |
+
catch (err)
|
1321 |
+
{
|
1322 |
+
alert(err);
|
1323 |
+
}
|
1324 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1325 |
+
{
|
1326 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1327 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1328 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1329 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1330 |
+
alert(error_message);
|
1331 |
+
});
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
function wpvivid_isolate_selected_image()
|
1335 |
+
{
|
1336 |
+
var json = {};
|
1337 |
+
json['selected']=Array();
|
1338 |
+
jQuery('input[name=uploads][type=checkbox]').each(function(index, value)
|
1339 |
+
{
|
1340 |
+
if(jQuery(value).prop('checked'))
|
1341 |
+
{
|
1342 |
+
json['selected'].push(jQuery(value).val())
|
1343 |
+
}
|
1344 |
+
});
|
1345 |
+
var selected= JSON.stringify(json);
|
1346 |
+
|
1347 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', true);
|
1348 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', true);
|
1349 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', true);
|
1350 |
+
var ajax_data = {
|
1351 |
+
'action': 'wpvivid_isolate_selected_image',
|
1352 |
+
'selected':selected,
|
1353 |
+
'search':wpvivid_result_list_search,
|
1354 |
+
'folder':wpvivid_result_list_folder
|
1355 |
+
};
|
1356 |
+
wpvivid_post_request(ajax_data, function (data)
|
1357 |
+
{
|
1358 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1359 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1360 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1361 |
+
jQuery('#wpvivid_scan_result_list').html('');
|
1362 |
+
try
|
1363 |
+
{
|
1364 |
+
var jsonarray = jQuery.parseJSON(data);
|
1365 |
+
if (jsonarray.result === 'success')
|
1366 |
+
{
|
1367 |
+
jQuery('#wpvivid_scan_result_list').html(jsonarray.html);
|
1368 |
+
jQuery('#wpvivid_iso_files_list').html(jsonarray.iso);
|
1369 |
+
}
|
1370 |
+
else
|
1371 |
+
{
|
1372 |
+
alert(jsonarray.error);
|
1373 |
+
}
|
1374 |
+
}
|
1375 |
+
catch (err)
|
1376 |
+
{
|
1377 |
+
alert(err);
|
1378 |
+
}
|
1379 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1380 |
+
{
|
1381 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1382 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1383 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1384 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1385 |
+
alert(error_message);
|
1386 |
+
});
|
1387 |
+
}
|
1388 |
+
|
1389 |
+
function wpvivid_start_isolate_all_image()
|
1390 |
+
{
|
1391 |
+
var ajax_data = {
|
1392 |
+
'action': 'wpvivid_start_isolate_all_image',
|
1393 |
+
'search':wpvivid_result_list_search,
|
1394 |
+
'folder':wpvivid_result_list_folder
|
1395 |
+
};
|
1396 |
+
|
1397 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', true);
|
1398 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', true);
|
1399 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', true);
|
1400 |
+
wpvivid_post_request(ajax_data, function (data)
|
1401 |
+
{
|
1402 |
+
try
|
1403 |
+
{
|
1404 |
+
var jsonarray = jQuery.parseJSON(data);
|
1405 |
+
if (jsonarray.result === 'success')
|
1406 |
+
{
|
1407 |
+
if(jsonarray.continue)
|
1408 |
+
{
|
1409 |
+
wpvivid_isolate_all_image();
|
1410 |
+
}
|
1411 |
+
else
|
1412 |
+
{
|
1413 |
+
location.href = '<?php echo admin_url() . 'admin.php?page='.apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner');?>';
|
1414 |
+
}
|
1415 |
+
}
|
1416 |
+
else if (jsonarray.result === 'failed')
|
1417 |
+
{
|
1418 |
+
alert(jsonarray.error);
|
1419 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1420 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1421 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1422 |
+
}
|
1423 |
+
}
|
1424 |
+
catch(err)
|
1425 |
+
{
|
1426 |
+
alert(err);
|
1427 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1428 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1429 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1430 |
+
}
|
1431 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1432 |
+
{
|
1433 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1434 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1435 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1436 |
+
|
1437 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1438 |
+
alert(error_message);
|
1439 |
+
});
|
1440 |
+
}
|
1441 |
+
|
1442 |
+
function wpvivid_isolate_all_image()
|
1443 |
+
{
|
1444 |
+
var ajax_data = {
|
1445 |
+
'action': 'wpvivid_isolate_all_image',
|
1446 |
+
'search':wpvivid_result_list_search,
|
1447 |
+
'folder':wpvivid_result_list_folder
|
1448 |
+
};
|
1449 |
+
wpvivid_post_request(ajax_data, function(data)
|
1450 |
+
{
|
1451 |
+
try
|
1452 |
+
{
|
1453 |
+
var jsonarray = jQuery.parseJSON(data);
|
1454 |
+
if (jsonarray.result === 'success')
|
1455 |
+
{
|
1456 |
+
if(jsonarray.continue)
|
1457 |
+
{
|
1458 |
+
wpvivid_isolate_all_image();
|
1459 |
+
}
|
1460 |
+
else
|
1461 |
+
{
|
1462 |
+
location.href = '<?php echo admin_url() . 'admin.php?page='.apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner');?>';
|
1463 |
+
}
|
1464 |
+
}
|
1465 |
+
else if (jsonarray.result === 'failed')
|
1466 |
+
{
|
1467 |
+
alert(jsonarray.error);
|
1468 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1469 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1470 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1471 |
+
}
|
1472 |
+
}
|
1473 |
+
catch(err)
|
1474 |
+
{
|
1475 |
+
alert(err);
|
1476 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1477 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1478 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1479 |
+
}
|
1480 |
+
|
1481 |
+
}, function(XMLHttpRequest, textStatus, errorThrown)
|
1482 |
+
{
|
1483 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1484 |
+
alert(error_message);
|
1485 |
+
jQuery('#wpvivid_scan_result_list').find('.action').prop('disabled', false);
|
1486 |
+
//jQuery('#wpvivid_isolate_selected_image').prop('disabled', false);
|
1487 |
+
//jQuery('#wpvivid_isolate_list_image').prop('disabled', false);
|
1488 |
+
});
|
1489 |
+
}
|
1490 |
+
|
1491 |
+
jQuery('#wpvivid_rescan').click(function()
|
1492 |
+
{
|
1493 |
+
jQuery( document ).trigger( '<?php echo $this->main_tab->container_id ?>-show','scan');
|
1494 |
+
});
|
1495 |
+
|
1496 |
+
</script>
|
1497 |
+
<script>
|
1498 |
+
var wpvivid_cancel=false;
|
1499 |
+
jQuery('#wpvivid_start_scan').click(function()
|
1500 |
+
{
|
1501 |
+
wpvivid_start_scan();
|
1502 |
+
//wpvivid_start_unused_files_task();
|
1503 |
+
});
|
1504 |
+
|
1505 |
+
jQuery('#wpvivid_uc_progress').on("click",'#wpvivid_uc_cancel',function()
|
1506 |
+
{
|
1507 |
+
wpvivid_cancel_scan();
|
1508 |
+
});
|
1509 |
+
|
1510 |
+
function wpvivid_cancel_scan()
|
1511 |
+
{
|
1512 |
+
wpvivid_cancel=true;
|
1513 |
+
jQuery('#wpvivid_uc_cancel').prop('disabled', true);
|
1514 |
+
}
|
1515 |
+
|
1516 |
+
function wpvivid_start_scan()
|
1517 |
+
{
|
1518 |
+
jQuery('#wpvivid_uc_progress').show();
|
1519 |
+
|
1520 |
+
jQuery('#wpvivid_uc_progress').html('<?php echo $progress_bar?>');
|
1521 |
+
jQuery('#wpvivid_uc_scan').hide();
|
1522 |
+
jQuery('#wpvivid_uc_cancel').prop('disabled', false);
|
1523 |
+
|
1524 |
+
wpvivid_cancel=false;
|
1525 |
+
|
1526 |
+
var ajax_data = {
|
1527 |
+
'action': 'wpvivid_start_scan_uploads_files_task'
|
1528 |
+
};
|
1529 |
+
wpvivid_post_request(ajax_data, function(data)
|
1530 |
+
{
|
1531 |
+
try
|
1532 |
+
{
|
1533 |
+
var jsonarray = jQuery.parseJSON(data);
|
1534 |
+
if (jsonarray.result === 'success')
|
1535 |
+
{
|
1536 |
+
jQuery('#wpvivid_uc_progress').html(jsonarray.progress_html);
|
1537 |
+
if(jsonarray.continue)
|
1538 |
+
{
|
1539 |
+
scan_uploads_files(jsonarray.start);
|
1540 |
+
}
|
1541 |
+
else
|
1542 |
+
{
|
1543 |
+
wpvivid_start_unused_files_task();
|
1544 |
+
}
|
1545 |
+
}
|
1546 |
+
else if (jsonarray.result === 'failed')
|
1547 |
+
{
|
1548 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1549 |
+
jQuery('#wpvivid_uc_scan').show();
|
1550 |
+
}
|
1551 |
+
}
|
1552 |
+
catch(err)
|
1553 |
+
{
|
1554 |
+
alert(err);
|
1555 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1556 |
+
jQuery('#wpvivid_uc_scan').show();
|
1557 |
+
}
|
1558 |
+
|
1559 |
+
}, function(XMLHttpRequest, textStatus, errorThrown)
|
1560 |
+
{
|
1561 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1562 |
+
alert(error_message);
|
1563 |
+
|
1564 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1565 |
+
jQuery('#wpvivid_uc_scan').show();
|
1566 |
+
});
|
1567 |
+
}
|
1568 |
+
|
1569 |
+
function scan_uploads_files(start)
|
1570 |
+
{
|
1571 |
+
if(wpvivid_cancel)
|
1572 |
+
{
|
1573 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1574 |
+
jQuery('#wpvivid_uc_scan').show();
|
1575 |
+
jQuery('#wpvivid_uc_cancel').prop('disabled', false);
|
1576 |
+
return;
|
1577 |
+
}
|
1578 |
+
|
1579 |
+
var ajax_data = {
|
1580 |
+
'action': 'wpvivid_scan_uploads_files_from_post',
|
1581 |
+
'start':start
|
1582 |
+
};
|
1583 |
+
wpvivid_post_request(ajax_data, function(data)
|
1584 |
+
{
|
1585 |
+
try
|
1586 |
+
{
|
1587 |
+
var jsonarray = jQuery.parseJSON(data);
|
1588 |
+
if (jsonarray.result === 'success')
|
1589 |
+
{
|
1590 |
+
jQuery('#wpvivid_uc_progress').html(jsonarray.progress_html);
|
1591 |
+
if(jsonarray.continue)
|
1592 |
+
{
|
1593 |
+
scan_uploads_files(jsonarray.start);
|
1594 |
+
}
|
1595 |
+
else
|
1596 |
+
{
|
1597 |
+
wpvivid_start_unused_files_task();
|
1598 |
+
}
|
1599 |
+
}
|
1600 |
+
else if (jsonarray.result === 'failed')
|
1601 |
+
{
|
1602 |
+
alert(jsonarray.error);
|
1603 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1604 |
+
jQuery('#wpvivid_uc_scan').show();
|
1605 |
+
}
|
1606 |
+
}
|
1607 |
+
catch(err)
|
1608 |
+
{
|
1609 |
+
alert(err);
|
1610 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1611 |
+
jQuery('#wpvivid_uc_scan').show();
|
1612 |
+
}
|
1613 |
+
|
1614 |
+
}, function(XMLHttpRequest, textStatus, errorThrown)
|
1615 |
+
{
|
1616 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1617 |
+
alert(error_message);
|
1618 |
+
|
1619 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1620 |
+
jQuery('#wpvivid_uc_scan').show();
|
1621 |
+
});
|
1622 |
+
}
|
1623 |
+
|
1624 |
+
function wpvivid_start_unused_files_task()
|
1625 |
+
{
|
1626 |
+
if(wpvivid_cancel)
|
1627 |
+
{
|
1628 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1629 |
+
jQuery('#wpvivid_uc_scan').show();
|
1630 |
+
jQuery('#wpvivid_uc_cancel').prop('disabled', false);
|
1631 |
+
return;
|
1632 |
+
}
|
1633 |
+
|
1634 |
+
var ajax_data = {
|
1635 |
+
'action': 'wpvivid_start_unused_files_task'
|
1636 |
+
};
|
1637 |
+
wpvivid_post_request(ajax_data, function(data)
|
1638 |
+
{
|
1639 |
+
try
|
1640 |
+
{
|
1641 |
+
var jsonarray = jQuery.parseJSON(data);
|
1642 |
+
if (jsonarray.result === 'success')
|
1643 |
+
{
|
1644 |
+
jQuery('#wpvivid_uc_progress').html(jsonarray.progress_html);
|
1645 |
+
if(jsonarray.continue)
|
1646 |
+
{
|
1647 |
+
wpvivid_unused_files_task();
|
1648 |
+
}
|
1649 |
+
else
|
1650 |
+
{
|
1651 |
+
location.href = '<?php echo admin_url() . 'admin.php?page='.apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner');?>';
|
1652 |
+
}
|
1653 |
+
}
|
1654 |
+
else if (jsonarray.result === 'failed')
|
1655 |
+
{
|
1656 |
+
alert(jsonarray.error);
|
1657 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1658 |
+
jQuery('#wpvivid_uc_scan').show();
|
1659 |
+
}
|
1660 |
+
}
|
1661 |
+
catch(err)
|
1662 |
+
{
|
1663 |
+
alert(err);
|
1664 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1665 |
+
jQuery('#wpvivid_uc_scan').show();
|
1666 |
+
}
|
1667 |
+
|
1668 |
+
}, function(XMLHttpRequest, textStatus, errorThrown)
|
1669 |
+
{
|
1670 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1671 |
+
alert(error_message);
|
1672 |
+
|
1673 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1674 |
+
jQuery('#wpvivid_uc_scan').show();
|
1675 |
+
});
|
1676 |
+
}
|
1677 |
+
|
1678 |
+
function wpvivid_unused_files_task()
|
1679 |
+
{
|
1680 |
+
if(wpvivid_cancel)
|
1681 |
+
{
|
1682 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1683 |
+
jQuery('#wpvivid_uc_scan').show();
|
1684 |
+
jQuery('#wpvivid_uc_cancel').prop('disabled', false);
|
1685 |
+
jQuery('#wpvivid_uc_scan_log').html("");
|
1686 |
+
return;
|
1687 |
+
}
|
1688 |
+
|
1689 |
+
var ajax_data = {
|
1690 |
+
'action': 'wpvivid_unused_files_task'
|
1691 |
+
};
|
1692 |
+
wpvivid_post_request(ajax_data, function(data)
|
1693 |
+
{
|
1694 |
+
try
|
1695 |
+
{
|
1696 |
+
var jsonarray = jQuery.parseJSON(data);
|
1697 |
+
if (jsonarray.result === 'success')
|
1698 |
+
{
|
1699 |
+
jQuery('#wpvivid_uc_progress').html(jsonarray.progress_html);
|
1700 |
+
if(jsonarray.continue)
|
1701 |
+
{
|
1702 |
+
wpvivid_unused_files_task();
|
1703 |
+
}
|
1704 |
+
else
|
1705 |
+
{
|
1706 |
+
location.href = '<?php echo admin_url() . 'admin.php?page='.apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner');?>';
|
1707 |
+
}
|
1708 |
+
}
|
1709 |
+
else if (jsonarray.result === 'failed')
|
1710 |
+
{
|
1711 |
+
alert(jsonarray.error);
|
1712 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1713 |
+
jQuery('#wpvivid_uc_scan').show();
|
1714 |
+
}
|
1715 |
+
}
|
1716 |
+
catch(err)
|
1717 |
+
{
|
1718 |
+
alert(err);
|
1719 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1720 |
+
jQuery('#wpvivid_uc_scan').show();
|
1721 |
+
}
|
1722 |
+
|
1723 |
+
}, function(XMLHttpRequest, textStatus, errorThrown)
|
1724 |
+
{
|
1725 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1726 |
+
alert(error_message);
|
1727 |
+
|
1728 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1729 |
+
jQuery('#wpvivid_uc_scan').show();
|
1730 |
+
});
|
1731 |
+
}
|
1732 |
+
|
1733 |
+
jQuery(document).ready(function($)
|
1734 |
+
{
|
1735 |
+
jQuery('#wpvivid_uc_scan').show();
|
1736 |
+
jQuery('#wpvivid_uc_progress').hide();
|
1737 |
+
});
|
1738 |
+
</script>
|
1739 |
+
<?php
|
1740 |
+
}
|
1741 |
+
|
1742 |
+
public function output_isolate()
|
1743 |
+
{
|
1744 |
+
$iso=new WPvivid_Isolate_Files();
|
1745 |
+
|
1746 |
+
$path=$this->transfer_path(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR);
|
1747 |
+
$abs=$this->transfer_path(ABSPATH);
|
1748 |
+
|
1749 |
+
$path=str_replace($abs,'...'.DIRECTORY_SEPARATOR,$path);
|
1750 |
+
$result=$iso->get_isolate_folder();
|
1751 |
+
?>
|
1752 |
+
<div class="postbox quickbackup-addon">
|
1753 |
+
<div style="margin-top: 10px;margin-bottom: 10px;">
|
1754 |
+
This tab displays the isolated images and their locations. You can choose to restore or delete specific isolated images.
|
1755 |
+
</div>
|
1756 |
+
<div style="margin-top: 10px;margin-bottom: 10px;">
|
1757 |
+
lsolated Folder Path: <a><?php echo $path?></a>
|
1758 |
+
</div>
|
1759 |
+
</div>
|
1760 |
+
<div class="postbox quickbackup-addon">
|
1761 |
+
<p>
|
1762 |
+
<input id="wpvivid_iso_list_search" type="search" name="s" value="" placeholder="Search">
|
1763 |
+
<select id="wpvivid_iso_list_folder" style="margin-top: -5px;">
|
1764 |
+
<option selected="selected" value="0">All Folders</option>
|
1765 |
+
<?php
|
1766 |
+
foreach ($result['folders'] as $folder)
|
1767 |
+
{
|
1768 |
+
echo "<option value='$folder'>$folder</option>";
|
1769 |
+
}
|
1770 |
+
?>
|
1771 |
+
</select>
|
1772 |
+
<input id="wpvivid_iso_list_search_btn" type="submit" class="button" value="Search">
|
1773 |
+
</p>
|
1774 |
+
</div>
|
1775 |
+
<div class="postbox">
|
1776 |
+
<div id="wpvivid_iso_files_list" style="margin: 10px;">
|
1777 |
+
<?php
|
1778 |
+
$files=$iso->get_isolate_files();
|
1779 |
+
$list = new WPvivid_Isolate_Files_List();
|
1780 |
+
|
1781 |
+
$list->set_list($files);
|
1782 |
+
$list->prepare_items();
|
1783 |
+
$list ->display();
|
1784 |
+
?>
|
1785 |
+
</div>
|
1786 |
+
</div>
|
1787 |
+
<script>
|
1788 |
+
var wpvivid_iso_list_search='';
|
1789 |
+
var wpvivid_iso_list_folder='';
|
1790 |
+
|
1791 |
+
jQuery('#wpvivid_iso_list_search_btn').click(function()
|
1792 |
+
{
|
1793 |
+
wpvivid_iso_list_search=jQuery('#wpvivid_iso_list_search').val();
|
1794 |
+
wpvivid_iso_list_folder=jQuery('#wpvivid_iso_list_folder').val();
|
1795 |
+
if(wpvivid_iso_list_folder=='0')
|
1796 |
+
{
|
1797 |
+
wpvivid_iso_list_folder='';
|
1798 |
+
}
|
1799 |
+
|
1800 |
+
if(wpvivid_iso_list_folder=='root')
|
1801 |
+
{
|
1802 |
+
wpvivid_iso_list_folder='.';
|
1803 |
+
}
|
1804 |
+
|
1805 |
+
wpvivid_get_iso_list('first');
|
1806 |
+
});
|
1807 |
+
|
1808 |
+
function wpvivid_get_iso_list(page)
|
1809 |
+
{
|
1810 |
+
var ajax_data = {
|
1811 |
+
'action': 'wpvivid_get_iso_list',
|
1812 |
+
'page':page,
|
1813 |
+
'search':wpvivid_iso_list_search,
|
1814 |
+
'folder':wpvivid_iso_list_folder
|
1815 |
+
};
|
1816 |
+
|
1817 |
+
wpvivid_post_request(ajax_data, function (data)
|
1818 |
+
{
|
1819 |
+
jQuery('#wpvivid_iso_files_list').html('');
|
1820 |
+
try
|
1821 |
+
{
|
1822 |
+
var jsonarray = jQuery.parseJSON(data);
|
1823 |
+
if (jsonarray.result === 'success')
|
1824 |
+
{
|
1825 |
+
jQuery('#wpvivid_iso_files_list').html(jsonarray.html);
|
1826 |
+
}
|
1827 |
+
else
|
1828 |
+
{
|
1829 |
+
alert(jsonarray.error);
|
1830 |
+
}
|
1831 |
+
}
|
1832 |
+
catch (err)
|
1833 |
+
{
|
1834 |
+
alert(err);
|
1835 |
+
}
|
1836 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1837 |
+
{
|
1838 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1839 |
+
alert(error_message);
|
1840 |
+
});
|
1841 |
+
}
|
1842 |
+
|
1843 |
+
jQuery('#wpvivid_iso_files_list').on("click",'.first-page',function()
|
1844 |
+
{
|
1845 |
+
wpvivid_get_iso_list('first');
|
1846 |
+
});
|
1847 |
+
|
1848 |
+
jQuery('#wpvivid_iso_files_list').on("click",'.prev-page',function()
|
1849 |
+
{
|
1850 |
+
var page=parseInt(jQuery(this).attr('value'));
|
1851 |
+
wpvivid_get_iso_list(page-1);
|
1852 |
+
});
|
1853 |
+
|
1854 |
+
jQuery('#wpvivid_iso_files_list').on("click",'.next-page',function()
|
1855 |
+
{
|
1856 |
+
var page=parseInt(jQuery(this).attr('value'));
|
1857 |
+
wpvivid_get_iso_list(page+1);
|
1858 |
+
});
|
1859 |
+
|
1860 |
+
jQuery('#wpvivid_iso_files_list').on("click",'.last-page',function()
|
1861 |
+
{
|
1862 |
+
wpvivid_get_iso_list('last');
|
1863 |
+
});
|
1864 |
+
|
1865 |
+
jQuery('#wpvivid_iso_files_list').on("keypress", '.current-page', function()
|
1866 |
+
{
|
1867 |
+
if(event.keyCode === 13){
|
1868 |
+
var page = jQuery(this).val();
|
1869 |
+
wpvivid_get_iso_list(page);
|
1870 |
+
}
|
1871 |
+
});
|
1872 |
+
|
1873 |
+
jQuery('#wpvivid_iso_files_list').on("click",'.action',function()
|
1874 |
+
{
|
1875 |
+
var selected=jQuery('#wpvivid_uc_iso_bulk_action').val();
|
1876 |
+
|
1877 |
+
if(selected=='wpvivid_delete_selected_image')
|
1878 |
+
{
|
1879 |
+
wpvivid_delete_selected_image();
|
1880 |
+
}
|
1881 |
+
else if(selected=='wpvivid_delete_list_image')
|
1882 |
+
{
|
1883 |
+
wpvivid_start_delete_all_image();
|
1884 |
+
}
|
1885 |
+
else if(selected=='wpvivid_restore_selected_image')
|
1886 |
+
{
|
1887 |
+
wpvivid_restore_selected_image();
|
1888 |
+
}
|
1889 |
+
else if(selected=='wpvivid_restore_list_image')
|
1890 |
+
{
|
1891 |
+
wpvivid_start_restore_all_image();
|
1892 |
+
}
|
1893 |
+
|
1894 |
+
});
|
1895 |
+
|
1896 |
+
function wpvivid_delete_selected_image()
|
1897 |
+
{
|
1898 |
+
var json = {};
|
1899 |
+
json['selected']=Array();
|
1900 |
+
jQuery('input[name=uploads][type=checkbox]').each(function(index, value)
|
1901 |
+
{
|
1902 |
+
if(jQuery(value).prop('checked'))
|
1903 |
+
{
|
1904 |
+
jQuery(value).closest('tr');
|
1905 |
+
var path = jQuery(this).closest('tr').attr('path');
|
1906 |
+
json['selected'].push(path)
|
1907 |
+
}
|
1908 |
+
});
|
1909 |
+
var selected= JSON.stringify(json);
|
1910 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', true);
|
1911 |
+
|
1912 |
+
var ajax_data = {
|
1913 |
+
'action': 'wpvivid_delete_selected_image',
|
1914 |
+
'selected':selected,
|
1915 |
+
'search':wpvivid_iso_list_search,
|
1916 |
+
'folder':wpvivid_iso_list_folder
|
1917 |
+
};
|
1918 |
+
wpvivid_post_request(ajax_data, function (data)
|
1919 |
+
{
|
1920 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
1921 |
+
|
1922 |
+
jQuery('#wpvivid_iso_files_list').html('');
|
1923 |
+
try
|
1924 |
+
{
|
1925 |
+
var jsonarray = jQuery.parseJSON(data);
|
1926 |
+
if (jsonarray.result === 'success')
|
1927 |
+
{
|
1928 |
+
jQuery('#wpvivid_iso_files_list').html(jsonarray.html);
|
1929 |
+
}
|
1930 |
+
else
|
1931 |
+
{
|
1932 |
+
alert(jsonarray.error);
|
1933 |
+
}
|
1934 |
+
}
|
1935 |
+
catch (err)
|
1936 |
+
{
|
1937 |
+
alert(err);
|
1938 |
+
}
|
1939 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1940 |
+
{
|
1941 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
1942 |
+
//jQuery('#wpvivid_delete_selected_image').prop('disabled', false);
|
1943 |
+
//jQuery('#wpvivid_delete_list_image').prop('disabled', false);
|
1944 |
+
//jQuery('#wpvivid_restore_selected_image').prop('disabled', false);
|
1945 |
+
//jQuery('#wpvivid_restore_list_image').prop('disabled', false);
|
1946 |
+
|
1947 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
1948 |
+
alert(error_message);
|
1949 |
+
});
|
1950 |
+
}
|
1951 |
+
|
1952 |
+
function wpvivid_start_delete_all_image()
|
1953 |
+
{
|
1954 |
+
var ajax_data = {
|
1955 |
+
'action': 'wpvivid_start_delete_all_image',
|
1956 |
+
'search':wpvivid_iso_list_search,
|
1957 |
+
'folder':wpvivid_iso_list_folder
|
1958 |
+
};
|
1959 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', true);
|
1960 |
+
|
1961 |
+
wpvivid_post_request(ajax_data, function (data)
|
1962 |
+
{
|
1963 |
+
try
|
1964 |
+
{
|
1965 |
+
var jsonarray = jQuery.parseJSON(data);
|
1966 |
+
if (jsonarray.result === 'success')
|
1967 |
+
{
|
1968 |
+
if(jsonarray.continue)
|
1969 |
+
{
|
1970 |
+
wpvivid_delete_all_image();
|
1971 |
+
}
|
1972 |
+
else
|
1973 |
+
{
|
1974 |
+
location.href = '<?php echo admin_url() . 'admin.php?page=' .apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner'). '&tab=isolate'?>';
|
1975 |
+
}
|
1976 |
+
}
|
1977 |
+
else if (jsonarray.result === 'failed')
|
1978 |
+
{
|
1979 |
+
alert(jsonarray.error);
|
1980 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
1981 |
+
}
|
1982 |
+
}
|
1983 |
+
catch(err)
|
1984 |
+
{
|
1985 |
+
alert(err);
|
1986 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
1987 |
+
//jQuery('#wpvivid_delete_selected_image').prop('disabled', false);
|
1988 |
+
//jQuery('#wpvivid_delete_list_image').prop('disabled', false);
|
1989 |
+
//jQuery('#wpvivid_restore_selected_image').prop('disabled', false);
|
1990 |
+
//jQuery('#wpvivid_restore_list_image').prop('disabled', false);
|
1991 |
+
}
|
1992 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
1993 |
+
{
|
1994 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
1995 |
+
//jQuery('#wpvivid_delete_selected_image').prop('disabled', false);
|
1996 |
+
//jQuery('#wpvivid_delete_list_image').prop('disabled', false);
|
1997 |
+
//jQuery('#wpvivid_restore_selected_image').prop('disabled', false);
|
1998 |
+
//jQuery('#wpvivid_restore_list_image').prop('disabled', false);
|
1999 |
+
|
2000 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
2001 |
+
alert(error_message);
|
2002 |
+
});
|
2003 |
+
}
|
2004 |
+
|
2005 |
+
function wpvivid_delete_all_image()
|
2006 |
+
{
|
2007 |
+
var ajax_data = {
|
2008 |
+
'action': 'wpvivid_delete_all_image',
|
2009 |
+
'search':wpvivid_iso_list_search,
|
2010 |
+
'folder':wpvivid_iso_list_folder
|
2011 |
+
};
|
2012 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', true);
|
2013 |
+
|
2014 |
+
wpvivid_post_request(ajax_data, function(data)
|
2015 |
+
{
|
2016 |
+
try
|
2017 |
+
{
|
2018 |
+
var jsonarray = jQuery.parseJSON(data);
|
2019 |
+
if (jsonarray.result === 'success')
|
2020 |
+
{
|
2021 |
+
if(jsonarray.continue)
|
2022 |
+
{
|
2023 |
+
wpvivid_delete_all_image();
|
2024 |
+
}
|
2025 |
+
else
|
2026 |
+
{
|
2027 |
+
location.href = '<?php echo admin_url() . 'admin.php?page=' .apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner'). '&tab=isolate'?>';
|
2028 |
+
}
|
2029 |
+
}
|
2030 |
+
else if (jsonarray.result === 'failed')
|
2031 |
+
{
|
2032 |
+
alert(jsonarray.error);
|
2033 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2034 |
+
}
|
2035 |
+
}
|
2036 |
+
catch(err)
|
2037 |
+
{
|
2038 |
+
alert(err);
|
2039 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2040 |
+
}
|
2041 |
+
|
2042 |
+
}, function(XMLHttpRequest, textStatus, errorThrown)
|
2043 |
+
{
|
2044 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
2045 |
+
alert(error_message);
|
2046 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2047 |
+
});
|
2048 |
+
}
|
2049 |
+
|
2050 |
+
function wpvivid_restore_selected_image()
|
2051 |
+
{
|
2052 |
+
var json = {};
|
2053 |
+
json['selected']=Array();
|
2054 |
+
jQuery('input[name=uploads][type=checkbox]').each(function(index, value)
|
2055 |
+
{
|
2056 |
+
if(jQuery(value).prop('checked'))
|
2057 |
+
{
|
2058 |
+
jQuery(value).closest('tr');
|
2059 |
+
var path = jQuery(this).closest('tr').attr('path');
|
2060 |
+
json['selected'].push(path)
|
2061 |
+
}
|
2062 |
+
});
|
2063 |
+
var selected= JSON.stringify(json);
|
2064 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', true);
|
2065 |
+
|
2066 |
+
var ajax_data = {
|
2067 |
+
'action': 'wpvivid_restore_selected_image',
|
2068 |
+
'selected':selected,
|
2069 |
+
'search':wpvivid_iso_list_search,
|
2070 |
+
'folder':wpvivid_iso_list_folder
|
2071 |
+
};
|
2072 |
+
wpvivid_post_request(ajax_data, function (data)
|
2073 |
+
{
|
2074 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2075 |
+
|
2076 |
+
jQuery('#wpvivid_iso_files_list').html('');
|
2077 |
+
try
|
2078 |
+
{
|
2079 |
+
|
2080 |
+
var jsonarray = jQuery.parseJSON(data);
|
2081 |
+
if (jsonarray.result === 'success')
|
2082 |
+
{
|
2083 |
+
jQuery('#wpvivid_iso_files_list').html(jsonarray.html);
|
2084 |
+
}
|
2085 |
+
else
|
2086 |
+
{
|
2087 |
+
alert(jsonarray.error);
|
2088 |
+
}
|
2089 |
+
}
|
2090 |
+
catch (err)
|
2091 |
+
{
|
2092 |
+
alert(err);
|
2093 |
+
}
|
2094 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
2095 |
+
{
|
2096 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2097 |
+
//jQuery('#wpvivid_delete_selected_image').prop('disabled', false);
|
2098 |
+
//jQuery('#wpvivid_delete_list_image').prop('disabled', false);
|
2099 |
+
//jQuery('#wpvivid_restore_selected_image').prop('disabled', false);
|
2100 |
+
//jQuery('#wpvivid_restore_list_image').prop('disabled', false);
|
2101 |
+
|
2102 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
2103 |
+
alert(error_message);
|
2104 |
+
});
|
2105 |
+
}
|
2106 |
+
|
2107 |
+
function wpvivid_start_restore_all_image()
|
2108 |
+
{
|
2109 |
+
var ajax_data = {
|
2110 |
+
'action': 'wpvivid_start_restore_all_image',
|
2111 |
+
'search':wpvivid_iso_list_search,
|
2112 |
+
'folder':wpvivid_iso_list_folder
|
2113 |
+
};
|
2114 |
+
wpvivid_post_request(ajax_data, function (data)
|
2115 |
+
{
|
2116 |
+
try
|
2117 |
+
{
|
2118 |
+
var jsonarray = jQuery.parseJSON(data);
|
2119 |
+
if (jsonarray.result === 'success')
|
2120 |
+
{
|
2121 |
+
if(jsonarray.continue)
|
2122 |
+
{
|
2123 |
+
wpvivid_restore_all_image();
|
2124 |
+
}
|
2125 |
+
else
|
2126 |
+
{
|
2127 |
+
location.href = '<?php echo admin_url() . 'admin.php?page=' .apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner'). '&tab=isolate'?>';
|
2128 |
+
}
|
2129 |
+
}
|
2130 |
+
else if (jsonarray.result === 'failed')
|
2131 |
+
{
|
2132 |
+
alert(jsonarray.error);
|
2133 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2134 |
+
}
|
2135 |
+
}
|
2136 |
+
catch(err)
|
2137 |
+
{
|
2138 |
+
alert(err);
|
2139 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2140 |
+
//jQuery('#wpvivid_delete_selected_image').prop('disabled', false);
|
2141 |
+
//jQuery('#wpvivid_delete_list_image').prop('disabled', false);
|
2142 |
+
//jQuery('#wpvivid_restore_selected_image').prop('disabled', false);
|
2143 |
+
//jQuery('#wpvivid_restore_list_image').prop('disabled', false);
|
2144 |
+
}
|
2145 |
+
}, function (XMLHttpRequest, textStatus, errorThrown)
|
2146 |
+
{
|
2147 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2148 |
+
//jQuery('#wpvivid_delete_selected_image').prop('disabled', false);
|
2149 |
+
//jQuery('#wpvivid_delete_list_image').prop('disabled', false);
|
2150 |
+
//jQuery('#wpvivid_restore_selected_image').prop('disabled', false);
|
2151 |
+
//jQuery('#wpvivid_restore_list_image').prop('disabled', false);
|
2152 |
+
|
2153 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
2154 |
+
alert(error_message);
|
2155 |
+
});
|
2156 |
+
}
|
2157 |
+
|
2158 |
+
function wpvivid_restore_all_image()
|
2159 |
+
{
|
2160 |
+
var ajax_data = {
|
2161 |
+
'action': 'wpvivid_restore_all_image',
|
2162 |
+
'search':wpvivid_iso_list_search,
|
2163 |
+
'folder':wpvivid_iso_list_folder
|
2164 |
+
};
|
2165 |
+
wpvivid_post_request(ajax_data, function(data)
|
2166 |
+
{
|
2167 |
+
try
|
2168 |
+
{
|
2169 |
+
var jsonarray = jQuery.parseJSON(data);
|
2170 |
+
if (jsonarray.result === 'success')
|
2171 |
+
{
|
2172 |
+
if(jsonarray.continue)
|
2173 |
+
{
|
2174 |
+
wpvivid_restore_all_image();
|
2175 |
+
}
|
2176 |
+
else
|
2177 |
+
{
|
2178 |
+
location.href = '<?php echo admin_url() . 'admin.php?page=' .apply_filters('wpvivid_white_label_plugin_name', 'wpvivid-cleaner'). '&tab=isolate'?>';
|
2179 |
+
}
|
2180 |
+
}
|
2181 |
+
else if (jsonarray.result === 'failed')
|
2182 |
+
{
|
2183 |
+
alert(jsonarray.error);
|
2184 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2185 |
+
//jQuery('#wpvivid_delete_selected_image').prop('disabled', false);
|
2186 |
+
//jQuery('#wpvivid_delete_list_image').prop('disabled', false);
|
2187 |
+
//jQuery('#wpvivid_restore_selected_image').prop('disabled', false);
|
2188 |
+
//jQuery('#wpvivid_restore_list_image').prop('disabled', false);
|
2189 |
+
}
|
2190 |
+
}
|
2191 |
+
catch(err)
|
2192 |
+
{
|
2193 |
+
alert(err);
|
2194 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2195 |
+
}
|
2196 |
+
|
2197 |
+
}, function(XMLHttpRequest, textStatus, errorThrown)
|
2198 |
+
{
|
2199 |
+
var error_message = wpvivid_output_ajaxerror('achieving backup', textStatus, errorThrown);
|
2200 |
+
alert(error_message);
|
2201 |
+
jQuery('#wpvivid_iso_files_list').find('.action').prop('disabled', false);
|
2202 |
+
//jQuery('#wpvivid_delete_selected_image').prop('disabled', false);
|
2203 |
+
//jQuery('#wpvivid_delete_list_image').prop('disabled', false);
|
2204 |
+
//jQuery('#wpvivid_restore_selected_image').prop('disabled', false);
|
2205 |
+
//jQuery('#wpvivid_restore_list_image').prop('disabled', false);
|
2206 |
+
});
|
2207 |
+
}
|
2208 |
+
</script>
|
2209 |
+
<?php
|
2210 |
+
}
|
2211 |
+
|
2212 |
+
public function output_database()
|
2213 |
+
{
|
2214 |
+
?>
|
2215 |
+
<div class="postbox quickbackup-addon">
|
2216 |
+
<h1>Coming soon</h1>
|
2217 |
+
</div>
|
2218 |
+
<?php
|
2219 |
+
}
|
2220 |
+
|
2221 |
+
public function start_scan_uploads_files_task()
|
2222 |
+
{
|
2223 |
+
set_time_limit(30);
|
2224 |
+
|
2225 |
+
$uploads_scanner=new WPvivid_Uploads_Scanner();
|
2226 |
+
$uploads_scanner->init_scan_task();
|
2227 |
+
$uploads_files=array();
|
2228 |
+
|
2229 |
+
$uploads_files[0]=$uploads_scanner->scan_sidebars_widgets();
|
2230 |
+
|
2231 |
+
$uploads_files[0]=$uploads_scanner->scan_termmeta_thumbnail();
|
2232 |
+
|
2233 |
+
$count=$uploads_scanner->get_post_count();
|
2234 |
+
|
2235 |
+
$start=0;
|
2236 |
+
$limit=min(get_option('wpvivid_uc_scan_limit',20),$count);
|
2237 |
+
|
2238 |
+
$posts=$uploads_scanner->get_posts($start,$limit);
|
2239 |
+
|
2240 |
+
|
2241 |
+
|
2242 |
+
foreach ($posts as $post)
|
2243 |
+
{
|
2244 |
+
$media=$uploads_scanner->get_media_from_post_content($post);
|
2245 |
+
//$uploads_files['post_id']=$post;
|
2246 |
+
//$uploads_files['uploads_files']=$media;
|
2247 |
+
//$uploads_files=array_merge($uploads_files,$media);
|
2248 |
+
|
2249 |
+
if(!empty($media))
|
2250 |
+
{
|
2251 |
+
$uploads_files[$post]=$media;
|
2252 |
+
}
|
2253 |
+
|
2254 |
+
$media=$uploads_scanner->get_media_from_post_meta($post);
|
2255 |
+
|
2256 |
+
if(!empty($media))
|
2257 |
+
{
|
2258 |
+
if(isset($uploads_files[$post]))
|
2259 |
+
$uploads_files[$post]=array_merge($uploads_files[$post],$media);
|
2260 |
+
else
|
2261 |
+
$uploads_files[$post]=$media;
|
2262 |
+
}
|
2263 |
+
//$uploads_ids=array_merge($uploads_ids,$media);
|
2264 |
+
}
|
2265 |
+
|
2266 |
+
$start+=$limit;
|
2267 |
+
|
2268 |
+
$result['result']='success';
|
2269 |
+
$result['percent']=intval(($start/$count)*100);
|
2270 |
+
$result['total_posts']=$start;
|
2271 |
+
$result['scanned_posts']=$count;
|
2272 |
+
$result['descript']='Scanning File from post';
|
2273 |
+
$result['progress_html']='
|
2274 |
+
<div class="action-progress-bar">
|
2275 |
+
<div class="action-progress-bar-percent" style="height:24px;width:' . $result['percent'] . '%"></div>
|
2276 |
+
</div>
|
2277 |
+
<div style="float:left;">
|
2278 |
+
<div class="backup-basic-info">
|
2279 |
+
<span class="wpvivid-element-space-right">' . __('Total Posts:', 'wpvivid-backuprestore') . '</span>
|
2280 |
+
<span>' . $result['total_posts'] . '</span>
|
2281 |
+
</div>
|
2282 |
+
<div class="backup-basic-info">
|
2283 |
+
<span class="wpvivid-element-space-right">' . __('Scanned:', 'wpvivid-backuprestore') . '</span>
|
2284 |
+
<span>' . $result['scanned_posts'] . '</span>
|
2285 |
+
</div>
|
2286 |
+
</div>
|
2287 |
+
<div style="clear:both;"></div>
|
2288 |
+
<div style="margin-left:10px; float: left; width:100%;">
|
2289 |
+
<p>' . $result['descript'] . '</p>
|
2290 |
+
</div>
|
2291 |
+
<div style="clear: both;"></div>
|
2292 |
+
<div>
|
2293 |
+
<div class="backup-log-btn">
|
2294 |
+
<input class="button-primary" id="wpvivid_uc_cancel" type="submit" value="' . esc_attr('Cancel', 'wpvivid-backuprestore') . '" />
|
2295 |
+
</div>
|
2296 |
+
</div>
|
2297 |
+
<div style="clear: both;"></div>';
|
2298 |
+
|
2299 |
+
if($start>=$count)
|
2300 |
+
{
|
2301 |
+
$uploads_scanner->update_scan_task($uploads_files,$start,'finished',100);
|
2302 |
+
$result['start']=$start;
|
2303 |
+
$result['status']='finished';
|
2304 |
+
$result['continue']=0;
|
2305 |
+
$result['log']='scan upload files finished'.PHP_EOL;
|
2306 |
+
}
|
2307 |
+
else
|
2308 |
+
{
|
2309 |
+
$uploads_scanner->update_scan_task($uploads_files,$start,'running');
|
2310 |
+
$result['start']=$start;
|
2311 |
+
$result['status']='running';
|
2312 |
+
$result['continue']=1;
|
2313 |
+
$result['log']='scanned posts:'.$start.PHP_EOL.'total posts:'.$count.PHP_EOL;
|
2314 |
+
}
|
2315 |
+
|
2316 |
+
|
2317 |
+
//$uploads_files=$uploads_scanner->get_files();
|
2318 |
+
//$result['count']=$count;
|
2319 |
+
//$result['files']=$uploads_files;
|
2320 |
+
|
2321 |
+
echo json_encode($result);
|
2322 |
+
die();
|
2323 |
+
}
|
2324 |
+
|
2325 |
+
public function scan_uploads_files_from_post()
|
2326 |
+
{
|
2327 |
+
set_time_limit(30);
|
2328 |
+
|
2329 |
+
$uploads_scanner=new WPvivid_Uploads_Scanner();
|
2330 |
+
|
2331 |
+
$count=$uploads_scanner->get_post_count();
|
2332 |
+
|
2333 |
+
$start=intval($_POST['start']);
|
2334 |
+
|
2335 |
+
$limit=min(get_option('wpvivid_uc_scan_limit',20),$count);
|
2336 |
+
|
2337 |
+
$posts=$uploads_scanner->get_posts($start,$limit);
|
2338 |
+
|
2339 |
+
$uploads_files=array();
|
2340 |
+
|
2341 |
+
foreach ($posts as $post)
|
2342 |
+
{
|
2343 |
+
$media=$uploads_scanner->get_media_from_post_content($post);
|
2344 |
+
//$uploads_files['post_id']=$post;
|
2345 |
+
//$uploads_files['uploads_files']=$media;
|
2346 |
+
//$uploads_files=array_merge($uploads_files,$media);
|
2347 |
+
|
2348 |
+
if(!empty($media))
|
2349 |
+
{
|
2350 |
+
$uploads_files[$post]=$media;
|
2351 |
+
}
|
2352 |
+
|
2353 |
+
$media=$uploads_scanner->get_media_from_post_meta($post);
|
2354 |
+
|
2355 |
+
if(!empty($media))
|
2356 |
+
{
|
2357 |
+
if(isset($uploads_files[$post]))
|
2358 |
+
$uploads_files[$post]=array_merge($uploads_files[$post],$media);
|
2359 |
+
else
|
2360 |
+
$uploads_files[$post]=$media;
|
2361 |
+
}
|
2362 |
+
|
2363 |
+
$media=$uploads_scanner->get_media_from_post_meta_elementor($post);
|
2364 |
+
|
2365 |
+
if(!empty($media))
|
2366 |
+
{
|
2367 |
+
if(isset($uploads_files[$post]))
|
2368 |
+
$uploads_files[$post]=array_merge($uploads_files[$post],$media);
|
2369 |
+
else
|
2370 |
+
$uploads_files[$post]=$media;
|
2371 |
+
}
|
2372 |
+
}
|
2373 |
+
|
2374 |
+
$start+=$limit;
|
2375 |
+
|
2376 |
+
$result['result']='success';
|
2377 |
+
$result['percent']=intval(($start/$count)*100);
|
2378 |
+
$result['total_posts']=$start;
|
2379 |
+
$result['scanned_posts']=$count;
|
2380 |
+
$result['descript']='Scanning File from post';
|
2381 |
+
$result['progress_html']='
|
2382 |
+
<div class="action-progress-bar">
|
2383 |
+
<div class="action-progress-bar-percent" style="height:24px;width:' . $result['percent'] . '%"></div>
|
2384 |
+
</div>
|
2385 |
+
<div style="float:left;">
|
2386 |
+
<div class="backup-basic-info">
|
2387 |
+
<span class="wpvivid-element-space-right">' . __('Total Posts:', 'wpvivid-backuprestore') . '</span>
|
2388 |
+
<span>' . $result['total_posts'] . '</span>
|
2389 |
+
</div>
|
2390 |
+
<div class="backup-basic-info">
|
2391 |
+
<span class="wpvivid-element-space-right">' . __('Scanned:', 'wpvivid-backuprestore') . '</span>
|
2392 |
+
<span>' . $result['scanned_posts'] . '</span>
|
2393 |
+
</div>
|
2394 |
+
</div>
|
2395 |
+
<div style="clear:both;"></div>
|
2396 |
+
<div style="margin-left:10px; float: left; width:100%;">
|
2397 |
+
<p>' . $result['descript'] . '</p>
|
2398 |
+
</div>
|
2399 |
+
<div style="clear: both;"></div>
|
2400 |
+
<div>
|
2401 |
+
<div class="backup-log-btn">
|
2402 |
+
<input class="button-primary" id="wpvivid_uc_cancel" type="submit" value="' . esc_attr('Cancel', 'wpvivid-backuprestore') . '" />
|
2403 |
+
</div>
|
2404 |
+
</div>
|
2405 |
+
<div style="clear: both;"></div>';
|
2406 |
+
|
2407 |
+
if($start>=$count)
|
2408 |
+
{
|
2409 |
+
$uploads_scanner->update_scan_task($uploads_files,$start,'finished',100);
|
2410 |
+
$result['start']=$start;
|
2411 |
+
$result['status']='finished';
|
2412 |
+
$result['continue']=0;
|
2413 |
+
$result['log']='scan upload files finished'.PHP_EOL;
|
2414 |
+
}
|
2415 |
+
else
|
2416 |
+
{
|
2417 |
+
$uploads_scanner->update_scan_task($uploads_files,$start,'running');
|
2418 |
+
$result['start']=$start;
|
2419 |
+
$result['status']='running';
|
2420 |
+
$result['continue']=1;
|
2421 |
+
$result['log']='scanned posts:'.$start.PHP_EOL.'total posts:'.$count.PHP_EOL;
|
2422 |
+
}
|
2423 |
+
|
2424 |
+
$ret=$uploads_scanner->get_unused_uploads_progress();
|
2425 |
+
$result['total_folders']=$ret['total_folders'];
|
2426 |
+
$result['scanned_folders']=$ret['scanned_folders'];
|
2427 |
+
$result['percent']=$ret['percent'];
|
2428 |
+
|
2429 |
+
echo json_encode($result);
|
2430 |
+
die();
|
2431 |
+
}
|
2432 |
+
|
2433 |
+
public function start_unused_files_task()
|
2434 |
+
{
|
2435 |
+
set_time_limit(30);
|
2436 |
+
|
2437 |
+
$uploads_scanner=new WPvivid_Uploads_Scanner();
|
2438 |
+
|
2439 |
+
$result=$uploads_scanner->get_folders();
|
2440 |
+
|
2441 |
+
$uploads_scanner->init_unused_uploads_task($result['folders']);
|
2442 |
+
|
2443 |
+
$files=array();
|
2444 |
+
foreach ($result['files'] as $file)
|
2445 |
+
{
|
2446 |
+
|
2447 |
+
if(!$uploads_scanner->is_uploads_files_exist($file))
|
2448 |
+
{
|
2449 |
+
$files[]=$file;
|
2450 |
+
}
|
2451 |
+
}
|
2452 |
+
|
2453 |
+
$uploads_scanner->update_unused_uploads_task($files,'.',1,0,'running',0,$result['size']);
|
2454 |
+
|
2455 |
+
$result['result']='success';
|
2456 |
+
$result['status']='running';
|
2457 |
+
$result['continue']=1;
|
2458 |
+
$result['log']='scanning files'.PHP_EOL;
|
2459 |
+
|
2460 |
+
$ret=$uploads_scanner->get_unused_uploads_progress();
|
2461 |
+
$result['total_folders']=$ret['total_folders'];
|
2462 |
+
$result['scanned_folders']=$ret['scanned_folders'];
|
2463 |
+
$result['percent']=$ret['percent'];
|
2464 |
+
$result['descript']='Scanning upload folder.';
|
2465 |
+
$result['progress_html']='
|
2466 |
+
<div class="action-progress-bar">
|
2467 |
+
<div class="action-progress-bar-percent" style="height:24px;width:' . $result['percent'] . '%"></div>
|
2468 |
+
</div>
|
2469 |
+
<div style="float:left;">
|
2470 |
+
<div class="backup-basic-info">
|
2471 |
+
<span class="wpvivid-element-space-right">' . __('Total Folders:', 'wpvivid-backuprestore') . '</span>
|
2472 |
+
<span>' . $result['total_folders'] . '</span>
|
2473 |
+
</div>
|
2474 |
+
<div class="backup-basic-info">
|
2475 |
+
<span class="wpvivid-element-space-right">' . __('Scanned:', 'wpvivid-backuprestore') . '</span>
|
2476 |
+
<span>' . $result['scanned_folders'] . '</span>
|
2477 |
+
</div>
|
2478 |
+
</div>
|
2479 |
+
<div style="clear:both;"></div>
|
2480 |
+
<div style="margin-left:10px; float: left; width:100%;">
|
2481 |
+
<p>' . $result['descript'] . '</p>
|
2482 |
+
</div>
|
2483 |
+
<div style="clear: both;"></div>
|
2484 |
+
<div>
|
2485 |
+
<div class="backup-log-btn">
|
2486 |
+
<input class="button-primary" id="wpvivid_uc_cancel" type="submit" value="' . esc_attr('Cancel', 'wpvivid-backuprestore') . '" />
|
2487 |
+
</div>
|
2488 |
+
</div>
|
2489 |
+
<div style="clear: both;"></div>';
|
2490 |
+
$result['.']=$files;
|
2491 |
+
echo json_encode($result);
|
2492 |
+
die();
|
2493 |
+
}
|
2494 |
+
|
2495 |
+
public function unused_files_task()
|
2496 |
+
{
|
2497 |
+
set_time_limit(30);
|
2498 |
+
|
2499 |
+
$uploads_scanner=new WPvivid_Uploads_Scanner();
|
2500 |
+
|
2501 |
+
$ret=$uploads_scanner->get_unfinished_folder();
|
2502 |
+
|
2503 |
+
if($ret===false)
|
2504 |
+
{
|
2505 |
+
$uploads_scanner->update_unused_uploads_task(array(),'.',1,0,'finished',100);
|
2506 |
+
$result['result']='success';
|
2507 |
+
$result['status']='finished';
|
2508 |
+
$result['log']='scanning files finished'.PHP_EOL;
|
2509 |
+
$result['percent']=100;
|
2510 |
+
$result['continue']=0;
|
2511 |
+
|
2512 |
+
}
|
2513 |
+
else
|
2514 |
+
{
|
2515 |
+
$size=0;
|
2516 |
+
$folder=$ret['folder'];
|
2517 |
+
$offset=$ret['offset'];
|
2518 |
+
$total=$ret['total'];
|
2519 |
+
$files=$uploads_scanner->get_files($folder);
|
2520 |
+
|
2521 |
+
$upload_folder = wp_upload_dir();
|
2522 |
+
|
2523 |
+
$root_path =$upload_folder['basedir'];
|
2524 |
+
|
2525 |
+
$start=0;
|
2526 |
+
$count=0;
|
2527 |
+
$limit=get_option('wpvivid_uc_files_limit',100);
|
2528 |
+
|
2529 |
+
$unused_files=array();
|
2530 |
+
foreach ($files as $file)
|
2531 |
+
{
|
2532 |
+
if($count>$limit)
|
2533 |
+
{
|
2534 |
+
$uploads_scanner->update_unused_uploads_task($unused_files,$folder,0,$start,'running',0,$size);
|
2535 |
+
|
2536 |
+
$result['result']='success';
|
2537 |
+
$result['status']='running';
|
2538 |
+
$result['continue']=1;
|
2539 |
+
$task=get_option('unused_uploads_task',array());
|
2540 |
+
$result['task']=$task;
|
2541 |
+
$result[$folder]=$unused_files;
|
2542 |
+
$result['log']='scanning folder '.$folder.PHP_EOL.'scanned files:'.$start.PHP_EOL;
|
2543 |
+
$ret=$uploads_scanner->get_unused_uploads_progress();
|
2544 |
+
$result['total_folders']=$ret['total_folders'];
|
2545 |
+
$result['scanned_folders']=$ret['scanned_folders'];
|
2546 |
+
$result['percent']=$ret['percent'];
|
2547 |
+
|
2548 |
+
$result['descript']='Scanning upload folder:'.$folder.'<br>'.$start.' files have been scanned in '.$total.' files';
|
2549 |
+
$result['progress_html']='
|
2550 |
+
<div class="action-progress-bar">
|
2551 |
+
<div class="action-progress-bar-percent" style="height:24px;width:' . $result['percent'] . '%"></div>
|
2552 |
+
</div>
|
2553 |
+
<div style="float:left;">
|
2554 |
+
<div class="backup-basic-info">
|
2555 |
+
<span class="wpvivid-element-space-right">' . __('Total Folders:', 'wpvivid-backuprestore') . '</span>
|
2556 |
+
<span>' . $result['total_folders'] . '</span>
|
2557 |
+
</div>
|
2558 |
+
<div class="backup-basic-info">
|
2559 |
+
<span class="wpvivid-element-space-right">' . __('Scanned:', 'wpvivid-backuprestore') . '</span>
|
2560 |
+
<span>' . $result['scanned_folders'] . '</span>
|
2561 |
+
</div>
|
2562 |
+
</div>
|
2563 |
+
<div style="clear:both;"></div>
|
2564 |
+
<div style="margin-left:10px; float: left; width:100%;">
|
2565 |
+
<p>' . $result['descript'] . '</p>
|
2566 |
+
</div>
|
2567 |
+
<div style="clear: both;"></div>
|
2568 |
+
<div>
|
2569 |
+
<div class="backup-log-btn">
|
2570 |
+
<input class="button-primary" id="wpvivid_uc_cancel" type="submit" value="' . esc_attr('Cancel', 'wpvivid-backuprestore') . '" />
|
2571 |
+
</div>
|
2572 |
+
</div>
|
2573 |
+
<div style="clear: both;"></div>';
|
2574 |
+
echo json_encode($result);
|
2575 |
+
die();
|
2576 |
+
}
|
2577 |
+
|
2578 |
+
if($start>=$offset)
|
2579 |
+
{
|
2580 |
+
if(!$uploads_scanner->is_uploads_files_exist($file))
|
2581 |
+
{
|
2582 |
+
$unused_files[]=$file;
|
2583 |
+
$size+=filesize($root_path.DIRECTORY_SEPARATOR . $file);
|
2584 |
+
}
|
2585 |
+
$count++;
|
2586 |
+
}
|
2587 |
+
$start++;
|
2588 |
+
}
|
2589 |
+
|
2590 |
+
$uploads_scanner->update_unused_uploads_task($unused_files,$folder,1,0,'running',0,$size);
|
2591 |
+
|
2592 |
+
$result['result']='success';
|
2593 |
+
$result['status']='running';
|
2594 |
+
$result['continue']=1;
|
2595 |
+
$result[$folder]=$unused_files;
|
2596 |
+
$result['log']='scanning folder '.$folder.PHP_EOL.'scanned files:'.$start.PHP_EOL;
|
2597 |
+
$ret=$uploads_scanner->get_unused_uploads_progress();
|
2598 |
+
$result['total_folders']=$ret['total_folders'];
|
2599 |
+
$result['scanned_folders']=$ret['scanned_folders'];
|
2600 |
+
$result['percent']=$ret['percent'];
|
2601 |
+
|
2602 |
+
$upload_folder = wp_upload_dir();
|
2603 |
+
|
2604 |
+
$result['descript']='Scanning upload folder:'.$folder.'<br>'.$start.' files have been scanned in '.$total.' files';
|
2605 |
+
$result['progress_html']='
|
2606 |
+
<div class="action-progress-bar">
|
2607 |
+
<div class="action-progress-bar-percent" style="height:24px;width:' . $result['percent'] . '%"></div>
|
2608 |
+
</div>
|
2609 |
+
<div style="float:left;">
|
2610 |
+
<div class="backup-basic-info">
|
2611 |
+
<span class="wpvivid-element-space-right">' . __('Total Folders:', 'wpvivid-backuprestore') . '</span>
|
2612 |
+
<span>' . $result['total_folders'] . '</span>
|
2613 |
+
</div>
|
2614 |
+
<div class="backup-basic-info">
|
2615 |
+
<span class="wpvivid-element-space-right">' . __('Scanned:', 'wpvivid-backuprestore') . '</span>
|
2616 |
+
<span>' . $result['scanned_folders'] . '</span>
|
2617 |
+
</div>
|
2618 |
+
</div>
|
2619 |
+
<div style="clear:both;"></div>
|
2620 |
+
<div style="margin-left:10px; float: left; width:100%;">
|
2621 |
+
<p>' . $result['descript'] . '</p>
|
2622 |
+
</div>
|
2623 |
+
<div style="clear: both;"></div>
|
2624 |
+
<div>
|
2625 |
+
<div class="backup-log-btn">
|
2626 |
+
<input class="button-primary" id="wpvivid_uc_cancel" type="submit" value="' . esc_attr('Cancel', 'wpvivid-backuprestore') . '" />
|
2627 |
+
</div>
|
2628 |
+
</div>
|
2629 |
+
<div style="clear: both;"></div>';
|
2630 |
+
}
|
2631 |
+
echo json_encode($result);
|
2632 |
+
die();
|
2633 |
+
}
|
2634 |
+
|
2635 |
+
public function scan_post_types($post_types)
|
2636 |
+
{
|
2637 |
+
$default_post_types=array();
|
2638 |
+
$default_post_types[]='attachment';
|
2639 |
+
$default_post_types[]='revision';
|
2640 |
+
$default_post_types[]='auto-draft';
|
2641 |
+
$default_post_types[]='nav_menu_item';
|
2642 |
+
$default_post_types[]='shop_order';
|
2643 |
+
$default_post_types[]='shop_order_refund';
|
2644 |
+
$default_post_types[]='oembed_cache';
|
2645 |
+
$post_types=get_option('wpvivid_uc_post_types',$default_post_types);
|
2646 |
+
return $post_types;
|
2647 |
+
}
|
2648 |
+
|
2649 |
+
public function scan_exclude_files_regex($regex)
|
2650 |
+
{
|
2651 |
+
$files=get_option('wpvivid_uc_exclude_files_regex',array());
|
2652 |
+
if(empty($files))
|
2653 |
+
{
|
2654 |
+
return $regex;
|
2655 |
+
}
|
2656 |
+
foreach ($files as $file)
|
2657 |
+
{
|
2658 |
+
$regex[]='#'.$file.'$#';
|
2659 |
+
}
|
2660 |
+
return $regex;
|
2661 |
+
}
|
2662 |
+
|
2663 |
+
public function scan_include_files_regex($regex)
|
2664 |
+
{
|
2665 |
+
$default_file_types=array();
|
2666 |
+
$default_file_types[]='png';
|
2667 |
+
$default_file_types[]='jpg';
|
2668 |
+
$default_file_types[]='jpeg';
|
2669 |
+
$scan_file_types=get_option('wpvivid_uc_scan_file_types',$default_file_types);
|
2670 |
+
|
2671 |
+
$regex=array();
|
2672 |
+
foreach ($scan_file_types as $scan_file_type)
|
2673 |
+
{
|
2674 |
+
$regex[]='#.*\.'.$scan_file_type.'#';
|
2675 |
+
}
|
2676 |
+
|
2677 |
+
return $regex;
|
2678 |
+
}
|
2679 |
+
|
2680 |
+
public function add_exclude_files()
|
2681 |
+
{
|
2682 |
+
$json = $_POST['selected'];
|
2683 |
+
$json = stripslashes($json);
|
2684 |
+
$json = json_decode($json, true);
|
2685 |
+
|
2686 |
+
$selected_list=$json['selected'];
|
2687 |
+
|
2688 |
+
$scanner=new WPvivid_Uploads_Scanner();
|
2689 |
+
$files=$scanner->get_selected_files_list($selected_list);
|
2690 |
+
|
2691 |
+
$list=new WPvivid_Unused_Upload_Files_List();
|
2692 |
+
|
2693 |
+
if($files===false||empty($files))
|
2694 |
+
{
|
2695 |
+
|
2696 |
+
}
|
2697 |
+
else
|
2698 |
+
{
|
2699 |
+
$options=get_option('wpvivid_uc_exclude_files_regex',array());
|
2700 |
+
|
2701 |
+
$options=array_merge($files,$options);
|
2702 |
+
|
2703 |
+
update_option('wpvivid_uc_exclude_files_regex',$options);
|
2704 |
+
|
2705 |
+
$scanner->delete_selected_files_list($selected_list);
|
2706 |
+
}
|
2707 |
+
|
2708 |
+
|
2709 |
+
$search='';
|
2710 |
+
if(isset($_POST['search']))
|
2711 |
+
{
|
2712 |
+
$search=$_POST['search'];
|
2713 |
+
}
|
2714 |
+
|
2715 |
+
$folder='';
|
2716 |
+
if(isset($_POST['folder']))
|
2717 |
+
{
|
2718 |
+
$folder=$_POST['folder'];
|
2719 |
+
}
|
2720 |
+
|
2721 |
+
$result=$scanner->get_scan_result($search,$folder);
|
2722 |
+
|
2723 |
+
$list->set_list($result);
|
2724 |
+
|
2725 |
+
$list->prepare_items();
|
2726 |
+
ob_start();
|
2727 |
+
$list->display();
|
2728 |
+
$html = ob_get_clean();
|
2729 |
+
|
2730 |
+
$ret['result']='success';
|
2731 |
+
$ret['html']=$html;
|
2732 |
+
echo json_encode($ret);
|
2733 |
+
die();
|
2734 |
+
}
|
2735 |
+
|
2736 |
+
public function get_result_list()
|
2737 |
+
{
|
2738 |
+
try
|
2739 |
+
{
|
2740 |
+
$search='';
|
2741 |
+
if(isset($_POST['search']))
|
2742 |
+
{
|
2743 |
+
$search=$_POST['search'];
|
2744 |
+
}
|
2745 |
+
|
2746 |
+
$folder='';
|
2747 |
+
if(isset($_POST['folder']))
|
2748 |
+
{
|
2749 |
+
$folder=$_POST['folder'];
|
2750 |
+
}
|
2751 |
+
|
2752 |
+
$list=new WPvivid_Unused_Upload_Files_List();
|
2753 |
+
$scanner=new WPvivid_Uploads_Scanner();
|
2754 |
+
$result=$scanner->get_scan_result($search,$folder);
|
2755 |
+
if(isset($_POST['page']))
|
2756 |
+
{
|
2757 |
+
$list->set_list($result,$_POST['page']);
|
2758 |
+
}
|
2759 |
+
else
|
2760 |
+
{
|
2761 |
+
$list->set_list($result);
|
2762 |
+
}
|
2763 |
+
|
2764 |
+
$list->prepare_items();
|
2765 |
+
ob_start();
|
2766 |
+
$list->display();
|
2767 |
+
$html = ob_get_clean();
|
2768 |
+
|
2769 |
+
$ret['result']='success';
|
2770 |
+
$ret['html']=$html;
|
2771 |
+
echo json_encode($ret);
|
2772 |
+
}
|
2773 |
+
catch (Exception $error)
|
2774 |
+
{
|
2775 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2776 |
+
error_log($message);
|
2777 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2778 |
+
}
|
2779 |
+
die();
|
2780 |
+
}
|
2781 |
+
|
2782 |
+
public function isolate_selected_image()
|
2783 |
+
{
|
2784 |
+
try
|
2785 |
+
{
|
2786 |
+
$json = $_POST['selected'];
|
2787 |
+
$json = stripslashes($json);
|
2788 |
+
$json = json_decode($json, true);
|
2789 |
+
|
2790 |
+
$selected_list=$json['selected'];
|
2791 |
+
|
2792 |
+
$scanner=new WPvivid_Uploads_Scanner();
|
2793 |
+
$files=$scanner->get_selected_files_list($selected_list);
|
2794 |
+
|
2795 |
+
if($files===false||empty($files))
|
2796 |
+
{
|
2797 |
+
|
2798 |
+
}
|
2799 |
+
else
|
2800 |
+
{
|
2801 |
+
$iso=new WPvivid_Isolate_Files();
|
2802 |
+
$result=$iso->isolate_files($files);
|
2803 |
+
|
2804 |
+
if($result['result']=='success')
|
2805 |
+
{
|
2806 |
+
$scanner->delete_selected_files_list($selected_list);
|
2807 |
+
}
|
2808 |
+
else
|
2809 |
+
{
|
2810 |
+
echo json_encode($result);
|
2811 |
+
die();
|
2812 |
+
}
|
2813 |
+
}
|
2814 |
+
|
2815 |
+
|
2816 |
+
$search='';
|
2817 |
+
if(isset($_POST['search']))
|
2818 |
+
{
|
2819 |
+
$search=$_POST['search'];
|
2820 |
+
}
|
2821 |
+
|
2822 |
+
$folder='';
|
2823 |
+
if(isset($_POST['folder']))
|
2824 |
+
{
|
2825 |
+
$folder=$_POST['folder'];
|
2826 |
+
}
|
2827 |
+
|
2828 |
+
$list=new WPvivid_Unused_Upload_Files_List();
|
2829 |
+
$scanner=new WPvivid_Uploads_Scanner();
|
2830 |
+
$result=$scanner->get_scan_result($search,$folder);
|
2831 |
+
|
2832 |
+
$list->set_list($result);
|
2833 |
+
|
2834 |
+
$list->prepare_items();
|
2835 |
+
ob_start();
|
2836 |
+
$list->display();
|
2837 |
+
$html = ob_get_clean();
|
2838 |
+
|
2839 |
+
$ret['result']='success';
|
2840 |
+
$ret['html']=$html;
|
2841 |
+
|
2842 |
+
$list=new WPvivid_Isolate_Files_List();
|
2843 |
+
$iso=new WPvivid_Isolate_Files();
|
2844 |
+
$result=$iso->get_isolate_files($search,'');
|
2845 |
+
if(isset($_POST['page']))
|
2846 |
+
{
|
2847 |
+
$list->set_list($result,$_POST['page']);
|
2848 |
+
}
|
2849 |
+
else
|
2850 |
+
{
|
2851 |
+
$list->set_list($result);
|
2852 |
+
}
|
2853 |
+
|
2854 |
+
$list->prepare_items();
|
2855 |
+
ob_start();
|
2856 |
+
$list->display();
|
2857 |
+
$iso = ob_get_clean();
|
2858 |
+
$ret['iso']=$iso;
|
2859 |
+
echo json_encode($ret);
|
2860 |
+
}
|
2861 |
+
catch (Exception $error)
|
2862 |
+
{
|
2863 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2864 |
+
error_log($message);
|
2865 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2866 |
+
}
|
2867 |
+
die();
|
2868 |
+
}
|
2869 |
+
|
2870 |
+
public function start_isolate_all_image()
|
2871 |
+
{
|
2872 |
+
try
|
2873 |
+
{
|
2874 |
+
$search='';
|
2875 |
+
if(isset($_POST['search']))
|
2876 |
+
{
|
2877 |
+
$search=$_POST['search'];
|
2878 |
+
}
|
2879 |
+
|
2880 |
+
$folder='';
|
2881 |
+
if(isset($_POST['folder']))
|
2882 |
+
{
|
2883 |
+
$folder=$_POST['folder'];
|
2884 |
+
}
|
2885 |
+
|
2886 |
+
$iso=new WPvivid_Isolate_Files();
|
2887 |
+
$scanner=new WPvivid_Uploads_Scanner();
|
2888 |
+
|
2889 |
+
$offset=0;
|
2890 |
+
$count=100;
|
2891 |
+
|
2892 |
+
$iso->init_isolate_task();
|
2893 |
+
$files=$scanner->get_all_files_list($search,$folder,$offset,$count);
|
2894 |
+
|
2895 |
+
if($files===false||empty($files))
|
2896 |
+
{
|
2897 |
+
$iso->update_isolate_task(0,'finished',100);
|
2898 |
+
|
2899 |
+
$result['result']='success';
|
2900 |
+
$result['status']='finished';
|
2901 |
+
$result['continue']=0;
|
2902 |
+
|
2903 |
+
echo json_encode($result);
|
2904 |
+
die();
|
2905 |
+
}
|
2906 |
+
else
|
2907 |
+
{
|
2908 |
+
$offset+=$count;
|
2909 |
+
$result=$iso->isolate_files($files);
|
2910 |
+
|
2911 |
+
$scanner->delete_all_files_list($search,$folder,$count);
|
2912 |
+
|
2913 |
+
if($result['result']=='success')
|
2914 |
+
{
|
2915 |
+
$iso->update_isolate_task($offset);
|
2916 |
+
}
|
2917 |
+
else
|
2918 |
+
{
|
2919 |
+
echo json_encode($result);
|
2920 |
+
die();
|
2921 |
+
}
|
2922 |
+
}
|
2923 |
+
|
2924 |
+
$ret['result']='success';
|
2925 |
+
$ret['status']='running';
|
2926 |
+
$ret['continue']=1;
|
2927 |
+
echo json_encode($ret);
|
2928 |
+
die();
|
2929 |
+
}
|
2930 |
+
catch (Exception $error)
|
2931 |
+
{
|
2932 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
2933 |
+
error_log($message);
|
2934 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
2935 |
+
}
|
2936 |
+
die();
|
2937 |
+
}
|
2938 |
+
|
2939 |
+
public function isolate_all_image()
|
2940 |
+
{
|
2941 |
+
try
|
2942 |
+
{
|
2943 |
+
$search='';
|
2944 |
+
if(isset($_POST['search']))
|
2945 |
+
{
|
2946 |
+
$search=$_POST['search'];
|
2947 |
+
}
|
2948 |
+
|
2949 |
+
$folder='';
|
2950 |
+
if(isset($_POST['folder']))
|
2951 |
+
{
|
2952 |
+
$folder=$_POST['folder'];
|
2953 |
+
}
|
2954 |
+
|
2955 |
+
$iso=new WPvivid_Isolate_Files();
|
2956 |
+
$scanner=new WPvivid_Uploads_Scanner();
|
2957 |
+
|
2958 |
+
$offset=$iso->get_isolate_task_offset();
|
2959 |
+
|
2960 |
+
if($offset===false)
|
2961 |
+
{
|
2962 |
+
$result['result']='success';
|
2963 |
+
$result['status']='finished';
|
2964 |
+
$result['continue']=0;
|
2965 |
+
|
2966 |
+
echo json_encode($result);
|
2967 |
+
die();
|
2968 |
+
}
|
2969 |
+
$start=0;
|
2970 |
+
$count=100;
|
2971 |
+
$files=$scanner->get_all_files_list($search,$folder,$start,$count);
|
2972 |
+
|
2973 |
+
if($files===false||empty($files))
|
2974 |
+
{
|
2975 |
+
$iso->update_isolate_task(0,'finished',100);
|
2976 |
+
|
2977 |
+
$result['result']='success';
|
2978 |
+
$result['status']='finished';
|
2979 |
+
$result['continue']=0;
|
2980 |
+
|
2981 |
+
echo json_encode($result);
|
2982 |
+
die();
|
2983 |
+
}
|
2984 |
+
else
|
2985 |
+
{
|
2986 |
+
$offset+=$count;
|
2987 |
+
$result=$iso->isolate_files($files);
|
2988 |
+
$scanner->delete_all_files_list($search,$folder,$count);
|
2989 |
+
|
2990 |
+
if($result['result']=='success')
|
2991 |
+
{
|
2992 |
+
$iso->update_isolate_task($offset);
|
2993 |
+
}
|
2994 |
+
else
|
2995 |
+
{
|
2996 |
+
echo json_encode($result);
|
2997 |
+
die();
|
2998 |
+
}
|
2999 |
+
}
|
3000 |
+
|
3001 |
+
$ret['result']='success';
|
3002 |
+
$ret['status']='running';
|
3003 |
+
$ret['continue']=1;
|
3004 |
+
echo json_encode($ret);
|
3005 |
+
die();
|
3006 |
+
}
|
3007 |
+
catch (Exception $error)
|
3008 |
+
{
|
3009 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3010 |
+
error_log($message);
|
3011 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3012 |
+
}
|
3013 |
+
die();
|
3014 |
+
}
|
3015 |
+
|
3016 |
+
public function get_iso_list()
|
3017 |
+
{
|
3018 |
+
try
|
3019 |
+
{
|
3020 |
+
$search='';
|
3021 |
+
if(isset($_POST['search']))
|
3022 |
+
{
|
3023 |
+
$search=$_POST['search'];
|
3024 |
+
}
|
3025 |
+
|
3026 |
+
$folder='';
|
3027 |
+
if(isset($_POST['folder']))
|
3028 |
+
{
|
3029 |
+
$folder=$_POST['folder'];
|
3030 |
+
}
|
3031 |
+
|
3032 |
+
$folder = str_replace('\\\\', '\\', $folder);
|
3033 |
+
|
3034 |
+
$list=new WPvivid_Isolate_Files_List();
|
3035 |
+
$iso=new WPvivid_Isolate_Files();
|
3036 |
+
$result=$iso->get_isolate_files($search,$folder);
|
3037 |
+
if(isset($_POST['page']))
|
3038 |
+
{
|
3039 |
+
$list->set_list($result,$_POST['page']);
|
3040 |
+
}
|
3041 |
+
else
|
3042 |
+
{
|
3043 |
+
$list->set_list($result);
|
3044 |
+
}
|
3045 |
+
|
3046 |
+
$list->prepare_items();
|
3047 |
+
ob_start();
|
3048 |
+
$list->display();
|
3049 |
+
$html = ob_get_clean();
|
3050 |
+
|
3051 |
+
$ret['result']='success';
|
3052 |
+
$ret['html']=$html;
|
3053 |
+
echo json_encode($ret);
|
3054 |
+
}
|
3055 |
+
catch (Exception $error)
|
3056 |
+
{
|
3057 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3058 |
+
error_log($message);
|
3059 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3060 |
+
}
|
3061 |
+
die();
|
3062 |
+
}
|
3063 |
+
|
3064 |
+
public function delete_selected_image()
|
3065 |
+
{
|
3066 |
+
try
|
3067 |
+
{
|
3068 |
+
$json = $_POST['selected'];
|
3069 |
+
$json = stripslashes($json);
|
3070 |
+
$json = json_decode($json, true);
|
3071 |
+
|
3072 |
+
$files=$json['selected'];
|
3073 |
+
|
3074 |
+
$iso=new WPvivid_Isolate_Files();
|
3075 |
+
|
3076 |
+
$iso->delete_files($files);
|
3077 |
+
|
3078 |
+
$search='';
|
3079 |
+
if(isset($_POST['search']))
|
3080 |
+
{
|
3081 |
+
$search=$_POST['search'];
|
3082 |
+
}
|
3083 |
+
|
3084 |
+
$folder='';
|
3085 |
+
if(isset($_POST['folder']))
|
3086 |
+
{
|
3087 |
+
$folder=$_POST['folder'];
|
3088 |
+
}
|
3089 |
+
|
3090 |
+
$folder = str_replace('\\\\', '\\', $folder);
|
3091 |
+
|
3092 |
+
$list=new WPvivid_Isolate_Files_List();
|
3093 |
+
$iso=new WPvivid_Isolate_Files();
|
3094 |
+
$result=$iso->get_isolate_files($search,$folder);
|
3095 |
+
if(isset($_POST['page']))
|
3096 |
+
{
|
3097 |
+
$list->set_list($result,$_POST['page']);
|
3098 |
+
}
|
3099 |
+
else
|
3100 |
+
{
|
3101 |
+
$list->set_list($result);
|
3102 |
+
}
|
3103 |
+
|
3104 |
+
$list->prepare_items();
|
3105 |
+
ob_start();
|
3106 |
+
$list->display();
|
3107 |
+
$html = ob_get_clean();
|
3108 |
+
|
3109 |
+
$ret['result']='success';
|
3110 |
+
$ret['html']=$html;
|
3111 |
+
echo json_encode($ret);
|
3112 |
+
}
|
3113 |
+
catch (Exception $error)
|
3114 |
+
{
|
3115 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3116 |
+
error_log($message);
|
3117 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3118 |
+
}
|
3119 |
+
die();
|
3120 |
+
}
|
3121 |
+
|
3122 |
+
public function delete_all_image()
|
3123 |
+
{
|
3124 |
+
try
|
3125 |
+
{
|
3126 |
+
$search='';
|
3127 |
+
if(isset($_POST['search']))
|
3128 |
+
{
|
3129 |
+
$search=$_POST['search'];
|
3130 |
+
}
|
3131 |
+
|
3132 |
+
$folder='';
|
3133 |
+
if(isset($_POST['folder']))
|
3134 |
+
{
|
3135 |
+
$folder=$_POST['folder'];
|
3136 |
+
}
|
3137 |
+
|
3138 |
+
$iso=new WPvivid_Isolate_Files();
|
3139 |
+
|
3140 |
+
$count=1000;
|
3141 |
+
|
3142 |
+
$files=$iso->get_isolate_files($search,$folder,$count);
|
3143 |
+
|
3144 |
+
if($files===false||empty($files))
|
3145 |
+
{
|
3146 |
+
$result['result']='success';
|
3147 |
+
$result['status']='finished';
|
3148 |
+
$result['continue']=0;
|
3149 |
+
|
3150 |
+
echo json_encode($result);
|
3151 |
+
die();
|
3152 |
+
}
|
3153 |
+
else
|
3154 |
+
{
|
3155 |
+
$iso->delete_files_ex($files);
|
3156 |
+
}
|
3157 |
+
|
3158 |
+
$ret['result']='success';
|
3159 |
+
$ret['status']='running';
|
3160 |
+
$ret['continue']=1;
|
3161 |
+
echo json_encode($ret);
|
3162 |
+
die();
|
3163 |
+
}
|
3164 |
+
catch (Exception $error)
|
3165 |
+
{
|
3166 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3167 |
+
error_log($message);
|
3168 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3169 |
+
}
|
3170 |
+
die();
|
3171 |
+
}
|
3172 |
+
|
3173 |
+
//restore_selected_image
|
3174 |
+
public function restore_selected_image()
|
3175 |
+
{
|
3176 |
+
try
|
3177 |
+
{
|
3178 |
+
$json = $_POST['selected'];
|
3179 |
+
$json = stripslashes($json);
|
3180 |
+
$json = json_decode($json, true);
|
3181 |
+
|
3182 |
+
$files=$json['selected'];
|
3183 |
+
|
3184 |
+
$iso=new WPvivid_Isolate_Files();
|
3185 |
+
$iso->restore_files($files);
|
3186 |
+
|
3187 |
+
$search='';
|
3188 |
+
if(isset($_POST['search']))
|
3189 |
+
{
|
3190 |
+
$search=$_POST['search'];
|
3191 |
+
}
|
3192 |
+
|
3193 |
+
$folder='';
|
3194 |
+
if(isset($_POST['folder']))
|
3195 |
+
{
|
3196 |
+
$folder=$_POST['folder'];
|
3197 |
+
}
|
3198 |
+
|
3199 |
+
$folder = str_replace('\\\\', '\\', $folder);
|
3200 |
+
|
3201 |
+
$list=new WPvivid_Isolate_Files_List();
|
3202 |
+
$iso=new WPvivid_Isolate_Files();
|
3203 |
+
$result=$iso->get_isolate_files($search,$folder);
|
3204 |
+
if(isset($_POST['page']))
|
3205 |
+
{
|
3206 |
+
$list->set_list($result,$_POST['page']);
|
3207 |
+
}
|
3208 |
+
else
|
3209 |
+
{
|
3210 |
+
$list->set_list($result);
|
3211 |
+
}
|
3212 |
+
|
3213 |
+
$list->prepare_items();
|
3214 |
+
ob_start();
|
3215 |
+
$list->display();
|
3216 |
+
$html = ob_get_clean();
|
3217 |
+
|
3218 |
+
$ret['result']='success';
|
3219 |
+
$ret['html']=$html;
|
3220 |
+
echo json_encode($ret);
|
3221 |
+
}
|
3222 |
+
catch (Exception $error)
|
3223 |
+
{
|
3224 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3225 |
+
error_log($message);
|
3226 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3227 |
+
}
|
3228 |
+
die();
|
3229 |
+
}
|
3230 |
+
|
3231 |
+
public function restore_all_image()
|
3232 |
+
{
|
3233 |
+
try
|
3234 |
+
{
|
3235 |
+
$search='';
|
3236 |
+
if(isset($_POST['search']))
|
3237 |
+
{
|
3238 |
+
$search=$_POST['search'];
|
3239 |
+
}
|
3240 |
+
|
3241 |
+
$folder='';
|
3242 |
+
if(isset($_POST['folder']))
|
3243 |
+
{
|
3244 |
+
$folder=$_POST['folder'];
|
3245 |
+
}
|
3246 |
+
|
3247 |
+
$iso=new WPvivid_Isolate_Files();
|
3248 |
+
|
3249 |
+
$count=100;
|
3250 |
+
|
3251 |
+
$files=$iso->get_isolate_files($search,$folder,$count);
|
3252 |
+
|
3253 |
+
if($files===false||empty($files))
|
3254 |
+
{
|
3255 |
+
$result['result']='success';
|
3256 |
+
$result['status']='finished';
|
3257 |
+
$result['continue']=0;
|
3258 |
+
|
3259 |
+
echo json_encode($result);
|
3260 |
+
die();
|
3261 |
+
}
|
3262 |
+
else
|
3263 |
+
{
|
3264 |
+
$iso->restore_files_ex($files);
|
3265 |
+
}
|
3266 |
+
|
3267 |
+
$ret['result']='success';
|
3268 |
+
$ret['status']='running';
|
3269 |
+
$ret['continue']=1;
|
3270 |
+
echo json_encode($ret);
|
3271 |
+
die();
|
3272 |
+
}
|
3273 |
+
catch (Exception $error)
|
3274 |
+
{
|
3275 |
+
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
3276 |
+
error_log($message);
|
3277 |
+
echo json_encode(array('result'=>'failed','error'=>$message));
|
3278 |
+
}
|
3279 |
+
die();
|
3280 |
+
}
|
3281 |
+
}
|
includes/upload-cleaner/class-wpvivid-uploads-scanner.php
ADDED
@@ -0,0 +1,1531 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('WPVIVID_PLUGIN_DIR'))
|
4 |
+
{
|
5 |
+
die;
|
6 |
+
}
|
7 |
+
|
8 |
+
class WPvivid_Uploads_Scanner
|
9 |
+
{
|
10 |
+
public $upload_url;
|
11 |
+
public $upload_base_url;
|
12 |
+
|
13 |
+
public $file_found_cache;
|
14 |
+
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
$upload_dir=wp_upload_dir();
|
18 |
+
$this->upload_url=$upload_dir['baseurl'];
|
19 |
+
$this->upload_base_url = substr($upload_dir['baseurl'],1+strlen(get_site_url()));
|
20 |
+
|
21 |
+
$this->file_found_cache=array();
|
22 |
+
}
|
23 |
+
|
24 |
+
public function init_scan_task()
|
25 |
+
{
|
26 |
+
$this->check_table();
|
27 |
+
|
28 |
+
$task['start_time']=time();
|
29 |
+
$task['running_time']=time();
|
30 |
+
$task['status']='running';
|
31 |
+
$task['progress']=0;
|
32 |
+
$task['offset']=0;
|
33 |
+
|
34 |
+
update_option('scan_unused_files_task',$task);
|
35 |
+
}
|
36 |
+
|
37 |
+
public function check_table_exist()
|
38 |
+
{
|
39 |
+
global $wpdb;
|
40 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
41 |
+
$charset_collate = $wpdb->get_charset_collate();
|
42 |
+
|
43 |
+
$table_name = $wpdb->prefix . "wpvivid_scan_result";
|
44 |
+
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
|
45 |
+
{
|
46 |
+
$sql = "CREATE TABLE $table_name (
|
47 |
+
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
48 |
+
path text NOT NULL,
|
49 |
+
from_post INT NOT NULL,
|
50 |
+
PRIMARY KEY (id)
|
51 |
+
) ". $charset_collate . ";";
|
52 |
+
//reference to upgrade.php file
|
53 |
+
dbDelta( $sql );
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
public function check_unused_uploads_files_table_exist()
|
58 |
+
{
|
59 |
+
global $wpdb;
|
60 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
61 |
+
$charset_collate = $wpdb->get_charset_collate();
|
62 |
+
|
63 |
+
$table_name = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
64 |
+
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
|
65 |
+
{
|
66 |
+
$sql = "CREATE TABLE $table_name (
|
67 |
+
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
68 |
+
path text NOT NULL,
|
69 |
+
folder text NOT NULL,
|
70 |
+
PRIMARY KEY (id)
|
71 |
+
)". $charset_collate . ";";
|
72 |
+
//reference to upgrade.php file
|
73 |
+
dbDelta( $sql );
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
public function check_table()
|
78 |
+
{
|
79 |
+
global $wpdb;
|
80 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
81 |
+
$charset_collate = $wpdb->get_charset_collate();
|
82 |
+
|
83 |
+
$table_name = $wpdb->prefix . "wpvivid_scan_result";
|
84 |
+
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
|
85 |
+
{
|
86 |
+
$sql = "CREATE TABLE $table_name (
|
87 |
+
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
88 |
+
path text NOT NULL,
|
89 |
+
from_post INT NOT NULL,
|
90 |
+
PRIMARY KEY (id)
|
91 |
+
) ". $charset_collate . ";";
|
92 |
+
//reference to upgrade.php file
|
93 |
+
dbDelta( $sql );
|
94 |
+
}
|
95 |
+
|
96 |
+
$wpdb->query("TRUNCATE TABLE $table_name");
|
97 |
+
}
|
98 |
+
|
99 |
+
public function init_unused_uploads_task($folders)
|
100 |
+
{
|
101 |
+
$this->check_unused_uploads_files_table();
|
102 |
+
update_option('unused_uploads_task',array());
|
103 |
+
$task['start_time']=time();
|
104 |
+
$task['running_time']=time();
|
105 |
+
$task['status']='running';
|
106 |
+
$task['progress']=0;
|
107 |
+
$task['size']=0;
|
108 |
+
|
109 |
+
$upload_folder = wp_upload_dir();
|
110 |
+
|
111 |
+
$root_path =$upload_folder['basedir'];
|
112 |
+
|
113 |
+
foreach ($folders as $folder)
|
114 |
+
{
|
115 |
+
$task['folder'][$folder]['finished']=0;
|
116 |
+
$task['folder'][$folder]['offset']=0;
|
117 |
+
if($folder=='.')
|
118 |
+
{
|
119 |
+
$task['folder'][$folder]['total']=0;
|
120 |
+
}
|
121 |
+
else
|
122 |
+
{
|
123 |
+
$path=$root_path.DIRECTORY_SEPARATOR.$folder;
|
124 |
+
if(file_exists($path))
|
125 |
+
{
|
126 |
+
$fi = new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS);
|
127 |
+
$task['folder'][$folder]['total']=iterator_count($fi);
|
128 |
+
}
|
129 |
+
else {
|
130 |
+
$task['folder'][$folder]['total']=0;
|
131 |
+
}
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
update_option('unused_uploads_task',$task);
|
136 |
+
}
|
137 |
+
|
138 |
+
public function check_unused_uploads_files_table()
|
139 |
+
{
|
140 |
+
global $wpdb;
|
141 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
142 |
+
$charset_collate = $wpdb->get_charset_collate();
|
143 |
+
|
144 |
+
$table_name = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
145 |
+
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
|
146 |
+
{
|
147 |
+
$sql = "CREATE TABLE $table_name (
|
148 |
+
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
149 |
+
path text NOT NULL,
|
150 |
+
folder text NOT NULL,
|
151 |
+
PRIMARY KEY (id)
|
152 |
+
)". $charset_collate . ";";
|
153 |
+
//reference to upgrade.php file
|
154 |
+
dbDelta( $sql );
|
155 |
+
}
|
156 |
+
|
157 |
+
$wpdb->query("TRUNCATE TABLE $table_name");
|
158 |
+
}
|
159 |
+
|
160 |
+
public function scan_sidebars_widgets()
|
161 |
+
{
|
162 |
+
global $wp_registered_widgets;
|
163 |
+
$syswidgets = $wp_registered_widgets;
|
164 |
+
$active_widgets = get_option( 'sidebars_widgets' );
|
165 |
+
|
166 |
+
$files=array();
|
167 |
+
|
168 |
+
foreach ( $active_widgets as $sidebar_name => $widgets )
|
169 |
+
{
|
170 |
+
if ( $sidebar_name != 'wp_inactive_widgets' && !empty( $widgets ) && is_array( $widgets ) )
|
171 |
+
{
|
172 |
+
foreach ( $widgets as $key => $widget )
|
173 |
+
{
|
174 |
+
$files=array_merge($files,$this->get_images_from_widget($syswidgets[$widget]));
|
175 |
+
|
176 |
+
//do_action( 'wpmc_scan_widget', $syswidgets[$widget] );
|
177 |
+
//$acfwidget = $syswidgets[$widget]['callback'][0]->id;
|
178 |
+
//if ( strlen($acfwidget)>11 && substr($acfwidget,0,11)=='acf_widget_' )
|
179 |
+
//{
|
180 |
+
//$this->get_images_from_acfwidgets ( $acfwidget );
|
181 |
+
//}
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
return $files;
|
187 |
+
}
|
188 |
+
|
189 |
+
public function get_images_from_widget($widget)
|
190 |
+
{
|
191 |
+
$widget_class = $widget['callback'][0]->option_name;
|
192 |
+
$instance_id = $widget['params'][0]['number'];
|
193 |
+
$widget_data = get_option( $widget_class );
|
194 |
+
|
195 |
+
$files=array();
|
196 |
+
|
197 |
+
$ids=array();
|
198 |
+
|
199 |
+
if ( !empty( $widget_data[$instance_id]['text'] ) )
|
200 |
+
{
|
201 |
+
$html = $widget_data[$instance_id]['text']; // mm change
|
202 |
+
$media=$this->get_media_from_html($html);
|
203 |
+
|
204 |
+
if(!empty($media))
|
205 |
+
{
|
206 |
+
$files=$media;
|
207 |
+
}
|
208 |
+
}
|
209 |
+
if ( !empty( $widget_data[$instance_id]['attachment_id'] ) )
|
210 |
+
{
|
211 |
+
$id = $widget_data[$instance_id]['attachment_id'];
|
212 |
+
array_push( $ids, $id );
|
213 |
+
}
|
214 |
+
|
215 |
+
|
216 |
+
if ( !empty( $widget_data[$instance_id]['url'] ) )
|
217 |
+
{
|
218 |
+
$url = $widget_data[$instance_id]['url'];
|
219 |
+
if ( $this->is_url( $url ) )
|
220 |
+
{
|
221 |
+
$src=$this->get_src($url);
|
222 |
+
array_push( $files, $src );
|
223 |
+
}
|
224 |
+
}
|
225 |
+
if ( !empty( $widget_data[$instance_id]['ids'] ) )
|
226 |
+
{
|
227 |
+
$newIds = $widget_data[$instance_id]['ids'];
|
228 |
+
$ids = array_merge( $ids, $newIds );
|
229 |
+
}
|
230 |
+
// Recent Blog Posts
|
231 |
+
if ( !empty( $widget_data[$instance_id]['thumbnail'] ) )
|
232 |
+
{
|
233 |
+
$id = $widget_data[$instance_id]['thumbnail'];
|
234 |
+
array_push( $ids, $id );
|
235 |
+
}
|
236 |
+
|
237 |
+
foreach ($ids as $id)
|
238 |
+
{
|
239 |
+
$files=array_merge($files,$this->get_img_from_id($id));
|
240 |
+
}
|
241 |
+
|
242 |
+
return $files;
|
243 |
+
}
|
244 |
+
|
245 |
+
public function scan_termmeta_thumbnail()
|
246 |
+
{
|
247 |
+
global $wpdb;
|
248 |
+
$query = "SELECT meta_value FROM $wpdb->termmeta WHERE meta_key LIKE '%thumbnail_id%'";
|
249 |
+
$metas = $wpdb->get_col( $query );
|
250 |
+
|
251 |
+
$files=array();
|
252 |
+
if(count($metas)>0)
|
253 |
+
{
|
254 |
+
$ids=array();
|
255 |
+
foreach ( $metas as $id )
|
256 |
+
{
|
257 |
+
if ( is_numeric( $id ) && $id > 0 )
|
258 |
+
$ids[]=$id;
|
259 |
+
}
|
260 |
+
|
261 |
+
foreach ($ids as $id)
|
262 |
+
{
|
263 |
+
$files=array_merge($files,$this->get_img_from_id($id));
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
$placeholder_id = get_option( 'woocommerce_placeholder_image', null, true );
|
268 |
+
if ( !empty( $placeholder_id ) )
|
269 |
+
$files=array_merge($files,$this->get_img_from_id($placeholder_id));
|
270 |
+
return $files;
|
271 |
+
}
|
272 |
+
|
273 |
+
/*
|
274 |
+
public function get_images_from_acfwidgets( $widget)
|
275 |
+
{
|
276 |
+
global $wpdb;
|
277 |
+
$result=array();
|
278 |
+
// $widget starts with: acf_widget_ and looks like this: acf_widget_15011-2
|
279 |
+
$LikeKey = 'widget_' . $widget . '_%'; // Example: option_name starts with widget_acf_widget_15216-3_
|
280 |
+
$q = "SELECT option_name, option_value FROM {$wpdb->options} where option_name like %s;";
|
281 |
+
$OptionRows = $wpdb->get_results( $wpdb->prepare( $q, $LikeKey ) , ARRAY_N );
|
282 |
+
if ( $wpdb->last_error )
|
283 |
+
{
|
284 |
+
$result['result']='failed';
|
285 |
+
$result['error']=$wpdb->last_error;
|
286 |
+
return $result;
|
287 |
+
}
|
288 |
+
if ( count( $OptionRows ) > 0 )
|
289 |
+
{
|
290 |
+
$ACFWidget_ids = array();
|
291 |
+
$ACFWidget_urls = array();
|
292 |
+
foreach( $OptionRows as $row )
|
293 |
+
{
|
294 |
+
//$row[0] = option_name from wp_options
|
295 |
+
//$row[1] = option_value from wp_options
|
296 |
+
// Three if statements in priority order (image ids, link fields, text fields)
|
297 |
+
// *** An image field containing a post id for the image or is it???
|
298 |
+
if ( strpos($row[0], 'image') || strpos($row[0], 'icon') !== false )
|
299 |
+
{
|
300 |
+
if ( is_numeric( $row[1] ) ) {
|
301 |
+
array_push( $ACFWidget_ids, $row[1] );
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
// No else here because sometimes image or icon is present in the option_name and link is also present
|
306 |
+
// Example: widget_acf_widget_15011-2_link_1_link_icon
|
307 |
+
// Example: widget_acf_widget_15216-3_widget_image_link
|
308 |
+
|
309 |
+
// *** A link field may contain a link or be empty
|
310 |
+
if ( strpos( $row[0], 'link' ) || strpos( $row[0], 'url' ) !== false )
|
311 |
+
{
|
312 |
+
if ( $this->is_url($row[1]) ) {
|
313 |
+
$url = $this->clean_url($row[1]);
|
314 |
+
if (!empty($url)) {
|
315 |
+
array_push($ACFWidget_urls, $url);
|
316 |
+
}
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
// *** A text field may contain HTML
|
321 |
+
if (strpos($row[0], 'text') || strpos($row[0], 'html') !== false)
|
322 |
+
{
|
323 |
+
if (!empty($row[1])) {
|
324 |
+
$ACFWidget_urls = array_merge($ACFWidget_urls, $this->get_urls_from_html($row[1])); // mm change
|
325 |
+
}
|
326 |
+
}
|
327 |
+
}
|
328 |
+
}
|
329 |
+
}
|
330 |
+
*/
|
331 |
+
|
332 |
+
public function get_post_count()
|
333 |
+
{
|
334 |
+
global $wpdb;
|
335 |
+
|
336 |
+
$post_types=apply_filters('wpvivid_scan_post_types', array());
|
337 |
+
|
338 |
+
$post_types="post_type NOT IN ('".implode("','",$post_types)."')";
|
339 |
+
|
340 |
+
$post_status="post_status NOT IN ('inherit', 'trash', 'auto-draft')";
|
341 |
+
|
342 |
+
$query="SELECT COUNT(*) FROM $wpdb->posts WHERE $post_types AND $post_status";
|
343 |
+
|
344 |
+
$result=$wpdb->get_results($query,ARRAY_N);
|
345 |
+
|
346 |
+
if($result && sizeof($result)>0)
|
347 |
+
{
|
348 |
+
$count = $result[0][0];
|
349 |
+
}
|
350 |
+
else
|
351 |
+
{
|
352 |
+
$count=0;
|
353 |
+
}
|
354 |
+
|
355 |
+
return $count;
|
356 |
+
}
|
357 |
+
|
358 |
+
public function get_posts($start,$limit)
|
359 |
+
{
|
360 |
+
global $wpdb;
|
361 |
+
|
362 |
+
$post_types=apply_filters('wpvivid_scan_post_types', array());
|
363 |
+
|
364 |
+
$post_types="post_type NOT IN ('".implode("','",$post_types)."')";
|
365 |
+
|
366 |
+
$post_status="post_status NOT IN ('inherit', 'trash', 'auto-draft')";
|
367 |
+
|
368 |
+
$query=$wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE $post_types AND $post_status LIMIT %d, %d",$start,$limit);
|
369 |
+
|
370 |
+
$posts = $wpdb->get_col( $query );
|
371 |
+
|
372 |
+
return $posts;
|
373 |
+
}
|
374 |
+
|
375 |
+
public function get_media_from_html($html)
|
376 |
+
{
|
377 |
+
$html = mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' );
|
378 |
+
$html = do_shortcode( $html );
|
379 |
+
$html = wp_make_content_images_responsive( $html );
|
380 |
+
|
381 |
+
if ( !class_exists("DOMDocument") )
|
382 |
+
{
|
383 |
+
echo 'The DOM extension for PHP is not installed.';
|
384 |
+
return array();
|
385 |
+
}
|
386 |
+
|
387 |
+
libxml_use_internal_errors(true);
|
388 |
+
$dom = new DOMDocument();
|
389 |
+
@$dom->loadHTML( $html );
|
390 |
+
libxml_clear_errors();
|
391 |
+
$results = array();
|
392 |
+
|
393 |
+
$this->get_img_from_tag_img($dom,$results);
|
394 |
+
|
395 |
+
$this->get_img_from_meta($dom,$results);
|
396 |
+
|
397 |
+
$this->get_img_from_tag_a($dom,$results);
|
398 |
+
|
399 |
+
$this->get_img_from_tag_a($dom,$results,'link');
|
400 |
+
|
401 |
+
$this->get_img_from_bk($html,$results);
|
402 |
+
|
403 |
+
$this->get_img_from_wp_image($html,$results);
|
404 |
+
|
405 |
+
return $results;
|
406 |
+
}
|
407 |
+
|
408 |
+
public function get_media_from_post_content($post)
|
409 |
+
{
|
410 |
+
$html = get_post_field( 'post_content', $post );
|
411 |
+
|
412 |
+
$html = mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' );
|
413 |
+
$html = do_shortcode( $html );
|
414 |
+
$html = wp_make_content_images_responsive( $html );
|
415 |
+
|
416 |
+
if ( !class_exists("DOMDocument") )
|
417 |
+
{
|
418 |
+
echo 'The DOM extension for PHP is not installed.';
|
419 |
+
return array();
|
420 |
+
}
|
421 |
+
|
422 |
+
libxml_use_internal_errors(true);
|
423 |
+
$dom = new DOMDocument();
|
424 |
+
@$dom->loadHTML( $html );
|
425 |
+
libxml_clear_errors();
|
426 |
+
$results = array();
|
427 |
+
|
428 |
+
$this->get_img_from_tag_img($dom,$results);
|
429 |
+
|
430 |
+
$this->get_img_from_meta($dom,$results);
|
431 |
+
|
432 |
+
$this->get_img_from_tag_a($dom,$results);
|
433 |
+
|
434 |
+
$this->get_img_from_tag_a($dom,$results,'link');
|
435 |
+
|
436 |
+
$this->get_img_from_bk($html,$results);
|
437 |
+
|
438 |
+
$this->get_img_from_wp_image($html,$results);
|
439 |
+
|
440 |
+
$this->get_img_from_divi($html,$results);
|
441 |
+
|
442 |
+
$galleries = get_post_galleries_images( $post );
|
443 |
+
foreach ( $galleries as $gallery )
|
444 |
+
{
|
445 |
+
foreach ( $gallery as $image )
|
446 |
+
{
|
447 |
+
$src=$this->get_src($image);
|
448 |
+
if($src!==false)
|
449 |
+
{
|
450 |
+
array_push( $results, $src );
|
451 |
+
}
|
452 |
+
}
|
453 |
+
}
|
454 |
+
|
455 |
+
return $results;
|
456 |
+
}
|
457 |
+
|
458 |
+
public function get_img_from_tag_img($dom,&$results)
|
459 |
+
{
|
460 |
+
$imgs = $dom->getElementsByTagName( 'img' );
|
461 |
+
foreach ( $imgs as $img )
|
462 |
+
{
|
463 |
+
$url = $img->getAttribute('src');
|
464 |
+
$src=$this->get_src($url);
|
465 |
+
if($src!==false)
|
466 |
+
{
|
467 |
+
array_push( $results, $src );
|
468 |
+
}
|
469 |
+
|
470 |
+
$srcset = $img->getAttribute('srcset');
|
471 |
+
if ( !empty( $srcset ) )
|
472 |
+
{
|
473 |
+
$setImgs = explode( ',', trim( $srcset ) );
|
474 |
+
foreach ( $setImgs as $setImg )
|
475 |
+
{
|
476 |
+
$urls = explode( ' ', trim( $setImg ) );
|
477 |
+
if ( is_array( $urls ) )
|
478 |
+
{
|
479 |
+
$src=$this->get_src($urls[0]);
|
480 |
+
if($src!==false)
|
481 |
+
{
|
482 |
+
array_push( $results, $src );
|
483 |
+
}
|
484 |
+
}
|
485 |
+
}
|
486 |
+
}
|
487 |
+
}
|
488 |
+
}
|
489 |
+
|
490 |
+
public function get_img_from_meta($dom,&$results)
|
491 |
+
{
|
492 |
+
$metas = $dom->getElementsByTagName( 'meta' );
|
493 |
+
foreach ( $metas as $meta )
|
494 |
+
{
|
495 |
+
$property = $meta->getAttribute( 'property' );
|
496 |
+
if ( $property == 'og:image' || $property == 'og:image:secure_url' || $property == 'twitter:image' )
|
497 |
+
{
|
498 |
+
$url = $meta->getAttribute( 'content' );
|
499 |
+
$src=$this->get_src($url);
|
500 |
+
if($src!==false)
|
501 |
+
{
|
502 |
+
array_push( $results, $src );
|
503 |
+
}
|
504 |
+
}
|
505 |
+
}
|
506 |
+
}
|
507 |
+
|
508 |
+
public function get_img_from_tag_a($dom,&$results,$tag='a')
|
509 |
+
{
|
510 |
+
$urls = $dom->getElementsByTagName($tag);
|
511 |
+
foreach ( $urls as $url )
|
512 |
+
{
|
513 |
+
$url_href = $url->getAttribute('href'); // mm change
|
514 |
+
|
515 |
+
$src=$this->get_src($url_href);
|
516 |
+
if($src!==false)
|
517 |
+
{
|
518 |
+
if ( !empty( $src ) )
|
519 |
+
{
|
520 |
+
array_push( $results, $src );
|
521 |
+
}
|
522 |
+
}
|
523 |
+
}
|
524 |
+
}
|
525 |
+
|
526 |
+
public function get_img_from_bk($html,&$results)
|
527 |
+
{
|
528 |
+
preg_match_all( "/url\(\'?\"?((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png))\'?\"?/", $html, $res );
|
529 |
+
if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
|
530 |
+
{
|
531 |
+
foreach ( $res[1] as $url )
|
532 |
+
{
|
533 |
+
$src=$this->get_src($url);
|
534 |
+
if($src!==false)
|
535 |
+
{
|
536 |
+
array_push( $results, $src );
|
537 |
+
}
|
538 |
+
}
|
539 |
+
}
|
540 |
+
}
|
541 |
+
|
542 |
+
public function get_img_from_wp_image($html,&$results)
|
543 |
+
{
|
544 |
+
$posts_images_ids=array();
|
545 |
+
preg_match_all( "/wp-image-([0-9]+)/", $html, $res );
|
546 |
+
if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
|
547 |
+
{
|
548 |
+
$posts_images_ids = array_merge( $posts_images_ids, $res[1] );
|
549 |
+
}
|
550 |
+
|
551 |
+
preg_match_all('/\[gallery.*ids=.(.*).\]/', $html, $res );
|
552 |
+
if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
|
553 |
+
{
|
554 |
+
foreach ( $res[1] as $id )
|
555 |
+
{
|
556 |
+
$ids = explode( ',', $id );
|
557 |
+
$posts_images_ids = array_merge( $posts_images_ids, $ids );
|
558 |
+
}
|
559 |
+
}
|
560 |
+
|
561 |
+
if(!empty($posts_images_ids))
|
562 |
+
{
|
563 |
+
foreach ($posts_images_ids as $id)
|
564 |
+
{
|
565 |
+
$files=$this->get_attachment_size($id);
|
566 |
+
if(!empty($files))
|
567 |
+
{
|
568 |
+
$results=array_merge( $results, $files );
|
569 |
+
}
|
570 |
+
}
|
571 |
+
}
|
572 |
+
}
|
573 |
+
|
574 |
+
public function get_img_from_divi( $html, &$results )
|
575 |
+
{
|
576 |
+
$galleries_images_et = array();
|
577 |
+
|
578 |
+
// Single Image
|
579 |
+
preg_match_all( "/src=\"((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\"/", $html, $res );
|
580 |
+
if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
|
581 |
+
{
|
582 |
+
foreach ( $res[1] as $url )
|
583 |
+
{
|
584 |
+
$src=$this->get_src($url);
|
585 |
+
if($src!==false)
|
586 |
+
{
|
587 |
+
array_push( $results, $src );
|
588 |
+
}
|
589 |
+
}
|
590 |
+
}
|
591 |
+
|
592 |
+
preg_match_all( "/image=\"((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\"/", $html, $res );
|
593 |
+
if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
|
594 |
+
{
|
595 |
+
foreach ( $res[1] as $url )
|
596 |
+
{
|
597 |
+
$src=$this->get_src($url);
|
598 |
+
if($src!==false)
|
599 |
+
{
|
600 |
+
array_push( $results, $src );
|
601 |
+
}
|
602 |
+
}
|
603 |
+
}
|
604 |
+
// Background Image
|
605 |
+
preg_match_all( "/background_image=\"((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\"/", $html, $res );
|
606 |
+
if ( !empty( $res ) && isset( $res[1] ) && count( $res[1] ) > 0 )
|
607 |
+
{
|
608 |
+
foreach ( $res[1] as $url )
|
609 |
+
{
|
610 |
+
$src=$this->get_src($url);
|
611 |
+
if($src!==false)
|
612 |
+
{
|
613 |
+
array_push( $results, $src );
|
614 |
+
}
|
615 |
+
}
|
616 |
+
}
|
617 |
+
|
618 |
+
// Modules with URL (like the Person module)
|
619 |
+
preg_match_all( "/url=\"((https?:\/\/)?[^\\&\#\[\] \"\?]+\.(jpe?g|gif|png|ico|tif?f|bmp))\"/", $html, $res );
|
620 |
+
if ( !empty( $res ) && isset( $res[1] ) )
|
621 |
+
{
|
622 |
+
foreach ( $res[1] as $url )
|
623 |
+
{
|
624 |
+
$src=$this->get_src($url);
|
625 |
+
if($src!==false)
|
626 |
+
{
|
627 |
+
array_push( $results, $src );
|
628 |
+
}
|
629 |
+
}
|
630 |
+
}
|
631 |
+
|
632 |
+
// Galleries
|
633 |
+
preg_match_all( "/gallery_ids=\"([0-9,]+)/", $html, $res );
|
634 |
+
if ( !empty( $res ) && isset( $res[1] ) )
|
635 |
+
{
|
636 |
+
foreach ( $res[1] as $r )
|
637 |
+
{
|
638 |
+
$ids = explode( ',', $r );
|
639 |
+
$galleries_images_et = array_merge( $galleries_images_et, $ids );
|
640 |
+
}
|
641 |
+
}
|
642 |
+
|
643 |
+
foreach ($galleries_images_et as $id)
|
644 |
+
{
|
645 |
+
$results=array_merge($results,$this->get_img_from_id($id));
|
646 |
+
}
|
647 |
+
|
648 |
+
}
|
649 |
+
|
650 |
+
public function get_attachment_size($attachment_id)
|
651 |
+
{
|
652 |
+
$files=array();
|
653 |
+
global $wpdb;
|
654 |
+
$meta_key="(meta_key = '_wp_attached_file')";
|
655 |
+
$postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND $meta_key", $attachment_id ) );
|
656 |
+
|
657 |
+
foreach ( $postmeta as $meta )
|
658 |
+
{
|
659 |
+
if($meta->meta_key=='_wp_attached_file')
|
660 |
+
{
|
661 |
+
$files[]=$meta->meta_value;
|
662 |
+
|
663 |
+
$attach_meta = wp_get_attachment_metadata( $attachment_id );
|
664 |
+
if($attach_meta!=false)
|
665 |
+
{
|
666 |
+
if(isset($attach_meta['sizes']))
|
667 |
+
{
|
668 |
+
foreach ($attach_meta['sizes'] as $key=>$value)
|
669 |
+
{
|
670 |
+
$data=image_get_intermediate_size($attachment_id,$key);
|
671 |
+
$files[]=$data['path'];
|
672 |
+
}
|
673 |
+
}
|
674 |
+
}
|
675 |
+
}
|
676 |
+
}
|
677 |
+
|
678 |
+
return $files;
|
679 |
+
}
|
680 |
+
|
681 |
+
public function get_media_from_post_meta($post)
|
682 |
+
{
|
683 |
+
global $wpdb;
|
684 |
+
$meta_key="(meta_key = '_thumbnail_id')";
|
685 |
+
$query=$wpdb->prepare("SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND $meta_key",$post);
|
686 |
+
|
687 |
+
$metas = $wpdb->get_col($query);
|
688 |
+
|
689 |
+
$postmeta_images_ids = array();
|
690 |
+
$postmeta_images_urls = array();
|
691 |
+
|
692 |
+
foreach ($metas as $meta)
|
693 |
+
{
|
694 |
+
if ( is_numeric( $meta ) )
|
695 |
+
{
|
696 |
+
if ( $meta > 0 )
|
697 |
+
array_push( $postmeta_images_ids, $meta );
|
698 |
+
continue;
|
699 |
+
}
|
700 |
+
else if ( is_serialized( $meta ) )
|
701 |
+
{
|
702 |
+
$decoded = @unserialize( $meta );
|
703 |
+
if ( is_array( $decoded ) )
|
704 |
+
{
|
705 |
+
$this->array_to_ids_or_urls( $decoded, $postmeta_images_ids, $postmeta_images_urls );
|
706 |
+
continue;
|
707 |
+
}
|
708 |
+
}
|
709 |
+
else {
|
710 |
+
$exploded = explode( ',', $meta );
|
711 |
+
if ( is_array( $exploded ) )
|
712 |
+
{
|
713 |
+
$this->array_to_ids_or_urls( $exploded, $postmeta_images_ids, $postmeta_images_urls );
|
714 |
+
continue;
|
715 |
+
}
|
716 |
+
}
|
717 |
+
}
|
718 |
+
|
719 |
+
$files=array();
|
720 |
+
|
721 |
+
foreach ($postmeta_images_ids as $id)
|
722 |
+
{
|
723 |
+
$files=array_merge($files,$this->get_img_from_id($id));
|
724 |
+
}
|
725 |
+
|
726 |
+
return $files;
|
727 |
+
}
|
728 |
+
|
729 |
+
public function get_media_from_post_meta_elementor( $post )
|
730 |
+
{
|
731 |
+
$postmeta_images_ids = array();
|
732 |
+
$files=array();
|
733 |
+
|
734 |
+
$_elementor_meta = get_post_meta( $post, '_elementor_data',true);
|
735 |
+
if($_elementor_meta!=false)
|
736 |
+
{
|
737 |
+
if ( is_string( $_elementor_meta ) && ! empty( $_elementor_meta ) )
|
738 |
+
{
|
739 |
+
$_elementor_meta = json_decode( $_elementor_meta, true );
|
740 |
+
}
|
741 |
+
if ( empty( $_elementor_meta ) )
|
742 |
+
{
|
743 |
+
$_elementor_meta = array();
|
744 |
+
}
|
745 |
+
$elements_data=$_elementor_meta;
|
746 |
+
foreach ( $elements_data as $element_data )
|
747 |
+
{
|
748 |
+
$element_image=$this->get_element_image($element_data,$postmeta_images_ids);
|
749 |
+
$postmeta_images_ids=array_merge($postmeta_images_ids,$element_image);
|
750 |
+
}
|
751 |
+
|
752 |
+
|
753 |
+
foreach ($postmeta_images_ids as $id)
|
754 |
+
{
|
755 |
+
$files=array_merge($files,$this->get_img_from_id($id));
|
756 |
+
}
|
757 |
+
}
|
758 |
+
return $files;
|
759 |
+
}
|
760 |
+
|
761 |
+
public function get_element_image($element_data,&$attachment_added_ids)
|
762 |
+
{
|
763 |
+
$element_image=array();
|
764 |
+
|
765 |
+
if(!empty($element_data['settings']))
|
766 |
+
{
|
767 |
+
$settings=$element_data['settings'];
|
768 |
+
if(isset($settings['image']))
|
769 |
+
{
|
770 |
+
if(!in_array($settings['image']['id'],$attachment_added_ids))
|
771 |
+
{
|
772 |
+
$element_image[]=$settings['image']['id'];
|
773 |
+
$attachment_added_ids[]=$settings['image']['id'];
|
774 |
+
}
|
775 |
+
|
776 |
+
}
|
777 |
+
}
|
778 |
+
|
779 |
+
if(!empty($element_data['elements']))
|
780 |
+
{
|
781 |
+
foreach ($element_data['elements'] as $element)
|
782 |
+
{
|
783 |
+
$temp=$this->get_element_image($element,$attachment_added_ids);
|
784 |
+
$element_image=array_merge($element_image,$temp);
|
785 |
+
}
|
786 |
+
}
|
787 |
+
|
788 |
+
return $element_image;
|
789 |
+
}
|
790 |
+
|
791 |
+
public function get_from_meta( $meta, $lookFor, &$ids, &$urls )
|
792 |
+
{
|
793 |
+
foreach ( $meta as $key => $value ) {
|
794 |
+
if ( is_object( $value ) || is_array( $value ) )
|
795 |
+
$this->get_from_meta( $value, $lookFor, $ids, $urls );
|
796 |
+
else if ( in_array( $key, $lookFor ) ) {
|
797 |
+
if ( empty( $value ) )
|
798 |
+
continue;
|
799 |
+
else if ( is_numeric( $value ) ) {
|
800 |
+
// It this an ID?
|
801 |
+
array_push( $ids, $value );
|
802 |
+
}
|
803 |
+
else {
|
804 |
+
if ( $this->is_url( $value ) ) {
|
805 |
+
// Is this an URL?
|
806 |
+
array_push( $urls, $this->clean_url( $value ) );
|
807 |
+
}
|
808 |
+
else {
|
809 |
+
// Is this an array of IDs, encoded as a string? (like "20,13")
|
810 |
+
$pieces = explode( ',', $value );
|
811 |
+
foreach ( $pieces as $pval ) {
|
812 |
+
if ( is_numeric( $pval ) ) {
|
813 |
+
array_push( $ids, $pval );
|
814 |
+
}
|
815 |
+
}
|
816 |
+
}
|
817 |
+
}
|
818 |
+
}
|
819 |
+
}
|
820 |
+
}
|
821 |
+
|
822 |
+
public function get_img_from_id($attachment_id)
|
823 |
+
{
|
824 |
+
$files=array();
|
825 |
+
$attach_meta = wp_get_attachment_metadata( $attachment_id );
|
826 |
+
if($attach_meta!=false)
|
827 |
+
{
|
828 |
+
if(isset($attach_meta['sizes']))
|
829 |
+
{
|
830 |
+
foreach ($attach_meta['sizes'] as $key=>$value)
|
831 |
+
{
|
832 |
+
$data=image_get_intermediate_size($attachment_id,$key);
|
833 |
+
$data['path']=ltrim($data['path'], './');
|
834 |
+
$name=$data['path'];
|
835 |
+
if(!in_array($name,$files))
|
836 |
+
{
|
837 |
+
$files[]=$name;
|
838 |
+
}
|
839 |
+
}
|
840 |
+
}
|
841 |
+
|
842 |
+
if(isset($attach_meta['file'])&&is_string($attach_meta['file']))
|
843 |
+
{
|
844 |
+
if(!in_array($attach_meta['file'],$files))
|
845 |
+
{
|
846 |
+
$files[]=$attach_meta['file'];
|
847 |
+
}
|
848 |
+
}
|
849 |
+
}
|
850 |
+
return $files;
|
851 |
+
}
|
852 |
+
|
853 |
+
public function get_src($url)
|
854 |
+
{
|
855 |
+
if(empty($url)||!is_string( $url ))
|
856 |
+
{
|
857 |
+
return false;
|
858 |
+
}
|
859 |
+
|
860 |
+
if(strlen($url)>4&&strtolower( substr( $url, 0, 4) ) == 'http')
|
861 |
+
{
|
862 |
+
$ipos = strpos( $url, $this->upload_url );
|
863 |
+
if ($ipos === false)
|
864 |
+
{
|
865 |
+
return false;
|
866 |
+
}
|
867 |
+
|
868 |
+
$str=substr( $url, 1 + strlen( $this->upload_url ) + $ipos );
|
869 |
+
|
870 |
+
return $str;
|
871 |
+
}
|
872 |
+
else if($url[0] == '/')
|
873 |
+
{
|
874 |
+
$ipos = strpos( $url, $this->upload_base_url );
|
875 |
+
if ($ipos === false)
|
876 |
+
return false;
|
877 |
+
return substr( $url, 1 + strlen( $this->upload_base_url ) + $ipos );
|
878 |
+
}
|
879 |
+
else
|
880 |
+
{
|
881 |
+
return false;
|
882 |
+
}
|
883 |
+
}
|
884 |
+
|
885 |
+
function is_url( $url ) {
|
886 |
+
return ( (
|
887 |
+
!empty( $url ) ) &&
|
888 |
+
is_string( $url ) &&
|
889 |
+
strlen( $url ) > 4 && (
|
890 |
+
strtolower( substr( $url, 0, 4) ) == 'http' || $url[0] == '/'
|
891 |
+
)
|
892 |
+
);
|
893 |
+
}
|
894 |
+
|
895 |
+
function array_to_ids_or_urls( &$meta, &$ids, &$urls )
|
896 |
+
{
|
897 |
+
$regex_file = '/[A-Za-z0-9-_,.\(\)\s]+[.]{1}(jpg|jpeg|jpe|gif|png|tiff|bmp|csv|pdf|xls|xlsx|doc|docx|odt|wpd|rtf|tiff|mp3|mp4|wav|lua)/';
|
898 |
+
foreach ( $meta as $k => $m )
|
899 |
+
{
|
900 |
+
if ( is_numeric( $m ) ) {
|
901 |
+
// Probably a Media ID
|
902 |
+
if ( $m > 0 )
|
903 |
+
array_push( $ids, $m );
|
904 |
+
}
|
905 |
+
else if ( is_array( $m ) )
|
906 |
+
{
|
907 |
+
// If it's an array with a width, probably that the index is the Media ID
|
908 |
+
if ( isset( $m['width'] ) && is_numeric( $k ) ) {
|
909 |
+
if ( $k > 0 )
|
910 |
+
array_push( $ids, $k );
|
911 |
+
}
|
912 |
+
}
|
913 |
+
else if ( !empty( $m ) )
|
914 |
+
{
|
915 |
+
// If it's a string, maybe it's a file (with an extension)
|
916 |
+
if ( preg_match( $regex_file, $m ) )
|
917 |
+
array_push( $urls, $m );
|
918 |
+
}
|
919 |
+
}
|
920 |
+
}
|
921 |
+
|
922 |
+
public function get_folders()
|
923 |
+
{
|
924 |
+
$upload_folder = wp_upload_dir();
|
925 |
+
|
926 |
+
$root_path =$upload_folder['basedir'];
|
927 |
+
|
928 |
+
$regex=apply_filters('wpvivid_uc_scan_include_files_regex',array());
|
929 |
+
|
930 |
+
$exclude_regex=apply_filters('wpvivid_uc_scan_exclude_files_regex',array());
|
931 |
+
|
932 |
+
$result=$this->get_folder_list($root_path,$regex,$exclude_regex);
|
933 |
+
|
934 |
+
return $result;
|
935 |
+
}
|
936 |
+
|
937 |
+
public function get_files($folder)
|
938 |
+
{
|
939 |
+
$upload_folder = wp_upload_dir();
|
940 |
+
|
941 |
+
$root_path =$upload_folder['basedir'];
|
942 |
+
|
943 |
+
$files =array();
|
944 |
+
|
945 |
+
$regex=apply_filters('wpvivid_uc_scan_include_files_regex',array());
|
946 |
+
|
947 |
+
$exclude_regex=apply_filters('wpvivid_uc_scan_exclude_files_regex',array());
|
948 |
+
|
949 |
+
$this->scan_list_uploaded_files($files, $root_path.DIRECTORY_SEPARATOR.$folder,$root_path,$regex,$exclude_regex);
|
950 |
+
|
951 |
+
return $files;
|
952 |
+
}
|
953 |
+
|
954 |
+
private function regex_match($regex_array,$string,$mode)
|
955 |
+
{
|
956 |
+
if(empty($regex_array))
|
957 |
+
{
|
958 |
+
return true;
|
959 |
+
}
|
960 |
+
|
961 |
+
if($mode==0)
|
962 |
+
{
|
963 |
+
foreach ($regex_array as $regex)
|
964 |
+
{
|
965 |
+
if(preg_match($regex,$string))
|
966 |
+
{
|
967 |
+
return false;
|
968 |
+
}
|
969 |
+
}
|
970 |
+
|
971 |
+
return true;
|
972 |
+
}
|
973 |
+
|
974 |
+
if($mode==1)
|
975 |
+
{
|
976 |
+
foreach ($regex_array as $regex)
|
977 |
+
{
|
978 |
+
if(preg_match($regex,$string))
|
979 |
+
{
|
980 |
+
return true;
|
981 |
+
}
|
982 |
+
}
|
983 |
+
|
984 |
+
return false;
|
985 |
+
}
|
986 |
+
|
987 |
+
return true;
|
988 |
+
}
|
989 |
+
|
990 |
+
private function get_folder_list($root_path,$regex=array(),$exclude_regex=array())
|
991 |
+
{
|
992 |
+
$result['folders']=array();
|
993 |
+
$result['files']=array();
|
994 |
+
$result['size']=0;
|
995 |
+
$handler = opendir($root_path);
|
996 |
+
if($handler!==false)
|
997 |
+
{
|
998 |
+
while (($filename = readdir($handler)) !== false)
|
999 |
+
{
|
1000 |
+
if ($filename != "." && $filename != "..")
|
1001 |
+
{
|
1002 |
+
if (is_dir($root_path . DIRECTORY_SEPARATOR . $filename))
|
1003 |
+
{
|
1004 |
+
if(preg_match('#^\d{4}$#',$filename))
|
1005 |
+
{
|
1006 |
+
$result['folders']=array_merge( $result['folders'],$this->get_sub_folder($root_path . DIRECTORY_SEPARATOR . $filename,$filename));
|
1007 |
+
}
|
1008 |
+
else
|
1009 |
+
{
|
1010 |
+
$result['folders'][]=$filename;
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
}
|
1014 |
+
else
|
1015 |
+
{
|
1016 |
+
if ($this->regex_match($exclude_regex, $filename, 0))
|
1017 |
+
{
|
1018 |
+
if($this->regex_match($regex, $filename, 1))
|
1019 |
+
{
|
1020 |
+
$result['files'][] = $filename;
|
1021 |
+
$result['size']+=filesize($root_path . DIRECTORY_SEPARATOR . $filename);
|
1022 |
+
}
|
1023 |
+
}
|
1024 |
+
}
|
1025 |
+
}
|
1026 |
+
}
|
1027 |
+
if($handler)
|
1028 |
+
@closedir($handler);
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
$result['folders'][]='.';
|
1032 |
+
return $result;
|
1033 |
+
}
|
1034 |
+
|
1035 |
+
function get_sub_folder($path,$root)
|
1036 |
+
{
|
1037 |
+
$folders=array();
|
1038 |
+
$handler = opendir($path);
|
1039 |
+
if($handler!==false)
|
1040 |
+
{
|
1041 |
+
while (($filename = readdir($handler)) !== false)
|
1042 |
+
{
|
1043 |
+
if ($filename != "." && $filename != "..")
|
1044 |
+
{
|
1045 |
+
if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
1046 |
+
{
|
1047 |
+
$folders[]=$root.DIRECTORY_SEPARATOR.$filename;
|
1048 |
+
|
1049 |
+
}
|
1050 |
+
}
|
1051 |
+
}
|
1052 |
+
if($handler)
|
1053 |
+
@closedir($handler);
|
1054 |
+
}
|
1055 |
+
return $folders;
|
1056 |
+
}
|
1057 |
+
|
1058 |
+
function scan_list_uploaded_files( &$files,$path,$root,$regex=array(),$exclude_regex=array())
|
1059 |
+
{
|
1060 |
+
$count = 0;
|
1061 |
+
if(is_dir($path))
|
1062 |
+
{
|
1063 |
+
$handler = opendir($path);
|
1064 |
+
if($handler!==false)
|
1065 |
+
{
|
1066 |
+
while (($filename = readdir($handler)) !== false)
|
1067 |
+
{
|
1068 |
+
if ($filename != "." && $filename != "..")
|
1069 |
+
{
|
1070 |
+
$count++;
|
1071 |
+
|
1072 |
+
if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
1073 |
+
{
|
1074 |
+
$this->scan_list_uploaded_files($files, $path . DIRECTORY_SEPARATOR . $filename,$root,$regex);
|
1075 |
+
}
|
1076 |
+
else
|
1077 |
+
{
|
1078 |
+
if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0))
|
1079 |
+
{
|
1080 |
+
if($this->regex_match($regex, $filename, 1))
|
1081 |
+
{
|
1082 |
+
$result['files'][] = $filename;
|
1083 |
+
$files[] = str_replace($root . DIRECTORY_SEPARATOR,'',$path . DIRECTORY_SEPARATOR . $filename);
|
1084 |
+
}
|
1085 |
+
}
|
1086 |
+
}
|
1087 |
+
}
|
1088 |
+
}
|
1089 |
+
if($handler)
|
1090 |
+
@closedir($handler);
|
1091 |
+
}
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
return $files;
|
1095 |
+
}
|
1096 |
+
|
1097 |
+
public function update_scan_task($uploads_files,$offset,$status='running',$progress=0)
|
1098 |
+
{
|
1099 |
+
$task=get_option('scan_unused_files_task',array());
|
1100 |
+
|
1101 |
+
$task['running_time']=time();
|
1102 |
+
$task['status']=$status;
|
1103 |
+
$task['progress']=$progress;
|
1104 |
+
$task['offset']=$offset;
|
1105 |
+
|
1106 |
+
$this->insert_scan_result($uploads_files);
|
1107 |
+
update_option('scan_unused_files_task',$task);
|
1108 |
+
}
|
1109 |
+
|
1110 |
+
public function update_unused_uploads_task($uploads_files,$folder,$finished,$offset,$status='running',$progress=0,$size=0)
|
1111 |
+
{
|
1112 |
+
$task=get_option('unused_uploads_task',array());
|
1113 |
+
|
1114 |
+
$task['running_time']=time();
|
1115 |
+
$task['status']=$status;
|
1116 |
+
$task['progress']=$progress;
|
1117 |
+
$task['size']+=$size;
|
1118 |
+
$task['folder'][$folder]['finished']=$finished;
|
1119 |
+
$task['folder'][$folder]['offset']=$offset;
|
1120 |
+
if(!empty($uploads_files))
|
1121 |
+
$this->insert_unused_uploads_files($folder,$uploads_files);
|
1122 |
+
update_option('unused_uploads_task',$task);
|
1123 |
+
}
|
1124 |
+
|
1125 |
+
public function get_unused_uploads_progress()
|
1126 |
+
{
|
1127 |
+
$task=get_option('unused_uploads_task',array());
|
1128 |
+
|
1129 |
+
if(isset($task['folder']))
|
1130 |
+
{
|
1131 |
+
$i=0;
|
1132 |
+
foreach ($task['folder'] as $folder=>$item)
|
1133 |
+
{
|
1134 |
+
if($item['finished'])
|
1135 |
+
$i++;
|
1136 |
+
}
|
1137 |
+
|
1138 |
+
$progress=intval(($i/sizeof($task['folder']))*100);
|
1139 |
+
|
1140 |
+
$ret['percent']=$progress;
|
1141 |
+
$ret['total_folders']=sizeof($task['folder']);
|
1142 |
+
$ret['scanned_folders']=$i;
|
1143 |
+
return $ret;
|
1144 |
+
}
|
1145 |
+
else
|
1146 |
+
{
|
1147 |
+
$ret['percent']=0;
|
1148 |
+
$ret['total_folders']=0;
|
1149 |
+
$ret['scanned_folders']=0;
|
1150 |
+
return $ret;
|
1151 |
+
}
|
1152 |
+
}
|
1153 |
+
|
1154 |
+
public function get_unfinished_folder()
|
1155 |
+
{
|
1156 |
+
$task=get_option('unused_uploads_task',array());
|
1157 |
+
|
1158 |
+
foreach ($task['folder'] as $folder=>$data)
|
1159 |
+
{
|
1160 |
+
if(!$data['finished'])
|
1161 |
+
{
|
1162 |
+
$result['folder']=$folder;
|
1163 |
+
$result['offset']=$data['offset'];
|
1164 |
+
$result['total']=$data['total'];
|
1165 |
+
return $result;
|
1166 |
+
}
|
1167 |
+
}
|
1168 |
+
|
1169 |
+
return false;
|
1170 |
+
}
|
1171 |
+
|
1172 |
+
public function insert_scan_result($uploads_files)
|
1173 |
+
{
|
1174 |
+
global $wpdb;
|
1175 |
+
$table_name = $wpdb->prefix . "wpvivid_scan_result";
|
1176 |
+
|
1177 |
+
$query = "INSERT INTO $table_name (id,path,from_post) VALUES ";
|
1178 |
+
$values = array();
|
1179 |
+
$place_holders=array();
|
1180 |
+
foreach ( $uploads_files as $id=>$files )
|
1181 |
+
{
|
1182 |
+
foreach ($files as $path)
|
1183 |
+
{
|
1184 |
+
array_push( $values, $path );
|
1185 |
+
array_push( $values, $id );
|
1186 |
+
$place_holders[] = "(NULL,'%s',%d)";
|
1187 |
+
}
|
1188 |
+
}
|
1189 |
+
if ( !empty( $values ) )
|
1190 |
+
{
|
1191 |
+
$query .= implode( ', ', $place_holders );
|
1192 |
+
$prepared = $wpdb->prepare( "$query ", $values );
|
1193 |
+
$wpdb->query( $prepared );
|
1194 |
+
}
|
1195 |
+
}
|
1196 |
+
|
1197 |
+
public function insert_unused_uploads_files($folder,$uploads_files)
|
1198 |
+
{
|
1199 |
+
global $wpdb;
|
1200 |
+
$table_name = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
1201 |
+
|
1202 |
+
$query = "INSERT INTO $table_name (id,path,folder) VALUES ";
|
1203 |
+
$values = array();
|
1204 |
+
$place_holders=array();
|
1205 |
+
foreach ( $uploads_files as $path )
|
1206 |
+
{
|
1207 |
+
array_push( $values, $path );
|
1208 |
+
array_push( $values, $folder );
|
1209 |
+
$place_holders[] = "(NULL,'%s','%s')";
|
1210 |
+
}
|
1211 |
+
|
1212 |
+
if ( !empty( $values ) )
|
1213 |
+
{
|
1214 |
+
$query .= implode( ', ', $place_holders );
|
1215 |
+
$prepared = $wpdb->prepare( "$query ", $values );
|
1216 |
+
$wpdb->query( $prepared );
|
1217 |
+
}
|
1218 |
+
}
|
1219 |
+
|
1220 |
+
public function is_uploads_files_exist($file)
|
1221 |
+
{
|
1222 |
+
global $wpdb;
|
1223 |
+
|
1224 |
+
$file=str_replace('\\','/',$file);
|
1225 |
+
|
1226 |
+
$table = $wpdb->prefix . "wpvivid_scan_result";
|
1227 |
+
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE path = '%s'", $file ) );
|
1228 |
+
if (empty($row))
|
1229 |
+
{
|
1230 |
+
$quick_scan=get_option('wpvivid_uc_quick_scan',false);
|
1231 |
+
|
1232 |
+
if(!$quick_scan)
|
1233 |
+
{
|
1234 |
+
$attachment_id=$this->find_media_id_from_file($file);
|
1235 |
+
|
1236 |
+
if($attachment_id)
|
1237 |
+
{
|
1238 |
+
if(isset($this->file_found_cache[$attachment_id]))
|
1239 |
+
{
|
1240 |
+
if($this->file_found_cache[$attachment_id])
|
1241 |
+
{
|
1242 |
+
return true;
|
1243 |
+
}
|
1244 |
+
else
|
1245 |
+
{
|
1246 |
+
return false;
|
1247 |
+
}
|
1248 |
+
}
|
1249 |
+
|
1250 |
+
$files=$this->get_img_from_id($attachment_id);
|
1251 |
+
|
1252 |
+
if(!empty($files))
|
1253 |
+
{
|
1254 |
+
$files = implode("','",$files);
|
1255 |
+
|
1256 |
+
$sql= "SELECT * FROM $table WHERE path IN ('$files')";
|
1257 |
+
$row = $wpdb->get_row($sql);
|
1258 |
+
|
1259 |
+
if (!empty($row))
|
1260 |
+
{
|
1261 |
+
$this->file_found_cache[$attachment_id]=1;
|
1262 |
+
return true;
|
1263 |
+
}
|
1264 |
+
else
|
1265 |
+
{
|
1266 |
+
$this->file_found_cache[$attachment_id]=0;
|
1267 |
+
}
|
1268 |
+
}
|
1269 |
+
}
|
1270 |
+
}
|
1271 |
+
|
1272 |
+
return false;
|
1273 |
+
}
|
1274 |
+
return true;
|
1275 |
+
}
|
1276 |
+
|
1277 |
+
public function find_media_id_from_file( $file )
|
1278 |
+
{
|
1279 |
+
global $wpdb;
|
1280 |
+
|
1281 |
+
$file=basename($file);
|
1282 |
+
|
1283 |
+
$sql = "SELECT post_id
|
1284 |
+
FROM {$wpdb->postmeta}
|
1285 |
+
WHERE meta_key = '_wp_attachment_metadata'
|
1286 |
+
AND meta_value LIKE '%$file%'";
|
1287 |
+
|
1288 |
+
$ret = $wpdb->get_var( $sql );
|
1289 |
+
|
1290 |
+
if(!$ret)
|
1291 |
+
{
|
1292 |
+
$sql = $wpdb->prepare( "SELECT post_id
|
1293 |
+
FROM {$wpdb->postmeta}
|
1294 |
+
WHERE meta_key = '_wp_attached_file'
|
1295 |
+
AND meta_value = %s", $file
|
1296 |
+
);
|
1297 |
+
$ret = $wpdb->get_var( $sql );
|
1298 |
+
}
|
1299 |
+
return $ret;
|
1300 |
+
}
|
1301 |
+
|
1302 |
+
public function get_scan_result($search,$folder)
|
1303 |
+
{
|
1304 |
+
global $wpdb;
|
1305 |
+
|
1306 |
+
$where='';
|
1307 |
+
if(!empty($search)||!empty($folder))
|
1308 |
+
{
|
1309 |
+
$where='WHERE ';
|
1310 |
+
if(!empty($search))
|
1311 |
+
{
|
1312 |
+
$where.="`path` LIKE '%$search%'";
|
1313 |
+
}
|
1314 |
+
|
1315 |
+
if(!empty($search)&&!empty($folder))
|
1316 |
+
{
|
1317 |
+
$where.=' AND ';
|
1318 |
+
}
|
1319 |
+
|
1320 |
+
if(!empty($folder))
|
1321 |
+
{
|
1322 |
+
$where.="`folder` = '$folder'";
|
1323 |
+
}
|
1324 |
+
}
|
1325 |
+
|
1326 |
+
$table = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
1327 |
+
$sql="SELECT * FROM $table ".$where;
|
1328 |
+
|
1329 |
+
$result=$wpdb->get_results($sql,ARRAY_A);
|
1330 |
+
return $result;
|
1331 |
+
}
|
1332 |
+
|
1333 |
+
public function get_scan_result_count()
|
1334 |
+
{
|
1335 |
+
global $wpdb;
|
1336 |
+
|
1337 |
+
$table = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
1338 |
+
$sql="SELECT COUNT(*) FROM $table";
|
1339 |
+
|
1340 |
+
$result=$wpdb->get_results($sql,ARRAY_N);
|
1341 |
+
if($result)
|
1342 |
+
{
|
1343 |
+
return $count=$result[0][0];
|
1344 |
+
}
|
1345 |
+
else
|
1346 |
+
{
|
1347 |
+
return false;
|
1348 |
+
}
|
1349 |
+
}
|
1350 |
+
|
1351 |
+
public function get_scan_result_size()
|
1352 |
+
{
|
1353 |
+
$task=get_option('unused_uploads_task',array());
|
1354 |
+
|
1355 |
+
if(empty($task))
|
1356 |
+
{
|
1357 |
+
return false;
|
1358 |
+
}
|
1359 |
+
else if(isset($task['size']))
|
1360 |
+
{
|
1361 |
+
return size_format($task['size'],2);
|
1362 |
+
}
|
1363 |
+
else
|
1364 |
+
{
|
1365 |
+
return false;
|
1366 |
+
}
|
1367 |
+
}
|
1368 |
+
|
1369 |
+
public function get_all_folder()
|
1370 |
+
{
|
1371 |
+
global $wpdb;
|
1372 |
+
|
1373 |
+
$table = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
1374 |
+
$sql="SELECT * FROM $table GROUP BY `folder`";
|
1375 |
+
|
1376 |
+
$result=$wpdb->get_results($sql,ARRAY_A);
|
1377 |
+
|
1378 |
+
if($result)
|
1379 |
+
{
|
1380 |
+
$folders=array();
|
1381 |
+
foreach ($result as $item)
|
1382 |
+
{
|
1383 |
+
if($item['folder']=='.')
|
1384 |
+
{
|
1385 |
+
$folders[]='root';
|
1386 |
+
}
|
1387 |
+
else
|
1388 |
+
{
|
1389 |
+
$folders[]=$item['folder'];
|
1390 |
+
}
|
1391 |
+
|
1392 |
+
}
|
1393 |
+
return $folders;
|
1394 |
+
}
|
1395 |
+
else
|
1396 |
+
{
|
1397 |
+
return false;
|
1398 |
+
}
|
1399 |
+
}
|
1400 |
+
|
1401 |
+
public function get_selected_files_list($selected_list)
|
1402 |
+
{
|
1403 |
+
global $wpdb;
|
1404 |
+
|
1405 |
+
$ids=implode(",",$selected_list);
|
1406 |
+
|
1407 |
+
$table = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
1408 |
+
$sql="SELECT * FROM $table WHERE `id` IN ($ids)";
|
1409 |
+
|
1410 |
+
$result=$wpdb->get_results($sql,ARRAY_A);
|
1411 |
+
if($result)
|
1412 |
+
{
|
1413 |
+
$files=array();
|
1414 |
+
foreach ($result as $item)
|
1415 |
+
{
|
1416 |
+
$files[]=$item['path'];
|
1417 |
+
}
|
1418 |
+
return $files;
|
1419 |
+
}
|
1420 |
+
else
|
1421 |
+
{
|
1422 |
+
return false;
|
1423 |
+
}
|
1424 |
+
}
|
1425 |
+
|
1426 |
+
public function delete_selected_files_list($selected_list)
|
1427 |
+
{
|
1428 |
+
global $wpdb;
|
1429 |
+
|
1430 |
+
$table = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
1431 |
+
|
1432 |
+
$ids=implode(",",$selected_list);
|
1433 |
+
|
1434 |
+
$sql="DELETE FROM $table WHERE `id` IN ($ids)";
|
1435 |
+
|
1436 |
+
$result=$wpdb->query($sql);
|
1437 |
+
if($result)
|
1438 |
+
{
|
1439 |
+
return true;
|
1440 |
+
}
|
1441 |
+
else
|
1442 |
+
{
|
1443 |
+
return false;
|
1444 |
+
}
|
1445 |
+
}
|
1446 |
+
|
1447 |
+
public function get_all_files_list($search,$folder,$offset,$count)
|
1448 |
+
{
|
1449 |
+
global $wpdb;
|
1450 |
+
|
1451 |
+
$where='';
|
1452 |
+
if(!empty($search)||!empty($folder))
|
1453 |
+
{
|
1454 |
+
$where='WHERE ';
|
1455 |
+
if(!empty($search))
|
1456 |
+
{
|
1457 |
+
$where.="`path` LIKE '%$search%'";
|
1458 |
+
}
|
1459 |
+
|
1460 |
+
if(!empty($search)&&!empty($folder))
|
1461 |
+
{
|
1462 |
+
$where.=' AND ';
|
1463 |
+
}
|
1464 |
+
|
1465 |
+
if(!empty($folder))
|
1466 |
+
{
|
1467 |
+
$where.="`folder` = '$folder'";
|
1468 |
+
}
|
1469 |
+
}
|
1470 |
+
$where.=" LIMIT $offset,$count";
|
1471 |
+
//LIMIT
|
1472 |
+
|
1473 |
+
$table = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
1474 |
+
$sql="SELECT * FROM $table ".$where;
|
1475 |
+
|
1476 |
+
$result=$wpdb->get_results($sql,ARRAY_A);
|
1477 |
+
if($result)
|
1478 |
+
{
|
1479 |
+
$files=array();
|
1480 |
+
foreach ($result as $item)
|
1481 |
+
{
|
1482 |
+
$files[]=$item['path'];
|
1483 |
+
}
|
1484 |
+
return $files;
|
1485 |
+
}
|
1486 |
+
else
|
1487 |
+
{
|
1488 |
+
return false;
|
1489 |
+
}
|
1490 |
+
}
|
1491 |
+
|
1492 |
+
public function delete_all_files_list($search,$folder,$count)
|
1493 |
+
{
|
1494 |
+
global $wpdb;
|
1495 |
+
|
1496 |
+
$where='';
|
1497 |
+
if(!empty($search)||!empty($folder))
|
1498 |
+
{
|
1499 |
+
$where='WHERE ';
|
1500 |
+
if(!empty($search))
|
1501 |
+
{
|
1502 |
+
$where.="`path` LIKE '%$search%'";
|
1503 |
+
}
|
1504 |
+
|
1505 |
+
if(!empty($search)&&!empty($folder))
|
1506 |
+
{
|
1507 |
+
$where.=' AND ';
|
1508 |
+
}
|
1509 |
+
|
1510 |
+
if(!empty($folder))
|
1511 |
+
{
|
1512 |
+
$where.="`folder` = '$folder'";
|
1513 |
+
}
|
1514 |
+
}
|
1515 |
+
$where.=" LIMIT $count";
|
1516 |
+
//LIMIT
|
1517 |
+
|
1518 |
+
$table = $wpdb->prefix . "wpvivid_unused_uploads_files";
|
1519 |
+
$sql="DELETE FROM $table ".$where;
|
1520 |
+
|
1521 |
+
$result=$wpdb->query($sql);
|
1522 |
+
if($result)
|
1523 |
+
{
|
1524 |
+
return true;
|
1525 |
+
}
|
1526 |
+
else
|
1527 |
+
{
|
1528 |
+
return false;
|
1529 |
+
}
|
1530 |
+
}
|
1531 |
+
}
|
readme.txt
CHANGED
@@ -1,19 +1,19 @@
|
|
1 |
-
===
|
2 |
Contributors: wpvivid
|
3 |
-
Tags: move, clone, migrate,
|
4 |
Requires at least: 4.5
|
5 |
Tested up to: 5.5
|
6 |
Requires PHP: 5.3
|
7 |
-
Stable tag: 0.9.
|
8 |
License: GPLv3 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
|
10 |
|
11 |
-
Migrate a backup of WP site
|
12 |
|
13 |
== Description ==
|
14 |
-
WPvivid Backup Plugin
|
15 |
|
16 |
-
Migrate a copy of WP site to a new host (a new domain), schedule backups, send backups to leading remote storage. All in one backup & migration plugin.
|
17 |
|
18 |
== WPvivid Backup for MainWP ==
|
19 |
[WPvivid Backup for MainWP](https://wpvivid.com/wpvivid-backup-for-mainwp) is now available to download.
|
@@ -25,13 +25,20 @@ Click to download [WPvivid Backup for MainWP](https://wordpress.org/plugins/wpvi
|
|
25 |
* Customize everything to backup
|
26 |
* Create staging sites and push staging to live site
|
27 |
* Incremental backups
|
|
|
28 |
* Auto backup WordPress core, themes, and plugins
|
|
|
29 |
* WordPress Multisite backup
|
|
|
|
|
30 |
* Advanced remote storage
|
31 |
* Advanced backup schedules
|
32 |
* Restore backups from remote storage
|
33 |
* Migrate everything via remote storage
|
|
|
|
|
34 |
* Edit user roles capabilities
|
|
|
35 |
|
36 |
See a review video on WPvivid Backup Pro:
|
37 |
|
@@ -44,37 +51,36 @@ WPvivid Backup Plugin has been tested by our users to migrate well on websites b
|
|
44 |
1. [Elementor Page Builder](https://wordpress.org/plugins/elementor/)
|
45 |
2. [Page Builder by SiteOrigin](https://wordpress.org/plugins/siteorigin-panels/)
|
46 |
3. [WordPress Page Builder – Beaver Builder](https://wordpress.org/plugins/beaver-builder-lite-version/)
|
|
|
47 |
|
48 |
== Core Features ==
|
49 |
|
50 |
-
= 1. Easy
|
|
|
|
|
51 |
Migrate your WordPress site to a new domain with a single click. WPvivid Backup Plugin supports site migration from dev environment to a new server, from dev environment to a new domain or from a live server to another.
|
52 |
|
53 |
You can also migrate a site to a subdirectory, from a.com to b.com, from a.com to a.com/directory and from a.com to b.com/directory.
|
54 |
|
55 |
-
You are free to choose what to migrate: the entire site, files or just
|
56 |
-
=
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
= 4. One-Click Restore =
|
62 |
Restore your WordPress site from a backup with a single click.
|
|
|
|
|
63 |
|
64 |
== Cloud Storage Supported ==
|
65 |
|
66 |
Dropbox, Google Drive, Microsoft OneDrive, Amazon S3, DigitalOcean Spaces, SFTP, FTP.
|
67 |
The pro version also supports Wasabi, pCloud and more are coming soon.
|
68 |
|
69 |
-
== Site Migration Process ==
|
70 |
-
1. Install WPvivid Backup plugin on both the destination site and the sending site.
|
71 |
-
2. Generate a site key on the destination site with one click.
|
72 |
-
3. Paste the key in the sending site and save it.
|
73 |
-
4. Migrate the site with one-click.
|
74 |
-
|
75 |
== Features Spotlight ==
|
76 |
* One-Click Site Move or Migration
|
77 |
* Upload Backups to Restore or Migrate
|
|
|
78 |
* Schedule Automated Backups
|
79 |
* Restore A Backup with One Click
|
80 |
* Create A Manual Backup
|
@@ -179,6 +185,10 @@ Thank you for translating WPvivid Backup Plugin to your languages!
|
|
179 |
* Valentin Lyong (Bulgarian)
|
180 |
|
181 |
== Changelog ==
|
|
|
|
|
|
|
|
|
182 |
= 0.9.44 =
|
183 |
- Successfully tested with WordPress 5.5.
|
184 |
- Fixed: Refreshing Google Drive token failed in some cases.
|
1 |
+
=== Backup & Migration & Unused Images Cleaner - WPvivid Backup Plugin ===
|
2 |
Contributors: wpvivid
|
3 |
+
Tags: move, clone, migrate, cleaner, backup, restore, auto backup, cloud backup
|
4 |
Requires at least: 4.5
|
5 |
Tested up to: 5.5
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 0.9.45
|
8 |
License: GPLv3 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
|
10 |
|
11 |
+
Migrate a backup of WP site, schedule offsite backups, clean unused images before backup and migration. All in one backup & migration plugin
|
12 |
|
13 |
== Description ==
|
14 |
+
WPvivid Backup Plugin offers backup and migration as basic features, and is integrating more and more elegant features, such as unused images cleaner etc.
|
15 |
|
16 |
+
Migrate a copy of WP site to a new host (a new domain), schedule backups, send backups to leading remote storage, clean unused images before backup and migration. All in one backup & migration plugin.
|
17 |
|
18 |
== WPvivid Backup for MainWP ==
|
19 |
[WPvivid Backup for MainWP](https://wpvivid.com/wpvivid-backup-for-mainwp) is now available to download.
|
25 |
* Customize everything to backup
|
26 |
* Create staging sites and push staging to live site
|
27 |
* Incremental backups
|
28 |
+
* Database backups encryption
|
29 |
* Auto backup WordPress core, themes, and plugins
|
30 |
+
* Unused images cleaner
|
31 |
* WordPress Multisite backup
|
32 |
+
* Create a staging for a WordPress MU
|
33 |
+
* Create a fresh WP install
|
34 |
* Advanced remote storage
|
35 |
* Advanced backup schedules
|
36 |
* Restore backups from remote storage
|
37 |
* Migrate everything via remote storage
|
38 |
+
* Migrate a childsite (MU) to a single WordPress install
|
39 |
+
* White label
|
40 |
* Edit user roles capabilities
|
41 |
+
* [More amazing features](https://wpvivid.com/backup-plugin-pro)
|
42 |
|
43 |
See a review video on WPvivid Backup Pro:
|
44 |
|
51 |
1. [Elementor Page Builder](https://wordpress.org/plugins/elementor/)
|
52 |
2. [Page Builder by SiteOrigin](https://wordpress.org/plugins/siteorigin-panels/)
|
53 |
3. [WordPress Page Builder – Beaver Builder](https://wordpress.org/plugins/beaver-builder-lite-version/)
|
54 |
+
4. More other page builders
|
55 |
|
56 |
== Core Features ==
|
57 |
|
58 |
+
= 1. Easy Backups =
|
59 |
+
Easily create a backup of your WordPress site. You can choose to back up the entire site(database+files), all files, or database only.
|
60 |
+
= 2. Auto Migration =
|
61 |
Migrate your WordPress site to a new domain with a single click. WPvivid Backup Plugin supports site migration from dev environment to a new server, from dev environment to a new domain or from a live server to another.
|
62 |
|
63 |
You can also migrate a site to a subdirectory, from a.com to b.com, from a.com to a.com/directory and from a.com to b.com/directory.
|
64 |
|
65 |
+
You are free to choose what to migrate: the entire site, files or just database only.
|
66 |
+
= 3. Scheduled Backups =
|
67 |
+
Set a schedule to run backups automatically on your website. You can set the backups to run every 12 hours, daily, weekly, fortnightly, monthly, and choose backup items and destination.
|
68 |
+
= 4. Offsite Backup to Remote Storage =
|
69 |
+
Send your backups offsite to a remote location. WPvivid Backup Plugin supports the leading cloud storage providers: Dropbox, Google Drive, Amazon S3, Microsoft OneDrive, DigitalOcean Spaces, FTP and SFTP.
|
70 |
+
= 5. One-Click Restore =
|
|
|
71 |
Restore your WordPress site from a backup with a single click.
|
72 |
+
= 6. Unused Images Cleaner =
|
73 |
+
Scan your WP media library to find unused images, then you can choose to clean specific or all unused images.
|
74 |
|
75 |
== Cloud Storage Supported ==
|
76 |
|
77 |
Dropbox, Google Drive, Microsoft OneDrive, Amazon S3, DigitalOcean Spaces, SFTP, FTP.
|
78 |
The pro version also supports Wasabi, pCloud and more are coming soon.
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
== Features Spotlight ==
|
81 |
* One-Click Site Move or Migration
|
82 |
* Upload Backups to Restore or Migrate
|
83 |
+
* Unused Images Cleaner
|
84 |
* Schedule Automated Backups
|
85 |
* Restore A Backup with One Click
|
86 |
* Create A Manual Backup
|
185 |
* Valentin Lyong (Bulgarian)
|
186 |
|
187 |
== Changelog ==
|
188 |
+
= 0.9.45 =
|
189 |
+
- New feature Added: Find and clean unused images in your WP media library.
|
190 |
+
- Fixed some bugs in the plugin code.
|
191 |
+
- Optimized the plugin code.
|
192 |
= 0.9.44 =
|
193 |
- Successfully tested with WordPress 5.5.
|
194 |
- Fixed: Refreshing Google Drive token failed in some cases.
|
wpvivid-backuprestore.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
* @wordpress-plugin
|
8 |
* Plugin Name: WPvivid Backup Plugin
|
9 |
* Description: Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one.
|
10 |
-
* Version: 0.9.
|
11 |
* Author: WPvivid Team
|
12 |
* Author URI: https://wpvivid.com
|
13 |
* License: GPL-3.0+
|
@@ -21,7 +21,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
21 |
die;
|
22 |
}
|
23 |
|
24 |
-
define( 'WPVIVID_PLUGIN_VERSION', '0.9.
|
25 |
//
|
26 |
define('WPVIVID_RESTORE_INIT','init');
|
27 |
define('WPVIVID_RESTORE_READY','ready');
|
7 |
* @wordpress-plugin
|
8 |
* Plugin Name: WPvivid Backup Plugin
|
9 |
* Description: Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one.
|
10 |
+
* Version: 0.9.45
|
11 |
* Author: WPvivid Team
|
12 |
* Author URI: https://wpvivid.com
|
13 |
* License: GPL-3.0+
|
21 |
die;
|
22 |
}
|
23 |
|
24 |
+
define( 'WPVIVID_PLUGIN_VERSION', '0.9.45' );
|
25 |
//
|
26 |
define('WPVIVID_RESTORE_INIT','init');
|
27 |
define('WPVIVID_RESTORE_READY','ready');
|