forked from cloudinary/cloudinary_php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.php
More file actions
127 lines (104 loc) · 4.85 KB
/
Copy pathHelpers.php
File metadata and controls
127 lines (104 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace {
function cl_upload_url($options = array())
{
if (!@$options["resource_type"]) $options["resource_type"] = "auto";
return Cloudinary::cloudinary_api_url("upload", $options);
}
function cl_upload_tag_params($options = array())
{
$params = Cloudinary\Uploader::build_upload_params($options);
$params = Cloudinary::sign_request($params, $options);
return json_encode($params);
}
function cl_image_upload_tag($field, $options = array())
{
$html_options = Cloudinary::option_get($options, "html", array());
$classes = array("cloudinary-fileupload");
if (isset($html_options["class"])) {
array_unshift($classes, Cloudinary::option_consume($html_options, "class"));
}
$tag_options = array_merge($html_options, array("type" => "file", "name" => "file",
"data-url" => cl_upload_url($options),
"data-form-data" => cl_upload_tag_params($options),
"data-cloudinary-field" => $field,
"class" => implode(" ", $classes),
));
return '<input ' . Cloudinary::html_attrs($tag_options) . '/>';
}
function cl_form_tag($callback_url, $options = array())
{
$form_options = Cloudinary::option_get($options, "form", array());
$options["callback_url"] = $callback_url;
$params = Cloudinary\Uploader::build_upload_params($options);
$params = Cloudinary::sign_request($params, $options);
$api_url = Cloudinary::cloudinary_api_url("upload", $options);
$form = "<form enctype='multipart/form-data' action='" . $api_url . "' method='POST' " . Cloudinary::html_attrs($form_options) . ">\n";
foreach ($params as $key => $value) {
$form .= "<input " . Cloudinary::html_attrs(array("name" => $key, "value" => $value, "type" => "hidden")) . "/>\n";
}
$form .= "</form>\n";
return $form;
}
// Examples
// cl_image_tag("israel.png", array("width"=>100, "height"=>100, "alt"=>"hello") # W/H are not sent to cloudinary
// cl_image_tag("israel.png", array("width"=>100, "height"=>100, "alt"=>"hello", "crop"=>"fit") # W/H are sent to cloudinary
function cl_image_tag($source, $options = array()) {
$source = cloudinary_url_internal($source, $options);
if (isset($options["html_width"])) $options["width"] = Cloudinary::option_consume($options, "html_width");
if (isset($options["html_height"])) $options["height"] = Cloudinary::option_consume($options, "html_height");
return "<img src='" . $source . "' " . Cloudinary::html_attrs($options) . "/>";
}
function fetch_image_tag($url, $options = array()) {
$options["type"] = "fetch";
return cl_image_tag($url, $options);
}
function facebook_profile_image_tag($profile, $options = array()) {
$options["type"] = "facebook";
return cl_image_tag($profile, $options);
}
function gravatar_profile_image_tag($email, $options = array()) {
$options["type"] = "gravatar";
$options["format"] = "jpg";
return cl_image_tag(md5(strtolower(trim($email))), $options);
}
function twitter_profile_image_tag($profile, $options = array()) {
$options["type"] = "twitter";
return cl_image_tag($profile, $options);
}
function twitter_name_profile_image_tag($profile, $options = array()) {
$options["type"] = "twitter_name";
return cl_image_tag($profile, $options);
}
function cloudinary_js_config() {
$params = array();
foreach (Cloudinary::$JS_CONFIG_PARAMS as $param) {
$value = Cloudinary::config_get($param);
if ($value) $params[$param] = $value;
}
return "<script type='text/javascript'>\n" .
"$.cloudinary.config(" . json_encode($params) . ");\n" .
"</script>\n";
}
function cloudinary_url($source, $options = array()) {
return cloudinary_url_internal($source, $options);
}
function cloudinary_url_internal($source, &$options = array()) {
if (!isset($options["secure"])) {
$options["secure"] = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' )
|| ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' );
}
return Cloudinary::cloudinary_url($source, $options);
}
function cl_sprite_url($tag, $options = array()) {
if (substr($tag, -strlen(".css")) != ".css") {
$options["format"] = "css";
}
$options["type"] = "sprite";
return cloudinary_url_internal($tag, $options);
}
function cl_sprite_tag($tag, $options = array()) {
return "<link rel='stylesheet' type='text/css' href='" . cl_sprite_url($tag, $options) . "'>";
}
}
?>