Skip to content
Browse files

Support for cname

  • Loading branch information...
1 parent ffe88e6 commit 2838e3f64c08d2fca0c26d9ded18bc4a6c7739a2 @TalLevAmi TalLevAmi committed
Showing with 21 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +4 −2 cloudinary.php
  3. +16 −0 cloudinary_test.php
View
1 .gitignore
@@ -0,0 +1 @@
+.project
View
6 cloudinary.php
@@ -141,6 +141,7 @@ public static function cloudinary_url($source, &$options=array()) {
$private_cdn = Cloudinary::option_consume($options, "private_cdn", Cloudinary::config_get("private_cdn"));
$secure_distribution = Cloudinary::option_consume($options, "secure_distribution", Cloudinary::config_get("secure_distribution"));
$cdn_subdomain = Cloudinary::option_consume($options, "cdn_subdomain", Cloudinary::config_get("cdn_subdomain"));
+ $cname = Cloudinary::option_consume($options, "cname", Cloudinary::config_get("cname"));
$original_source = $source;
if (!$source) return $original_source;
@@ -161,8 +162,9 @@ public static function cloudinary_url($source, &$options=array()) {
if ($secure) {
$prefix = "https://" . $secure_distribution;
} else {
- $subdomain = $cdn_subdomain ? "a" . ((crc32(source) % 5 + 5) % 5 + 1) : "";
- $prefix = "http://" . $subdomain . ($private_cdn ? $cloud_name . "-" : "") . "res.cloudinary.com";
+ $subdomain = $cdn_subdomain ? "a" . ((crc32($source) % 5 + 5) % 5 + 1) . "." : "";
+ $host = $cname ? $cname : ($private_cdn ? $cloud_name . "-" : "") . "res.cloudinary.com";
+ $prefix = "http://" . $subdomain . $host;
}
if (!$private_cdn) $prefix .= "/" . $cloud_name;
View
16 cloudinary_test.php
@@ -169,6 +169,22 @@ public function test_fetch() {
$this->assertEquals("http://res.cloudinary.com/test123/image/fetch/http://blah.com/hello%3Fa%3Db", $result);
}
+ public function test_cname() {
+ // should support extenal cname
+ $options = array("cname" => "hello.com");
+ $result = Cloudinary::cloudinary_url("test", $options);
+ $this->assertEquals(array(), $options);
+ $this->assertEquals("http://hello.com/test123/image/upload/test", $result);
+ }
+
+ public function test_cname_subdomain() {
+ // should support extenal cname with cdn_subdomain on
+ $options = array("cname" => "hello.com", "cdn_subdomain" => TRUE);
+ $result = Cloudinary::cloudinary_url("test", $options);
+ $this->assertEquals(array(), $options);
+ $this->assertEquals("http://a2.hello.com/test123/image/upload/test", $result);
+ }
+
public function test_http_escape() {
// should escape http urls
$options = array("type" => "youtube");

0 comments on commit 2838e3f

Please sign in to comment.
Something went wrong with that request. Please try again.