Changeset 403515
- Timestamp:
- 07/01/2011 10:46:43 PM (15 years ago)
- Location:
- wp-s3/trunk
- Files:
-
- 2 edited
-
s3-options.php (modified) (1 diff)
-
s3.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-s3/trunk/s3-options.php
r402696 r403515 105 105 <span class="description"><?php _e('No of files to upload on each cron execution.') ?></span> 106 106 </td> 107 </tr> 107 </tr> 108 <tr valign="top"> 109 <th scope="row"><label for="s3plugin_cloudfrontURL"><?php _e('Path prefix') ?></label></th> 110 <td> 111 <input name="s3plugin_path_prefix" type="text" id="s3plugin_path_prefix" value="<?php form_option('s3plugin_dir_prefix'); ?>" readonly="readonly" size="7" /> 112 <span class="description"><?php _e('Path prefix. This will be auto generated when you clear cache.') ?></span> 113 </td> 114 </tr> 115 <tr valign="top"> 116 <th scope="row"><?php _e('Clear Cache') ?></th> 117 <td> 118 <fieldset> 119 <legend class="screen-reader-text"><span><?php _e('Use SSL') ?></span></legend> 120 <label for="s3plugin_clear_cache"> 121 <input name="s3plugin_clear_cache" type="checkbox" id="s3plugin_clear_cache" value="1" <?php checked('1', get_option('s3plugin_clear_cache')); ?> /> 122 <?php _e('Clear Cache. This will change the upload prefix.') ?> 123 </label> 124 </fieldset> 125 </td> 126 </tr> 127 108 128 </table> 109 129 <p class="submit"> -
wp-s3/trunk/s3.php
r403224 r403515 9 9 Author URI: http://imthi.com/ 10 10 */ 11 12 error_reporting(E_ALL); 11 13 12 14 class S3Plugin { … … 22 24 var $s3UseCloudFrontURL; 23 25 var $s3CloudFrontURL; 26 var $s3DirPrefix; 24 27 var $cronScheduleTime; 25 28 var $cronUploadLimit; … … 59 62 } 60 63 61 $this->blockDirectory = array('wpcf7_captcha' );64 $this->blockDirectory = array('wpcf7_captcha', 'wp-admin'); 62 65 $this->blockExtension = array('php', 'htm', 'html'); 63 66 … … 69 72 $this->s3BucketName = get_option('s3plugin_amazon_bucket_name'); 70 73 $this->s3UseSSL = (bool) get_option('s3plugin_use_ssl', 0); 74 $this->s3DirPrefix = get_option('s3plugin_dir_prefix'); 71 75 72 76 $this->s3UseCloudFrontURL = (bool) get_option('s3plugin_use_cloudfrontURL', 0); … … 96 100 add_filter('style_loader_src', array(&$this, 'style_loader_src'), 99); 97 101 98 99 102 if (isset($_GET ['page']) && $_GET ['page'] == 's3plugin-options') { 100 103 ob_start(); … … 147 150 delete_option('s3plugin_use_cloudfrontURL'); 148 151 } 152 if (isset($_POST ['s3plugin_clear_cache'])) { 153 $this->recursive_remove_directory($this->s3CacheFolder, FALSE); 154 $this->db->query("DELETE FROM `{$this->tabeImageQueue}` WHERE 1=1;"); 155 update_option('s3plugin_dir_prefix', substr(md5(time() + microtime()), 0, 6) . '/'); 156 } 157 149 158 update_option('s3plugin_cloudfrontURL', $_POST ['s3plugin_cloudfrontURL']); 150 159 … … 201 210 ignore_user_abort(true); 202 211 set_time_limit(0); 212 213 print "Hello"; 203 214 204 215 include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 's3-php5-curl' . DIRECTORY_SEPARATOR . 'S3.php'; … … 206 217 $s3Adapter = new S3($this->s3AccessKey, $this->s3SecretKey, $this->s3UseSSL); 207 218 $availableBuckets = @$s3Adapter->listBuckets(); 219 cmVarDebug($availableBuckets); 220 208 221 if (!empty($availableBuckets) && in_array($this->s3BucketName, $availableBuckets) == TRUE) { 209 222 $query = "SELECT * FROM {$this->tabeImageQueue} WHERE status='queue' ORDER BY added LIMIT {$this->cronUploadLimit};"; … … 214 227 $fileStatus = 'error'; 215 228 $filePath = ABSPATH . $fileInfo ['path']; 216 $fileObjectInfo = $s3Adapter->getObjectInfo($this->s3BucketName, $ fileInfo ['path'], TRUE);229 $fileObjectInfo = $s3Adapter->getObjectInfo($this->s3BucketName, $this->s3DirPrefix . $fileInfo ['path'], TRUE); 217 230 if (!empty($fileObjectInfo)) { 218 231 if ($fileObjectInfo ['size'] != filesize($filePath)) { 219 if ($s3Adapter->deleteObject($this->s3BucketName, $ fileInfo ['path']) === FALSE) {232 if ($s3Adapter->deleteObject($this->s3BucketName, $this->s3DirPrefix . $fileInfo ['path']) === FALSE) { 220 233 $shouldUpload = FALSE; 221 234 } … … 227 240 if ($shouldUpload) { 228 241 $fileMimeType = $this->getFileType($filePath); 229 if ($s3Adapter->putObjectFile($filePath, $this->s3BucketName, $ fileInfo ['path'], S3::ACL_PUBLIC_READ, array(), $fileMimeType) === TRUE) {242 if ($s3Adapter->putObjectFile($filePath, $this->s3BucketName, $this->s3DirPrefix . $fileInfo ['path'], S3::ACL_PUBLIC_READ, array(), $fileMimeType) === TRUE) { 230 243 $fileStatus = 'done'; 231 244 } … … 380 393 if ($fileContents == 'done') { 381 394 if ($instance->isCloudFrontURLEnabled) { 382 return $instance->s3CloudFrontURL . '/' . $ relativePath;395 return $instance->s3CloudFrontURL . '/' . $instance->s3DirPrefix . $relativePath; 383 396 } else { 384 return "http://{$instance->s3BucketName}.s3.amazonaws.com/" . $ relativePath;397 return "http://{$instance->s3BucketName}.s3.amazonaws.com/" . $instance->s3DirPrefix . $relativePath; 385 398 } 386 399 } … … 408 421 } 409 422 423 public static function scanForImages($htmlContent) { 424 $instance = self::getInstance(); 425 $mediaList = $instance->getMediaFromContent($htmlContent); 426 if (!empty($mediaList)) { 427 foreach ($mediaList as $fileURL) { 428 $fileCDNURL = self::getCDNURL($fileURL); 429 if ($fileCDNURL !== FALSE) { 430 $htmlContent = str_replace($fileURL, $fileCDNURL, $htmlContent); 431 } 432 } 433 } 434 return $htmlContent; 435 } 436 410 437 function theContent($the_content) { 411 438 $id = 0; … … 414 441 return $the_content; 415 442 } 416 $mediaList = $this->getMediaFromContent($the_content); 417 if (!empty($mediaList)) { 418 foreach ($mediaList as $fileURL) { 419 $fileCDNURL = self::getCDNURL($fileURL); 420 if ($fileCDNURL !== FALSE) { 421 $the_content = str_replace($fileURL, $fileCDNURL, $the_content); 422 } 423 } 424 } 425 return $the_content; 443 return self::scanForImages($the_content); 426 444 } 427 445 … … 466 484 } 467 485 486 function recursive_remove_directory($directory, $empty=FALSE) { 487 if (substr($directory, -1) == '/') { 488 $directory = substr($directory, 0, -1); 489 } 490 if (!file_exists($directory) || !is_dir($directory)) { 491 return FALSE; 492 } elseif (is_readable($directory)) { 493 $handle = opendir($directory); 494 while (FALSE !== ($item = readdir($handle))) { 495 if ($item != '.' && $item != '..') { 496 $path = $directory . '/' . $item; 497 if (is_dir($path)) { 498 $this->recursive_remove_directory($path); 499 } else { 500 unlink($path); 501 } 502 } 503 } 504 closedir($handle); 505 if ($empty == FALSE) { 506 if (!rmdir($directory)) { 507 return FALSE; 508 } 509 } 510 } 511 return TRUE; 512 } 513 468 514 } 469 515
Note: See TracChangeset
for help on using the changeset viewer.