Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Test New Permissions */
- /*
- Plugin Name: WPEC Personalize
- Plugin URI: http://www.derekweathersbee.com/products/wpec-personalize
- Description: Plugin for Extended Personalization of WP E-Commerce
- Version: 1.0
- Author: Derek Weathersbee (derek@derekweathersbee.com), Chris Vanzo of Vanzo Ink (http://vanzoink.com), and Sluchak Anton (anketko@gmail.com).
- Author URI: http://derekweathersbee.com
- */
- /*
- IMPORTANT NOTE added by vanzoink.com
- -----------------------------------------------------------------------------
- The file "wpsc-admin/includes/display-items-functions.php" has a bug that will be fixed in the next revision 3.8.5 of wpec details below
- Revision details at: http://code.google.com/p/wp-e-commerce/source/detail?r=491
- Instructions for manual fix:
- 1. You must open up the file wpsc-admin/includes/display-items-functions.php
- 2. Find the following code on the following lines:
- 754 - ob_start();
- 755 754 do_action( 'wpsc_add_advanced_options', $post->ID );
- 756 - ob_get_contents();
- 757 - ob_end_clean();
- 3. Comment or delete out lines 754, 756 and 757 to get
- 754 - //ob_start();
- 755 754 do_action( 'wpsc_add_advanced_options', $post->ID );
- 756 - //ob_get_contents();
- 757 - //ob_end_clean();
- ---------------------------------------------------------------------------
- */
- /*
- if (is_admin()) {
- function wpsc_add_modules_admin_pages($page_hooks, $base_page) {
- @$page_hooks[] = @add_submenu_page($base_page, __('-New Page','wpsc'), __('-New Page','wpsc'), 7, 'customization_ec.php', 'wpsc_display_admin_pages');
- return $page_hooks;
- }
- @add_filter('wpsc_additional_pages', 'wpsc_add_modules_admin_pages',10, 2);
- }
- */
- //PLUGIN START!!!
- register_activation_hook( __FILE__, 'customisation_ec_activate' );
- function customisation_ec_activate(){
- global $wpdb;
- $table_name = $wpdb->prefix . "wpsc_pers_products";
- $table_name_global = $wpdb->prefix . "wpsc_pers_global";
- $sql = "CREATE TABLE IF NOT EXISTS ".$table_name_global." (pers_id int(11) NOT NULL, pers_name text, pers_type text, PRIMARY KEY (pers_id)) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
- $sql2 = "CREATE TABLE IF NOT EXISTS ".$table_name."( product_id int(11) NOT NULL, pers_id int(11) NOT NULL, enabled tinyint(1) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
- $wpdb->query($sql);
- $wpdb->query($sql2);
- }
- $page_single = false;
- $product_counter = 0;
- $js = '';
- add_action('wpsc_product_before_description', 'checker_single');
- function checker_single(){
- global $page_single;
- $page_single = wpsc_is_single_product();
- }
- function wpsc_display_products_page_ext($query) {
- global $wpdb, $wpsc_query, $wpsc_theme_path;
- /// added by xiligroup.dev to be compatible with touchshop
- $cur_wpsc_theme_folder = apply_filters('wpsc_theme_folder',$wpsc_theme_path.WPSC_THEME_DIR);
- /// end of added by xiligroup.dev to be compatible with touchshop
- $temp_wpsc_query = new WPSC_query($query);
- list($wpsc_query, $temp_wpsc_query) = array($temp_wpsc_query, $wpsc_query); // swap the wpsc_query objects
- $GLOBALS['nzshpcrt_activateshpcrt'] = true;
- ob_start();
- include($cur_wpsc_theme_folder."/single_product.php");
- $output = ob_get_contents();
- ob_end_clean();
- //$output = str_replace('$','\$', $output);
- list($temp_wpsc_query, $wpsc_query) = array($wpsc_query, $temp_wpsc_query); // swap the wpsc_query objects back
- return $output;
- }
- function wpsc_products_shorttag_ext($atts) {
- $number_per_page = get_option('use_pagination') ? get_option('wpsc_products_per_page') : 0;
- $query = shortcode_atts(array(
- 'product_id' => 0,
- 'product_url_name' => null,
- 'product_name' => null,
- 'category_id' => 0,
- 'category_url_name' => null,
- 'tag' => null,
- 'price' => 0,
- 'limit_of_items' => 0,
- 'sort_order' => null,
- 'number_per_page' => $number_per_page,
- 'page' => 0,
- ), $atts);
- return wpsc_display_products_page_ext($query);
- }
- add_shortcode('wpsc_products_ext', 'wpsc_products_shorttag_ext');
- $prod_id = 0;
- add_action('testaction', 'shopping_cart_echo');
- function shopping_cart_echo($product_id){
- echo "<<<<:".$product_id;
- }
- add_action('wpsc_product_addon_after_descr', 'client_echo'); // show data to the user
- function client_echo($product_id){
- global $prod_id;
- $prod_id = $product_id;
- ?>
- <style type="text/css">
- .custom_text {
- display:none;
- }
- </style>
- <?php
- global $wpdb;
- global $page_single;
- global $product_counter;
- $table_name = $wpdb->prefix . "wpsc_pers_products";
- $table_name_global = $wpdb->prefix . "wpsc_pers_global";
- if (isset($product_id) /*&& ($page_single)*/){
- global $js;
- // $product_id = $_GET['product_id']; //custom_text
- $js .= "<script language=\"JavaScript\" type=\"text/javascript\">
- document.getElementById('product_".$product_id."_submit_button').onclick = function(){
- var j = document.getElementById('ii_".$product_id."').value;
- text_general = '';
- caption = '';
- text = '';
- for (var i=0; i<j; i++){
- capt_name = 'pers_capt_".$product_id."_'+i;
- pers_capt_name = 'personal_".$product_id."_'+i;
- if(document.getElementById(pers_capt_name).value != ''){
- caption = document.getElementById(capt_name).value;
- text = document.getElementById(pers_capt_name).value;
- text_general += '<p><strong>'+caption+'</strong> <br><em>'+text+'</em><br></p>';
- }
- }
- document.getElementsByName('custom_text')[".$product_counter."].value = text_general;
- }
- </script>";
- $product_counter++;
- $i = 0;
- echo '<div class="customisation_extended">';
- $myresult = $wpdb->get_results("SELECT pers_id FROM ". $table_name." WHERE product_id = ".$product_id." AND enabled = 1 ORDER BY pers_id ASC");
- foreach ($myresult as $personalization){
- $echo_vars = $wpdb->get_results("SELECT * FROM ". $table_name_global ." WHERE pers_id = ". $personalization->pers_id);
- foreach ($echo_vars as $echo_var){
- echo '<input id="pers_capt_'.$product_id.'_'.$i.'" name="pers_capt_'.$product_id.'_'.$i.'" type="hidden" value="'.$echo_var->pers_name.'">';
- echo '<input id="pers_typeid_'.$product_id.'_'.$i.'" name="pers_type_'.$product_id.'_'.$i.'" type="hidden" value="'.$echo_var->pers_type.'">';
- echo '<div class="personalization_caption">'.$echo_var->pers_name.'</div>';
- echo '<div class="personalisation_input">';
- /* edited by dw to add a title "slug" to each field */
- $fieldLabel = $echo_var->pers_name;
- $fieldLabel = preg_replace("/[^a-z0-9- ]/i", "", $fieldLabel);
- $fieldLabel = str_replace(" ", "-", $fieldLabel);
- $fieldLabel = strtolower($fieldLabel);
- if ($echo_var->pers_type == 'textarea'){
- echo '<textarea title="'.$fieldLabel.'" class="personalisation_textarea" id="personal_'.$product_id.'_'.$i.'" name="personal_'.$product_id.'_'.$personalization->pers_id.'" rows=5 cols=20 wrap="off"></textarea>';
- }else{
- echo '<input title="'.$fieldLabel.'" class="personalisation_textfield" id="personal_'.$product_id.'_'.$i.'" name="personal_'.$product_id.'_'.$personalization->pers_id.'" type="text" value="">';
- }
- echo '</div>';
- }
- $i++;
- }
- echo '<input name="iii" id="ii_'.$product_id.'" type="hidden" value="'.$i.'">';
- echo '</div>';
- }
- }
- add_action('wp_footer', 'footer_script');
- function footer_script(){
- global $js;
- echo $js;
- }
- add_action('wpsc_add_advanced_options', 'enable_settings'); // add to add-edit products pages
- function enable_settings($product_id){
- global $wpdb;
- $table_name = $wpdb->prefix . "wpsc_pers_products";
- $table_name_global = $wpdb->prefix . "wpsc_pers_global";
- if(isset($product_id)){
- //add fields
- $myresult = $wpdb->get_results("SELECT pers_id FROM ". $table_name_global);
- foreach ($myresult as $myresults){
- $add = $wpdb->get_var( $wpdb->prepare(
- "SELECT enabled FROM %s WHERE pers_id = %d AND product_id = %d",
- $table_name,
- $myresults->pers_id,
- $product_id
- ));
- if ($add ==''){
- $aff_rows = $wpdb->insert( $table_name, array( 'product_id' => $product_id, 'pers_id' => $myresults->pers_id, 'enabled' => '1' ) );
- }
- }
- ?>
- <script language="JavaScript" type="text/javascript">
- document.getElementById('add_engrave_text').checked = true;
- document.getElementById('add_engrave_text').onclick = function(){
- document.getElementById('add_engrave_text').checked = true;
- }
- </script>
- <style>
- .personalizations-admin {
- margin: 14px 0 0;
- }
- .personalizations-admin td {
- padding: 3px 8px;
- text-align: left;
- text-transform: capitalize;
- }
- .personalizations-admin th {
- padding: 3px 8px 8px;
- font-weight: bold;
- text-transform: capitalize;
- text-align: left;
- color: #21759B;
- font-size: 120%;
- }
- </style>
- <table class='personalizations-admin'>
- <th colspan = 3> <strong>Personalization options extended</strong> </th>
- <tr>
- <td><b>enabled</b></td>
- <td><b>personalization name</b></td>
- <td><b>field type</b></td>
- </tr>
- <?php
- $myresult = $wpdb->get_results("SELECT pers_id, enabled FROM ". $table_name ." WHERE product_id = ". $product_id." ORDER BY pers_id ASC");
- foreach ($myresult as $myresults){
- $row = $wpdb->get_row("SELECT * FROM ". $table_name_global ." WHERE pers_id = ". $myresults->pers_id);
- if ($myresults->enabled == 1){
- $checked = 'checked';
- }else{
- $checked = '';
- }
- echo '<tr> <td><input name="enabled_'.$row->pers_id.'" type="checkbox" value="ON" '.$checked.'></td> <td>'.$row->pers_name.'</td> <td>'.$row->pers_type.'</td></tr>';
- }
- ?>
- </table>
- <?php
- }
- }
- add_action('wpsc_edit_product', 'add_customise'); // add to add-edit products pages
- function add_customise($product_id){
- global $wpdb;
- $table_name_global = $wpdb->prefix . "wpsc_pers_global";
- $table_name = $wpdb->prefix . "wpsc_pers_products";
- if (isset($product_id)){
- //add fields
- $myresult = $wpdb->get_results("SELECT pers_id FROM ". $table_name_global);
- foreach ($myresult as $myresults){
- $add = $wpdb->get_var( $wpdb->prepare(
- "SELECT enabled FROM %s WHERE pers_id = %d AND product_id = %d",
- $table_name,
- $myresults->pers_id,
- $product_id
- ));
- if ($add ==''){
- $aff_rows = $wpdb->insert( $table_name, array( 'product_id' => $product_id, 'pers_id' => $myresults->pers_id, 'enabled' => '1' ) );
- }
- }
- //enable\disable personalization
- $myresult = $wpdb->get_results("SELECT pers_id FROM ". $table_name ." WHERE product_id = ".$product_id);
- foreach ($myresult as $myresults){
- $post_var_name = 'enabled_'.$myresults->pers_id;
- if ($_POST[$post_var_name] == 'ON'){
- $query = "UPDATE ".$table_name." SET `enabled` = '1' WHERE `product_id` = ".$product_id." AND `pers_id` = ".$myresults->pers_id." LIMIT 1 ;";
- $wpdb->query($query);
- }else{
- $query = "UPDATE ".$table_name." SET `enabled` = '0' WHERE `product_id` = ".$product_id." AND `pers_id` = ".$myresults->pers_id." LIMIT 1 ;";
- $wpdb->query($query);
- }
- }
- }
- }
- add_action('admin_menu', 'template_plugin');
- function template_plugin() {
- //create new top-level menu
- // add_menu_page('Header Options Plugin Settings', 'Header Options', 'administrator', __FILE__, 'display_menu_settings_page',plugins_url('/images/icon.png', __FILE__));
- add_menu_page('WPEC Personalize', 'WPEC Personalize', 'administrator', __FILE__, 'template_plugin_settings');
- }
- /*
- ADMIN
- */
- function template_plugin_settings() {
- global $wpdb;
- // added by vanzoink.com to clear up some php warnings
- $update = $del_option = $add_option = false;
- // end of add
- $table_name = $wpdb->prefix . "wpsc_pers_global";
- $table_name_all = $wpdb->prefix . 'wpsc_pers_products';
- if (isset ($_POST['option_change'])){
- $myresult = $wpdb->get_results("SELECT pers_id FROM ". $table_name );
- foreach ($myresult as $myresults){
- $pers_name = 'custom_text_'.$myresults->pers_id;
- $pers_type = 'pers_type_'.$myresults->pers_id;
- $wpdb->update( $table_name, array( 'pers_name' => $_POST[$pers_name], 'pers_type' => $_POST[$pers_type] ), array( 'pers_id' => $myresults->pers_id));
- }
- $update = true;
- }
- if ($_GET['action'] == 'add' && !isset ($_POST['option_change'])){
- $id_pers = $wpdb->get_var($wpdb->prepare("SELECT pers_id FROM ".$table_name." ORDER BY pers_id DESC LIMIT 0 , 1"));
- $id_pers++;
- $aff_rows = $wpdb->insert( $table_name, array( 'pers_id' => $id_pers, 'pers_name' => 'personalization text', 'pers_type' => 'textfield' ) );
- /* changed by vanzoink.com for 1.8 compatibility */
- // $myresult = $wpdb->get_results("SELECT id FROM ". $wpdb->prefix ."wpsc_product_list" );
- $myresult = $wpdb->get_results("SELECT id FROM ". $wpdb->prefix ."posts WHERE 'post_type' = 'wpsc-product' " );
- /* end of change */
- foreach ($myresult as $myresults){
- $aff_rows = $wpdb->insert( $table_name_all, array( 'product_id' => $myresults->id, 'pers_id' => $id_pers, 'enabled' => 1 ) );
- }
- $add_option = true;
- }
- if ($_GET['action'] == 'del' && !isset ($_POST['option_change'])){
- $wpdb->query('DELETE FROM `'.$table_name.'` WHERE `pers_id` = '.$_GET['id'].' LIMIT 1');
- $wpdb->query('DELETE FROM `'.$table_name_all.'` WHERE `pers_id` = '.$_GET['id']);
- $del_option = true;
- }
- ?>
- <div class="wrap">
- <h2>WPEC Personalize</h2>
- <?php if($update){?>
- <div class="updated">
- <p><strong>Options saved.</strong></p>
- </div>
- <?php }?>
- <?php if($add_option){?>
- <div class="updated">
- <p><strong>New field was successfully added</strong></p>
- </div>
- <?php }?>
- <?php if($del_option){?>
- <div class="updated">
- <p><strong>The field was successfully deleted</strong></p>
- </div>
- <?php }?>
- <form method="post" >
- <input name="option_change" type="hidden" value="">
- <?
- $plugin_url = explode ('&', $_SERVER['REQUEST_URI']);
- $myresult = $wpdb->get_results("SELECT * FROM ". $table_name." ORDER BY pers_id ASC" );
- foreach ($myresult as $personalization){
- echo '<input name="custom_text_'.$personalization->pers_id.'" type="text" size="60" value="'.$personalization->pers_name.'">';
- if($personalization->pers_type == 'textfield'){
- echo '<select size="1" name="pers_type_'.$personalization->pers_id.'"> <option value="textfield" SELECTED >textfield</option> <option value="textarea">textarea</option> </select>';
- }else{
- echo '<select size="1" name="pers_type_'.$personalization->pers_id.'"> <option value="textfield">textfield</option> <option value="textarea" SELECTED>textarea</option> </select>';
- }
- echo '<a class="submitdelete deletion" href="'.$plugin_url[0].'&action=del&id='.$personalization->pers_id.'">delete</a> <br>';
- }
- ?>
- <p class="submit">
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
- <a href="<?php echo $plugin_url[0]; ?>&action=add">Add new field</a> </p>
- </form>
- </div>
- <? // donation section ?>
- <style>
- .donation-section {
- padding: 20px;
- text-align: left;
- width: 600px;
- }
- .donation-section h3 {
- background: transparent!important;
- font-size: 24px;
- font-weight: bold;
- color: #555;
- padding: 0;
- margin: 0 0 18px;
- }
- .donation-section .donate-link {
- display: inline-block;
- padding: 0 10px 3px;
- background: #069;
- text-shadow: #000 1px 1px 1px;
- color: #fff !important;
- line-height: 22px;
- text-decoration: none;
- -moz-border-radius: 4px;
- -webkit-border-radius: 4px;
- border-radius: 4px;
- }
- </style>
- <div class="postbox donation-section">
- <h3>Donate to the Author</h3>
- <p>Has this plugin helped you? If so, please consider making a donation to compensate for the time, energy, and financial investment of the developers.</p>
- <p><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=U98WSHGPXJ2V8" target='_blank' class='donate-link'>Donate Now</a></p>
- </div>
- <? // donation section ?>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement