コード例 #1
0
/**
 * Get CDN URL
 */
function get_cdn_url($type = 'http')
{
    // Ensure CDN instance exists
    if (check_cdn() === false) {
        $wp_url = wp_upload_dir();
        return $wp_url['baseurl'];
    }
    // Get correct CDN URL
    $type = strtolower($type);
    if ($type == 'ssl' || $type == 'https') {
        // Return HTTPS URI
        return $_SESSION['cdn']->container_object()->SSLURI();
    } else {
        // Return HTTP URI
        return $_SESSION['cdn']->container_object()->CDNURI();
    }
}
コード例 #2
0
/**
 * Get CDN URL
 */
function get_cdn_url($type = 'http')
{
    // Ensure CDN instance exists
    if (check_cdn() === false) {
        $wp_url = wp_upload_dir();
        return $wp_url['baseurl'];
    }
    // Get correct CDN URL
    $type = strtolower($type);
    if ($_SESSION['cdn']->opencloud_version == '1.10.0') {
        if ($type == 'ssl' || $type == 'https') {
            // Return SSL URI
            return $_SESSION['cdn']->container_object()->getCdn()->getCdnSslUri();
        } elseif ($type == 'streaming') {
            // Return Streaming URI
            return $_SESSION['cdn']->container_object()->getCdn()->getCdnStreamingUri();
        } elseif ($type == 'ios-streaming') {
            // Return Streaming URI
            return $_SESSION['cdn']->container_object()->getCdn()->getIosStreamingUri();
        } else {
            // Return HTTP URI
            return $_SESSION['cdn']->container_object()->getCdn()->getCdnUri();
        }
    } else {
        if ($type == 'ssl' || $type == 'https') {
            // Return SSL URI
            return $_SESSION['cdn']->container_object()->SSLURI();
        } elseif ($type == 'streaming') {
            // Return Streaming URI
            // return $_SESSION['cdn']->container_object()->getCdn()->getCdnStreamingUri();
            return $_SESSION['cdn']->container_object()->CDNURI();
        } elseif ($type == 'ios-streaming') {
            // Return Streaming URI
            // return $_SESSION['cdn']->container_object()->getCdn()->getIosStreamingUri();
            return $_SESSION['cdn']->container_object()->CDNURI();
        } else {
            // Return HTTP URI
            return $_SESSION['cdn']->container_object()->CDNURI();
        }
    }
}
コード例 #3
0
 /**
  *  Get list of CDN objects
  */
 public function get_cdn_objects($force_cache = false)
 {
     // Get time difference
     $this->api_settings->last_cache_time = isset($this->api_settings->last_cache_time) ? $this->api_settings->last_cache_time : time();
     $time_diff = (time() - $this->api_settings->last_cache_time) / 60;
     // If caching is set, return CDN cache
     if (isset($this->api_settings->cache_cdn_objects) && $this->api_settings->cache_cdn_objects > 0) {
         if (isset($_SESSION['cdn_object_cache']) && $time_diff < $this->api_settings->cache_cdn_objects && $force_cache === false) {
             return $_SESSION['cdn_object_cache'];
         }
     }
     // Ensure CDN instance exists
     if (check_cdn() === false) {
         return array('response' => 'fail', 'message' => 'Error instantiating CDN session.');
     }
     // Set array to store CDN objects
     $cdn_objects = array();
     // Get objects
     if ($this->opencloud_version == '1.10.0') {
         $oc_service = $this->opencloud_client()->objectStoreService('cloudFiles', $this->api_settings->region);
         $objects = $oc_service->getContainer($this->api_settings->container)->objectList();
         foreach ($objects as $object) {
             $cdn_objects[] = array('file_name' => $object->getName(), 'file_size' => $object->getContentLength());
         }
     } else {
         $files = $this->container_object()->objectList();
         while ($file = $files->next()) {
             $cdn_objects[] = array('file_name' => $file->name, 'file_size' => $file->bytes);
         }
     }
     // Set object cache
     if (isset($this->api_settings->cache_cdn_objects) && $this->api_settings->cache_cdn_objects > 0 || $force_cache == true) {
         $this->api_settings->last_cache_time = time();
         $_SESSION['cdn_object_cache'] = $cdn_objects;
     }
     // Return CDN objects
     return $cdn_objects;
 }
コード例 #4
0
    try {
        $save_settings = save_cdn_settings();
        // See if save was successful
        if (isset($save_settings['response']) && $save_settings['response'] == 'error') {
            $show_errors[] = $save_settings['message'];
        }
    } catch (Exception $exc) {
        $settings_error = true;
    }
}
/**
 * Try to create a CDN instance
 */
try {
    // Create new instance
    if (check_cdn() == false) {
        $show_errors[] = 'Could not create instance of class RS_CDN.';
    }
    // Check if connection has been made by grabbing container
    if (!isset($_SESSION['cdn']) || !is_object($_SESSION['cdn']) || is_null($_SESSION['cdn']) || is_null($_SESSION['cdn']->container_object())) {
        $show_errors[] = 'Container does not exist.';
    }
} catch (Exception $exc) {
    if (stripos($exc, 'Unauthorized') !== false) {
        $show_errors[] = 'Unable to connect to the CDN, please check the credentials below.';
    } else {
        $show_errors[] = $exc;
    }
}
/**
 * Assign API settings
コード例 #5
0
 /**
  *  Get list of CDN objects
  */
 public function get_cdn_objects($force_cache = false)
 {
     // Ensure CDN instance exists
     if (check_cdn() === false) {
         return array();
     }
     // Path to cache file
     $cache_file_path = RS_CDN_PATH . 'object_cache';
     // Set array to store CDN objects
     $cdn_objects = array();
     // Check if caching is enabled
     if ($force_cache === true || !is_writable(RS_CDN_PATH) || !is_writable($cache_file_path)) {
         // Update object cache
         try {
             $objects = $this->container_object()->objectList();
         } catch (Exception $exc) {
             return array();
         }
         // Setup objects
         $cdn_objects = array();
         foreach ($objects as $object) {
             $cdn_objects[] = array('fn' => $object['name'], 'fs' => $object['bytes']);
         }
         // Write files to cache file
         if (is_writable(RS_CDN_PATH) && is_writable($cache_file_path)) {
             // Write to cache file
             file_put_contents($cache_file_path, json_encode($cdn_objects));
         }
         // Return CDN objects
         return $cdn_objects;
     } else {
         // Return caching
         return json_decode(file_get_contents($cache_file_path), true);
     }
 }