Skip to content

Commit

Permalink
Support for cname
Browse files Browse the repository at this point in the history
  • Loading branch information
TalLevAmi committed Sep 15, 2012
1 parent ffe88e6 commit 2838e3f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.project
6 changes: 4 additions & 2 deletions cloudinary.php
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions cloudinary_test.php
Expand Up @@ -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");
Expand Down

0 comments on commit 2838e3f

Please sign in to comment.