Advanced Excerpt - Version 4.1

Version Description

  • Fix: Template function with custom options works again
  • Fix: Data before header bug (retro-fixed in 4.0)
  • Feature: Template function also works with array-style parameters
  • Removed multibyte support
  • Removed PHP 4 support (WP 3.2+ users should be fine, others should update)
  • Better code testing before release!
Download this release

Release Info

Developer basvd
Plugin Icon wp plugin Advanced Excerpt
Version 4.1
Comparing to
See all releases

Code changes from version 4.0 to 4.1

Files changed (2) hide show
  1. advanced-excerpt.php +179 -237
  2. readme.txt +33 -22
advanced-excerpt.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /*
3
  Plugin Name: Advanced Excerpt
4
- Plugin URI: http://sparepencil.com/code/advanced-excerpt/
5
  Description: Several improvements over WP's default excerpt. The size of the excerpt can be limited using character or word count, and HTML markup is not removed.
6
- Version: 4.0
7
  Author: Bas van Doren
8
- Author URI: http://sparepencil.com/
9
 
10
  Copyright 2007 Bas van Doren
11
 
@@ -27,19 +27,24 @@ if (!class_exists('AdvancedExcerpt')):
27
  class AdvancedExcerpt
28
  {
29
  // Plugin configuration
30
- var $name;
31
- var $text_domain;
32
- var $mb;
33
-
34
- var $default_options;
35
- var $custom_options;
36
-
37
- // Tricky variable
38
- var $skip_next_call;
39
-
40
- // Reference arrays
41
- // Basic HTML tags (determines which tags are in the checklist)
42
- var $options_basic_tags = array
 
 
 
 
 
43
  (
44
  'a', 'abbr', 'acronym', 'b', 'big',
45
  'blockquote', 'br', 'center', 'cite', 'code', 'dd', 'del', 'div', 'dl', 'dt',
@@ -48,9 +53,8 @@ if (!class_exists('AdvancedExcerpt')):
48
  'sup', 'table', 'td', 'th', 'tr', 'u', 'ul'
49
  );
50
 
51
- // HTML tags allowed in <body>
52
- // <style> is <head>-only, but usage is often non-standard, so it's included here
53
- var $options_body_tags = array(
54
  'a', 'abbr', 'acronym', 'address', 'applet',
55
  'area', 'b', 'bdo', 'big', 'blockquote', 'br', 'button', 'caption', 'center',
56
  'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir', 'div', 'dl',
@@ -62,36 +66,29 @@ if (!class_exists('AdvancedExcerpt')):
62
  'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'tr', 'tt', 'u', 'ul',
63
  'var'
64
  );
65
-
66
- // (not used) HTML tags which may have content that should not be considered actual text
67
- // TODO: Implement a way to remove tag + content if tag is not allowed (low priority)
68
- var $non_text_tags = array(
69
- 'applet', 'noframes', 'noscript', 'object', 'select', 'script', 'style'
70
- );
71
-
72
-
73
- function AdvancedExcerpt()
74
  {
75
- $this->name = strtolower(get_class($this));
76
- $this->text_domain = $this->name;
77
- $this->skip_next_call = false;
78
- $this->charset = get_bloginfo('charset');
79
-
 
 
 
 
 
 
80
  $this->load_options();
81
-
82
- // Carefully support multibyte languages
83
- if (extension_loaded('mbstring') && function_exists('mb_list_encodings'))
84
- $this->mb = in_array($this->charset, mb_list_encodings());
85
-
86
- load_plugin_textdomain($this->text_domain, PLUGINDIR . '/advanced-excerpt/');
87
-
88
- // __FILE__ doesn't seem to work
89
- $file = ABSPATH . PLUGINDIR . '/advanced-excerpt/advanced-excerpt.php';
90
- register_activation_hook($file, array(
91
  &$this,
92
  'install'
93
  ));
94
-
95
  //register_deactivation_hook($file, array(&$this, 'uninstall'));
96
 
97
  add_action('admin_menu', array(
@@ -100,162 +97,150 @@ if (!class_exists('AdvancedExcerpt')):
100
  ));
101
 
102
  // Replace the default filter (see /wp-includes/default-filters.php)
103
- remove_filter('get_the_excerpt', 'wp_trim_excerpt');
 
 
104
  add_filter('get_the_excerpt', array(
105
  &$this,
106
  'filter'
107
  ));
108
  }
109
 
110
- // Deprecated: php-4 support
111
- function __construct()
112
  {
113
- self::AdvancedExcerpt();
114
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
- function filter($text, $options = null)
117
- {
118
- // Merge options
119
- if (is_array($options))
120
- $r = array_merge($this->default_options, $options);
121
- else
122
- $r = $this->default_options;
123
 
124
- extract($r, EXTR_SKIP);
 
125
 
126
- // Only make the excerpt if it does not exist or 'No Custom Excerpt' is set to true
127
- if ('' == $text || $no_custom)
128
- {
129
- // Get the full content and filter it
130
- $text = get_the_content('');
131
- if (1 == $no_shortcode)
132
- $text = strip_shortcodes($text);
133
- $text = apply_filters('the_content', $text);
134
-
135
- // From the default wp_trim_excerpt():
136
- // Some kind of precaution against malformed CDATA in RSS feeds I suppose
137
- $text = str_replace(']]>', ']]&gt;', $text);
138
-
139
- // Strip HTML if allow-all is not set
140
- if (!in_array('_all', $allowed_tags))
141
- {
142
- if (count($allowed_tags) > 0)
143
- $tag_string = '<' . implode('><', $allowed_tags) . '>';
144
- else
145
- $tag_string = '';
146
- $text = strip_tags($text, $tag_string);
147
  }
148
-
149
- $tokens = array();
150
- $out = '';
151
- $w = 0;
152
- // Divide the string into tokens; HTML tags, or words, followed by any whitespace
153
- // (<[^>]+>|[^<>\s]+\s*)
154
- preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $text, $tokens);
155
- foreach($tokens[0] as $t)
156
- { // Parse each token
157
- if($w >= $length && !$finish_sentence)
158
- { // Limit reached
159
  break;
160
  }
161
- if($t[0] != '<')
162
- { // Token is not a tag
163
- if($w >= $length && $finish_sentence && preg_match('/[\?\.\!]\s*$/uS', $t) == 1)
164
- { // Limit reached, continue until ? . or ! occur at the end
165
- $out .= trim($t);
166
- break;
167
- }
168
- if(1 == $use_words)
169
- { // Count words
170
- $w++;
171
- }
172
- else
173
- { // Count/trim characters
174
- $chars = trim($t); // Remove surrounding space
175
- $c = $this->strlen($chars);
176
- if($c + $w > $length && !$finish_sentence)
177
- { // Token is too long
178
- $c = ($finish_word) ? $c : $length - $w; // Keep token to finish word
179
- $t = $this->substr($t, 0, $c);
180
- }
181
- $w += $c;
182
  }
 
183
  }
184
- // Append what's left of the token
185
- $out .= $t;
186
- }
187
-
188
- $text = trim(force_balance_tags($out));
189
-
190
- // New filter in WP2.9, seems unnecessary for now
191
- //$ellipsis = apply_filters('excerpt_more', $ellipsis);
192
-
193
- // Read more
194
- if ($add_link)
195
- {
196
- $ellipsis = $ellipsis . sprintf(' <a href="%s" class="read_more">%s</a>', get_permalink(), $read_more);
197
- }
198
-
199
- // Adding the ellipsis
200
- $pos = strpos($text, '</p>', max(0, strlen($text) - 7));
201
- if ($pos !== false)
202
- {
203
- // Stay inside the last paragraph (if it's in the last 6 characters)
204
- $text = substr_replace($text, $ellipsis, $pos, 0);
205
- }
206
- else
207
- {
208
- // If <p> is an allowed tag,
209
- // wrap the ellipsis for consistency with excerpt markup
210
- if (in_array('_all', $allowed_tags) || in_array('p', $allowed_tags))
211
- $ellipsis = '<p>' . $ellipsis . '</p>';
212
-
213
- $text = $text . $ellipsis;
214
  }
 
 
215
  }
216
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  return $text;
218
  }
219
 
220
- function install()
221
  {
222
- add_option($this->name . '_length', 40);
223
- add_option($this->name . '_use_words', 1);
224
- add_option($this->name . '_no_custom', 0);
225
- add_option($this->name . '_no_shortcode', 1);
226
- add_option($this->name . '_finish_word', 0);
227
- add_option($this->name . '_finish_sentence', 0);
228
- add_option($this->name . '_ellipsis', '&hellip;');
229
- add_option($this->name . '_read_more', 'Read the rest');
230
- add_option($this->name . '_add_link', 0);
231
- add_option($this->name . '_allowed_tags', $this->options_basic_tags);
232
-
233
- //$this->load_options();
234
  }
235
 
236
- function uninstall()
237
  {
238
  // Nothing to do (note: deactivation hook is also disabled)
239
  }
240
 
241
- function load_options()
242
  {
243
- $this->default_options = array(
244
- 'length' => get_option($this->name . '_length'),
245
- 'use_words' => get_option($this->name . '_use_words'),
246
- 'no_custom' => get_option($this->name . '_no_custom'),
247
- 'no_shortcode' => get_option($this->name . '_no_shortcode'),
248
- 'finish_word' => get_option($this->name . '_finish_word'),
249
- 'finish_sentence' => get_option($this->name . '_finish_sentence'),
250
- 'ellipsis' => get_option($this->name . '_ellipsis'),
251
- 'read_more' => get_option($this->name . '_read_more'),
252
- 'add_link' => get_option($this->name . '_add_link'),
253
- 'allowed_tags' => (array) get_option($this->name . '_allowed_tags')
254
- );
255
  }
256
 
257
-
258
- function update_options()
259
  {
260
  $length = (int) $_POST[$this->name . '_length'];
261
  $use_words = ('on' == $_POST[$this->name . '_use_words']) ? 1 : 0;
@@ -265,6 +250,7 @@ if (!class_exists('AdvancedExcerpt')):
265
  $finish_sentence = ('on' == $_POST[$this->name . '_finish_sentence']) ? 1 : 0;
266
  $add_link = ('on' == $_POST[$this->name . '_add_link']) ? 1 : 0;
267
 
 
268
  $ellipsis = (get_magic_quotes_gpc() == 1) ? stripslashes($_POST[$this->name . '_ellipsis']) : $_POST[$this->name . '_ellipsis'];
269
  $read_more = (get_magic_quotes_gpc() == 1) ? stripslashes($_POST[$this->name . '_read_more']) : $_POST[$this->name . '_read_more'];
270
 
@@ -287,7 +273,7 @@ if (!class_exists('AdvancedExcerpt')):
287
  <?php
288
  }
289
 
290
- function page_options()
291
  {
292
  if ('POST' == $_SERVER['REQUEST_METHOD'])
293
  {
@@ -297,12 +283,10 @@ if (!class_exists('AdvancedExcerpt')):
297
 
298
  extract($this->default_options, EXTR_SKIP);
299
 
300
- // HTML entities for textbox
301
  $ellipsis = htmlentities($ellipsis);
302
  $read_more = htmlentities($read_more);
303
 
304
- // Basic tags + enabled tags
305
- $tag_list = $this->set_union($this->options_basic_tags, $allowed_tags);
306
  sort($tag_list);
307
  $tag_cols = 5;
308
  ?>
@@ -439,7 +423,7 @@ if (!class_exists('AdvancedExcerpt')):
439
  More tags:
440
  <select name="<?php echo $this->name; ?>_more_tags" id="<?php echo $this->name; ?>_more_tags">
441
  <?php
442
- foreach ($this->options_body_tags as $tag):
443
  ?>
444
  <option value="<?php echo $tag; ?>"><?php echo $tag; ?></option>
445
  <?php
@@ -457,14 +441,14 @@ if (!class_exists('AdvancedExcerpt')):
457
  <?php
458
  }
459
 
460
- function page_script()
461
  {
462
  wp_enqueue_script($this->name . '_script', WP_PLUGIN_URL . '/advanced-excerpt/advanced-excerpt.js', array(
463
  'jquery'
464
  ));
465
  }
466
 
467
- function add_pages()
468
  {
469
  $options_page = add_options_page(__("Advanced Excerpt Options", $this->text_domain), __("Excerpt", $this->text_domain), 'manage_options', 'options-' . $this->name, array(
470
  &$this,
@@ -477,77 +461,35 @@ if (!class_exists('AdvancedExcerpt')):
477
  'page_script'
478
  ));
479
  }
480
-
481
- // Careful multibyte support (fallback to normal functions if not available)
482
-
483
- function substr($str, $start, $length = null)
484
- {
485
- $length = (is_null($length)) ? $this->strlen($str) : $length;
486
- if ($this->mb)
487
- return mb_substr($str, $start, $length, $this->charset);
488
- else
489
- return substr($str, $start, $length);
490
- }
491
-
492
- function strlen($str)
493
- {
494
- if ($this->mb)
495
- return mb_strlen($str, $this->charset);
496
- else
497
- return strlen($str);
498
- }
499
-
500
- // Some utility functions
501
-
502
- function set_complement($a, $b)
503
- {
504
- $c = array_diff($a, $b);
505
- return array_unique($c);
506
- }
507
-
508
- function set_union($a, $b)
509
- {
510
- $c = array_merge($a, $b);
511
- return array_unique($c);
512
- }
513
  }
514
-
515
- $advancedexcerpt = new AdvancedExcerpt();
516
 
517
  // Do not use outside the Loop!
518
  function the_advanced_excerpt($args = '', $get = true)
519
  {
520
- global $advancedexcerpt;
521
-
522
- $r = wp_parse_args($args);
523
-
524
- if (isset($r['ellipsis']))
525
- $r['ellipsis'] = urldecode($r['ellipsis']);
526
-
527
- // TODO: Switch to 'allowed_tags' (compatibility code)
528
- if (isset($r['allow_tags']))
529
  {
530
- $r['allowed_tags'] = $r['allow_tags'];
531
- unset($r['allow_tags']);
532
- }
533
 
534
- if (isset($r['allowed_tags']))
535
- $r['allowed_tags'] = preg_split('/[\s,]+/', $r['allow_tags']);
 
536
 
537
- if (isset($r['exclude_tags']))
538
- {
539
- $r['exclude_tags'] = preg_split('/[\s,]+/', $r['exclude_tags']);
540
- // {all_tags} - {exclude_tags}
541
- $r['allowed_tags'] = $advancedexcerpt->set_complement($advancedexcerpt->options_body_tags, $r['exclude_tags']);
542
- unset($r['exclude_tags']);
543
- }
544
 
545
- // Set custom options (discard after use)
546
- $advancedexcerpt->custom_options = $r;
 
 
 
 
 
 
547
  if ($get)
548
- echo get_the_excerpt();
549
  else
550
  the_excerpt();
551
- $advancedexcerpt->custom_options = null;
552
  }
553
  endif;
1
  <?php
2
  /*
3
  Plugin Name: Advanced Excerpt
4
+ Plugin URI: http://basvd.com/code/advanced-excerpt/
5
  Description: Several improvements over WP's default excerpt. The size of the excerpt can be limited using character or word count, and HTML markup is not removed.
6
+ Version: 4.1
7
  Author: Bas van Doren
8
+ Author URI: http://basvd.com/
9
 
10
  Copyright 2007 Bas van Doren
11
 
27
  class AdvancedExcerpt
28
  {
29
  // Plugin configuration
30
+ public $name;
31
+ public $text_domain;
32
+ public $options;
33
+ public $default_options = array(
34
+ 'length' => 40,
35
+ 'use_words' => 1,
36
+ 'no_custom' => 1,
37
+ 'no_shortcode' => 1,
38
+ 'finish_word' => 0,
39
+ 'finish_sentence' => 0,
40
+ 'ellipsis' => '&hellip;',
41
+ 'read_more' => 'Read the rest',
42
+ 'add_link' => 0,
43
+ 'allowed_tags' => array('_all')
44
+ );
45
+
46
+ // Basic HTML tags (determines which tags are in the checklist by default)
47
+ public static $options_basic_tags = array
48
  (
49
  'a', 'abbr', 'acronym', 'b', 'big',
50
  'blockquote', 'br', 'center', 'cite', 'code', 'dd', 'del', 'div', 'dl', 'dt',
53
  'sup', 'table', 'td', 'th', 'tr', 'u', 'ul'
54
  );
55
 
56
+ // Almost all HTML tags (extra options)
57
+ public static $options_all_tags = array(
 
58
  'a', 'abbr', 'acronym', 'address', 'applet',
59
  'area', 'b', 'bdo', 'big', 'blockquote', 'br', 'button', 'caption', 'center',
60
  'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir', 'div', 'dl',
66
  'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'tr', 'tt', 'u', 'ul',
67
  'var'
68
  );
69
+
70
+ // Singleton
71
+ private static $inst = null;
72
+ public static function Instance($new = false)
 
 
 
 
 
73
  {
74
+ if (self::$inst == null || $new)
75
+ {
76
+ self::$inst = new AdvancedExcerpt();
77
+ }
78
+ return self::$inst;
79
+ }
80
+
81
+ private function __construct()
82
+ {
83
+ $this->name = strtolower(get_class());
84
+ $this->text_domain = $this->name;
85
  $this->load_options();
86
+
87
+ load_plugin_textdomain($this->text_domain, false, dirname(plugin_basename(__FILE__)));
88
+ register_activation_hook(__FILE__, array(
 
 
 
 
 
 
 
89
  &$this,
90
  'install'
91
  ));
 
92
  //register_deactivation_hook($file, array(&$this, 'uninstall'));
93
 
94
  add_action('admin_menu', array(
97
  ));
98
 
99
  // Replace the default filter (see /wp-includes/default-filters.php)
100
+ //remove_filter('get_the_excerpt', 'wp_trim_excerpt');
101
+ // Replace everything
102
+ remove_all_filters('get_the_excerpt');
103
  add_filter('get_the_excerpt', array(
104
  &$this,
105
  'filter'
106
  ));
107
  }
108
 
109
+ public function filter($text)
 
110
  {
111
+ // Extract options (skip collisions)
112
+ if (is_array($this->options))
113
+ {
114
+ extract($this->options, EXTR_SKIP);
115
+ $this->options = null; // Reset
116
+ }
117
+ extract($this->default_options, EXTR_SKIP);
118
+
119
+ // Avoid custom excerpts
120
+ if (!empty($text) && !$no_custom)
121
+ return $text;
122
+
123
+ // Get the full content and filter it
124
+ $text = get_the_content('');
125
+ if (1 == $no_shortcode)
126
+ $text = strip_shortcodes($text);
127
+ $text = apply_filters('the_content', $text);
128
+
129
+ // From the default wp_trim_excerpt():
130
+ // Some kind of precaution against malformed CDATA in RSS feeds I suppose
131
+ $text = str_replace(']]>', ']]&gt;', $text);
132
+
133
+ // Determine allowed tags
134
+ if(!isset($allowed_tags))
135
+ $allowed_tags = self::$options_all_tags;
136
+
137
+ if(isset($exclude_tags))
138
+ $allowed_tags = array_diff($allowed_tags, $exclude_tags);
139
+
140
+ // Strip HTML if allow-all is not set
141
+ if (!in_array('_all', $allowed_tags))
142
+ {
143
+ if (count($allowed_tags) > 0)
144
+ $tag_string = '<' . implode('><', $allowed_tags) . '>';
145
+ else
146
+ $tag_string = '';
147
+ $text = strip_tags($text, $tag_string);
148
+ }
149
 
150
+ // Create the excerpt
151
+ $text = $this->text_excerpt($text, $length, $use_words, $finish_word, $finish_sentence);
 
 
 
 
 
152
 
153
+ // Add the ellipsis or link
154
+ $text = $this->text_add_more($text, $ellipsis, ($add_link) ? $read_more : false);
155
 
156
+ return $text;
157
+ }
158
+
159
+ public function text_excerpt($text, $length, $use_words, $finish_word, $finish_sentence)
160
+ {
161
+ $tokens = array();
162
+ $out = '';
163
+ $w = 0;
164
+
165
+ // Divide the string into tokens; HTML tags, or words, followed by any whitespace
166
+ // (<[^>]+>|[^<>\s]+\s*)
167
+ preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $text, $tokens);
168
+ foreach ($tokens[0] as $t)
169
+ { // Parse each token
170
+ if ($w >= $length && !$finish_sentence)
171
+ { // Limit reached
172
+ break;
 
 
 
 
173
  }
174
+ if ($t[0] != '<')
175
+ { // Token is not a tag
176
+ if ($w >= $length && $finish_sentence && preg_match('/[\?\.\!]\s*$/uS', $t) == 1)
177
+ { // Limit reached, continue until ? . or ! occur at the end
178
+ $out .= trim($t);
 
 
 
 
 
 
179
  break;
180
  }
181
+ if (1 == $use_words)
182
+ { // Count words
183
+ $w++;
184
+ } else
185
+ { // Count/trim characters
186
+ $chars = trim($t); // Remove surrounding space
187
+ $c = strlen($chars);
188
+ if ($c + $w > $length && !$finish_sentence)
189
+ { // Token is too long
190
+ $c = ($finish_word) ? $c : $length - $w; // Keep token to finish word
191
+ $t = substr($t, 0, $c);
 
 
 
 
 
 
 
 
 
 
192
  }
193
+ $w += $c;
194
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  }
196
+ // Append what's left of the token
197
+ $out .= $t;
198
  }
199
+
200
+ return trim(force_balance_tags($out));
201
+ }
202
+
203
+ public function text_add_more($text, $ellipsis, $read_more)
204
+ {
205
+ // New filter in WP2.9, seems unnecessary for now
206
+ //$ellipsis = apply_filters('excerpt_more', $ellipsis);
207
+
208
+ if ($read_more)
209
+ $ellipsis .= sprintf(' <a href="%s" class="read_more">%s</a>', get_permalink(), $read_more);
210
+
211
+ $pos = strrpos($text, '</');
212
+ if ($pos !== false)
213
+ // Inside last HTML tag
214
+ $text = substr_replace($text, $ellipsis, $pos, 0);
215
+ else
216
+ // After the content
217
+ $text .= $ellipsis;
218
+
219
  return $text;
220
  }
221
 
222
+ public function install()
223
  {
224
+ foreach($this->default_options as $k => $v)
225
+ {
226
+ add_option($this->name . '_' . $k, $v);
227
+ }
 
 
 
 
 
 
 
 
228
  }
229
 
230
+ public function uninstall()
231
  {
232
  // Nothing to do (note: deactivation hook is also disabled)
233
  }
234
 
235
+ private function load_options()
236
  {
237
+ foreach($this->default_options as $k => $v)
238
+ {
239
+ $this->default_options[$k] = get_option($this->name . '_' . $k, $v);
240
+ }
 
 
 
 
 
 
 
 
241
  }
242
 
243
+ private function update_options()
 
244
  {
245
  $length = (int) $_POST[$this->name . '_length'];
246
  $use_words = ('on' == $_POST[$this->name . '_use_words']) ? 1 : 0;
250
  $finish_sentence = ('on' == $_POST[$this->name . '_finish_sentence']) ? 1 : 0;
251
  $add_link = ('on' == $_POST[$this->name . '_add_link']) ? 1 : 0;
252
 
253
+ // TODO: Drop magic quotes (deprecated in php 5.3)
254
  $ellipsis = (get_magic_quotes_gpc() == 1) ? stripslashes($_POST[$this->name . '_ellipsis']) : $_POST[$this->name . '_ellipsis'];
255
  $read_more = (get_magic_quotes_gpc() == 1) ? stripslashes($_POST[$this->name . '_read_more']) : $_POST[$this->name . '_read_more'];
256
 
273
  <?php
274
  }
275
 
276
+ public function page_options()
277
  {
278
  if ('POST' == $_SERVER['REQUEST_METHOD'])
279
  {
283
 
284
  extract($this->default_options, EXTR_SKIP);
285
 
 
286
  $ellipsis = htmlentities($ellipsis);
287
  $read_more = htmlentities($read_more);
288
 
289
+ $tag_list = array_unique(self::$options_basic_tags + $allowed_tags);
 
290
  sort($tag_list);
291
  $tag_cols = 5;
292
  ?>
423
  More tags:
424
  <select name="<?php echo $this->name; ?>_more_tags" id="<?php echo $this->name; ?>_more_tags">
425
  <?php
426
+ foreach (self::$options_all_tags as $tag):
427
  ?>
428
  <option value="<?php echo $tag; ?>"><?php echo $tag; ?></option>
429
  <?php
441
  <?php
442
  }
443
 
444
+ public function page_script()
445
  {
446
  wp_enqueue_script($this->name . '_script', WP_PLUGIN_URL . '/advanced-excerpt/advanced-excerpt.js', array(
447
  'jquery'
448
  ));
449
  }
450
 
451
+ public function add_pages()
452
  {
453
  $options_page = add_options_page(__("Advanced Excerpt Options", $this->text_domain), __("Excerpt", $this->text_domain), 'manage_options', 'options-' . $this->name, array(
454
  &$this,
461
  'page_script'
462
  ));
463
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  }
465
+
466
+ AdvancedExcerpt::Instance();
467
 
468
  // Do not use outside the Loop!
469
  function the_advanced_excerpt($args = '', $get = true)
470
  {
471
+ if (!empty($args) && !is_array($args))
 
 
 
 
 
 
 
 
472
  {
473
+ $args = wp_parse_args($args);
 
 
474
 
475
+ // Parse query style parameters
476
+ if (isset($args['ellipsis']))
477
+ $args['ellipsis'] = urldecode($args['ellipsis']);
478
 
479
+ if (isset($args['allowed_tags']))
480
+ $args['allowed_tags'] = preg_split('/[\s,]+/', $args['allowed_tags']);
 
 
 
 
 
481
 
482
+ if (isset($args['exclude_tags']))
483
+ {
484
+ $args['exclude_tags'] = preg_split('/[\s,]+/', $args['exclude_tags']);
485
+ }
486
+ }
487
+ // Set temporary options
488
+ AdvancedExcerpt::Instance()->options = $args;
489
+
490
  if ($get)
491
+ return get_the_excerpt();
492
  else
493
  the_excerpt();
 
494
  }
495
  endif;
readme.txt CHANGED
@@ -2,27 +2,26 @@
2
  Contributors: basvd
3
  Tags: excerpt, advanced, post, posts, template, formatting
4
  Donate link: http://basvd.com/code/advanced-excerpt/
5
- Requires at least: 2.2
6
- Tested up to: 3.2.1
7
- Stable tag: 4.0
8
 
9
- Several improvements over WP's default excerpt. The size of the excerpt can be limited using character or word count, and HTML markup is not removed.
10
 
11
  == Description ==
12
 
13
  This plugin adds several improvements to WordPress' default way of creating excerpts.
14
 
15
- 1. It can keep HTML markup in the excerpt (and you get to choose which tags are included)
16
- 2. It trims the excerpt to a given length using either character count or word count
17
- 3. You can customize the excerpt length and the ellipsis character that will be used when trimming
18
- 4. A read-more link can be added automatically
19
- 4. The excerpt length is *real* (everything belonging to HTML tags is not counted)
20
- 5. Can ignore custom excerpts and use the generated one instead
21
- 6. Theme developers can use `the_advanced_excerpt()` for even more control (see the FAQ)
 
22
 
23
- In addition to keeping HTML markup in the excerpt, the plugin also corrects HTML that might have been broken due to the trimming process.
24
-
25
- This plugin is also compatible with Shortcodes.
26
 
27
  == Installation ==
28
 
@@ -32,29 +31,33 @@ After you've downloaded and extracted the files:
32
  2. Activate the plugin through the 'Plugins' menu in WordPress
33
  3. Go to 'Excerpt' under the 'Settings' menu and configure the plugin
34
 
35
-
36
  == Frequently Asked Questions ==
37
 
 
 
 
 
38
  = Why do I need this plugin? =
39
 
40
  The default excerpt created by WordPress removes all HTML. If your theme uses `the_excerpt()` to view excerpts, they might look weird because of this (smilies are removed, lists are flattened, etc.) This plugin fixes that and also gives you more control over excerpts.
41
 
42
  = Does it work for WordPress version x.x.x? =
43
 
44
- I haven't had the chance to test the plugin on many versions of WordPress. It has recently been tested on 2.9, but it might work on other versions, too. You can safely try it yourself, because the plugin is unlikely to break anything (it's only an output filter). Please let me know if you successfully tested it on another version of WordPress.
 
 
45
 
46
  = Is this plugin available in my language? / How do I translate this plugin? =
47
 
48
- The plugin comes bundled with a few languages. The correct language will automatically be selected to match your [WordPress locale](http://codex.wordpress.org/WordPress_in_Your_Language).
49
 
50
  More information on translation will be added in the future.
51
 
52
  = Does this plugin support multibyte characters, such as Chinese? =
53
 
54
- First of all, it should be noted that word-based excerpt length only works if your language uses normal whitespace as a word separator. If you use another language, you have to uncheck the *Use words?* option.
55
 
56
- PHP's support for multibyte characters is not perfect. The plugin provides support for these characters to the best of its ability, but there are no guarantees that everything will work.
57
- Your best bet is to use UTF-8 encoding (which WordPress uses by default). If you still encounter problems, check with your host if the *mbstring* PHP extension is enabled on your server.
58
 
59
  = Can I manually call the filter in my WP theme or plugin? =
60
 
@@ -82,11 +85,19 @@ A custom advanced excerpt call could look like this:
82
 
83
  = Does this plugin work outside the Loop? =
84
 
85
- No, this plugin fetches the post from The Loop and there is currently no way to pass a post ID or anything custom of that kind to it.
86
- You can, however, consider to [start The Loop manually](http://codex.wordpress.org/The_Loop#Multiple_Loops).
87
 
88
  == Changelog ==
89
 
 
 
 
 
 
 
 
 
90
  = 4.0 =
91
  * Feature: Brand new parsing algorithm which should resolve some running time issues
92
  * Feature: Options to finish a word or sentence before cutting the excerpt
2
  Contributors: basvd
3
  Tags: excerpt, advanced, post, posts, template, formatting
4
  Donate link: http://basvd.com/code/advanced-excerpt/
5
+ Requires at least: 3.2
6
+ Tested up to: 3.3
7
+ Stable tag: 4.1
8
 
9
+ Several improvements over WP's default excerpt. The size can be limited using character or word count, and HTML markup is not removed.
10
 
11
  == Description ==
12
 
13
  This plugin adds several improvements to WordPress' default way of creating excerpts.
14
 
15
+ 1. Keeps HTML markup in the excerpt (and you get to choose which tags are included)
16
+ 2. Trims the excerpt to a given length using either character count or word count
17
+ 3. Only the 'real' text is counted (HTML is ignored but kept)
18
+ 4. Customizes the excerpt length and the ellipsis character that are used
19
+ 5. Completes the last word or sentence in an excerpt (no weird cuts)
20
+ 6. Adds a *read-more* link to the text
21
+ 7. Ignores custom excerpts and use the generated one instead
22
+ 8. Theme developers can use `the_advanced_excerpt()` for even more control (see the FAQ)
23
 
24
+ Most of the above features are optional and/or can be customized by the user or theme developer.
 
 
25
 
26
  == Installation ==
27
 
31
  2. Activate the plugin through the 'Plugins' menu in WordPress
32
  3. Go to 'Excerpt' under the 'Settings' menu and configure the plugin
33
 
 
34
  == Frequently Asked Questions ==
35
 
36
+ = What's an excerpt? =
37
+
38
+ A short version of a post that is usually displayed wherever the whole post would be too much (eg. search results, news feeds, archives). You can write them yourself, but if you don't, WordPress will make a very basic one instead.
39
+
40
  = Why do I need this plugin? =
41
 
42
  The default excerpt created by WordPress removes all HTML. If your theme uses `the_excerpt()` to view excerpts, they might look weird because of this (smilies are removed, lists are flattened, etc.) This plugin fixes that and also gives you more control over excerpts.
43
 
44
  = Does it work for WordPress version x.x.x? =
45
 
46
+ During development, the plugin is tested with the most recent version(s) of WordPress. The range of tested versions is listed on this page (3.2 - 3.3 at the moment). It might work on older versions, but it's better to just keep your installation up-to-date.
47
+
48
+ The plugin requires PHP 5 to work. So if you are using WordPress before 3.2, make sure you have it (WP 3.2 and higher require PHP 5 already).
49
 
50
  = Is this plugin available in my language? / How do I translate this plugin? =
51
 
52
+ The plugin comes bundled with a few (2) languages. The correct language will automatically be selected to match your [WordPress locale](http://codex.wordpress.org/WordPress_in_Your_Language).
53
 
54
  More information on translation will be added in the future.
55
 
56
  = Does this plugin support multibyte characters, such as Chinese? =
57
 
58
+ Before 4.1, multibyte characters were supported directly by this plugin. This feature has been removed because it added irrelevant code for a 'problem' that isn't actually specific to the plugin.
59
 
60
+ If you require multibyte character support on your website, you can [override the default text operations](http://www.php.net/manual/en/mbstring.overload.php) in PHP.
 
61
 
62
  = Can I manually call the filter in my WP theme or plugin? =
63
 
85
 
86
  = Does this plugin work outside the Loop? =
87
 
88
+ No, this plugin fetches the post from The Loop and there is currently no way to pass a post ID or any custom input to it.
89
+ However, you can [start The Loop manually](http://codex.wordpress.org/The_Loop#Multiple_Loops) and apply the plugin as usual.
90
 
91
  == Changelog ==
92
 
93
+ = 4.1 =
94
+ * Fix: Template function with custom options works again
95
+ * Fix: Data before header bug (retro-fixed in 4.0)
96
+ * Feature: Template function also works with array-style parameters
97
+ * Removed multibyte support
98
+ * Removed PHP 4 support (WP 3.2+ users should be fine, others should update)
99
+ * Better code testing before release!
100
+
101
  = 4.0 =
102
  * Feature: Brand new parsing algorithm which should resolve some running time issues
103
  * Feature: Options to finish a word or sentence before cutting the excerpt