function yss_shortcode($atts) { global $codes; $return = ''; $allow_play = false; $id = isset($atts['id']) ? $atts['id'] : ''; $player = isset($atts['plr']) ? $atts['plr'] : get_option('yss_playerofchoice'); $width = isset($atts['width']) ? $atts['width'] : 640; $height = isset($atts['height']) ? $atts['height'] : 380; if (!$id) { //error out as no Video ID return '<p>' . __('No video ID specified', 'yss') . '</p>'; } $video = yss_get($id); if (!$video) { return '<p>' . __('The video requested could not be found', 'yss') . '</p>'; } var_dump($video); //access_check if (!$video->members && !$video->account_types) { $allow_play = true; //no access restriction } else { //priority given to ac check if ($video->account_types) { if ($acs = explode('||', $video->account_types)) { $ac = strtolower(ym_get_user_account_type()); if (in_array($ac, $acs)) { $allow_play = true; } } } //if ac check fails or is not used and post comparison is then use this... if ($video->members && !$allow_play) { $posts = yss_get_video_post_assoc($id); foreach ($posts as $post) { if (ym_user_has_access($post->post_id)) { $allow_play = true; break; } } } } //if the logic above deems access should be granted then... if ($allow_play) { $return = yss_generate_player($player, $video, $width, $height); } else { if ($message = get_option('yss_no_access_message')) { //else if the admin has put in a no access message this appears $return = $message; } } return $return; }
function yss_s3_edit($id = false) { global $wpdb, $yss_post_assoc; $checked = array(); $s3file = yss_get($id); $sql = 'SELECT ID, post_title FROM ' . $wpdb->posts . ' WHERE post_status = "publish" AND post_type IN ("page","post") ORDER BY post_title'; $posts = $wpdb->get_results($sql); if ($id) { $sql = 'SELECT post_id FROM ' . $yss_post_assoc . ' WHERE s3_id = ' . $id; $results = $wpdb->get_results($sql); foreach ($results as $result) { $checked[] = $result->post_id; } } echo ym_start_box($id ? 'Edit Video' : 'Add Video'); if (!$id) { require_once YSS_CLASSES_DIR . 'S3.php'; $s3 = new S3(); $s3->setAuth(get_option('yss_user_key'), get_option('yss_secret_key')); } echo ' <table class="widefat form-table" style="width: 100%;" cellspacing="10"> <tr valign="top"> <td> ' . __('S3 Bucket/file', "ym") . ' </td> <td>'; if (!$id) { echo ' <select name="s3_file_select"> '; foreach ($s3->listBuckets() as $bucket) { $thisbucket = $s3->getBucket($bucket); foreach ($thisbucket as $file) { echo '<option '; if ($s3file->bucket . '/' . $s3file->resource_path == $bucket . '/' . $file['name']) { echo 'selected="selected"'; } echo '>' . $bucket . '/' . $file['name'] . '</option>'; } } echo ' </select> '; } else { echo $s3file->bucket . '/' . $s3file->resource_path; echo '<input type="hidden" name="s3_file_select" value="' . $s3file->bucket . '/' . $s3file->resource_path . '" />'; } echo ' </td> </tr> <tr valign="top"> <td> ' . __('Your Members Package Types access', "ym") . ' <div style="font-size: 10px; color: gray; margin-top: 10px;">Your videos can be protected by account type here. If none of the boxes are checked then it will fall back to the next section (post protection)</div> </td><td>'; echo ' <div>'; if ($data = get_option('ym_account_types')) { $types = $data->types; $ac_checked = array(); if ($selected = @$s3file->account_types) { $ac_checked = explode('||', $selected); } foreach ((array) $types as $type) { $checked_string = ''; if (in_array($type, $ac_checked)) { $checked_string = 'checked="checked"'; } echo ' <div class="ym_setting_list_item"> <label> <input type="checkbox" class="checkbox" name="account_types[]" value="' . $type . '" ' . $checked_string . ' /> ' . __($type) . ' </label> </div>'; } } else { echo '<div>The system is unable to find any YM account types. Is there a problem with the install?</div>'; } echo '</div>'; echo ' </td> </tr> <tr valign="top"> <td> ' . __('Restrict access by post/page?', "ym") . ' <input type="checkbox" name="memberonly" ' . (@$s3file->members ? "checked='checked'" : '') . ' /> (Check to activate) <div style="font-size: 10px; color: gray; margin-top: 10px;">If the above account type check fails or you choose not to use it then you can optionally use this section. This will check access against a number of posts or pages and if at least one has access then the video will be shown.<br /><br />If the restrict access checkbox is unticked then YSS will assume that the video should remain unprotected (if you are not using the account type protection)</div> </td> <td> <br /><select name="link_to_post_id[]" multiple size=10 style="height: 250px; width: 450px;">'; foreach ($posts as $row) { $selected = in_array($row->ID, $checked) ? 'selected="selected"' : ''; echo '<option value="' . $row->ID . '" ' . $selected . ' >' . $row->post_title . '</option>'; } echo ' </select> </td> </tr>'; echo ' </table> <p class="submit"> <div style="float: right;"> <input type="submit" class="button" name="submit_edit_s3" value="' . __('Save', 'yss') . '" /> </div> <input type="submit" value="' . __('Back', 'yss') . '" /> <div class="ym_clear"> </div> </p> <input type="hidden" name="task" value="save" /> <input type="hidden" name="s3s_id" value="' . @$s3file->id . '" /> '; echo ym_end_box(); }
function yss_s3_distribution($type, $id) { global $ym_formgen, $yss_cloudfront, $yss_db, $wpdb; // file details $s3file = yss_get($id); if ($_POST) { // here we go $distro = $_POST['distro']; list($can, $oai, $bucket, $file, $domain, $type) = explode('|', $distro); $packet = array('type' => 'CanonicalUser', 'id' => $can, 'name' => 'CloudFront Origin Access Identity ' . $oai, 'permission' => 'READ'); $acp = array(); require_once YSS_CLASSES_DIR . 'S3.php'; $s3 = new S3(); $s3->setAuth(get_option('yss_user_key'), get_option('yss_secret_key')); //get existing and merge $acp = $s3->getAccessControlPolicy($bucket, $file); $acp['acl'][] = $packet; if ($s3->setAccessControlPolicy($bucket, $file, $acp)) { $acp = $s3->getAccessControlPolicy($bucket, $file); // store $distribution = json_decode($s3file->distribution); if ($type == 'stream') { $distribution->streaming = $domain; } else { $distribution->download = $domain; } $distribution = json_encode($distribution); $sql = 'UPDATE ' . $yss_db . ' SET distribution = \'' . $distribution . '\' WHERE id = ' . $id; $wpdb->query($sql); echo '<div id="message" class="updated"><p>Permissions updated</p></div>'; yss_s3_list(); return; } else { echo '<div id="message" class="error"><p>Permissions update failed</p></div>'; } } if ($type == 'stream') { $data = $yss_cloudfront->get_streaming(); } else { $data = $yss_cloudfront->get_distribution(); } if (is_array($data)) { $test = array_keys($data); if ($test[0] != '0') { $data = array($data); } } if (is_array($data)) { echo ym_box_top('Deploy'); echo ' <form action="" method="post"> <fieldset> <p>You can select a distribution to expose the file, ' . $s3file->bucket . '/' . $s3file->resource_path . ' onto</p> <table class="form-table"> '; $items = array('blank' => 'Select'); foreach ($data as $item) { $bucket = $item['S3Origin']['DNSName']['value']; list($bucket, $null) = explode('.', $bucket, 2); $enabled = $item['Enabled']['value']; if ($enabled == 'true' && $s3file->bucket == $bucket) { // Distribution is enabled and is for this bucket matches $status = $item['Status']['value']; $domain = $item['DomainName']['value']; $oai = $item['S3Origin']['OriginAccessIdentity']['value']; list($null, $nulm, $oai) = explode('/', $oai); // oai needs canonical $canonical = $yss_cloudfront->get_oai_canonical($oai); $value = $canonical . '|' . $oai . '|' . $bucket . '|' . $s3file->resource_path . '|' . $domain . '|' . $type; //echo '<option value="' . $value . '">' . $domain . '</option>'; $items[$value] = $domain; } } $ym_formgen->render_combo_from_array_row('Distribution', 'distro', $items, '', 'Which Distribution to expose this file on'); echo ' </table> <p class="submit"> <input type="submit" value="Deploy!" /> </p> </fieldset> </form> '; echo ym_box_bottom(); } else { echo '<div id="message" class="error"><p>Failed to load Distributions or none available</p></div>'; } }