-
Notifications
You must be signed in to change notification settings - Fork 0
/
stampinup.php
231 lines (199 loc) · 7.1 KB
/
stampinup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/**
* @package Stampinup
* @version 0.3
*/
/*
Plugin Name: Stampin Up easy
Plugin URI: http://www.hosl.de/
Description: This Plugin adds a shortcode for easy Stampin Up Product presentation and adds your dbwsdemoid to every stampinup shop link to you place in the content.
Author: Andreas H.
Version: 0.3
Author URI: http://hosl.de/
*/
/**
* Add parent stylesheet to child
*/
function stampinup_enqueue_styles() {
wp_enqueue_style( 'stampinup-style', plugins_url('stampinup.css', __FILE__));
}
add_action( 'wp_enqueue_scripts', 'stampinup_enqueue_styles' );
/**
* Add Shortcode stampused
* adds Stampin Up products to your post
*/
function stempeltier_stampused_sc( $atts , $content = null ) {
// Attributes
extract( shortcode_atts(
array(
'size' => 'small',
'style' => 'stampused',
), $atts )
);
switch( true ) {
case strtolower($size) === "small":
$imgsize = "s";
break;
case strtolower($size) === "big":
$imgsize = "g";
break;
default:
$size = "s";
}
$size = sanitize_text_field( $size );
$style = sanitize_text_field( $style );
$products = sanitize_text_field( $products );
// Content
$products = explode(" ", $content, 20);
// DemoID from DB
$demoid = get_option( 'stampinup-demoid' );
// HOSTCODE from DB
$hostcode = get_option( 'stampinup-hostcode' );
if ( $hostcode != '' ) {
$hostcode = "&hostcode=$hostcode";
}
// Code
$return = "<div class=\"$style $style-wrap\">\n";
//$return.= "<!-- $content :".count($products)." -->\n";
foreach ($products as $product) {
//$return.= "<!-- $product -->\n";
if ( preg_match( "/^[0-9]{6}$/", $product) ) {
$return.= " <div class=\"$style-item $style-item-$size\">\n";
$return.= " <a href=\"https://www.stampinup.de/products/$product?dbwsdemoid=$demoid$hostcode\"
alt=\"Stampin Up Product $product\" title=\"Stampin Up Online Shop Product $product\" target=\"_blank\">
<img src=\"//www2.stampinup.com/images/EC/$product$imgsize.jpg\" alt=\"Stampin Up Product $product\"></a>";
/*$return.= " <a href=\"http://www2.stampinup.com/ECWeb/ProductDetails.aspx?productID=$product&dbwsdemoid=$demoid\"
alt=\"Stampin Up Product $product\" title=\"Stampin Up Online Shop Product $product\" target=\"_blank\">
<img src=\"//www2.stampinup.com/images/EC/$product$imgsize.jpg\" alt=\"Stampin Up Product $product\"></a>";*/
$return.= " </div>\n";
}
}
$return.= "</div>\n";
return $return;
}
add_shortcode( 'stampused', 'stempeltier_stampused_sc' );
/**
* Add Shortcode stampprod
* adds Stampin Up products to your post
*/
function stempeltier_stampprod_sc( $atts , $content = null ) {
// Attributes
extract( shortcode_atts(
array(
'id' => '0',
'hover' => 'yes',
'style' => 'stampprod',
), $atts )
);
switch( true ) {
case strtolower($hover) === "yes":
$hover = "true";
break;
default:
$hover = "false";
}
if ( preg_match( "/^[0-9]{6}$/", $id) ) {
$product = $id;
}
else {
$id = 0;
}
$style = sanitize_text_field( $style );
// Content
$linktext = sanitize_text_field( $content );
// DemoID from DB
$demoid = get_option( 'stampinup-demoid' );
// HOSTCODE from DB
$hostcode = get_option( 'stampinup-hostcode' );
if ( $hostcode != '' ) {
$hostcode = "&hostcode=$hostcode";
}
// Code
if ( $id != 0 ) {
wp_enqueue_script( 'stempprod-js', get_stylesheet_directory_uri() . '/js/stampsc.js', array(), '0.0.1', true);
$return = "<a href=\"https://www.stampinup.de/products/$product?dbwsdemoid=$demoid$hostcode\"
alt=\"Stampin Up Product $product\" title=\"Stampin Up Online Shop Product $product\" target=\"_blank\" class=\"$style\">";
if ( $hover ) {
$return.= " <span id=\"stampprod-span\">";
$return.= " <img src=\"//www2.stampinup.com/images/EC/${product}s.jpg\" alt=\"Stampin Up Product $product\">";
$return.= " </span>";
}
$return.= $linktext;
$return.= "</a>";
}
else {
$return = $linktext;
}
return $return;
}
add_shortcode( 'stampprod', 'stempeltier_stampprod_sc' );
/**
* Add content filter for demoid
*/
function stampinup_demoid_content_filter($content) {
// if( is_singular() && is_main_query() ) {
if( is_main_query() ) {
// DemoID from DB
$demoid = get_option( 'stampinup-demoid' );
// HOSTCODE from DB
$hostcode = get_option( 'stampinup-hostcode' );
if ( $hostcode != '' ) {
$hostcode = "&hostcode=$hostcode";
}
$new_content = preg_replace( '/(|\&\;)dbwsdemoid=[0-9]+/i', '', $content );
$new_content = preg_replace( '/(href=.http:\/\/www2\.stampinup\.com\/ECWeb\/[a-z.?&=;0-9]+)/i', '$1&dbwsdemoid='.$demoid, $new_content) ;
$new_content = preg_replace( '/(href=.https:\/\/www\.stampinup\.(com|de)\/search\/[a-z.?&=;0-9]+)/i', '$1?&dbwsdemoid='.$demoid.$hostcode, $new_content) ;
$new_content = preg_replace( '/(href=.https:\/\/www\.stampinup\.(com|de)\/products\/[a-z.?&=;0-9]+)/i', '$1?&dbwsdemoid='.$demoid.$hostcode, $new_content) ;
$content = $new_content;
}
return $content;
}
add_filter('the_content', 'stampinup_demoid_content_filter');
/**
* Add Settings Menu
* for Stampinup Plugin
*/
add_action( 'admin_menu', 'stampinup_menu' );
/**
* Register Settings Page
*/
function stampinup_menu() {
add_options_page( 'Stampin Up Options', 'Stampin Up', 'manage_options','stampinup-plugin', 'stampinup_options' );
add_action( 'admin_init', 'register_stampinup_settings' );
}
/**
* Register Stampinup settings
*/
function register_stampinup_settings() {
//register our settings
register_setting( 'stampinup-settings-group', 'stampinup-demoid' );
register_setting( 'stampinup-settings-group', 'stampinup-hostcode' );
}
/**
* Build the Settins Page
*/
function stampinup_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
?>
<div class="wrap">
<h2>Stampinup Settings</h2>
<form method="post" action="options.php">
<?php settings_fields( 'stampinup-settings-group' ); ?>
<?php do_settings_sections( 'stampinup-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Your Stampin Up Demo ID</th>
<td><input type="text" name="stampinup-demoid" value="<?php echo esc_attr( get_option('stampinup-demoid') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Your Stampin Up HOSTCODE</th>
<td><input type="text" name="stampinup-hostcode" value="<?php echo esc_attr( get_option('stampinup-hostcode') ); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php }
?>