Version Description
Download this release
Release Info
Developer | artstorm |
Plugin | Post Snippets |
Version | 1.8 |
Comparing to | |
See all releases |
Code changes from version 1.7.3 to 1.8
- post-snippets.php +180 -39
- readme.txt +14 -3
post-snippets.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Post Snippets
|
4 |
Plugin URI: http://wpstorm.net/wordpress-plugins/post-snippets/
|
5 |
Description: Stores snippets of HTML code or reoccurring text that you often use in your posts. You can use predefined variables to replace parts of the snippet on insert. All snippets are available in the post editor with a TinyMCE button or Quicktags.
|
6 |
-
Version: 1.
|
7 |
Author: Johan Steen
|
8 |
Author URI: http://wpstorm.net/
|
9 |
Text Domain: post-snippets
|
@@ -29,11 +29,10 @@ class post_snippets {
|
|
29 |
var $plugin_options = "post_snippets_options";
|
30 |
|
31 |
/**
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
function post_snippets()
|
36 |
-
{
|
37 |
// define URL
|
38 |
define('post_snippets_ABSPATH', WP_PLUGIN_DIR.'/'.plugin_basename( dirname(__FILE__) ).'/' );
|
39 |
define('post_snippets_URLPATH', WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__) ).'/' );
|
@@ -52,10 +51,10 @@ class post_snippets {
|
|
52 |
}
|
53 |
|
54 |
/**
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
function init_hooks() {
|
60 |
# Settings link on plugins list
|
61 |
add_filter( 'plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
|
@@ -76,10 +75,10 @@ class post_snippets {
|
|
76 |
|
77 |
|
78 |
/**
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
function plugin_action_links( $links, $file ) {
|
84 |
if ( $file == plugin_basename( dirname(__FILE__).'/post-snippets.php' ) ) {
|
85 |
$links[] = '<a href="options-general.php?page=post-snippets/post-snippets.php">'.__('Settings', 'post-snippets').'</a>';
|
@@ -88,10 +87,10 @@ class post_snippets {
|
|
88 |
}
|
89 |
|
90 |
/**
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
function version_warning() {
|
96 |
echo '<div class="updated fade"><p><strong>'.__('Post Snippets requires WordPress version 3.0 or higher.', 'post-snippets').'</strong></p></div>';
|
97 |
}
|
@@ -320,9 +319,9 @@ function edOpenPostSnippets(myField) {
|
|
320 |
|
321 |
|
322 |
/**
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
function create_shortcodes() {
|
327 |
$snippets = get_option($this->plugin_options);
|
328 |
if (!empty($snippets)) {
|
@@ -349,7 +348,7 @@ function edOpenPostSnippets(myField) {
|
|
349 |
$snippet = str_replace("{".$key."}", $val, $snippet);
|
350 |
}
|
351 |
|
352 |
-
return stripslashes($snippet);') );
|
353 |
}
|
354 |
}
|
355 |
}
|
@@ -357,9 +356,9 @@ function edOpenPostSnippets(myField) {
|
|
357 |
|
358 |
|
359 |
/**
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
function wp_admin() {
|
364 |
add_action( 'contextual_help', array(&$this,'add_help_text'), 10, 3 );
|
365 |
add_options_page( 'Post Snippets Options', 'Post Snippets', 'administrator', __FILE__, array(&$this, 'options_page') );
|
@@ -420,6 +419,7 @@ function edOpenPostSnippets(myField) {
|
|
420 |
'description' => "",
|
421 |
'shortcode' => false,
|
422 |
'quicktag' => false,
|
|
|
423 |
'snippet' => ""));
|
424 |
update_option($this->plugin_options, $snippets);
|
425 |
$this->admin_message( __( 'A snippet named Untitled has been added.', 'post-snippets' ) );
|
@@ -432,9 +432,9 @@ function edOpenPostSnippets(myField) {
|
|
432 |
for ($i=0; $i < count($snippets); $i++) {
|
433 |
$snippets[$i]['title'] = trim($_POST[$i.'_title']);
|
434 |
$snippets[$i]['vars'] = str_replace(" ", "", trim($_POST[$i.'_vars']) );
|
435 |
-
$snippets[$i]['description'] = esc_html( $_POST[$i.'_description'] );
|
436 |
$snippets[$i]['shortcode'] = isset($_POST[$i.'_shortcode']) ? true : false;
|
437 |
$snippets[$i]['quicktag'] = isset($_POST[$i.'_quicktag']) ? true : false;
|
|
|
438 |
/* Check if the plugin runs on PHP below version 5.1.0
|
439 |
Because of a bug in WP 2.7.x in includes/compat.php the htmlspecialchars_decode
|
440 |
don't revert back to a PHP 4.x compatible version. So this is a workaround to make
|
@@ -443,8 +443,10 @@ function edOpenPostSnippets(myField) {
|
|
443 |
*/
|
444 |
if (version_compare(PHP_VERSION, '5.1.0', '<')) {
|
445 |
$snippets[$i]['snippet'] = htmlspecialchars_decode( trim(stripslashes($_POST[$i.'_snippet'])), ENT_NOQUOTES);
|
|
|
446 |
} else {
|
447 |
$snippets[$i]['snippet'] = wp_specialchars_decode( trim(stripslashes($_POST[$i.'_snippet'])), ENT_NOQUOTES);
|
|
|
448 |
}
|
449 |
}
|
450 |
update_option($this->plugin_options, $snippets);
|
@@ -467,6 +469,9 @@ function edOpenPostSnippets(myField) {
|
|
467 |
$this->admin_message( __( 'Selected snippets have been deleted.', 'post-snippets' ) );
|
468 |
}
|
469 |
}
|
|
|
|
|
|
|
470 |
?>
|
471 |
<div class=wrap>
|
472 |
<h2>Post Snippets</h2>
|
@@ -490,9 +495,6 @@ function edOpenPostSnippets(myField) {
|
|
490 |
<th scope="col" style="width: 180px;"><?php _e( 'Title', 'post-snippets' ) ?></th>
|
491 |
<th scope="col" style="width: 180px;"><?php _e( 'Variables', 'post-snippets' ) ?></th>
|
492 |
<th scope="col"><?php _e( 'Snippet', 'post-snippets' ) ?></th>
|
493 |
-
<th scope="col"><?php _e( 'Description', 'post-snippets' ) ?></th>
|
494 |
-
<th scope="col" style="width: 20px;"><?php _e( 'SC', 'post-snippets' ) ?></th>
|
495 |
-
<th scope="col" style="width: 20px;"><?php _e( 'QT', 'post-snippets' ) ?></th>
|
496 |
</tr>
|
497 |
</thead>
|
498 |
|
@@ -502,9 +504,6 @@ function edOpenPostSnippets(myField) {
|
|
502 |
<th scope="col"><?php _e( 'Title', 'post-snippets' ) ?></th>
|
503 |
<th scope="col"><?php _e( 'Variables', 'post-snippets' ) ?></th>
|
504 |
<th scope="col"><?php _e( 'Snippet', 'post-snippets' ) ?></th>
|
505 |
-
<th scope="col"><?php _e( 'Description', 'post-snippets' ) ?></th>
|
506 |
-
<th scope="col"><?php _e( 'SC', 'post-snippets' ) ?></th>
|
507 |
-
<th scope="col"><?php _e( 'QT', 'post-snippets' ) ?></th>
|
508 |
</tr>
|
509 |
</tfoot>
|
510 |
|
@@ -515,12 +514,20 @@ function edOpenPostSnippets(myField) {
|
|
515 |
for ($i=0; $i < count($snippets); $i++) { ?>
|
516 |
<tr class='recent'>
|
517 |
<th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='<?php echo $i; ?>' /></th>
|
518 |
-
<td class='row-title'
|
519 |
-
<
|
520 |
-
|
521 |
-
<td class='
|
522 |
-
<
|
523 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
</tr>
|
525 |
<?php
|
526 |
}
|
@@ -532,10 +539,144 @@ function edOpenPostSnippets(myField) {
|
|
532 |
<input type="submit" name="update-post-snippets" value="<?php _e( 'Update Snippets', 'post-snippets' ) ?>" class="button-primary" /></div>
|
533 |
</form>
|
534 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
535 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
536 |
}
|
537 |
-
}
|
538 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
539 |
add_action( 'plugins_loaded', create_function( '', 'global $post_snippets; $post_snippets = new post_snippets();' ) );
|
540 |
|
541 |
|
3 |
Plugin Name: Post Snippets
|
4 |
Plugin URI: http://wpstorm.net/wordpress-plugins/post-snippets/
|
5 |
Description: Stores snippets of HTML code or reoccurring text that you often use in your posts. You can use predefined variables to replace parts of the snippet on insert. All snippets are available in the post editor with a TinyMCE button or Quicktags.
|
6 |
+
Version: 1.8
|
7 |
Author: Johan Steen
|
8 |
Author URI: http://wpstorm.net/
|
9 |
Text Domain: post-snippets
|
29 |
var $plugin_options = "post_snippets_options";
|
30 |
|
31 |
/**
|
32 |
+
* Constructor
|
33 |
+
*
|
34 |
+
*/
|
35 |
+
function post_snippets() {
|
|
|
36 |
// define URL
|
37 |
define('post_snippets_ABSPATH', WP_PLUGIN_DIR.'/'.plugin_basename( dirname(__FILE__) ).'/' );
|
38 |
define('post_snippets_URLPATH', WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__) ).'/' );
|
51 |
}
|
52 |
|
53 |
/**
|
54 |
+
* Initializes the hooks for the plugin
|
55 |
+
*
|
56 |
+
* @returns Nothing
|
57 |
+
*/
|
58 |
function init_hooks() {
|
59 |
# Settings link on plugins list
|
60 |
add_filter( 'plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
|
75 |
|
76 |
|
77 |
/**
|
78 |
+
* Quick link to the Post Snippets Settings page from the Plugins page.
|
79 |
+
*
|
80 |
+
* @returns Array with all the plugin's action links
|
81 |
+
*/
|
82 |
function plugin_action_links( $links, $file ) {
|
83 |
if ( $file == plugin_basename( dirname(__FILE__).'/post-snippets.php' ) ) {
|
84 |
$links[] = '<a href="options-general.php?page=post-snippets/post-snippets.php">'.__('Settings', 'post-snippets').'</a>';
|
87 |
}
|
88 |
|
89 |
/**
|
90 |
+
* Displays a warning when installed in an old Wordpress Version
|
91 |
+
*
|
92 |
+
* @returns Nothing
|
93 |
+
*/
|
94 |
function version_warning() {
|
95 |
echo '<div class="updated fade"><p><strong>'.__('Post Snippets requires WordPress version 3.0 or higher.', 'post-snippets').'</strong></p></div>';
|
96 |
}
|
319 |
|
320 |
|
321 |
/**
|
322 |
+
* Create the functions for shortcodes dynamically and register them
|
323 |
+
*
|
324 |
+
*/
|
325 |
function create_shortcodes() {
|
326 |
$snippets = get_option($this->plugin_options);
|
327 |
if (!empty($snippets)) {
|
348 |
$snippet = str_replace("{".$key."}", $val, $snippet);
|
349 |
}
|
350 |
|
351 |
+
return do_shortcode(stripslashes($snippet));') );
|
352 |
}
|
353 |
}
|
354 |
}
|
356 |
|
357 |
|
358 |
/**
|
359 |
+
* The Admin Page and all it's functions
|
360 |
+
*
|
361 |
+
*/
|
362 |
function wp_admin() {
|
363 |
add_action( 'contextual_help', array(&$this,'add_help_text'), 10, 3 );
|
364 |
add_options_page( 'Post Snippets Options', 'Post Snippets', 'administrator', __FILE__, array(&$this, 'options_page') );
|
419 |
'description' => "",
|
420 |
'shortcode' => false,
|
421 |
'quicktag' => false,
|
422 |
+
'php' => false,
|
423 |
'snippet' => ""));
|
424 |
update_option($this->plugin_options, $snippets);
|
425 |
$this->admin_message( __( 'A snippet named Untitled has been added.', 'post-snippets' ) );
|
432 |
for ($i=0; $i < count($snippets); $i++) {
|
433 |
$snippets[$i]['title'] = trim($_POST[$i.'_title']);
|
434 |
$snippets[$i]['vars'] = str_replace(" ", "", trim($_POST[$i.'_vars']) );
|
|
|
435 |
$snippets[$i]['shortcode'] = isset($_POST[$i.'_shortcode']) ? true : false;
|
436 |
$snippets[$i]['quicktag'] = isset($_POST[$i.'_quicktag']) ? true : false;
|
437 |
+
$snippets[$i]['php'] = isset($_POST[$i.'_php']) ? true : false;
|
438 |
/* Check if the plugin runs on PHP below version 5.1.0
|
439 |
Because of a bug in WP 2.7.x in includes/compat.php the htmlspecialchars_decode
|
440 |
don't revert back to a PHP 4.x compatible version. So this is a workaround to make
|
443 |
*/
|
444 |
if (version_compare(PHP_VERSION, '5.1.0', '<')) {
|
445 |
$snippets[$i]['snippet'] = htmlspecialchars_decode( trim(stripslashes($_POST[$i.'_snippet'])), ENT_NOQUOTES);
|
446 |
+
$snippets[$i]['description'] = htmlspecialchars_decode( trim(stripslashes($_POST[$i.'_description'])), ENT_NOQUOTES);
|
447 |
} else {
|
448 |
$snippets[$i]['snippet'] = wp_specialchars_decode( trim(stripslashes($_POST[$i.'_snippet'])), ENT_NOQUOTES);
|
449 |
+
$snippets[$i]['description'] = wp_specialchars_decode( trim(stripslashes($_POST[$i.'_description'])), ENT_NOQUOTES);
|
450 |
}
|
451 |
}
|
452 |
update_option($this->plugin_options, $snippets);
|
469 |
$this->admin_message( __( 'Selected snippets have been deleted.', 'post-snippets' ) );
|
470 |
}
|
471 |
}
|
472 |
+
|
473 |
+
// Handle import of snippets (Run before the option page is outputted, in case any snippets have been imported, so they are displayed).
|
474 |
+
$import = $this->import_snippets();
|
475 |
?>
|
476 |
<div class=wrap>
|
477 |
<h2>Post Snippets</h2>
|
495 |
<th scope="col" style="width: 180px;"><?php _e( 'Title', 'post-snippets' ) ?></th>
|
496 |
<th scope="col" style="width: 180px;"><?php _e( 'Variables', 'post-snippets' ) ?></th>
|
497 |
<th scope="col"><?php _e( 'Snippet', 'post-snippets' ) ?></th>
|
|
|
|
|
|
|
498 |
</tr>
|
499 |
</thead>
|
500 |
|
504 |
<th scope="col"><?php _e( 'Title', 'post-snippets' ) ?></th>
|
505 |
<th scope="col"><?php _e( 'Variables', 'post-snippets' ) ?></th>
|
506 |
<th scope="col"><?php _e( 'Snippet', 'post-snippets' ) ?></th>
|
|
|
|
|
|
|
507 |
</tr>
|
508 |
</tfoot>
|
509 |
|
514 |
for ($i=0; $i < count($snippets); $i++) { ?>
|
515 |
<tr class='recent'>
|
516 |
<th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='<?php echo $i; ?>' /></th>
|
517 |
+
<td class='row-title'>
|
518 |
+
<input type='text' name='<?php echo $i; ?>_title' value='<?php echo $snippets[$i]['title']; ?>' />
|
519 |
+
</td>
|
520 |
+
<td class='name'>
|
521 |
+
<input type='text' name='<?php echo $i; ?>_vars' value='<?php echo $snippets[$i]['vars']; ?>' /><br/>
|
522 |
+
<input type='checkbox' name='<?php echo $i; ?>_shortcode' value='true'<?php if ($snippets[$i]['shortcode'] == true) { echo " checked"; }?> /> <?php _e( 'Shortcode', 'post-snippets' ) ?><br/>
|
523 |
+
<input type='checkbox' name='<?php echo $i; ?>_quicktag' value='true'<?php if ($snippets[$i]['quicktag'] == true) { echo " checked"; }?> /> <?php _e( 'Quicktag', 'post-snippets' ) ?><br/>
|
524 |
+
<!-- <input type='checkbox' name='< ?php echo $i; ? >_php' value='true'< ?php if ($snippets[$i]['php'] == true) { echo " checked"; }? > /> < ?php _e( 'PHP Code', 'post-snippets' ) ? ><br/> -->
|
525 |
+
</td>
|
526 |
+
<td class='desc'>
|
527 |
+
<textarea name="<?php echo $i; ?>_snippet" class="large-text" style='width: 100%;' rows="5"><?php echo htmlspecialchars($snippets[$i]['snippet'], ENT_NOQUOTES); ?></textarea>
|
528 |
+
<?php _e( 'Description', 'post-snippets' ) ?>:
|
529 |
+
<input type='text' style='width: 100%;' name='<?php echo $i; ?>_description' value='<?php if (isset( $snippets[$i]['description'] ) ) echo esc_html($snippets[$i]['description']); ?>' /><br/>
|
530 |
+
</td>
|
531 |
</tr>
|
532 |
<?php
|
533 |
}
|
539 |
<input type="submit" name="update-post-snippets" value="<?php _e( 'Update Snippets', 'post-snippets' ) ?>" class="button-primary" /></div>
|
540 |
</form>
|
541 |
</div>
|
542 |
+
|
543 |
+
<h3><?php _e( 'Import/Export', 'post-snippets' ); ?></h3>
|
544 |
+
<strong><?php _e( 'Export', 'post-snippets' ); ?></strong><br/>
|
545 |
+
<form method="post">
|
546 |
+
<p><?php _e( 'Export your snippets for backup or to import them on another site.', 'post-snippets' ); ?></p>
|
547 |
+
<input type="submit" class="button" name="postsnippets_export" value="<?php _e( 'Export Snippets', 'post-snippets');?>"/>
|
548 |
+
</form>
|
549 |
<?php
|
550 |
+
$this->export_snippets();
|
551 |
+
echo $import;
|
552 |
+
}
|
553 |
+
|
554 |
+
|
555 |
+
/**
|
556 |
+
* Check if an export file shall be created, or if a download url should be pushed to the footer.
|
557 |
+
* Also checks for old export files laying around and deletes them (for security).
|
558 |
+
*
|
559 |
+
* @since Post Snippets 1.8
|
560 |
+
*
|
561 |
+
* @returns string URL to the exported snippets
|
562 |
+
*/
|
563 |
+
function export_snippets() {
|
564 |
+
if ( isset($_POST['postsnippets_export']) ) {
|
565 |
+
$url = $this->create_export_file();
|
566 |
+
if ($url) {
|
567 |
+
define('PSURL', $url);
|
568 |
+
function psnippets_footer() {
|
569 |
+
$export .= '<script type="text/javascript">
|
570 |
+
document.location = \''.PSURL.'\';
|
571 |
+
</script>';
|
572 |
+
echo $export;
|
573 |
+
}
|
574 |
+
add_action('admin_footer', 'psnippets_footer', 10000);
|
575 |
+
|
576 |
+
} else {
|
577 |
+
$export .= 'Error: '.$url;
|
578 |
+
}
|
579 |
+
} else {
|
580 |
+
// Check if there is any old export files to delete
|
581 |
+
$dir = wp_upload_dir();
|
582 |
+
$upload_dir = $dir['basedir'] . '/';
|
583 |
+
chdir($upload_dir);
|
584 |
+
if (file_exists ( './post-snippets-export.zip' ) )
|
585 |
+
unlink('./post-snippets-export.zip');
|
586 |
+
}
|
587 |
}
|
|
|
588 |
|
589 |
+
/**
|
590 |
+
* Create a zipped filed containing all Post Snippets, for export.
|
591 |
+
*
|
592 |
+
* @since Post Snippets 1.8
|
593 |
+
*
|
594 |
+
* @returns string URL to the exported snippets
|
595 |
+
*/
|
596 |
+
function create_export_file() {
|
597 |
+
$snippets = serialize(get_option($this->plugin_options));
|
598 |
+
$dir = wp_upload_dir();
|
599 |
+
$upload_dir = $dir['basedir'] . '/';
|
600 |
+
$upload_url = $dir['baseurl'] . '/';
|
601 |
+
|
602 |
+
// Open a file stream and write the serialized options to it.
|
603 |
+
if ( !$handle = fopen( $upload_dir.'post-snippets-export.cfg', 'w' ) )
|
604 |
+
die();
|
605 |
+
if ( !fwrite($handle, $snippets) )
|
606 |
+
die();
|
607 |
+
fclose($handle);
|
608 |
+
|
609 |
+
// Create a zip archive
|
610 |
+
require_once (ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
611 |
+
chdir($upload_dir);
|
612 |
+
$zip = new PclZip('./post-snippets-export.zip');
|
613 |
+
$zipped = $zip->create('./post-snippets-export.cfg');
|
614 |
+
|
615 |
+
// Delete the snippet file
|
616 |
+
unlink('./post-snippets-export.cfg');
|
617 |
+
|
618 |
+
if (!$zipped)
|
619 |
+
return false;
|
620 |
+
|
621 |
+
return $upload_url.'post-snippets-export.zip';
|
622 |
+
}
|
623 |
+
|
624 |
+
/**
|
625 |
+
* Handles uploading of post snippets archive and import the snippets.
|
626 |
+
*
|
627 |
+
* @uses wp_handle_upload() in wp-admin/includes/file.php
|
628 |
+
* @since Post Snippets 1.8
|
629 |
+
*
|
630 |
+
* @returns string HTML to handle the import
|
631 |
+
*/
|
632 |
+
function import_snippets() {
|
633 |
+
$import = '<br/><br/><strong>'.__( 'Import', 'post-snippets' ).'</strong><br/>';
|
634 |
+
if ( !isset($_FILES['postsnippets_import_file']) || empty($_FILES['postsnippets_import_file']) ) {
|
635 |
+
$import .= '<p>'.__( 'Import snippets from a post-snippets-export.zip file. Importing overwrites any existing snippets.', 'post-snippets' ).'</p>';
|
636 |
+
$import .= '<form method="post" enctype="multipart/form-data">';
|
637 |
+
$import .= '<input type="file" name="postsnippets_import_file"/>';
|
638 |
+
$import .= '<input type="hidden" name="action" value="wp_handle_upload"/>';
|
639 |
+
$import .= '<input type="submit" class="button" value="'.__( 'Import Snippets', 'post-snippets' ).'"/>';
|
640 |
+
$import .= '</form>';
|
641 |
+
} else {
|
642 |
+
$file = wp_handle_upload( $_FILES['postsnippets_import_file'] );
|
643 |
+
|
644 |
+
if ( isset( $file['file'] ) && !is_wp_error($file) ) {
|
645 |
+
require_once (ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
646 |
+
$zip = new PclZip( $file['file'] );
|
647 |
+
$dir = wp_upload_dir();
|
648 |
+
$upload_dir = $dir['basedir'] . '/';
|
649 |
+
chdir($upload_dir);
|
650 |
+
$unzipped = $zip->extract();
|
651 |
+
|
652 |
+
if ( $unzipped[0]['stored_filename'] == 'post-snippets-export.cfg' && $unzipped[0]['status'] == 'ok') {
|
653 |
+
// Delete the uploaded archive
|
654 |
+
unlink($file['file']);
|
655 |
+
|
656 |
+
$options = file_get_contents( $upload_dir.'post-snippets-export.cfg' ); // Returns false on failure, else the contents
|
657 |
+
if ($options)
|
658 |
+
update_option($this->plugin_options, unserialize($options));
|
659 |
+
|
660 |
+
// Delete the snippet file
|
661 |
+
unlink('./post-snippets-export.cfg');
|
662 |
+
|
663 |
+
$this->admin_message( __( 'Snippets have been updated.', 'post-snippets' ) );
|
664 |
+
|
665 |
+
$import .= '<p><strong>'.__( 'Snippets successfully imported.').'</strong></p>';
|
666 |
+
} else {
|
667 |
+
$import .= '<p><strong>'.__( 'Snippets could not be imported:').' '.__('Unzipping failed.').'</strong></p>';
|
668 |
+
}
|
669 |
+
} else {
|
670 |
+
if ( $file['error'] || is_wp_error( $file ) )
|
671 |
+
$import .= '<p><strong>'.__( 'Snippets could not be imported:').' '.$file['error'].'</strong></p>';
|
672 |
+
else
|
673 |
+
$import .= '<p><strong>'.__( 'Snippets could not be imported:').' '.__('Upload failed.').'</strong></p>';
|
674 |
+
}
|
675 |
+
}
|
676 |
+
return $import;
|
677 |
+
}
|
678 |
+
|
679 |
+
}
|
680 |
add_action( 'plugins_loaded', create_function( '', 'global $post_snippets; $post_snippets = new post_snippets();' ) );
|
681 |
|
682 |
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: artstorm
|
|
3 |
Donate link: http://wpstorm.net/wordpress-plugins/post-snippets/#donation
|
4 |
Tags: post, admin, snippet, html, custom, page, dynamic, editor, quicktag
|
5 |
Requires at least: 3.0
|
6 |
-
Tested up to: 3.1
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
Store snippets of HTML code or reoccurring text that you often use in your posts. Custom variables can be used.
|
10 |
|
@@ -45,6 +45,12 @@ See the [Changelog](http://wordpress.org/extend/plugins/post-snippets/changelog/
|
|
45 |
|
46 |
== Frequently Asked Questions ==
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
Please visit the [Support Forum](http://wordpress.org/tags/post-snippets?forum_id=10 "Use this for support and feature requests") for questions, answers, support and feature requests.
|
49 |
|
50 |
== Screenshots ==
|
@@ -55,9 +61,14 @@ Please visit the [Support Forum](http://wordpress.org/tags/post-snippets?forum_i
|
|
55 |
|
56 |
== Changelog ==
|
57 |
|
|
|
|
|
|
|
|
|
|
|
58 |
= Version 1.7.3 - 3 Mar 2011 =
|
59 |
* Added a text area field in the settings panel to enter an optional description for each snippet. This decription is displayed for the editor writing a post in the jQuery Post Snippet dialog.
|
60 |
-
* Fixed the syling of the quicktag jQuery window when the user have
|
61 |
* Fixed problem with line formatting in the new quicktag snippets.
|
62 |
* Fixed a problem with JavaScript snippets breaking the admin page.
|
63 |
* Various small bugfixes.
|
3 |
Donate link: http://wpstorm.net/wordpress-plugins/post-snippets/#donation
|
4 |
Tags: post, admin, snippet, html, custom, page, dynamic, editor, quicktag
|
5 |
Requires at least: 3.0
|
6 |
+
Tested up to: 3.1.3
|
7 |
+
Stable tag: 1.8
|
8 |
|
9 |
Store snippets of HTML code or reoccurring text that you often use in your posts. Custom variables can be used.
|
10 |
|
45 |
|
46 |
== Frequently Asked Questions ==
|
47 |
|
48 |
+
= Why do importing Snippets on a multi site install fail? =
|
49 |
+
|
50 |
+
Upload of zip files must be allowed, enable this in Sites Network Admin -> Settings -> Upload Settings -> Upload file types.
|
51 |
+
|
52 |
+
= Where can I get support? =
|
53 |
+
|
54 |
Please visit the [Support Forum](http://wordpress.org/tags/post-snippets?forum_id=10 "Use this for support and feature requests") for questions, answers, support and feature requests.
|
55 |
|
56 |
== Screenshots ==
|
61 |
|
62 |
== Changelog ==
|
63 |
|
64 |
+
= Version 1.8 - 30 May 2011 =
|
65 |
+
* Fixed an escaping problem with the snippet description.
|
66 |
+
* Added Import / Export functionality.
|
67 |
+
* Snippets used as shortcodes can now nest other shortcodes in them.
|
68 |
+
|
69 |
= Version 1.7.3 - 3 Mar 2011 =
|
70 |
* Added a text area field in the settings panel to enter an optional description for each snippet. This decription is displayed for the editor writing a post in the jQuery Post Snippet dialog.
|
71 |
+
* Fixed the syling of the quicktag jQuery window when the user have disabled the visual editor completely.
|
72 |
* Fixed problem with line formatting in the new quicktag snippets.
|
73 |
* Fixed a problem with JavaScript snippets breaking the admin page.
|
74 |
* Various small bugfixes.
|