Skip to content

Commit

Permalink
Allow hastag for autotags content
Browse files Browse the repository at this point in the history
  • Loading branch information
herewithme committed Nov 9, 2014
1 parent 9f8be97 commit 0a580f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
10 changes: 10 additions & 0 deletions inc/class.admin.autoterms.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public static function pageAutoTerms() {

// Full word ?
$taxo_options['only_full_word'] = ( isset($_POST['only_full_word']) && $_POST['only_full_word'] == '1' ) ? '1' : '0';

// Support hashtag format ?
$taxo_options['allow_hashtag_format'] = ( isset($_POST['allow_hashtag_format']) && $_POST['allow_hashtag_format'] == '1' ) ? '1' : '0';

$options[SimpleTags_Admin::$post_type][SimpleTags_Admin::$taxonomy] = $taxo_options;
update_option( STAGS_OPTIONS_NAME_AUTO, $options );
Expand Down Expand Up @@ -212,6 +215,13 @@ public static function pageAutoTerms() {
<label for="only_full_word"><?php _e('Autotag only a post when terms finded in the content are a the same name. (whole word only)', 'simpletags'); ?></label>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Suport Hashtag format ?', 'simpletags'); ?></th>
<td>
<input type="checkbox" id="allow_hashtag_format" name="allow_hashtag_format" value="1" <?php echo ( isset($taxo_options['allow_hashtag_format']) && $taxo_options['allow_hashtag_format'] == 1 ) ? 'checked="checked"' : ''; ?> />
<label for="allow_hashtag_format"><?php _e('When the whole word option is enabled, hashtag will not be autotag because of # prefix. This option allow to fixed this issue!', 'simpletags'); ?></label>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="auto_list"><?php _e('Keywords list', 'simpletags'); ?></label></th>
<td>
Expand Down
30 changes: 19 additions & 11 deletions inc/class.client.autoterms.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function auto_terms_post( $object, $taxonomy = 'post_tag', $option
if ( isset($object->post_excerpt) ) {
$content .= ' ' . $object->post_excerpt;
}

$content = trim(strip_tags($content));
if ( empty($content) ) {
return false;
Expand All @@ -97,10 +97,14 @@ public static function auto_terms_post( $object, $taxonomy = 'post_tag', $option
$term = trim($term);

// Whole word ?
if ( (int) $options['only_full_word'] == 1 ) {
if ( isset($options['only_full_word']) && (int) $options['only_full_word'] == 1 ) {
if ( preg_match("/\b".$term."\b/i", $content) ) {
$terms_to_add[] = $term;
}

if ( isset($options['allow_hashtag_format']) && (int) $options['allow_hashtag_format'] == 1 && stristr($content, '#'.$term) ) {
$terms_to_add[] = $term;
}
} elseif ( stristr($content, $term) ) {
$terms_to_add[] = $term;
}
Expand All @@ -124,15 +128,19 @@ public static function auto_terms_post( $object, $taxonomy = 'post_tag', $option
if ( !is_string($term) && empty($term) ) {
continue;
}

// Whole word ?
if ( (int) $options['only_full_word'] == 1 ) {
$term = ' '.$term.' '; // Add space before and after !
}

if ( stristr($content, $term) ) {
$terms_to_add[] = $term;
}

// Whole word ?
if ( isset($options['only_full_word']) && (int) $options['only_full_word'] == 1 ) {
if ( preg_match("/\b".$term."\b/i", $content) ) {
$terms_to_add[] = $term;
}

if ( isset($options['allow_hashtag_format']) && (int) $options['allow_hashtag_format'] == 1 && stristr($content, '#'.$term) ) {
$terms_to_add[] = $term;
}
} elseif ( stristr($content, $term) ) {
$terms_to_add[] = $term;
}
}

// Clean memory
Expand Down

0 comments on commit 0a580f8

Please sign in to comment.