option_consume() public static method

public static option_consume ( &$options, $option, $default = NULL )
Example #1
0
 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");
     }
     $responsive = Cloudinary::option_consume($options, "responsive");
     $hidpi = Cloudinary::option_consume($options, "hidpi");
     if ($responsive || $hidpi) {
         $options["data-src"] = $source;
         $classes = array($responsive ? "cld-responsive" : "cld-hidpi");
         $current_class = Cloudinary::option_consume($options, "class");
         if ($current_class) {
             array_unshift($classes, $current_class);
         }
         $options["class"] = implode(" ", $classes);
         $source = Cloudinary::option_consume($options, "responsive_placeholder", Cloudinary::config_get("responsive_placeholder"));
         if ($source == "blank") {
             $source = Cloudinary::BLANK;
         }
     }
     $html = "<img ";
     if ($source) {
         $html .= "src='{$source}' ";
     }
     $html .= Cloudinary::html_attrs($options) . "/>";
     return $html;
 }
Example #2
0
 public static function build_eager($transformations)
 {
     $eager = array();
     foreach (\Cloudinary::build_array($transformations) as $trans) {
         $transformation = $trans;
         $format = \Cloudinary::option_consume($transformation, "format");
         $single_eager = implode("/", array_filter(array(\Cloudinary::generate_transformation_string($transformation), $format)));
         array_push($eager, $single_eager);
     }
     return implode("|", $eager);
 }
Example #3
0
 function cl_video_tag($source, $options = array())
 {
     $source = preg_replace('/\\.(' . implode('|', default_source_types()) . ')$/', '', $source);
     $source_types = Cloudinary::option_consume($options, 'source_types', array());
     $source_transformation = Cloudinary::option_consume($options, 'source_transformation', array());
     $fallback = Cloudinary::option_consume($options, 'fallback_content', '');
     if (empty($source_types)) {
         $source_types = default_source_types();
     }
     $video_options = $options;
     if (array_key_exists('poster', $video_options)) {
         if (is_array($video_options['poster'])) {
             if (array_key_exists('public_id', $video_options['poster'])) {
                 $video_options['poster'] = cloudinary_url_internal($video_options['poster']['public_id'], $video_options['poster']);
             } else {
                 $video_options['poster'] = cl_video_thumbnail_path($source, $video_options['poster']);
             }
         }
     } else {
         $video_options['poster'] = cl_video_thumbnail_path($source, $options);
     }
     if (empty($video_options['poster'])) {
         unset($video_options['poster']);
     }
     $html = '<video ';
     if (!array_key_exists('resource_type', $video_options)) {
         $video_options['resource_type'] = 'video';
     }
     $multi_source = is_array($source_types);
     if (!$multi_source) {
         $source .= '.' . $source_types;
     }
     $src = cloudinary_url_internal($source, $video_options);
     if (!$multi_source) {
         $video_options['src'] = $src;
     }
     if (isset($video_options["html_width"])) {
         $video_options['width'] = Cloudinary::option_consume($video_options, 'html_width');
     }
     if (isset($video_options['html_height'])) {
         $video_options['height'] = Cloudinary::option_consume($video_options, 'html_height');
     }
     $html .= Cloudinary::html_attrs($video_options) . '>';
     if ($multi_source) {
         foreach ($source_types as $source_type) {
             $transformation = Cloudinary::option_consume($source_transformation, $source_type, array());
             $transformation = array_merge($options, $transformation);
             $src = cl_video_path($source . '.' . $source_type, $transformation);
             $video_type = $source_type == 'ogv' ? 'ogg' : $source_type;
             $mime_type = "video/{$video_type}";
             $html .= '<source ' . Cloudinary::html_attrs(array('src' => $src, 'type' => $mime_type)) . '>';
         }
     }
     $html .= $fallback;
     $html .= '</video>';
     return $html;
 }
Example #4
0
 protected static function build_responsive_breakpoints($breakpoints)
 {
     if (!$breakpoints) {
         return NULL;
     }
     $breakpoints_params = array();
     foreach (\Cloudinary::build_array($breakpoints) as $breakpoint_settings) {
         if ($breakpoint_settings) {
             $transformation = \Cloudinary::option_consume($breakpoint_settings, "transformation");
             if ($transformation) {
                 $breakpoint_settings["transformation"] = \Cloudinary::generate_transformation_string($transformation);
             }
             array_push($breakpoints_params, $breakpoint_settings);
         }
     }
     return json_encode($breakpoints_params);
 }
Example #5
0
 public static function check_cloudinary_field($source, &$options = array())
 {
     $IDENTIFIER_RE = "~" . "^(?:([^/]+)/)??(?:([^/]+)/)??(?:(?:v(\\d+)/)(?:([^#]+)/)?)?" . "([^#/]+?)(?:\\.([^.#/]+))?(?:#([^/]+))?\$" . "~";
     $matches = array();
     if (!(is_object($source) && method_exists($source, 'identifier'))) {
         return $source;
     }
     $identifier = $source->identifier();
     if (!$identifier || strstr(':', $identifier) !== false || !preg_match($IDENTIFIER_RE, $identifier, $matches)) {
         return $source;
     }
     $optionNames = array('resource_type', 'type', 'version', 'folder', 'public_id', 'format');
     foreach ($optionNames as $index => $optionName) {
         if (@$matches[$index + 1]) {
             $options[$optionName] = $matches[$index + 1];
         }
     }
     return Cloudinary::option_consume($options, 'public_id');
 }
Example #6
0
 public static function cloudinary_url($source, &$options = array())
 {
     $type = Cloudinary::option_consume($options, "type", "upload");
     if ($type == "fetch" && !isset($options["fetch_format"])) {
         $options["fetch_format"] = Cloudinary::option_consume($options, "format");
     }
     $transformation = Cloudinary::generate_transformation_string($options);
     $resource_type = Cloudinary::option_consume($options, "resource_type", "image");
     $version = Cloudinary::option_consume($options, "version");
     $format = Cloudinary::option_consume($options, "format");
     $cloud_name = Cloudinary::option_consume($options, "cloud_name", Cloudinary::config_get("cloud_name"));
     if (!$cloud_name) {
         throw new InvalidArgumentException("Must supply cloud_name in tag or in configuration");
     }
     $secure = Cloudinary::option_consume($options, "secure", Cloudinary::config_get("secure"));
     $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;
     }
     if (preg_match("/^https?:\\//i", $source)) {
         if ($type == "upload" || $type == "asset") {
             return $original_source;
         }
         $source = Cloudinary::smart_escape($source);
     } else {
         if ($format) {
             $source = $source . "." . $format;
         }
     }
     if ($secure && !$secure_distribution) {
         if ($private_cdn) {
             throw new InvalidArgumentException("secure_distribution not defined");
         } else {
             $secure_distribution = Cloudinary::SHARED_CDN;
         }
     }
     if ($secure) {
         $prefix = "https://" . $secure_distribution;
     } else {
         $crc = crc32($source);
         if ($crc < 0) {
             $crc += 4294967296;
         }
         $subdomain = $cdn_subdomain ? "a" . (fmod($crc, 5) + 1) . "." : "";
         $host = $cname ? $cname : ($private_cdn ? $cloud_name . "-" : "") . "res.cloudinary.com";
         $prefix = "http://" . $subdomain . $host;
     }
     if (!$private_cdn) {
         $prefix .= "/" . $cloud_name;
     }
     return preg_replace("/([^:])\\/+/", "\$1/", implode("/", array($prefix, $resource_type, $type, $transformation, $version ? "v" . $version : "", $source)));
 }
 echo "<div class='public_id'>" . $photo["public_id"] . "</div>";
 echo cl_image_tag($photo["public_id"], array_merge($thumbs_params, array("crop" => "fill")));
 ?>
         </a>
       
       <div class="less_info">
         <a href="#" class="toggle_info">More transformations...</a>
       </div>
       
       <div class="more_info">
         <a href="#" class="toggle_info">Hide transformations...</a>
         <table class="thumbnails">
           <?php 
 $thumbs = array(array("crop" => "fill", "radius" => 10), array("crop" => "scale"), array("crop" => "fit", "format" => "png"), array("crop" => "thumb", "gravity" => "face"), array("override" => true, "format" => "png", "angle" => 20, "transformation" => array("crop" => "fill", "gravity" => "north", "width" => 150, "height" => 150, "effect" => "sepia")));
 foreach ($thumbs as $params) {
     $merged_params = array_merge(\Cloudinary::option_consume($params, "override") ? array() : $thumbs_params, $params);
     echo "<td>";
     echo "<div class='thumbnail_holder'>";
     echo "<a target='_blank' href='" . cloudinary_url($photo["public_id"], $merged_params) . "'>" . cl_image_tag($photo["public_id"], $merged_params) . "</a>";
     echo "</div>";
     echo "<br/>";
     \PhotoAlbum\array_to_table($merged_params);
     echo "</td>";
 }
 ?>
           
         </table>
         
         <div class="note">             	
         	Take a look at our documentation of <a href="http://cloudinary.com/documentation/image_transformations" target="_blank">Image Transformations</a> for a full list of supported transformations.
         </div>	
 public static function cloudinary_url($source, &$options = array())
 {
     $type = Cloudinary::option_consume($options, "type", "upload");
     if ($type == "fetch" && !isset($options["fetch_format"])) {
         $options["fetch_format"] = Cloudinary::option_consume($options, "format");
     }
     $transformation = Cloudinary::generate_transformation_string($options);
     $resource_type = Cloudinary::option_consume($options, "resource_type", "image");
     $version = Cloudinary::option_consume($options, "version");
     $format = Cloudinary::option_consume($options, "format");
     $cloud_name = Cloudinary::option_consume($options, "cloud_name", Cloudinary::config_get("cloud_name"));
     if (!$cloud_name) {
         throw new InvalidArgumentException("Must supply cloud_name in tag or in configuration");
     }
     $secure = Cloudinary::option_consume($options, "secure", Cloudinary::config_get("secure"));
     $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"));
     $shorten = Cloudinary::option_consume($options, "shorten", Cloudinary::config_get("shorten"));
     $original_source = $source;
     if (!$source) {
         return $original_source;
     }
     if (preg_match("/^https?:\\//i", $source)) {
         if ($type == "upload" || $type == "asset") {
             return $original_source;
         }
         $source = Cloudinary::smart_escape($source);
     } else {
         $source = Cloudinary::smart_escape(rawurldecode($source));
         if ($format) {
             $source = $source . "." . $format;
         }
     }
     $shared_domain = !$private_cdn;
     if ($secure) {
         if (!$secure_distribution || $secure_distribution == Cloudinary::OLD_AKAMAI_SHARED_CDN) {
             $secure_distribution = $private_cdn ? $cloud_name . "-res.cloudinary.com" : Cloudinary::SHARED_CDN;
         }
         $shared_domain = $shared_domain || $secure_distribution == Cloudinary::SHARED_CDN;
         $prefix = "https://" . $secure_distribution;
     } else {
         $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 ($shared_domain) {
         $prefix .= "/" . $cloud_name;
     }
     if ($shorten && $resource_type == "image" && $type == "upload") {
         $resource_type = "iu";
         $type = "";
     }
     if (strpos($source, "/") && !preg_match("/^https?:\\//", $source) && !preg_match("/^v[0-9]+/", $source) && empty($version)) {
         $version = "1";
     }
     return preg_replace("/([^:])\\/+/", "\$1/", implode("/", array($prefix, $resource_type, $type, $transformation, $version ? "v" . $version : "", $source)));
 }
<?php

require 'main.php';
# You can add here your custom verification code
# Check for a valid Cloudinary response
$api_secret = Cloudinary::config_get("api_secret");
if (!$api_secret) {
    throw new \InvalidArgumentException("Must supply api_secret");
}
$existing_signature = \Cloudinary::option_consume($_POST, "signature");
$to_sign = array('public_id' => $_POST['public_id'], 'version' => $_POST['version']);
$calculated_signature = \Cloudinary::api_sign_request($to_sign, $api_secret);
if ($existing_signature == $calculated_signature) {
    # Create a model record using the data received (best practice is to save locally
    # only data needed for reaching the image on Cloudinary - public_id and version;
    # and fields that might be needed for your application (e.g.,), width, height)
    $photo = \PhotoAlbum\create_photo_model($_POST);
} else {
    error_log("Received signature verficiation failed (" . $existing_signature . " != " . $calculated_signature . "). data: " . \PhotoAlbum\ret_var_dump($_POST));
}