<?
	require 'CloudFront.php';
	
	// your AWS/CloudFront keys go here
	$keyId          = ""; 
	$secretKey      = "";
	$distributionId = "";
	
	$key = ""; // String representing the existing CloudFront object to invalidate
	
	$cf  = new CloudFront($keyId, $secretKey, $distributionId);
?>
<html>
<head>
<style> textarea {width:100%; height:600px; font:12px/16px consolas;} </style>
</head>
<body>
	Key: <?php 
echo $key;
?>
<br/>
	<hr/>
	CF call:<br/>
	<?/* 
	 	Passing "true" to enable debugging for the purpose of this example. 
		This will render the XML response.
	*/?>
	<textarea><?php 
echo $cf->invalidate($key, true);
?>
</textarea>
Ejemplo n.º 2
0
 public static function cdnPurge()
 {
     $file = JRequest::getVar('purge');
     $cdn = JRequest::getVar('cdn');
     $result = false;
     if ($cdn == 'cloudfront') {
         $keys = JRequest::getVar('keys', '');
         list($accessKeyId, $secretKey, $distributionId) = explode('::', $keys);
         if ($accessKeyId && $secretKey && $distributionId) {
             require_once self::pluginLocation(true) . 'jbetolo/CloudFront.php';
             $cf = new CloudFront($accessKeyId, $secretKey, $distributionId);
             $result = $cf->invalidate($file);
         }
     } else {
         if ($cdn == 'maxcdn') {
             require_once self::pluginLocation(true) . 'jbetolo/xmlrpc/xmlrpc.inc';
             date_default_timezone_set('America/Los_Angeles');
             $cur = date('c');
             $keys = JRequest::getVar('keys', '');
             list($apiKey, $apiId) = explode('::', $keys);
             $namespace = 'cache';
             $method = 'purge';
             $authString = hash('sha256', $cur . ':' . $apiKey . ':' . $method);
             $f = new xmlrpcmsg("{$namespace}.{$method}", array(php_xmlrpc_encode($apiUserId), php_xmlrpc_encode($authString), php_xmlrpc_encode($cur), php_xmlrpc_encode($file)));
             $c = new xmlrpc_client("/xmlrpc/cache", "api.netdna.com", 80, 'http11');
             $result =& $c->send($f);
         }
     }
     return JText::_($result ? 'PLG_SYSTEM_JBETOLO_CDN_PURGE_SUCCESS' : 'PLG_SYSTEM_JBETOLO_CDN_PURGE_FAILED');
 }
function yss_generate_player($player, $video, $width, $height)
{
    global $codes, $yss_plugins, $yss_master_counter;
    $yss_master_counter++;
    $distribution = $video->distribution;
    $distribution = json_decode($distribution);
    $stream = FALSE;
    $url = '';
    $valid = time() + YSS_EXPIRE_TIME_LIMIT;
    $return = '';
    $yss_cloudfront = new CloudFront();
    if (isset($distribution->streaming) && $distribution->streaming) {
        $streamer = $distribution->streaming;
        // streamer
        // resource magic
        // FLV?
        $resource = str_replace('.flv', '', $video->resource_path);
        $url = $yss_cloudfront->generateSecureUrl($resource, $valid);
        // streamer
        $streamer = 'rtmp://' . $streamer . '/cfx/st';
        // non standard code required
        switch ($player) {
            case 'custom':
                $url = yss_generate_yss_url($video, FALSE);
                $return = yss_custom_player($url, $height, $width, $streamer);
                break;
            case 'fv-wordpress-flowplayer':
                if (strpos($video->resource_path, '.flv')) {
                    $url = str_replace(array('=', '&'), array('%3D', '%26'), $url);
                    $return = '
<div id="streams_' . str_replace('.', '_', $resource) . '" style="display:block;width:' . $width . 'px;height:' . $height . 'px;"></div>
<script type="text/javascript">' . "\nflowplayer('streams_" . str_replace('.', '_', $resource) . "', '" . PLAYER . " ', {\n\tclip:  {\n\t\tautoPlay: false,\n\t\tautoBuffering: true,\n\t\t\n\t\turl: '" . $url . "',\n\t\tprovider: 'rtmp'\n\t},\n\tplugins: {\n\t\trtmp: {\n\t\t\turl: '" . YSS_RESOURCES . "/flowplayer.rtmp-3.2.3.swf',\n\t\t\tnetConnectionUrl: '" . $streamer . "'\n\t\t}\n\t}\n});\n</script>";
                } else {
                    echo 'YSS does not support non FLV files in a streaming distribution under FlowPlayer. It just does not work!';
                }
                break;
            case 'jw-player-plugin-for-wordpress':
                if (isset($distribution->download) && $distribution->download) {
                    $download = $distribution->download;
                    $durl = 'https://' . $download . '/' . $video->resource_path;
                    $durl = $yss_cloudfront->generateSecureUrl($durl, $valid);
                } else {
                    $durl = yss_generate_yss_url($video, FALSE);
                }
                $return = '
<div id="mediaspace_' . str_replace('.', '_', $resource) . '_' . $yss_master_counter . '">This text will be replaced</div>
<script type="text/javascript">' . "\n\tjwplayer('mediaspace_" . str_replace('.', '_', $resource) . '_' . $yss_master_counter . "').setup({\n\t\tflashplayer:\t'" . JWPLAYER_FILES_URL . "/player/player.swf',\n\t\tcontrolbar:\t\t'bottom',\n\t\twidth:\t\t\t'" . $width . "',\n\t\theight:\t\t\t'" . $height . "',\n\t\tconfig:\t\t\t'" . JWPLAYER_FILES_URL . '/configs/' . get_option('jwplayermodule_default') . ".xml',\n\t\tmodes: [\n\t\t\t{\n\t\t\t\ttype: 'flash',\n\t\t\t\tsrc: '" . JWPLAYER_FILES_URL . "/player/player.swf',\n\t\t\t\tconfig: {\n\t\t\t\t\tfile: '" . $url . "',\n\t\t\t\t\tstreamer: '" . $streamer . "',\n\t\t\t\t\tprovider: 'rtmp'\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'html5',\n\t\t\t\tconfig: {\n\t\t\t\t\tfile: '" . $durl . "'\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: 'flash',\n\t\t\t\tsrc: '" . JWPLAYER_FILES_URL . "/player/player.swf',\n\t\t\t\tconfig: {\n\t\t\t\t\tfile: '" . $durl . "'\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t});\n</script>\n";
                break;
            default:
                $return = '<p>' . __('No Player Selected', 'yss') . '</p>';
        }
    } else {
        if (isset($distribution->download) && $distribution->download) {
            $download = $distribution->download;
            // download dist
            $url = 'https://' . $download . '/' . $video->resource_path;
            $url = $yss_cloudfront->generateSecureUrl($url, $valid);
            if ($yss_plugins[$player]['encode']) {
                $url = explode('?', $url);
                $url[1] = urlencode($url[1]);
                $url = implode('?', $url);
            }
            $return = sprintf($codes[$player], $url, $width, $height);
        } else {
            // s3
            if ($player == 'custom') {
                $url = yss_generate_yss_url($video, FALSE);
                $return = yss_custom_player($url, $height, $width);
            } else {
                $url = yss_generate_yss_url($video);
                $return = sprintf($codes[$player], $url, $width, $height);
            }
        }
    }
    return $return;
}
<?
require 'CloudFront.php';

// your AWS/CloudFront keys go here
$keyId = "";
$secretKey = "";
$distributionId = "";

$key = ""; // String representing the existing CloudFront object to invalidate

$cf = new CloudFront($keyId, $secretKey, $distributionId);
$cf->invalidate($key);

?>
<html>
<head>
    <style> textarea {
        width: 100%;
        height: 600px;
        font: 12px/16px consolas;
    } </style>
</head>
<body>
Key: <?php 
echo $key;
?>
<br/>
<hr/>
CF call:<br/>
<!--Passing "true" to enable debugging for the purpose of this example.
This will render the XML response.-->