Plugin Directory

Changeset 403109


Ignore:
Timestamp:
07/01/2011 06:20:43 AM (15 years ago)
Author:
imthiaz
Message:

Work in progress

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-s3/trunk/s3.php

    r402696 r403109  
    66  Description: This plugin helps the users to view your blog in a pda and iPhone browser.
    77  Author: Imthiaz Rafiq
    8   Version: 1.0
     8  Version: 1.1 Alpha
    99  Author URI: http://imthi.com/
    1010 */
    11 
    12 error_reporting(E_ALL);
    13 ini_set('display_errors', true);
    1411
    1512class S3Plugin {
     
    1815    var $s3CacheFolder;
    1916    var $siteURL;
    20    
    2117    var $isCloudFrontURLEnabled;
    22    
    2318    var $s3AccessKey;
    2419    var $s3SecretKey;
     
    7772    $this->s3UseCloudFrontURL = (bool) get_option('s3plugin_use_cloudfrontURL', 0);
    7873    $this->s3CloudFrontURL = untrailingslashit(get_option('s3plugin_cloudfrontURL'));
    79    
    80     if($this->s3UseCloudFrontURL && !empty ($this->s3UseCloudFrontURL)){
     74
     75    if ($this->s3UseCloudFrontURL && !empty($this->s3UseCloudFrontURL)) {
    8176        $this->isCloudFrontURLEnabled = TRUE;
    82     }else{
     77    } else {
    8378        $this->isCloudFrontURLEnabled = FALSE;
    8479    }
    85    
    86    
     80
     81
    8782    $this->cronScheduleTime = get_option('s3plugin_cron_interval', 300);
    8883    $this->cronUploadLimit = get_option('s3plugin_cron_limit', 20);
     
    9893        'deactivatePlugin'));
    9994    add_action('admin_menu', array(&$this, 's3AdminMenu'));
     95    add_filter('script_loader_src', array(&$this, 'script_loader_src'));
     96
    10097    if (isset($_GET ['page']) && $_GET ['page'] == 's3plugin-options') {
    10198        ob_start();
     
    122119    }
    123120
     121    function script_loader_src($scriptURL) {
     122    if (!is_admin()) {
     123        $urlParts = parse_url($scriptURL);
     124        $justURL = $urlParts['scheme'] . '://' . $urlParts['host'] . $urlParts['path'];
     125        $fileCDNURL = self::getCDNURL($justURL);
     126        if ($fileCDNURL !== FALSE) {
     127        if (isset($urlParts['query']) && !empty($urlParts['query'])) {
     128            return $fileCDNURL . '?' . $urlParts['query'];
     129        }
     130        return $fileCDNURL;
     131        }
     132    }
     133    return $scriptURL;
     134    }
     135
    124136    function s3AdminMenu() {
    125137    if (function_exists('add_submenu_page')) {
     
    149161        }
    150162        update_option('s3plugin_cloudfrontURL', $_POST ['s3plugin_cloudfrontURL']);
    151        
     163
    152164        if ($this->checkS3AccessAndBucket($_POST ['s3plugin_amazon_key_id'], $_POST ['s3plugin_amazon_secret_key'], $useSSL, $_POST ['s3plugin_amazon_bucket_name']) === FALSE) {
    153165        $s3PuginMessage = 'Connection failed. Plugin not active.';
     
    264276        $fileContents = file_get_contents($cacheFilePath);
    265277        if ($fileContents == 'done') {
    266             if($instance->isCloudFrontURLEnabled){
    267             return $instance->s3CloudFrontURL .'/'.$relativePath;
    268             }else{
     278            if ($instance->isCloudFrontURLEnabled) {
     279            return $instance->s3CloudFrontURL . '/' . $relativePath;
     280            } else {
    269281            return "http://{$instance->s3BucketName}.s3.amazonaws.com/" . $relativePath;
    270282            }
     
    355367$wp_s3 = S3Plugin::getInstance();
    356368
     369function jsDebug($var='') {
     370    print "<script type='text/javascript'>\n";
     371    print "console.log('{$var}');\n";
     372    print "</script>\n";
     373}
     374
    357375function cmVarDebug($var, $echo = true) {
    358376    $dump = "<div style=\"border:1px solid #f00;font-family:arial;font-size:12px;font-weight:normal;background:#f0f0f0;text-align:left;padding:3px;\"><pre>" . print_r($var, true) . "</pre></div>";
Note: See TracChangeset for help on using the changeset viewer.