/**
  * @return string
  */
 public function process()
 {
     if (isset($_POST['SourceURL'])) {
         $sourceURL = $_POST['SourceURL'];
         $bIsCloudinary = CloudinaryVideo::isCloudinary($sourceURL);
         $bIsYoutube = YoutubeVideo::is_youtube($sourceURL);
         $bIsVimeo = VimeoVideo::is_vimeo($sourceURL);
         $video = null;
         if ($bIsYoutube || $bIsVimeo || $bIsCloudinary) {
             if ($bIsCloudinary) {
                 $filterClass = 'CloudinaryVideo';
                 $fileType = 'video';
             } elseif ($bIsYoutube) {
                 $filterClass = 'YoutubeVideo';
                 $fileType = 'youtube';
             } else {
                 $filterClass = 'VimeoVideo';
                 $fileType = 'vimeo';
             }
             $funcForID = $bIsYoutube ? 'youtube_id_from_url' : 'vimeo_id_from_url';
             $funcForDetails = $bIsYoutube ? 'youtube_video_details' : 'vimeo_video_details';
             if ($bIsCloudinary) {
                 $arr = Config::inst()->get('CloudinaryConfigs', 'settings');
                 if (isset($arr['CloudName']) && !empty($arr['CloudName'])) {
                     $arrPieces = explode('/', $sourceURL);
                     $arrFileName = array_slice($arrPieces, 7);
                     $fileName = implode('/', $arrFileName);
                     $publicID = substr($fileName, 0, strrpos($fileName, '.'));
                     $video = $filterClass::get()->filterAny(array('URL' => $sourceURL, 'PublicID' => $publicID))->first();
                     if (!$video) {
                         $api = new \Cloudinary\Api();
                         $resource = $api->resource($publicID, array("resource_type" => "video"));
                         //qoogjqs9ksyez7ch8sh5
                         $json = json_encode($resource);
                         $arrResource = Convert::json2array($json);
                         $video = new $filterClass(array('Title' => $arrResource['public_id'] . '.' . $arrResource['format'], 'PublicID' => $arrResource['public_id'], 'Version' => $arrResource['version'], 'URL' => $arrResource['url'], 'SecureURL' => $arrResource['secure_url'], 'FileType' => $arrResource['resource_type'], 'FileSize' => $arrResource['bytes'], 'Format' => $arrResource['format'], 'Signature' => isset($arrResource['signature']) ? $arrResource['signature'] : ''));
                         $video->write();
                     }
                 }
             } else {
                 $video = $filterClass::get()->filter('URL', $sourceURL)->first();
                 if (!$video) {
                     $sourceID = $filterClass::$funcForID($sourceURL);
                     $details = $filterClass::$funcForDetails($sourceID);
                     $video = new $filterClass(array('Title' => $details['title'], 'Duration' => $details['duration'], 'URL' => $sourceURL, 'secure_url' => $sourceURL, 'PublicID' => $sourceID, 'FileType' => $fileType));
                     $video->write();
                 }
             }
             if ($video) {
                 $this->value = $iVideoID = $video->ID;
                 $file = $this->customiseCloudinaryFile($video);
                 return Convert::array2json(array('colorselect_url' => $file->UploadFieldImageURL, 'thumbnail_url' => $file->UploadFieldThumbnailURL, 'fieldname' => $this->getName(), 'id' => $file->ID, 'url' => $file->URL, 'buttons' => $file->UploadFieldFileButtons, 'more_files' => $this->canUploadMany(), 'field_id' => $this->ID()));
             }
         }
     }
     return Convert::array2json(array());
 }
 public function deleteAsset(Event $event)
 {
     $settings = craft()->plugins->getPlugin('npCloudinary')->getSettings();
     if ($settings['removeIfDeleted']) {
         try {
             $api = new \Cloudinary\Api();
             $api->delete_resources([$this->getAssetHandle($event->params['asset'])]);
             return true;
         } catch (\Cloudinary\Error $e) {
             $this->handleError($e->getMessage());
         } catch (\Cloudinary\Api\AuthorizationRequired $e) {
             $this->handleError($e->getMessage());
         }
     }
 }
     */
    return function (UploadedFileInterface $photo, $memberData) use($settings, $session) {
        if ($photo->getError() !== UPLOAD_ERR_OK) {
            return $memberData;
        }
        $allowedTypes = ['image/jpeg', 'image/png'];
        if (!in_array($photo->getClientMediaType(), $allowedTypes)) {
            throw new InvalidArgumentException('We only accept jpg and png image');
        }
        $ext = strtolower(pathinfo($photo->getClientFilename(), PATHINFO_EXTENSION));
        $cdnTargetPath = 'phpindonesia/' . $settings['mode'] . '/';
        $newFileName = $session->get('user_id') . '-' . date('YmdHis');
        Cloudinary\Uploader::upload($photo->file, ['public_id' => $cdnTargetPath . $newFileName, 'tags' => ['user-avatar']]);
        $memberData['photo'] = $newFileName . '.' . $ext;
        if ($session->get('photo')) {
            $api = new Cloudinary\Api();
            $publicId = str_replace('.' . $ext, '', $session->get('photo'));
            $api->delete_resources($cdnTargetPath . $publicId, ['public_id' => $cdnTargetPath . $newFileName, 'tags' => ['user-avatar']]);
            $session->set('photo', $memberData['photo']);
        }
        return $memberData;
    };
};
/**
 * Setup mailer container
 *
 * TODO: will replaced with PHPMailer
 */
$container['mailer'] = function ($container) {
    $smtp_account = $container->get('settings')['smtp'];
    $transport = null;
 /**
  * Test image deletion
  *
  * @return void
  * @author Andrew Lowther <*****@*****.**>
  **/
 public function testCloudinaryImageDeletion()
 {
     $api = new \Cloudinary\Api();
     $result = $api->delete_resources(array('test.png'));
     $this->assertTrue(is_a($result, 'Cloudinary\\Api\\Response'));
 }
Пример #5
0
 public function tearDown()
 {
     Curl::$instance = new Curl();
     $api = new \Cloudinary\Api();
     $api->delete_resources_by_tag($this->tag);
 }
Пример #6
0
 function test_upload_preset()
 {
     // should support unsigned uploading using presets
     $api = new \Cloudinary\Api();
     $preset = $api->create_upload_preset(array("folder" => "upload_folder", "unsigned" => TRUE));
     $result = \Cloudinary\Uploader::unsigned_upload("tests/logo.png", $preset["name"]);
     $this->assertRegExp('/^upload_folder\\/[a-z0-9]+$/', $result["public_id"]);
     $api->delete_upload_preset($preset["name"]);
 }
<?php

require 'bootstrap.php';
set_time_limit(0);
\Cloudinary::config($container['settings']['cloudinary']);
$api = new \Cloudinary\Api();
$api->delete_resources_by_tag('user-avatar');
Пример #8
0
          allow uploading directly from the browser to your Cloudinary account -->
    <?php 
$unsigned = isset($_GET["unsigned"]) && $_GET["unsigned"] == "1";
?>
    <div id='direct_upload'>
      <h1>Direct <?php 
if ($unsigned) {
    echo "unsigned ";
}
?>
upload from the browser</h1>
      <form>
      <?php 
if ($unsigned) {
    # For the sake of simplicity of the sample site, we generate the preset on the fly. It only needs to be created once, in advance.
    $api = new \Cloudinary\Api();
    $upload_preset = "sample_" . substr(sha1(Cloudinary::config_get("api_key") . Cloudinary::config_get("api_secret")), 0, 10);
    try {
        $api->upload_preset($upload_preset);
    } catch (\Cloudinary\Api\NotFound $e) {
        $api->create_upload_preset(array("name" => $upload_preset, "unsigned" => TRUE, "folder" => "preset_folder"));
    }
    # The callback URL is set to point to an HTML file on the local server which works-around restrictions
    # in older browsers (e.g., IE) which don't full support CORS.
    echo cl_unsigned_image_upload_tag('test', $upload_preset, array("tags" => "direct_photo_album", "callback" => $cors_location, "html" => array("multiple" => true)));
} else {
    # The callback URL is set to point to an HTML file on the local server which works-around restrictions
    # in older browsers (e.g., IE) which don't full support CORS.
    echo cl_image_upload_tag('test', array("tags" => "direct_photo_album", "callback" => $cors_location, "html" => array("multiple" => true)));
}
?>
Пример #9
0
    <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls">
        <div class="slides"></div>
        <h3 class="title"></h3>
        <a class="prev">‹</a>
        <a class="next">›</a>
        <a class="close">×</a>
        <a class="play-pause"></a>
        <ol class="indicator"></ol>
    </div>

    <!-- Page Content -->
    <div class="container">
        <div id="links">
        <?php 
$api = new \Cloudinary\Api();
$result = $api->resources(array("max_results" => "500", "type" => "upload", "prefix" => "concert/"));
foreach ($result["resources"] as $photo) {
    ?>
            <a href="<?php 
    echo $photo["url"];
    ?>
" title="photo">
                <?php 
    echo cl_image_tag($photo["public_id"] . ".jpg", array("crop" => "scale", "width" => 0.04));
    echo "\n";
    ?>
            </a>
            <?php 
}
?>
Пример #10
0
 public function tearDown()
 {
     $api = new \Cloudinary\Api();
     $api->delete_resources_by_tag($this->tag);
 }
Пример #11
0
 function test_overwrite_upload()
 {
     $api = new \Cloudinary\Api();
     $public_id = "api_test_overwrite";
     $api->delete_resources($public_id);
     $resource = \Cloudinary\Uploader::upload("tests/logo.png", array("public_id" => $public_id));
     $this->assertArrayHasKey("etag", $resource, "Should return an etag when uploading a new resource");
     $resource = \Cloudinary\Uploader::upload("tests/logo.png", array("public_id" => $public_id, "overwrite" => false));
     $this->assertArrayNotHasKey("etag", $resource, "Should not return an etag when uploading a existing resource with overwrite=false");
     $this->assertArrayHasKey("existing", $resource, "Should return 'existing' when uploading a existing resource with overwrite=false");
     $resource = \Cloudinary\Uploader::upload("tests/logo.png", array("public_id" => $public_id, "overwrite" => true));
     $this->assertArrayHasKey("etag", $resource, "Should return an etag when uploading an existing resource with overwrite=true");
     $api->delete_resources($public_id);
 }
 if ($_FILES['photo']['error'] == UPLOAD_ERR_OK) {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime_type = finfo_file($finfo, $_FILES['photo']['tmp_name']);
     finfo_close($finfo);
     $ext = strtolower(pathinfo($_FILES['photo']['name'], PATHINFO_EXTENSION));
     $env_mode = $this->getContainer()->get('settings')['mode'];
     $cdn_upload_path = 'phpindonesia/' . $env_mode . '/';
     $new_fname = $_SESSION['MembershipAuth']['user_id'] . '-' . date('YmdHis');
     $options = ['public_id' => $cdn_upload_path . $new_fname, 'tags' => ['user-avatar']];
     if (in_array($mime_type, ['image/jpeg', 'image/png']) && $ext != 'php') {
         // Upload photo to CDN Cloudinary
         $photo = \Cloudinary\Uploader::upload($_FILES['photo']['tmp_name'], $options);
         $members_profiles['photo'] = $new_fname . '.' . $ext;
         // Delete old photo
         if ($_SESSION['MembershipAuth']['photo'] != null) {
             $api = new \Cloudinary\Api();
             $public_id = str_replace('.' . $ext, '', $_SESSION['MembershipAuth']['photo']);
             $options = ['public_id' => $cdn_upload_path . $new_fname, 'tags' => ['user-avatar']];
             $api->delete_resources($cdn_upload_path . $public_id, $options);
             $_SESSION['MembershipAuth']['photo'] = $members_profiles['photo'];
         }
     }
 }
 // Update profile data record
 $db->update('members_profiles', $members_profiles, array('user_id' => $_SESSION['MembershipAuth']['user_id']));
 $db->update('users', array('email' => trim($_POST['email']), 'province_id' => $_POST['province_id'], 'city_id' => $_POST['city_id'], 'area' => $area, 'modified' => date('Y-m-d H:i:s'), 'modified_by' => $_SESSION['MembershipAuth']['user_id']), array('user_id' => $_SESSION['MembershipAuth']['user_id']));
 // Handle social medias
 if (isset($_POST['socmeds']) && !empty($_POST['socmeds'])) {
     foreach ($_POST['socmeds'] as $item) {
         $row = array('user_id' => $_SESSION['MembershipAuth']['user_id'], 'socmed_type' => filter_var(trim($item['socmed_type']), FILTER_SANITIZE_STRING), 'account_name' => filter_var(trim($item['account_name']), FILTER_SANITIZE_STRING), 'account_url' => filter_var(trim($item['account_url']), FILTER_SANITIZE_STRING), 'created' => date('Y-m-d H:i:s'));
         if ($item['member_socmed_id'] == 0) {