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 wp_nav_menu_object($sorted_menu_items, $args = array())
 {
     $modified_menu_items = array();
     foreach ($sorted_menu_items as $item) {
         if (ym_user_has_access($item->object_id) || $item->object == 'custom') {
             $modified_menu_items[] = $item;
         }
     }
     return $modified_menu_items;
 }
function ym_membership_content_page($with_boxes = false, $with_snippets = TRUE, $with_expires = FALSE, $show = 'posts,bundles,premium')
{
    get_currentuserinfo();
    global $current_user, $wpdb, $ym_res;
    $snippet_length = 200;
    $max_loops = 30;
    $html = '';
    $membership_level = ym_get_user_package_type($current_user->ID);
    $posts = false;
    $show = explode(',', $show);
    if (in_array('posts', $show)) {
        if ($pp = ym_render_my_purchased_posts($current_user->ID, false, true, $with_expires, $with_snippets)) {
            if ($with_boxes) {
                $html .= ym_start_box(__('My Purchased Posts', 'ym'));
            }
            $html .= $pp;
            if ($with_boxes) {
                $html .= ym_end_box();
            }
        }
    }
    if (in_array('bundles', $show)) {
        // bundle
        if ($bundles = ym_render_my_purchased_bundles($current_user->ID, $with_expires, TRUE, $with_snippets)) {
            if ($with_boxes) {
                $html .= ym_start_box(__('My Purchased Bundles', 'ym'));
            }
            $html .= $bundles;
            if ($with_boxes) {
                $html .= ym_end_box();
            }
        }
    }
    if (in_array('premium', $show)) {
        $sql = 'SELECT DISTINCT(ID), post_title, post_date, post_content
				FROM
					' . $wpdb->posts . ' p
					JOIN ' . $wpdb->postmeta . ' pm ON (
						p.ID = pm.post_id
						AND p.post_status = "publish"
						AND pm.meta_key = "_ym_account_type"
						AND pm.meta_value LIKE "%' . $membership_level . '%"
						AND post_type = "post"
					)
				ORDER BY post_date DESC';
        $results = $wpdb->get_results($sql);
        $loops = 0;
        if ($members_pages = count($results)) {
            foreach ($results as $id => $obj) {
                if (!ym_user_has_access($obj->ID)) {
                    $membership_pages--;
                    continue;
                }
                $published = date(YM_DATEFORMAT, strtotime($obj->post_date));
                $full_content = apply_filters('the_content', $obj->post_content);
                $title = $obj->post_title;
                if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
                    $title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($title);
                    $full_content = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($full_content);
                }
                $row = '<tr>
				<td style="border-top: 1px solid silver;">
					<div style="margin-bottom: 5px;"><a href="' . get_permalink($obj->ID) . '">' . $title . '</a></div>
					';
                if ($with_snippets) {
                    $content = substr(strip_tags($full_content), 0, $snippet_length);
                    //$content = preg_replace("'\[/?\s?private\s?\]'i",'', $content);
                    $ending = strlen($full_content) > strip_tags($snippet_length) ? '...' : '';
                    $row .= '<div style="font-size: 10px; margin-bottom: 5px;">' . $content . $ending . '</div>';
                }
                $row .= '
				</td>
				<td style="vertical-align: top; border-top: 1px solid silver;">' . $published . '</td>
			</tr>';
                $posts .= $row;
                $loops++;
                if ($loops >= $max_loops) {
                    break;
                }
            }
        }
        $table_intro = 'Showing the most recent ' . $loops . ' posts of a total ' . $members_pages . ' available to you.';
        $html .= $ym_res->members_content_divider_html;
        if ($with_boxes) {
            $html .= ym_start_box(__('Premium Content', 'ym'));
        }
        $html .= '	<div class="premium_content_intro">' . __('Your membership level is:', "ym") . ' <strong>' . $membership_level . '</strong>. 	
				' . __('You have access to a total of', "ym") . ' ' . $members_pages . ' ' . __('premium', 'ym') . ' ' . ($members_pages == 1 ? __('post', 'ym') : __('posts', 'ym')) . ' 
			</div>';
        if ($members_pages > 0) {
            $html .= $table_intro;
            $html .= '<div style="padding-top: 10px; margin-bottom: 10px;">
				<table style="width: 100%" cellspacing="0" cellpadding="2">
				<tr>
					<th style="text-align: left;">Post Title</th>
					<th style="width: 160px; text-align: left;">Published</th>
				</tr>
					' . $posts . '
			</table></div>';
        }
        if ($with_boxes) {
            $html .= ym_end_box();
        }
    }
    return $html;
}
Esempio n. 4
0
function ym_delete_enclosure($data)
{
    global $post;
    if (ym_user_has_access($post->ID)) {
        return $data;
    } else {
        return '';
    }
}
function ym_buy_button_content_filter($content)
{
    if (!is_user_logged_in()) {
        return $content;
    }
    if (isset($_POST['ym_buy_button_content']) && isset($_POST['ym_buy_button_args'])) {
        $code = '[ym_buy_content ';
        $args = json_decode(stripslashes($_POST['ym_buy_button_args']));
        if ($args) {
            foreach ($args as $name => $val) {
                $code .= $name . '="' . $val . '" ';
            }
        }
        $code .= ' ]';
        return $code;
    } else {
        global $post_id;
        if (ym_user_has_access($post_id)) {
            return $content;
        }
        if (FALSE !== strpos($content, '[ym_buy_content ') || FALSE !== strpos($content, '[ym_buy_content]')) {
            if (FALSE !== ($start = strpos($content, '[private'))) {
                $mid = strpos($content, '[/private', $start);
                $end = strpos($content, ']', $mid);
                $end++;
                $bit_to_remove = substr($content, $start, $end - $start);
                $content = str_replace($bit_to_remove, '', $content);
            }
        }
        return $content;
    }
}
function ym_download_file($download_id)
{
    get_currentuserinfo();
    global $wpdb, $current_user, $ym_upload_root;
    $allow_download = true;
    if ($download = ym_get_download($download_id)) {
        if ($download->members) {
            $allow_download = false;
            if ($current_user->ID) {
                if (!isset($current_user->caps['administrator'])) {
                    $posts = ym_get_download_posts($download_id);
                    foreach ($posts as $post) {
                        if (ym_user_has_access($post->post_id)) {
                            $allow_download = true;
                            break;
                        }
                    }
                } else {
                    $allow_download = true;
                }
            }
        }
        if ($allow_download) {
            $abs_file = ym_get_abs_file($download->filename);
            if (file_exists($abs_file)) {
                set_time_limit(0);
                ini_set('memory_limit', -1);
                $file_name = strrpos($download->filename, '/');
                $loc = substr($download->filename, 0, $file_name);
                $file_name = substr($download->filename, $file_name + 1);
                @ym_log_transaction(YM_DOWNLOAD_STARTED, $download->filename, $current_user->ID);
                header("Pragma: public");
                // required
                header("Expires: 0");
                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                header("Cache-Control: private", false);
                // required for certain browsers
                header("Content-type: application/force-download");
                header("Content-Transfer-Encoding: Binary");
                header("Content-length: " . @filesize($abs_file));
                header("Content-disposition: attachment; filename=\"" . $file_name . "\"");
                //readfile($abs_file);
                flush();
                $file = fopen($abs_file, "rb");
                while (!feof($file)) {
                    // send the current file part to the browser
                    print fread($file, 8192);
                    flush();
                }
                fclose($file);
                @ym_log_transaction(YM_DOWNLOAD_COMPLETED, $download->filename, $current_user->ID);
                exit;
            } else {
                echo __('You can not download this file because it does not exist. Please notify the Administrator.', 'ym');
                exit;
            }
        } else {
            echo __('You can not download this file because you do not have access', 'ym');
            exit;
        }
    } else {
        die;
    }
}