Example #1
0
function tinypass_uninstall()
{
    tinypass_include();
    delete_option('tinypass_legacy');
    $storage = new TPStorage();
    $storage->deleteAll();
}
Example #2
0
/**
 * Save the post popup form
 */
function ajax_tp_saveEditPopup()
{
    if (!current_user_can('edit_posts')) {
        die;
    }
    if (!wp_verify_nonce($_REQUEST['tinypass_nonce'], 'tinypass_options')) {
        die('Security check failed');
    }
    tinypass_include();
    $storage = new TPStorage();
    $errors = array();
    $ss = $storage->getSiteSettings();
    $ps = $ss->validatePostSettings($_POST['tinypass'], $errors);
    $storage->savePostSettings($_POST['post_ID'], $ps);
    if (count($errors)) {
        echo "var a; tinypass.clearError(); ";
        foreach ($errors as $field => $msg) {
            echo "tinypass.doError('{$field}', \"{$msg}\");";
        }
        die;
    }
    $ps = $storage->getPostSettings($_POST['post_ID']);
    echo tinypass_post_options_summary($ps);
    die;
}
/**
 * Display the enable toggle on the page edit page
 */
function tinypass_page_options_display($post)
{
    tinypass_include();
    $storage = new TPStorage();
    $ps = $storage->getPostSettings($post->ID);
    ?>

	<?php 
    wp_nonce_field('tp-post-save-nonce', 'tp-post-save-nonce');
    ?>
	<input type="checkbox" name="tinypass[enabled]" id="tp_page_enabled" <?php 
    checked($ps->isEnabled());
    ?>
 ><label for="tp_page_enabled">&nbsp;Protect this page<label>

		<?php 
}
 public function validatePaySettings($form, &$errors)
 {
     $form = new NiceArray($form);
     $activeMode = $form['mode'];
     if ($activeMode == TPPaySettings::MODE_OFF) {
         $storage = new TPStorage();
         $ps = $storage->getPaywall($form['resource_id']);
         $ps->setMode(TPPaySettings::MODE_OFF);
         return $ps;
     } else {
         if ($activeMode != TPPaySettings::MODE_OFF) {
             if ($activeMode != TPPaySettings::MODE_METERED_LIGHT) {
                 if (empty($form['resource_name'])) {
                     $errors['resource_name'] = "Paywall name must no be empty";
                 }
             }
             if (!is_array($form['tags'])) {
                 $form['tags'] = array();
             }
             $form['tags'] = array_unique($form['tags']);
             $tags = array();
             foreach ($form['tags'] as $tag) {
                 if (term_exists($tag)) {
                     $tags[] = $tag;
                 } else {
                     $errors['tags' . $tag] = "Tag '{$tag}' does not exist.";
                 }
             }
             $form['tags'] = $tags;
             if (count($form['tags']) == 0) {
                 $errors['tags'] = "Tinypass should be configured for at least 1 tag.  No tags have been specified!";
             }
             for ($i = 1; $i <= 3; $i++) {
                 if ($form['po_en' . $i] == 0) {
                     unset($form["po_en{$i}"]);
                     unset($form["po_p{$i}"]);
                     unset($form["po_ap{$i}"]);
                     unset($form["po_ap_type{$i}"]);
                     unset($form["po_cap{$i}"]);
                     unset($form["po_st{$i}"]);
                     unset($form["po_et{$i}"]);
                     continue;
                 }
                 $p = $form['po_p' . $i];
                 if (!TPValidate::validatePrice($p)) {
                     $errors["po_p{$i}"] = _(TPValidate::PRICE_FAILED_MSG);
                 }
                 $ap = $form['po_ap' . $i];
                 if (!TPValidate::validateAccessPeriod($ap)) {
                     $errors["po_ap{$i}"] = _(TPValidate::ACCESS_PERIOD_FAILED_MSG);
                 }
             }
             if ($form['metered'] && $form->isValEnabled('metered')) {
                 if (!TPValidate::validateNumber($form['m_lp'])) {
                     $errors['m_lp'] = _('Lockout period' . TPValidate::NUMBER_FAILED_MSG);
                 }
             }
             //validate metered options
             if ($form['metered'] == 'time') {
                 if (!TPValidate::validateNumber($form['m_tp'])) {
                     $errors['m_tp'] = _('Preview trial period' . TPValidate::NUMBER_FAILED_MSG);
                 }
                 if (!TPValidate::validateNumber($form['m_lp'])) {
                     $errors['m_lp'] = _('Preview lockout period' . TPValidate::NUMBER_FAILED_MSG);
                 }
             } else {
                 if ($form['metered'] == 'count') {
                     if (!TPValidate::validateNumber($form['m_maa'])) {
                         $errors['m_maa'] = _('Preview number of views' . TPValidate::NUMBER_FAILED_MSG);
                     }
                     if (!TPValidate::validateNumber($form['m_lp'])) {
                         $errors['m_lp'] = _('Preview trial period' . TPValidate::NUMBER_FAILED_MSG);
                     }
                 }
             }
             if (isset($form['sub_page']) && $form['sub_page'] != '') {
                 foreach (array('sub_page', 'sub_page_success') as $name) {
                     $sub_path = $form[$name];
                     $page = get_page_by_path($sub_path, OBJECT, 'page');
                     if ($page == null) {
                         $errors[$name] = _(esc_js('Could not find valid page for "' . $sub_path . '"'));
                         $form[$name] = '';
                     } else {
                         $form[$name . "_ref"] = $page->ID;
                     }
                 }
                 if (isset($form['sub_page_ref']) && !isset($form['sub_page_success_ref'])) {
                     $errors['sub_page_success'] = "Confirmation page must be defined if dedicated page is created";
                 }
                 if (isset($form['sub_page_ref']) && isset($form['sub_page_success_ref'])) {
                     if ($form['sub_page_ref'] == $form['sub_page_success_ref']) {
                         $errors['sub_page_success'] = "Dedicated sign page and confirmation page must be different";
                     }
                 }
             }
         }
     }
     $ps = new TPPaySettings($form->toArray());
     return $ps;
 }
Example #5
0
function tinypass_meta_box_display($post)
{
    $storage = new TPStorage();
    $postSettings = $storage->getPostSettings($post->ID);
    tinypass_post_header_form($postSettings);
}
Example #6
0
function tinypass_paywalls_list()
{
    if (isset($_REQUEST['switch'])) {
        tinypass_switch_version();
        return;
    }
    $storage = new TPStorage();
    $pws = $storage->getPaywalls(true);
    if (count($pws) == 0) {
        wp_redirect(menu_page_url("TinyPassEditPaywall"));
    }
    ?>

	<div id = "poststuff">
		<div class="tp-settings">
			<h2><?php 
    _e('My Paywalls');
    ?>
</h2>
			<hr>

			<?php 
    foreach ($pws as $rid => $ps) {
        ?>
				<?php 
        tinypass_display_card($rid, $ps);
        ?>
			<?php 
    }
    ?>

			<br>
			<div class="buttons">
				<a class="button" href="admin.php?page=TinyPassEditPaywall&rid="><?php 
    _e("Add another");
    ?>
</a>
			</div>
		</div>

		<br><br>

	</div>


	<script>
		jQuery(function(){
			var $ = jQuery;
			$('.tp-slider').bind('click', function(event){
				$('.choice-selected', this).removeClass("choice-selected");
				var choice = $(event.target);
				choice.addClass('choice-selected');
				$("input", this).val(choice.parent().attr('val'));
				tinypass.enablePaywall($(this).parents("form"));
			})

			$('#tp-show-deleted').bind('click', function(event){
				$("#tp-deleted-paywalls").toggle();
				return false;
			})

		})
	</script>

<?php 
}
/**
 * This file is responsbile for confiuring, displaying, and saving
 * individual paywall settings.
 */
function tinypass_mode_settings()
{
    $storage = new TPStorage();
    $errors = array();
    $ps = null;
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    if (isset($_POST['_Submit'])) {
        if (!wp_verify_nonce($_REQUEST['_wpnonce'])) {
            wp_die(__('This action is not allowed'));
            check_admin_referer();
        }
        //Save the paywall
        $ss = $storage->getSiteSettings();
        $ps = $ss->validatePaySettings($_POST['tinypass'], $errors);
        if (count($errors) == 0) {
            $storage->savePaywallSettings($ss, $ps);
            $_REQUEST['msg'] = 'Your settings have been saved!';
        }
    }
    $edit = false;
    $ps = $storage->getPaywall('pw_config', true);
    ?>

	<div id="poststuff">
		<div class="tp-settings">

			<?php 
    if (!count($errors)) {
        ?>
				<?php 
        if (!empty($_REQUEST['msg'])) {
            ?>
					<div class="updated fade"><p><strong><?php 
            echo esc_html($_REQUEST['msg']);
            ?>
</strong></p></div>
				<?php 
        }
        ?>
			<?php 
    } else {
        ?>
				<div id="tp-error" class="error fade"></div>
			<?php 
    }
    ?>


			<div id="tp_mode4_panel" class="tp_mode_panel">
				<form action="" method="post" autocomplete="off">
					<?php 
    wp_nonce_field();
    ?>
					<input class="tp_mode" name="tinypass[mode]" type="hidden" value="<?php 
    echo esc_attr(TPPaySettings::MODE_METERED_LIGHT);
    ?>
">
					<div style="float:right">
						<input type="hidden" readonly="true" name="tinypass[resource_id]" value="<?php 
    echo esc_attr($ps->getResourceId());
    ?>
">
						<input type="hidden" readonly="true" name="tinypass[resource_name]" value="na">
						<input type="hidden" readonly="true" name="tinypass[en]" value="<?php 
    echo esc_attr($ps->getEnabled());
    ?>
">
					</div>
					<?php 
    $num = 0;
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Setup your paywall"));
    ?>
					<?php 
    __tinypass_mlite_display($ps);
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Select your premium content"));
    ?>
					<?php 
    __tinypass_tag_display($ps);
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Miscellaneous"));
    ?>
					<?php 
    __tinypass_misc_display($ps);
    ?>
					<?php 
    __tinypass_save_buttons($ps, $edit);
    ?>
				</form>
			</div>


		</div>
	</div>

	<script>
		var scope = '';
		jQuery(function(){
			var $ = jQuery;

			$(".tp-tag-holder").click(function(event){
				if($(event.target).hasClass("remove"))
					$(event.target).parent().remove();
			})

			function addTag(){
				var tag = $(".premium_tags", scope).val();
				if(tag == "")
					return;

				$(".tp-tag-holder", scope).append("<div class='tag'><div class='text'>" + tag + "</div><div class='remove'></div>" 
					+ "<input type='hidden' name='tinypass[tags][]' value='" + tag  + "'>" 
					+ "</div>"
			);
				$(".premium_tags", scope).val("");
				$(".premium_tags", scope).focus();
			}
			$(".tp-tag-entry .add_tag").click(function(){
				addTag();
			});

			$(".tp-tag-entry .premium_tags").keypress(function(event){
				if(event.which == 13){
					addTag();
					event.stopPropagation();
					return false;
				}
			});
										  	                                                                                        									
			$('.premium_tags').suggest("admin-ajax.php?action=ajax-tag-search&tax=post_tag",{minchars:2,multiple:false,multipleSep:""})

		});

	</script>

	<?php 
    if (count($errors)) {
        ?>
		<?php 
        foreach ($errors as $key => $value) {
            ?>
			<script>tinypass.doError("<?php 
            echo esc_js($key);
            ?>
", "<?php 
            echo esc_js($value);
            ?>
");</script>
		<?php 
        }
        ?>
	<?php 
    }
    ?>


	<?php 
}
/**
 * Load and init global tinypass settings
 */
function tinypass_load_settings()
{
    $storage = new TPStorage();
    $ss = $storage->getSiteSettings();
    return $ss;
}
/**
 * This file performs the saving and display of TinyPass settings on the 
 * TinyPass->General menu
 */
function tinypass_site_settings()
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    $storage = new TPStorage();
    if (isset($_POST['_Submit'])) {
        if (!wp_verify_nonce($_REQUEST['_wpnonce'])) {
            wp_die(__('This action is not allowed'));
            check_admin_referer();
        }
        $ss = $storage->getSiteSettings();
        $ss->mergeValues($_POST['tinypass']);
        $storage->saveSiteSettings($ss);
    }
    $ss = $storage->getSiteSettings();
    ?>
	<div id="poststuff" class="metabox-holder has-right-sidebar">
		<?php 
    if (!empty($_POST['_Submit'])) {
        ?>
			<div id="message" class="updated fade"><p><strong><?php 
        _e('Options saved.');
        ?>
</strong></p></div>
		<?php 
    }
    ?>

		<div class="">
			<form action="" method="post" id="tinypass-conf">

				<?php 
    wp_nonce_field();
    ?>
				<?php 
    __tinypass_section_head_alt(__("General settings"));
    ?>
				<br>

				<div class="tp-section">
					<div class="info">
						<div class="heading">Environment</div>
						<div class="desc"></div>
					</div>
					<div class="body">
						<div class="postbox">
							<h3><?php 
    _e('Environment');
    ?>
 </h3>
							<div class="inside">
								<input type="radio" id="tp_cb_sand" name="tinypass[env]" value="0" <?php 
    echo checked($ss->isSand(), true);
    ?>
><label for="tp_cb_sand">&nbsp;<?php 
    _e('Sandbox - for testing only');
    ?>
</label><br>
								<input type="radio" id="tp_cb_prod" name="tinypass[env]" value="1" <?php 
    echo checked($ss->isProd(), true);
    ?>
><label for="tp_cb_prod">&nbsp;<?php 
    _e('Live - for live payments');
    ?>
</label>
							</div>
						</div>
					</div>
				</div>

				<div class="tp-section">
					<div class="info">
						<div class="heading">Other</div>
						<div class="desc"></div>
					</div>
					<div class="body">
						<div class="postbox">
							<h3><?php 
    _e('Shortcode');
    ?>
 </h3>
							<div class="inside">
								<p>
									A Wordpress <a target="_blank" href="http://codex.wordpress.org/Shortcode">shortcode</a> can be used within posts to generate a link that will open the Tinypass offer popup.
								</p>
								<p>
									The format for this shortcode is:
								</p>
								<pre>
		[tinypass_offer text="Here is my link text"]
								</pre>
								<p>
									where the 'text' attribute is the link text.  The above shortcode example will output the following link
								</p>
								<br> <a href="">Here is my link text</a>
							</div>
						</div>
					</div>
				</div>



				<div class="clear"></div>

				<p>
					<input type="submit" name="_Submit" id="publish" value="Save Changes" tabindex="4" class="button-primary" />
				</p>

			</form>
		</div>
	</div>
<?php 
}
/**
 * This file is responsbile for confiuring, displaying, and saving
 * individual paywall settings.
 */
function tinypass_mode_settings()
{
    $storage = new TPStorage();
    $errors = array();
    $ps = null;
    //Delete the paywall
    if (isset($_POST['_Delete'])) {
        if (isset($_POST['tinypass']['resource_id'])) {
            $rid = $_POST['tinypass']['resource_id'];
            $ss = $storage->getSiteSettings();
            $ps = $storage->getPaywall($rid, true);
            $storage->deletePaywall($ps);
            $location = 'admin.php?page=tinypass.php&msg=' . urlencode(__('Your paywall has been deleted!.'));
            wp_redirect($location);
        }
    } else {
        if (isset($_POST['_Submit'])) {
            //Save the paywall
            $ss = $storage->getSiteSettings();
            $ps = $ss->validatePaySettings($_POST['tinypass'], $errors);
            if (count($errors) == 0) {
                $storage->savePaywallSettings($ss, $ps);
                $location = 'admin.php?page=TinyPassEditPaywall&rid=' . $ps->getResourceId() . "&msg=" . urlencode(__('Your paywall has been saved!.'));
                wp_redirect($location);
            }
        }
    }
    $edit = false;
    $many = false;
    if ($ps == null) {
        $rid = 'wp_bundle1';
        $pws = $storage->getPaywalls(true);
        $many = count($pws) > 0;
        if (isset($_GET['rid']) && $_GET['rid'] != '') {
            $edit = true;
            $rid = $_GET['rid'];
        } else {
            if ($pws != null || count($pws) > 1) {
                $last = 0;
                foreach ($pws as $ps) {
                    $last = max($last, preg_replace('/[^0-9]*/', '', $ps->getResourceId()));
                }
                $rid = 'wp_bundle' . ($last + 1);
            }
        }
        $ps = $storage->getPaywall($rid, true);
    }
    ?>

	<div id="poststuff">
		<div class="tp-settings">

			<?php 
    if (!count($errors)) {
        ?>
				<?php 
        if (!empty($_REQUEST['msg'])) {
            ?>
					<div class="updated fade"><p><strong><?php 
            echo $_REQUEST['msg'];
            ?>
</strong></p></div>
				<?php 
        }
        ?>
			<?php 
    } else {
        ?>
				<div id="tp-error" class="error fade"></div>
			<?php 
    }
    ?>


			<div class="tp-section">

				<?php 
    if ($many) {
        ?>
					<div class="tp-all-paywalls-crumb">
						<a href="<?php 
        menu_page_url("tinypass.php");
        ?>
"> &lsaquo; <?php 
        _e("All my paywalls");
        ?>
 </a>
					</div>
				<?php 
    }
    ?>
				<?php 
    __tinypass_section_head($ps, 1, __("Paywall mode"), '<div id="tp-hide-paywalls">
          <span>Hide paywall details</span>
          <img src="' . TINYPASS_IMAGE_DIR . 'closer.png">
        </div>
        <div id="tp-show-paywalls">
          <span>Show paywall details</span>
          <img src="' . TINYPASS_IMAGE_DIR . 'opener.png">
        </div>');
    ?>


				<div id="tp_mode_details">
					<div id="tp_mode1_details" class="choice" mode="<?php 
    echo TPPaySettings::MODE_PPV;
    ?>
" >
						<div class="inner">
							<img src="<?php 
    echo TINYPASS_IMAGE_DIR;
    ?>
/icon-ppv.png">
							<div class="name"><?php 
    echo TPPaySettings::MODE_PPV_NAME;
    ?>
</div>
							<div class="sub">Purchase individual items</div>
							<div class="info">Sell access to individual blog posts. Set some default price options or tweak them per post.</div>
							<!--<div class="example">Examples: <a href="http://www.djbooth.net">djbooth.net</a></div>-->
						</div>
					</div>
					<div id="tp_mode2_details" class="choice" mode="<?php 
    echo TPPaySettings::MODE_METERED;
    ?>
" >
						<div class="inner">
							<img src="<?php 
    echo TINYPASS_IMAGE_DIR;
    ?>
/icon-metered.png">
							<div class="name"><?php 
    echo TPPaySettings::MODE_METERED_NAME;
    ?>
</div>
							<div class="sub">Preview period</div>
							<div class="info">Users can look at your content for a certain number of views, or for a certain time period.</div>
							<!--<div class="example">Examples: <a href="http://www.nytimes.com">The New York Times</a></div>-->
						</div>
					</div>
					<div id="tp_mode3_details" class="choice" mode="<?php 
    echo TPPaySettings::MODE_STRICT;
    ?>
" >
						<div class="inner">
							<img src="<?php 
    echo TINYPASS_IMAGE_DIR;
    ?>
/icon-hard.png">
							<div class="name"><?php 
    echo TPPaySettings::MODE_STRICT_NAME;
    ?>
</div>
							<div class="sub">No preview</div>
							<div class="info">All of your tagged content is restricted by the paywall right from the beginning.</div>
							<!--<div class="example">Examples: <a href="http://www.thebostonglobe.com">The Boston Globe</a></div>-->
						</div>
					</div>
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
				<div id="tp_modes">
					<div id="tp_mode1" class="choice" mode="<?php 
    echo TPPaySettings::MODE_PPV;
    ?>
" <?php 
    checked($ps->getMode(), TPPaySettings::MODE_PPV);
    ?>
 ><?php 
    echo TPPaySettings::MODE_PPV_NAME;
    ?>
</div>
					<div id="tp_mode2" class="choice" mode="<?php 
    echo TPPaySettings::MODE_METERED;
    ?>
" <?php 
    checked($ps->getMode(), TPPaySettings::MODE_METERED);
    ?>
><?php 
    echo TPPaySettings::MODE_METERED_NAME;
    ?>
</div>
					<div id="tp_mode3" class="choice" mode="<?php 
    echo TPPaySettings::MODE_STRICT;
    ?>
" <?php 
    checked($ps->getMode(), TPPaySettings::MODE_STRICT);
    ?>
><?php 
    echo TPPaySettings::MODE_STRICT_NAME;
    ?>
</div>
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
			</div>
			<div class="hr"></div>


			<div id="tp_mode1_panel" class="tp_mode_panel">
				<form action="" method="post" autocomplete="off">
					<input class="tp_mode" name="tinypass[mode]" type="hidden">
					<div style="float:right">
						<input type="hidden" readonly="true" name="tinypass[resource_id]" value="<?php 
    echo $ps->getResourceId();
    ?>
">
						<input type="hidden" readonly="true" name="tinypass[en]" value="<?php 
    echo $ps->getEnabled();
    ?>
">
						<input type="hidden" readonly="true" name="tinypass[resource_name]" value="Pay-per-view">
					</div>
					<?php 
    $num = 1;
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Pick and price your content"));
    ?>
					<?php 
    __tinypass_tag_display($ps);
    ?>
					<?php 
    __tinypass_pricing_display($ps);
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Messaging & appearances"));
    ?>
					<?php 
    __tinypass_purchase_option_table_display($ps);
    ?>
					<?php 
    __tinypass_save_buttons($ps, $edit);
    ?>
				</form>
			</div>


			<div id="tp_mode2_panel" class="tp_mode_panel">
				<form action="" method="post" autocomplete="off">
					<input class="tp_mode" name="tinypass[mode]" type="hidden">
					<div style="float:right">
						<input type="hidden" readonly="true" name="tinypass[resource_id]" value="<?php 
    echo $ps->getResourceId();
    ?>
">
						<input type="hidden" readonly="true" name="tinypass[en]" value="<?php 
    echo $ps->getEnabled();
    ?>
">
					</div>
					<?php 
    $num = 1;
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Pick and price your content"));
    ?>
					<?php 
    __tinypass_name_display($ps);
    ?>
					<?php 
    __tinypass_tag_display($ps);
    ?>
					<?php 
    __tinypass_pricing_display($ps);
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Customize your preview period"));
    ?>
					<?php 
    __tinypass_metered_display($ps);
    ?>
					<?php 
    __tinypass_counter_display($ps);
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Messaging & appearances"));
    ?>
					<?php 
    __tinypass_purchase_option_table_display($ps);
    ?>
					<?php 
    __tinypass_purchase_page_display($ps);
    ?>
					<?php 
    __tinypass_save_buttons($ps, $edit);
    ?>
				</form>
			</div>

			<div id="tp_mode3_panel" class="tp_mode_panel">
				<form action="" method="post" autocomplete="off">
					<input class="tp_mode" name="tinypass[mode]" type="hidden">
					<div style="float:right">
						<input type="hidden" readonly="true" name="tinypass[resource_id]" value="<?php 
    echo $ps->getResourceId();
    ?>
">
						<input type="hidden" readonly="true" name="tinypass[en]" value="<?php 
    echo $ps->getEnabled();
    ?>
">
					</div>
					<?php 
    $num = 1;
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Pick and price your content"));
    ?>
					<?php 
    __tinypass_name_display($ps);
    ?>
					<?php 
    __tinypass_tag_display($ps);
    ?>
					<?php 
    __tinypass_pricing_display($ps);
    ?>
					<?php 
    __tinypass_section_head($ps, ++$num, __("Messaging & appearances"));
    ?>
					<?php 
    __tinypass_purchase_option_table_display($ps);
    ?>
					<?php 
    __tinypass_purchase_page_display($ps);
    ?>
					<?php 
    __tinypass_save_buttons($ps, $edit);
    ?>
				</form>
			</div>
		</div>
	</div>

	<script>
		var scope = '';
		jQuery(function(){
			var $ = jQuery;

			//setup modes
			$('#tp_modes .choice').hover(
			function(){
				$(this).addClass("choice-on");
			}, 
			function(){
				$(this).removeClass("choice-on");
			});

			$('#tp_mode_details .choice').click(function(){
				var index = $(this).index();
				var elem = $('#tp_modes .choice').get(index);
				$(elem).trigger('click');
			})

			$('#tp_modes .choice').click(function(){
				$('#tp_mode_details .choice').removeClass("choice-selected");
				$('#tp_modes .choice').removeClass("choice-selected");
				$('#tp_modes .choice').removeAttr("checked");

				$(this).addClass("choice-selected");
				$(this).attr("checked", "checked");
	  	                                                                                        													
				var elem = $(".choice[checked=checked]");
				var id = elem.attr("id");

				scope = '#' + id + '_panel';

				$(".tp_mode").val(elem.attr('mode'));

				$('#tp_mode_details #' + id + "_details").addClass("choice-selected");

				tinypass.fullHide('.tp_mode_panel');
				tinypass.fullShow(scope);

			});
			$("#tp_modes .choice[checked=checked]").trigger('click');

			$(".tag-holder").click(function(event){
				if($(event.target).hasClass("remove"))
					$(event.target).parent().remove();
			})

			function addTag(){
				var tag = $(".premium_tags", scope).val();
				if(tag == "")
					return;

				$(".tag-holder", scope).append("<div class='tag'><div class='text'>" + tag + "</div><div class='remove'></div>" 
					+ "<input type='hidden' name='tinypass[tags][]' value='" + tag  + "'>" 
					+ "</div>"
			);
				$(".premium_tags", scope).val("");
				$(".premium_tags", scope).focus();
			}
			$(".tag-entry .add_tag").click(function(){
				addTag();
			});

			$(".tag-entry .premium_tags").keypress(function(event){
				if(event.which == 13){
					addTag();
					event.stopPropagation();
					return false;
				}
			});
	  	                                                                                        									
			//toggle access_period after recurring is changed
			$('.recurring-opts-off').bind('change', function(){
				var index = $(this).attr("opt");
				if($(this).is(":checked")){
					$(scope + " .po_ap_opts" + index).removeAttr("disabled");
				}
			});

			$('.recurring-opts-on').bind('change', function(){
				var index = $(this).attr("opt");
				if($(this).is(":checked")){
					$(scope + " .po_ap_opts" + index).attr("disabled", "disabled");
				} else {
					$(scope + " .po_ap_opts" + index).removeAttr("disabled");
				}
			})
			$('.recurring-opts-on').trigger('change');

			$('.premium_tags').suggest("admin-ajax.php?action=ajax-tag-search&tax=post_tag",{minchars:2,multiple:false,multipleSep:""})


			$('.tp-slider').bind('click', function(event){
				$('.choice-selected', this).removeClass("choice-selected");
				var choice = $(event.target);
				choice.addClass('choice-selected');
				$("input", this).val(choice.parent().attr('val'));
			})

			tinypass.showMeteredOptions(document.getElementsByName("tinypass[metered]")[0])

			$('#tp-hide-paywalls').bind('click', function(event){
				$('#tp_mode_details').hide();
				$(this).hide();
				$('#tp-show-paywalls').show();
			})

			$('#tp-show-paywalls').bind('click', function(event){
				$('#tp_mode_details').slideDown('slow');
				$(this).hide();
				$('#tp-hide-paywalls').show();
			})
		
	<?php 
    if (isset($_REQUEST['rid'])) {
        echo "\$('#tp-hide-paywalls').trigger('click');";
    } else {
        echo "\$('#tp-show-paywalls').trigger('click');";
    }
    ?>
		});
	</script>

	<?php 
    if (count($errors)) {
        ?>
		<?php 
        foreach ($errors as $key => $value) {
            ?>
			<script>tinypass.doError("<?php 
            echo $key;
            ?>
", "<?php 
            echo $value;
            ?>
");</script>
		<?php 
        }
        ?>
	<?php 
    }
    ?>


<?php 
}
/**
 * This file perform the saving and dispalying of TinyPass settings on the 
 * TinyPass->Settings menu
 */
function tinypass_site_settings()
{
    $storage = new TPStorage();
    if (isset($_POST['_Submit'])) {
        $ss = $storage->getSiteSettings();
        $ss->clear(array(TPSiteSettings::PPP_ENABLED, TPSiteSettings::DISABLE_COMMENTS_WHEN_DENIED));
        $ss->mergeValues($_POST['tinypass']);
        $storage->saveSiteSettings($ss);
    }
    $ss = $storage->getSiteSettings();
    ?>
	<div id="poststuff" class="metabox-holder has-right-sidebar">
		<?php 
    if (!empty($_POST['_Submit'])) {
        ?>
			<div id="message" class="updated fade"><p><strong><?php 
        _e('Options saved.');
        ?>
</strong></p></div>
		<?php 
    }
    ?>

		<div class="">
			<form action="" method="post" id="tinypass-conf">

				<?php 
    __tinypass_section_head_alt(__("General settings"));
    ?>
				<br>
				<div class="tp-section">
					<div class="info">
						<div class="desc">Customize the Tinypass experience by changing these additional options</div>
					</div>
					<div class="body">

						<div class="postbox">
							<h3><?php 
    _e('Options');
    ?>
 </h3>
							<div class="inside">
								<input type="checkbox" name="tinypass[ppv]" <?php 
    echo checked($ss->isPPPEnabled());
    ?>
><label>&nbsp;<?php 
    _e('Enable Tinypass for individual posts ');
    ?>
</label>
								<br>
								<input type="checkbox" name="tinypass[dc]" <?php 
    echo checked($ss->isDisableCommentsWhenDenied());
    ?>
><label>&nbsp;<?php 
    _e('Disable post comments when access is denied');
    ?>
</label>
							</div>
						</div>
						<?php 
    __tinypass_ppv_payment_display($ss);
    ?>

					</div>
					<?php 
    __tinypass_section_head_alt(__("Plugin settings"));
    ?>
					<br>
				</div>

				<div class="tp-section">
					<div class="info">
						<div class="heading">Environment</div>
						<div class="desc"></div>
					</div>
					<div class="body">
						<div class="postbox">
							<h3><?php 
    _e('Environment');
    ?>
 </h3>
							<div class="inside">
								<input type="radio" name="tinypass[env]" value="0" <?php 
    echo checked($ss->isSand(), true);
    ?>
><label><?php 
    _e('Sandbox - for testing only');
    ?>
</label><br>
								<input type="radio" name="tinypass[env]" value="1" <?php 
    echo checked($ss->isProd(), true);
    ?>
><label><?php 
    _e('Live - for live payments');
    ?>
</label>
							</div>
						</div>
					</div>
				</div>

				<div class="tp-section">
					<div class="info">
						<div class="heading">Application IDs and Keys</div>
					</div>
					<div class="body">


						<div class="postbox">
							<h3><?php 
    _e('Application IDs and Keys');
    ?>
 </h3>
							<div class="inside">

								<table class="form-table">

									<tr valign="top">
										<th scope="row"><?php 
    _e('Application ID (Sandbox)');
    ?>
</th>
										<td>
											<input id="aid_sand" name="tinypass[aid_sand]" type="text" size="10" maxlength="10" value="<?php 
    echo $ss->getAIDSand();
    ?>
"/><br>
											<span class="description">The Application ID (sandbox) can be retrieved from your account at <a target="_blank" href="http://sandbox.tinypass.com/member/merch">http://sandbox.tinypass.com</a></span>
										</td>
									</tr>

									<tr valign="top">
										<th scope="row"><?php 
    _e('Application Secret Key (Sandbox)');
    ?>
</th>
										<td>
											<input id="secret_key_sand" name="tinypass[secret_key_sand]" type="text" size="40" maxlength="40" value="<?php 
    echo $ss->getSecretKeySand();
    ?>
" style="" /><br>
											<span class="description">The Secret Key (sandbox) can be retrieved from your account at <a target="_blank" href="http://sandbox.tinypass.com/member/merch">http://sandbox.tinypass.com</a></span><br>
										</td>
									</tr>
									<tr valign="top">
										<th scope="row"><?php 
    _e('Application ID (Live)');
    ?>
</th>
										<td>
											<input id="aid_prod" name="tinypass[aid_prod]" type="text" size="10" maxlength="10" value="<?php 
    echo $ss->getAIDProd();
    ?>
"/><br>
											<span class="description">The Application ID (Live) can be retrieved from your account at <a target="_blank" href="http://dashboard.tinypass.com/member/merch">http://www.tinypass.com</a></span>
										</td>
									</tr>

									<tr valign="top">
										<th scope="row"><?php 
    _e('Application Secret Key (Live)');
    ?>
</th>
										<td>
											<input id="secret_key_prod" name="tinypass[secret_key_prod]" type="text" size="40" maxlength="40" value="<?php 
    echo $ss->getSecretKeyProd();
    ?>
" style="" /><br>
											<span class="description">The Secret Key (Live) can be retrieved from your account at <a target="_blank" href="http://dashboard.tinypass.com/member/merch">http://www.tinypass.com</a></span>
										</td>
									</tr>

								</table>
							</div>
						</div>
					</div>
					<div class="clear"></div>
				</div>

				<p>
					<input type="submit" name="_Submit" id="publish" value="Save Changes" tabindex="4" class="button-primary" />
				</p>

			</form>
		</div>
	</div>
<?php 
}