ادامه کد ها
if (preg_match("/http/", $addcart)) // Use the image as the 'add to cart' button
{
$replacement .= '<input type="image" src="'.$addcart.'" class="wp_cart_button" alt="'.(__("Add to Cart", "WSPSC")).'"/>';
}
else
{
$replacement .= '<input type="submit" value="'.$addcart.'" />';
}
$replacement .= '<input type="hidden" name="product" value="'.$pieces['0'].'" /><input type="hidden" name="price" value="'.$pieces['1'].'" />';
$replacement .= '<input type="hidden" name="product_tmp" value="'.$pieces['0'].'" />';
if (sizeof($pieces) >2 )
{
//we have shipping
$replacement .= '<input type="hidden" name="shipping" value="'.$pieces['2'].'" />';
}
$replacement .= '<input type="hidden" name="cartLink" value="'.cart_current_page_url().'" />';
$replacement .= '<input type="hidden" name="addcart" value="1" /></form>';
$replacement .= '</div>';
$content = str_replace ($match, $replacement, $content);
}
return $content;
}
function wp_cart_add_read_form_javascript()
{
echo '
<script type="text/javascript">
<!--
//
function ReadForm (obj1, tst)
{
// Read the user form
var i,j,pos;
val_total="";val_combo="";
for (i=0; i<obj1.length; i++)
{
// run entire form
obj = obj1.elements[i]; // a form element
if (obj.type == "select-one")
{ // just selects
if (obj.name == "quantity" ||
obj.name == "amount") continue;
pos = obj.selectedIndex; // which option selected
val = obj.options[pos].value; // selected value
val_combo = val_combo + "(" + val + ")";
}
}
// Now summarize everything we have processed above
val_total = obj1.product_tmp.value + val_combo;
obj1.product.value = val_total;
}
//-->
</script>';
}
function print_wp_cart_button_for_product($name, $price, $shipping=0)
{
$addcart = get_option('addToCartButtonName');
if (!$addcart || ($addcart == '') )
$addcart = __("Add to Cart", "WSPSC");
$replacement = '<div class="wp_cart_button_wrapper">';
$replacement .= '<form method="post" class="wp-cart-button-form" action="" style="display:inline">';
if (preg_match("/http:/", $addcart)) // Use the image as the 'add to cart' button
{
$replacement .= '<input type="image" src="'.$addcart.'" class="wp_cart_button" alt="'.(__("Add to Cart", "WSPSC")).'"/>';
}
else
{
$replacement .= '<input type="submit" value="'.$addcart.'" />';
}
$replacement .= '<input type="hidden" name="product" value="'.$name.'" /><input type="hidden" name="price" value="'.$price.'" /><input type="hidden" name="shipping" value="'.$shipping.'" /><input type="hidden" name="addcart" value="1" /><input type="hidden" name="cartLink" value="'.cart_current_page_url().'" />';
$replacement .= '</form>';
$replacement .= '</div>';
return $replacement;
}
function cart_not_empty()
{
$count = 0;
if (isset($_SESSION['simpleCart']) && is_array($_SESSION['simpleCart']))
{
foreach ($_SESSION['simpleCart'] as $item)
$count++;
return $count;
}
else
return 0;
}
function print_payment_currency($price, $symbol, $decimal)
{
return $symbol.number_format($price, 2, $decimal, ',');
}
function cart_current_page_url() {
$pageURL = 'http';
if(!isset($_SERVER["HTTPS"])){$_SERVER["HTTPS"]="";}
if(!isset($_SERVER["SERVER_PORT"])){$_SERVER["SERVER_PORT"]="";}
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
function show_wp_cart_options_page () {
$wp_simple_paypal_shopping_cart_version = "3.5";
if (isset($_POST['info_update']))
{
update_option('cart_payment_currency', (string)$_POST["cart_payment_currency"]);
update_option('cart_currency_symbol', (string)$_POST["cart_currency_symbol"]);
update_option('cart_base_shipping_cost', (string)$_POST["cart_base_shipping_cost"]);
update_option('cart_free_shipping_threshold', (string)$_POST["cart_free_shipping_threshold"]);
update_option('wp_shopping_cart_collect_address', ($_POST['wp_shopping_cart_collect_address']!='') ? 'checked="checked"':'' );
update_option('wp_shopping_cart_use_profile_shippi ng', ($_POST['wp_shopping_cart_use_profile_shipping']!='') ? 'checked="checked"':'' );
update_option('cart_paypal_email', (string)$_POST["cart_paypal_email"]);
update_option('addToCartButtonName', (string)$_POST["addToCartButtonName"]);
update_option('wp_cart_title', (string)$_POST["wp_cart_title"]);
update_option('wp_cart_empty_text', (string)$_POST["wp_cart_empty_text"]);
update_option('cart_return_from_paypal_url', (string)$_POST["cart_return_from_paypal_url"]);
update_option('cart_products_page_url', (string)$_POST["cart_products_page_url"]);
update_option('wp_shopping_cart_auto_redirect_to_c heckout_page', ($_POST['wp_shopping_cart_auto_redirect_to_checkout_page']!='') ? 'checked="checked"':'' );
update_option('cart_checkout_page_url', (string)$_POST["cart_checkout_page_url"]);
update_option('wp_shopping_cart_reset_after_redire ction_to_return_page', ($_POST['wp_shopping_cart_reset_after_redirection_to_retur n_page']!='') ? 'checked="checked"':'' );
update_option('wp_shopping_cart_image_hide', ($_POST['wp_shopping_cart_image_hide']!='') ? 'checked="checked"':'' );
update_option('wp_cart_note_to_seller_text', (string)$_POST["wp_cart_note_to_seller_text"]);
update_option('wp_use_aff_platform', ($_POST['wp_use_aff_platform']!='') ? 'checked="checked"':'' );
update_option('wp_shopping_cart_enable_sandbox', ($_POST['wp_shopping_cart_enable_sandbox']!='') ? 'checked="checked"':'' );
echo '<div id="message" class="updated fade">';
echo '<p><strong>'.(__("Options Updated!", "WSPSC")).'</strong></p></div>';
}
$defaultCurrency = get_option('cart_payment_currency');
if (empty($defaultCurrency)) $defaultCurrency = __("USD", "WSPSC");
$defaultSymbol = get_option('cart_currency_symbol');
if (empty($defaultSymbol)) $defaultSymbol = __("$", "WSPSC");
$baseShipping = get_option('cart_base_shipping_cost');
if (empty($baseShipping)) $baseShipping = 0;
$cart_free_shipping_threshold = get_option('cart_free_shipping_threshold');
$defaultEmail = get_option('cart_paypal_email');
if (empty($defaultEmail)) $defaultEmail = get_bloginfo('admin_email');
$return_url = get_option('cart_return_from_paypal_url');
$addcart = get_option('addToCartButtonName');
if (empty($addcart)) $addcart = __("Add to Cart", "WSPSC");
$title = get_option('wp_cart_title');
//if (empty($title)) $title = __("Your Shopping Cart", "WSPSC");
$emptyCartText = get_option('wp_cart_empty_text');
$cart_products_page_url = get_option('cart_products_page_url');
$cart_checkout_page_url = get_option('cart_checkout_page_url');
if (get_option('wp_shopping_cart_auto_redirect_to_che ckout_page'))
$wp_shopping_cart_auto_redirect_to_checkout_page = 'checked="checked"';
else
$wp_shopping_cart_auto_redirect_to_checkout_page = '';
if (get_option('wp_shopping_cart_reset_after_redirect ion_to_return_page'))
$wp_shopping_cart_reset_after_redirection_to_retur n_page = 'checked="checked"';
else
$wp_shopping_cart_reset_after_redirection_to_retur n_page = '';
if (get_option('wp_shopping_cart_collect_address'))
$wp_shopping_cart_collect_address = 'checked="checked"';
else
$wp_shopping_cart_collect_address = '';
if (get_option('wp_shopping_cart_use_profile_shipping '))
$wp_shopping_cart_use_profile_shipping = 'checked="checked"';
else
$wp_shopping_cart_use_profile_shipping = '';
if (get_option('wp_shopping_cart_image_hide'))
$wp_cart_image_hide = 'checked="checked"';
else
$wp_cart_image_hide = '';
$wp_cart_note_to_seller_text = get_option('wp_cart_note_to_seller_text');
if (get_option('wp_use_aff_platform'))
$wp_use_aff_platform = 'checked="checked"';
else
$wp_use_aff_platform = '';
//$wp_shopping_cart_enable_sandbox = get_option('wp_shopping_cart_enable_sandbox');
if (get_option('wp_shopping_cart_enable_sandbox'))
$wp_shopping_cart_enable_sandbox = 'checked="checked"';
else
$wp_shopping_cart_enable_sandbox = '';
?>
<h2><?php _e("Simple PayPal Shopping Cart Settings", "WSPSC"); ?> v <?php echo $wp_simple_paypal_shopping_cart_version; ?></h2>
<div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
<p><?php _e("For more information, updates, detailed documentation and video tutorial, please visit:", "WSPSC"); ?><br />
<a href="http://www.tipsandtricks-hq.com/?p=768" target="_blank"><?php _e("WP simple cart homepage", "WSPSC"); ?></a></p>
</div>
<div class="postbox">
<h3><label for="title"><?php _e("Quick Usage Guide", "WSPSC"); ?></label></h3>
<div class="inside">
<p><?php _e("1. To add an 'Add to Cart' button for a product simply add the shortcode", "WSPSC"); ?> <strong>[wp_cart:<?php _e("PRODUCT-NAME", "WSPSC"); ?>:price:<?php _e("PRODUCT-PRICE", "WSPSC"); ?>:end]</strong> <?php _e("to a post or page next to the product. Replace PRODUCT-NAME and PRODUCT-PRICE with the actual name and price. For example: [wp_cart:Test Product:price:15.00:end]", "WSPSC"); ?></p>
<p><?php _e("2. To add the shopping cart to a post or page (example, checkout page) simply add the shortcode", "WSPSC"); ?><strong>[show_wp_shopping_cart]</strong> <?php _e("to a post or page or use the sidebar widget to add the shopping cart to the sidebar.", "WSPSC"); ?></p>
</div></div>
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
<input type="hidden" name="info_update" id="info_update" value="true" />
<?php
echo '
<div class="postbox">
<h3><label for="title">'.(__("PayPal and Shopping Cart Settings", "WSPSC")).'</label></h3>
<div class="inside">';
echo '
<table class="form-table">
<tr valign="top">
<th scope="row">'.(__("Paypal Email Address", "WSPSC")).'</th>
<td><input type="text" name="cart_paypal_email" value="'.$defaultEmail.'" size="40" /></td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Enable Sandbox Testing", "WSPSC")).'</th>
<td><input type="checkbox" name="wp_shopping_cart_enable_sandbox" value="1" '.$wp_shopping_cart_enable_sandbox.' />
<br />'.(__("Check this option if you want to do PayPal sandbox testing. You will need to create a PayPal sandbox account from PayPal Developer site", "WSPSC")).'</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Shopping Cart title", "WSPSC")).'</th>
<td><input type="text" name="wp_cart_title" value="'.$title.'" size="40" /></td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Text/Image to Show When Cart Empty", "WSPSC")).'</th>
<td><input type="text" name="wp_cart_empty_text" value="'.$emptyCartText.'" size="60" /><br />'.(__("You can either enter plain text or the URL of an image that you want to show when the shopping cart is empty", "WSPSC")).'</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Currency", "WSPSC")).'</th>
<td><input type="text" name="cart_payment_currency" value="'.$defaultCurrency.'" size="6" /> ('.(__("e.g.", "WSPSC")).' USD, EUR, GBP, AUD)</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Currency Symbol", "WSPSC")).'</th>
<td><input type="text" name="cart_currency_symbol" value="'.$defaultSymbol.'" size="2" style="width: 1.5em;" /> ('.(__("e.g.", "WSPSC")).' $, £, €)
</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Base Shipping Cost", "WSPSC")).'</th>
<td><input type="text" name="cart_base_shipping_cost" value="'.$baseShipping.'" size="5" /> <br />'.(__("This is the base shipping cost that will be added to the total of individual products shipping cost. Put 0 if you do not want to charge shipping cost or use base shipping cost.", "WSPSC")).' <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=297" target="_blank">'.(__("Learn More on Shipping Calculation", "WSPSC")).'</a></td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Free Shipping for Orders Over", "WSPSC")).'</th>
<td><input type="text" name="cart_free_shipping_threshold" value="'.$cart_free_shipping_threshold.'" size="5" /> <br />'.(__("When a customer orders more than this amount he/she will get free shipping. Leave empty if you do not want to use it.", "WSPSC")).'</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Must Collect Shipping Address on PayPal", "WSPSC")).'</th>
<td><input type="checkbox" name="wp_shopping_cart_collect_address" value="1" '.$wp_shopping_cart_collect_address.' /><br />'.(__("If checked the customer will be forced to enter a shipping address on PayPal when checking out.", "WSPSC")).'</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Use PayPal Profile Based Shipping", "WSPSC")).'</th>
<td><input type="checkbox" name="wp_shopping_cart_use_profile_shipping" value="1" '.$wp_shopping_cart_use_profile_shipping.' /><br />'.(__("Check this if you want to use", "WSPSC")).' <a href="https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_html_ProfileAndTools#id08A9EF00IQY" target="_blank">'.(__("PayPal profile based shipping", "WSPSC")).'</a>. '.(__("Using this will ignore any other shipping options that you have specified in this plugin.", "WSPSC")).'</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Add to Cart button text or Image", "WSPSC")).'</th>
<td><input type="text" name="addToCartButtonName" value="'.$addcart.'" size="100" /><br />'.(__("To use a customized image as the button simply enter the URL of the image file.", "WSPSC")).' '.(__("e.g.", "WSPSC")).' http://www.your-domain.com/wp-content/plugins/wordpress-paypal-shopping-cart/images/buy_now_button.png</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Return URL", "WSPSC")).'</th>
<td><input type="text" name="cart_return_from_paypal_url" value="'.$return_url.'" size="100" /><br />'.(__("This is the URL the customer will be redirected to after a successful payment", "WSPSC")).'</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Products Page URL", "WSPSC")).'</th>
<td><input type="text" name="cart_products_page_url" value="'.$cart_products_page_url.'" size="100" /><br />'.(__("This is the URL of your products page if you have any. If used, the shopping cart widget will display a link to this page when cart is empty", "WSPSC")).'</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Automatic redirection to checkout page", "WSPSC")).'</th>
<td><input type="checkbox" name="wp_shopping_cart_auto_redirect_to_checkout_p age" value="1" '.$wp_shopping_cart_auto_redirect_to_checkout_page .' />
'.(__("Checkout Page URL", "WSPSC")).': <input type="text" name="cart_checkout_page_url" value="'.$cart_checkout_page_url.'" size="60" />
<br />'.(__("If checked the visitor will be redirected to the Checkout page after a product is added to the cart. You must enter a URL in the Checkout Page URL field for this to work.", "WSPSC")).'</td>
</tr>
<tr valign="top">
<th scope="row">'.(__("Reset Cart After Redirection to Return Page", "WSPSC")).'</th>
<td><input type="checkbox" name="wp_shopping_cart_reset_after_redirection_to_ return_page" value="1" '.$wp_shopping_cart_reset_after_redirection_to_ret urn_page.' />
<br />'.(__("If checked the shopping cart will be reset when the customer lands on the return URL (Thank You) page.", "WSPSC")).'</td>
</tr>
</table>
<table class="form-table">
<tr valign="top">
<th scope="row">'.(__("Hide Shopping Cart Image", "WSPSC")).'</th>
<td><input type="checkbox" name="wp_shopping_cart_image_hide" value="1" '.$wp_cart_image_hide.' /><br />'.(__("If ticked the shopping cart image will not be shown.", "WSPSC")).'</td>
</tr>
</table>
<table class="form-table">
<tr valign="top">
<th scope="row">'.(__("Customize the Note to Seller Text", "WSPSC")).'</th>
<td><input type="text" name="wp_cart_note_to_seller_text" value="'.$wp_cart_note_to_seller_text.'" size="100" />
<br />'.(__("Specify the text that you want to use for the note field on PayPal checkout page to collect special instruction (leave this field empty if you don't need to customize it). The default label for the note field is \"Add special instructions to merchant\".", "WSPSC")).'</td>
</tr>
</table>
<table class="form-table">
<tr valign="top">
<th scope="row">'.(__("Use WP Affiliate Platform", "WSPSC")).'</th>
<td><input type="checkbox" name="wp_use_aff_platform" value="1" '.$wp_use_aff_platform.' />
<br />'.(__("Check this if using with the", "WSPSC")).' <a href="http://www.tipsandtricks-hq.com/?p=1474" target="_blank">WP Affiliate Platform plugin</a>. '.(__("This plugin lets you run your own affiliate campaign/program and allows you to reward (pay commission) your affiliates for referred sales", "WSPSC")).'</td>
</tr>
</table>
</div></div>
<div class="submit">
<input type="submit" name="info_update" value="'.(__("Update Options »", "WSPSC")).'" />
</div>
</form>
';
echo (__("Like the Simple WordPress Shopping Cart Plugin?", "WSPSC")).' <a href="http://wordpress.org/extend/plugins/wordpress-simple-paypal-shopping-cart" target="_blank">'.(__("Give it a good rating", "WSPSC")).'</a>';
?>
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
<div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
<p><?php _e("Need a shopping cart plugin with more features? Checkout my ", "WSPSC"); ?>
<a href="http://www.tipsandtricks-hq.com/?p=1059" target="_blank"><?php _e("WP eStore Plugin", "WSPSC"); ?></a></p>
</div>
<?php
}
function simple_cart_total()
{
$grand_total = 0;
foreach ((array) $_SESSION['simpleCart'] as $item)
{
$total += $item['price'] * $item['quantity'];
$item_total_shipping += $item['shipping'] * $item['quantity'];
}
$grand_total = $total + $item_total_shipping;
return number_format($grand_total,2);
}
function wp_cart_options()
{
echo '<div class="wrap"><h2>'.(__("WP Paypal Shopping Cart Options", "WSPSC")).'</h2>';
echo '<div id="poststuff"><div id="post-body">';
show_wp_cart_options_page();
echo '</div></div>';
echo '</div>';
}
// Display The Options Page
function wp_cart_options_page ()
{
add_options_page(__("WP Paypal Shopping Cart", "WSPSC"), __("WP Shopping Cart", "WSPSC"), 'manage_options', __FILE__, 'wp_cart_options');
}
function wp_paypal_shopping_cart_load_widgets()
{
register_widget('WP_PayPal_Cart_Widget');
}
class WP_PayPal_Cart_Widget extends WP_Widget {
function WP_PayPal_Cart_Widget() {
parent::WP_Widget('wp_paypal_shopping_cart_widgets ', 'WP Paypal Shopping Cart', array('description' => 'WP Paypal Shopping Cart Widget') );
}
function form($instance) {
// outputs the options form on admin
}
function update($new_instance, $old_instance) {
// processes widget options to be saved
}
function widget($args, $instance) {
// outputs the content of the widget
extract( $args );
$cart_title = get_option('wp_cart_title');
if (empty($cart_title)) $cart_title = __("Shopping Cart", "WSPSC");
echo $before_widget;
echo $before_title . $cart_title . $after_title;
echo print_wp_shopping_cart();
echo $after_widget;
}
}
function wp_cart_css()
{
echo '<link type="text/css" rel="stylesheet" href="'.WP_CART_URL.'/wp_shopping_cart_style.css" />'."\n";
}
// Add the settings link
function wp_simple_cart_add_settings_link($links, $file)
{
if ($file == plugin_basename(__FILE__)){
$settings_link = '<a href="options-general.php?page='.dirname(plugin_basename(__FILE_ _)).'/wp_shopping_cart.php">'.(__("Settings", "WSPSC")).'</a>';
array_unshift($links, $settings_link);
}
return $links;
}
add_filter('plugin_action_links', 'wp_simple_cart_add_settings_link', 10, 2 );
// Insert the options page to the admin menu
add_action('admin_menu','wp_cart_options_page');
add_action('widgets_init','wp_paypal_shopping_cart _load_widgets');
//add_filter('the_content', 'print_wp_cart_button',11);
add_filter('the_content', 'print_wp_cart_button_new',11);
add_filter('the_content', 'shopping_cart_show');
if (!is_admin())
{add_filter('widget_text', 'do_shortcode');}
add_shortcode('show_wp_shopping_cart', 'show_wp_shopping_cart_handler');
add_shortcode('always_show_wp_shopping_cart', 'always_show_cart_handler');
add_shortcode('wp_cart_button', 'wp_cart_button_handler');
add_action('wp_head', 'wp_cart_css');
add_action('wp_head', 'wp_cart_add_read_form_javascript');
?>