Post Snippets - Version 3.1.4

Version Description

Download this release

Release Info

Developer wpexpertsio
Plugin Icon 128x128 Post Snippets
Version 3.1.4
Comparing to
See all releases

Code changes from version 3.1.3 to 3.1.4

post-snippets.php CHANGED
@@ -3,302 +3,296 @@
3
  /**
4
  * Post Snippets
5
  *
6
- * @package PS
7
- * @author Postsnippets <support@wpexperts.io>
8
- * @license GPL-2.0+
9
- * @link https://www.postsnippets.com
10
  *
11
  * @wordpress-plugin
12
  * Plugin Name: Post Snippets
13
  * Plugin URI: https://www.postsnippets.com
14
  * Description: Create a library of reusable content and insert it into your posts and pages. Navigate to "Settings > Post Snippets" to get started.
15
- * Version: 3.1.3
16
  * Author: Postsnippets
17
  * Author URI: https://www.postsnippets.com
18
  * License: GPL-2.0+
19
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
20
  * Text Domain: post-snippets
21
  * Domain Path: /lang
22
- *
23
  */
24
 
25
- if ( !function_exists( 'postsnippets_fs' ) ) {
26
- // Create a helper function for easy SDK access.
27
- function postsnippets_fs()
28
- {
29
- global $postsnippets_fs ;
30
-
31
- if ( !isset( $postsnippets_fs ) ) {
32
- // Include Freemius SDK.
33
- require_once dirname( __FILE__ ) . '/freemius/start.php';
34
- $postsnippets_fs = fs_dynamic_init( array(
35
- 'id' => '1576',
36
- 'slug' => 'post-snippets',
37
- 'type' => 'plugin',
38
- 'public_key' => 'pk_58a2ec84c44485a459aae07bfaf5f',
39
- 'is_premium' => false,
40
- 'has_addons' => false,
41
- 'has_paid_plans' => true,
42
- 'trial' => array(
43
- 'days' => 14,
44
- 'is_require_payment' => true,
45
- ),
46
- 'menu' => array(
47
- 'slug' => 'post-snippets',
48
- 'contact' => false,
49
- 'support' => false,
50
- ),
51
- 'is_live' => true,
52
- ) );
53
- }
54
-
55
- return $postsnippets_fs;
56
- }
57
-
58
- // Init Freemius.
59
- postsnippets_fs();
60
- // Signal that SDK was initiated.
61
- do_action( 'postsnippets_fs_loaded' );
62
- function postsnippets_fs_settings_url()
63
- {
64
- return admin_url( 'admin.php?page=post-snippets' );
65
- }
66
-
67
- // postsnippets_fs()->add_filter( 'connect_url', 'postsnippets_fs_settings_url' );
68
- // postsnippets_fs()->add_filter( 'after_skip_url', 'postsnippets_fs_settings_url' );
69
- // postsnippets_fs()->add_filter( 'after_connect_url', 'postsnippets_fs_settings_url' );
70
- // postsnippets_fs()->add_filter( 'after_pending_connect_url', 'postsnippets_fs_settings_url' );
71
- /**
72
- * Only show Post Snippets submenu when PS is open, not on all Settings pages
73
- */
74
- function postsnippets_show_submenu( $is_visible )
75
- {
76
- if ( isset( $_REQUEST['page'] ) ) {
77
- if ( $is_visible && false !== strpos( $_REQUEST['page'], 'post-snippets' ) ) {
78
- return true;
79
- }
80
- }
81
- return false;
82
- }
83
-
84
- postsnippets_fs()->add_filter(
85
- 'is_submenu_visible',
86
- 'postsnippets_show_submenu',
87
- 10,
88
- 2
89
- );
90
- if ( !defined( 'PS_MAIN_FILE' ) ) {
91
- define( 'PS_MAIN_FILE', basename( __FILE__ ) );
92
- }
93
- if ( !defined( 'PS_VERSION' ) ) {
94
- define( 'PS_VERSION', '3.1.3' );
95
- }
96
- if ( !defined( 'PS_MAIN_FILE_PATH' ) ) {
97
- define( 'PS_MAIN_FILE_PATH', __FILE__ );
98
- }
99
- if ( !defined( 'PS_DIRECTORY' ) ) {
100
- define( 'PS_DIRECTORY', plugin_basename( dirname( __FILE__ ) ) );
101
- }
102
- if ( !defined( 'PS_PATH' ) ) {
103
- define( 'PS_PATH', plugin_dir_path( __FILE__ ) );
104
- }
105
- if ( !defined( 'PS_URL' ) ) {
106
- define( 'PS_URL', plugins_url( '', __FILE__ ) . '/' );
107
- }
108
- if ( !defined( 'PS_MAIN_PAGE_URL' ) ) {
109
- define( 'PS_MAIN_PAGE_URL', esc_url( admin_url( 'admin.php?page=post-snippets' ) ) );
110
- }
111
- class PostSnippets
112
- {
113
- /** Holds the plugin instance */
114
- private static $instance = false ;
115
- /** Define plugin constants */
116
- const MIN_PHP_VERSION = '5.3.0' ;
117
- const MIN_WP_VERSION = '3.3' ;
118
- const SETTINGS = 'post_snippets' ;
119
- const OPTION_KEY = 'post_snippets_options' ;
120
- const USER_META_KEY = 'post_snippets' ;
121
- const FILE = __FILE__ ;
122
- /**
123
- * Singleton class
124
- */
125
- public static function getInstance()
126
- {
127
- if ( !self::$instance ) {
128
- self::$instance = new self();
129
- }
130
- return self::$instance;
131
- }
132
-
133
- /**
134
- * Initializes the plugin.
135
- */
136
- private function __construct()
137
- {
138
- if ( !$this->testHost() ) {
139
- return;
140
- }
141
- load_plugin_textdomain( 'post-snippets', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
142
- add_action( 'after_setup_theme', array( &$this, 'phpExecState' ) );
143
- new \PostSnippets\Admin();
144
- new \PostSnippets\WPEditor();
145
- new \PostSnippets\Shortcode();
146
- }
147
-
148
- /**
149
- * PSR-0 compliant autoloader to load classes as needed.
150
- *
151
- * @param string $classname
152
- *
153
- * @return void
154
- */
155
- public static function autoload( $className )
156
- {
157
- if ( __CLASS__ !== mb_substr( $className, 0, strlen( __CLASS__ ) ) ) {
158
- return;
159
- }
160
- $className = ltrim( $className, '\\' );
161
- $fileName = '';
162
- $namespace = '';
163
-
164
- if ( $lastNsPos = strrpos( $className, '\\' ) ) {
165
- $namespace = substr( $className, 0, $lastNsPos );
166
- $className = substr( $className, $lastNsPos + 1 );
167
- $fileName = str_replace( '\\', DIRECTORY_SEPARATOR, $namespace );
168
- $fileName .= DIRECTORY_SEPARATOR;
169
- }
170
-
171
- $fileName .= str_replace( '_', DIRECTORY_SEPARATOR, $className );
172
- require 'src' . DIRECTORY_SEPARATOR . $fileName . '.php';
173
- }
174
-
175
- // -------------------------------------------------------------------------
176
- // Helpers
177
- // -------------------------------------------------------------------------
178
- /**
179
- * Allow snippets to be retrieved directly from PHP.
180
- *
181
- * @since Post Snippets 1.8.9.1
182
- *
183
- * @param string $name The name of the snippet to retrieve
184
- * @param string|array $variables The variables to pass to the snippet,
185
- * formatted as a query string or an associative array.
186
- *
187
- * @return string The Snippet
188
- */
189
- public static function getSnippet( $name, $variables = '' )
190
- {
191
- $snippets = get_option( self::OPTION_KEY, array() );
192
- for ( $i = 0 ; $i < count( $snippets ) ; $i++ ) {
193
-
194
- if ( $snippets[$i]['title'] == $name ) {
195
- if ( !is_array( $variables ) ) {
196
- parse_str( htmlspecialchars_decode( $variables ), $variables );
197
- }
198
- $snippet = $snippets[$i]['snippet'];
199
- $var_arr = explode( ",", $snippets[$i]['vars'] );
200
- if ( !empty($var_arr[0]) ) {
201
- for ( $j = 0 ; $j < count( $var_arr ) ; $j++ ) {
202
- $snippet = str_replace( "{" . $var_arr[$j] . "}", $variables[$var_arr[$j]], $snippet );
203
- }
204
- }
205
- break;
206
- }
207
-
208
- }
209
- return do_shortcode( $snippet );
210
- }
211
-
212
- // -------------------------------------------------------------------------
213
- // Environment Checks
214
- // -------------------------------------------------------------------------
215
- /**
216
- * Checks PHP and WordPress versions.
217
- */
218
- private function testHost()
219
- {
220
- // Check if PHP is too old
221
-
222
- if ( version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '<' ) ) {
223
- // Display notice
224
- add_action( 'admin_notices', array( &$this, 'phpVersionError' ) );
225
- return false;
226
- }
227
-
228
- // Check if WordPress is too old
229
- global $wp_version ;
230
-
231
- if ( version_compare( $wp_version, self::MIN_WP_VERSION, '<' ) ) {
232
- add_action( 'admin_notices', array( &$this, 'wpVersionError' ) );
233
- return false;
234
- }
235
-
236
- return true;
237
- }
238
-
239
- /**
240
- * Displays a warning when installed on an old PHP version.
241
- */
242
- public function phpVersionError()
243
- {
244
- echo '<div class="error"><p><strong>' ;
245
- printf(
246
- 'Error: %3$s requires PHP version %1$s or greater.<br/>' . 'Your installed PHP version: %2$s',
247
- self::MIN_PHP_VERSION,
248
- PHP_VERSION,
249
- $this->getPluginName()
250
- );
251
- echo '</strong></p></div>' ;
252
- }
253
-
254
- /**
255
- * Displays a warning when installed in an old WordPress version.
256
- */
257
- public function wpVersionError()
258
- {
259
- echo '<div class="error"><p><strong>' ;
260
- printf( 'Error: %2$s requires WordPress version %1$s or greater.', self::MIN_WP_VERSION, $this->getPluginName() );
261
- echo '</strong></p></div>' ;
262
- }
263
-
264
- /**
265
- * Get the name of this plugin.
266
- *
267
- * @return string The plugin name.
268
- */
269
- private function getPluginName()
270
- {
271
- $data = get_plugin_data( self::FILE );
272
- return $data['Name'];
273
- }
274
-
275
- // -------------------------------------------------------------------------
276
- // Deprecated methods
277
- // -------------------------------------------------------------------------
278
- /**
279
- * Allow plugins to disable the PHP Code execution feature with a filter.
280
- * Deprecated: Use the POST_SNIPPETS_DISABLE_PHP global constant to disable
281
- * PHP instead.
282
- *
283
- * @see http://wordpress.org/extend/plugins/post-snippets/faq/
284
- * @since 2.1
285
- * @deprecated 2.3
286
  */
287
- public function phpExecState()
288
- {
289
- $filter = apply_filters( 'post_snippets_php_execution_enabled', true );
290
-
291
- if ( $filter == false and !defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
292
- _deprecated_function( 'post_snippets_php_execution_enabled', '2.3', 'define(\'POST_SNIPPETS_DISABLE_PHP\', true);' );
293
- define( 'POST_SNIPPETS_DISABLE_PHP', true );
294
- }
295
-
296
- }
297
-
298
- }
299
- add_action( 'plugins_loaded', array( 'PostSnippets', 'getInstance' ) );
300
- /**
301
- * Load all of the necessary class files for the plugin
302
- */
303
- spl_autoload_register( 'PostSnippets::autoload' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  }
3
  /**
4
  * Post Snippets
5
  *
6
+ * @package PS
7
+ * @author Postsnippets <support@wpexperts.io>
8
+ * @license GPL-2.0+
9
+ * @link https://www.postsnippets.com
10
  *
11
  * @wordpress-plugin
12
  * Plugin Name: Post Snippets
13
  * Plugin URI: https://www.postsnippets.com
14
  * Description: Create a library of reusable content and insert it into your posts and pages. Navigate to "Settings > Post Snippets" to get started.
15
+ * Version: 3.1.4
16
  * Author: Postsnippets
17
  * Author URI: https://www.postsnippets.com
18
  * License: GPL-2.0+
19
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
20
  * Text Domain: post-snippets
21
  * Domain Path: /lang
 
22
  */
23
 
24
+ if ( ! function_exists( 'postsnippets_fs' ) ) {
25
+ // Create a helper function for easy SDK access.
26
+ function postsnippets_fs() {
27
+ global $postsnippets_fs;
28
+
29
+ if ( ! isset( $postsnippets_fs ) ) {
30
+ // Include Freemius SDK.
31
+ include_once dirname( __FILE__ ) . '/freemius/start.php';
32
+ $postsnippets_fs = fs_dynamic_init(
33
+ array(
34
+ 'id' => '1576',
35
+ 'slug' => 'post-snippets',
36
+ 'type' => 'plugin',
37
+ 'public_key' => 'pk_58a2ec84c44485a459aae07bfaf5f',
38
+ 'is_premium' => false,
39
+ 'has_addons' => false,
40
+ 'has_paid_plans' => true,
41
+ 'trial' => array(
42
+ 'days' => 14,
43
+ 'is_require_payment' => true,
44
+ ),
45
+ 'menu' => array(
46
+ 'slug' => 'post-snippets',
47
+ 'contact' => false,
48
+ 'support' => false,
49
+ ),
50
+ 'is_live' => true,
51
+ )
52
+ );
53
+ }
54
+
55
+ return $postsnippets_fs;
56
+ }
57
+
58
+ // Init Freemius.
59
+ postsnippets_fs();
60
+ // Signal that SDK was initiated.
61
+ do_action( 'postsnippets_fs_loaded' );
62
+ function postsnippets_fs_settings_url() {
63
+ return admin_url( 'admin.php?page=post-snippets' );
64
+ }
65
+
66
+ // postsnippets_fs()->add_filter( 'connect_url', 'postsnippets_fs_settings_url' );
67
+ // postsnippets_fs()->add_filter( 'after_skip_url', 'postsnippets_fs_settings_url' );
68
+ // postsnippets_fs()->add_filter( 'after_connect_url', 'postsnippets_fs_settings_url' );
69
+ // postsnippets_fs()->add_filter( 'after_pending_connect_url', 'postsnippets_fs_settings_url' );
70
+ /**
71
+ * Only show Post Snippets submenu when PS is open, not on all Settings pages
72
+ */
73
+ function postsnippets_show_submenu( $is_visible ) {
74
+ if ( isset( $_REQUEST['page'] ) ) {
75
+ if ( $is_visible && false !== strpos( sanitize_key( $_REQUEST['page'] ), 'post-snippets' ) ) {
76
+ return true;
77
+ }
78
+ }
79
+ return false;
80
+ }
81
+
82
+ postsnippets_fs()->add_filter(
83
+ 'is_submenu_visible',
84
+ 'postsnippets_show_submenu',
85
+ 10,
86
+ 2
87
+ );
88
+ if ( ! defined( 'PS_MAIN_FILE' ) ) {
89
+ define( 'PS_MAIN_FILE', basename( __FILE__ ) );
90
+ }
91
+ if ( ! defined( 'PS_VERSION' ) ) {
92
+ define( 'PS_VERSION', '3.1.4' );
93
+ }
94
+ if ( ! defined( 'PS_MAIN_FILE_PATH' ) ) {
95
+ define( 'PS_MAIN_FILE_PATH', __FILE__ );
96
+ }
97
+ if ( ! defined( 'PS_DIRECTORY' ) ) {
98
+ define( 'PS_DIRECTORY', plugin_basename( dirname( __FILE__ ) ) );
99
+ }
100
+ if ( ! defined( 'PS_PATH' ) ) {
101
+ define( 'PS_PATH', plugin_dir_path( __FILE__ ) );
102
+ }
103
+ if ( ! defined( 'PS_URL' ) ) {
104
+ define( 'PS_URL', plugins_url( '', __FILE__ ) . '/' );
105
+ }
106
+ if ( ! defined( 'PS_MAIN_PAGE_URL' ) ) {
107
+ define( 'PS_MAIN_PAGE_URL', esc_url( admin_url( 'admin.php?page=post-snippets' ) ) );
108
+ }
109
+ class PostSnippets {
110
+
111
+ /**
112
+ * Holds the plugin instance
113
+ */
114
+ private static $instance = false;
115
+ /**
116
+ * Define plugin constants
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  */
118
+ const MIN_PHP_VERSION = '5.3.0';
119
+ const MIN_WP_VERSION = '3.3';
120
+ const SETTINGS = 'post_snippets';
121
+ const OPTION_KEY = 'post_snippets_options';
122
+ const USER_META_KEY = 'post_snippets';
123
+ const FILE = __FILE__;
124
+ /**
125
+ * Singleton class
126
+ */
127
+ public static function getInstance() {
128
+ if ( ! self::$instance ) {
129
+ self::$instance = new self();
130
+ }
131
+ return self::$instance;
132
+ }
133
+
134
+ /**
135
+ * Initializes the plugin.
136
+ */
137
+ private function __construct() {
138
+ if ( ! $this->testHost() ) {
139
+ return;
140
+ }
141
+ load_plugin_textdomain( 'post-snippets', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
142
+ add_action( 'after_setup_theme', array( &$this, 'phpExecState' ) );
143
+ new \PostSnippets\Admin();
144
+ new \PostSnippets\WPEditor();
145
+ new \PostSnippets\Shortcode();
146
+ }
147
+
148
+ /**
149
+ * PSR-0 compliant autoloader to load classes as needed.
150
+ *
151
+ * @param string $classname
152
+ *
153
+ * @return void
154
+ */
155
+ public static function autoload( $className ) {
156
+ if ( __CLASS__ !== mb_substr( $className, 0, strlen( __CLASS__ ) ) ) {
157
+ return;
158
+ }
159
+ $className = ltrim( $className, '\\' );
160
+ $fileName = '';
161
+ $namespace = '';
162
+
163
+ if ( $lastNsPos = strrpos( $className, '\\' ) ) {
164
+ $namespace = substr( $className, 0, $lastNsPos );
165
+ $className = substr( $className, $lastNsPos + 1 );
166
+ $fileName = str_replace( '\\', DIRECTORY_SEPARATOR, $namespace );
167
+ $fileName .= DIRECTORY_SEPARATOR;
168
+ }
169
+
170
+ $fileName .= str_replace( '_', DIRECTORY_SEPARATOR, $className );
171
+ include 'src' . DIRECTORY_SEPARATOR . $fileName . '.php';
172
+ }
173
+
174
+ // -------------------------------------------------------------------------
175
+ // Helpers
176
+ // -------------------------------------------------------------------------
177
+ /**
178
+ * Allow snippets to be retrieved directly from PHP.
179
+ *
180
+ * @since Post Snippets 1.8.9.1
181
+ *
182
+ * @param string $name The name of the snippet to retrieve
183
+ * @param string|array $variables The variables to pass to the snippet,
184
+ * formatted as a query string or an associative array.
185
+ *
186
+ * @return string The Snippet
187
+ */
188
+ public static function getSnippet( $name, $variables = '' ) {
189
+ $snippets = get_option( self::OPTION_KEY, array() );
190
+ $snippet_count = count( $snippets );
191
+ for ( $i = 0; $i < $snippet_count; $i++ ) {
192
+
193
+ if ( $snippets[ $i ]['title'] == $name ) {
194
+ if ( ! is_array( $variables ) ) {
195
+ parse_str( htmlspecialchars_decode( $variables ), $variables );
196
+ }
197
+ $snippet = $snippets[ $i ]['snippet'];
198
+ $var_arr = explode( ',', $snippets[ $i ]['vars'] );
199
+ if ( ! empty( $var_arr[0] ) ) {
200
+ $var_arr_count = count( $var_arr );
201
+ for ( $j = 0; $j < $var_arr_count; $j++ ) {
202
+ $snippet = str_replace( '{' . $var_arr[ $j ] . '}', $variables[ $var_arr[ $j ] ], $snippet );
203
+ }
204
+ }
205
+ break;
206
+ }
207
+ }
208
+ return do_shortcode( $snippet );
209
+ }
210
+
211
+ // -------------------------------------------------------------------------
212
+ // Environment Checks
213
+ // -------------------------------------------------------------------------
214
+ /**
215
+ * Checks PHP and WordPress versions.
216
+ */
217
+ private function testHost() {
218
+ // Check if PHP is too old
219
+
220
+ if ( version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '<' ) ) {
221
+ // Display notice
222
+ add_action( 'admin_notices', array( &$this, 'phpVersionError' ) );
223
+ return false;
224
+ }
225
+
226
+ // Check if WordPress is too old
227
+ global $wp_version;
228
+
229
+ if ( version_compare( $wp_version, self::MIN_WP_VERSION, '<' ) ) {
230
+ add_action( 'admin_notices', array( &$this, 'wpVersionError' ) );
231
+ return false;
232
+ }
233
+
234
+ return true;
235
+ }
236
+
237
+ /**
238
+ * Displays a warning when installed on an old PHP version.
239
+ */
240
+ public function phpVersionError() {
241
+ echo '<div class="error"><p><strong>';
242
+ printf(
243
+ 'Error: %3$s requires PHP version %1$s or greater.<br/>' . 'Your installed PHP version: %2$s',
244
+ esc_html( self::MIN_PHP_VERSION ),
245
+ esc_html( PHP_VERSION ),
246
+ esc_html( $this->getPluginName() )
247
+ );
248
+ echo '</strong></p></div>';
249
+ }
250
+
251
+ /**
252
+ * Displays a warning when installed in an old WordPress version.
253
+ */
254
+ public function wpVersionError() {
255
+ echo '<div class="error"><p><strong>';
256
+ printf( 'Error: %2$s requires WordPress version %1$s or greater.', esc_html( self::MIN_WP_VERSION ), esc_html( $this->getPluginName() ) );
257
+ echo '</strong></p></div>';
258
+ }
259
+
260
+ /**
261
+ * Get the name of this plugin.
262
+ *
263
+ * @return string The plugin name.
264
+ */
265
+ private function getPluginName() {
266
+ $data = get_plugin_data( self::FILE );
267
+ return $data['Name'];
268
+ }
269
+
270
+ // -------------------------------------------------------------------------
271
+ // Deprecated methods
272
+ // -------------------------------------------------------------------------
273
+ /**
274
+ * Allow plugins to disable the PHP Code execution feature with a filter.
275
+ * Deprecated: Use the POST_SNIPPETS_DISABLE_PHP global constant to disable
276
+ * PHP instead.
277
+ *
278
+ * @see http://wordpress.org/extend/plugins/post-snippets/faq/
279
+ * @since 2.1
280
+ * @deprecated 2.3
281
+ */
282
+ public function phpExecState() {
283
+ $filter = apply_filters( 'post_snippets_php_execution_enabled', true );
284
+
285
+ if ( $filter == false && ! defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
286
+ _deprecated_function( 'post_snippets_php_execution_enabled', '2.3', 'define(\'POST_SNIPPETS_DISABLE_PHP\', true);' );
287
+ define( 'POST_SNIPPETS_DISABLE_PHP', true );
288
+ }
289
+
290
+ }
291
+
292
+ }
293
+ add_action( 'plugins_loaded', array( 'PostSnippets', 'getInstance' ) );
294
+ /**
295
+ * Load all of the necessary class files for the plugin
296
+ */
297
+ spl_autoload_register( 'PostSnippets::autoload' );
298
  }
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: wpexpertsio
3
  Tags: custom snippet, custom shortcode, snippet, snippets, shortcode, shortcodes, block, blocks, html
4
  Requires at least: 3.3
5
- Tested up to: 5.8
6
  Requires PHP: 5.3
7
- Stable tag: 3.1.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -107,6 +107,10 @@ your clients to be able to use PHP code in a post snippet.
107
 
108
  == Changelog ==
109
 
 
 
 
 
110
  = Version 3.1.3 - 10 Aug 2021 =
111
 
112
  * Updated Freemius SDK Version 2.4.2
2
  Contributors: wpexpertsio
3
  Tags: custom snippet, custom shortcode, snippet, snippets, shortcode, shortcodes, block, blocks, html
4
  Requires at least: 3.3
5
+ Tested up to: 5.9
6
  Requires PHP: 5.3
7
+ Stable tag: 3.1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
107
 
108
  == Changelog ==
109
 
110
+ = Version 3.1.4 - 28 Jan 2022 =
111
+
112
+ * Improvement - Code Optimization
113
+
114
  = Version 3.1.3 - 10 Aug 2021 =
115
 
116
  * Updated Freemius SDK Version 2.4.2
src/PostSnippets/Admin.php CHANGED
@@ -7,1084 +7,1098 @@ namespace PostSnippets;
7
  *
8
  * Class that renders out the HTML for the settings screen and contains helpful
9
  * methods to simply the maintainance of the admin screen.
10
- *
11
  */
12
- class Admin
13
- {
14
- /**
15
- * Plugin settings.
16
- *
17
- * @var array
18
- */
19
- protected $settings ;
20
- /**
21
- * Defines hooks and filters for admin page.
22
- */
23
- public function __construct()
24
- {
25
- add_action( 'admin_menu', array( &$this, 'menu' ) );
26
- add_action( 'admin_init', array( &$this, 'init' ) );
27
- add_action( 'current_screen', array( &$this, 'addHeaderXss' ) );
28
- add_filter( 'plugin_action_links_' . plugin_basename( PS_MAIN_FILE_PATH ), array( $this, 'actionLinks' ) );
29
- // Newsletter sign-up admin notice
30
- add_action( 'admin_notices', array( $this, 'admin_notice_newsletter' ) );
31
- // Get started admin notice
32
- add_action( 'admin_notices', array( $this, 'admin_notice_get_started' ) );
33
- add_action( 'wp_ajax_update_post_snippets_order', array( $this, 'update_snippets_order' ) );
34
- add_action( 'wp_ajax_update_post_snippet_title', array( $this, 'update_post_snippet_title' ) );
35
- add_action( 'wp_ajax_update_post_snippet', array( $this, 'update_post_snippet' ) );
36
- add_action( 'wp_ajax_delete_post_snippet', array( $this, 'delete_post_snippet' ) );
37
- add_action( 'wp_ajax_sync_up', array( $this, 'sync_up' ) );
38
- add_action( 'wp_ajax_sync_list', array( $this, 'sync_list' ) );
39
- add_action( 'wp_ajax_sync', array( $this, 'sync' ) );
40
- add_action( 'enqueue_block_editor_assets', array( $this, 'load_block' ) );
41
- }
42
-
43
- public function load_block()
44
- {
45
- wp_enqueue_script(
46
- 'post-snippets-block',
47
- PS_URL . 'dist/blocks.build.js',
48
- array( 'wp-blocks', 'wp-editor' ),
49
- true
50
- );
51
-
52
- $snippets = get_option( \PostSnippets::OPTION_KEY );
53
- if(isset($snippets) && !empty($snippets) && is_array($snippets)) {
54
- usort( $snippets, function ( $a, $b ) {
55
- return strcasecmp( $a["title"], $b["title"] );
56
- } );
57
- }
58
- wp_localize_script( 'post-snippets-block', 'post_snippets_s', $snippets );
59
- }
60
-
61
- // -------------------------------------------------------------------------
62
- // Setup
63
- // -------------------------------------------------------------------------
64
- /**
65
- * Register the administration page.
66
- *
67
- * @return void
68
- */
69
- public function menu()
70
- {
71
- $capability = $this->get_allowed_capability();
72
-
73
- if ( $capability == 'edit_posts' ) {
74
- $allowed = true;
75
- }
76
-
77
-
78
- if ( current_user_can( 'manage_options' ) or isset( $allowed ) ) {
79
- $optionPage = add_menu_page(
80
- __( 'Post Snippets', 'post-snippets' ),
81
- __( 'Post Snippets', 'post-snippets' ),
82
- $capability,
83
- 'post-snippets',
84
- array( $this, 'optionsPage' ),
85
- PS_URL . 'assets/icon.svg'
86
- );
87
- $newsPage = add_submenu_page(
88
- 'post-snippets',
89
- __( 'News', 'post-snippets' ),
90
- __( 'News', 'post-snippets' ),
91
- $capability,
92
- 'post-snippets-news',
93
- array( $this, 'newsPage' )
94
- );
95
- /*$optionPage = add_submenu_page(
96
- __( 'Post Snippets', 'post-snippets'),
97
- __( 'Post Snippets', 'post-snippets'),
98
- $capability,
99
- 'post-snippets',
100
- array ( &$this, 'optionsPage' )
101
- );*/
102
- new Help( $optionPage );
103
- } else {
104
- add_menu_page(
105
- __( 'Post Snippets', 'post-snippets' ),
106
- __( 'Post Snippets', 'post-snippets' ),
107
- 'manage_options',
108
- 'post-snippets',
109
- array( $this, 'overviewPage' ),
110
- PS_URL . 'assets/icon.svg'
111
- );
112
- }
113
-
114
- }
115
-
116
- /**
117
- * Initialize assets for the administration page.
118
- *
119
- * @return void
120
- */
121
- public function init()
122
- {
123
- wp_register_script(
124
- 'post-snippets',
125
- plugins_url( '/assets/post-snippets.js', \PostSnippets::FILE ),
126
- array( 'jquery' ),
127
- PS_VERSION,
128
- true
129
- );
130
- $this->scripts();
131
- $this->registerSettings();
132
- }
133
-
134
- /**
135
- * Enqueue scripts to be loaded.
136
- *
137
- * @return void
138
- */
139
- public function scripts()
140
- {
141
- // Localize the strings in the script
142
- $translation_array = array(
143
- 'invalid_shortcode' => __( 'Invalid shortcode name', 'post-snippets' ),
144
- 'save_title_nonce' => wp_create_nonce('ps-save-title-nonce'),
145
- 'update_snippet_nonce' => wp_create_nonce('ps-update-snippet-nonce'),
146
- );
147
- wp_localize_script( 'post-snippets', 'post_snippets', $translation_array );
148
- // Add CSS for Pro features page
149
- $features_style_url = plugins_url( '/assets/features.css', \PostSnippets::FILE );
150
- wp_register_style(
151
- 'post-snippets-icons',
152
- $features_style_url,
153
- array(),
154
- PS_VERSION
155
- );
156
- wp_enqueue_style( 'post-snippets-icons' );
157
- // Add CSS for icons
158
- $features_style_url = plugins_url( '/assets/icons.css', \PostSnippets::FILE );
159
- wp_register_style(
160
- 'post-snippets-features',
161
- $features_style_url,
162
- array(),
163
- PS_VERSION
164
- );
165
- wp_enqueue_style( 'post-snippets-features' );
166
- // Add CSS for newsletter opt-in
167
- $features_style_url = plugins_url( '/assets/newsletter.css', \PostSnippets::FILE );
168
- wp_register_style(
169
- 'post-snippets-newsletter',
170
- $features_style_url,
171
- array(),
172
- PS_VERSION
173
- );
174
- wp_enqueue_style( 'post-snippets-newsletter' );
175
- wp_enqueue_script( 'jquery-ui-sortable' );
176
- wp_enqueue_script( 'jquery-ui-dialog' );
177
- wp_enqueue_script( 'underscore' );
178
- wp_enqueue_script( 'post-snippets' );
179
- }
180
-
181
- /**
182
- * Add X-XSS-Protection header.
183
- *
184
- * Newer versions of Chrome does not allow form tags to be submitted in the
185
- * forms. This header disables that functionlity on the Post Snippets admin
186
- * screen only.
187
- */
188
- public function addHeaderXss( $current_screen )
189
- {
190
- if ( $current_screen->base == 'settings_page_post-snippets/post-snippets' ) {
191
- header( 'X-XSS-Protection: 0' );
192
- }
193
- }
194
-
195
- /**
196
- * Quick link to the Post Snippets Settings page from the Plugins page.
197
- *
198
- * @param array $links Array of all plugin links
199
- *
200
- * @return array $links Array with all the plugin's action links
201
- */
202
- public function actionLinks( $links )
203
- {
204
- $links[] = '<a href="' . PS_MAIN_PAGE_URL . '">' . __( 'Settings', 'post-snippets' ) . '</a>';
205
- return $links;
206
- }
207
-
208
- // -------------------------------------------------------------------------
209
- // Handle form submissions
210
- // -------------------------------------------------------------------------
211
- /**
212
- * Add New Snippet.
213
- */
214
- private function add()
215
- {
216
-
217
- if ( isset( $_POST['add-snippet'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( $_POST['update_snippets_nonce'], 'update_snippets' ) ) {
218
- $snippets = get_option( \PostSnippets::OPTION_KEY );
219
- if ( empty($snippets) ) {
220
- $snippets = array();
221
- }
222
- array_push( $snippets, array(
223
- 'title' => 'Untitled',
224
- 'vars' => '',
225
- 'description' => '',
226
- 'shortcode' => false,
227
- 'php' => false,
228
- 'wptexturize' => false,
229
- 'snippet' => '',
230
- ) );
231
- update_option( \PostSnippets::OPTION_KEY, $snippets );
232
- $this->message( __( 'A snippet named Untitled has been added.', 'post-snippets' ) );
233
- }
234
-
235
- }
236
-
237
- public function sync_list()
238
- {
239
-
240
- if ( wp_verify_nonce( $_POST['sync_down'], 'sync_down' ) ) {
241
-
242
- if ( postsnippets_fs()->can_use_premium_code() ) {
243
- $license = postsnippets_fs()->_get_license();
244
-
245
- if ( $license != null ) {
246
- $id = $license->id;
247
- $secret = $license->secret_key;
248
- $query = array();
249
- $query["lid"] = $id;
250
- $query["s"] = $secret;
251
- $ch = curl_init();
252
- curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/list" );
253
- curl_setopt( $ch, CURLOPT_POST, 1 );
254
- curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
255
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
256
- $server_output = curl_exec( $ch );
257
- $response = json_decode( $server_output );
258
- wp_send_json_success( $response );
259
- }
260
-
261
- }
262
-
263
- } else {
264
- wp_send_json_error();
265
- }
266
-
267
- }
268
-
269
- public function sync()
270
- {
271
-
272
- if ( wp_verify_nonce( $_POST['sync_up'], 'sync_up' ) ) {
273
- $ids = explode( ",", $_POST["ids"] );
274
-
275
- if ( count( $ids ) == 0 ) {
 
 
276
  wp_send_json_error();
277
  return;
278
  }
279
-
280
- $snippets = get_option( \PostSnippets::OPTION_KEY );
281
-
282
- if ( postsnippets_fs()->can_use_premium_code() ) {
283
- $license = postsnippets_fs()->_get_license();
284
-
285
- if ( $license != null ) {
286
- $id = $license->id;
287
- $secret = $license->secret_key;
288
- $query = array();
289
- $query["lid"] = $id;
290
- $query["s"] = $secret;
291
- $ch = curl_init();
292
- curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/list" );
293
- curl_setopt( $ch, CURLOPT_POST, 1 );
294
- curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
295
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
296
- $server_output = curl_exec( $ch );
297
- $response = json_decode( $server_output, true );
298
- $saved_snippets = $response["data"];
299
- $i = 0;
300
- $updated = array();
301
- foreach ( $snippets as &$snippet ) {
302
- foreach ( $saved_snippets as $saved ) {
303
-
304
- if ( $snippet["title"] == $saved["title"] && in_array( $saved["id"], $ids ) ) {
305
- $snippet = $saved;
306
- $options = json_decode( $saved["options"], true );
307
- $snippet["php"] = ( $options["php"] ? "1" : "0" );
308
- $snippet["shortcode"] = ( $options["shortcode"] ? "1" : "0" );
309
- $snippet["wptexturize"] = ( $options["wptexturize"] ? "1" : "0" );
310
- if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
311
- $snippet['php'] = '0';
312
- }
313
- $updated[] = $snippet["title"];
314
- }
315
-
316
- }
317
- }
318
- foreach ( $saved_snippets as $saved ) {
319
- if ( !in_array( $saved["id"], $ids ) ) {
320
- continue;
321
- }
322
-
323
- if ( !in_array( $saved["title"], $updated ) ) {
324
- $snippet = $saved;
325
- $options = json_decode( $saved["options"], true );
326
- $snippet["php"] = ( $options["php"] ? "1" : "0" );
327
- $snippet["shortcode"] = ( $options["shortcode"] ? "1" : "0" );
328
- $snippet["wptexturize"] = ( $options["wptexturize"] ? "1" : "0" );
329
- if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
330
- $snippet['php'] = '0';
331
- }
332
- $snippets[] = $snippet;
333
- }
334
-
335
- }
336
- update_option( \PostSnippets::OPTION_KEY, $snippets );
337
- wp_send_json_success();
338
- }
339
-
340
- }
341
-
342
- } else {
343
- wp_send_json_error();
344
- }
345
-
346
- }
347
-
348
- public function sync_up()
349
- {
350
-
351
- if ( wp_verify_nonce( $_POST['sync_up'], 'sync_up' ) ) {
352
- $snippets = get_option( \PostSnippets::OPTION_KEY );
353
-
354
- if ( empty($snippets) || !isset( $_POST['key'] ) ) {
355
- wp_send_json_error( __( 'Nothing selected to save.', 'post-snippets' ) );
356
- return;
357
- }
358
-
359
-
360
- if ( postsnippets_fs()->can_use_premium_code() ) {
361
- $license = postsnippets_fs()->_get_license();
362
-
363
- if ( $license != null ) {
364
- $id = $license->id;
365
- $secret = $license->secret_key;
366
- $snippets = get_option( \PostSnippets::OPTION_KEY );
367
-
368
- if ( empty($snippets) || !isset( $_POST['key'] ) ) {
369
- wp_send_json_error( __( 'Nothing selected to save.', 'post-snippets' ) );
370
- return;
371
- }
372
-
373
- $toSave = $_POST['key'];
374
- $newsnippets = array();
375
- $data = null;
376
- foreach ( $snippets as $key => $snippet ) {
377
-
378
- if ( $key == $toSave ) {
379
- $data = $snippet;
380
- break;
381
- }
382
-
383
- }
384
-
385
- if ( $data == null ) {
386
- wp_send_json_error( __( "Snippet {$key} not found", 'post-snippets' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  return;
388
  }
389
-
390
- $query = array();
391
- $query["update"] = $_POST["update"];
392
- $query["lid"] = $id;
393
- $query["s"] = $secret;
394
- $query["title"] = $snippet["title"];
395
- $query["description"] = $snippet["description"];
396
- $query["vars"] = $snippet["vars"];
397
- $query["snippet"] = $snippet["snippet"];
398
- $query["options"] = json_encode( array(
399
- "shortcode" => isset( $snippet["shortcode"] ) && $snippet["shortcode"] == "1",
400
- "php" => isset( $snippet["php"] ) && $snippet["php"] == "1",
401
- "wptexturize" => isset( $snippet["wptexturize"] ) && $snippet["wptexturize"] == "1",
402
- ) );
403
- $ch = curl_init();
404
- curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/save" );
405
- curl_setopt( $ch, CURLOPT_POST, 1 );
406
- curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
407
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
408
- $server_output = curl_exec( $ch );
409
- $response = json_decode( $server_output );
410
- curl_close( $ch );
411
-
412
- if ( isset( $response->code ) && $response->code != "1" ) {
413
- $msg = "?";
414
- if ( isset( $response->code ) ) {
415
- $msg = $response->data;
416
- }
417
- wp_send_json_error( $response );
418
- } else {
419
- wp_send_json_success();
420
- }
421
-
422
- } else {
423
- wp_send_json_error( 'enter-license' );
424
- return;
425
- }
426
-
427
- } else {
428
- wp_send_json_error( 'license' );
429
- return;
430
- }
431
-
432
- }
433
-
434
- }
435
-
436
- /**
437
- * Delete snippet via ajax
438
- */
439
- public function delete_post_snippet()
440
- {
441
-
442
- if ( wp_verify_nonce( $_POST['delete_snippet'], 'delete_snippet' ) ) {
443
- $snippets = get_option( \PostSnippets::OPTION_KEY );
444
-
445
- if ( empty($snippets) || !isset( $_POST['key'] ) ) {
446
- wp_send_json_error( __( 'Nothing selected to delete.', 'post-snippets' ) );
447
- return;
448
- }
449
-
450
- $delete = $_POST['key'];
451
- $newsnippets = array();
452
- foreach ( $snippets as $key => $snippet ) {
453
- if ( $key != $delete ) {
454
- array_push( $newsnippets, $snippet );
455
- }
456
- }
457
- update_option( \PostSnippets::OPTION_KEY, $newsnippets );
458
- wp_send_json_success();
459
- } else {
460
- wp_send_json_error( __( 'Security check failed.', 'post-snippets' ) );
461
- }
462
-
463
- wp_die();
464
- }
465
-
466
- /**
467
- * Delete Snippet/s.
468
- */
469
- private function delete()
470
- {
471
-
472
- if ( isset( $_POST['delete-snippets'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( $_POST['update_snippets_nonce'], 'update_snippets' ) ) {
473
- $snippets = get_option( \PostSnippets::OPTION_KEY );
474
-
475
- if ( empty($snippets) || !isset( $_POST['checked'] ) ) {
476
- $this->message( __( 'Nothing selected to delete.', 'post-snippets' ) );
477
- return;
478
- }
479
-
480
- $delete = $_POST['checked'];
481
- $newsnippets = array();
482
- foreach ( $snippets as $key => $snippet ) {
483
- if ( in_array( $key, $delete ) == false ) {
484
- array_push( $newsnippets, $snippet );
485
- }
486
- }
487
- update_option( \PostSnippets::OPTION_KEY, $newsnippets );
488
- $this->message( __( 'Selected snippets have been deleted.', 'post-snippets' ) );
489
- }
490
-
491
- }
492
-
493
- /**
494
- * Update Snippet/s.
495
- */
496
- private function update()
497
- {
498
-
499
- if ( isset( $_POST['update-snippets'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( $_POST['update_snippets_nonce'], 'update_snippets' ) ) {
500
- $default = array(
501
- 'title' => '',
502
- 'rtf' => '0',
503
- 'snippet' => '',
504
- 'description' => '',
505
- 'vars' => '',
506
- 'shortcode' => '0',
507
- 'php' => '0',
508
- 'wptexturize' => '0',
509
- );
510
- $formatted_snippets = array();
511
-
512
- if ( !empty($_POST['snippets']) ) {
513
- $snippets = map_deep( $_POST['snippets'], 'trim' );
514
- $i = 0;
515
- foreach ( $snippets as $snippet ) {
516
- if ( empty($snippets) ) {
517
- continue;
518
- }
519
- $snippet = wp_parse_args( $snippet, $default );
520
- $snippet['title'] = str_replace( ' ', '', $snippet['title'] );
521
- if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
522
- $snippet['php'] = '0';
523
- }
524
- $snippet['snippet'] = wp_specialchars_decode( trim( stripslashes( $snippet['snippet'] ) ), ENT_NOQUOTES );
525
- $snippet['description'] = wp_specialchars_decode( trim( stripslashes( $snippet['description'] ) ), ENT_NOQUOTES );
526
- $formatted_snippets[$i] = $snippet;
527
- $i++;
528
- }
529
- }
530
-
531
- update_option( \PostSnippets::OPTION_KEY, $formatted_snippets );
532
- $this->message( __( 'Snippets have been updated.', 'post-snippets' ) );
533
- }
534
-
535
- }
536
-
537
- /**
538
- * Update User Option.
539
- *
540
- * Sets the per user option for the read-only overview page.
541
- *
542
- * @since Post Snippets 1.9.7
543
- */
544
- private function setUserOptions()
545
- {
546
-
547
- if ( isset( $_POST['post_snippets_user_nonce'] ) && wp_verify_nonce( $_POST['post_snippets_user_nonce'], 'post_snippets_user_options' ) ) {
548
- $id = get_current_user_id();
549
- $render = ( isset( $_POST['render'] ) ? true : false );
550
- update_user_meta( $id, \PostSnippets::USER_META_KEY, $render );
551
- }
552
-
553
- }
554
-
555
- /**
556
- * Get User Option.
557
- *
558
- * Gets the per user option for the read-only overview page.
559
- *
560
- * @since Post Snippets 1.9.7
561
- * @return boolean If overview should be rendered on output or not
562
- */
563
- private function getUserOptions()
564
- {
565
- $id = get_current_user_id();
566
- $options = get_user_meta( $id, \PostSnippets::USER_META_KEY, true );
567
- return $options;
568
- }
569
-
570
- // -------------------------------------------------------------------------
571
- // HTML generation for option pages
572
- // -------------------------------------------------------------------------
573
- /**
574
- * Display Flashing Message.
575
- *
576
- * @param string $message Message to display to the user.
577
- */
578
- private function message( $message )
579
- {
580
- if ( $message ) {
581
- echo "<div class='updated'><p><strong>{$message}</strong></p></div>" ;
582
- }
583
- }
584
-
585
- public function newsPage()
586
- {
587
- $plugins = array( array(
588
- "name" => "myCred",
589
- "description" => "myCred makes it simple to create a loyalty program or gamify your website so that you can increase the average customer value with less marketing effort.",
590
- "image" => "myCred.png",
591
- "url" => "https://wordpress.org/plugins/mycred",
592
- ), array(
593
- "name" => "WP Contact Slider",
594
- "description" => "WP contact slider is simple contact slider to display contactform7, Gravity forms, Wp Forms, Caldera forms, Constant Contact Forms or display random text or HTML.",
595
- "image" => "ContactSlider.png",
596
- "url" => "https://wordpress.org/plugins/wp-contact-slider/",
597
- ), array(
598
- "name" => "Wholesale For WooCommerce",
599
- "description" => "Sign up wholesale customers and display wholesale prices based on multiple wholesale user roles on your existing WooCommerce store",
600
- "image" => "WholesaleForWoocommerce.png",
601
- "url" => "https://woocommerce.com/products/wholesale-for-woocommerce/",
602
- ), array(
603
- "name" => "WooCommerce Product Disclaimer",
604
- "description" => "Woocommerce extension where you can set some products to accept terms and conditions before adding product to cart. ",
605
- "image" => "ProductDisclaimer.png",
606
- "url" => "https://wordpress.org/plugins/woo-product-disclaimer/",
607
- ) );
608
- include PS_PATH . "/views/admin_news.php";
609
- }
610
-
611
- /**
612
- * Creates the snippets administration page.
613
- *
614
- * For users with manage_options capability (admin, super admin).
615
- *
616
- * @since Post Snippets 1.8.8
617
- */
618
- public function optionsPage()
619
- {
620
- // Handle Form Submits
621
- $this->add();
622
- $this->delete();
623
- $this->update();
624
- // Header
625
- echo '
 
 
 
 
 
626
  <!-- Create a header in the default WordPress \'wrap\' container -->
627
  <div class="wrap">
628
  <div id="icon-plugins" class="icon32"></div>
629
- <h2>' ;
630
- echo __( 'Post Snippets', 'post-snippets' ) ;
631
- echo '</h2>' ;
632
- // Tabs
633
- $active_tab = ( isset( $_GET['tab'] ) ? $_GET['tab'] : 'snippets' );
634
- $base_url = '?page=post-snippets&amp;tab=';
635
- $tabs = array(
636
- 'snippets' => __( 'Manage Snippets', 'post-snippets' ),
637
- 'options' => __( 'Options', 'post-snippets' ),
638
- 'tools' => __( 'Import/Export', 'post-snippets' ),
639
- );
640
- if ( postsnippets_fs()->is_not_paying() ) {
641
- $tabs['upgrade'] = __( 'Upgrade', 'post-snippets' );
642
- }
643
- echo '<h2 class="nav-tab-wrapper">' ;
644
- foreach ( $tabs as $tab => $title ) {
645
- $active = ( $active_tab == $tab ? ' nav-tab-active' : '' );
646
- $link = $base_url . $tab;
647
- if ( $tab == 'upgrade' ) {
648
- $link = postsnippets_fs()->get_upgrade_url();
649
- }
650
- echo "<a href='{$link}' class='nav-tab {$active} tab-{$tab}'>{$title}</a>" ;
651
- }
652
- echo '</h2>' ;
653
- // Tab content
654
-
655
- if ( $active_tab == 'snippets' ) {
656
- $this->tabSnippets();
657
- } elseif ( $active_tab == 'options' ) {
658
- $this->tabOptions();
659
- } elseif ( $active_tab == 'tools' ) {
660
- $this->tabTools();
661
- } else {
662
- $this->tabFeatures();
663
- }
664
-
665
- // Close it
666
- echo '</div>' ;
667
- }
668
-
669
- /**
670
- * Tab to Manage Snippets.
671
- *
672
- * @since Post Snippets 2.0
673
- */
674
- private function tabSnippets()
675
- {
676
- echo '<p class="description post-snippets-documentation-note">' ;
677
- _e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
678
- echo '</p>' ;
679
- $data = array();
680
- echo View::render( 'admin_snippets', $data ) ;
681
- }
682
-
683
- /**
684
- * Tab to set options for the plugin.
685
- *
686
- * @return void
687
- */
688
- private function tabOptions()
689
- {
690
- echo '<p class="description post-snippets-documentation-note">' ;
691
- _e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
692
- echo '</p>' ;
693
- $data = array();
694
- echo View::render( 'admin_options', $data ) ;
695
- }
696
-
697
- /**
698
- * Tab for Import/Export
699
- *
700
- * @since Post Snippets 2.0
701
- */
702
- private function tabTools()
703
- {
704
- echo '<p class="description post-snippets-documentation-note">' ;
705
- _e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
706
- echo '</p>' ;
707
- $ie = new ImportExport();
708
- // Create header and export html form
709
- printf( "<h3>%s</h3>", __( 'Import/Export', 'post-snippets' ) );
710
- printf( "<h4>%s</h4>", __( 'Export', 'post-snippets' ) );
711
- echo '<form method="post">' ;
712
- echo '<p>' ;
713
- _e( 'Export your snippets for backup or to import them on another site.', 'post-snippets' );
714
- echo '</p>' ;
715
- printf( "<input type='submit' class='button' name='postsnippets_export' value='%s' />", __( 'Export Snippets', 'post-snippets' ) );
716
- echo '</form>' ;
717
- // Export logic, and import html form and logic
718
- $ie->exportSnippets();
719
- echo $ie->importSnippets() ;
720
- }
721
-
722
- /**
723
- * Tab for Pro features
724
- *
725
- * @since Post Snippets 2.5.4
726
- */
727
- private function tabFeatures()
728
- {
729
- $features = new Features();
730
- echo $features->showFeatures() ;
731
- }
732
-
733
- /**
734
- * Creates a read-only overview page.
735
- *
736
- * For users with edit_posts capability but without manage_options
737
- * capability.
738
- *
739
- * @since Post Snippets 1.9.7
740
- */
741
- public function overviewPage()
742
- {
743
- // Header
744
- echo '<div class="wrap">' ;
745
- echo '<h2>Post Snippets</h2>' ;
746
- echo '<p>' ;
747
- _e( 'This is an overview of all snippets defined for this site. These snippets are inserted into posts from the post editor using the Post Snippets button. You can choose to see the snippets here as-is or as they are actually rendered on the website. Enabling rendered snippets for this overview might look strange if the snippet have dependencies on variables, CSS or other parameters only available on the frontend. If that is the case it is recommended to keep this option disabled.', 'post-snippets' );
748
- echo '</p>' ;
749
- // Form
750
- $this->setUserOptions();
751
- $render = $this->getUserOptions();
752
- echo '<form method="post" action="">' ;
753
- wp_nonce_field( 'post_snippets_user_options', 'post_snippets_user_nonce' );
754
- $this->checkbox( __( 'Display rendered snippets', 'post-snippets' ), 'render', $render );
755
- $this->submit( 'update-post-snippets-user', __( 'Update', 'post-snippets' ) );
756
- echo '</form>' ;
757
- // Snippet List
758
- $snippets = get_option( \PostSnippets::OPTION_KEY );
759
- if ( !empty($snippets) ) {
760
- foreach ( $snippets as $key => $snippet ) {
761
- echo "<hr style='border: none;border-top:1px dashed #aaa; margin:24px 0;' />" ;
762
- echo "<h3>{$snippet['title']}" ;
763
- if ( $snippet['description'] ) {
764
- echo "<span class='description'> {$snippet['description']}</span>" ;
765
- }
766
- echo "</h3>" ;
767
- if ( $snippet['vars'] ) {
768
- printf( "<strong>%s:</strong> {$snippet['vars']}<br/>", __( 'Variables', 'post-snippets' ) );
769
- }
770
- // echo "<strong>Variables:</strong> {$snippet['vars']}<br/>";
771
- $options = array();
772
- if ( $snippet['shortcode'] ) {
773
- array_push( $options, 'Shortcode' );
774
- }
775
- if ( $snippet['php'] ) {
776
- array_push( $options, 'PHP' );
777
- }
778
- if ( $snippet['wptexturize'] ) {
779
- array_push( $options, 'wptexturize' );
780
- }
781
- if ( $options ) {
782
- printf( "<strong>%s:</strong> %s<br/>", __( 'Options', 'post-snippets' ), implode( ', ', $options ) );
783
- }
784
- printf( "<br/><strong>%s:</strong><br/>", __( 'Snippet', 'post-snippets' ) );
785
-
786
- if ( $render ) {
787
- echo do_shortcode( $snippet['snippet'] ) ;
788
- } else {
789
- echo "<code>" ;
790
- echo nl2br( htmlspecialchars( $snippet['snippet'], ENT_NOQUOTES ) ) ;
791
- echo "</code>" ;
792
- }
793
-
794
- }
795
- }
796
- // Close
797
- echo '</div>' ;
798
- }
799
-
800
- // -------------------------------------------------------------------------
801
- // Register and callbacks for the options tab
802
- // -------------------------------------------------------------------------
803
- /**
804
- * Register settings for the options tab.
805
- *
806
- * @return void
807
- */
808
- protected function registerSettings()
809
- {
810
- $this->settings = get_option( \PostSnippets::SETTINGS );
811
- register_setting( \PostSnippets::SETTINGS, \PostSnippets::SETTINGS );
812
- add_settings_section(
813
- 'general_section',
814
- __( 'General', 'post-snippets' ),
815
- null,
816
- 'post-snippets'
817
- );
818
- add_settings_field(
819
- 'exclude_from_custom_editors',
820
- __( 'Exclude from Custom Editors', 'post-snippets' ),
821
- array( $this, 'cbExcludeFromCustomEditors' ),
822
- 'post-snippets',
823
- 'general_section',
824
- array(
825
- 'id' => 'exclude_from_custom_editors',
826
- 'label_for' => 'exclude_from_custom_editors',
827
- 'description' => __( 'Checking this only includes Post Snippets on standard WordPress post editing screens.', 'post-snippets' ),
828
- )
829
- );
830
- }
831
-
832
- /**
833
- * Callback for HTML generator for exlusion of custom editors.
834
- *
835
- * @param array $args
836
- *
837
- * @return void
838
- */
839
- public function cbExcludeFromCustomEditors( $args )
840
- {
841
- $checked = ( isset( $this->settings[$args['id']] ) ? $this->settings[$args['id']] : false );
842
- echo "<input type='checkbox' id='{$args['id']}' " ;
843
- echo "name='" . \PostSnippets::SETTINGS . "[{$args['id']}]' value='1' " ;
844
- if ( $checked ) {
845
- echo 'checked ' ;
846
- }
847
- echo " />" ;
848
- echo "<span class='description'>{$args['description']}</span>" ;
849
- }
850
-
851
- // -------------------------------------------------------------------------
852
- // HTML and Form element methods for Snippets form
853
- // -------------------------------------------------------------------------
854
- /**
855
- * Checkbox.
856
- *
857
- * Renders the HTML for an input checkbox.
858
- *
859
- * @param string $label The label rendered to screen
860
- * @param string $name The unique name and id to identify the input
861
- * @param boolean $checked If the input is checked or not
862
- *
863
- * @return void
864
- */
865
- public static function checkbox( $label, $name, $checked )
866
- {
867
- echo "<label for=\"{$name}\">" ;
868
- printf( '<input type="checkbox" name="%1$s" id="%1$s" value="true"', $name );
869
- if ( $checked ) {
870
- echo ' checked' ;
871
- }
872
- echo ' />' ;
873
- echo " {$label}</label><br/>" ;
874
- }
875
-
876
- /**
877
- * Submit.
878
- *
879
- * Renders the HTML for a submit button.
880
- *
881
- * @since Post Snippets 1.9.7
882
- *
883
- * @param string $name The name that identifies the button on submit
884
- * @param string $label The label rendered on the button
885
- * @param string $class Optional. Button class. Default: button-primary
886
- * @param boolean $wrap Optional. Wrap in a submit div. Default: true
887
- *
888
- * @return void
889
- */
890
- public static function submit(
891
- $name,
892
- $label,
893
- $class = 'button-primary',
894
- $wrap = true
895
- )
896
- {
897
- $btn = sprintf(
898
- '<input type="submit" name="%s" value="%s" class="%s" />&nbsp;&nbsp;&nbsp;',
899
- $name,
900
- $label,
901
- $class
902
- );
903
- if ( $wrap ) {
904
- $btn = "<div class=\"submit\">{$btn}</div>";
905
- }
906
- echo $btn ;
907
- }
908
-
909
- /**
910
- *
911
- * Show newsletter opt-in, only in Post Snippets.
912
- * Not on Pro features tab/page.
913
- * Not when user selected to Hide opt-in.
914
- *
915
- * @since 2.5.4
916
- */
917
- public function admin_notice_newsletter()
918
- {
919
- // Hide newsletter opt-in if option is true
920
- if ( get_option( 'ps_hide_admin_notice_newsletter' ) == true ) {
921
- return;
922
- }
923
- // Set option if "hide" button click detected (custom querystring value set to 1).
924
-
925
- if ( !empty($_REQUEST['ps-dismiss-newsletter-nag']) ) {
926
- update_option( 'ps_hide_admin_notice_newsletter', true );
927
- return;
928
- }
929
-
930
- // Show newsletter notice.
931
-
932
- if ( get_current_screen()->id == 'settings_page_post-snippets/post-snippets' ) {
933
- $active_tab = ( isset( $_GET['tab'] ) ? $_GET['tab'] : 'snippets' );
934
- if ( $active_tab != 'features' ) {
935
- include_once PS_PATH . '/views/admin_notice_newsletter.php';
936
- }
937
- }
938
-
939
- }
940
-
941
- /**
942
- *
943
- * Show 'Get started' admin notice', everywhere.
944
- * Not when user already clicked or dismissed.
945
- *
946
- * @since 2.5.4
947
- */
948
- public function admin_notice_get_started()
949
- {
950
- // Hide newsletter opt-in if option is true
951
- if ( get_option( 'ps_hide_admin_notice_get_started' ) == true ) {
952
- return;
953
- }
954
- // Set option if "hide" button click detected (custom query string value set to 1).
955
-
956
- if ( !empty($_REQUEST['ps-dismiss-get-started-nag']) ) {
957
- update_option( 'ps_hide_admin_notice_get_started', true );
958
- return;
959
- }
960
-
961
- // Show newsletter notice.
962
-
963
- if ( strpos( get_current_screen()->id, '/post-snippets' ) == false ) {
964
- $active_tab = ( isset( $_GET['tab'] ) ? $_GET['tab'] : 'snippets' );
965
- if ( $active_tab != 'features' ) {
966
- include_once PS_PATH . '/views/admin_notice_get_started.php';
967
- }
968
- }
969
-
970
- }
971
-
972
- /**
973
- * Save Updated sorting
974
- */
975
- public function update_snippets_order()
976
- {
977
- if ( empty($_POST['order']) || !is_array( $_POST['order'] ) ) {
978
- wp_send_json_error( 'order data not received' );
979
- }
980
- $capability = $this->get_allowed_capability();
981
- if ( !current_user_can( $capability ) ) {
982
- wp_send_json_error( 'permission denied' );
983
- }
984
- $orders = array_map( 'intval', $_POST['order'] );
985
- $snippets = get_option( 'post_snippets_options', array() );
986
- if ( empty($snippets) ) {
987
- wp_send_json_error( 'snippets empty' );
988
- }
989
- $updated_order = array();
990
- foreach ( $orders as $order ) {
991
- if ( isset( $snippets[$order] ) ) {
992
- $updated_order[] = $snippets[$order];
993
- }
994
- }
995
- update_option( 'post_snippets_options', $updated_order );
996
- wp_send_json_success( 'success' );
997
- }
998
-
999
- /**
1000
- * Save Updated title
1001
- */
1002
- public function update_post_snippet_title()
1003
- {
1004
- if ( !isset( $_POST['key'] ) || empty($_POST['title']) ) {
1005
- wp_send_json_error();
1006
- }
1007
- if ( !wp_verify_nonce( $_POST['save_title_nonce'], 'ps-save-title-nonce' ) ) {
1008
- wp_send_json_error();
1009
- }
1010
-
1011
- $capability = $this->get_allowed_capability();
1012
- if ( !current_user_can( $capability ) ) {
1013
- wp_send_json_error('permission denied');
1014
- }
1015
- $pkey = intval( $_POST['key'] );
1016
- $title = sanitize_text_field( $_POST['title'] );
1017
- $snippets = get_option( 'post_snippets_options', array() );
1018
- if ( empty($snippets) ) {
1019
- wp_send_json_error();
1020
- }
1021
-
1022
- if ( isset( $snippets[$pkey] ) && $snippets[$pkey]['title'] == $title ) {
1023
-
1024
- wp_send_json_error( __( 'You have not made any changes to the snippet title.', 'post-snippets' ) );
1025
- }
1026
-
1027
- foreach ( $snippets as $key => $snippet ) {
1028
- if ( $snippet['title'] == $title ) {
1029
- wp_send_json_error( __( 'Duplicate title is not allowed. Please use different title for each snippets.', 'post-snippets' ) );
1030
- }
1031
- }
1032
-
1033
- if ( isset( $snippets[$pkey] ) ) {
1034
- $snippets[$pkey]['title'] = $title;
1035
- update_option( 'post_snippets_options', $snippets );
1036
- }
1037
-
1038
- wp_send_json_success( $title );
1039
- }
1040
-
1041
- public function update_post_snippet()
1042
- {
1043
- if ( !isset( $_POST['key'] ) ) {
1044
- wp_send_json_error();
1045
- }
1046
- if ( !wp_verify_nonce( $_POST['update_snippet_nonce'], 'ps-update-snippet-nonce' ) ) {
1047
- wp_send_json_error();
1048
- }
1049
-
1050
- $capability = $this->get_allowed_capability();
1051
- if ( !current_user_can( $capability ) ) {
1052
- wp_send_json_error('permission denied');
1053
- }
1054
- $key = intval( $_POST['key'] );
1055
- $snippets = get_option( 'post_snippets_options', array() );
1056
- if ( empty($snippets) ) {
1057
- wp_send_json_error();
1058
- }
1059
- $title = "";
1060
- if(isset($_POST['title'])){
1061
- $title = sanitize_text_field( $_POST['title'] );
1062
- }
1063
-
1064
- if ( isset( $snippets[$key] ) ) {
1065
- $snippets[$key]['description'] = wp_specialchars_decode( stripslashes( $_POST['description'] ) );
1066
- $snippets[$key]['snippet'] = wp_specialchars_decode( stripslashes( $_POST['snippet'] ) );
1067
- $snippets[$key]['vars'] = wp_specialchars_decode( stripslashes( $_POST['vars'] ) );
1068
- $snippets[$key]['shortcode'] = wp_specialchars_decode( stripslashes( $_POST['shortcode'] ) );
1069
- $snippets[$key]['php'] = wp_specialchars_decode( stripslashes( $_POST['php'] ) );
1070
- $snippets[$key]['wptexturize'] = wp_specialchars_decode( stripslashes( $_POST['wptexturize'] ) );
1071
- if(!empty($title)){
1072
- $snippets[ $key ]['title'] = $title;
1073
- }
1074
- update_option( 'post_snippets_options', $snippets );
1075
- }
1076
-
1077
- wp_send_json_success( $title );
1078
- }
1079
-
1080
- public function get_allowed_capability(){
1081
- $capability = 'manage_options';
1082
-
1083
- if ( defined( 'POST_SNIPPETS_ALLOW_EDIT_POSTS' ) and current_user_can( 'edit_posts' ) ) {
1084
- $capability = 'edit_posts';
1085
- }
1086
-
1087
- return $capability;
1088
- }
1089
-
1090
- }
7
  *
8
  * Class that renders out the HTML for the settings screen and contains helpful
9
  * methods to simply the maintainance of the admin screen.
 
10
  */
11
+ class Admin {
12
+
13
+ /**
14
+ * Plugin settings.
15
+ *
16
+ * @var array
17
+ */
18
+ protected $settings;
19
+ /**
20
+ * Defines hooks and filters for admin page.
21
+ */
22
+ public function __construct() {
23
+ add_action( 'admin_menu', array( &$this, 'menu' ) );
24
+ add_action( 'admin_init', array( &$this, 'init' ) );
25
+ add_action( 'current_screen', array( &$this, 'addHeaderXss' ) );
26
+ add_filter( 'plugin_action_links_' . plugin_basename( PS_MAIN_FILE_PATH ), array( $this, 'actionLinks' ) );
27
+ // Newsletter sign-up admin notice
28
+ add_action( 'admin_notices', array( $this, 'admin_notice_newsletter' ) );
29
+ // Get started admin notice
30
+ add_action( 'admin_notices', array( $this, 'admin_notice_get_started' ) );
31
+ // add_action( 'wp_ajax_update_post_snippets_order', array( $this, 'update_snippets_order' ) );
32
+ add_action( 'wp_ajax_update_post_snippet_title', array( $this, 'update_post_snippet_title' ) );
33
+ add_action( 'wp_ajax_update_post_snippet', array( $this, 'update_post_snippet' ) );
34
+ add_action( 'wp_ajax_delete_post_snippet', array( $this, 'delete_post_snippet' ) );
35
+ add_action( 'wp_ajax_sync_up', array( $this, 'sync_up' ) );
36
+ add_action( 'wp_ajax_sync_list', array( $this, 'sync_list' ) );
37
+ add_action( 'wp_ajax_sync', array( $this, 'sync' ) );
38
+ add_action( 'enqueue_block_editor_assets', array( $this, 'load_block' ) );
39
+ }
40
+
41
+ public function load_block() {
42
+ wp_enqueue_script(
43
+ 'post-snippets-block',
44
+ PS_URL . 'dist/blocks.build.js',
45
+ array( 'wp-blocks', 'wp-editor' ),
46
+ true
47
+ );
48
+
49
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
50
+ if ( isset( $snippets ) && ! empty( $snippets ) && is_array( $snippets ) ) {
51
+ usort(
52
+ $snippets,
53
+ function ( $a, $b ) {
54
+ return strcasecmp( $a['title'], $b['title'] );
55
+ }
56
+ );
57
+ }
58
+ wp_localize_script( 'post-snippets-block', 'post_snippets_s', $snippets );
59
+ }
60
+
61
+ // -------------------------------------------------------------------------
62
+ // Setup
63
+ // -------------------------------------------------------------------------
64
+ /**
65
+ * Register the administration page.
66
+ *
67
+ * @return void
68
+ */
69
+ public function menu() {
70
+ $capability = $this->get_allowed_capability();
71
+
72
+ if ( $capability == 'edit_posts' ) {
73
+ $allowed = true;
74
+ }
75
+
76
+ if ( current_user_can( 'manage_options' ) || isset( $allowed ) ) {
77
+ $optionPage = add_menu_page(
78
+ __( 'Post Snippets', 'post-snippets' ),
79
+ __( 'Post Snippets', 'post-snippets' ),
80
+ $capability,
81
+ 'post-snippets',
82
+ array( $this, 'optionsPage' ),
83
+ PS_URL . 'assets/icon.svg'
84
+ );
85
+ $newsPage = add_submenu_page(
86
+ 'post-snippets',
87
+ __( 'News', 'post-snippets' ),
88
+ __( 'News', 'post-snippets' ),
89
+ $capability,
90
+ 'post-snippets-news',
91
+ array( $this, 'newsPage' )
92
+ // array( $this, 'overviewPage' )
93
+ );
94
+ /*
95
+ $optionPage = add_submenu_page(
96
+ __( 'Post Snippets', 'post-snippets'),
97
+ __( 'Post Snippets', 'post-snippets'),
98
+ $capability,
99
+ 'post-snippets',
100
+ array ( &$this, 'optionsPage' )
101
+ );*/
102
+ new Help( $optionPage );
103
+ } else {
104
+ add_menu_page(
105
+ __( 'Post Snippets', 'post-snippets' ),
106
+ __( 'Post Snippets', 'post-snippets' ),
107
+ 'manage_options',
108
+ 'post-snippets',
109
+ array( $this, 'overviewPage' ),
110
+ PS_URL . 'assets/icon.svg'
111
+ );
112
+ }
113
+
114
+ }
115
+
116
+ /**
117
+ * Initialize assets for the administration page.
118
+ *
119
+ * @return void
120
+ */
121
+ public function init() {
122
+ wp_register_script(
123
+ 'post-snippets',
124
+ plugins_url( '/assets/post-snippets.js', \PostSnippets::FILE ),
125
+ array( 'jquery' ),
126
+ PS_VERSION,
127
+ true
128
+ );
129
+ $this->scripts();
130
+ $this->registerSettings();
131
+ }
132
+
133
+ /**
134
+ * Enqueue scripts to be loaded.
135
+ *
136
+ * @return void
137
+ */
138
+ public function scripts() {
139
+ // Localize the strings in the script
140
+ $translation_array = array(
141
+ 'invalid_shortcode' => __( 'Invalid shortcode name', 'post-snippets' ),
142
+ 'save_title_nonce' => wp_create_nonce( 'ps-save-title-nonce' ),
143
+ 'update_snippet_nonce' => wp_create_nonce( 'ps-update-snippet-nonce' ),
144
+ );
145
+ wp_localize_script( 'post-snippets', 'post_snippets', $translation_array );
146
+ // Add CSS for Pro features page
147
+ $features_style_url = plugins_url( '/assets/features.css', \PostSnippets::FILE );
148
+ wp_register_style(
149
+ 'post-snippets-icons',
150
+ $features_style_url,
151
+ array(),
152
+ PS_VERSION
153
+ );
154
+ wp_enqueue_style( 'post-snippets-icons' );
155
+ // Add CSS for icons
156
+ $features_style_url = plugins_url( '/assets/icons.css', \PostSnippets::FILE );
157
+ wp_register_style(
158
+ 'post-snippets-features',
159
+ $features_style_url,
160
+ array(),
161
+ PS_VERSION
162
+ );
163
+ wp_enqueue_style( 'post-snippets-features' );
164
+ // Add CSS for newsletter opt-in
165
+ $features_style_url = plugins_url( '/assets/newsletter.css', \PostSnippets::FILE );
166
+ wp_register_style(
167
+ 'post-snippets-newsletter',
168
+ $features_style_url,
169
+ array(),
170
+ PS_VERSION
171
+ );
172
+ wp_enqueue_style( 'post-snippets-newsletter' );
173
+ wp_enqueue_script( 'jquery-ui-sortable' );
174
+ wp_enqueue_script( 'jquery-ui-dialog' );
175
+ wp_enqueue_script( 'underscore' );
176
+ wp_enqueue_script( 'post-snippets' );
177
+ }
178
+
179
+ /**
180
+ * Add X-XSS-Protection header.
181
+ *
182
+ * Newer versions of Chrome does not allow form tags to be submitted in the
183
+ * forms. This header disables that functionlity on the Post Snippets admin
184
+ * screen only.
185
+ */
186
+ public function addHeaderXss( $current_screen ) {
187
+ if ( $current_screen->base == 'settings_page_post-snippets/post-snippets' ) {
188
+ header( 'X-XSS-Protection: 0' );
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Quick link to the Post Snippets Settings page from the Plugins page.
194
+ *
195
+ * @param array $links Array of all plugin links
196
+ *
197
+ * @return array $links Array with all the plugin's action links
198
+ */
199
+ public function actionLinks( $links ) {
200
+ $links[] = '<a href="' . PS_MAIN_PAGE_URL . '">' . __( 'Settings', 'post-snippets' ) . '</a>';
201
+ return $links;
202
+ }
203
+
204
+ // -------------------------------------------------------------------------
205
+ // Handle form submissions
206
+ // -------------------------------------------------------------------------
207
+ /**
208
+ * Add New Snippet.
209
+ */
210
+ private function add() {
211
+
212
+ if ( isset( $_POST['add-snippet'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['update_snippets_nonce'] ), 'update_snippets' ) && current_user_can( 'manage_options' ) ) {
213
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
214
+ if ( empty( $snippets ) ) {
215
+ $snippets = array();
216
+ }
217
+ array_push(
218
+ $snippets,
219
+ array(
220
+ 'title' => 'Untitled',
221
+ 'vars' => '',
222
+ 'description' => '',
223
+ 'shortcode' => false,
224
+ 'php' => false,
225
+ 'wptexturize' => false,
226
+ 'snippet' => '',
227
+ )
228
+ );
229
+ update_option( \PostSnippets::OPTION_KEY, $snippets );
230
+ $this->message( __( 'A snippet named Untitled has been added.', 'post-snippets' ) );
231
+ }
232
+
233
+ }
234
+
235
+ public function sync_list() {
236
+
237
+ if ( isset( $_POST['sync_down'] ) && wp_verify_nonce( sanitize_key( $_POST['sync_down'] ), 'sync_down' ) && current_user_can( 'manage_options' ) ) {
238
+
239
+ if ( postsnippets_fs()->can_use_premium_code() ) {
240
+ $license = postsnippets_fs()->_get_license();
241
+
242
+ if ( $license != null ) {
243
+ $id = $license->id;
244
+ $secret = $license->secret_key;
245
+ $query = array();
246
+ $query['lid'] = $id;
247
+ $query['s'] = $secret;
248
+ $arg = array(
249
+ 'method' => 'POST',
250
+ 'body' => ( $query ),
251
+ 'data_format' => 'body',
252
+ );
253
+ $response = wp_remote_post( 'https://cloud.postsnippets.com/wp-content/themes/twentytwenty/ps-cloud/list.php', $arg );
254
+ $body = wp_remote_retrieve_body( $response );
255
+ // $http_code = wp_remote_retrieve_response_code( $response );
256
+
257
+ $response = json_decode( $body );
258
+ // $ch = curl_init();
259
+ // curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/list" );
260
+ // curl_setopt( $ch, CURLOPT_POST, 1 );
261
+ // curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
262
+ // curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
263
+ // $server_output = curl_exec( $ch );
264
+ // $response = json_decode( $server_output );
265
+ wp_send_json_success( $response );
266
+ }
267
+ }
268
+ } else {
269
+ wp_send_json_error();
270
+ }
271
+
272
+ }
273
+
274
+ public function sync() {
275
+ if ( isset( $_POST['sync_up'] ) && wp_verify_nonce( sanitize_key( $_POST['sync_up'] ), 'sync_up' ) && current_user_can( 'manage_options' ) ) {
276
+ if ( ! isset( $_POST['ids'] ) ) {
277
  wp_send_json_error();
278
  return;
279
  }
280
+ $ids = explode( ',', sanitize_text_field( wp_unslash( $_POST['ids'] ) ) );
281
+
282
+ foreach ( $ids as $id ) {
283
+ if ( ! is_numeric( $id ) ) {
284
+ wp_send_json_error();
285
+ return;
286
+ }
287
+ }
288
+
289
+ if ( count( $ids ) == 0 ) {
290
+ wp_send_json_error();
291
+ return;
292
+ }
293
+
294
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
295
+
296
+ if ( postsnippets_fs()->can_use_premium_code() ) {
297
+ $license = postsnippets_fs()->_get_license();
298
+
299
+ if ( $license != null ) {
300
+ $id = $license->id;
301
+ $secret = $license->secret_key;
302
+ $query = array();
303
+ $query['lid'] = $id;
304
+ $query['s'] = $secret;
305
+ $arg = array(
306
+ 'method' => 'POST',
307
+ 'body' => ( $query ),
308
+ 'data_format' => 'body',
309
+ );
310
+ $response = wp_remote_post( 'https://cloud.postsnippets.com/wp-content/themes/twentytwenty/ps-cloud/list.php', $arg );
311
+ $body = wp_remote_retrieve_body( $response );
312
+
313
+ // $ch = curl_init();
314
+ // curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/list" );
315
+ // curl_setopt( $ch, CURLOPT_POST, 1 );
316
+ // curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
317
+ // curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
318
+ // $server_output = curl_exec( $ch );
319
+
320
+ $response = json_decode( $body, true );
321
+ $saved_snippets = $response['data'];
322
+ $i = 0;
323
+ $updated = array();
324
+ foreach ( $snippets as &$snippet ) {
325
+ foreach ( $saved_snippets as $saved ) {
326
+
327
+ if ( $snippet['title'] == $saved['title'] && in_array( $saved['id'], $ids ) ) {
328
+ $snippet = $saved;
329
+ $options = json_decode( $saved['options'], true );
330
+ $snippet['php'] = ( $options['php'] ? '1' : '0' );
331
+ $snippet['shortcode'] = ( $options['shortcode'] ? '1' : '0' );
332
+ $snippet['wptexturize'] = ( $options['wptexturize'] ? '1' : '0' );
333
+ if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
334
+ $snippet['php'] = '0';
335
+ }
336
+ $updated[] = $snippet['title'];
337
+ }
338
+ }
339
+ }
340
+ foreach ( $saved_snippets as $saved ) {
341
+ if ( ! in_array( $saved['id'], $ids ) ) {
342
+ continue;
343
+ }
344
+
345
+ if ( ! in_array( $saved['title'], $updated ) ) {
346
+ $snippet = $saved;
347
+ $options = json_decode( $saved['options'], true );
348
+ $snippet['php'] = ( $options['php'] ? '1' : '0' );
349
+ $snippet['shortcode'] = ( $options['shortcode'] ? '1' : '0' );
350
+ $snippet['wptexturize'] = ( $options['wptexturize'] ? '1' : '0' );
351
+ if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
352
+ $snippet['php'] = '0';
353
+ }
354
+ $snippets[] = $snippet;
355
+ }
356
+ }
357
+ update_option( \PostSnippets::OPTION_KEY, $snippets );
358
+ wp_send_json_success();
359
+ }
360
+ }
361
+ } else {
362
+ wp_send_json_error();
363
+ }
364
+
365
+ }
366
+
367
+ public function sync_up() {
368
+
369
+ if ( isset( $_POST['sync_up'] ) && wp_verify_nonce( sanitize_key( $_POST['sync_up'] ), 'sync_up' ) && current_user_can( 'manage_options' ) ) {
370
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
371
+
372
+ if ( empty( $snippets ) || ! isset( $_POST['key'] ) ) {
373
+ wp_send_json_error( __( 'Nothing selected to save.', 'post-snippets' ) );
374
+ return;
375
+ }
376
+
377
+ if ( postsnippets_fs()->can_use_premium_code() ) {
378
+ $license = postsnippets_fs()->_get_license();
379
+
380
+ if ( $license != null ) {
381
+ $id = $license->id;
382
+ $secret = $license->secret_key;
383
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
384
+
385
+ if ( empty( $snippets ) || ! isset( $_POST['key'] ) ) {
386
+ wp_send_json_error( __( 'Nothing selected to save.', 'post-snippets' ) );
387
+ return;
388
+ }
389
+
390
+ $toSave = sanitize_key( $_POST['key'] );
391
+ $newsnippets = array();
392
+ $data = null;
393
+ foreach ( $snippets as $key => $snippet ) {
394
+
395
+ if ( $key == $toSave ) {
396
+ $data = $snippet;
397
+ break;
398
+ }
399
+ }
400
+
401
+ if ( $data == null ) {
402
+ wp_send_json_error( __( "Snippet {$key} not found", 'post-snippets' ) );
403
+ return;
404
+ }
405
+
406
+ if ( ! isset( $_POST['update'] ) ) {
407
+ wp_send_json_error( __( 'Update not defined.', 'post-snippets' ) );
408
  return;
409
  }
410
+
411
+ $query = array();
412
+ $query['update'] = sanitize_text_field( wp_unslash( $_POST['update'] ) );
413
+ $query['lid'] = $id;
414
+ $query['s'] = $secret;
415
+ $query['title'] = $snippet['title'];
416
+ $query['description'] = $snippet['description'];
417
+ $query['vars'] = $snippet['vars'];
418
+ $query['snippet'] = $snippet['snippet'];
419
+ $query['options'] = wp_json_encode(
420
+ array(
421
+ 'shortcode' => isset( $snippet['shortcode'] ) && $snippet['shortcode'] == '1',
422
+ 'php' => isset( $snippet['php'] ) && $snippet['php'] == '1',
423
+ 'wptexturize' => isset( $snippet['wptexturize'] ) && $snippet['wptexturize'] == '1',
424
+ )
425
+ );
426
+
427
+ $arg = array(
428
+ 'method' => 'POST',
429
+ 'body' => ( $query ),
430
+ 'data_format' => 'body',
431
+ );
432
+ $response = wp_remote_post( 'https://cloud.postsnippets.com/wp-content/themes/twentytwenty/ps-cloud/list.php', $arg );
433
+ $body = wp_remote_retrieve_body( $response );
434
+
435
+ // $ch = curl_init();
436
+ // curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/save" );
437
+ // curl_setopt( $ch, CURLOPT_POST, 1 );
438
+ // curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
439
+ // curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
440
+ // $server_output = curl_exec( $ch );
441
+ // curl_close( $ch );
442
+
443
+ $response = json_decode( $body );
444
+
445
+ if ( isset( $response->code ) && $response->code != '1' ) {
446
+ $msg = '?';
447
+ if ( isset( $response->code ) ) {
448
+ $msg = $response->data;
449
+ }
450
+ wp_send_json_error( $response );
451
+ } else {
452
+ wp_send_json_success();
453
+ }
454
+ } else {
455
+ wp_send_json_error( 'enter-license' );
456
+ return;
457
+ }
458
+ } else {
459
+ wp_send_json_error( 'license' );
460
+ return;
461
+ }
462
+ }
463
+
464
+ }
465
+
466
+ /**
467
+ * Delete snippet via ajax
468
+ */
469
+ public function delete_post_snippet() {
470
+
471
+ if ( isset( $_POST['delete_snippet'] ) && wp_verify_nonce( sanitize_key( $_POST['delete_snippet'] ), 'delete_snippet' ) && current_user_can( 'manage_options' ) ) {
472
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
473
+
474
+ if ( empty( $snippets ) || ! isset( $_POST['key'] ) ) {
475
+ wp_send_json_error( __( 'Nothing selected to delete.', 'post-snippets' ) );
476
+ return;
477
+ }
478
+
479
+ $delete = sanitize_key( $_POST['key'] );
480
+ $newsnippets = array();
481
+ foreach ( $snippets as $key => $snippet ) {
482
+ if ( $key != $delete ) {
483
+ array_push( $newsnippets, $snippet );
484
+ }
485
+ }
486
+ update_option( \PostSnippets::OPTION_KEY, $newsnippets );
487
+ wp_send_json_success();
488
+ } else {
489
+ wp_send_json_error( __( 'Security check failed.', 'post-snippets' ) );
490
+ }
491
+
492
+ wp_die();
493
+ }
494
+
495
+ /**
496
+ * Delete Snippet/s.
497
+ */
498
+ private function delete() {
499
+
500
+ if ( isset( $_POST['delete-snippets'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['update_snippets_nonce'] ), 'update_snippets' ) && current_user_can( 'manage_options' ) ) {
501
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
502
+
503
+ if ( empty( $snippets ) || ! isset( $_POST['checked'] ) ) {
504
+ $this->message( __( 'Nothing selected to delete.', 'post-snippets' ) );
505
+ return;
506
+ }
507
+
508
+ $delete = array_map( 'sanitize_text_field', wp_unslash( $_POST['checked'] ) );
509
+ $newsnippets = array();
510
+ foreach ( $snippets as $key => $snippet ) {
511
+ if ( in_array( $key, $delete ) == false ) {
512
+ array_push( $newsnippets, $snippet );
513
+ }
514
+ }
515
+ update_option( \PostSnippets::OPTION_KEY, $newsnippets );
516
+ $this->message( __( 'Selected snippets have been deleted.', 'post-snippets' ) );
517
+ }
518
+
519
+ }
520
+
521
+ /**
522
+ * Update Snippet/s.
523
+ */
524
+ private function update() {
525
+ if ( isset( $_POST['update-snippets'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['update_snippets_nonce'] ), 'update_snippets' ) && current_user_can( 'manage_options' ) ) {
526
+ $default = array(
527
+ 'title' => '',
528
+ 'rtf' => '0',
529
+ 'snippet' => '',
530
+ 'description' => '',
531
+ 'vars' => '',
532
+ 'shortcode' => '0',
533
+ 'php' => '0',
534
+ 'wptexturize' => '0',
535
+ );
536
+ $formatted_snippets = array();
537
+
538
+ if ( ! empty( $_POST['snippets'] ) ) {
539
+ $snippets = array_map( 'sanitize_text_field', wp_unslash( $_POST['snippets'] ) );
540
+ $i = 0;
541
+ foreach ( $snippets as $snippet ) {
542
+ if ( empty( $snippets ) ) {
543
+ continue;
544
+ }
545
+ $snippet = wp_parse_args( $snippet, $default );
546
+ $snippet['title'] = str_replace( ' ', '', $snippet['title'] );
547
+ if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
548
+ $snippet['php'] = '0';
549
+ }
550
+ $snippet['snippet'] = wp_specialchars_decode( trim( stripslashes( $snippet['snippet'] ) ), ENT_NOQUOTES );
551
+ $snippet['description'] = wp_specialchars_decode( trim( stripslashes( $snippet['description'] ) ), ENT_NOQUOTES );
552
+ $formatted_snippets[ $i ] = $snippet;
553
+ $i++;
554
+ }
555
+ }
556
+
557
+ update_option( \PostSnippets::OPTION_KEY, $formatted_snippets );
558
+ $this->message( __( 'Snippets have been updated.', 'post-snippets' ) );
559
+ }
560
+
561
+ }
562
+
563
+ /**
564
+ * Update User Option.
565
+ *
566
+ * Sets the per user option for the read-only overview page.
567
+ *
568
+ * @since Post Snippets 1.9.7
569
+ */
570
+ private function setUserOptions() {
571
+
572
+ if ( isset( $_POST['post_snippets_user_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['post_snippets_user_nonce'] ), 'post_snippets_user_options' ) && current_user_can( 'manage_options' ) ) {
573
+ $id = get_current_user_id();
574
+ $render = ( isset( $_POST['render'] ) ? true : false );
575
+ update_user_meta( $id, \PostSnippets::USER_META_KEY, $render );
576
+ }
577
+
578
+ }
579
+
580
+ /**
581
+ * Get User Option.
582
+ *
583
+ * Gets the per user option for the read-only overview page.
584
+ *
585
+ * @since Post Snippets 1.9.7
586
+ * @return boolean If overview should be rendered on output or not
587
+ */
588
+ private function getUserOptions() {
589
+ $id = get_current_user_id();
590
+ $options = get_user_meta( $id, \PostSnippets::USER_META_KEY, true );
591
+ return $options;
592
+ }
593
+
594
+ // -------------------------------------------------------------------------
595
+ // HTML generation for option pages
596
+ // -------------------------------------------------------------------------
597
+ /**
598
+ * Display Flashing Message.
599
+ *
600
+ * @param string $message Message to display to the user.
601
+ */
602
+ private function message( $message ) {
603
+ if ( $message ) {
604
+ echo "<div class='updated'><p><strong>" .esc_html( $message ). "</strong></p></div>";
605
+ }
606
+ }
607
+
608
+ public function newsPage() {
609
+ $plugins = array(
610
+ array(
611
+ 'name' => 'myCred',
612
+ 'description' => 'myCred makes it simple to create a loyalty program or gamify your website so that you can increase the average customer value with less marketing effort.',
613
+ 'image' => 'myCred.png',
614
+ 'url' => 'https://wordpress.org/plugins/mycred',
615
+ ),
616
+ array(
617
+ 'name' => 'WP Contact Slider',
618
+ 'description' => 'WP contact slider is simple contact slider to display contactform7, Gravity forms, Wp Forms, Caldera forms, Constant Contact Forms or display random text or HTML.',
619
+ 'image' => 'ContactSlider.png',
620
+ 'url' => 'https://wordpress.org/plugins/wp-contact-slider/',
621
+ ),
622
+ array(
623
+ 'name' => 'Wholesale For WooCommerce',
624
+ 'description' => 'Sign up wholesale customers and display wholesale prices based on multiple wholesale user roles on your existing WooCommerce store',
625
+ 'image' => 'WholesaleForWoocommerce.png',
626
+ 'url' => 'https://woocommerce.com/products/wholesale-for-woocommerce/',
627
+ ),
628
+ array(
629
+ 'name' => 'WooCommerce Product Disclaimer',
630
+ 'description' => 'Woocommerce extension where you can set some products to accept terms and conditions before adding product to cart. ',
631
+ 'image' => 'ProductDisclaimer.png',
632
+ 'url' => 'https://wordpress.org/plugins/woo-product-disclaimer/',
633
+ ),
634
+ );
635
+ include PS_PATH . '/views/admin_news.php';
636
+ }
637
+
638
+ /**
639
+ * Creates the snippets administration page.
640
+ *
641
+ * For users with manage_options capability (admin, super admin).
642
+ *
643
+ * @since Post Snippets 1.8.8
644
+ */
645
+ public function optionsPage() {
646
+ // Handle Form Submits
647
+ $this->add();
648
+ $this->delete();
649
+ $this->update();
650
+ // Header
651
+ echo '
652
  <!-- Create a header in the default WordPress \'wrap\' container -->
653
  <div class="wrap">
654
  <div id="icon-plugins" class="icon32"></div>
655
+ <h2>';
656
+ echo esc_html__( 'Post Snippets', 'post-snippets' );
657
+ echo '</h2>';
658
+ // Tabs
659
+ $active_tab = ( isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'snippets' ); // phpcs:ignore
660
+ $base_url = '?page=post-snippets&amp;tab=';
661
+ $tabs = array(
662
+ 'snippets' => __( 'Manage Snippets', 'post-snippets' ),
663
+ 'options' => __( 'Options', 'post-snippets' ),
664
+ 'tools' => __( 'Import/Export', 'post-snippets' ),
665
+ );
666
+ if ( postsnippets_fs()->is_not_paying() ) {
667
+ $tabs['upgrade'] = __( 'Upgrade', 'post-snippets' );
668
+ }
669
+ echo '<h2 class="nav-tab-wrapper">';
670
+ foreach ( $tabs as $tab => $title ) {
671
+ $active = ( $active_tab == $tab ? ' nav-tab-active' : '' );
672
+ $link = $base_url . $tab;
673
+ if ( $tab == 'upgrade' ) {
674
+ $link = postsnippets_fs()->get_upgrade_url();
675
+ }
676
+ echo "<a href='" . esc_url( $link ) . "' class='nav-tab " . esc_attr( $active ) . ' tab-' . esc_attr( $tab ) . "'>" . esc_html( $title ) . '</a>';
677
+ }
678
+ echo '</h2>';
679
+ // Tab content
680
+
681
+ if ( $active_tab == 'snippets' ) {
682
+ $this->tabSnippets();
683
+ } elseif ( $active_tab == 'options' ) {
684
+ $this->tabOptions();
685
+ } elseif ( $active_tab == 'tools' ) {
686
+ $this->tabTools();
687
+ } else {
688
+ $this->tabFeatures();
689
+ }
690
+
691
+ // Close it
692
+ echo '</div>';
693
+ }
694
+
695
+ /**
696
+ * Tab to Manage Snippets.
697
+ *
698
+ * @since Post Snippets 2.0
699
+ */
700
+ private function tabSnippets() {
701
+ echo '<p class="description post-snippets-documentation-note">';
702
+ esc_html_e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
703
+ echo '</p>';
704
+ $data = array();
705
+ echo View::render( 'admin_snippets', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
706
+ }
707
+
708
+ /**
709
+ * Tab to set options for the plugin.
710
+ *
711
+ * @return void
712
+ */
713
+ private function tabOptions() {
714
+ echo '<p class="description post-snippets-documentation-note">';
715
+ esc_html_e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
716
+ echo '</p>';
717
+ $data = array();
718
+ echo View::render( 'admin_options', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
719
+ }
720
+
721
+ /**
722
+ * Tab for Import/Export
723
+ *
724
+ * @since Post Snippets 2.0
725
+ */
726
+ private function tabTools() {
727
+ echo '<p class="description post-snippets-documentation-note">';
728
+ esc_html_e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
729
+ echo '</p>';
730
+ $ie = new ImportExport();
731
+ // Create header and export html form
732
+ printf( '<h3>%s</h3>', esc_html__( 'Import/Export', 'post-snippets' ) );
733
+ printf( '<h4>%s</h4>', esc_html__( 'Export', 'post-snippets' ) );
734
+ echo '<form method="post">';
735
+ echo '<p>';
736
+ esc_html_e( 'Export your snippets for backup or to import them on another site.', 'post-snippets' );
737
+ echo '</p>';
738
+ printf( "<input type='submit' class='button' name='postsnippets_export' value='%s' />", esc_html__( 'Export Snippets', 'post-snippets' ) );
739
+ wp_nonce_field( 'pspro_export_snippets', 'pspro_export_snippets_nonce', false );
740
+ echo '</form>';
741
+ // Export logic, and import html form and logic
742
+ $ie->exportSnippets();
743
+ echo $ie->importSnippets(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
744
+ }
745
+
746
+ /**
747
+ * Tab for Pro features
748
+ *
749
+ * @since Post Snippets 2.5.4
750
+ */
751
+ private function tabFeatures() {
752
+ $features = new Features();
753
+ echo $features->showFeatures(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
754
+ }
755
+
756
+ /**
757
+ * Creates a read-only overview page.
758
+ *
759
+ * For users with edit_posts capability but without manage_options
760
+ * capability.
761
+ *
762
+ * @since Post Snippets 1.9.7
763
+ */
764
+ public function overviewPage() {
765
+ // Header
766
+ echo '<div class="wrap">';
767
+ echo '<h2>Post Snippets</h2>';
768
+ echo '<p>';
769
+ esc_html_e( 'This is an overview of all snippets defined for this site. These snippets are inserted into posts from the post editor using the Post Snippets button. You can choose to see the snippets here as-is or as they are actually rendered on the website. Enabling rendered snippets for this overview might look strange if the snippet have dependencies on variables, CSS or other parameters only available on the frontend. If that is the case it is recommended to keep this option disabled.', 'post-snippets' );
770
+ echo '</p>';
771
+ // Form
772
+ $this->setUserOptions();
773
+ $render = $this->getUserOptions();
774
+ echo '<form method="post" action="">';
775
+ wp_nonce_field( 'post_snippets_user_options', 'post_snippets_user_nonce' );
776
+ $this->checkbox( __( 'Display rendered snippets', 'post-snippets' ), 'render', $render );
777
+ $this->submit( 'update-post-snippets-user', __( 'Update', 'post-snippets' ) );
778
+ echo '</form>';
779
+ // Snippet List
780
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
781
+ if ( ! empty( $snippets ) ) {
782
+ foreach ( $snippets as $key => $snippet ) {
783
+ echo "<hr style='border: none;border-top:1px dashed #aaa; margin:24px 0;' />";
784
+ echo '<h3>' . esc_html( $snippet['title'] );
785
+ if ( $snippet['description'] ) {
786
+ echo "<span class='description'> " . esc_html( $snippet['description'] ) . '</span>';
787
+ }
788
+ echo '</h3>';
789
+ if ( $snippet['vars'] ) {
790
+ printf( '<strong>%s:</strong> ' . esc_html( $snippet['vars'] ) . '<br/>', esc_html__( 'Variables', 'post-snippets' ) );
791
+ }
792
+ // echo "<strong>Variables:</strong> {$snippet['vars']}<br/>";
793
+ $options = array();
794
+ if ( $snippet['shortcode'] ) {
795
+ array_push( $options, 'Shortcode' );
796
+ }
797
+ if ( $snippet['php'] ) {
798
+ array_push( $options, 'PHP' );
799
+ }
800
+ if ( $snippet['wptexturize'] ) {
801
+ array_push( $options, 'wptexturize' );
802
+ }
803
+ if ( $options ) {
804
+ printf( '<strong>%s:</strong> %s<br/>', esc_html__( 'Options', 'post-snippets' ), esc_html( implode( ', ', $options ) ) );
805
+ }
806
+ printf( '<br/><strong>%s:</strong><br/>', esc_html__( 'Snippet', 'post-snippets' ) );
807
+
808
+ if ( $render ) {
809
+ echo do_shortcode( $snippet['snippet'] );
810
+ } else {
811
+ echo '<code>';
812
+ echo esc_html( $snippet['snippet'] );
813
+ echo '</code>';
814
+ }
815
+ }
816
+ }
817
+ // Close
818
+ echo '</div>';
819
+ }
820
+
821
+ // -------------------------------------------------------------------------
822
+ // Register and callbacks for the options tab
823
+ // -------------------------------------------------------------------------
824
+ /**
825
+ * Register settings for the options tab.
826
+ *
827
+ * @return void
828
+ */
829
+ protected function registerSettings() {
830
+ $this->settings = get_option( \PostSnippets::SETTINGS );
831
+ register_setting( \PostSnippets::SETTINGS, \PostSnippets::SETTINGS );
832
+ add_settings_section(
833
+ 'general_section',
834
+ __( 'General', 'post-snippets' ),
835
+ null,
836
+ 'post-snippets'
837
+ );
838
+ add_settings_field(
839
+ 'exclude_from_custom_editors',
840
+ __( 'Exclude from Custom Editors', 'post-snippets' ),
841
+ array( $this, 'cbExcludeFromCustomEditors' ),
842
+ 'post-snippets',
843
+ 'general_section',
844
+ array(
845
+ 'id' => 'exclude_from_custom_editors',
846
+ 'label_for' => 'exclude_from_custom_editors',
847
+ 'description' => __( 'Checking this only includes Post Snippets on standard WordPress post editing screens.', 'post-snippets' ),
848
+ )
849
+ );
850
+ }
851
+
852
+ /**
853
+ * Callback for HTML generator for exlusion of custom editors.
854
+ *
855
+ * @param array $args
856
+ *
857
+ * @return void
858
+ */
859
+ public function cbExcludeFromCustomEditors( $args ) {
860
+ $checked = ( isset( $this->settings[ $args['id'] ] ) ? $this->settings[ $args['id'] ] : false );
861
+ echo "<input type='checkbox' id='" . esc_attr( $args['id'] ) . "' ";
862
+ echo "name='" . esc_attr( \PostSnippets::SETTINGS . '[' . $args['id'] . ']' ) . "'" . "value='1' ";
863
+ if ( $checked ) {
864
+ echo 'checked ';
865
+ }
866
+ echo ' />';
867
+ echo "<span class='description'>" . esc_html( $args['description'] ) . '</span>';
868
+ }
869
+
870
+ // -------------------------------------------------------------------------
871
+ // HTML and Form element methods for Snippets form
872
+ // -------------------------------------------------------------------------
873
+ /**
874
+ * Checkbox.
875
+ *
876
+ * Renders the HTML for an input checkbox.
877
+ *
878
+ * @param string $label The label rendered to screen
879
+ * @param string $name The unique name and id to identify the input
880
+ * @param boolean $checked If the input is checked or not
881
+ *
882
+ * @return void
883
+ */
884
+ public static function checkbox( $label, $name, $checked ) {
885
+ echo '<label for="' . esc_attr( $name ) . '">';
886
+ printf( '<input type="checkbox" name="%1$s" id="%1$s" value="true"', esc_attr( $name ) );
887
+ if ( $checked ) {
888
+ echo ' checked';
889
+ }
890
+ echo ' />';
891
+ echo esc_html( $label ) . '</label><br/>';
892
+ }
893
+
894
+ /**
895
+ * Submit.
896
+ *
897
+ * Renders the HTML for a submit button.
898
+ *
899
+ * @since Post Snippets 1.9.7
900
+ *
901
+ * @param string $name The name that identifies the button on submit
902
+ * @param string $label The label rendered on the button
903
+ * @param string $class Optional. Button class. Default: button-primary
904
+ * @param boolean $wrap Optional. Wrap in a submit div. Default: true
905
+ *
906
+ * @return void
907
+ */
908
+ public static function submit(
909
+ $name,
910
+ $label,
911
+ $class = 'button-primary',
912
+ $wrap = true
913
+ ) {
914
+
915
+ if ( $wrap ) {
916
+
917
+ echo "<div class=\"submit\"><input type=submit name='" . esc_attr( $name ) . "' value='" . esc_attr( $label ) . "' class='" . esc_attr( $class ) . "' />&nbsp;&nbsp;&nbsp;</div>";
918
+ return;
919
+
920
+ }
921
+
922
+ echo "<input type=submit name='" . esc_attr( $name ) . "' value='" . esc_attr( $label ) . "' class='" . esc_attr( $class ) . "' />&nbsp;&nbsp;&nbsp;";
923
+
924
+ }
925
+
926
+ /**
927
+ *
928
+ * Show newsletter opt-in, only in Post Snippets.
929
+ * Not on Pro features tab/page.
930
+ * Not when user selected to Hide opt-in.
931
+ *
932
+ * @since 2.5.4
933
+ */
934
+ public function admin_notice_newsletter() {
935
+ // Hide newsletter opt-in if option is true
936
+ if ( get_option( 'ps_hide_admin_notice_newsletter' ) == true ) {
937
+ return;
938
+ }
939
+ // Set option if "hide" button click detected (custom querystring value set to 1).
940
+
941
+ if ( ! empty( $_REQUEST['ps-dismiss-newsletter-nag'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
942
+ update_option( 'ps_hide_admin_notice_newsletter', true );
943
+ return;
944
+ }
945
+
946
+ // Show newsletter notice.
947
+
948
+ if ( get_current_screen()->id == 'settings_page_post-snippets/post-snippets' ) {
949
+ $active_tab = ( isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'snippets' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
950
+ if ( $active_tab != 'features' ) {
951
+ include_once PS_PATH . '/views/admin_notice_newsletter.php';
952
+ }
953
+ }
954
+
955
+ }
956
+
957
+ /**
958
+ *
959
+ * Show 'Get started' admin notice', everywhere.
960
+ * Not when user already clicked or dismissed.
961
+ *
962
+ * @since 2.5.4
963
+ */
964
+ public function admin_notice_get_started() {
965
+ // Hide newsletter opt-in if option is true
966
+ if ( get_option( 'ps_hide_admin_notice_get_started' ) == true ) {
967
+ return;
968
+ }
969
+ // Set option if "hide" button click detected (custom query string value set to 1).
970
+
971
+ if ( ! empty( $_REQUEST['ps-dismiss-get-started-nag'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
972
+ update_option( 'ps_hide_admin_notice_get_started', true );
973
+ return;
974
+ }
975
+
976
+ // Show newsletter notice.
977
+
978
+ if ( strpos( get_current_screen()->id, '/post-snippets' ) == false ) {
979
+ $active_tab = ( isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'snippets' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
980
+ if ( $active_tab != 'features' ) {
981
+ include_once PS_PATH . '/views/admin_notice_get_started.php';
982
+ }
983
+ }
984
+
985
+ }
986
+
987
+ /**
988
+ * Save Updated sorting
989
+ */
990
+ /*
991
+ public function update_snippets_order() {
992
+ if ( empty( $_POST['order'] ) || ! is_array( $_POST['order'] ) ) {
993
+ wp_send_json_error( 'order data not received' );
994
+ }
995
+ $capability = $this->get_allowed_capability();
996
+ if ( ! current_user_can( $capability ) ) {
997
+ wp_send_json_error( 'permission denied' );
998
+ }
999
+ $orders = array_map( 'sanitize_key', array_map( 'intval', $_POST['order'] ) );
1000
+ $snippets = get_option( 'post_snippets_options', array() );
1001
+ if ( empty( $snippets ) ) {
1002
+ wp_send_json_error( 'snippets empty' );
1003
+ }
1004
+ $updated_order = array();
1005
+ foreach ( $orders as $order ) {
1006
+ if ( isset( $snippets[ $order ] ) ) {
1007
+ $updated_order[] = $snippets[ $order ];
1008
+ }
1009
+ }
1010
+ update_option( 'post_snippets_options', $updated_order );
1011
+ wp_send_json_success( 'success' );
1012
+ }
1013
+ */
1014
+
1015
+ /**
1016
+ * Save Updated title
1017
+ */
1018
+ public function update_post_snippet_title() {
1019
+ if ( ! isset( $_POST['key'] ) || empty( $_POST['title'] ) ) {
1020
+ wp_send_json_error();
1021
+ }
1022
+ if ( ! isset( $_POST['save_title_nonce'] ) || !wp_verify_nonce( sanitize_key( $_POST['save_title_nonce'] ), 'ps-save-title-nonce' ) || !current_user_can( 'manage_options' ) ) {
1023
+ wp_send_json_error();
1024
+ }
1025
+
1026
+ $capability = $this->get_allowed_capability();
1027
+ if ( ! current_user_can( $capability ) ) {
1028
+ wp_send_json_error( 'permission denied' );
1029
+ }
1030
+ $pkey = intval( sanitize_text_field( wp_unslash( $_POST['key'] ) ) );
1031
+ $title = sanitize_text_field( wp_unslash( $_POST['title'] ) );
1032
+ $snippets = get_option( 'post_snippets_options', array() );
1033
+ if ( empty( $snippets ) ) {
1034
+ wp_send_json_error();
1035
+ }
1036
+
1037
+ if ( isset( $snippets[ $pkey ] ) && $snippets[ $pkey ]['title'] == $title ) {
1038
+
1039
+ wp_send_json_error( __( 'You have not made any changes to the snippet title.', 'post-snippets' ) );
1040
+ }
1041
+
1042
+ foreach ( $snippets as $key => $snippet ) {
1043
+ if ( $snippet['title'] == $title ) {
1044
+ wp_send_json_error( __( 'Duplicate title is not allowed. Please use different title for each snippets.', 'post-snippets' ) );
1045
+ }
1046
+ }
1047
+
1048
+ if ( isset( $snippets[ $pkey ] ) ) {
1049
+ $snippets[ $pkey ]['title'] = $title;
1050
+ update_option( 'post_snippets_options', $snippets );
1051
+ }
1052
+
1053
+ wp_send_json_success( $title );
1054
+ }
1055
+
1056
+ public function update_post_snippet() {
1057
+ if ( ! isset( $_POST['key'] ) ) {
1058
+ wp_send_json_error();
1059
+ }
1060
+ if ( ! isset( $_POST['update_snippet_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['update_snippet_nonce'] ), 'ps-update-snippet-nonce' ) || !current_user_can( 'manage_options' ) ) {
1061
+ wp_send_json_error();
1062
+ }
1063
+
1064
+ $capability = $this->get_allowed_capability();
1065
+ if ( ! current_user_can( $capability ) ) {
1066
+ wp_send_json_error( 'permission denied' );
1067
+ }
1068
+ $key = intval( sanitize_text_field( wp_unslash ( $_POST['key'] ) ) );
1069
+ $snippets = get_option( 'post_snippets_options', array() );
1070
+ if ( empty( $snippets ) ) {
1071
+ wp_send_json_error();
1072
+ }
1073
+ $title = '';
1074
+ if ( isset( $_POST['title'] ) ) {
1075
+ $title = sanitize_text_field( wp_unslash( $_POST['title'] ) );
1076
+ }
1077
+
1078
+ if ( isset( $snippets[ $key ] ) ) {
1079
+ $snippets[ $key ]['description'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['description'] ?? '' ) ) );
1080
+ $snippets[ $key ]['snippet'] = stripslashes( wp_kses_post( wp_unslash( $_POST['snippet'] ?? '' ) ) );
1081
+ $snippets[ $key ]['vars'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['vars'] ?? '' ) ) );
1082
+ $snippets[ $key ]['shortcode'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['shortcode'] ?? '' ) ) );
1083
+ $snippets[ $key ]['php'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['php'] ?? '' ) ) );
1084
+ $snippets[ $key ]['wptexturize'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['wptexturize'] ?? '' ) ) );
1085
+ if ( ! empty( $title ) ) {
1086
+ $snippets[ $key ]['title'] = $title;
1087
+ }
1088
+ update_option( 'post_snippets_options', $snippets );
1089
+ }
1090
+
1091
+ wp_send_json_success( $title );
1092
+ }
1093
+
1094
+ public function get_allowed_capability() {
1095
+ $capability = 'manage_options';
1096
+
1097
+ if ( defined( 'POST_SNIPPETS_ALLOW_EDIT_POSTS' ) && current_user_can( 'edit_posts' ) ) {
1098
+ $capability = 'edit_posts';
1099
+ }
1100
+
1101
+ return $capability;
1102
+ }
1103
+
1104
+ }
 
 
 
 
 
 
 
 
 
 
 
 
src/PostSnippets/Features.php CHANGED
@@ -5,7 +5,6 @@ namespace PostSnippets;
5
  /**
6
  * Post Snippets Features.
7
  *
8
- *
9
  * @author GreenTreeLabs <info at postsnippets dot com>
10
  * @link https://www.postsnippets.com
11
  */
@@ -15,7 +14,7 @@ class Features {
15
  public function showFeatures() {
16
  $html = '';
17
  ob_start();
18
- ?>
19
  <div class="wrap">
20
  <div id="pt-features">
21
  <div id="pt-features-content">
@@ -31,11 +30,11 @@ class Features {
31
  </div>
32
  <!-- .pt-features -->
33
  </div><!-- .wrap -->
34
- <?php
35
 
36
- $html .= ob_get_contents();
37
- ob_end_clean();
38
 
39
- return $html;
40
  }
41
  }
5
  /**
6
  * Post Snippets Features.
7
  *
 
8
  * @author GreenTreeLabs <info at postsnippets dot com>
9
  * @link https://www.postsnippets.com
10
  */
14
  public function showFeatures() {
15
  $html = '';
16
  ob_start();
17
+ ?>
18
  <div class="wrap">
19
  <div id="pt-features">
20
  <div id="pt-features-content">
30
  </div>
31
  <!-- .pt-features -->
32
  </div><!-- .wrap -->
33
+ <?php
34
 
35
+ $html .= ob_get_contents();
36
+ ob_end_clean();
37
 
38
+ return $html;
39
  }
40
  }
src/PostSnippets/Help.php CHANGED
@@ -1,114 +1,109 @@
1
  <?php
 
2
  namespace PostSnippets;
3
 
4
  /**
5
  * Handles the plugin help screen.
6
- *
7
  */
8
- class Help
9
- {
10
- /**
11
- * Define actions.
12
- *
13
- * @param string
14
- * @return void
15
- */
16
- public function __construct($optionPage)
17
- {
18
- add_action('load-'.$optionPage, array(&$this, 'tabs'));
19
 
20
- add_action('load-post.php', array(&$this, 'postEditor'));
21
- add_action('load-post-new.php', array(&$this, 'postEditor'));
22
- }
23
 
24
- /**
25
- * Load the post editor tab in the admin_head filter.
26
- *
27
- * We load the tab that will integrate in the post editor help menu via the
28
- * admin_head hook, as we are not otherwise able to make it get ordered
29
- * below the native help tabs.
30
- *
31
- * @return void.
32
- */
33
- public function postEditor()
34
- {
35
- add_action('admin_head', array(&$this, 'postEditorTabs'));
36
- }
37
 
38
- /**
39
- * Setup the help tabs and sidebar.
40
- *
41
- * @return void
42
- */
43
- public function tabs()
44
- {
45
- $screen = get_current_screen();
46
- $screen->set_help_sidebar($this->content('help/sidebar'));
47
- $screen->add_help_tab(
48
- array(
49
- 'id' => 'usage-plugin-help',
50
- 'title' => __('Usage', 'post-snippets'),
51
- 'content' => $this->content('help/usage')
52
- )
53
- );
54
- $screen->add_help_tab(
55
- array(
56
- 'id' => 'post-plugin-help',
57
- 'title' => __('Post Editor', 'post-snippets'),
58
- 'content' => $this->content('help/post')
59
- )
60
- );
61
- if (!defined('POST_SNIPPETS_DISABLE_PHP')) {
62
- $screen->add_help_tab(
63
- array(
64
- 'id' => 'php-plugin-help',
65
- 'title' => __('PHP', 'post-snippets'),
66
- 'content' => $this->content('help/php')
67
- )
68
- );
69
- }
70
- $screen->add_help_tab(
71
- array(
72
- 'id' => 'advanced-plugin-help',
73
- 'title' => __('Advanced', 'post-snippets'),
74
- 'content' => $this->content('help/advanced')
75
- )
76
- );
77
- $screen->add_help_tab(
78
- array(
79
- 'id' => 'filters-plugin-help',
80
- 'title' => __('Filters', 'post-snippets'),
81
- 'content' => $this->content('help/filters')
82
- )
83
- );
84
- }
85
 
86
- /**
87
- * Setup the help tab for the post editor.
88
- *
89
- * @return void
90
- */
91
- public function postEditorTabs()
92
- {
93
- $screen = get_current_screen();
94
 
95
- $screen->add_help_tab(
96
- array(
97
- 'id' => 'postsnippets-plugin-help',
98
- 'title' => 'Post Snippets',
99
- 'content' => $this->content('help/post')
100
- )
101
- );
102
- }
103
 
104
- /**
105
- * Get the content for a help tab
106
- *
107
- * @param string $tab
108
- * @return string
109
- */
110
- private function content($tab)
111
- {
112
- return View::render($tab);
113
- }
114
  }
1
  <?php
2
+
3
  namespace PostSnippets;
4
 
5
  /**
6
  * Handles the plugin help screen.
 
7
  */
8
+ class Help {
9
+
10
+ /**
11
+ * Define actions.
12
+ *
13
+ * @param string
14
+ * @return void
15
+ */
16
+ public function __construct( $optionPage ) {
17
+ add_action( 'load-' . $optionPage, array( &$this, 'tabs' ) );
 
18
 
19
+ add_action( 'load-post.php', array( &$this, 'postEditor' ) );
20
+ add_action( 'load-post-new.php', array( &$this, 'postEditor' ) );
21
+ }
22
 
23
+ /**
24
+ * Load the post editor tab in the admin_head filter.
25
+ *
26
+ * We load the tab that will integrate in the post editor help menu via the
27
+ * admin_head hook, as we are not otherwise able to make it get ordered
28
+ * below the native help tabs.
29
+ *
30
+ * @return void.
31
+ */
32
+ public function postEditor() {
33
+ add_action( 'admin_head', array( &$this, 'postEditorTabs' ) );
34
+ }
 
35
 
36
+ /**
37
+ * Setup the help tabs and sidebar.
38
+ *
39
+ * @return void
40
+ */
41
+ public function tabs() {
42
+ $screen = get_current_screen();
43
+ $screen->set_help_sidebar( $this->content( 'help/sidebar' ) );
44
+ $screen->add_help_tab(
45
+ array(
46
+ 'id' => 'usage-plugin-help',
47
+ 'title' => __( 'Usage', 'post-snippets' ),
48
+ 'content' => $this->content( 'help/usage' ),
49
+ )
50
+ );
51
+ $screen->add_help_tab(
52
+ array(
53
+ 'id' => 'post-plugin-help',
54
+ 'title' => __( 'Post Editor', 'post-snippets' ),
55
+ 'content' => $this->content( 'help/post' ),
56
+ )
57
+ );
58
+ if ( ! defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
59
+ $screen->add_help_tab(
60
+ array(
61
+ 'id' => 'php-plugin-help',
62
+ 'title' => __( 'PHP', 'post-snippets' ),
63
+ 'content' => $this->content( 'help/php' ),
64
+ )
65
+ );
66
+ }
67
+ $screen->add_help_tab(
68
+ array(
69
+ 'id' => 'advanced-plugin-help',
70
+ 'title' => __( 'Advanced', 'post-snippets' ),
71
+ 'content' => $this->content( 'help/advanced' ),
72
+ )
73
+ );
74
+ $screen->add_help_tab(
75
+ array(
76
+ 'id' => 'filters-plugin-help',
77
+ 'title' => __( 'Filters', 'post-snippets' ),
78
+ 'content' => $this->content( 'help/filters' ),
79
+ )
80
+ );
81
+ }
 
82
 
83
+ /**
84
+ * Setup the help tab for the post editor.
85
+ *
86
+ * @return void
87
+ */
88
+ public function postEditorTabs() {
89
+ $screen = get_current_screen();
 
90
 
91
+ $screen->add_help_tab(
92
+ array(
93
+ 'id' => 'postsnippets-plugin-help',
94
+ 'title' => 'Post Snippets',
95
+ 'content' => $this->content( 'help/post' ),
96
+ )
97
+ );
98
+ }
99
 
100
+ /**
101
+ * Get the content for a help tab
102
+ *
103
+ * @param string $tab
104
+ * @return string
105
+ */
106
+ private function content( $tab ) {
107
+ return View::render( $tab );
108
+ }
 
109
  }
src/PostSnippets/ImportExport.php CHANGED
@@ -5,225 +5,253 @@ namespace PostSnippets;
5
  * Post Snippets I/O.
6
  *
7
  * Class to handle import and export of Snippets.
8
- *
9
  */
10
- class ImportExport
11
- {
12
- protected static $FILE_ZIP;
13
- const FILE_CFG = 'post-snippets-export.cfg';
14
-
15
- private $downloadUrl;
16
-
17
- /**
18
- * Export Snippets.
19
- *
20
- * Check if an export file shall be created, or if a download url should be
21
- * pushed to the footer. Also checks for old export files laying around and
22
- * deletes them (for security).
23
- *
24
- * @return void
25
- */
26
- public function exportSnippets()
27
- {
28
- self::set_export_name();
29
- if (isset($_POST['postsnippets_export'])) {
30
- $url = $this->createExportFile();
31
- if ($url) {
32
- $this->downloadUrl = $url;
33
- add_action(
34
- 'admin_footer',
35
- array(&$this, 'psnippetsFooter'),
36
- 10000
37
- );
38
- } else {
39
- echo __('Error: ', 'post-snippets').$url;
40
- }
41
- } else {
42
- // Check if there is any old export files to delete
43
- $dir = wp_upload_dir();
44
- $upload_dir = $dir['basedir'] . '/';
45
- chdir($upload_dir);
46
- if (file_exists('./'.self::$FILE_ZIP)) {
47
- unlink('./'.self::$FILE_ZIP);
48
- }
49
- }
50
- }
51
-
52
- /**
53
- * Handles uploading of post snippets archive and import the snippets.
54
- *
55
- * @uses wp_handle_upload() in wp-admin/includes/file.php
56
- * @return string HTML to handle the import
57
- */
58
- public function importSnippets()
59
- {
60
- $import =
61
- '<br/><br/><strong>'.
62
- __('Import', 'post-snippets').
63
- '</strong><br/>';
64
- if (!isset($_FILES['postsnippets_import_file'])
65
- || empty($_FILES['postsnippets_import_file'])
66
- ) {
67
- $import .=
68
- '<p>'.__('Import snippets from a post-snippets-export.zip file. Imported sinppets will get added at the bottom.', 'post-snippets').
69
- '</p>';
70
- $import .=
71
- '<p>'.__('Please make sure no snippets have duplicate titles.', 'post-snippets').
72
- '</p>';
73
- $import .= '<form method="post" enctype="multipart/form-data">';
74
- $import .= '<input type="file" name="postsnippets_import_file"/>';
75
- $import .= '<input type="hidden" name="action" value="wp_handle_upload"/>';
76
- $import .=
77
- '<input type="submit" class="button" value="'.
78
- __('Import Snippets', 'post-snippets').'"/>';
79
- $import .= '</form>';
80
- } else {
81
- $file = wp_handle_upload($_FILES['postsnippets_import_file']);
82
-
83
- if (isset($file['file']) && !is_wp_error($file)) {
84
- require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
85
- $zip = new \PclZip($file['file']);
86
- $dir = wp_upload_dir();
87
- $upload_dir = $dir['basedir'] . '/';
88
- chdir($upload_dir);
89
- $unzipped = $zip->extract();
90
-
91
- if ($unzipped[0]['stored_filename'] == self::FILE_CFG
92
- && $unzipped[0]['status'] == 'ok'
93
- ) {
94
- // Delete the uploaded archive
95
- unlink($file['file']);
96
-
97
- $snippets = file_get_contents(
98
- $upload_dir.self::FILE_CFG
99
- );
100
-
101
- if ($snippets) {
102
- $snippets = apply_filters(
103
- 'post_snippets_import',
104
- $snippets
105
- );
106
-
107
- $imported_snippets = unserialize($snippets);
108
- $current_snippets = get_option( \PostSnippets::OPTION_KEY );
109
-
110
- $all_snippets = $current_snippets;
111
- $duplicate_title_exist = false;
112
- $duplicate_title = '';
113
- foreach($imported_snippets as $snippet){
114
- $all_snippets[]=$snippet;
115
- foreach($current_snippets as $current){
116
- if($current['title'] == $snippet['title']){
117
- $duplicate_title = $snippet['title'];
118
- $duplicate_title_exist = true;
119
- break;
120
- }
121
- }
122
- }
123
-
124
- if ($duplicate_title_exist == false) {
125
- update_option( \PostSnippets::OPTION_KEY, $all_snippets );
126
- $import .=
127
- '<p><strong>'.
128
- __('Snippets successfully imported.', 'post-snippets').
129
- '</strong></p>';
130
- } else {
131
- $import .=
132
- '<p><strong>'.
133
- __('All the snippets should have unique titles. The snippet in your import file with title "'.$duplicate_title.'" already exists in your site.', 'post-snippets').
134
- '</strong></p>';
135
- }
136
-
137
- }
138
-
139
- // Delete the snippet file
140
- unlink('./'.self::FILE_CFG);
141
-
142
-
143
- } else {
144
- $import .=
145
- '<p><strong>'.
146
- __('Snippets could not be imported:', 'post-snippets').
147
- ' '.
148
- __('Unzipping failed.', 'post-snippets').
149
- '</strong></p>';
150
- }
151
- } else {
152
- if ($file['error'] || is_wp_error($file)) {
153
- $import .=
154
- '<p><strong>'.
155
- __('Snippets could not be imported:', 'post-snippets').
156
- ' '.
157
- $file['error'].'</strong></p>';
158
- } else {
159
- $import .=
160
- '<p><strong>'.
161
- __('Snippets could not be imported:', 'post-snippets').
162
- ' '.
163
- __('Upload failed.', 'post-snippets').
164
- '</strong></p>';
165
- }
166
- }
167
- }
168
- return $import;
169
- }
170
-
171
- /**
172
- * Create a zipped filed containing all Post Snippets, for export.
173
- *
174
- * @return string URL to the exported snippets
175
- */
176
- private function createExportFile()
177
- {
178
- $snippets = serialize(get_option(\PostSnippets::OPTION_KEY));
179
- $snippets = apply_filters('post_snippets_export', $snippets);
180
- $dir = wp_upload_dir();
181
- $upload_dir = $dir['basedir'] . '/';
182
- $upload_url = $dir['baseurl'] . '/';
183
-
184
- // Open a file stream and write the serialized options to it.
185
- if (!$handle = fopen($upload_dir.'./'.self::FILE_CFG, 'w')) {
186
- die();
187
- }
188
- if (!fwrite($handle, $snippets)) {
189
- die();
190
- }
191
- fclose($handle);
192
-
193
- // Create a zip archive
194
- require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
195
- chdir($upload_dir);
196
- $zip = new \PclZip('./'.self::$FILE_ZIP);
197
- $zipped = $zip->create('./'.self::FILE_CFG);
198
-
199
- // Delete the snippet file
200
- unlink('./'.self::FILE_CFG);
201
-
202
- if (!$zipped) {
203
- return false;
204
- }
205
-
206
- return $upload_url.'./'.self::$FILE_ZIP;
207
- }
208
-
209
- /**
210
- * Set export file name
211
- */
212
- public static function set_export_name(){
213
- $date_part = date('Y-m-d');
214
- self::$FILE_ZIP = "post-snippets-export-{$date_part}.zip";
215
- }
216
-
217
- /**
218
- * Generates the javascript to trigger the download of the file.
219
- *
220
- * @return void
221
- */
222
- public function psnippetsFooter()
223
- {
224
- $export = '<script type="text/javascript">
225
- document.location = \''.$this->downloadUrl.'\';
226
- </script>';
227
- echo $export;
228
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  }
5
  * Post Snippets I/O.
6
  *
7
  * Class to handle import and export of Snippets.
 
8
  */
9
+ class ImportExport {
10
+
11
+ protected static $FILE_ZIP;
12
+ const FILE_CFG = 'post-snippets-export.cfg';
13
+
14
+ private $downloadUrl;
15
+
16
+ /**
17
+ * Export Snippets.
18
+ *
19
+ * Check if an export file shall be created, or if a download url should be
20
+ * pushed to the footer. Also checks for old export files laying around and
21
+ * deletes them (for security).
22
+ *
23
+ * @return void
24
+ */
25
+ public function exportSnippets() {
26
+ self::set_export_name();
27
+ if ( isset( $_POST['postsnippets_export'] ) ) {
28
+ check_admin_referer( 'pspro_export_snippets', 'pspro_export_snippets_nonce' );
29
+ if( !current_user_can( 'manage_options' ) ){
30
+ return;
31
+ }
32
+ $url = $this->createExportFile();
33
+ if ( $url ) {
34
+ $this->downloadUrl = $url;
35
+ add_action(
36
+ 'admin_footer',
37
+ array( &$this, 'psnippetsFooter' ),
38
+ 10000
39
+ );
40
+ } else {
41
+ echo esc_html__( 'Error: ', 'post-snippets' ) . esc_url( $url );
42
+ }
43
+ } else {
44
+ // Check if there is any old export files to delete
45
+ $dir = wp_upload_dir();
46
+ $upload_dir = $dir['basedir'] . '/';
47
+ chdir( $upload_dir );
48
+ if ( file_exists( './' . self::$FILE_ZIP ) ) {
49
+ unlink( './' . self::$FILE_ZIP );
50
+ }
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Handles uploading of post snippets archive and import the snippets.
56
+ *
57
+ * @uses wp_handle_upload() in wp-admin/includes/file.php
58
+ * @return string HTML to handle the import
59
+ */
60
+ public function importSnippets() {
61
+ $import =
62
+ '<br/><br/><strong>' .
63
+ esc_html__( 'Import', 'post-snippets' ) .
64
+ '</strong><br/>';
65
+ if ( ! isset( $_FILES['postsnippets_import_file'] )
66
+ || empty( $_FILES['postsnippets_import_file'] )
67
+ ) {
68
+ $import .=
69
+ '<p>' . esc_html__( 'Import snippets from a post-snippets-export.zip file. Imported sinppets will get added at the bottom.', 'post-snippets' ) .
70
+ '</p>';
71
+ $import .=
72
+ '<p>' . esc_html__( 'Please make sure no snippets have duplicate titles.', 'post-snippets' ) .
73
+ '</p>';
74
+ $import .= '<form method="post" enctype="multipart/form-data">';
75
+ $import .= '<input type="file" name="postsnippets_import_file"/>';
76
+ $import .= '<input type="hidden" name="action" value="wp_handle_upload"/>';
77
+ $import .=
78
+ '<input type="submit" class="button" value="' .
79
+ __( 'Import Snippets', 'post-snippets' ) . '"/>';
80
+ $import .= wp_nonce_field( 'pspro_import_snippets', 'pspro_import_snippets_nonce', false, false );
81
+ $import .= '</form>';
82
+ } else {
83
+ check_admin_referer( 'pspro_import_snippets', 'pspro_import_snippets_nonce' );
84
+
85
+ if( !current_user_can( 'manage_options' ) ){
86
+
87
+ $import .=
88
+ '<p><strong>' .
89
+ esc_html__( 'Only Admins can import snippets', 'post-snippets' ) .
90
+ '</strong></p>';
91
+
92
+ return $import;
93
+ }
94
+
95
+ $file = wp_handle_upload( $_FILES['postsnippets_import_file'] );
96
+
97
+ if ( isset( $file['file'] ) && ! is_wp_error( $file ) ) {
98
+ require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
99
+ $zip = new \PclZip( $file['file'] );
100
+ $dir = wp_upload_dir();
101
+ $upload_dir = $dir['basedir'] . '/';
102
+ chdir( $upload_dir );
103
+ $unzipped = $zip->extract();
104
+
105
+ if ( $unzipped[0]['stored_filename'] == self::FILE_CFG
106
+ && $unzipped[0]['status'] == 'ok'
107
+ ) {
108
+ // Delete the uploaded archive
109
+ unlink( $file['file'] );
110
+
111
+ $snippets = file_get_contents(
112
+ $upload_dir . self::FILE_CFG
113
+ );
114
+
115
+ if ( $snippets ) {
116
+ $snippets = apply_filters(
117
+ 'post_snippets_import',
118
+ $snippets
119
+ );
120
+
121
+ $imported_snippets = maybe_unserialize( $snippets );
122
+ $current_snippets = get_option( \PostSnippets::OPTION_KEY );
123
+
124
+ if ( empty( $current_snippets ) ) {
125
+ $current_snippets = array();
126
+ }
127
+
128
+ $all_snippets = $current_snippets;
129
+ $duplicate_title_exist = false;
130
+ $empty_title = false;
131
+ $duplicate_title = '';
132
+ foreach ( $imported_snippets as $snippet ) {
133
+ foreach ( $snippet as $key => $value ) {
134
+ $snippet[ $key ] = sanitize_text_field( $snippet[ $key ] );
135
+ }
136
+ if ( empty( $snippet['title'] ) ) {
137
+ $empty_title = true;
138
+ break;
139
+ }
140
+ // $snippet['title'] = sanitize_text_field( $snippet['title'] );
141
+ $all_snippets[] = $snippet;
142
+ foreach ( $current_snippets as $current ) {
143
+ if ( $current['title'] == $snippet['title'] ) {
144
+ $duplicate_title = $snippet['title'];
145
+ $duplicate_title_exist = true;
146
+ break;
147
+ }
148
+ }
149
+ }
150
+
151
+ if ( $empty_title ) {
152
+ $import .=
153
+ '<p><strong>' .
154
+ esc_html__( 'Snippets cannot have empty Titles', 'post-snippets' ) .
155
+ '</strong></p>';
156
+ } elseif ( $duplicate_title_exist == false ) {
157
+ update_option( \PostSnippets::OPTION_KEY, $all_snippets );
158
+ $import .=
159
+ '<p><strong>' .
160
+ esc_html__( 'Snippets successfully imported.', 'post-snippets' ) .
161
+ '</strong></p>';
162
+ } else {
163
+ $import .=
164
+ '<p><strong>' .
165
+ esc_html__( 'All the snippets should have unique titles. The snippet in your import file with title "' . $duplicate_title . '" already exists in your site.', 'post-snippets' ) .
166
+ '</strong></p>';
167
+ }
168
+ }
169
+
170
+ // Delete the snippet file
171
+ unlink( './' . self::FILE_CFG );
172
+
173
+ } else {
174
+ $import .=
175
+ '<p><strong>' .
176
+ esc_html__( 'Snippets could not be imported:', 'post-snippets' ) .
177
+ ' ' .
178
+ esc_html__( 'Unzipping failed.', 'post-snippets' ) .
179
+ '</strong></p>';
180
+ }
181
+ } else {
182
+ if ( $file['error'] || is_wp_error( $file ) ) {
183
+ $import .=
184
+ '<p><strong>' .
185
+ esc_html__( 'Snippets could not be imported:', 'post-snippets' ) .
186
+ ' ' .
187
+ $file['error'] . '</strong></p>';
188
+ } else {
189
+ $import .=
190
+ '<p><strong>' .
191
+ esc_html__( 'Snippets could not be imported:', 'post-snippets' ) .
192
+ ' ' .
193
+ esc_html__( 'Upload failed.', 'post-snippets' ) .
194
+ '</strong></p>';
195
+ }
196
+ }
197
+ }
198
+ return $import;
199
+ }
200
+
201
+ /**
202
+ * Create a zipped filed containing all Post Snippets, for export.
203
+ *
204
+ * @return string URL to the exported snippets
205
+ */
206
+ private function createExportFile() {
207
+ $snippets = maybe_serialize( get_option( \PostSnippets::OPTION_KEY ) );
208
+ $snippets = apply_filters( 'post_snippets_export', $snippets );
209
+ $dir = wp_upload_dir();
210
+ $upload_dir = $dir['basedir'] . '/';
211
+ $upload_url = $dir['baseurl'] . '/';
212
+
213
+ // Open a file stream and write the serialized options to it.
214
+ if ( ! $handle = fopen( $upload_dir . './' . self::FILE_CFG, 'w' ) ) {
215
+ die();
216
+ }
217
+ if ( ! fwrite( $handle, $snippets ) ) {
218
+ die();
219
+ }
220
+ fclose( $handle );
221
+
222
+ // Create a zip archive
223
+ require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
224
+ chdir( $upload_dir );
225
+ $zip = new \PclZip( './' . self::$FILE_ZIP );
226
+ $zipped = $zip->create( './' . self::FILE_CFG );
227
+
228
+ // Delete the snippet file
229
+ unlink( './' . self::FILE_CFG );
230
+
231
+ if ( ! $zipped ) {
232
+ return false;
233
+ }
234
+
235
+ return $upload_url . './' . self::$FILE_ZIP;
236
+ }
237
+
238
+ /**
239
+ * Set export file name
240
+ */
241
+ public static function set_export_name() {
242
+ $date_part = date( 'Y-m-d' );
243
+ self::$FILE_ZIP = "post-snippets-export-{$date_part}.zip";
244
+ }
245
+
246
+ /**
247
+ * Generates the javascript to trigger the download of the file.
248
+ *
249
+ * @return void
250
+ */
251
+ public function psnippetsFooter() {
252
+ echo '<script type="text/javascript">
253
+ document.location = \'' . esc_js( $this->downloadUrl ) . '\';
254
+ </script>';
255
+ // echo $export;
256
+ }
257
  }
src/PostSnippets/Shortcode.php CHANGED
@@ -3,107 +3,103 @@ namespace PostSnippets;
3
 
4
  /**
5
  * Shortcode Handling.
6
- *
7
  */
8
- class Shortcode
9
- {
10
- public function __construct()
11
- {
12
- $this->create();
13
- }
14
 
15
- /**
16
- * Create the functions for shortcodes dynamically and register them
17
- */
18
- public function create()
19
- {
20
- $snippets = get_option(\PostSnippets::OPTION_KEY);
21
- if (!empty($snippets)) {
22
- foreach ($snippets as $snippet) {
23
- // If shortcode is enabled for the snippet, and a snippet has been entered, register it as a shortcode.
24
- if (isset($snippet['shortcode']) && $snippet['shortcode'] && !empty($snippet['snippet'])) {
25
- $vars = explode(",", $snippet['vars']);
26
 
27
- $default_atts = array();
28
- foreach ($vars as $var) {
29
- $attribute = explode('=', $var);
30
- $default_value = (count($attribute) > 1) ? $attribute[1] : '';
31
- $default_atts[$attribute[0]] = $default_value;
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
34
- // Get the wptexturize setting
35
- $texturize = isset($snippet["wptexturize"]) ? $snippet["wptexturize"] : false;
36
 
37
- add_shortcode(
38
- $snippet['title'],
39
- function ( $atts, $content = null ) use ( $snippet, $texturize, $default_atts ) {
40
 
41
  $short_atts = shortcode_atts( $default_atts, $atts );
42
  extract( $short_atts );
43
- foreach(array_keys( $default_atts ) as $key) {
44
- $attributes[$key] =
45
- isset(${"$key"}) ? ${"$key"} :
46
- (isset($short_atts[$key]) ? $short_atts[$key] : null);
47
  }
48
 
49
- //$attributes = compact( array_keys( $default_atts ) );
50
- // Add enclosed content if available to the attributes array
51
- if ( $content != null ) {
52
- $attributes["content"] = $content;
53
- }
54
- $generated_content = $snippet["snippet"];
55
- // Disables auto conversion from & to &amp; as that should be done in snippet, not code (destroys php etc).
56
  // $snippet = str_replace("&", "&amp;", $snippet);
57
- foreach ( $attributes as $key => $val ) {
58
- $generated_content = str_replace( "{" . $key . "}", $val, $generated_content );
59
  }
60
 
61
- // There might be the case that a snippet contains
62
- // the post snippets reserved variable {content} to
63
- // capture the content in enclosed shortcodes, but
64
- // the shortcode is used without enclosing it. To
65
- // avoid outputting {content} as part of the string
66
- // lets remove possible occurences.
67
- $generated_content = str_replace( "{content}", "", $generated_content );
68
 
69
- // Handle PHP shortcodes
70
- $php = $snippet["php"];
71
- if ( $php == true ) {
72
- $generated_content = \PostSnippets\Shortcode::phpEval( $generated_content );
73
- }
74
- // Strip escaping and execute nested shortcodes
75
- $generated_content = do_shortcode( stripslashes( $generated_content ) );
76
- // WPTexturize the Snippet
77
- if ( !empty($snippet['wptexturize']) && ( $snippet['wptexturize'] == true ) ) {
78
- $generated_content = wptexturize( $generated_content );
79
- }
80
- return $generated_content;
81
- }
82
- );
83
- }
84
- }
85
- }
86
- }
87
 
88
- /**
89
- * Evaluate a snippet as PHP code.
90
- *
91
- * @since Post Snippets 1.9
92
- * @param string $content The snippet to evaluate
93
- * @return string The result of the evaluation
94
- */
95
- public static function phpEval($content)
96
- {
97
- if (defined('POST_SNIPPETS_DISABLE_PHP')) {
98
- return $content;
99
- }
100
 
101
- $content = stripslashes($content);
102
 
103
- ob_start();
104
- eval($content);
105
- $content = ob_get_clean();
106
 
107
- return addslashes($content);
108
- }
109
  }
3
 
4
  /**
5
  * Shortcode Handling.
 
6
  */
7
+ class Shortcode {
 
 
 
 
 
8
 
9
+ public function __construct() {
10
+ $this->create();
11
+ }
 
 
 
 
 
 
 
 
12
 
13
+ /**
14
+ * Create the functions for shortcodes dynamically and register them
15
+ */
16
+ public function create() {
17
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
18
+ if ( ! empty( $snippets ) ) {
19
+ foreach ( $snippets as $snippet ) {
20
+ // If shortcode is enabled for the snippet, and a snippet has been entered, register it as a shortcode.
21
+ if ( isset( $snippet['shortcode'] ) && $snippet['shortcode'] && ! empty( $snippet['snippet'] ) ) {
22
+ $vars = explode( ',', $snippet['vars'] );
23
+
24
+ $default_atts = array();
25
+ foreach ( $vars as $var ) {
26
+ $attribute = explode( '=', $var );
27
+ $default_value = ( count( $attribute ) > 1 ) ? $attribute[1] : '';
28
+ $default_atts[ $attribute[0] ] = $default_value;
29
  }
30
 
31
+ // Get the wptexturize setting
32
+ $texturize = isset( $snippet['wptexturize'] ) ? $snippet['wptexturize'] : false;
33
 
34
+ add_shortcode(
35
+ $snippet['title'],
36
+ function ( $atts, $content = null ) use ( $snippet, $texturize, $default_atts ) {
37
 
38
  $short_atts = shortcode_atts( $default_atts, $atts );
39
  extract( $short_atts );
40
+ foreach ( array_keys( $default_atts ) as $key ) {
41
+ $attributes[ $key ] =
42
+ isset( ${"$key"} ) ? ${"$key"} :
43
+ ( isset( $short_atts[ $key ] ) ? $short_atts[ $key ] : null );
44
  }
45
 
46
+ // $attributes = compact( array_keys( $default_atts ) );
47
+ // Add enclosed content if available to the attributes array
48
+ if ( $content != null ) {
49
+ $attributes['content'] = $content;
50
+ }
51
+ $generated_content = $snippet['snippet'];
52
+ // Disables auto conversion from & to &amp; as that should be done in snippet, not code (destroys php etc).
53
  // $snippet = str_replace("&", "&amp;", $snippet);
54
+ foreach ( $attributes as $key => $val ) {
55
+ $generated_content = str_replace( '{' . $key . '}', $val, $generated_content );
56
  }
57
 
58
+ // There might be the case that a snippet contains
59
+ // the post snippets reserved variable {content} to
60
+ // capture the content in enclosed shortcodes, but
61
+ // the shortcode is used without enclosing it. To
62
+ // avoid outputting {content} as part of the string
63
+ // lets remove possible occurences.
64
+ $generated_content = str_replace( '{content}', '', $generated_content );
65
 
66
+ // Handle PHP shortcodes
67
+ $php = $snippet['php'];
68
+ if ( $php == true ) {
69
+ $generated_content = \PostSnippets\Shortcode::phpEval( $generated_content );
70
+ }
71
+ // Strip escaping and execute nested shortcodes
72
+ $generated_content = do_shortcode( stripslashes( $generated_content ) );
73
+ // WPTexturize the Snippet
74
+ if ( ! empty( $snippet['wptexturize'] ) && ( $snippet['wptexturize'] == true ) ) {
75
+ $generated_content = wptexturize( $generated_content );
76
+ }
77
+ return $generated_content;
78
+ }
79
+ );
80
+ }
81
+ }
82
+ }
83
+ }
84
 
85
+ /**
86
+ * Evaluate a snippet as PHP code.
87
+ *
88
+ * @since Post Snippets 1.9
89
+ * @param string $content The snippet to evaluate
90
+ * @return string The result of the evaluation
91
+ */
92
+ public static function phpEval( $content ) {
93
+ if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
94
+ return $content;
95
+ }
 
96
 
97
+ $content = stripslashes( $content );
98
 
99
+ ob_start();
100
+ eval( $content );
101
+ $content = ob_get_clean();
102
 
103
+ return addslashes( $content );
104
+ }
105
  }
src/PostSnippets/View.php CHANGED
@@ -3,27 +3,25 @@ namespace PostSnippets;
3
 
4
  /**
5
  * View Handling.
6
- *
7
  */
8
- class View
9
- {
10
- /**
11
- * Render a View.
12
- *
13
- * @param string $view
14
- * @param array $data
15
- * @return string
16
- */
17
- public static function render($view, $data = null)
18
- {
19
- // Handle data
20
- ($data) ? extract($data) : null;
21
 
22
- ob_start();
23
- include(plugin_dir_path(__FILE__).'../../views/'.$view.'.php');
24
- $view = ob_get_contents();
25
- ob_end_clean();
 
 
 
 
 
 
26
 
27
- return $view;
28
- }
 
 
 
 
 
29
  }
3
 
4
  /**
5
  * View Handling.
 
6
  */
7
+ class View {
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ /**
10
+ * Render a View.
11
+ *
12
+ * @param string $view
13
+ * @param array $data
14
+ * @return string
15
+ */
16
+ public static function render( $view, $data = null ) {
17
+ // Handle data
18
+ ( $data ) ? extract( $data ) : null;
19
 
20
+ ob_start();
21
+ include plugin_dir_path( __FILE__ ) . '../../views/' . $view . '.php';
22
+ $view = ob_get_contents();
23
+ ob_end_clean();
24
+
25
+ return $view;
26
+ }
27
  }
src/PostSnippets/WPEditor.php CHANGED
@@ -3,301 +3,290 @@ namespace PostSnippets;
3
 
4
  /**
5
  * Post Snippets WP Editor.
6
- *
7
  */
8
- class WPEditor
9
- {
10
- const TINYMCE_PLUGIN_NAME = 'post_snippets';
11
-
12
- public function __construct()
13
- {
14
- // Add TinyMCE button
15
- add_action('init', array(&$this, 'addTinymceButton'));
16
-
17
- // Add Editor QuickTag button:
18
- add_action(
19
- 'admin_print_footer_scripts',
20
- array(&$this, 'addQuicktagButton'),
21
- 100
22
- );
23
-
24
- add_action('admin_head', array(&$this, 'jqueryUiDialog'));
25
- add_action('admin_footer', array(&$this, 'addJqueryUiDialog'));
26
-
27
- // Adds the JS and HTML code in the header and footer for the jQuery
28
- // insert UI dialog in the editor
29
- add_action('admin_init', array(&$this, 'enqueueAssets'));
30
- }
31
-
32
-
33
- // -------------------------------------------------------------------------
34
- // WordPress Editor Buttons
35
- // -------------------------------------------------------------------------
36
-
37
- /**
38
- * Add TinyMCE button.
39
- *
40
- * Adds filters to add custom buttons to the TinyMCE editor (Visual Editor)
41
- * in WordPress.
42
- *
43
- * @since Post Snippets 1.8.7
44
- */
45
- public function addTinymceButton()
46
- {
47
- // Don't bother doing this stuff if the current user lacks permissions
48
- if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
49
- return;
50
- }
51
-
52
- // Add only in Rich Editor mode
53
- if (get_user_option('rich_editing') == 'true') {
54
- add_filter(
55
- 'mce_external_plugins',
56
- array(&$this, 'registerTinymcePlugin')
57
- );
58
- add_filter(
59
- 'mce_buttons',
60
- array(&$this, 'registerTinymceButton')
61
- );
62
- }
63
- }
64
-
65
- /**
66
- * Register TinyMCE button.
67
- *
68
- * Pushes the custom TinyMCE button into the array of with button names.
69
- * 'separator' or '|' can be pushed to the array as well. See the link
70
- * for all available TinyMCE controls.
71
- *
72
- * @see wp-includes/class-wp-editor.php
73
- * @link http://www.tinymce.com/wiki.php/Buttons/controls
74
- * @since Post Snippets 1.8.7
75
- *
76
- * @param array $buttons Filter supplied array of buttons to modify
77
- * @return array The modified array with buttons
78
- */
79
- public function registerTinymceButton($buttons)
80
- {
81
- if (!$this->isEditingPost()) {
82
- return $buttons;
83
- }
84
-
85
- array_push($buttons, 'separator', self::TINYMCE_PLUGIN_NAME);
86
- return $buttons;
87
- }
88
-
89
- /**
90
- * Register TinyMCE plugin.
91
- *
92
- * Adds the absolute URL for the TinyMCE plugin to the associative array of
93
- * plugins. Array structure: 'plugin_name' => 'plugin_url'
94
- *
95
- * @see wp-includes/class-wp-editor.php
96
- * @since Post Snippets 1.8.7
97
- *
98
- * @param array $plugins Filter supplied array of plugins to modify
99
- * @return array The modified array with plugins
100
- */
101
- public function registerTinymcePlugin($plugins)
102
- {
103
- if (!$this->isEditingPost()) {
104
- return $plugins;
105
- }
106
-
107
- // Load the TinyMCE plugin, editor_plugin.js, into the array
108
- $plugins[self::TINYMCE_PLUGIN_NAME] =
109
- plugins_url('/tinymce/editor_plugin.js?ver=1.9', \PostSnippets::FILE);
110
-
111
- return $plugins;
112
- }
113
-
114
-
115
- /**
116
- * Adds a QuickTag button to the HTML editor.
117
- *
118
- * Compatible with WordPress 3.3 and newer.
119
- *
120
- * @see wp-includes/js/quicktags.dev.js -> qt.addButton()
121
- * @since Post Snippets 1.8.6
122
- */
123
- public function addQuicktagButton()
124
- {
125
- if (!$this->isEditingPost()) {
126
- return;
127
- }
128
-
129
- echo "\n<!-- START: Add QuickTag button for Post Snippets -->\n";
130
- ?>
131
- <script type="text/javascript" charset="utf-8">
132
- if (typeof QTags != 'undefined') {
133
- function qt_post_snippets() {
134
- post_snippets_caller = 'html';
135
- jQuery("#post-snippets-dialog").dialog("open");
136
- }
137
- QTags.addButton('post_snippets_id', 'Post Snippets', qt_post_snippets);
138
- }
139
- </script>
140
- <?php
141
- echo "\n<!-- END: Add QuickTag button for Post Snippets -->\n";
142
- }
143
-
144
-
145
- // -------------------------------------------------------------------------
146
- // JavaScript / jQuery handling for the post editor
147
- // -------------------------------------------------------------------------
148
-
149
- /**
150
- * Enqueues the necessary scripts and styles for the plugins
151
- *
152
- * @since Post Snippets 1.7
153
- */
154
- public function enqueueAssets()
155
- {
156
- wp_enqueue_script('jquery-ui-dialog');
157
- wp_enqueue_script('jquery-ui-tabs');
158
- wp_enqueue_style('wp-jquery-ui-dialog');
159
-
160
- # Adds the CSS stylesheet for the jQuery UI dialog
161
- $style_url = plugins_url('/assets/post-snippets.css', \PostSnippets::FILE);
162
- wp_register_style( 'post-snippets', $style_url, false, PS_VERSION );
163
- wp_enqueue_style('post-snippets');
164
- }
165
-
166
- /**
167
- * jQuery control for the dialog and Javascript needed to insert snippets into the editor
168
- *
169
- * @since Post Snippets 1.7
170
- */
171
- public function jqueryUiDialog()
172
- {
173
- if (!$this->isEditingPost()) {
174
- return;
175
- }
176
-
177
- # Prepare the snippets and shortcodes into javascript variables
178
- # so they can be inserted into the editor, and get the variables replaced
179
- # with user defined strings.
180
- $snippets = get_option(\PostSnippets::OPTION_KEY, array());
181
-
182
- //Let other plugins change the snippets array
183
- $snippets = apply_filters('post_snippets_snippets_list', $snippets);
184
-
185
- $snippetStack = array();
186
-
187
- if (is_array($snippets) || is_object($snippets)) {
188
- foreach ( $snippets as $key => $snippet ) {
189
- if ( isset($snippet['shortcode']) && ! empty($snippet['shortcode']) ) {
190
- # Build a long string of the variables, ie: varname1={varname1} varname2={varname2}
191
- # so {varnameX} can be replaced at runtime.
192
- $var_arr = explode( ",", $snippet['vars'] );
193
- $variables = '';
194
- if ( ! empty( $var_arr[0] ) ) {
195
- foreach ( $var_arr as $var ) {
196
- $var = $this->stripDefaultVal( $var );
197
-
198
- $variables .= ' ' . $var . '="{' . $var . '}"';
199
- }
200
- }
201
- $shortcode = $snippet['title'] . $variables;
202
- array_push( $snippetStack, "var postsnippet_{$key} = '[" . $shortcode . "]';\n" );
203
- } else if(isset($snippet['snippet'])) {
204
- // To use $snippet is probably not a good naming convention here.
205
- // rename to js_snippet or something?
206
- $snippet = $snippet['snippet'];
207
- # Fixes for potential collisions:
208
- /* Replace <> with char codes, otherwise </script> in a snippet will break it */
209
- $snippet = str_replace( '<', '\x3C', str_replace( '>', '\x3E', $snippet ) );
210
- /* Escape " with \" */
211
- $snippet = str_replace( '"', '\"', $snippet );
212
- /* Remove CR and replace LF with \n to keep formatting */
213
- $snippet = str_replace( chr( 13 ), '', str_replace( chr( 10 ), '\n', $snippet ) );
214
- # Print out the variable containing the snippet
215
- array_push( $snippetStack, "var postsnippet_{$key} = \"" . $snippet . "\";\n" );
216
- }
217
- }
218
- }
219
- ?>
220
-
221
- <?php
222
- $data = array(
223
- 'methods' => $this,
224
- 'snippets' => $snippets,
225
- 'snippetStack' => $snippetStack
226
- );
227
- echo View::render('jquery_ui_dialog_head', $data);
228
- }
229
-
230
- /**
231
- * Build jQuery UI Window.
232
- *
233
- * Creates the jQuery for Post Editor popup window, its snippet tabs and the
234
- * form fields to enter variables.
235
- *
236
- * @since Post Snippets 1.7
237
- */
238
- public function addJqueryUiDialog()
239
- {
240
- if (!$this->isEditingPost()) {
241
- return;
242
- }
243
-
244
- $snippets = get_option(\PostSnippets::OPTION_KEY, array());
245
-
246
- //Let other plugins change the snippets array
247
- $snippets = apply_filters('post_snippets_snippets_list', $snippets);
248
- $data = array('snippets' => $snippets);
249
-
250
- echo View::render('jquery_ui_dialog_footer', $data);
251
- }
252
-
253
- /**
254
- * Determine if current screen is a post editing screen.
255
- *
256
- * @return boolean
257
- */
258
- protected function isEditingPost()
259
- {
260
- $settings = get_option(\PostSnippets::SETTINGS);
261
- $exclude = isset($settings['exclude_from_custom_editors']) ?
262
- $settings['exclude_from_custom_editors'] :
263
- false;
264
-
265
- // If we are not excluding from custom editors, always return true.
266
- if (!$exclude) {
267
- return true;
268
- }
269
-
270
- // If get_current_screen doesn't exist, we're on the frontend,
271
- // so return false, as it's then definately a custom editor
272
- if (function_exists('get_current_screen')) {
273
- $screen = get_current_screen();
274
- } else {
275
- $screen = false;
276
- }
277
-
278
- return is_object($screen) ? $screen->base == 'post' : false;
279
- }
280
-
281
- /**
282
- * Strip Default Value.
283
- *
284
- * Checks if a variable string contains a default value, and if it does it
285
- * will strip it away and return the string with only the variable name
286
- * kept.
287
- *
288
- * @since Post Snippets 1.9.3
289
- * @param string $variable The variable to check for default value
290
- * @return string The variable without any default value
291
- */
292
- public function stripDefaultVal($variable)
293
- {
294
- // Check if variable contains a default defintion
295
- $def_pos = strpos($variable, '=');
296
-
297
- if ($def_pos !== false) {
298
- $split = str_split($variable, $def_pos);
299
- $variable = $split[0];
300
- }
301
- return $variable;
302
- }
303
  }
3
 
4
  /**
5
  * Post Snippets WP Editor.
 
6
  */
7
+ class WPEditor {
8
+
9
+ const TINYMCE_PLUGIN_NAME = 'post_snippets';
10
+
11
+ public function __construct() {
12
+ // Add TinyMCE button
13
+ add_action( 'init', array( &$this, 'addTinymceButton' ) );
14
+
15
+ // Add Editor QuickTag button:
16
+ add_action(
17
+ 'admin_print_footer_scripts',
18
+ array( &$this, 'addQuicktagButton' ),
19
+ 100
20
+ );
21
+
22
+ add_action( 'admin_head', array( &$this, 'jqueryUiDialog' ) );
23
+ add_action( 'admin_footer', array( &$this, 'addJqueryUiDialog' ) );
24
+
25
+ // Adds the JS and HTML code in the header and footer for the jQuery
26
+ // insert UI dialog in the editor
27
+ add_action( 'admin_init', array( &$this, 'enqueueAssets' ) );
28
+ }
29
+
30
+
31
+ // -------------------------------------------------------------------------
32
+ // WordPress Editor Buttons
33
+ // -------------------------------------------------------------------------
34
+
35
+ /**
36
+ * Add TinyMCE button.
37
+ *
38
+ * Adds filters to add custom buttons to the TinyMCE editor (Visual Editor)
39
+ * in WordPress.
40
+ *
41
+ * @since Post Snippets 1.8.7
42
+ */
43
+ public function addTinymceButton() {
44
+ // Don't bother doing this stuff if the current user lacks permissions
45
+ if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
46
+ return;
47
+ }
48
+
49
+ // Add only in Rich Editor mode
50
+ if ( get_user_option( 'rich_editing' ) == 'true' ) {
51
+ add_filter(
52
+ 'mce_external_plugins',
53
+ array( &$this, 'registerTinymcePlugin' )
54
+ );
55
+ add_filter(
56
+ 'mce_buttons',
57
+ array( &$this, 'registerTinymceButton' )
58
+ );
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Register TinyMCE button.
64
+ *
65
+ * Pushes the custom TinyMCE button into the array of with button names.
66
+ * 'separator' or '|' can be pushed to the array as well. See the link
67
+ * for all available TinyMCE controls.
68
+ *
69
+ * @see wp-includes/class-wp-editor.php
70
+ * @link http://www.tinymce.com/wiki.php/Buttons/controls
71
+ * @since Post Snippets 1.8.7
72
+ *
73
+ * @param array $buttons Filter supplied array of buttons to modify
74
+ * @return array The modified array with buttons
75
+ */
76
+ public function registerTinymceButton( $buttons ) {
77
+ if ( ! $this->isEditingPost() ) {
78
+ return $buttons;
79
+ }
80
+
81
+ array_push( $buttons, 'separator', self::TINYMCE_PLUGIN_NAME );
82
+ return $buttons;
83
+ }
84
+
85
+ /**
86
+ * Register TinyMCE plugin.
87
+ *
88
+ * Adds the absolute URL for the TinyMCE plugin to the associative array of
89
+ * plugins. Array structure: 'plugin_name' => 'plugin_url'
90
+ *
91
+ * @see wp-includes/class-wp-editor.php
92
+ * @since Post Snippets 1.8.7
93
+ *
94
+ * @param array $plugins Filter supplied array of plugins to modify
95
+ * @return array The modified array with plugins
96
+ */
97
+ public function registerTinymcePlugin( $plugins ) {
98
+ if ( ! $this->isEditingPost() ) {
99
+ return $plugins;
100
+ }
101
+
102
+ // Load the TinyMCE plugin, editor_plugin.js, into the array
103
+ $plugins[ self::TINYMCE_PLUGIN_NAME ] =
104
+ plugins_url( '/tinymce/editor_plugin.js?ver=1.9', \PostSnippets::FILE );
105
+
106
+ return $plugins;
107
+ }
108
+
109
+
110
+ /**
111
+ * Adds a QuickTag button to the HTML editor.
112
+ *
113
+ * Compatible with WordPress 3.3 and newer.
114
+ *
115
+ * @see wp-includes/js/quicktags.dev.js -> qt.addButton()
116
+ * @since Post Snippets 1.8.6
117
+ */
118
+ public function addQuicktagButton() {
119
+ if ( ! $this->isEditingPost() ) {
120
+ return;
121
+ }
122
+
123
+ echo "\n<!-- START: Add QuickTag button for Post Snippets -->\n";
124
+ ?>
125
+ <script type="text/javascript" charset="utf-8">
126
+ if (typeof QTags != 'undefined') {
127
+ function qt_post_snippets() {
128
+ post_snippets_caller = 'html';
129
+ jQuery("#post-snippets-dialog").dialog("open");
130
+ }
131
+ QTags.addButton('post_snippets_id', 'Post Snippets', qt_post_snippets);
132
+ }
133
+ </script>
134
+ <?php
135
+ echo "\n<!-- END: Add QuickTag button for Post Snippets -->\n";
136
+ }
137
+
138
+
139
+ // -------------------------------------------------------------------------
140
+ // JavaScript / jQuery handling for the post editor
141
+ // -------------------------------------------------------------------------
142
+
143
+ /**
144
+ * Enqueues the necessary scripts and styles for the plugins
145
+ *
146
+ * @since Post Snippets 1.7
147
+ */
148
+ public function enqueueAssets() {
149
+ wp_enqueue_script( 'jquery-ui-dialog' );
150
+ wp_enqueue_script( 'jquery-ui-tabs' );
151
+ wp_enqueue_style( 'wp-jquery-ui-dialog' );
152
+
153
+ // Adds the CSS stylesheet for the jQuery UI dialog
154
+ $style_url = plugins_url( '/assets/post-snippets.css', \PostSnippets::FILE );
155
+ wp_register_style( 'post-snippets', $style_url, false, PS_VERSION );
156
+ wp_enqueue_style( 'post-snippets' );
157
+ }
158
+
159
+ /**
160
+ * jQuery control for the dialog and Javascript needed to insert snippets into the editor
161
+ *
162
+ * @since Post Snippets 1.7
163
+ */
164
+ public function jqueryUiDialog() {
165
+ if ( ! $this->isEditingPost() ) {
166
+ return;
167
+ }
168
+
169
+ // Prepare the snippets and shortcodes into javascript variables
170
+ // so they can be inserted into the editor, and get the variables replaced
171
+ // with user defined strings.
172
+ $snippets = get_option( \PostSnippets::OPTION_KEY, array() );
173
+
174
+ // Let other plugins change the snippets array
175
+ $snippets = apply_filters( 'post_snippets_snippets_list', $snippets );
176
+
177
+ $snippetStack = array();
178
+
179
+ if ( is_array( $snippets ) || is_object( $snippets ) ) {
180
+ foreach ( $snippets as $key => $snippet ) {
181
+ if ( isset( $snippet['shortcode'] ) && ! empty( $snippet['shortcode'] ) ) {
182
+ // Build a long string of the variables, ie: varname1={varname1} varname2={varname2}
183
+ // so {varnameX} can be replaced at runtime.
184
+ $var_arr = explode( ',', $snippet['vars'] );
185
+ $variables = '';
186
+ if ( ! empty( $var_arr[0] ) ) {
187
+ foreach ( $var_arr as $var ) {
188
+ $var = $this->stripDefaultVal( $var );
189
+
190
+ $variables .= ' ' . $var . '="{' . $var . '}"';
191
+ }
192
+ }
193
+ $shortcode = $snippet['title'] . $variables;
194
+ array_push( $snippetStack, "var postsnippet_{$key} = '[" . $shortcode . "]';\n" );
195
+ } elseif ( isset( $snippet['snippet'] ) ) {
196
+ // To use $snippet is probably not a good naming convention here.
197
+ // rename to js_snippet or something?
198
+ $snippet = $snippet['snippet'];
199
+ // Fixes for potential collisions:
200
+ /* Replace <> with char codes, otherwise </script> in a snippet will break it */
201
+ $snippet = str_replace( '<', '\x3C', str_replace( '>', '\x3E', $snippet ) );
202
+ /* Escape " with \" */
203
+ $snippet = str_replace( '"', '\"', $snippet );
204
+ /* Remove CR and replace LF with \n to keep formatting */
205
+ $snippet = str_replace( chr( 13 ), '', str_replace( chr( 10 ), '\n', $snippet ) );
206
+ // Print out the variable containing the snippet
207
+ array_push( $snippetStack, "var postsnippet_{$key} = \"" . $snippet . "\";\n" );
208
+ }
209
+ }
210
+ }
211
+ ?>
212
+
213
+ <?php
214
+ $data = array(
215
+ 'methods' => $this,
216
+ 'snippets' => $snippets,
217
+ 'snippetStack' => $snippetStack,
218
+ );
219
+ echo View::render( 'jquery_ui_dialog_head', $data );
220
+ }
221
+
222
+ /**
223
+ * Build jQuery UI Window.
224
+ *
225
+ * Creates the jQuery for Post Editor popup window, its snippet tabs and the
226
+ * form fields to enter variables.
227
+ *
228
+ * @since Post Snippets 1.7
229
+ */
230
+ public function addJqueryUiDialog() {
231
+ if ( ! $this->isEditingPost() ) {
232
+ return;
233
+ }
234
+
235
+ $snippets = get_option( \PostSnippets::OPTION_KEY, array() );
236
+
237
+ // Let other plugins change the snippets array
238
+ $snippets = apply_filters( 'post_snippets_snippets_list', $snippets );
239
+ $data = array( 'snippets' => $snippets );
240
+
241
+ echo View::render( 'jquery_ui_dialog_footer', $data );
242
+ }
243
+
244
+ /**
245
+ * Determine if current screen is a post editing screen.
246
+ *
247
+ * @return boolean
248
+ */
249
+ protected function isEditingPost() {
250
+ $settings = get_option( \PostSnippets::SETTINGS );
251
+ $exclude = isset( $settings['exclude_from_custom_editors'] ) ?
252
+ $settings['exclude_from_custom_editors'] :
253
+ false;
254
+
255
+ // If we are not excluding from custom editors, always return true.
256
+ if ( ! $exclude ) {
257
+ return true;
258
+ }
259
+
260
+ // If get_current_screen doesn't exist, we're on the frontend,
261
+ // so return false, as it's then definately a custom editor
262
+ if ( function_exists( 'get_current_screen' ) ) {
263
+ $screen = get_current_screen();
264
+ } else {
265
+ $screen = false;
266
+ }
267
+
268
+ return is_object( $screen ) ? $screen->base == 'post' : false;
269
+ }
270
+
271
+ /**
272
+ * Strip Default Value.
273
+ *
274
+ * Checks if a variable string contains a default value, and if it does it
275
+ * will strip it away and return the string with only the variable name
276
+ * kept.
277
+ *
278
+ * @since Post Snippets 1.9.3
279
+ * @param string $variable The variable to check for default value
280
+ * @return string The variable without any default value
281
+ */
282
+ public function stripDefaultVal( $variable ) {
283
+ // Check if variable contains a default defintion
284
+ $def_pos = strpos( $variable, '=' );
285
+
286
+ if ( $def_pos !== false ) {
287
+ $split = str_split( $variable, $def_pos );
288
+ $variable = $split[0];
289
+ }
290
+ return $variable;
291
+ }
 
 
 
 
 
 
 
 
 
 
292
  }
src/init.php CHANGED
@@ -24,8 +24,8 @@ function guten_post_list_cgb_block_assets() { // phpcs:ignore
24
  wp_enqueue_style(
25
  'guten_post_list-cgb-style-css', // Handle.
26
  plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
27
- array( 'wp-editor' ) // Dependency to include the CSS after it.
28
- // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
29
  );
30
  }
31
 
@@ -47,7 +47,7 @@ function guten_post_list_cgb_editor_assets() { // phpcs:ignore
47
  'guten_post_list-cgb-block-js', // Handle.
48
  plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
49
  array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), // Dependencies, defined above.
50
- // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: File modification time.
51
  true // Enqueue the script in the footer.
52
  );
53
 
@@ -55,8 +55,8 @@ function guten_post_list_cgb_editor_assets() { // phpcs:ignore
55
  wp_enqueue_style(
56
  'guten_post_list-cgb-block-editor-css', // Handle.
57
  plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
58
- array( 'wp-edit-blocks' ) // Dependency to include the CSS after it.
59
- // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
60
  );
61
  }
62
 
24
  wp_enqueue_style(
25
  'guten_post_list-cgb-style-css', // Handle.
26
  plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
27
+ array( 'wp-editor' ), // Dependency to include the CSS after it.
28
+ filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
29
  );
30
  }
31
 
47
  'guten_post_list-cgb-block-js', // Handle.
48
  plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
49
  array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), // Dependencies, defined above.
50
+ filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: File modification time.
51
  true // Enqueue the script in the footer.
52
  );
53
 
55
  wp_enqueue_style(
56
  'guten_post_list-cgb-block-editor-css', // Handle.
57
  plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
58
+ array( 'wp-edit-blocks' ), // Dependency to include the CSS after it.
59
+ filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
60
  );
61
  }
62
 
views/admin_news.php CHANGED
@@ -4,40 +4,40 @@
4
 
5
  <style>
6
  .sab-plugin {
7
- width: 300px;
8
- display: inline-block;
9
- background: #fff;
10
- border: 1px solid #ccc;
11
- padding: 4px 4px 20px 4px;
12
- margin:0 10px 10px 0;
13
  }
14
  .sab-plugin img {
15
- width: 100%;
16
- height: 200px;
17
  }
18
  .sab-plugin p {
19
- padding: 15px;
20
- height: 106px;
21
  }
22
  .sab-center {
23
- text-align: center;
24
  }
25
  .sab-plugin .sab-button {
26
- display:inline-block;
27
  }
28
  </style>
29
 
30
  <div class="sab-plugins">
31
- <?php foreach($plugins as $plugin) : ?>
32
- <div class="sab-plugin">
33
- <a target="_blank" href="<?php echo $plugin["url"] ?>">
34
- <img src="<?php echo PS_URL . "assets/img/" , $plugin["image"] ?>" alt="Go to <?php echo $plugin["name"] ?>" />
35
- </a>
36
- <p><?php echo $plugin["description"] ?></p>
37
- <div class="sab-center">
38
- <a target="_blank" class="button button-primary button-hero" href="<?php echo $plugin["url"] ?>"><?php _e('Read more') ?></a>
39
- </div>
40
- </div>
41
- <?php endforeach ?>
42
  </div>
43
  </div>
4
 
5
  <style>
6
  .sab-plugin {
7
+ width: 300px;
8
+ display: inline-block;
9
+ background: #fff;
10
+ border: 1px solid #ccc;
11
+ padding: 4px 4px 20px 4px;
12
+ margin:0 10px 10px 0;
13
  }
14
  .sab-plugin img {
15
+ width: 100%;
16
+ height: 200px;
17
  }
18
  .sab-plugin p {
19
+ padding: 15px;
20
+ height: 106px;
21
  }
22
  .sab-center {
23
+ text-align: center;
24
  }
25
  .sab-plugin .sab-button {
26
+ display:inline-block;
27
  }
28
  </style>
29
 
30
  <div class="sab-plugins">
31
+ <?php foreach ( $plugins as $plugin ) : ?>
32
+ <div class="sab-plugin">
33
+ <a target="_blank" href="<?php echo esc_url( $plugin['url'] ); ?>">
34
+ <img src="<?php echo esc_url( PS_URL ) . 'assets/img/' , esc_attr( $plugin['image'] ); ?>" alt="Go to <?php echo esc_attr( $plugin['name'] ); ?>" />
35
+ </a>
36
+ <p><?php echo esc_html( $plugin['description'] ); ?></p>
37
+ <div class="sab-center">
38
+ <a target="_blank" class="button button-primary button-hero" href="<?php echo esc_url( $plugin['url'] ); ?>"><?php esc_html_e( 'Read more' ); ?></a>
39
+ </div>
40
+ </div>
41
+ <?php endforeach ?>
42
  </div>
43
  </div>
views/admin_notice_get_started.php CHANGED
@@ -19,21 +19,21 @@ $snippet_count = count( get_option( 'post_snippets_options', array() ) );
19
  ?>
20
 
21
  <style>
22
- #pt-admin-notice .button-primary,
23
- #pt-admin-notice .button-secondary {
24
- margin-left: 15px;
25
- }
26
  </style>
27
 
28
  <div id="ps-admin-notice" class="updated">
29
- <p>
30
- <?php _e( 'You\'ve just installed Post Snippets, find it under \'Settings\'.', 'post-snippets' ); ?>
31
- &nbsp;&nbsp;
32
- <a href="<?php echo PS_MAIN_PAGE_URL . '&ps-dismiss-get-started-nag=1'; ?>" class="button-primary"
33
- style="vertical-align: baseline;"><?php _e( 'Go to Post Snippets', 'post-snippets' ); ?></a>
34
- <a href="<?php echo esc_url( add_query_arg( 'ps-dismiss-get-started-nag', 1 ) ); ?>"
35
- class="button-secondary"><?php _e( 'Hide this', 'post-snippets' ); ?></a>
36
- </p>
37
  </div>
38
 
39
 
19
  ?>
20
 
21
  <style>
22
+ #pt-admin-notice .button-primary,
23
+ #pt-admin-notice .button-secondary {
24
+ margin-left: 15px;
25
+ }
26
  </style>
27
 
28
  <div id="ps-admin-notice" class="updated">
29
+ <p>
30
+ <?php esc_html_e( 'You\'ve just installed Post Snippets, find it under \'Settings\'.', 'post-snippets' ); ?>
31
+ &nbsp;&nbsp;
32
+ <a href="<?php echo esc_attr( PS_MAIN_PAGE_URL ) . '&ps-dismiss-get-started-nag=1'; ?>" class="button-primary"
33
+ style="vertical-align: baseline;"><?php esc_html_e( 'Go to Post Snippets', 'post-snippets' ); ?></a>
34
+ <a href="<?php echo esc_url( add_query_arg( 'ps-dismiss-get-started-nag', 1 ) ); ?>"
35
+ class="button-secondary"><?php esc_html_e( 'Hide this', 'post-snippets' ); ?></a>
36
+ </p>
37
  </div>
38
 
39
 
views/admin_notice_newsletter.php CHANGED
@@ -25,42 +25,42 @@ $snippet_count = count( get_option( 'post_snippets_options', array() ) );
25
  <div class="subscribe-form ml-block-success" style="display:none">
26
  <div class="form-section mb0">
27
  <p>
28
- <?php _e( 'Thank you for subscribing to the Post Snippets newsletter!', 'post-snippets' ); ?>
29
  </p>
30
  </div>
31
  </div>
32
 
33
- <!-- FOR NEW PLUGIN - UPDATE BELOW ID IN ACTION URL -->
34
  <form class="ml-block-form" action="//app.mailerlite.com/webforms/submit/a3m1f7" data-id="177069"
35
- data-code="c7d6k5" method="POST" target="_blank">
36
  <div class="subscribe-form horizontal">
37
  <div class="form-section horizontal" style="display: inline">
38
  <div class="form-group ml-field-email ml-validate-required ml-validate-email"
39
- style="display: inline">
40
  <span
41
- class="subscribe-message"><?php _e( 'Subscribe for Post Snippets updates:', 'post-snippets' ); ?></span>
42
  <input style="display: inline" type="text" name="fields[email]" class="form-control"
43
- placeholder="Email*" value="<?php echo wp_get_current_user()->user_email; ?>">
 
 
 
44
  </div>
45
- <div class="form-group ml-field-ps_count ml-validate-required" style="display: none">
46
- <input style="display: none" type="text" name="fields[ps_count]" class="form-control" placeholder="PS Count*" value="<?php echo $snippet_count ?>" spellcheck="false" autocapitalize="off" autocorrect="off">
47
- </div>
48
 
49
  </div>
50
  <div class="form-section horizontal" style="display: inline">
51
  <button type="submit" class="primary">
52
- <?php _e( 'Subscribe now!', 'post-snippets' ); ?>
53
  </button>
54
 
55
  <button disabled="disabled" style="display: none;" type="button" class="loading primary">
56
  <img src="//static.mailerlite.com/images/rolling.gif" width="20" height="20"
57
- style="padding-top: 3px;">
58
  </button>
59
 
60
  </div>
61
 
62
  <a href="<?php echo esc_url( add_query_arg( 'ps-dismiss-newsletter-nag', 1 ) ); ?>"
63
- class="button-secondary"><?php _e( 'Hide this', 'post-snippets' ); ?></a>
64
 
65
  <div class="clearfix" style="clear: both;"></div>
66
  <input type="hidden" name="ml-submit" value="1"/>
@@ -71,14 +71,14 @@ $snippet_count = count( get_option( 'post_snippets_options', array() ) );
71
  function ml_webform_success_6493346() {
72
  jQuery('.ml-subscribe-form-6493346 .ml-block-success').show();
73
  jQuery('.ml-subscribe-form-6493346 .ml-block-form, .subscribe-message').hide();
74
- window.location.search += '&ps-dismiss-newsletter-nag=1';
75
  }
76
  </script>
77
 
78
  </div>
79
  </div>
80
  <script type="text/javascript"
81
- src="//static.mailerlite.com/js/w/webforms.min.js?v3772b61f1ec61c541c401d4eadfdd02f"></script>
82
 
83
 
84
 
25
  <div class="subscribe-form ml-block-success" style="display:none">
26
  <div class="form-section mb0">
27
  <p>
28
+ <?php esc_html_e( 'Thank you for subscribing to the Post Snippets newsletter!', 'post-snippets' ); ?>
29
  </p>
30
  </div>
31
  </div>
32
 
33
+ <!-- FOR NEW PLUGIN - UPDATE BELOW ID IN ACTION URL -->
34
  <form class="ml-block-form" action="//app.mailerlite.com/webforms/submit/a3m1f7" data-id="177069"
35
+ data-code="c7d6k5" method="POST" target="_blank">
36
  <div class="subscribe-form horizontal">
37
  <div class="form-section horizontal" style="display: inline">
38
  <div class="form-group ml-field-email ml-validate-required ml-validate-email"
39
+ style="display: inline">
40
  <span
41
+ class="subscribe-message"><?php esc_html_e( 'Subscribe for Post Snippets updates:', 'post-snippets' ); ?></span>
42
  <input style="display: inline" type="text" name="fields[email]" class="form-control"
43
+ placeholder="Email*" value="<?php echo esc_attr( wp_get_current_user()->user_email ); ?>">
44
+ </div>
45
+ <div class="form-group ml-field-ps_count ml-validate-required" style="display: none">
46
+ <input style="display: none" type="text" name="fields[ps_count]" class="form-control" placeholder="PS Count*" value="<?php echo esc_attr( $snippet_count ); ?>" spellcheck="false" autocapitalize="off" autocorrect="off">
47
  </div>
 
 
 
48
 
49
  </div>
50
  <div class="form-section horizontal" style="display: inline">
51
  <button type="submit" class="primary">
52
+ <?php esc_html_e( 'Subscribe now!', 'post-snippets' ); ?>
53
  </button>
54
 
55
  <button disabled="disabled" style="display: none;" type="button" class="loading primary">
56
  <img src="//static.mailerlite.com/images/rolling.gif" width="20" height="20"
57
+ style="padding-top: 3px;">
58
  </button>
59
 
60
  </div>
61
 
62
  <a href="<?php echo esc_url( add_query_arg( 'ps-dismiss-newsletter-nag', 1 ) ); ?>"
63
+ class="button-secondary"><?php esc_html_e( 'Hide this', 'post-snippets' ); ?></a>
64
 
65
  <div class="clearfix" style="clear: both;"></div>
66
  <input type="hidden" name="ml-submit" value="1"/>
71
  function ml_webform_success_6493346() {
72
  jQuery('.ml-subscribe-form-6493346 .ml-block-success').show();
73
  jQuery('.ml-subscribe-form-6493346 .ml-block-form, .subscribe-message').hide();
74
+ window.location.search += '&ps-dismiss-newsletter-nag=1';
75
  }
76
  </script>
77
 
78
  </div>
79
  </div>
80
  <script type="text/javascript"
81
+ src="//static.mailerlite.com/js/w/webforms.min.js?v3772b61f1ec61c541c401d4eadfdd02f"></script>
82
 
83
 
84
 
views/admin_options.php CHANGED
@@ -1,7 +1,7 @@
1
  <form method="post" action="options.php">
2
  <?php
3
- settings_fields(\PostSnippets::SETTINGS);
4
- do_settings_sections('post-snippets');
5
- submit_button();
6
  ?>
7
  </form>
1
  <form method="post" action="options.php">
2
  <?php
3
+ settings_fields( \PostSnippets::SETTINGS );
4
+ do_settings_sections( 'post-snippets' );
5
+ submit_button();
6
  ?>
7
  </form>
views/admin_snippets.php CHANGED
@@ -1,339 +1,330 @@
1
  <form method="post" action="" class="post-snippets-wrap">
2
- <?php
3
- wp_nonce_field( 'update_snippets', 'update_snippets_nonce' );
4
- ?>
5
- <div class="post-snippets-buttons-top">
6
- <?php
7
- \PostSnippets\Admin::submit(
8
- 'add-snippet',
9
- __( 'Add New Snippet', 'post-snippets' ),
10
- 'button-secondary',
11
- false
12
- );
13
- \PostSnippets\Admin::submit(
14
- 'delete-snippets',
15
- __( 'Delete Selected', 'post-snippets' ),
16
- 'button-secondary',
17
- false
18
- );
19
- ?>
20
  <a href="#" class="button" data-ps-download><i class="wp-ps-cloud-download"></i> Download snippets</a>
21
- </div>
22
 
23
  <div>
24
 
25
  </div>
26
 
27
- <table class="widefat fixed mt-20 post-snippets-table" cellspacing="0">
28
- <thead>
29
- <tr>
30
- <th scope="col" class="check-column"><input type="checkbox" /></th>
31
- <th scope="col" class="text-right expand-collapse">
32
- <a href="#" class="expand-all">
33
- <?php
34
- _e( 'Expand All', 'post-snippets' );
35
- ?>
36
- </a>
37
- <a href="#" class="collapse-all">
38
- <?php
39
- _e( 'Collapse All', 'post-snippets' );
40
- ?>
41
- </a>
42
- </th>
43
- </tr>
44
- </thead>
45
- </table>
46
-
47
- <div class="post-snippets post-snippets-list post-snippets-list-empty" style="display: none;">
48
- <p>
49
- <?php
50
- echo __( 'You\'ve just installed Post Snippets, awesome!', 'post-snippets' ) ;
51
- ?><br />
52
- <?php
53
- echo __( 'Click "Add New Snippet" to create your first snippet or read the documentation at the top right under "Help".', 'post-snippets' ) ;
54
- ?>
55
- </p>
56
- </div>
57
- <?php
58
- wp_nonce_field( 'delete_snippet', 'delete_snippet' );
59
- ?>
60
- <?php
61
- wp_nonce_field( 'sync_up', 'sync_up' );
62
- ?>
63
- <?php
64
- wp_nonce_field( 'sync_down', 'sync_down' );
65
- ?>
66
- <?php
67
- $snippets = get_option( \PostSnippets::OPTION_KEY );
68
-
69
- if ( !empty($snippets) ) {
70
- ?>
71
 
72
- <div class="post-snippets post-snippets-list">
73
- <?php
74
- foreach ( $snippets as $key => $snippet ) {
75
- ?>
76
- <div class="post-snippets-item ui-state-highlight" data-order="<?php
77
- echo $key ;
78
- ?>" id="key-<?php
79
- echo $key ;
80
- ?>">
81
- <div class="post-snippets-toolbar">
82
- <div class="text-left">
83
- <input type='checkbox' name='checked[]' value='<?php
84
- echo $key ;
85
- ?>'/>
86
- <input type='text' class="post-snippet-title" name='<?php
87
- echo "snippets[{$key}][title]" ;
88
- ?>' value='<?php
89
- echo $snippet['title'] ;
90
- ?>'/>
91
- <span id="snippet-<?php
92
- echo $key ;
93
- ?>-title" class="post-snippet-title"><?php
94
- echo $snippet['title'] ;
95
- ?></span>
96
- <span class='ps-description'><?php
97
- if ( !empty($snippet['description']) ) {
98
- echo " (" . esc_html( $snippet['description'] ) . ")" ;
99
- }
100
- ?></span>
101
- <a href="#" class="edit-title">
102
- <i class="dashicons dashicons-edit"></i>
103
- </a>
104
- <a href="#" class="save-title">
105
- <i class="dashicons dashicons-yes"></i>
106
- </a>
107
- </div>
108
- <div class="text-right post-snippets-toolbar-right">
109
 
110
- <?php
111
- ?>
112
 
113
- <a href="#" class="toggle-post-snippets-data" title="Expand/Collapse">
114
- <i class="dashicons dashicons-arrow-down"></i>
115
- <i class="dashicons dashicons-arrow-up"></i>
116
- </a>
117
- </div>
118
- </div>
119
- <div class="post-snippets-data">
120
- <div class="post-snippets-data-cell">
121
- <div>
122
- <textarea id="snippet-<?php
123
- echo $key ;
124
- ?>" class="snippet" name="<?php
125
- echo "snippets[{$key}][snippet]" ;
126
- ?>" class="large-text" style='width: 100%;' rows="5"><?php
127
- echo htmlspecialchars( $snippet['snippet'], ENT_NOQUOTES ) ;
128
- ?></textarea>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
- <?php
131
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
- <?php
134
- _e( 'Description', 'post-snippets' );
135
- ?>:
136
- <input type='text' style='width: 100%;' id="description-<?php
137
- echo $key ;
138
- ?>" name="<?php
139
- echo "snippets[{$key}][description]" ;
140
- ?>" value='<?php
141
- if ( isset( $snippet['description'] ) ) {
142
- echo esc_html( $snippet['description'] ) ;
143
- }
144
- ?>'/>
145
- <a style="margin-top:6px" href="#" data-save-snippet="<?php
146
- echo $key ;
147
- ?>" class="button-primary"><?php
148
- _e( 'Save', 'post-snippets' );
149
- ?></a>
150
- <span id="saved-success-<?php
151
- echo $key ;
152
- ?>" style="display: none;">Snippet saved</span>
153
- </div>
154
- </div>
155
- <div class="post-snippets-data-cell">
156
- <strong>Variables:</strong><br/>
157
- <input type='text' id="vars-<?php
158
- echo $key ;
159
- ?>" name="<?php
160
- echo "snippets[{$key}][vars]" ;
161
- ?>" value='<?php
162
- echo $snippet['vars'] ;
163
- ?>'/>
164
- <br/>
165
- <br/>
166
 
167
- <label for="<?php
168
- echo "snippets[{$key}][shortcode]" ;
169
- ?>">
170
- <input type="checkbox" name="<?php
171
- echo "snippets[{$key}][shortcode]" ;
172
- ?>" id="shortcode-<?php
173
- echo $key ;
174
- ?>" value="1" <?php
175
- checked( $snippet['shortcode'], '1', true );
176
- ?>>
177
- Shortcode
178
- </label>
179
 
180
- <br/><strong><?php
181
- _e( 'Shortcode Options:', 'post-snippets' );
182
- ?></strong><br/>
183
- <?php
184
-
185
- if ( !defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
186
- ?>
187
- <label for="<?php
188
- echo "snippets[{$key}][php]" ;
189
- ?>">
190
- <input type="checkbox" name="<?php
191
- echo "snippets[{$key}][php]" ;
192
- ?>" id="php-<?php
193
- echo $key ;
194
- ?>" value="1" <?php
195
- checked( $snippet['php'], '1', true );
196
- ?>>
197
- PHP Code
198
- </label>
199
- <br/>
200
- <?php
201
- }
202
-
203
- ?>
204
 
205
- <label for="<?php
206
- echo "snippets[{$key}][wptexturize]" ;
207
- ?>">
208
- <input type="checkbox" name="<?php
209
- echo "snippets[{$key}][wptexturize]" ;
210
- ?>" id="wptexturize-<?php
211
- echo $key ;
212
- ?>" value="1" <?php
213
- checked( $snippet['wptexturize'], '1', true );
214
- ?>>
215
- wptexturize
216
- </label>
217
- </div>
218
- </div>
219
- </div>
220
- <?php
221
- }
222
- ?>
223
- </div>
224
- <?php
225
- }
 
226
 
227
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
 
230
- <div id="delete-confirm" title="<?php
231
- _e( 'Confirm', 'post-snippets' );
232
- ?>" style="display:none;">
233
- <p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
234
- <?php
235
- _e( 'Do you wan to delete snippet', 'post-snippets' );
236
- ?>: <strong></strong>?
237
- </div>
 
238
 
239
- <div id="sync-up-confirm" title="<?php
240
- _e( 'Confirm', 'post-snippets' );
241
- ?>" style="display:none;">
242
- <p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
243
- <?php
244
- _e( 'Do you want to upload the snippet', 'post-snippets' );
245
- ?>: <strong></strong> <?php
246
- _e( 'in your snippets cloud?', 'post-snippets' );
247
- ?>
248
- </div>
 
 
249
 
250
- <div id="sync-up-success" title="<?php
251
- _e( 'Success', 'post-snippets' );
252
- ?>" style="display:none;">
253
- <p><span class="dashicons dashicons-thumbs-up" style="float:left; margin-right:12px;"></span>
254
- <?php
255
- _e( 'Snippet successfully saved!', 'post-snippets' );
256
- ?>
257
- </div>
 
258
 
259
- <div id="sync-success" title="<?php
260
- _e( 'Success', 'post-snippets' );
261
- ?>" style="display:none;">
262
- <p><span class="dashicons dashicons-thumbs-up" style="float:left; margin-right:12px;"></span>
263
- <?php
264
- _e( 'Snippet successfully downloaded!', 'post-snippets' );
265
- ?>
266
- </div>
 
267
 
268
- <div id="sync-up-error" title="<?php
269
- _e( 'Error', 'post-snippets' );
270
- ?>" style="display:none;">
271
- <p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
272
- <p data-error></p>
273
- </div>
274
 
275
- <div id="sync-update-confirm" title="<?php
276
- _e( 'Confirm', 'post-snippets' );
277
- ?>" style="display:none;">
278
- <p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
279
- <?php
280
- _e( 'A snippet with title <strong data-title></strong> already exists in your online library:', 'post-snippets' );
281
- ?>
282
- <div class='snippet'>
283
- <p><b>Title</b>: <span data-title></span></p>
284
- <p><b>Description</b>: <span data-description></span></p>
285
- <p><b>Variables</b>: <span data-vars></span></p>
286
- <p><b>Snippet</b>: <textarea readonly></textarea></p>
287
- <p><b>Options</b>: <span data-options></span></p>
288
- </div>
289
- </div>
 
290
 
291
- <div id="sync-down-list" title="<?php
292
- _e( 'Donwload your snippets', 'post-snippets' );
293
- ?>">
294
- <p class="message"></p>
295
- <table class="wp-list-table widefat striped">
296
- <thead>
297
- <tr>
298
- <td class="manage-column column-cb"><input type='checkbox' data-toggle-all></td>
299
- <th class=""><?php
300
- _e( 'Title', 'post-snippets' );
301
- ?></th>
302
- <th><?php
303
- _e( 'Description', 'post-snippets' );
304
- ?></th>
305
- <th><?php
306
- _e( 'Variables', 'post-snippets' );
307
- ?></th>
308
- <th><?php
309
- _e( 'Snippet', 'post-snippets' );
310
- ?></th>
311
- </tr>
312
- </thead>
313
- <tbody>
 
 
 
 
 
 
 
314
 
315
- </tbody>
316
- </table>
317
- </div>
318
 
319
- <div id="sp-loading" style="display:none;">
320
- <span></span>
321
- </div>
322
 
323
  <div class="post-snippets-buttons-bottom">
324
- <?php
325
- \PostSnippets\Admin::submit(
326
- 'add-snippet',
327
- __( 'Add New Snippet', 'post-snippets' ),
328
- 'button-secondary',
329
- false
330
- );
331
- \PostSnippets\Admin::submit(
332
- 'delete-snippets',
333
- __( 'Delete Selected', 'post-snippets' ),
334
- 'button-secondary',
335
- false
336
- );
337
- ?>
338
  </div>
339
  </form>
1
  <form method="post" action="" class="post-snippets-wrap">
2
+ <?php
3
+ wp_nonce_field( 'update_snippets', 'update_snippets_nonce' );
4
+ ?>
5
+ <div class="post-snippets-buttons-top">
6
+ <?php
7
+ \PostSnippets\Admin::submit(
8
+ 'add-snippet',
9
+ __( 'Add New Snippet', 'post-snippets' ),
10
+ 'button-secondary',
11
+ false
12
+ );
13
+ \PostSnippets\Admin::submit(
14
+ 'delete-snippets',
15
+ __( 'Delete Selected', 'post-snippets' ),
16
+ 'button-secondary',
17
+ false
18
+ );
19
+ ?>
20
  <a href="#" class="button" data-ps-download><i class="wp-ps-cloud-download"></i> Download snippets</a>
21
+ </div>
22
 
23
  <div>
24
 
25
  </div>
26
 
27
+ <table class="widefat fixed mt-20 post-snippets-table" cellspacing="0">
28
+ <thead>
29
+ <tr>
30
+ <th scope="col" class="check-column"><input type="checkbox" /></th>
31
+ <th scope="col" class="text-right expand-collapse">
32
+ <a href="#" class="expand-all">
33
+ <?php
34
+ esc_html_e( 'Expand All', 'post-snippets' );
35
+ ?>
36
+ </a>
37
+ <a href="#" class="collapse-all">
38
+ <?php
39
+ esc_html_e( 'Collapse All', 'post-snippets' );
40
+ ?>
41
+ </a>
42
+ </th>
43
+ </tr>
44
+ </thead>
45
+ </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ <div class="post-snippets post-snippets-list post-snippets-list-empty" style="display: none;">
48
+ <p>
49
+ <?php
50
+ echo esc_html__( 'You\'ve just installed Post Snippets, awesome!', 'post-snippets' );
51
+ ?>
52
+ <br />
53
+ <?php
54
+ echo esc_html__( 'Click "Add New Snippet" to create your first snippet or read the documentation at the top right under "Help".', 'post-snippets' );
55
+ ?>
56
+ </p>
57
+ </div>
58
+ <?php
59
+ wp_nonce_field( 'delete_snippet', 'delete_snippet' );
60
+ ?>
61
+ <?php
62
+ wp_nonce_field( 'sync_up', 'sync_up' );
63
+ ?>
64
+ <?php
65
+ wp_nonce_field( 'sync_down', 'sync_down' );
66
+ ?>
67
+ <?php
68
+ $snippets = get_option( \PostSnippets::OPTION_KEY );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
+ if ( ! empty( $snippets ) ) {
71
+ ?>
72
 
73
+ <div class="post-snippets post-snippets-list">
74
+ <?php
75
+ foreach ( $snippets as $key => $snippet ) {
76
+ ?>
77
+ <div class="post-snippets-item ui-state-highlight"
78
+ data-order="<?php echo esc_attr( $key ); ?>"
79
+ id="key-<?php echo esc_attr( $key ); ?> ">
80
+ <div class="post-snippets-toolbar">
81
+ <div class="text-left">
82
+ <input type='checkbox' name='checked[]' value='<?php echo esc_attr( $key ); ?>'/>
83
+ <input type='text' class="post-snippet-title"
84
+ name='<?php echo 'snippets[' . esc_attr( $key ) . '][title]'; ?>'
85
+ value='<?php echo esc_attr( $snippet['title'] ); ?>'
86
+ />
87
+ <span id="snippet-<?php echo esc_attr( $key ); ?>-title"
88
+ class="post-snippet-title"><?php echo esc_attr( $snippet['title'] ); ?>
89
+ </span>
90
+ <span class='ps-description'>
91
+ <?php
92
+ if ( ! empty( $snippet['description'] ) ) {
93
+ echo ' (' . esc_html( $snippet['description'] ) . ')';
94
+ }
95
+ ?>
96
+ </span>
97
+ <a href="#" class="edit-title">
98
+ <i class="dashicons dashicons-edit"></i>
99
+ </a>
100
+ <a href="#" class="save-title">
101
+ <i class="dashicons dashicons-yes"></i>
102
+ </a>
103
+ </div>
104
+ <div class="text-right post-snippets-toolbar-right">
105
+ <a href="#" class="toggle-post-snippets-data" title="Expand/Collapse">
106
+ <i class="dashicons dashicons-arrow-down"></i>
107
+ <i class="dashicons dashicons-arrow-up"></i>
108
+ </a>
109
+ </div>
110
+ </div>
111
+ <div class="post-snippets-data">
112
+ <div class="post-snippets-data-cell">
113
+ <div>
114
+ <textarea id="snippet-<?php echo esc_attr( $key ); ?>"
115
+ class="snippet"
116
+ name="<?php echo 'snippets[' . esc_attr( $key ) . '][snippet]'; ?>"
117
+ class="large-text" style='width: 100%;' rows="5"><?php
118
+ echo esc_html( $snippet['snippet'] );
119
+ ?></textarea>
120
 
121
+ <?php
122
+ esc_html_e( 'Description', 'post-snippets' );
123
+ ?>:
124
+ <input type='text' style='width: 100%;'
125
+ id="description-<?php echo esc_attr( $key ); ?>"
126
+ name="<?php echo 'snippets[' . esc_attr( $key ) . '][description]'; ?>"
127
+ value =
128
+ '<?php
129
+ if ( isset( $snippet['description'] ) ) {
130
+ echo esc_html( $snippet['description'] );
131
+ }
132
+ ?>'/>
133
+ <a style="margin-top:6px" href="#"
134
+ data-save-snippet="<?php echo esc_attr( $key ); ?>"
135
+ class="button-primary"
136
+ >
137
+ <?php
138
+ esc_html_e( 'Save', 'post-snippets' );
139
+ ?>
140
+ </a>
141
 
142
+ <span id="saved-success-<?php echo esc_attr( $key ); ?>"
143
+ style="display: none;">Snippet saved
144
+ </span>
145
+ </div>
146
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
+ <div class="post-snippets-data-cell">
149
+ <strong>Variables:</strong><br/>
150
+ <input type='text' id="vars-<?php echo esc_attr( $key ); ?>"
151
+ name="<?php echo 'snippets[' . esc_attr( $key ) . '][vars]'; ?>"
152
+ value='<?php echo esc_attr( $snippet['vars'] ); ?>'
153
+ />
154
+ <br/><br/>
 
 
 
 
 
155
 
156
+ <label for="<?php echo 'snippets[' . esc_attr( $key ) . '][shortcode]'; ?> ">
157
+ <input type="checkbox"
158
+ name="<?php echo 'snippets[' . esc_attr( $key ) . '][shortcode]'; ?>"
159
+ id="shortcode-<?php echo esc_attr( $key ); ?>" value="1"
160
+ <?php checked( $snippet['shortcode'], '1', true );
161
+ ?>
162
+ >Shortcode
163
+ </label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
+ <br/>
166
+ <strong>
167
+ <?php
168
+ esc_html_e( 'Shortcode Options:', 'post-snippets' );
169
+ ?>
170
+ </strong><br/>
171
+
172
+ <?php
173
+ if ( ! defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
174
+ ?>
175
+ <label for="<?php echo 'snippets[' . esc_attr( $key ) . '][php]';?>">
176
+ <input type="checkbox"
177
+ name="<?php echo 'snippets[' . esc_attr( $key ) . '][php]'; ?>"
178
+ id="php-<?php echo esc_attr( $key ); ?>"
179
+ value="1" <?php checked( $snippet['php'], '1', true ); ?>
180
+ >
181
+ PHP Code
182
+ </label>
183
+ <br/>
184
+ <?php
185
+ }
186
+ ?>
187
 
188
+ <label for="<?php echo 'snippets[' . esc_attr( $key ) . '][wptexturize]'; ?>">
189
+ <input type="checkbox"
190
+ name="<?php echo 'snippets[' . esc_attr( $key ) . '][wptexturize]'; ?>"
191
+ id="wptexturize-<?php echo esc_attr( $key ); ?>"
192
+ value="1" <?php checked( $snippet['wptexturize'], '1', true ); ?>
193
+ >
194
+ wptexturize
195
+ </label>
196
+ </div>
197
+ </div>
198
+ </div>
199
+ <?php
200
+ }
201
+ ?>
202
+ </div>
203
+ <?php
204
+ }
205
+ ?>
206
 
207
 
208
+ <div id="delete-confirm"
209
+ title="<?php esc_attr_e( 'Confirm', 'post-snippets' );?>"
210
+ style="display:none;">
211
+ <p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
212
+ <?php
213
+ esc_html_e( 'Do you want to delete snippet', 'post-snippets' );
214
+ ?>: <strong></strong>?
215
+ </p>
216
+ </div>
217
 
218
+ <div id="sync-up-confirm"
219
+ title="<?php esc_attr_e( 'Confirm', 'post-snippets' ); ?>"
220
+ style="display:none;">
221
+ <p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
222
+ <?php
223
+ esc_html_e( 'Do you want to upload the snippet', 'post-snippets' );
224
+ ?>: <strong></strong>
225
+ <?php
226
+ esc_html_e( 'in your snippets cloud?', 'post-snippets' );
227
+ ?>
228
+ </p>
229
+ </div>
230
 
231
+ <div id="sync-up-success"
232
+ title="<?php esc_attr_e( 'Success', 'post-snippets' ); ?>"
233
+ style="display:none;">
234
+ <p><span class="dashicons dashicons-thumbs-up" style="float:left; margin-right:12px;"></span>
235
+ <?php
236
+ esc_html_e( 'Snippet successfully saved!', 'post-snippets' );
237
+ ?>
238
+ </p>
239
+ </div>
240
 
241
+ <div id="sync-success"
242
+ title="<?php esc_attr_e( 'Success', 'post-snippets' );?>"
243
+ style="display:none;">
244
+ <p><span class="dashicons dashicons-thumbs-up" style="float:left; margin-right:12px;"></span>
245
+ <?php
246
+ esc_html_e( 'Snippet successfully downloaded!', 'post-snippets' );
247
+ ?>
248
+ </p>
249
+ </div>
250
 
251
+ <div id="sync-up-error"
252
+ title="<?php esc_attr_e( 'Error', 'post-snippets' ); ?>" style="display:none;">
253
+ <p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
254
+ <p data-error></p>
255
+ </p>
256
+ </div>
257
 
258
+ <div id="sync-update-confirm"
259
+ title="<?php esc_attr_e( 'Confirm', 'post-snippets' ); ?>"
260
+ style="display:none;">
261
+ <p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
262
+ <?php
263
+ esc_html_e( 'A snippet with title <strong data-title></strong> already exists in your online library:', 'post-snippets' );
264
+ ?>
265
+ </p>
266
+ <div class='snippet'>
267
+ <p><b>Title</b>: <span data-title></span></p>
268
+ <p><b>Description</b>: <span data-description></span></p>
269
+ <p><b>Variables</b>: <span data-vars></span></p>
270
+ <p><b>Snippet</b>: <textarea readonly></textarea></p>
271
+ <p><b>Options</b>: <span data-options></span></p>
272
+ </div>
273
+ </div>
274
 
275
+ <div id="sync-down-list"
276
+ title="<?php esc_attr_e( 'Donwload your snippets', 'post-snippets' );?>">
277
+ <p class="message"></p>
278
+ <table class="wp-list-table widefat striped">
279
+ <thead>
280
+ <tr>
281
+ <td class="manage-column column-cb"><input type='checkbox' data-toggle-all></td>
282
+ <th class="">
283
+ <?php
284
+ esc_html_e( 'Title', 'post-snippets' );
285
+ ?>
286
+ </th>
287
+ <th>
288
+ <?php
289
+ esc_html_e( 'Description', 'post-snippets' );
290
+ ?>
291
+ </th>
292
+ <th>
293
+ <?php
294
+ esc_html_e( 'Variables', 'post-snippets' );
295
+ ?>
296
+ </th>
297
+ <th>
298
+ <?php
299
+ esc_html_e( 'Snippet', 'post-snippets' );
300
+ ?>
301
+ </th>
302
+ </tr>
303
+ </thead>
304
+ <tbody>
305
 
306
+ </tbody>
307
+ </table>
308
+ </div>
309
 
310
+ <div id="sp-loading" style="display:none;">
311
+ <span></span>
312
+ </div>
313
 
314
  <div class="post-snippets-buttons-bottom">
315
+ <?php
316
+ \PostSnippets\Admin::submit(
317
+ 'add-snippet',
318
+ __( 'Add New Snippet', 'post-snippets' ),
319
+ 'button-secondary',
320
+ false
321
+ );
322
+ \PostSnippets\Admin::submit(
323
+ 'delete-snippets',
324
+ __( 'Delete Selected', 'post-snippets' ),
325
+ 'button-secondary',
326
+ false
327
+ );
328
+ ?>
329
  </div>
330
  </form>
views/help/advanced.php CHANGED
@@ -1,4 +1,4 @@
1
- <h2><?php _e('Advanced', 'post-snippets'); ?> (<em><?php _e('for developers', 'post-snippets'); ?></em>)</h2>
2
 
3
  <p>
4
  You can add constants to wp-config.php or the theme’s functions.php file to control some aspects of the plugin. Available constants to set are:
@@ -12,31 +12,31 @@ define('POST_SNIPPETS_DISABLE_PHP', true);
12
  </code></pre>
13
 
14
  <p>
15
- <?php _e('You can retrieve a Post Snippet directly from PHP, in a theme for instance, by using the PostSnippets::getSnippet() method.', 'post-snippets'); ?>
16
  </p>
17
 
18
- <h2><?php _e('Usage', 'post-snippets'); ?></h2>
19
  <p>
20
  <code>
21
  &lt;?php $my_snippet = PostSnippets::getSnippet( $snippet_name, $snippet_vars ); ?&gt;
22
  </code></p>
23
 
24
- <h2><?php _e('Parameters', 'post-snippets'); ?></h2>
25
  <p>
26
  <strong>$snippet_name</strong><br/>
27
- <?php _e('(string) (required) The name of the snippet to retrieve.', 'post-snippets'); ?>
28
  <br/><br/>
29
  <strong>$snippet_vars</strong><br/>
30
- <?php _e('(string) The variables to pass to the snippet, formatted as a query string.', 'post-snippets'); ?>
31
  </p>
32
 
33
 
34
- <h2><?php _e('Example', 'post-snippets'); ?></h2>
35
 
36
  <pre><code>// Use querystring for variables
37
  $mySnippet = PostSnippets::getSnippet('internal-link', 'title=Awesome&url=2011/02/awesome/');
38
- echo $mySnippet;
39
 
40
  // Use array for variables
41
  $mySnippet = PostSnippets::getSnippet('internal-link', array('title' => 'Awesome', 'url' => '2011/02/awesome/');
42
- echo $mySnippet;</code></pre>
1
+ <h2><?php esc_html_e( 'Advanced', 'post-snippets' ); ?> (<em><?php esc_html_e( 'for developers', 'post-snippets' ); ?></em>)</h2>
2
 
3
  <p>
4
  You can add constants to wp-config.php or the theme’s functions.php file to control some aspects of the plugin. Available constants to set are:
12
  </code></pre>
13
 
14
  <p>
15
+ <?php esc_html_e( 'You can retrieve a Post Snippet directly from PHP, in a theme for instance, by using the PostSnippets::getSnippet() method.', 'post-snippets' ); ?>
16
  </p>
17
 
18
+ <h2><?php esc_html_e( 'Usage', 'post-snippets' ); ?></h2>
19
  <p>
20
  <code>
21
  &lt;?php $my_snippet = PostSnippets::getSnippet( $snippet_name, $snippet_vars ); ?&gt;
22
  </code></p>
23
 
24
+ <h2><?php esc_html_e( 'Parameters', 'post-snippets' ); ?></h2>
25
  <p>
26
  <strong>$snippet_name</strong><br/>
27
+ <?php esc_html_e( '(string) (required) The name of the snippet to retrieve.', 'post-snippets' ); ?>
28
  <br/><br/>
29
  <strong>$snippet_vars</strong><br/>
30
+ <?php esc_html_e( '(string) The variables to pass to the snippet, formatted as a query string.', 'post-snippets' ); ?>
31
  </p>
32
 
33
 
34
+ <h2><?php esc_html_e( 'Example', 'post-snippets' ); ?></h2>
35
 
36
  <pre><code>// Use querystring for variables
37
  $mySnippet = PostSnippets::getSnippet('internal-link', 'title=Awesome&url=2011/02/awesome/');
38
+ echo esc_html($mySnippet);
39
 
40
  // Use array for variables
41
  $mySnippet = PostSnippets::getSnippet('internal-link', array('title' => 'Awesome', 'url' => '2011/02/awesome/');
42
+ echo esc_html($mySnippet);</code></pre>
views/help/filters.php CHANGED
@@ -1,14 +1,14 @@
1
- <h2><?php _e('Filters', 'post-snippets'); ?> (<em><?php _e('for developers', 'post-snippets'); ?></em>)</h2>
2
 
3
- <p><?php _e('The following filters are available for hooking into the plugin:', 'post-snippets'); ?></p>
4
 
5
  <ul>
6
- <li><strong>post_snippets_import</strong>&nbsp;&nbsp;&nbsp;<em>serialized array</em>&nbsp;&nbsp;&nbsp;<?php _e('Modify snippets and related data before the imported file populates the snippets.', 'post-snippets'); ?></li>
7
- <li><strong>post_snippets_export</strong>&nbsp;&nbsp;&nbsp;<em>serialized array</em>&nbsp;&nbsp;&nbsp;<?php _e('Modify snippets and related data before the export file is created.', 'post-snippets'); ?></li>
8
- <li><strong>post_snippets_snippets_list</strong>&nbsp;&nbsp;&nbsp;<em>array</em>&nbsp;&nbsp;&nbsp;<?php _e('Modify the array of snippets that are used as the snippet list for the jQuery UI dialog in the edit post screen.', 'post-snippets'); ?></li>
9
  </ul>
10
 
11
- <h3><?php _e('Examples', 'post-snippets'); ?></h3>
12
 
13
  <strong>post_snippets_export</strong>
14
  <pre><code>// Filter Exported Snippets
@@ -16,8 +16,8 @@ function ps_export( $snippets )
16
  {
17
  $snippets = unserialize( $snippets );
18
  foreach ( $snippets as &$snippet ) {
19
- // Do something here. Example below search and replaces in snippets
20
- $snippet['snippet'] = str_replace('search','replace', $snippet['snippet']);
21
  }
22
  return serialize( $snippets );
23
  }
@@ -29,8 +29,8 @@ function ps_import( $snippets )
29
  {
30
  $snippets = unserialize( $snippets );
31
  foreach ( $snippets as &$snippet ) {
32
- // Do something here. Example below search and replaces in variables
33
- $snippet['vars'] = str_replace('search', 'replace', $snippet['vars']);
34
  }
35
  return serialize( $snippets );
36
  }
1
+ <h2><?php esc_html_e( 'Filters', 'post-snippets' ); ?> (<em><?php esc_html_e( 'for developers', 'post-snippets' ); ?></em>)</h2>
2
 
3
+ <p><?php esc_html_e( 'The following filters are available for hooking into the plugin:', 'post-snippets' ); ?></p>
4
 
5
  <ul>
6
+ <li><strong>post_snippets_import</strong>&nbsp;&nbsp;&nbsp;<em>serialized array</em>&nbsp;&nbsp;&nbsp;<?php esc_html_e( 'Modify snippets and related data before the imported file populates the snippets.', 'post-snippets' ); ?></li>
7
+ <li><strong>post_snippets_export</strong>&nbsp;&nbsp;&nbsp;<em>serialized array</em>&nbsp;&nbsp;&nbsp;<?php esc_html_e( 'Modify snippets and related data before the export file is created.', 'post-snippets' ); ?></li>
8
+ <li><strong>post_snippets_snippets_list</strong>&nbsp;&nbsp;&nbsp;<em>array</em>&nbsp;&nbsp;&nbsp;<?php esc_html_e( 'Modify the array of snippets that are used as the snippet list for the jQuery UI dialog in the edit post screen.', 'post-snippets' ); ?></li>
9
  </ul>
10
 
11
+ <h3><?php esc_html_e( 'Examples', 'post-snippets' ); ?></h3>
12
 
13
  <strong>post_snippets_export</strong>
14
  <pre><code>// Filter Exported Snippets
16
  {
17
  $snippets = unserialize( $snippets );
18
  foreach ( $snippets as &$snippet ) {
19
+ // Do something here. Example below search and replaces in snippets
20
+ $snippet['snippet'] = str_replace('search','replace', $snippet['snippet']);
21
  }
22
  return serialize( $snippets );
23
  }
29
  {
30
  $snippets = unserialize( $snippets );
31
  foreach ( $snippets as &$snippet ) {
32
+ // Do something here. Example below search and replaces in variables
33
+ $snippet['vars'] = str_replace('search', 'replace', $snippet['vars']);
34
  }
35
  return serialize( $snippets );
36
  }
views/help/php.php CHANGED
@@ -1,25 +1,25 @@
1
  <h2>PHP Code</h2>
2
 
3
  <p>
4
- <?php _e('Snippets defined as shortcodes can optionally also be evaluated as PHP Code by enabling the PHP checkbox. PHP snippets is only available when treating the snippet as a shortcode.', 'post-snippets'); ?>
5
  </p>
6
 
7
  <p>
8
- <?php _e('Check this image for an example PHP snippet:', 'post-snippets'); ?>
9
  </p>
10
 
11
- <img src="<?php echo plugins_url('assets/img/help/php-snippet.jpg', \PostSnippets::FILE); ?>" />
12
 
13
  <p>
14
- <?php _e('With a snippet defined like the one above, you can call it with its shortcode definition in a post. Let\'s pretend that the example snippet is named phpcode and have one variable defined loop_me, then it would be called like this from a post:', 'post-snippets'); ?>
15
  </p>
16
 
17
  <code>[phpcode loop_me="post snippet with PHP!"]</code>
18
 
19
  <p>
20
- <?php _e('When the shortcode is executed the loop_me variable will be replaced with the string supplied in the shortcode and then the PHP code will be evaluated. (Outputting the string five times in this case. Wow!)', 'post-snippets'); ?>
21
  </p>
22
 
23
  <p>
24
- <?php _e('Note the evaluation order, any snippet variables will be replaced before the snippet is evaluated as PHP code. Also note that a PHP snippet don\'t need to be wrapped in &lt;?php #code; ?&gt;.', 'post-snippets'); ?>
25
  </p>
1
  <h2>PHP Code</h2>
2
 
3
  <p>
4
+ <?php esc_html_e( 'Snippets defined as shortcodes can optionally also be evaluated as PHP Code by enabling the PHP checkbox. PHP snippets is only available when treating the snippet as a shortcode.', 'post-snippets' ); ?>
5
  </p>
6
 
7
  <p>
8
+ <?php esc_html_e( 'Check this image for an example PHP snippet:', 'post-snippets' ); ?>
9
  </p>
10
 
11
+ <img src="<?php echo esc_url( plugins_url( 'assets/img/help/php-snippet.jpg', \PostSnippets::FILE ) ); ?>" />
12
 
13
  <p>
14
+ <?php esc_html_e( 'With a snippet defined like the one above, you can call it with its shortcode definition in a post. Let\'s pretend that the example snippet is named phpcode and have one variable defined loop_me, then it would be called like this from a post:', 'post-snippets' ); ?>
15
  </p>
16
 
17
  <code>[phpcode loop_me="post snippet with PHP!"]</code>
18
 
19
  <p>
20
+ <?php esc_html_e( 'When the shortcode is executed the loop_me variable will be replaced with the string supplied in the shortcode and then the PHP code will be evaluated. (Outputting the string five times in this case. Wow!)', 'post-snippets' ); ?>
21
  </p>
22
 
23
  <p>
24
+ <?php esc_html_e( 'Note the evaluation order, any snippet variables will be replaced before the snippet is evaluated as PHP code. Also note that a PHP snippet don\'t need to be wrapped in &lt;?php #code; ?&gt;.', 'post-snippets' ); ?>
25
  </p>
views/help/post.php CHANGED
@@ -1,13 +1,13 @@
1
- <h2><?php _e('The Post Editor', 'post-snippets'); ?></h2>
2
 
3
- <img src="<?php echo plugins_url('assets/img/help/post-snippets-editor.jpg', \PostSnippets::FILE); ?>" />
4
 
5
  <p>
6
- <?php _e('With your snippets set up, you\'ll find a new button in your post editor (circled in the image above), which you can click to open the Post Snippet window to insert one of your snippets in your post.', 'post-snippets'); ?>
7
  </p>
8
 
9
- <img src="<?php echo plugins_url('assets/img/help/post-snippets-window.jpg', \PostSnippets::FILE); ?>" />
10
 
11
  <p>
12
- <?php _e('When you click this button, you get a window with all your available snippets. Each snippet has its own tab in the Post Snippet window, so you can select which snippet to insert. If you have set up custom variables for the snippet, you can now enter the values for these variables before clicking insert and they will be inserted in the correct places in the snippet string.', 'post-snippets'); ?>
13
  </p>
1
+ <h2><?php esc_html_e( 'The Post Editor', 'post-snippets' ); ?></h2>
2
 
3
+ <img src="<?php echo esc_url( plugins_url( 'assets/img/help/post-snippets-editor.jpg', \PostSnippets::FILE ) ); ?>" />
4
 
5
  <p>
6
+ <?php esc_html_e( 'With your snippets set up, you\'ll find a new button in your post editor (circled in the image above), which you can click to open the Post Snippet window to insert one of your snippets in your post.', 'post-snippets' ); ?>
7
  </p>
8
 
9
+ <img src="<?php echo esc_url( plugins_url( 'assets/img/help/post-snippets-window.jpg', \PostSnippets::FILE ) ); ?>" />
10
 
11
  <p>
12
+ <?php esc_html_e( 'When you click this button, you get a window with all your available snippets. Each snippet has its own tab in the Post Snippet window, so you can select which snippet to insert. If you have set up custom variables for the snippet, you can now enter the values for these variables before clicking insert and they will be inserted in the correct places in the snippet string.', 'post-snippets' ); ?>
13
  </p>
views/help/sidebar.php CHANGED
@@ -1,16 +1,22 @@
1
  <p><strong>
2
- <?php _e('Related:', 'post-snippets'); ?>
3
  </strong></p>
4
 
5
- <p><a href="//www.postsnippets.com" target="_blank"><?php
6
- _e('Website', 'post-snippets');
7
- ?></a></p>
 
 
8
 
9
- <p><a href="http://wordpress.org/support/plugin/post-snippets" target="_blank"><?php
10
- _e('Support', 'post-snippets');
11
- ?></a></p>
 
 
12
 
13
- <p><a href="https://github.com/GreenTreeLabs/post-snippets" target="_blank"><?php
14
- _e('GitHub', 'post-snippets');
15
- ?></a></p>
 
 
16
 
1
  <p><strong>
2
+ <?php esc_html_e( 'Related:', 'post-snippets' ); ?>
3
  </strong></p>
4
 
5
+ <p><a href="//www.postsnippets.com" target="_blank">
6
+ <?php
7
+ esc_html_e( 'Website', 'post-snippets' );
8
+ ?>
9
+ </a></p>
10
 
11
+ <p><a href="http://wordpress.org/support/plugin/post-snippets" target="_blank">
12
+ <?php
13
+ esc_html_e( 'Support', 'post-snippets' );
14
+ ?>
15
+ </a></p>
16
 
17
+ <p><a href="https://github.com/GreenTreeLabs/post-snippets" target="_blank">
18
+ <?php
19
+ esc_html_e( 'GitHub', 'post-snippets' );
20
+ ?>
21
+ </a></p>
22
 
views/help/usage.php CHANGED
@@ -1,62 +1,62 @@
1
- <h2><?php _e('Usage', 'post-snippets'); ?></h2>
2
 
3
 
4
- <h3><?php _e('Title', 'post-snippets'); ?></h3>
5
  <p>
6
- <?php _e('Give the snippet a title that helps you identify it in the post editor. This also becomes the name of the shortcode if you enable that option.', 'post-snippets'); ?>
7
  </p>
8
 
9
 
10
- <h3><?php _e('Variables', 'post-snippets'); ?></h3>
11
  <p>
12
- <?php _e('A comma separated list of custom variables you can reference in your snippet. A variable can also be assigned a default value that will be used in the insert window by using the equal sign, variable=default.', 'post-snippets'); ?>
13
  </p>
14
 
15
  <p>
16
- <strong><?php _e('Example', 'post-snippets'); ?></strong>
17
- <pre><code>url,name,role=user,title</code></pre>
18
  </p>
19
 
20
 
21
- <h3><?php _e('Snippet', 'post-snippets'); ?></h3>
22
  <p>
23
- <?php _e('This is the block of text, HTML or PHP to insert in the post or as a shortcode. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.', 'post-snippets'); ?>
24
  </p>
25
 
26
- <p><strong><?php _e('Example', 'post-snippets'); ?></strong></p>
27
- <p><?php _e('To reference the variables in the example above, you would enter {url} and {name}. So if you enter this snippet:', 'post-snippets'); ?></p>
28
- <p><?php _e('So if you enter this snippet:', 'post-snippets'); ?></p>
29
 
30
  <pre><code>This is the website of &lt;a href="{url}"&gt;{name}&lt;/a&gt;</code></pre>
31
 
32
- <p><?php _e('You will get the option to replace url and name on insert if they are defined as variables.', 'post-snippets'); ?></p>
33
 
34
 
35
- <h3><?php _e('Description', 'post-snippets'); ?></h3>
36
  <p>
37
- <?php _e('An optional description for the Snippet. If filled out, the description will be displayed in the snippets insert window in the post editor.', 'post-snippets'); ?>
38
  </p>
39
 
40
 
41
- <h3><?php _e('Shortcode', 'post-snippets'); ?></h3>
42
  <p>
43
- <?php _e('When enabling the shortcode checkbox, the snippet is no longer inserted directly but instead inserted as a shortcode. The obvious advantage of this is of course that you can insert a block of text or code in many places on the site, and update the content from one single place.', 'post-snippets'); ?>
44
  </p>
45
 
46
  <p>
47
- <?php _e('The name to use the shortcode is the same as the title of the snippet (spaces are not allowed). When inserting a shortcode snippet, the shortcode and not the content will be inserted in the post.', 'post-snippets'); ?>
48
  </p>
49
 
50
  <p>
51
- <?php _e('If you enclose the shortcode in your posts, you can access the enclosed content by using the variable {content} in your snippet. The {content} variable is reserved, so don\'t use it in the variables field.', 'post-snippets'); ?>
52
  </p>
53
 
54
- <h3><?php _e('PHP Code', 'post-snippets'); ?></h3>
55
  <p>
56
- <?php _e('See the dedicated help section for information about PHP shortcodes.', 'post-snippets'); ?>
57
  </p>
58
 
59
  <h3>wptexturize</h3>
60
  <p>
61
- <?php printf(__('Before the shortcode is outputted, it can optionally be formatted with %s, to transform quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.', 'post-snippets'), '<a href="http://codex.wordpress.org/Function_Reference/wptexturize">wptexturize</a>'); ?>
62
  </p>
1
+ <h2><?php esc_html_e( 'Usage', 'post-snippets' ); ?></h2>
2
 
3
 
4
+ <h3><?php esc_html_e( 'Title', 'post-snippets' ); ?></h3>
5
  <p>
6
+ <?php esc_html_e( 'Give the snippet a title that helps you identify it in the post editor. This also becomes the name of the shortcode if you enable that option.', 'post-snippets' ); ?>
7
  </p>
8
 
9
 
10
+ <h3><?php esc_html_e( 'Variables', 'post-snippets' ); ?></h3>
11
  <p>
12
+ <?php esc_html_e( 'A comma separated list of custom variables you can reference in your snippet. A variable can also be assigned a default value that will be used in the insert window by using the equal sign, variable=default.', 'post-snippets' ); ?>
13
  </p>
14
 
15
  <p>
16
+ <strong><?php esc_html_e( 'Example', 'post-snippets' ); ?></strong>
17
+ <pre><code>url,name,role=user,title</code></pre>
18
  </p>
19
 
20
 
21
+ <h3><?php esc_html_e( 'Snippet', 'post-snippets' ); ?></h3>
22
  <p>
23
+ <?php esc_html_e( 'This is the block of text, HTML or PHP to insert in the post or as a shortcode. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.', 'post-snippets' ); ?>
24
  </p>
25
 
26
+ <p><strong><?php esc_html_e( 'Example', 'post-snippets' ); ?></strong></p>
27
+ <p><?php esc_html_e( 'To reference the variables in the example above, you would enter {url} and {name}. So if you enter this snippet:', 'post-snippets' ); ?></p>
28
+ <p><?php esc_html_e( 'So if you enter this snippet:', 'post-snippets' ); ?></p>
29
 
30
  <pre><code>This is the website of &lt;a href="{url}"&gt;{name}&lt;/a&gt;</code></pre>
31
 
32
+ <p><?php esc_html_e( 'You will get the option to replace url and name on insert if they are defined as variables.', 'post-snippets' ); ?></p>
33
 
34
 
35
+ <h3><?php esc_html_e( 'Description', 'post-snippets' ); ?></h3>
36
  <p>
37
+ <?php esc_html_e( 'An optional description for the Snippet. If filled out, the description will be displayed in the snippets insert window in the post editor.', 'post-snippets' ); ?>
38
  </p>
39
 
40
 
41
+ <h3><?php esc_html_e( 'Shortcode', 'post-snippets' ); ?></h3>
42
  <p>
43
+ <?php esc_html_e( 'When enabling the shortcode checkbox, the snippet is no longer inserted directly but instead inserted as a shortcode. The obvious advantage of this is of course that you can insert a block of text or code in many places on the site, and update the content from one single place.', 'post-snippets' ); ?>
44
  </p>
45
 
46
  <p>
47
+ <?php esc_html_e( 'The name to use the shortcode is the same as the title of the snippet (spaces are not allowed). When inserting a shortcode snippet, the shortcode and not the content will be inserted in the post.', 'post-snippets' ); ?>
48
  </p>
49
 
50
  <p>
51
+ <?php esc_html_e( 'If you enclose the shortcode in your posts, you can access the enclosed content by using the variable {content} in your snippet. The {content} variable is reserved, so don\'t use it in the variables field.', 'post-snippets' ); ?>
52
  </p>
53
 
54
+ <h3><?php esc_html_e( 'PHP Code', 'post-snippets' ); ?></h3>
55
  <p>
56
+ <?php esc_html_e( 'See the dedicated help section for information about PHP shortcodes.', 'post-snippets' ); ?>
57
  </p>
58
 
59
  <h3>wptexturize</h3>
60
  <p>
61
+ <?php printf( esc_html__( 'Before the shortcode is outputted, it can optionally be formatted with %s, to transform quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.', 'post-snippets' ), '<a href="http://codex.wordpress.org/Function_Reference/wptexturize">wptexturize</a>' ); ?>
62
  </p>
views/jquery_ui_dialog_footer.php CHANGED
@@ -1,91 +1,105 @@
1
  <!-- START: Post Snippets UI Dialog -->
2
  <?php // Setup the dialog divs ?>
3
  <div class="hidden">
4
- <div id="post-snippets-dialog" title="Post Snippets">
5
- <?php // Init the tabs div ?>
6
- <div id="post-snippets-tabs">
7
 
8
- <?php
9
 
10
- if ( empty($snippets)) {
11
- echo sprintf(__('No snippets found, to create them go to &nbsp;&nbsp; %sPost Snippets &rarr;%s', 'post-snippets'), '<a href="'. admin_url( 'options-general.php?page=post-snippets') .'" class="button-primary">', '</a>');
12
- } else {
13
- ?>
14
- <ul>
15
- <?php
16
- // Create a tab for each available snippet
17
- foreach ( $snippets as $key => $snippet ) {
18
- ?>
19
- <li><a href="#ps-tabs-<?php echo $key;
20
- ?>"><?php echo $snippet['title'];
21
- ?></a></li>
22
- <?php
23
- }
24
- ?>
25
- </ul>
26
- <?php
27
- }
 
 
 
28
 
29
- // Create a panel with form fields for each available snippet
30
- foreach ($snippets as $key => $snippet) {
31
- ?>
32
- <div id="ps-tabs-<?php echo $key;
33
- ?>">
34
- <?php
35
- // Print a snippet description is available
36
- if (isset($snippet['description'])) {
37
- ?>
38
- <p class="howto"><?php echo $snippet['description'];
39
- ?></p>
40
- <?php
 
 
41
 
42
- }
43
 
44
- // Get all variables defined for the snippet and output them as
45
- // input fields
46
- $var_arr = explode(',', $snippet['vars']);
47
- if (!empty($var_arr[0])) {
48
- foreach ($var_arr as $key_2 => $var) {
49
- // Default value exists?
50
- $def_pos = strpos($var, '=');
51
- if ($def_pos !== false) {
52
- $split = explode('=', $var);
53
- $var = $split[0];
54
- $def = $split[1];
55
- } else {
56
- $def = '';
57
- }
58
- ?>
59
- <label for="var_<?php echo $key.'_'.$key_2;
60
- ?>"><?php echo $var;
61
- ?>:</label>
62
- <input type="text" id="var_<?php echo $key.'_'.$key_2;
63
- ?>" name="var_<?php echo $key.'_'.$key_2;
64
- ?>" value="<?php echo $def;
65
- ?>" style="width: 190px" />
66
- <br/>
67
- <?php
 
 
68
 
69
- }
70
- } else {
71
- // If no variables and no description available, output a text
72
- // to inform the user that it's an insert snippet only.
73
- if (empty($snippet['description'])) {
74
- ?>
75
- <p class="howto"><?php _e('This snippet is insert only, no variables defined.', 'post-snippets');
76
- ?></p>
77
- <?php
 
 
 
78
 
79
- }
80
- }
81
- ?>
82
- </div><!-- #ps-tabs-<?php echo $key;
83
- ?> -->
84
- <?php
 
 
 
85
 
86
- }
87
- // Close the tabs and dialog divs ?>
88
- </div><!-- #post-snippets-tabs -->
89
- </div><!-- #post-snippets-dialog -->
 
90
  </div><!-- .hidden -->
91
  <!-- END: Post Snippets UI Dialog -->
1
  <!-- START: Post Snippets UI Dialog -->
2
  <?php // Setup the dialog divs ?>
3
  <div class="hidden">
4
+ <div id="post-snippets-dialog" title="Post Snippets">
5
+ <?php // Init the tabs div ?>
6
+ <div id="post-snippets-tabs">
7
 
8
+ <?php
9
 
10
+ if ( empty( $snippets ) ) {
11
+ echo sprintf( esc_html__( 'No snippets found, to create them go to &nbsp;&nbsp; %1$sPost Snippets &rarr;%2$s', 'post-snippets' ), '<a href="' . esc_url( admin_url( 'options-general.php?page=post-snippets' ) ) . '" class="button-primary">', '</a>' );
12
+ } else {
13
+ ?>
14
+ <ul>
15
+ <?php
16
+ // Create a tab for each available snippet
17
+ foreach ( $snippets as $key => $snippet ) {
18
+ ?>
19
+ <li><a href="#ps-tabs-<?php echo esc_attr( $key ); ?>">
20
+ <?php
21
+ echo esc_html( $snippet['title'] );
22
+ ?>
23
+ </a>
24
+ </li>
25
+ <?php
26
+ }
27
+ ?>
28
+ </ul>
29
+ <?php
30
+ }
31
 
32
+ // Create a panel with form fields for each available snippet
33
+ foreach ( $snippets as $key => $snippet ) {
34
+ ?>
35
+ <div id="ps-tabs-<?php echo esc_attr( $key ); ?>">
36
+ <?php
37
+ // Print a snippet description is available
38
+ if ( isset( $snippet['description'] ) ) {
39
+ ?>
40
+ <p class="howto">
41
+ <?php
42
+ echo esc_html( $snippet['description'] );
43
+ ?>
44
+ </p>
45
+ <?php
46
 
47
+ }
48
 
49
+ // Get all variables defined for the snippet and output them as
50
+ // input fields
51
+ $var_arr = explode( ',', $snippet['vars'] );
52
+ if ( ! empty( $var_arr[0] ) ) {
53
+ foreach ( $var_arr as $key_2 => $var ) {
54
+ // Default value exists?
55
+ $def_pos = strpos( $var, '=' );
56
+ if ( $def_pos !== false ) {
57
+ $split = explode( '=', $var );
58
+ $var = $split[0];
59
+ $def = $split[1];
60
+ } else {
61
+ $def = '';
62
+ }
63
+ ?>
64
+ <label for="var_<?php echo esc_attr( $key ) . '_' . esc_attr( $key_2 );?>">
65
+ <?php
66
+ echo esc_html( $var );
67
+ ?>:
68
+ </label>
69
+ <input type="text" id="var_<?php echo esc_attr( $key ) . '_' . esc_attr( $key_2 ); ?>"
70
+ name="var_<?php echo esc_attr( $key ) . '_' . esc_attr( $key_2 );?>"
71
+ value="<?php echo esc_attr( $def ); ?>"
72
+ style="width: 190px" />
73
+ <br/>
74
+ <?php
75
 
76
+ }
77
+ } else {
78
+ // If no variables and no description available, output a text
79
+ // to inform the user that it's an insert snippet only.
80
+ if ( empty( $snippet['description'] ) ) {
81
+ ?>
82
+ <p class="howto">
83
+ <?php
84
+ esc_html_e( 'This snippet is insert only, no variables defined.', 'post-snippets' );
85
+ ?>
86
+ </p>
87
+ <?php
88
 
89
+ }
90
+ }
91
+ ?>
92
+ </div><!-- #ps-tabs-
93
+ <?php
94
+ echo esc_html( $key );
95
+ ?>
96
+ -->
97
+ <?php
98
 
99
+ }
100
+ // Close the tabs and dialog divs
101
+ ?>
102
+ </div><!-- #post-snippets-tabs -->
103
+ </div><!-- #post-snippets-dialog -->
104
  </div><!-- .hidden -->
105
  <!-- END: Post Snippets UI Dialog -->
views/jquery_ui_dialog_head.php CHANGED
@@ -1,110 +1,122 @@
1
 
2
  <!-- START: Post Snippets jQuery UI and related functions -->
3
  <script type='text/javascript'>
4
- <?php
5
- foreach ($snippetStack as $snippetVarString) {
6
- echo $snippetVarString;
7
- } ?>
8
 
9
- jQuery(document).ready(function($){
10
- <?php
11
- # Create js variables for all form fields
12
- foreach ($snippets as $key => $snippet) {
13
- $var_arr = explode(",", $snippet['vars']);
14
- if (!empty($var_arr[0])) {
15
- foreach ($var_arr as $key_2 => $var) {
16
- $varname = "var_" . $key . "_" . $key_2;
17
- echo "var {$varname} = $( \"#{$varname}\" );\n";
18
- }
19
- }
20
- }
21
- ?>
22
- // We do the check to see if post snippets dialog is in the footer.
23
- // Some plugins, like 'download monitor' uses WordPress admin bootstrap and
24
- // then bring in admin_head but not admin_footer. So to allow other plugins
25
- // to do that 'hack', we bail out in thoise cases.
26
- if ($("#post-snippets-tabs").length>0) {
27
 
28
- if($.isFunction($().tabs)){ // Ensure the tabs function is available
29
- var tabs = $("#post-snippets-tabs").tabs();
30
- }
31
 
32
- $(function() {
33
 
34
- if($.isFunction($().dialog)){ // Ensure the dialog function is available
35
 
36
- $("#post-snippets-dialog").dialog({
37
- autoOpen: false,
38
- modal: true,
39
- dialogClass: 'wp-dialog',
40
- buttons: {
41
- Cancel: function() {
42
- $(this).dialog("close");
43
- },
44
- "Insert": function() {
45
- $(this).dialog("close");
46
- <?php
47
- global $wp_version;
48
- if (version_compare($wp_version, '3.5', '<')) {
49
- ?>
50
- var selected = tabs.tabs('option', 'selected');
51
- <?php
52
 
53
- } else {
54
- ?>
55
- var selected = tabs.tabs('option', 'active');
56
- <?php
57
 
58
- }
59
 
60
- foreach ($snippets as $key => $snippet) {
61
- ?>
62
- if (selected == <?php echo $key;
63
- ?>) {
64
- insert_snippet = postsnippet_<?php echo $key;
65
- ?>;
66
- <?php
67
- $var_arr = explode(",", $snippet['vars']);
68
- if (!empty($var_arr[0])) {
69
- foreach ($var_arr as $key_2 => $var) {
70
- $varname = "var_" . $key . "_" . $key_2;
71
- ?>
72
- insert_snippet = insert_snippet.replace(/\{<?php echo $methods->stripDefaultVal($var);
73
- ?>\}/g, <?php echo $varname;
74
- ?>.val());
75
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
- }
78
- }
79
- ?>
80
- }
81
 
82
- <?php
83
 
84
- }
85
- ?>
86
 
87
- // Decide what method to use to insert the snippet depending
88
- // from what editor the window was opened from
89
- if (post_snippets_caller == 'html') {
90
- // HTML editor in WordPress 3.3 and greater
91
- QTags.insertContent(insert_snippet);
92
- } else {
93
- // Visual Editor
94
- post_snippets_canvas.execCommand('mceInsertContent', false, insert_snippet);
95
- }
96
- }
97
- },
98
- width: 500,
99
- });
100
- }
101
- });
102
- }
103
- });
104
 
105
- // Global variables to keep track on the canvas instance and from what editor
106
- // that opened the Post Snippets popup.
107
- var post_snippets_canvas;
108
- var post_snippets_caller = '';
109
  </script>
110
  <!-- END: Post Snippets jQuery UI and related functions -->
1
 
2
  <!-- START: Post Snippets jQuery UI and related functions -->
3
  <script type='text/javascript'>
4
+ <?php
5
+ foreach ( $snippetStack as $snippetVarString ) {
6
+ echo html_entity_decode( esc_html( $snippetVarString ), ENT_QUOTES );
7
+ } ?>
8
 
9
+ jQuery(document).ready(function($){
10
+ <?php
11
+ // Create js variables for all form fields
12
+ foreach ( $snippets as $key => $snippet ) {
13
+ $var_arr = explode( ',', $snippet['vars'] );
14
+ if ( ! empty( $var_arr[0] ) ) {
15
+ foreach ( $var_arr as $key_2 => $var ) {
16
+ $varname = 'var_' . $key . '_' . $key_2;
17
+ echo 'var ' . esc_js( $varname ) . ' = $( "#' . esc_js( $varname ) . "\" );\n";
18
+ }
19
+ }
20
+ }
21
+ ?>
22
+ // We do the check to see if post snippets dialog is in the footer.
23
+ // Some plugins, like 'download monitor' uses WordPress admin bootstrap and
24
+ // then bring in admin_head but not admin_footer. So to allow other plugins
25
+ // to do that 'hack', we bail out in thoise cases.
26
+ if ($("#post-snippets-tabs").length>0) {
27
 
28
+ if($.isFunction($().tabs)){ // Ensure the tabs function is available
29
+ var tabs = $("#post-snippets-tabs").tabs();
30
+ }
31
 
32
+ $(function() {
33
 
34
+ if($.isFunction($().dialog)){ // Ensure the dialog function is available
35
 
36
+ $("#post-snippets-dialog").dialog({
37
+ autoOpen: false,
38
+ modal: true,
39
+ dialogClass: 'wp-dialog',
40
+ buttons: {
41
+ Cancel: function() {
42
+ $(this).dialog("close");
43
+ },
44
+ "Insert": function() {
45
+ $(this).dialog("close");
46
+ <?php
47
+ global $wp_version;
48
+ if ( version_compare( $wp_version, '3.5', '<' ) ) {
49
+ ?>
50
+ var selected = tabs.tabs('option', 'selected');
51
+ <?php
52
 
53
+ } else {
54
+ ?>
55
+ var selected = tabs.tabs('option', 'active');
56
+ <?php
57
 
58
+ }
59
 
60
+ foreach ( $snippets as $key => $snippet ) {
61
+ ?>
62
+ if (selected ==
63
+ <?php
64
+ echo esc_js( $key );
65
+ ?>
66
+ ) {
67
+ insert_snippet = postsnippet_
68
+ <?php
69
+ echo esc_js( $key );
70
+ ?>
71
+ ;
72
+ <?php
73
+ $var_arr = explode( ',', $snippet['vars'] );
74
+ if ( ! empty( $var_arr[0] ) ) {
75
+ foreach ( $var_arr as $key_2 => $var ) {
76
+ $varname = 'var_' . $key . '_' . $key_2;
77
+ ?>
78
+ insert_snippet = insert_snippet.replace(/\{
79
+ <?php
80
+ echo esc_js( $methods->stripDefaultVal( $var ) );
81
+ ?>
82
+ \}/g,
83
+ <?php
84
+ echo esc_js( $varname );
85
+ ?>
86
+ .val());
87
+ <?php
88
 
89
+ }
90
+ }
91
+ ?>
92
+ }
93
 
94
+ <?php
95
 
96
+ }
97
+ ?>
98
 
99
+ // Decide what method to use to insert the snippet depending
100
+ // from what editor the window was opened from
101
+ if (post_snippets_caller == 'html') {
102
+ // HTML editor in WordPress 3.3 and greater
103
+ QTags.insertContent(insert_snippet);
104
+ } else {
105
+ // Visual Editor
106
+ post_snippets_canvas.execCommand('mceInsertContent', false, insert_snippet);
107
+ }
108
+ }
109
+ },
110
+ width: 500,
111
+ });
112
+ }
113
+ });
114
+ }
115
+ });
116
 
117
+ // Global variables to keep track on the canvas instance and from what editor
118
+ // that opened the Post Snippets popup.
119
+ var post_snippets_canvas;
120
+ var post_snippets_caller = '';
121
  </script>
122
  <!-- END: Post Snippets jQuery UI and related functions -->