Skip to content

Commit

Permalink
Completely revise the "Keep Markup" section FancyThemes#29
Browse files Browse the repository at this point in the history
  • Loading branch information
aprea committed May 22, 2014
1 parent e5e1830 commit ee3c176
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions asset/js/advanced-excerpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
}
});

$('#dont-remove-any-markup').change(function(event){
if( $(this).is(':checked') ){
$('input[name=allowed_tags_option]').change(function(event){
if ( 'dont_remove_any' == $(this).val() ){
$('#tags-table tr').not(':first-child').hide();
$('.tags-control').hide();
} else {
$('#tags-table tr').not(':first-child').show();
$('.tags-control').show();
$('.tags-control').show();
}
});

Expand Down
16 changes: 13 additions & 3 deletions class/advanced-excerpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class Advanced_Excerpt {
'ellipsis' => '…',
'read_more' => 'Read the rest',
'add_link' => 0,
'allowed_tags' => array( '_all' ),
'allowed_tags' => array(),
'the_excerpt' => 1,
'the_content' => 1,
'the_content_no_break' => 0,
'exclude_pages' => array(),
'allowed_tags_option' => 'dont_remove_any',
);

public $options_basic_tags; // Basic HTML tags (determines which tags are in the checklist by default)
Expand Down Expand Up @@ -118,6 +119,14 @@ function load_options() {
delete_option( $option_name );
}

// convert legacy option '_all' in the allowed_tags option to it's updated equivalent
if ( false !== ( $all_key = array_search( '_all', $this->options['allowed_tags'] ) ) ) {
unset( $this->options['allowed_tags'][$all_key] );
$this->options['allowed_tags_option'] = 'dont_remove_any';
} else {
$this->options['allowed_tags_option'] = 'remove_all_tags_except';
}

// filtering the_content() is disabled by default when migrating from version 4.1.1 of the plugin
$this->options['the_excerpt'] = 1;
$this->options['the_content'] = 0;
Expand Down Expand Up @@ -232,8 +241,8 @@ function filter( $text ) {
$allowed_tags = array_diff( $allowed_tags, $exclude_tags );
}

// Strip HTML if allow-all is not set
if ( !in_array( '_all', $allowed_tags ) ) {
// Strip HTML if $allowed_tags_option is set to 'remove_all_tags_except'
if ( 'remove_all_tags_except' === $allowed_tags_option ) {
if ( count( $allowed_tags ) > 0 ) {
$tag_string = '<' . implode( '><', $allowed_tags ) . '>';
} else {
Expand Down Expand Up @@ -338,6 +347,7 @@ function update_options() {
$this->options['read_more'] = isset( $_POST['read_more'] ) ? $_POST['read_more'] : $this->options['read_more'];
$this->options['allowed_tags'] = ( isset( $_POST['allowed_tags'] ) ) ? array_unique( (array) $_POST['allowed_tags'] ) : array();
$this->options['exclude_pages'] = ( isset( $_POST['exclude_pages'] ) ) ? array_unique( (array) $_POST['exclude_pages'] ) : array();
$this->options['allowed_tags_option'] = $_POST['allowed_tags_option'];

update_option( 'advanced_excerpt', $this->options );

Expand Down
23 changes: 15 additions & 8 deletions template/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,30 @@
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( "Keep Markup:", 'advanced-excerpt' ); ?></th>
<th scope="row">
<?php _e( "Strip Tags:", 'advanced-excerpt' ); ?>
</th>
<td>
<table id="tags-table">
<tr>
<td colspan="<?php echo $tag_cols; ?>">
<label for="dont-remove-any-markup">
<input name="allowed_tags[]" type="checkbox" id="dont-remove-any-markup" value="_all" <?php echo ( in_array( '_all', $allowed_tags ) ) ? 'checked="checked" ' : ''; ?> />
<?php _e( "Don't remove any markup", 'advanced-excerpt' ); ?>
</label>
<p>
<label for="dont-remove-any-tags">
<input name="allowed_tags_option" type="radio" id="dont-remove-any-tags" value="dont_remove_any" <?php echo ( 'dont_remove_any' == $allowed_tags_option ) ? 'checked="checked"' : ''; ?> />
<?php _e( "Don't remove any tags", 'advanced-excerpt' ); ?>
</label><br />
<label for="remove-all-tags-except">
<input name="allowed_tags_option" type="radio" id="remove-all-tags-except" value="remove_all_tags_except" <?php echo ( 'remove_all_tags_except' == $allowed_tags_option ) ? 'checked="checked"' : ''; ?> />
<?php _e( "Remove all tags except the following", 'advanced-excerpt' ); ?>
</label>
</p>
</td>
</tr>
<?php
$i = 0;
foreach ( $tag_list as $tag ) :
if ( $tag == '_all' ) continue;
if ( 0 == $i % $tag_cols ) : ?>
<tr<?php echo ( in_array( '_all', $allowed_tags ) ) ? ' style="display: none;"' : '' ?>>
<tr<?php echo ( 'dont_remove_any' == $allowed_tags_option ) ? ' style="display: none;"' : '' ?>>
<?php endif; $i++; ?>
<td>
<label for="<?php echo 'ae-' . $tag; ?>">
Expand All @@ -186,7 +193,7 @@
<?php endif; ?>
</table>

<div class="tags-control"<?php echo ( in_array( '_all', $allowed_tags ) ) ? ' style="display: none;"' : '' ?>>
<div class="tags-control"<?php echo ( 'dont_remove_any' == $allowed_tags_option ) ? ' style="display: none;"' : '' ?>>
<a href="" id="select-all"><?php _e( "Select all", 'advanced-excerpt' ); ?></a> / <a href="" id="select-none"><?php _e( "Select none", 'advanced-excerpt' ); ?></a><br />
<?php _e( "More tags", 'advanced-excerpt' ); ?>
<select name="more_tags" id="more-tags">
Expand Down

0 comments on commit ee3c176

Please sign in to comment.