Version Description
Download this release
Release Info
Developer | basvd |
Plugin | Advanced Excerpt |
Version | 0.2.2 |
Comparing to | |
See all releases |
Version 0.2.2
- COPYING +165 -0
- advanced-excerpt.php +340 -0
- advancedexcerpt-nl_NL.mo +0 -0
- advancedexcerpt.po +64 -0
- readme.txt +81 -0
COPYING
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 29 June 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
|
9 |
+
This version of the GNU Lesser General Public License incorporates
|
10 |
+
the terms and conditions of version 3 of the GNU General Public
|
11 |
+
License, supplemented by the additional permissions listed below.
|
12 |
+
|
13 |
+
0. Additional Definitions.
|
14 |
+
|
15 |
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16 |
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17 |
+
General Public License.
|
18 |
+
|
19 |
+
"The Library" refers to a covered work governed by this License,
|
20 |
+
other than an Application or a Combined Work as defined below.
|
21 |
+
|
22 |
+
An "Application" is any work that makes use of an interface provided
|
23 |
+
by the Library, but which is not otherwise based on the Library.
|
24 |
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25 |
+
of using an interface provided by the Library.
|
26 |
+
|
27 |
+
A "Combined Work" is a work produced by combining or linking an
|
28 |
+
Application with the Library. The particular version of the Library
|
29 |
+
with which the Combined Work was made is also called the "Linked
|
30 |
+
Version".
|
31 |
+
|
32 |
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33 |
+
Corresponding Source for the Combined Work, excluding any source code
|
34 |
+
for portions of the Combined Work that, considered in isolation, are
|
35 |
+
based on the Application, and not on the Linked Version.
|
36 |
+
|
37 |
+
The "Corresponding Application Code" for a Combined Work means the
|
38 |
+
object code and/or source code for the Application, including any data
|
39 |
+
and utility programs needed for reproducing the Combined Work from the
|
40 |
+
Application, but excluding the System Libraries of the Combined Work.
|
41 |
+
|
42 |
+
1. Exception to Section 3 of the GNU GPL.
|
43 |
+
|
44 |
+
You may convey a covered work under sections 3 and 4 of this License
|
45 |
+
without being bound by section 3 of the GNU GPL.
|
46 |
+
|
47 |
+
2. Conveying Modified Versions.
|
48 |
+
|
49 |
+
If you modify a copy of the Library, and, in your modifications, a
|
50 |
+
facility refers to a function or data to be supplied by an Application
|
51 |
+
that uses the facility (other than as an argument passed when the
|
52 |
+
facility is invoked), then you may convey a copy of the modified
|
53 |
+
version:
|
54 |
+
|
55 |
+
a) under this License, provided that you make a good faith effort to
|
56 |
+
ensure that, in the event an Application does not supply the
|
57 |
+
function or data, the facility still operates, and performs
|
58 |
+
whatever part of its purpose remains meaningful, or
|
59 |
+
|
60 |
+
b) under the GNU GPL, with none of the additional permissions of
|
61 |
+
this License applicable to that copy.
|
62 |
+
|
63 |
+
3. Object Code Incorporating Material from Library Header Files.
|
64 |
+
|
65 |
+
The object code form of an Application may incorporate material from
|
66 |
+
a header file that is part of the Library. You may convey such object
|
67 |
+
code under terms of your choice, provided that, if the incorporated
|
68 |
+
material is not limited to numerical parameters, data structure
|
69 |
+
layouts and accessors, or small macros, inline functions and templates
|
70 |
+
(ten or fewer lines in length), you do both of the following:
|
71 |
+
|
72 |
+
a) Give prominent notice with each copy of the object code that the
|
73 |
+
Library is used in it and that the Library and its use are
|
74 |
+
covered by this License.
|
75 |
+
|
76 |
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77 |
+
document.
|
78 |
+
|
79 |
+
4. Combined Works.
|
80 |
+
|
81 |
+
You may convey a Combined Work under terms of your choice that,
|
82 |
+
taken together, effectively do not restrict modification of the
|
83 |
+
portions of the Library contained in the Combined Work and reverse
|
84 |
+
engineering for debugging such modifications, if you also do each of
|
85 |
+
the following:
|
86 |
+
|
87 |
+
a) Give prominent notice with each copy of the Combined Work that
|
88 |
+
the Library is used in it and that the Library and its use are
|
89 |
+
covered by this License.
|
90 |
+
|
91 |
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92 |
+
document.
|
93 |
+
|
94 |
+
c) For a Combined Work that displays copyright notices during
|
95 |
+
execution, include the copyright notice for the Library among
|
96 |
+
these notices, as well as a reference directing the user to the
|
97 |
+
copies of the GNU GPL and this license document.
|
98 |
+
|
99 |
+
d) Do one of the following:
|
100 |
+
|
101 |
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102 |
+
License, and the Corresponding Application Code in a form
|
103 |
+
suitable for, and under terms that permit, the user to
|
104 |
+
recombine or relink the Application with a modified version of
|
105 |
+
the Linked Version to produce a modified Combined Work, in the
|
106 |
+
manner specified by section 6 of the GNU GPL for conveying
|
107 |
+
Corresponding Source.
|
108 |
+
|
109 |
+
1) Use a suitable shared library mechanism for linking with the
|
110 |
+
Library. A suitable mechanism is one that (a) uses at run time
|
111 |
+
a copy of the Library already present on the user's computer
|
112 |
+
system, and (b) will operate properly with a modified version
|
113 |
+
of the Library that is interface-compatible with the Linked
|
114 |
+
Version.
|
115 |
+
|
116 |
+
e) Provide Installation Information, but only if you would otherwise
|
117 |
+
be required to provide such information under section 6 of the
|
118 |
+
GNU GPL, and only to the extent that such information is
|
119 |
+
necessary to install and execute a modified version of the
|
120 |
+
Combined Work produced by recombining or relinking the
|
121 |
+
Application with a modified version of the Linked Version. (If
|
122 |
+
you use option 4d0, the Installation Information must accompany
|
123 |
+
the Minimal Corresponding Source and Corresponding Application
|
124 |
+
Code. If you use option 4d1, you must provide the Installation
|
125 |
+
Information in the manner specified by section 6 of the GNU GPL
|
126 |
+
for conveying Corresponding Source.)
|
127 |
+
|
128 |
+
5. Combined Libraries.
|
129 |
+
|
130 |
+
You may place library facilities that are a work based on the
|
131 |
+
Library side by side in a single library together with other library
|
132 |
+
facilities that are not Applications and are not covered by this
|
133 |
+
License, and convey such a combined library under terms of your
|
134 |
+
choice, if you do both of the following:
|
135 |
+
|
136 |
+
a) Accompany the combined library with a copy of the same work based
|
137 |
+
on the Library, uncombined with any other library facilities,
|
138 |
+
conveyed under the terms of this License.
|
139 |
+
|
140 |
+
b) Give prominent notice with the combined library that part of it
|
141 |
+
is a work based on the Library, and explaining where to find the
|
142 |
+
accompanying uncombined form of the same work.
|
143 |
+
|
144 |
+
6. Revised Versions of the GNU Lesser General Public License.
|
145 |
+
|
146 |
+
The Free Software Foundation may publish revised and/or new versions
|
147 |
+
of the GNU Lesser General Public License from time to time. Such new
|
148 |
+
versions will be similar in spirit to the present version, but may
|
149 |
+
differ in detail to address new problems or concerns.
|
150 |
+
|
151 |
+
Each version is given a distinguishing version number. If the
|
152 |
+
Library as you received it specifies that a certain numbered version
|
153 |
+
of the GNU Lesser General Public License "or any later version"
|
154 |
+
applies to it, you have the option of following the terms and
|
155 |
+
conditions either of that published version or of any later version
|
156 |
+
published by the Free Software Foundation. If the Library as you
|
157 |
+
received it does not specify a version number of the GNU Lesser
|
158 |
+
General Public License, you may choose any version of the GNU Lesser
|
159 |
+
General Public License ever published by the Free Software Foundation.
|
160 |
+
|
161 |
+
If the Library as you received it specifies that a proxy can decide
|
162 |
+
whether future versions of the GNU Lesser General Public License shall
|
163 |
+
apply, that proxy's public statement of acceptance of any version is
|
164 |
+
permanent authorization for you to choose that version for the
|
165 |
+
Library.
|
advanced-excerpt.php
ADDED
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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: 0.2.2
|
7 |
+
Author: Bas van Doren
|
8 |
+
Author URI: http://sparepencil.com/
|
9 |
+
|
10 |
+
Copyright 2007 Bas van Doren
|
11 |
+
|
12 |
+
This program is free software; you can redistribute it and/or modify
|
13 |
+
it under the terms of the GNU General Public License as published by
|
14 |
+
the Free Software Foundation; either version 3 of the License, or
|
15 |
+
(at your option) any later version.
|
16 |
+
|
17 |
+
This program is distributed in the hope that it will be useful,
|
18 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
+
GNU General Public License for more details.
|
21 |
+
|
22 |
+
You should have received a copy of the GNU General Public License
|
23 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
24 |
+
*/
|
25 |
+
|
26 |
+
if(!class_exists('AdvancedExcerpt')) :
|
27 |
+
class AdvancedExcerpt
|
28 |
+
{
|
29 |
+
var $name;
|
30 |
+
var $text_domain;
|
31 |
+
var $mb;
|
32 |
+
|
33 |
+
var $skip_next_call;
|
34 |
+
|
35 |
+
function AdvancedExcerpt()
|
36 |
+
{
|
37 |
+
$this->name = strtolower(get_class($this));
|
38 |
+
$this->text_domain = $this->name;
|
39 |
+
$this->skip_next_call = false;
|
40 |
+
$this->charset = get_bloginfo('charset');
|
41 |
+
|
42 |
+
// Carefully support multibyte languages
|
43 |
+
if(extension_loaded('mbstring') && function_exists('mb_list_encodings'))
|
44 |
+
$this->mb = in_array($this->charset, mb_list_encodings());
|
45 |
+
|
46 |
+
load_plugin_textdomain($this->text_domain, PLUGINDIR . '/advanced-excerpt/');
|
47 |
+
|
48 |
+
register_activation_hook(__FILE__, array(&$this, 'install'));
|
49 |
+
|
50 |
+
// Nothing to do on deactivation
|
51 |
+
//register_deactivation_hook(__FILE__, array(&$this, 'uninstall'));
|
52 |
+
|
53 |
+
add_action('admin_menu', array(&$this, 'add_pages'));
|
54 |
+
|
55 |
+
// Replace the default filter (see /wp-includes/default-filters.php)
|
56 |
+
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
|
57 |
+
add_filter('get_the_excerpt', array(&$this, 'filter'));
|
58 |
+
}
|
59 |
+
|
60 |
+
function __construct()
|
61 |
+
{
|
62 |
+
self::AdvancedExcerpt();
|
63 |
+
}
|
64 |
+
|
65 |
+
function filter($text, $length = null, $use_words = null, $ellipsis = null, $allowed_tags = null, $no_custom = null, $api_used = false)
|
66 |
+
{
|
67 |
+
global $id, $post;
|
68 |
+
|
69 |
+
// Avoid trouble when the API (aka template tag) was used
|
70 |
+
if($this->skip_next_call)
|
71 |
+
{
|
72 |
+
$this->skip_next_call = false;
|
73 |
+
return $text;
|
74 |
+
}
|
75 |
+
$this->skip_next_call = $api_used;
|
76 |
+
|
77 |
+
$no_custom = (!is_null($no_custom)) ? (int) (bool) $no_custom : get_option($this->name . '_no_custom');
|
78 |
+
|
79 |
+
// Only make the excerpt if it does not exist or 'No Custom Excerpt' is set to true
|
80 |
+
if('' == $text || $no_custom)
|
81 |
+
{
|
82 |
+
$length = (!is_null($length)) ? (int) $length : get_option($this->name . '_length');
|
83 |
+
$use_words = (!is_null($use_words)) ? (int) (bool) $use_words : get_option($this->name . '_use_words');
|
84 |
+
$ellipsis = (!is_null($ellipsis)) ? $ellipsis : get_option($this->name . '_ellipsis');
|
85 |
+
|
86 |
+
$allowed_tags = (is_array($allowed_tags)) ? $allowed_tags : get_option($this->name . '_allowed_tags');
|
87 |
+
$allowed_tags = '<' . implode('><', $allowed_tags) . '>';
|
88 |
+
|
89 |
+
$text = apply_filters('the_content', get_the_content(''));
|
90 |
+
|
91 |
+
// From the default wp_trim_excerpt():
|
92 |
+
// Some kind of precaution against malformed CDATA in RSS feeds I suppose
|
93 |
+
$text = str_replace(']]>', ']]>', $text);
|
94 |
+
$text = strip_tags($text, $allowed_tags);
|
95 |
+
|
96 |
+
if(1 == $use_words)
|
97 |
+
{
|
98 |
+
// Count words, not HTML tags
|
99 |
+
if($length > count(preg_split('/[\s]+/', strip_tags($text), -1)))
|
100 |
+
return $text;
|
101 |
+
|
102 |
+
// Now we start counting
|
103 |
+
$text_bits = preg_split('/([\s]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
|
104 |
+
$in_tag = false;
|
105 |
+
$n_words = 0;
|
106 |
+
$text = '';
|
107 |
+
foreach($text_bits as $chunk)
|
108 |
+
{
|
109 |
+
// Determine whether a tag is opened (and not immediately closed) in this chunk
|
110 |
+
if(0 < preg_match('/<[^>]*$/s', $chunk))
|
111 |
+
$in_tag = true;
|
112 |
+
elseif(0 < preg_match('/>[^<]*$/s', $chunk))
|
113 |
+
$in_tag = false;
|
114 |
+
|
115 |
+
// This should check if there is a word before the tag
|
116 |
+
// but it doesn't work very well
|
117 |
+
/*
|
118 |
+
if($in_tag && $this->substr($chunk, 0, 1) != '<')
|
119 |
+
$n_words++;
|
120 |
+
*/
|
121 |
+
|
122 |
+
// Is there a word?
|
123 |
+
if(!$in_tag && '' != trim($chunk) && $this->substr($chunk, -1, 1) != '>')
|
124 |
+
$n_words++;
|
125 |
+
|
126 |
+
$text .= $chunk;
|
127 |
+
|
128 |
+
if($n_words >= $length && !$in_tag)
|
129 |
+
break;
|
130 |
+
}
|
131 |
+
$text = $text . $ellipsis;
|
132 |
+
}
|
133 |
+
else
|
134 |
+
{
|
135 |
+
// Count characters, not whitespace, not those belonging to HTML tags
|
136 |
+
if($length > $this->strlen(strip_tags($text)))
|
137 |
+
return $text;
|
138 |
+
|
139 |
+
$in_tag = false;
|
140 |
+
$n_chars = 0;
|
141 |
+
for($i = 0; $n_chars < $length || $in_tag; $i++)
|
142 |
+
{
|
143 |
+
// Is the character worth counting (ie. not part of an HTML tag)
|
144 |
+
if($this->substr($text, $i, 1) == '<')
|
145 |
+
$in_tag = true;
|
146 |
+
elseif($this->substr($text, $i, 1) == '>')
|
147 |
+
$in_tag = false;
|
148 |
+
elseif(!$in_tag && '' != trim($this->substr($text, $i, 1)))
|
149 |
+
$n_chars++;
|
150 |
+
|
151 |
+
// Prevent eternal loops (this could happen with incomplete HTML tags)
|
152 |
+
if($i >= $this->strlen($text) - 1)
|
153 |
+
break;
|
154 |
+
}
|
155 |
+
$text = $this->substr($text, 0, $i) . $ellipsis;
|
156 |
+
}
|
157 |
+
$text = force_balance_tags($text);
|
158 |
+
}
|
159 |
+
return $text;
|
160 |
+
}
|
161 |
+
|
162 |
+
function update_options()
|
163 |
+
{
|
164 |
+
$length = (int) $_POST[$this->name . '_length'];
|
165 |
+
$use_words = ('on' == $_POST[$this->name . '_use_words']) ? 1 : 0 ;
|
166 |
+
$no_custom = ('on' == $_POST[$this->name . '_no_custom']) ? 1 : 0 ;
|
167 |
+
|
168 |
+
$ellipsis = (get_magic_quotes_gpc() == 1) ? stripslashes($_POST[$this->name . '_ellipsis']) : $_POST[$this->name . '_ellipsis'];
|
169 |
+
$ellipsis = $ellipsis;
|
170 |
+
|
171 |
+
$allowed_tags = (array) $_POST[$this->name . '_allowed_tags'];
|
172 |
+
|
173 |
+
update_option($this->name . '_length', $length);
|
174 |
+
update_option($this->name . '_use_words', $use_words);
|
175 |
+
update_option($this->name . '_no_custom', $no_custom);
|
176 |
+
update_option($this->name . '_ellipsis', $ellipsis);
|
177 |
+
update_option($this->name . '_allowed_tags', $allowed_tags);
|
178 |
+
?>
|
179 |
+
<div id="message" class="updated fade"><p>Options saved.</p></div>
|
180 |
+
<?php
|
181 |
+
}
|
182 |
+
|
183 |
+
|
184 |
+
function page_options()
|
185 |
+
{
|
186 |
+
global $allowedposttags;
|
187 |
+
|
188 |
+
if ('POST' == $_SERVER['REQUEST_METHOD'])
|
189 |
+
{
|
190 |
+
check_admin_referer($this->name . '_update_options');
|
191 |
+
$this->update_options();
|
192 |
+
}
|
193 |
+
|
194 |
+
$length = get_option($this->name . '_length');
|
195 |
+
$use_words = get_option($this->name . '_use_words');
|
196 |
+
$no_custom = get_option($this->name . '_no_custom');
|
197 |
+
$ellipsis = htmlentities(get_option($this->name . '_ellipsis'));
|
198 |
+
$allowed_tags = get_option($this->name . '_allowed_tags');
|
199 |
+
?>
|
200 |
+
<div class="wrap">
|
201 |
+
<div id="icon-options-general" class="icon32"><br /></div>
|
202 |
+
<h2><?php _e("Advanced Excerpt Options", $this->text_domain); ?></h2>
|
203 |
+
<form method="post" action="">
|
204 |
+
<?php
|
205 |
+
if ( function_exists('wp_nonce_field') )
|
206 |
+
wp_nonce_field($this->name . '_update_options'); ?>
|
207 |
+
|
208 |
+
<table class="form-table">
|
209 |
+
<tr valign="top">
|
210 |
+
<th scope="row"><label for="<?php echo $this->name ?>_length"><?php _e("Excerpt Length:", $this->text_domain); ?></label></th>
|
211 |
+
<td>
|
212 |
+
<input name="<?php echo $this->name ?>_length" type="text" id="<?php echo $this->name ?>_length" value="<?php echo $length; ?>" size="2" />
|
213 |
+
<input name="<?php echo $this->name ?>_use_words" type="checkbox" id="<?php echo $this->name ?>_use_words" value="on" <?php echo (1 == $use_words) ? 'checked="checked" ': ''; ?>/> <?php _e("Use words?", $this->text_domain); ?>
|
214 |
+
</td>
|
215 |
+
</tr>
|
216 |
+
<tr valign="top">
|
217 |
+
<th scope="row"><label for="<?php echo $this->name ?>_ellipsis"><?php _e("Ellipsis:", $this->text_domain); ?></label></th>
|
218 |
+
<td>
|
219 |
+
<input name="<?php echo $this->name ?>_ellipsis" type="text" id="<?php echo $this->name ?>_ellipsis" value="<?php echo $ellipsis; ?>" size="5" /> <?php _e('(use <a href="http://www.w3schools.com/tags/ref_entities.asp">HTML entities</a>)', $this->text_domain); ?>
|
220 |
+
<br />
|
221 |
+
<?php _e("Will substitute the part of the post that is omitted in the excerpt.", $this->text_domain); ?>
|
222 |
+
</td>
|
223 |
+
</tr>
|
224 |
+
<tr valign="top">
|
225 |
+
<th scope="row"><label for="<?php echo $this->name ?>_no_custom"><?php _e("No Custom Excerpts:", $this->text_domain); ?></label></th>
|
226 |
+
<td>
|
227 |
+
<input name="<?php echo $this->name ?>_no_custom" type="checkbox" id="<?php echo $this->name ?>_no_custom" value="on" <?php echo (1 == $no_custom) ? 'checked="checked" ': ''; ?>/>
|
228 |
+
<?php _e("Generate excerpts even if a post has a custom excerpt attached.", $this->text_domain); ?>
|
229 |
+
</td>
|
230 |
+
</tr>
|
231 |
+
<tr valign="top">
|
232 |
+
<th scope="row"><?php _e("Keep Markup:", $this->text_domain); ?></th>
|
233 |
+
<td>
|
234 |
+
<table>
|
235 |
+
<?php
|
236 |
+
$i = 0;
|
237 |
+
foreach($allowedposttags as $tag => $spec) :
|
238 |
+
if(1 == $i / 4) : ?><tr><?php endif;
|
239 |
+
$i++;
|
240 |
+
?>
|
241 |
+
<td><input name="<?php echo $this->name ?>_allowed_tags[]" type="checkbox" id="<?php echo $this->name ?>_allow_<?php echo $tag; ?>" value="<?php echo $tag; ?>" <?php echo (in_array($tag, $allowed_tags)) ? 'checked="checked" ': ''; ?>/> <code><?php echo $tag; ?></code></td><?php if(1 == $i / 4) : $i = 0; ?></tr><?php endif;?>
|
242 |
+
<?php
|
243 |
+
endforeach;
|
244 |
+
if(1 != $i / 4) : ?><td colspan="<?php echo (4 - $i); ?>"> </td></tr><?php endif;?>
|
245 |
+
</table>
|
246 |
+
<!--<?php _e("See <a href=\"http://xref.redalt.com/wptrunk/nav.htm?wp-includes/kses.php.source.htm\"><code>wp-includes/kses.php</code></a> if you want to control more tags.", $this->text_domain); ?>-->
|
247 |
+
</td>
|
248 |
+
</tr>
|
249 |
+
</table>
|
250 |
+
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e("Save Changes", $this->text_domain); ?>" /></p>
|
251 |
+
</form>
|
252 |
+
</div>
|
253 |
+
<?php
|
254 |
+
}
|
255 |
+
|
256 |
+
function add_pages()
|
257 |
+
{
|
258 |
+
add_options_page(__("Advanced Excerpt Options", $this->text_domain), __("Excerpt", $this->text_domain), 'manage_options', 'options-' . $this->name, array(&$this, 'page_options'));
|
259 |
+
}
|
260 |
+
|
261 |
+
function install()
|
262 |
+
{
|
263 |
+
global $allowedposttags;
|
264 |
+
foreach($allowedposttags as $tag => $spec)
|
265 |
+
$allowed_tags[] = $tag;
|
266 |
+
add_option($this->name . '_length', 40);
|
267 |
+
add_option($this->name . '_use_words', 1);
|
268 |
+
add_option($this->name . '_no_custom', 0);
|
269 |
+
add_option($this->name . '_ellipsis', '…');
|
270 |
+
add_option($this->name . '_allowed_tags', $allowed_tags);
|
271 |
+
}
|
272 |
+
|
273 |
+
function uninstall()
|
274 |
+
{
|
275 |
+
// Nothing to do (note: deactivation hook is also disabled)
|
276 |
+
}
|
277 |
+
|
278 |
+
// Careful multibyte support (fallback to normal functions if not available)
|
279 |
+
function substr($str, $start, $length = null)
|
280 |
+
{
|
281 |
+
$length = (is_null($length)) ? $this->strlen($str) : $length;
|
282 |
+
if($this->mb)
|
283 |
+
return mb_substr($str, $start, $length, $this->charset);
|
284 |
+
else
|
285 |
+
return substr($str, $start, $length);
|
286 |
+
}
|
287 |
+
|
288 |
+
function strlen($str)
|
289 |
+
{
|
290 |
+
if($this->mb)
|
291 |
+
return mb_strlen($str, $this->charset);
|
292 |
+
else
|
293 |
+
return strlen($str);
|
294 |
+
}
|
295 |
+
|
296 |
+
// PHP seems to lack a simple complement function for arrays
|
297 |
+
function array_complement($a, $b)
|
298 |
+
{
|
299 |
+
$a = array_unique($a);
|
300 |
+
$b = array_unique($b);
|
301 |
+
$c = array();
|
302 |
+
foreach($a as $t)
|
303 |
+
{
|
304 |
+
if(!in_array($t, $b))
|
305 |
+
$c[] = $t;
|
306 |
+
}
|
307 |
+
}
|
308 |
+
}
|
309 |
+
|
310 |
+
$advancedexcerpt = new AdvancedExcerpt();
|
311 |
+
|
312 |
+
function the_advanced_excerpt($args = '')
|
313 |
+
{
|
314 |
+
global $advancedexcerpt;
|
315 |
+
$defaults = array(
|
316 |
+
'length' => get_option($advancedexcerpt->name . '_length'),
|
317 |
+
'use_words' => get_option($advancedexcerpt->name . '_use_words'),
|
318 |
+
'no_custom' => get_option($advancedexcerpt->name . '_no_custom'),
|
319 |
+
// URL encode, because URL decode is used on this setting later
|
320 |
+
'ellipsis' => urlencode(get_option($advancedexcerpt->name . '_ellipsis')),
|
321 |
+
'allow_tags' => implode(',', get_option($advancedexcerpt->name . '_allowed_tags')),
|
322 |
+
'exclude_tags' => '');
|
323 |
+
|
324 |
+
$r = wp_parse_args($args, $defaults);
|
325 |
+
|
326 |
+
extract($r, EXTR_SKIP);
|
327 |
+
|
328 |
+
$allow_tags = preg_split('/[\s,]+/', $allow_tags);
|
329 |
+
$exclude_tags = preg_split('/[\s,]+/', $exclude_tags);
|
330 |
+
$ellipsis = urldecode($ellipsis);
|
331 |
+
|
332 |
+
// {allow_tags} - {exclude_tags}
|
333 |
+
$allow_tags = $advancedexcerpt->array_complement($allow_tags, $exclude_tags);
|
334 |
+
|
335 |
+
// All filters are applied, however, the advanced excerpt now behaves like a priorite 1 filter, instead of the default priority 10
|
336 |
+
$text = $advancedexcerpt->filter('', $length, $use_words, $ellipsis, $allow_tags, $no_custom, true);
|
337 |
+
$text = apply_filters('get_the_excerpt', $text);
|
338 |
+
echo apply_filters('the_excerpt', $text);
|
339 |
+
}
|
340 |
+
endif;
|
advancedexcerpt-nl_NL.mo
ADDED
Binary file
|
advancedexcerpt.po
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: Advanced Excerpt\n"
|
4 |
+
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: 2009-01-14 16:33+0100\n"
|
6 |
+
"PO-Revision-Date: \n"
|
7 |
+
"Last-Translator: Bas van Doren\n"
|
8 |
+
"Language-Team: \n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Poedit-KeywordsList: _e;__\n"
|
13 |
+
"X-Poedit-Basepath: .\n"
|
14 |
+
"X-Poedit-SearchPath-0: .\n"
|
15 |
+
|
16 |
+
#: advanced-excerpt.php:223
|
17 |
+
#: advanced-excerpt.php:279
|
18 |
+
msgid "Advanced Excerpt Options"
|
19 |
+
msgstr "Verbeterde Uittreksel Opties"
|
20 |
+
|
21 |
+
#: advanced-excerpt.php:231
|
22 |
+
msgid "Excerpt Length:"
|
23 |
+
msgstr "Lengte van uittreksel:"
|
24 |
+
|
25 |
+
#: advanced-excerpt.php:234
|
26 |
+
msgid "Use words?"
|
27 |
+
msgstr "Gebruik woorden?"
|
28 |
+
|
29 |
+
#: advanced-excerpt.php:238
|
30 |
+
msgid "Ellipsis:"
|
31 |
+
msgstr "Weglating:"
|
32 |
+
|
33 |
+
#: advanced-excerpt.php:240
|
34 |
+
msgid "(use <a href=\"http://www.w3schools.com/tags/ref_entities.asp\">HTML entities</a>)"
|
35 |
+
msgstr "(gebruik <a href=\"http://www.w3schools.com/tags/ref_entities.asp\">HTML entiteiten</a>)"
|
36 |
+
|
37 |
+
#: advanced-excerpt.php:242
|
38 |
+
msgid "Will substitute the part of the post that is omitted in the excerpt."
|
39 |
+
msgstr "Vervangt het deel van het bericht dat weggelaten wordt in de uittreksel."
|
40 |
+
|
41 |
+
#: advanced-excerpt.php:246
|
42 |
+
msgid "No Custom Excerpts:"
|
43 |
+
msgstr "Negeer gebruikers uittreksels:"
|
44 |
+
|
45 |
+
#: advanced-excerpt.php:249
|
46 |
+
msgid "Generate excerpts even if a post has a custom excerpt attached."
|
47 |
+
msgstr "Genereer altijd een uittreksel, ook als er al een bij het bericht gevoegd is."
|
48 |
+
|
49 |
+
#: advanced-excerpt.php:253
|
50 |
+
msgid "Keep Markup:"
|
51 |
+
msgstr "Behoud opmaak:"
|
52 |
+
|
53 |
+
#: advanced-excerpt.php:267
|
54 |
+
msgid "See <a href=\"http://xref.redalt.com/wptrunk/nav.htm?wp-includes/kses.php.source.htm\"><code>wp-includes/kses.php</code></a> if you want to control more tags."
|
55 |
+
msgstr "Zie <a href=\"http://xref.redalt.com/wptrunk/nav.htm?wp-includes/kses.php.source.htm\"><code>wp-includes/kses.php</code></a> als je meer controle wil over deze tags."
|
56 |
+
|
57 |
+
#: advanced-excerpt.php:271
|
58 |
+
msgid "Save Changes"
|
59 |
+
msgstr "Wijzigingen opslaan"
|
60 |
+
|
61 |
+
#: advanced-excerpt.php:279
|
62 |
+
msgid "Excerpt"
|
63 |
+
msgstr "Uittreksel"
|
64 |
+
|
readme.txt
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Advanced Excerpt ===
|
2 |
+
Contributors: basvd
|
3 |
+
Tags: excerpt, advanced, post, posts, template, formatting
|
4 |
+
Donate link: http://sparepencil.com/code/advanced-excerpt/
|
5 |
+
Requires at least: 2.2
|
6 |
+
Tested up to: 2.7
|
7 |
+
Stable tag: trunk
|
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 customise the excerpt length and the ellipsis character that will be used when trimming
|
18 |
+
4. The excerpt length is *real* (everything belonging to HTML tags is not counted)
|
19 |
+
5. Possibility to ignore custom excerpts and use the generated one instead
|
20 |
+
6. Theme developers can use `the_advanced_excerpt()` for even more control (see the FAQ)
|
21 |
+
|
22 |
+
In addition to keeping HTML markup in the excerpt, the plugin also corrects HTML that might have been broken due to the trimming process.
|
23 |
+
|
24 |
+
Version 0.2.1 adds support for multibyte characters (eg. Chinese and Japanese). This is slightly experimental, more details in the FAQ.
|
25 |
+
Plugin translations are fully supported and language files are included for translation. The FAQ provides more info on this, also.
|
26 |
+
|
27 |
+
== Installation ==
|
28 |
+
|
29 |
+
After you've downloaded and extracted the files:
|
30 |
+
|
31 |
+
1. Upload the complete `advanced-excerpt` folder to the `/wp-content/plugins/` directory
|
32 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
33 |
+
3. Go to 'Excerpt' under the 'Options' tab 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 (e.g. 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 been tested on 2.2 through 2.7, 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 succesfully 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 templates, for example? =
|
60 |
+
|
61 |
+
The plugin automatically hooks on `the_excerpt()` function and uses the parameters specified in the options panel.
|
62 |
+
|
63 |
+
If you want to call the filter with different options, you can use `the_advanced_excerpt()` template tag provided by this plugin. This tag accepts [query-string-style parameters](http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_query-string-style_parameters) (theme developers will be familiar with this notation).
|
64 |
+
|
65 |
+
The following parameters can be set:
|
66 |
+
|
67 |
+
* `length`, an integer that determines the length of the excerpt
|
68 |
+
* `use_words`, if set to `1`, the excerpt length will be in words; if set to `0`, characters will be used for the count
|
69 |
+
* `no_custom`, if set to `1`, an excerpt will be generated even if the post has a custom excerpt; if set to `0`, the custom excerpt will be used
|
70 |
+
* `ellipsis`, the string that will substitute the omitted part of the post; if you want to use HTML entities in the string, use `%26` instead of the `&` prefix to avoid breaking the query
|
71 |
+
* `exclude_tags`, a comma-separated list of HTML tags that must be removed from the excerpt
|
72 |
+
* `allow_tags`, a comma-separated list of HTML tags that are allowed in the excerpt
|
73 |
+
|
74 |
+
A custom, advanced excerpt call could look like this:
|
75 |
+
|
76 |
+
`the_advanced_excerpt('length=320&use_words=0&no_custom=1&ellipsis=%26hellip;&exclude_tags=img,p,strong');`
|
77 |
+
|
78 |
+
= Does this plugin work outside the Loop? =
|
79 |
+
|
80 |
+
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.
|
81 |
+
You can, however, consider to [start The Loop manually](http://codex.wordpress.org/The_Loop#Multiple_Loops).
|