| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Post Teaser |
|---|
| 4 | Plugin URI: http://wordpress.org/extend/plugins/post-teaser/ |
|---|
| 5 | Description: Post Teaser generates a preview or "teaser" of a post for the main, archive and category pages, with a link underneath to go to the full post page. It includes features to generate a word count, image count, and an estimated reading time. |
|---|
| 6 | Version: 4.1.1 |
|---|
| 7 | Author: WeyHan Ng |
|---|
| 8 | Author URI: http://sandboxblogger.com/ |
|---|
| 9 | Text Domain: post-teaser |
|---|
| 10 | |
|---|
| 11 | **** WARNING: DO NOT EDIT THIS FILE! YOU CAN CONFIGURE THE PLUGIN FROM THE "OPTIONS > POST TEASER" MENU **** |
|---|
| 12 | |
|---|
| 13 | **** NOTE: PLEASE DO NOT EMAIL JONATHAN LEIGHTON FOR SUPPORT. Instead email <han at sandboxblogger dot com> for support. **** |
|---|
| 14 | |
|---|
| 15 | Post Teaser -- A teaser plugin for WordPress |
|---|
| 16 | Copyright (C) Jonathan Leighton (j@jonathanleighton.com) |
|---|
| 17 | Copyright (C) WeyHan Ng (han@sandboxblogger.com) |
|---|
| 18 | |
|---|
| 19 | This program is free software; you can redistribute it and/or |
|---|
| 20 | modify it under the terms of the GNU General Public License |
|---|
| 21 | as published by the Free Software Foundation; either version 2 |
|---|
| 22 | of the License, or (at your option) any later version. |
|---|
| 23 | |
|---|
| 24 | This program is distributed in the hope that it will be useful, |
|---|
| 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 27 | GNU General Public License for more details. |
|---|
| 28 | |
|---|
| 29 | You should have received a copy of the GNU General Public License |
|---|
| 30 | along with WordPress; if not, write to the Free Software |
|---|
| 31 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 32 | */ |
|---|
| 33 | class post_teaser { |
|---|
| 34 | var $version = "4.1.1"; |
|---|
| 35 | var $debug = false; |
|---|
| 36 | |
|---|
| 37 | var $meta = ""; |
|---|
| 38 | |
|---|
| 39 | /*** Default option values ***/ |
|---|
| 40 | var $default_options = array(); |
|---|
| 41 | |
|---|
| 42 | /*** Anything that doesn't really need to be configurable ***/ |
|---|
| 43 | var $static_options = array |
|---|
| 44 | ( |
|---|
| 45 | 'blocks' => 'p|li|dt|dd|address|form|pre|tr' |
|---|
| 46 | ); |
|---|
| 47 | |
|---|
| 48 | /*** Called once before any teasering. Puts the options into properties. ***/ |
|---|
| 49 | function post_teaser() { |
|---|
| 50 | load_plugin_textdomain('post-teaser'); |
|---|
| 51 | $this->default_options['full_template'] = __('<a href="%permalink%" title="Permanent Link: %plain_title%" rel="bookmark">Permanent link to this post</a> (%word_image_count%, estimated %reading_time% reading time)', 'post-teaser'); |
|---|
| 52 | $this->default_options['more_template'] = __(' <a href="%permalink%" title="Permanent Link: %plain_title%" rel="bookmark">Read more...</a> <i>(%word_image_count%, estimated %reading_time% reading time)</i>', 'post-teaser'); |
|---|
| 53 | $this->default_options['teaser_template'] = __('This is a preview of <q>%title%</q>. <a href="%permalink%" title="Permanent Link: %plain_title%" rel="bookmark">Read the full post (%word_image_count%, estimated %reading_time% reading time)</a>', 'post-teaser'); |
|---|
| 54 | $this->default_options['target'] = '100'; |
|---|
| 55 | $this->default_options['word_mins'] = __(' mins', 'post-teaser'); |
|---|
| 56 | $this->default_options['word_secs'] = __(' secs', 'post-teaser'); |
|---|
| 57 | $this->default_options['time_separator'] = ':'; |
|---|
| 58 | $this->default_options['zero_counts'] = '0'; |
|---|
| 59 | $this->default_options['count_separator'] = ', '; |
|---|
| 60 | $this->default_options['more_link'] = '0'; |
|---|
| 61 | $this->default_options['block_stats'] = '1'; |
|---|
| 62 | $this->default_options['block_stats_before'] = '0'; |
|---|
| 63 | $this->default_options['omit_fullpost'] = '0'; |
|---|
| 64 | $this->default_options['use_disable_filter'] = '0'; |
|---|
| 65 | $this->default_options['home_control'] = '0'; |
|---|
| 66 | $this->default_options['home_disable'] = '0'; |
|---|
| 67 | $this->default_options['home_showall'] = '0'; |
|---|
| 68 | $this->default_options['disable_cat'] = ''; |
|---|
| 69 | $this->default_options['disable_cat_always'] = '0'; |
|---|
| 70 | $this->default_options['disable_inverse'] = '0'; |
|---|
| 71 | $this->default_options['disable_tag'] = ''; |
|---|
| 72 | $this->default_options['disable_tag_always'] = '0'; |
|---|
| 73 | $this->default_options['use_showall_filter'] = '0'; |
|---|
| 74 | $this->default_options['showall_cat'] = ''; |
|---|
| 75 | $this->default_options['showall_cat_always'] = '0'; |
|---|
| 76 | $this->default_options['showall_inverse'] = '0'; |
|---|
| 77 | $this->default_options['showall_tag'] = ''; |
|---|
| 78 | $this->default_options['showall_tag_always'] = '0'; |
|---|
| 79 | |
|---|
| 80 | $options = get_option('post_teaser'); |
|---|
| 81 | if (!$options) { |
|---|
| 82 | add_option('post_teaser', $this->default_options); |
|---|
| 83 | $options = $this->default_options; |
|---|
| 84 | } |
|---|
| 85 | foreach ($options as $option_name => $option_value) |
|---|
| 86 | $this->{$option_name} = $option_value; |
|---|
| 87 | foreach ($this->static_options as $option_name => $option_value) |
|---|
| 88 | $this->{$option_name} = $option_value; |
|---|
| 89 | |
|---|
| 90 | if (!$this->full_template) { |
|---|
| 91 | $this->full_template = $this->default_options['full_template']; |
|---|
| 92 | } |
|---|
| 93 | if (!$this->more_template) { |
|---|
| 94 | $this->more_template = $this->default_options['more_template']; |
|---|
| 95 | } |
|---|
| 96 | if (!$this->teaser_template) { |
|---|
| 97 | $this->teaser_template = $this->default_options['teaser_template']; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | if (strstr($this->full_template, '%reading_time%') || strstr($this->more_template, '%reading_time%') || strstr($this->teaser_template, '%reading_time%')) |
|---|
| 101 | $this->doing_reading_time = true; |
|---|
| 102 | else |
|---|
| 103 | $this->doing_reading_time = false; |
|---|
| 104 | |
|---|
| 105 | if (strstr($this->full_template, '%word_image_count%') || strstr($this->more_template, '%word_image_count%') || strstr($this->teaser_template, '%word_image_count%')) |
|---|
| 106 | $this->doing_counts = true; |
|---|
| 107 | else |
|---|
| 108 | $this->doing_counts = false; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /*** For editing the plugin's configuration in the admin menu ***/ |
|---|
| 112 | function init_option_page() { |
|---|
| 113 | if (isset($_POST['post_teaser_submit']) && $_POST['post_teaser_submit']) { |
|---|
| 114 | $uri_arg_pos = strpos($_SERVER["REQUEST_URI"], "&"); |
|---|
| 115 | if ($uri_arg_pos !== false) |
|---|
| 116 | $request_uri = substr($_SERVER["REQUEST_URI"], 0, $uri_arg_pos); |
|---|
| 117 | else |
|---|
| 118 | $request_uri = $_SERVER["REQUEST_URI"]; |
|---|
| 119 | |
|---|
| 120 | if (isset($_POST['submit_update'])) { |
|---|
| 121 | $new_options = array |
|---|
| 122 | ( |
|---|
| 123 | 'full_template' => trim(stripslashes($_POST['full_template'])), |
|---|
| 124 | 'more_template' => trim(stripslashes($_POST['more_template'])), |
|---|
| 125 | 'teaser_template' => trim(stripslashes($_POST['teaser_template'])), |
|---|
| 126 | 'target' => (int) $_POST['target'], |
|---|
| 127 | 'word_mins' => $_POST['word_mins'], |
|---|
| 128 | 'word_secs' => $_POST['word_secs'], |
|---|
| 129 | 'time_separator' => $_POST['time_separator'], |
|---|
| 130 | 'zero_counts' => $_POST['zero_counts'], |
|---|
| 131 | 'count_separator' => $_POST['count_separator'], |
|---|
| 132 | 'more_link' => $_POST['more_link'], |
|---|
| 133 | 'block_stats' => $_POST['block_stats'], |
|---|
| 134 | 'block_stats_before' => $_POST['block_stats_before'], |
|---|
| 135 | 'omit_fullpost' => $_POST['omit_fullpost'], |
|---|
| 136 | 'use_disable_filter' => $_POST['use_disable_filter'], |
|---|
| 137 | 'home_control' => $_POST['home_control'], |
|---|
| 138 | 'home_control_opt' => $_POST['home_control_opt'], |
|---|
| 139 | 'disable_cat' => $_POST['disable_cat'], |
|---|
| 140 | 'disable_cat_always' => $_POST['disable_cat_always'], |
|---|
| 141 | 'disable_inverse' => $_POST['disable_inverse'], |
|---|
| 142 | 'disable_tag' => $_POST['disable_tag'], |
|---|
| 143 | 'disable_tag_always' => $_POST['disable_tag_always'], |
|---|
| 144 | 'use_showall_filter' => $_POST['use_showall_filter'], |
|---|
| 145 | 'showall_cat' => $_POST['showall_cat'], |
|---|
| 146 | 'showall_cat_always' => $_POST['showall_cat_always'], |
|---|
| 147 | 'showall_inverse' => $_POST['showall_inverse'], |
|---|
| 148 | 'showall_tag' => $_POST['showall_tag'], |
|---|
| 149 | 'showall_tag_always' => $_POST['showall_tag_always'] |
|---|
| 150 | ); |
|---|
| 151 | |
|---|
| 152 | $new_options['count_separator'] = str_replace('&', '&', $new_options['count_separator']); |
|---|
| 153 | |
|---|
| 154 | /** Store all checked box as '1' or' 0' for checked or unchecked **/ |
|---|
| 155 | $new_options['zero_counts'] = $new_options['zero_counts'] ? '1' : '0'; |
|---|
| 156 | $new_options['more_link'] = $new_options['more_link'] ? '1' : '0'; |
|---|
| 157 | $new_options['block_stats'] = $new_options['block_stats'] ? '1' : '0'; |
|---|
| 158 | $new_options['block_stats_before'] = $new_options['block_stats_before'] ? '1' : '0'; |
|---|
| 159 | $new_options['omit_fullpost'] = $new_options['omit_fullpost'] ? '1' : '0'; |
|---|
| 160 | $new_options['home_control'] = $new_options['home_control'] ? '1' : '0'; |
|---|
| 161 | $new_options['use_disable_filter'] = $new_options['use_disable_filter'] ? '1' : '0'; |
|---|
| 162 | $new_options['disable_cat_always'] = $new_options['disable_cat_always'] ? '1' : '0'; |
|---|
| 163 | $new_options['disable_inverse'] = $new_options['disable_inverse'] ? '1' : '0'; |
|---|
| 164 | $new_options['disable_tag_always'] = $new_options['disable_tag_always'] ? '1' : '0'; |
|---|
| 165 | $new_options['use_showall_filter'] = $new_options['use_showall_filter'] ? '1' : '0'; |
|---|
| 166 | $new_options['showall_cat_always'] = $new_options['showall_cat_always'] ? '1' : '0'; |
|---|
| 167 | $new_options['showall_inverse'] = $new_options['showall_inverse'] ? '1' : '0'; |
|---|
| 168 | $new_options['showall_tag_always'] = $new_options['showall_tag_always'] ? '1' : '0'; |
|---|
| 169 | |
|---|
| 170 | /** normalized space for all free text list field before saving options**/ |
|---|
| 171 | $cat_str = $new_options['disable_cat']; |
|---|
| 172 | if ($cat_str) { |
|---|
| 173 | $new_cat_str = ''; |
|---|
| 174 | foreach(explode(",", $cat_str) as $cat) { |
|---|
| 175 | $new_cat_str = $new_cat_str . "," . trim($cat); |
|---|
| 176 | } |
|---|
| 177 | $new_options['disable_cat'] = trim($new_cat_str, ","); |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | switch ($new_options['home_control_opt']) { |
|---|
| 181 | case "home_disable": |
|---|
| 182 | $new_options['home_disable'] = '1'; |
|---|
| 183 | break; |
|---|
| 184 | case "home_showall": |
|---|
| 185 | $new_options['home_showall'] = '1'; |
|---|
| 186 | break; |
|---|
| 187 | default: |
|---|
| 188 | $new_options['home_disable'] = '0'; |
|---|
| 189 | $new_options['home_showall'] = '0'; |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | $tag_str = $new_options['disable_tag']; |
|---|
| 193 | if ($tag_str) { |
|---|
| 194 | $new_tag_str = ''; |
|---|
| 195 | foreach(explode(",", $tag_str) as $tag) { |
|---|
| 196 | $new_tag_str = $new_tag_str . "," . trim($tag); |
|---|
| 197 | } |
|---|
| 198 | $new_options['disable_tag'] = trim($new_tag_str, ","); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | $cat_str = $new_options['showall_cat']; |
|---|
| 202 | if ($cat_str) { |
|---|
| 203 | $new_cat_str = ''; |
|---|
| 204 | foreach(explode(",", $cat_str) as $cat) { |
|---|
| 205 | $new_cat_str = $new_cat_str . "," . trim($cat); |
|---|
| 206 | } |
|---|
| 207 | $new_options['showall_cat'] = trim($new_cat_str, ","); |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | $tag_str = $new_options['showall_tag']; |
|---|
| 211 | if ($tag_str) { |
|---|
| 212 | $new_tag_str = ''; |
|---|
| 213 | foreach(explode(",", $tag_str) as $tag) { |
|---|
| 214 | $new_tag_str = $new_tag_str . "," . trim($tag); |
|---|
| 215 | } |
|---|
| 216 | $new_options['showall_tag'] = trim($new_tag_str, ","); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | update_option('post_teaser', $new_options); |
|---|
| 220 | header('Location: ' . $request_uri . '&saved=true'); |
|---|
| 221 | } elseif (isset($_POST['submit_reset'])) { |
|---|
| 222 | update_option('post_teaser', $this->default_options); |
|---|
| 223 | header('Location: ' . $request_uri . '&saved=true'); |
|---|
| 224 | } |
|---|
| 225 | die; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | $post_teaser_page = add_options_page(__('Post Teaser', 'post-teaser'), __('Post Teaser', 'post-teaser'), 6, __FILE__, array(&$this, 'option_page')); |
|---|
| 229 | add_action("admin_print_scripts-$post_teaser_page", array(&$this, 'option_page_head')); |
|---|
| 230 | } |
|---|
| 231 | function option_page_head() { |
|---|
| 232 | $plugindir = get_option('siteurl').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__)); |
|---|
| 233 | echo "<link rel='stylesheet' href='$plugindir/post-teaser.css' type='text/css' />\n"; |
|---|
| 234 | ?> |
|---|
| 235 | <script type="text/javascript"> |
|---|
| 236 | //<![CDATA[ |
|---|
| 237 | var count_separator = '<?php echo $this->count_separator; ?>'; |
|---|
| 238 | var time_separator = '<?php echo $this->time_separator; ?>'; |
|---|
| 239 | var word_mins = '<?php echo $this->word_mins; ?>'; |
|---|
| 240 | function update_preview(textareaId, previewId) { |
|---|
| 241 | template = document.getElementById(textareaId).value; |
|---|
| 242 | if (textareaId == "more_template") { |
|---|
| 243 | template = '<span class="grayout">' + '<?php _e('...post text before cut-off', 'post-teaser') ?>' + '</span>' + template; |
|---|
| 244 | } |
|---|
| 245 | template = template.replace('%title%', '<?php _e('An <em>example<\/em> post', 'post-teaser') ?>'); |
|---|
| 246 | template = template.replace('%plain_title%', '<?php _e('An example post', 'post-teaser') ?>'); |
|---|
| 247 | template = template.replace('%permalink%', 'http://example.com'); |
|---|
| 248 | template = template.replace('%word_image_count%', '462 <?php _e('words', 'post-teaser') ?>' + count_separator + '3 <?php _e('images', 'post-teaser') ?>'); |
|---|
| 249 | template = template.replace('%reading_time%', '3' + time_separator + '34 ' + word_mins); |
|---|
| 250 | document.getElementById(previewId).innerHTML = template; |
|---|
| 251 | template = null; |
|---|
| 252 | } |
|---|
| 253 | window.onload = function() { |
|---|
| 254 | if (!document.getElementById('block_stats').checked) { |
|---|
| 255 | document.getElementById('omit_fullpost').disabled = true; |
|---|
| 256 | document.getElementById('omit_fullpost_label').className = "grayout"; |
|---|
| 257 | document.getElementById('omit_fullpost_info').className = "info grayout"; |
|---|
| 258 | document.getElementById('block_stats_before').disabled = true; |
|---|
| 259 | document.getElementById('block_stats_before_label').className = "grayout"; |
|---|
| 260 | document.getElementById('block_stats_before_info').className = "info grayout"; |
|---|
| 261 | document.getElementById('teaser_template').disabled = true; |
|---|
| 262 | document.getElementById('teaser_template').className = "template grayout"; |
|---|
| 263 | document.getElementById('full_template').disabled = true; |
|---|
| 264 | document.getElementById('full_template').className = "template grayout"; |
|---|
| 265 | } else { |
|---|
| 266 | if (document.getElementById('omit_fullpost').checked) { |
|---|
| 267 | document.getElementById('full_template').disabled = true; |
|---|
| 268 | document.getElementById('full_template').className = "template grayout"; |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | if (!document.getElementById('more_link').checked) { |
|---|
| 272 | document.getElementById('more_template').disabled = true; |
|---|
| 273 | document.getElementById('more_template').className = "template grayout"; |
|---|
| 274 | } |
|---|
| 275 | if (!document.getElementById('home_control').checked) { |
|---|
| 276 | document.getElementById('home_disable').disabled = true; |
|---|
| 277 | document.getElementById('home_showall').disabled = true; |
|---|
| 278 | document.getElementById('home_disable_label').className = "grayout"; |
|---|
| 279 | document.getElementById('home_showall_label').className = "grayout"; |
|---|
| 280 | } |
|---|
| 281 | if (!document.getElementById('use_disable_filter').checked) { |
|---|
| 282 | document.getElementById('disable_cat').disabled = true; |
|---|
| 283 | document.getElementById('disable_cat_always').disabled = true; |
|---|
| 284 | document.getElementById('disable_inverse').disabled = true; |
|---|
| 285 | document.getElementById('disable_tag').disabled = true; |
|---|
| 286 | document.getElementById('disable_tag_always').disabled = true; |
|---|
| 287 | document.getElementById('disable_cat_label').className = "grayout indent"; |
|---|
| 288 | document.getElementById('disable_cat_info').className = "grayout info"; |
|---|
| 289 | document.getElementById('disable_cat_always_label').className = "grayout"; |
|---|
| 290 | document.getElementById('disable_cat_always_info').className = "grayout info"; |
|---|
| 291 | document.getElementById('disable_inverse_label').className = "grayout"; |
|---|
| 292 | document.getElementById('disable_inverse_info').className = "grayout info"; |
|---|
| 293 | document.getElementById('disable_tag_label').className = "grayout indent"; |
|---|
| 294 | document.getElementById('disable_tag_info').className = "grayout info"; |
|---|
| 295 | document.getElementById('disable_tag_always_label').className = "grayout"; |
|---|
| 296 | document.getElementById('disable_tag_always_info').className = "grayout info"; |
|---|
| 297 | } |
|---|
| 298 | if (!document.getElementById('use_showall_filter').checked) { |
|---|
| 299 | document.getElementById('showall_cat').disabled = true; |
|---|
| 300 | document.getElementById('showall_cat_always').disabled = true; |
|---|
| 301 | document.getElementById('showall_inverse').disabled = true; |
|---|
| 302 | document.getElementById('showall_tag').disabled = true; |
|---|
| 303 | document.getElementById('showall_tag_always').disabled = true; |
|---|
| 304 | document.getElementById('showall_cat_label').className = "grayout indent"; |
|---|
| 305 | document.getElementById('showall_cat_info').className = "grayout info"; |
|---|
| 306 | document.getElementById('showall_cat_always_label').className = "grayout"; |
|---|
| 307 | document.getElementById('showall_cat_always_info').className = "grayout info"; |
|---|
| 308 | document.getElementById('showall_inverse_label').className = "grayout"; |
|---|
| 309 | document.getElementById('showall_inverse_info').className = "grayout info"; |
|---|
| 310 | document.getElementById('showall_tag_label').className = "grayout indent"; |
|---|
| 311 | document.getElementById('showall_tag_info').className = "grayout info"; |
|---|
| 312 | document.getElementById('showall_tag_always_label').className = "grayout"; |
|---|
| 313 | document.getElementById('showall_tag_always_info').className = "grayout info"; |
|---|
| 314 | } |
|---|
| 315 | var container = document.getElementById('teaser_template_container'); |
|---|
| 316 | var insert = document.createElement('h4'); |
|---|
| 317 | insert.innerHTML = '<?php _e('Preview', 'post-teaser') ?>'; |
|---|
| 318 | container.appendChild(insert); |
|---|
| 319 | |
|---|
| 320 | insert = document.createElement('div'); |
|---|
| 321 | insert.id = 'teaser_template_preview'; |
|---|
| 322 | insert.className = 'preview left'; |
|---|
| 323 | container.appendChild(insert); |
|---|
| 324 | |
|---|
| 325 | document.getElementById('teaser_template').onkeyup = function() { update_preview('teaser_template', 'teaser_template_preview'); }; |
|---|
| 326 | update_preview('teaser_template', 'teaser_template_preview'); |
|---|
| 327 | |
|---|
| 328 | container = document.getElementById('more_template_container'); |
|---|
| 329 | insert = document.createElement('h4'); |
|---|
| 330 | insert.innerHTML = '<?php _e('Preview', 'post-teaser') ?>'; |
|---|
| 331 | container.appendChild(insert); |
|---|
| 332 | |
|---|
| 333 | insert = document.createElement('div'); |
|---|
| 334 | insert.id = 'more_template_preview'; |
|---|
| 335 | insert.className = 'preview left'; |
|---|
| 336 | container.appendChild(insert); |
|---|
| 337 | |
|---|
| 338 | document.getElementById('more_template').onkeyup = function() { update_preview('more_template', 'more_template_preview'); }; |
|---|
| 339 | update_preview('more_template', 'more_template_preview'); |
|---|
| 340 | |
|---|
| 341 | container = document.getElementById('full_template_container'); |
|---|
| 342 | insert = document.createElement('h4'); |
|---|
| 343 | insert.innerHTML = '<?php _e('Preview', 'post-teaser') ?>'; |
|---|
| 344 | container.appendChild(insert); |
|---|
| 345 | |
|---|
| 346 | insert = document.createElement('div'); |
|---|
| 347 | insert.id = 'full_template_preview'; |
|---|
| 348 | insert.className = 'preview left'; |
|---|
| 349 | container.appendChild(insert); |
|---|
| 350 | |
|---|
| 351 | document.getElementById('full_template').onkeyup = function() { update_preview('full_template', 'full_template_preview'); }; |
|---|
| 352 | update_preview('full_template', 'full_template_preview'); |
|---|
| 353 | |
|---|
| 354 | document.getElementById('count_separator').onchange = function() { |
|---|
| 355 | count_separator = this.value; |
|---|
| 356 | update_preview('full_template', 'full_template_preview'); |
|---|
| 357 | update_preview('more_template', 'more_template_preview'); |
|---|
| 358 | update_preview('teaser_template', 'teaser_template_preview'); |
|---|
| 359 | }; |
|---|
| 360 | document.getElementById('time_separator').onchange = function() { |
|---|
| 361 | time_separator = this.value; |
|---|
| 362 | update_preview('full_template', 'full_template_preview'); |
|---|
| 363 | update_preview('more_template', 'more_template_preview'); |
|---|
| 364 | update_preview('teaser_template', 'teaser_template_preview'); |
|---|
| 365 | }; |
|---|
| 366 | document.getElementById('word_mins').onkeyup = function() { |
|---|
| 367 | word_mins = this.value; |
|---|
| 368 | update_preview('full_template', 'full_template_preview'); |
|---|
| 369 | update_preview('more_template', 'more_template_preview'); |
|---|
| 370 | update_preview('teaser_template', 'teaser_template_preview'); |
|---|
| 371 | }; |
|---|
| 372 | document.getElementById('more_link').onclick = function() { |
|---|
| 373 | if(document.getElementById('more_link').checked) { |
|---|
| 374 | document.getElementById('more_template').disabled=false; |
|---|
| 375 | document.getElementById('more_template').className = "template"; |
|---|
| 376 | } else { |
|---|
| 377 | document.getElementById('more_template').disabled=true; |
|---|
| 378 | document.getElementById('more_template').className = "template grayout"; |
|---|
| 379 | } |
|---|
| 380 | if (document.getElementById('block_stats').checked) { |
|---|
| 381 | document.getElementById('teaser_template').disabled=false; |
|---|
| 382 | document.getElementById('teaser_template').className = "template"; |
|---|
| 383 | } else { |
|---|
| 384 | document.getElementById('teaser_template').disabled=true; |
|---|
| 385 | document.getElementById('teaser_template').className = "template grayout"; |
|---|
| 386 | } |
|---|
| 387 | }; |
|---|
| 388 | document.getElementById('block_stats').onclick = function() { |
|---|
| 389 | if(document.getElementById('block_stats').checked) { |
|---|
| 390 | document.getElementById('teaser_template').disabled=false; |
|---|
| 391 | document.getElementById('teaser_template').className = "template"; |
|---|
| 392 | document.getElementById('omit_fullpost').disabled=false; |
|---|
| 393 | document.getElementById('omit_fullpost_label').className = ""; |
|---|
| 394 | document.getElementById('omit_fullpost_info').className = "info"; |
|---|
| 395 | document.getElementById('block_stats_before').disabled=false; |
|---|
| 396 | document.getElementById('block_stats_before_label').className = ""; |
|---|
| 397 | document.getElementById('block_stats_before_info').className = "info"; |
|---|
| 398 | if (!document.getElementById('omit_fullpost').checked) { |
|---|
| 399 | document.getElementById('full_template').disabled=false; |
|---|
| 400 | document.getElementById('full_template').className = "template"; |
|---|
| 401 | } |
|---|
| 402 | } else { |
|---|
| 403 | document.getElementById('teaser_template').disabled=true; |
|---|
| 404 | document.getElementById('teaser_template').className = "template grayout"; |
|---|
| 405 | document.getElementById('full_template').disabled=true; |
|---|
| 406 | document.getElementById('full_template').className = "template grayout"; |
|---|
| 407 | document.getElementById('omit_fullpost').disabled=true; |
|---|
| 408 | document.getElementById('omit_fullpost_label').className = "grayout"; |
|---|
| 409 | document.getElementById('omit_fullpost_info').className = "info grayout"; |
|---|
| 410 | document.getElementById('block_stats_before').disabled=true; |
|---|
| 411 | document.getElementById('block_stats_before_label').className = "grayout"; |
|---|
| 412 | document.getElementById('block_stats_before_info').className = "info grayout"; |
|---|
| 413 | } |
|---|
| 414 | }; |
|---|
| 415 | document.getElementById('omit_fullpost').onclick = function() { |
|---|
| 416 | if (document.getElementById('omit_fullpost').checked) { |
|---|
| 417 | document.getElementById('full_template').disabled=true; |
|---|
| 418 | document.getElementById('full_template').className = "template grayout"; |
|---|
| 419 | } else { |
|---|
| 420 | document.getElementById('full_template').disabled=false; |
|---|
| 421 | document.getElementById('full_template').className = "template"; |
|---|
| 422 | } |
|---|
| 423 | }; |
|---|
| 424 | document.getElementById('home_control').onclick = function() { |
|---|
| 425 | if (document.getElementById('home_control').checked) { |
|---|
| 426 | document.getElementById('home_disable').disabled=false; |
|---|
| 427 | document.getElementById('home_showall').disabled=false; |
|---|
| 428 | document.getElementById('home_disable_label').className = ""; |
|---|
| 429 | document.getElementById('home_showall_label').className = ""; |
|---|
| 430 | } else { |
|---|
| 431 | document.getElementById('home_disable').disabled=true; |
|---|
| 432 | document.getElementById('home_showall').disabled=true; |
|---|
| 433 | document.getElementById('home_disable_label').className = "grayout"; |
|---|
| 434 | document.getElementById('home_showall_label').className = "grayout"; |
|---|
| 435 | } |
|---|
| 436 | }; |
|---|
| 437 | document.getElementById('use_disable_filter').onclick = function() { |
|---|
| 438 | if (document.getElementById('use_disable_filter').checked) { |
|---|
| 439 | document.getElementById('disable_cat').disabled=false; |
|---|
| 440 | document.getElementById('disable_cat_always').disabled=false; |
|---|
| 441 | document.getElementById('disable_inverse').disabled=false; |
|---|
| 442 | document.getElementById('disable_tag').disabled=false; |
|---|
| 443 | document.getElementById('disable_tag_always').disabled=false; |
|---|
| 444 | document.getElementById('disable_cat_label').className = "indent"; |
|---|
| 445 | document.getElementById('disable_cat_info').className = "info"; |
|---|
| 446 | document.getElementById('disable_cat_always_label').className = ""; |
|---|
| 447 | document.getElementById('disable_cat_always_info').className = "info"; |
|---|
| 448 | document.getElementById('disable_inverse_label').className = ""; |
|---|
| 449 | document.getElementById('disable_inverse_info').className = "info"; |
|---|
| 450 | document.getElementById('disable_tag_label').className = "indent"; |
|---|
| 451 | document.getElementById('disable_tag_info').className = "info"; |
|---|
| 452 | document.getElementById('disable_tag_always_label').className = ""; |
|---|
| 453 | document.getElementById('disable_tag_always_info').className = "info"; |
|---|
| 454 | } else { |
|---|
| 455 | document.getElementById('disable_cat').disabled=true; |
|---|
| 456 | document.getElementById('disable_cat_always').disabled=true; |
|---|
| 457 | document.getElementById('disable_inverse').disabled=true; |
|---|
| 458 | document.getElementById('disable_tag').disabled=true; |
|---|
| 459 | document.getElementById('disable_tag_always').disabled=true; |
|---|
| 460 | document.getElementById('disable_cat_label').className = "grayout indent"; |
|---|
| 461 | document.getElementById('disable_cat_info').className = "grayout info"; |
|---|
| 462 | document.getElementById('disable_cat_always_label').className = "grayout"; |
|---|
| 463 | document.getElementById('disable_cat_always_info').className = "grayout info"; |
|---|
| 464 | document.getElementById('disable_inverse_label').className = "grayout"; |
|---|
| 465 | document.getElementById('disable_inverse_info').className = "grayout info"; |
|---|
| 466 | document.getElementById('disable_tag_label').className = "grayout indent"; |
|---|
| 467 | document.getElementById('disable_tag_info').className = "grayout info"; |
|---|
| 468 | document.getElementById('disable_tag_always_label').className = "grayout"; |
|---|
| 469 | document.getElementById('disable_tag_always_info').className = "grayout info"; |
|---|
| 470 | } |
|---|
| 471 | }; |
|---|
| 472 | document.getElementById('use_showall_filter').onclick = function() { |
|---|
| 473 | if (document.getElementById('use_showall_filter').checked) { |
|---|
| 474 | document.getElementById('showall_cat').disabled=false; |
|---|
| 475 | document.getElementById('showall_cat_always').disabled=false; |
|---|
| 476 | document.getElementById('showall_inverse').disabled=false; |
|---|
| 477 | document.getElementById('showall_tag').disabled=false; |
|---|
| 478 | document.getElementById('showall_tag_always').disabled=false; |
|---|
| 479 | document.getElementById('showall_cat_label').className = "indent"; |
|---|
| 480 | document.getElementById('showall_cat_info').className = "info"; |
|---|
| 481 | document.getElementById('showall_cat_always_label').className = ""; |
|---|
| 482 | document.getElementById('showall_cat_always_info').className = "info"; |
|---|
| 483 | document.getElementById('showall_inverse_label').className = ""; |
|---|
| 484 | document.getElementById('showall_inverse_info').className = "info"; |
|---|
| 485 | document.getElementById('showall_tag_label').className = "indent"; |
|---|
| 486 | document.getElementById('showall_tag_info').className = "info"; |
|---|
| 487 | document.getElementById('showall_tag_always_label').className = ""; |
|---|
| 488 | document.getElementById('showall_tag_always_info').className = "info"; |
|---|
| 489 | } else { |
|---|
| 490 | document.getElementById('showall_cat').disabled=true; |
|---|
| 491 | document.getElementById('showall_cat_always').disabled=true; |
|---|
| 492 | document.getElementById('showall_inverse').disabled=true; |
|---|
| 493 | document.getElementById('showall_tag').disabled=true; |
|---|
| 494 | document.getElementById('showall_tag_always').disabled=true; |
|---|
| 495 | document.getElementById('showall_cat_label').className = "grayout indent"; |
|---|
| 496 | document.getElementById('showall_cat_info').className = "grayout info"; |
|---|
| 497 | document.getElementById('showall_cat_always_label').className = "grayout"; |
|---|
| 498 | document.getElementById('showall_cat_always_info').className = "grayout info"; |
|---|
| 499 | document.getElementById('showall_inverse_label').className = "grayout"; |
|---|
| 500 | document.getElementById('showall_inverse_info').className = "grayout info"; |
|---|
| 501 | document.getElementById('showall_tag_label').className = "grayout indent"; |
|---|
| 502 | document.getElementById('showall_tag_info').className = "grayout info"; |
|---|
| 503 | document.getElementById('showall_tag_always_label').className = "grayout"; |
|---|
| 504 | document.getElementById('showall_tag_always_info').className = "grayout info"; |
|---|
| 505 | } |
|---|
| 506 | }; |
|---|
| 507 | document.getElementById('post_teaser_form').onsubmit = function() { |
|---|
| 508 | document.getElementById('teaser_template').disabled=false; |
|---|
| 509 | document.getElementById('more_template').disabled=false; |
|---|
| 510 | document.getElementById('full_template').disabled=false; |
|---|
| 511 | document.getElementById('home_control').disabled=false; |
|---|
| 512 | document.getElementById('home_disable').disabled=false; |
|---|
| 513 | document.getElementById('home_showall').disabled=false; |
|---|
| 514 | document.getElementById('disable_cat').disabled=false; |
|---|
| 515 | document.getElementById('disable_cat_always').disabled=false; |
|---|
| 516 | document.getElementById('disable_inverse').disabled=false; |
|---|
| 517 | document.getElementById('disable_tag').disabled=false; |
|---|
| 518 | document.getElementById('disable_tag_always').disabled=false; |
|---|
| 519 | document.getElementById('showall_cat').disabled=false; |
|---|
| 520 | document.getElementById('showall_cat_always').disabled=false; |
|---|
| 521 | document.getElementById('showall_inverse').disabled=false; |
|---|
| 522 | document.getElementById('showall_tag').disabled=false; |
|---|
| 523 | document.getElementById('showall_tag_always').disabled=false; |
|---|
| 524 | }; |
|---|
| 525 | document.getElementById('default-reset').onclick = function() { |
|---|
| 526 | if (confirm('<?php _e('Do you really want to reset all your configuration to the default values?', 'post-teaser') ?>')) |
|---|
| 527 | return true; |
|---|
| 528 | else |
|---|
| 529 | return false; |
|---|
| 530 | }; |
|---|
| 531 | |
|---|
| 532 | container, insert = null; |
|---|
| 533 | }; |
|---|
| 534 | //]]> |
|---|
| 535 | </script> |
|---|
| 536 | <?php |
|---|
| 537 | } |
|---|
| 538 | function option_page() { |
|---|
| 539 | ?> |
|---|
| 540 | <?php if ($_GET['saved'] == 'true'): ?> |
|---|
| 541 | <div style="background-color: rgb(207, 235, 247);" id="message" class="updated fade"><p><?php _e('Settings saved.', 'post-teaser') ?> <a href="<?php echo get_settings('siteurl'); ?>"><?php _e('View site »', 'post-teaser') ?></a></p></div> |
|---|
| 542 | <?php endif; ?> |
|---|
| 543 | |
|---|
| 544 | <div class="wrap"> |
|---|
| 545 | <div id="icon-options-general" class="icon32"><br /></div> |
|---|
| 546 | <h2><?php _e('Post Teaser Settings', 'post-teaser') ?></h2> |
|---|
| 547 | |
|---|
| 548 | <p><?php _e('You can configure Post Teaser here. You might also be interested in <a href="http://wordpress.org/extend/plugins/post-teaser/" title="The Documentation page for Post Teaser">viewing the latest documentation</a> or the <a href="http://wordpress.org/extend/plugins/post-teaser/faq/" title="The frequently asked question for Post Teaser">FAQ</a>.', 'post-teaser') ?></p> |
|---|
| 549 | |
|---|
| 550 | <form action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]); ?>" method="post" name="post_teaser_form" id="post_teaser_form"> |
|---|
| 551 | <fieldset class="options clearfix"> |
|---|
| 552 | <h3><?php _e('Basic settings', 'post-teaser') ?></h3> |
|---|
| 553 | |
|---|
| 554 | <p><?php printf(__('I would like the teaser to be as close to %s words as possible.', 'post-teaser'), '<input type="text" id="target" name="target" value="' . $this->target . '" />'); ?></p> |
|---|
| 555 | |
|---|
| 556 | <div class="right" id="key"> |
|---|
| 557 | <h3><?php _e('Placeholders', 'post-teaser') ?></h3> |
|---|
| 558 | |
|---|
| 559 | <p><?php _e('These will be replaced with the appropriate values when the plugin runs.', 'post-teaser') ?></p> |
|---|
| 560 | |
|---|
| 561 | <dl> |
|---|
| 562 | <dt>%title%</dt> |
|---|
| 563 | <dd><?php _e('The title of the post', 'post-teaser') ?></dd> |
|---|
| 564 | |
|---|
| 565 | <dt>%plain_title%</dt> |
|---|
| 566 | <dd><?php _e('The title in plain text with no <abbr title="Hypertext Markup Language">HTML</abbr> (to go in the <code>title</code> attribute of a link, for instance)', 'post-teaser') ?></dd> |
|---|
| 567 | |
|---|
| 568 | <dt>%permalink%</dt> |
|---|
| 569 | <dd><?php _e('The <abbr title="Uniform Resource Identifier">URI</abbr> of the post', 'post-teaser') ?></dd> |
|---|
| 570 | |
|---|
| 571 | <dt>%reading_time%</dt> |
|---|
| 572 | <dd><?php _e('An estimation of how long it will take to read', 'post-teaser') ?></dd> |
|---|
| 573 | |
|---|
| 574 | <dt>%word_image_count%</dt> |
|---|
| 575 | <dd><?php _e('A count of the number of words and images in the post', 'post-teaser') ?></dd> |
|---|
| 576 | </dl> |
|---|
| 577 | </div> |
|---|
| 578 | |
|---|
| 579 | <div class="left" id="templates"> |
|---|
| 580 | |
|---|
| 581 | <div id="teaser_template_container"> |
|---|
| 582 | <p><?php _e('If the post is made into a teaser, I want the message to be in the following format:', 'post-teaser') ?></p> |
|---|
| 583 | <textarea name="teaser_template" id="teaser_template" rows="4" cols="80" class="template"><?php echo htmlspecialchars($this->teaser_template); ?></textarea> |
|---|
| 584 | </div> |
|---|
| 585 | |
|---|
| 586 | <div id="more_template_container"> |
|---|
| 587 | <p><?php _e('If read more link is enabled, I want the message to be in the following format:', 'post-teaser') ?></p> |
|---|
| 588 | <textarea name="more_template" id="more_template" rows="4" cols="80" class="template"><?php echo htmlspecialchars($this->more_template); ?></textarea> |
|---|
| 589 | </div> |
|---|
| 590 | |
|---|
| 591 | <div id="full_template_container"> |
|---|
| 592 | <p><?php _e('If the post is displayed in full, I want the message to be in the following format:', 'post-teaser') ?></p> |
|---|
| 593 | <textarea name="full_template" id="full_template" rows="4" cols="80" class="template"><?php echo htmlspecialchars($this->full_template); ?></textarea> |
|---|
| 594 | </div> |
|---|
| 595 | </div> |
|---|
| 596 | </fieldset> |
|---|
| 597 | |
|---|
| 598 | <fieldset class="options"> |
|---|
| 599 | <h3><?php _e('Tease message control', 'post-teaser') ?></h3> |
|---|
| 600 | |
|---|
| 601 | <p><label> |
|---|
| 602 | <?php if ($this->more_link == '1'): ?> |
|---|
| 603 | <input type="checkbox" name="more_link" id="more_link" checked="checked" /> |
|---|
| 604 | <?php else: ?> |
|---|
| 605 | <input type="checkbox" name="more_link" id="more_link" /> |
|---|
| 606 | <?php endif; ?> |
|---|
| 607 | <?php _e("Show read more link at the end of teased post", 'post-teaser') ?> <span class="info"><?php _e("(immediately following post text with no line-breaks)", 'post-teaser') ?></span> |
|---|
| 608 | </label></p> |
|---|
| 609 | |
|---|
| 610 | <p><label> |
|---|
| 611 | <?php if ($this->block_stats == '1'): ?> |
|---|
| 612 | <input type="checkbox" name="block_stats" id="block_stats" checked="checked" /> |
|---|
| 613 | <?php else: ?> |
|---|
| 614 | <input type="checkbox" name="block_stats" id="block_stats" /> |
|---|
| 615 | <?php endif; ?> |
|---|
| 616 | <?php _e("Show post statistics as block", 'post-teaser') ?> <span class="info"><?php _e("(original style teaser massage with paragraph break after post text)", 'post-teaser') ?></span> |
|---|
| 617 | </label></p> |
|---|
| 618 | |
|---|
| 619 | <p class="indent"><label> |
|---|
| 620 | <?php if ($this->block_stats_before == '1'): ?> |
|---|
| 621 | <input type="checkbox" name="block_stats_before" id="block_stats_before" checked="checked" /> |
|---|
| 622 | <?php else: ?> |
|---|
| 623 | <input type="checkbox" name="block_stats_before" id="block_stats_before" /> |
|---|
| 624 | <?php endif; ?> |
|---|
| 625 | <span id="block_stats_before_label"><?php _e("Show post statistic block before post", 'post-teaser') ?></span> <span id="block_stats_before_info" class="info"><?php _e("(by default post statistic block appears after post)", 'post-teaser') ?></span> |
|---|
| 626 | </label></p> |
|---|
| 627 | |
|---|
| 628 | <p class="indent"><label> |
|---|
| 629 | <?php if ($this->omit_fullpost == '1'): ?> |
|---|
| 630 | <input type="checkbox" name="omit_fullpost" id="omit_fullpost" checked="checked" /> |
|---|
| 631 | <?php else: ?> |
|---|
| 632 | <input type="checkbox" name="omit_fullpost" id="omit_fullpost" /> |
|---|
| 633 | <?php endif; ?> |
|---|
| 634 | <span id="omit_fullpost_label"><?php _e("Omit post statistics for fullpost", 'post-teaser') ?></span> <span id="omit_fullpost_info" class="info"><?php _e("(suppress post statistic if fullpost is showned)", 'post-teaser') ?></span> |
|---|
| 635 | </label></p> |
|---|
| 636 | </fieldset> |
|---|
| 637 | |
|---|
| 638 | <fieldset class="options"> |
|---|
| 639 | <h3><?php _e('Advance tease control', 'post-teaser') ?></h3> |
|---|
| 640 | |
|---|
| 641 | <p><em> |
|---|
| 642 | <?php _e("The filters below follows the precedence (priority) as it is ordered below if there are confilcts in the filters setting") ?> |
|---|
| 643 | <?php echo "<br />" ?> |
|---|
| 644 | <?php _e("(i.e. the first filter overwrites the second and so on)") ?> |
|---|
| 645 | </em></p> |
|---|
| 646 | |
|---|
| 647 | <p><label> |
|---|
| 648 | <?php if ($this->home_control == '1'): ?> |
|---|
| 649 | <input type="checkbox" name="home_control" id="home_control" checked="checked" /> |
|---|
| 650 | <?php else: ?> |
|---|
| 651 | <input type="checkbox" name="home_control" id="home_control" /> |
|---|
| 652 | <?php endif; ?> |
|---|
| 653 | <span id="home_control_label"><?php _e("Control tease in homepage", 'post-teaser') ?></span> <span id="home_control_info" class="info"><?php _e("(allows disabling tease or force fullpost on homepage)", 'post-teaser') ?></span> |
|---|
| 654 | </label></p> |
|---|
| 655 | |
|---|
| 656 | <p class="indent"><label> |
|---|
| 657 | <?php if ($this->home_disable == '1'): ?> |
|---|
| 658 | <input type="radio" name="home_control_opt" value="home_disable" id="home_disable" checked /> |
|---|
| 659 | <?php else: ?> |
|---|
| 660 | <input type="radio" name="home_control_opt" value="home_disable" id="home_disable" /> |
|---|
| 661 | <?php endif; ?> |
|---|
| 662 | <span id="home_disable_label"><?php _e("Disable tease in homepage", 'post-teaser') ?></span> |
|---|
| 663 | </label></p> |
|---|
| 664 | |
|---|
| 665 | <p class="indent"><label> |
|---|
| 666 | <?php if ($this->home_showall == '1'): ?> |
|---|
| 667 | <input type="radio" name="home_control_opt" value="home_showall" id="home_showall" checked /> |
|---|
| 668 | <?php else: ?> |
|---|
| 669 | <input type="radio" name="home_control_opt" value="home_showall" id="home_showall" /> |
|---|
| 670 | <?php endif; ?> |
|---|
| 671 | <span id="home_showall_label"><?php _e("Show fullpost in homepage", 'post-teaser') ?></span> |
|---|
| 672 | </label></p> |
|---|
| 673 | |
|---|
| 674 | <p><label> |
|---|
| 675 | <?php if ($this->use_disable_filter == '1'): ?> |
|---|
| 676 | <input type="checkbox" name="use_disable_filter" id="use_disable_filter" checked="checked" /> |
|---|
| 677 | <?php else: ?> |
|---|
| 678 | <input type="checkbox" name="use_disable_filter" id="use_disable_filter" /> |
|---|
| 679 | <?php endif; ?> |
|---|
| 680 | <?php _e("Use filters to disable tease", 'post-teaser') ?> <span class="info"><?php _e("(prevent PostTeaser from processing matched post)", 'post-teaser') ?></span> |
|---|
| 681 | </label></p> |
|---|
| 682 | |
|---|
| 683 | <p class="indent"><label> |
|---|
| 684 | <?php if ($this->disable_inverse == '1'): ?> |
|---|
| 685 | <input type="checkbox" name="disable_inverse" id="disable_inverse" checked="checked" /> |
|---|
| 686 | <?php else: ?> |
|---|
| 687 | <input type="checkbox" name="disable_inverse" id="disable_inverse" /> |
|---|
| 688 | <?php endif; ?> |
|---|
| 689 | <span id="disable_inverse_label"><?php _e("Disable tease for categories and/or tags excluded in the list", 'post-teaser') ?></span> <span id="disable_inverse_info" class="info"><?php _e("(If unchecked categories and/or tags in the list is inclusive)", 'post-teaser') ?></span> |
|---|
| 690 | </label></p> |
|---|
| 691 | |
|---|
| 692 | <p id="disable_cat_label" class="indent"><?php _e('In archive pages of category:', 'post-teaser') ?> <input type="text" id="disable_cat" name="disable_cat" value="<?php echo $this->disable_cat; ?>" /> <span id="disable_cat_info" class="info"><?php _e('(comma separated list in any combination of category name, id, or slug)', 'post-teaser') ?></span></p> |
|---|
| 693 | |
|---|
| 694 | <p class="indent2"><label> |
|---|
| 695 | <?php if ($this->disable_cat_always == '1'): ?> |
|---|
| 696 | <input type="checkbox" name="disable_cat_always" id="disable_cat_always" checked="checked" /> |
|---|
| 697 | <?php else: ?> |
|---|
| 698 | <input type="checkbox" name="disable_cat_always" id="disable_cat_always" /> |
|---|
| 699 | <?php endif; ?> |
|---|
| 700 | <span id="disable_cat_always_label"><?php _e("Always apply filter to post even in non-category archive pages", 'post-teaser') ?></span> <span id="disable_cat_always_info" class="info"><?php _e("(e.g. in homepage)", 'post-teaser') ?></span> |
|---|
| 701 | </label></p> |
|---|
| 702 | |
|---|
| 703 | <p id="disable_tag_label" class="indent"><?php _e('In archive pages of tag:', 'post-teaser') ?> <input type="text" id="disable_tag" name="disable_tag" value="<?php echo $this->disable_tag; ?>" /> <span id="disable_tag_info" class="info"><?php _e('(comma separated list in any combination of tag name, id, or slug)', 'post-teaser') ?></span></p> |
|---|
| 704 | <p class="indent2"><label> |
|---|
| 705 | <?php if ($this->disable_tag_always == '1'): ?> |
|---|
| 706 | <input type="checkbox" name="disable_tag_always" id="disable_tag_always" checked="checked" /> |
|---|
| 707 | <?php else: ?> |
|---|
| 708 | <input type="checkbox" name="disable_tag_always" id="disable_tag_always" /> |
|---|
| 709 | <?php endif; ?> |
|---|
| 710 | <span id="disable_tag_always_label"><?php _e("Always apply filter to post even in non-tag archive pages", 'post-teaser') ?></span> <span id="disable_tag_always_info" class="info"><?php _e("(e.g. in homepage)", 'post-teaser') ?></span> |
|---|
| 711 | </label></p> |
|---|
| 712 | </fieldset> |
|---|
| 713 | |
|---|
| 714 | <p><label> |
|---|
| 715 | <?php if ($this->use_showall_filter == '1'): ?> |
|---|
| 716 | <input type="checkbox" name="use_showall_filter" id="use_showall_filter" checked="checked" /> |
|---|
| 717 | <?php else: ?> |
|---|
| 718 | <input type="checkbox" name="use_showall_filter" id="use_showall_filter" /> |
|---|
| 719 | <?php endif; ?> |
|---|
| 720 | <?php _e("Use filters to force fullpost", 'post-teaser') ?> <span class="info"><?php _e("(disable tease but process post for statistic)", 'post-teaser') ?></span> |
|---|
| 721 | </label></p> |
|---|
| 722 | |
|---|
| 723 | <p class="indent"><label> |
|---|
| 724 | <?php if ($this->showall_inverse == '1'): ?> |
|---|
| 725 | <input type="checkbox" name="showall_inverse" id="showall_inverse" checked="checked" /> |
|---|
| 726 | <?php else: ?> |
|---|
| 727 | <input type="checkbox" name="showall_inverse" id="showall_inverse" /> |
|---|
| 728 | <?php endif; ?> |
|---|
| 729 | <span id="showall_inverse_label"><?php _e("Show fullpost for categories and/or tags excluded in the list", 'post-teaser') ?></span> <span id="showall_inverse_info" class="info"><?php _e("(If unchecked categories and/or tags in the list is inclusive)", 'post-teaser') ?></span> |
|---|
| 730 | </label></p> |
|---|
| 731 | |
|---|
| 732 | <p id="showall_cat_label" class="indent"><?php _e('In archive pages of category:', 'post-teaser') ?> <input type="text" id="showall_cat" name="showall_cat" value="<?php echo $this->showall_cat; ?>" /> <span id="showall_cat_info" class="info"><?php _e('(comma separated list in any combination of category name, id, or slug)', 'post-teaser') ?></span></p> |
|---|
| 733 | |
|---|
| 734 | <p class="indent2"><label> |
|---|
| 735 | <?php if ($this->showall_cat_always == '1'): ?> |
|---|
| 736 | <input type="checkbox" name="showall_cat_always" id="showall_cat_always" checked="checked" /> |
|---|
| 737 | <?php else: ?> |
|---|
| 738 | <input type="checkbox" name="showall_cat_always" id="showall_cat_always" /> |
|---|
| 739 | <?php endif; ?> |
|---|
| 740 | <span id="showall_cat_always_label"><?php _e("Always apply filter to post even in non-category archive pages", 'post-teaser') ?></span> <span id="showall_cat_always_info" class="info"><?php _e("(e.g. in homepage)", 'post-teaser') ?></span> |
|---|
| 741 | </label></p> |
|---|
| 742 | |
|---|
| 743 | <p id="showall_tag_label" class="indent"><?php _e('In archive pages of tag:', 'post-teaser') ?> <input type="text" id="showall_tag" name="showall_tag" value="<?php echo $this->showall_tag; ?>" /> <span id="showall_tag_info" class="info"><?php _e('(comma separated list in any combination of tag name, id, or slug)', 'post-teaser') ?></span></p> |
|---|
| 744 | <p class="indent2"><label> |
|---|
| 745 | <?php if ($this->showall_tag_always == '1'): ?> |
|---|
| 746 | <input type="checkbox" name="showall_tag_always" id="showall_tag_always" checked="checked" /> |
|---|
| 747 | <?php else: ?> |
|---|
| 748 | <input type="checkbox" name="showall_tag_always" id="showall_tag_always" /> |
|---|
| 749 | <?php endif; ?> |
|---|
| 750 | <span id="showall_tag_always_label"><?php _e("Always apply filter to post even in non-tag archive pages", 'post-teaser') ?></span> <span id="showall_tag_always_info" class="info"><?php _e("(e.g. in homepage)", 'post-teaser') ?></span> |
|---|
| 751 | </label></p> |
|---|
| 752 | </fieldset> |
|---|
| 753 | |
|---|
| 754 | <fieldset class="options"> |
|---|
| 755 | <h3><?php _e('Fine tuning', 'post-teaser') ?></h3> |
|---|
| 756 | |
|---|
| 757 | <p><?php _e('Show seconds like this:', 'post-teaser') ?> <span class="example">54 <input type="text" id="word_secs" name="word_secs" value="<?php echo $this->word_secs; ?>" /></span></p> |
|---|
| 758 | |
|---|
| 759 | <p><?php _e('Show minutes like this:', 'post-teaser') ?> |
|---|
| 760 | <select id="time_separator" name="time_separator" class="example"> |
|---|
| 761 | <?php |
|---|
| 762 | $separators = array |
|---|
| 763 | ( |
|---|
| 764 | 0 => ':', |
|---|
| 765 | 1 => '.', |
|---|
| 766 | 2 => '-' |
|---|
| 767 | ); |
|---|
| 768 | foreach ($separators as $separator) { |
|---|
| 769 | if ($separator == $this->time_separator) |
|---|
| 770 | echo "<option value=\"$separator\" selected=\"selected\">3{$separator}34</option>"; |
|---|
| 771 | else |
|---|
| 772 | echo "<option value=\"$separator\">3{$separator}34</option>"; |
|---|
| 773 | } |
|---|
| 774 | ?> |
|---|
| 775 | </select> |
|---|
| 776 | <input type="text" id="word_mins" name="word_mins" class="example" value="<?php echo $this->word_mins; ?>" /> |
|---|
| 777 | </p> |
|---|
| 778 | |
|---|
| 779 | <p><?php _e('Show word and image counts like this:', 'post-teaser') ?> |
|---|
| 780 | <select name="count_separator" id="count_separator" class="example"> |
|---|
| 781 | <?php |
|---|
| 782 | $separators = array |
|---|
| 783 | ( |
|---|
| 784 | 0 => ', ', |
|---|
| 785 | 1 => __(' and ', 'post-teaser'), |
|---|
| 786 | 2 => ' & ', |
|---|
| 787 | 3 => ' + ' |
|---|
| 788 | ); |
|---|
| 789 | foreach ($separators as $separator) { |
|---|
| 790 | if ($separator == $this->count_separator) |
|---|
| 791 | echo "<option value=\"$separator\" selected=\"selected\">462 ". __('words', 'post-teaser'). $separator. '3 '. __('images', 'post-teaser'). '</option>'; |
|---|
| 792 | else |
|---|
| 793 | echo "<option value=\"$separator\">462 ". __('words', 'post-teaser'). $separator. '3 '. __('images', 'post-teaser'). '</option>'; |
|---|
| 794 | } |
|---|
| 795 | ?> |
|---|
| 796 | </select></p> |
|---|
| 797 | |
|---|
| 798 | <p><label> |
|---|
| 799 | <?php if ($this->zero_counts == '1'): ?> |
|---|
| 800 | <input type="checkbox" name="zero_counts" id="zero_counts" checked="checked" /> |
|---|
| 801 | <?php else: ?> |
|---|
| 802 | <input type="checkbox" name="zero_counts" id="zero_counts" /> |
|---|
| 803 | <?php endif; ?> |
|---|
| 804 | <?php _e("Show the count of images or words, even if it's zero", 'post-teaser') ?> |
|---|
| 805 | </label></p> |
|---|
| 806 | </fieldset> |
|---|
| 807 | |
|---|
| 808 | <p class="submit"> |
|---|
| 809 | <input type="hidden" name="post_teaser_submit" value="1" /> |
|---|
| 810 | <input type="submit" value="<?php _e('Reset to defaults', 'post-teaser') ?>" name="submit_reset" id="default-reset" /> |
|---|
| 811 | <input type="submit" value="<?php _e('Update Options', 'post-teaser')?> »" name="submit_update" /> |
|---|
| 812 | </p> |
|---|
| 813 | </form> |
|---|
| 814 | </div> |
|---|
| 815 | <?php |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | /*** Debugging ***/ |
|---|
| 819 | var $debug_message; |
|---|
| 820 | function debug($message) { |
|---|
| 821 | if ($this->debug) |
|---|
| 822 | $this->debug_message .= $message . "\n"; |
|---|
| 823 | } |
|---|
| 824 | |
|---|
| 825 | /*** Replaces placeholders with the relevant values ***/ |
|---|
| 826 | function placeholders($template) { |
|---|
| 827 | $template = str_replace('%title%', the_title('', '', false), $template); |
|---|
| 828 | $template = str_replace('%plain_title%', strip_tags(str_replace('"', '"', the_title('', '', false))), $template); |
|---|
| 829 | $template = str_replace('%permalink%', get_permalink(), $template); |
|---|
| 830 | $template = str_replace('%word_image_count%', $this->word_image_count, $template); |
|---|
| 831 | $template = str_replace('%reading_time%', $this->reading_time, $template); |
|---|
| 832 | return $template; |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| 835 | /*** Counts words. PHP's str_word_count() only works for alphabetic characters ***/ |
|---|
| 836 | function word_count($text) { |
|---|
| 837 | $text = strip_tags($text); |
|---|
| 838 | $text = preg_split("/\s+/", $text); |
|---|
| 839 | $count = count($text); |
|---|
| 840 | return $count; |
|---|
| 841 | } |
|---|
| 842 | |
|---|
| 843 | /*** Where all the conditions we don't want to tease are checked here ***/ |
|---|
| 844 | function is_disabled() { |
|---|
| 845 | global $post, $cookiehash, $action, $sem_home_page; |
|---|
| 846 | |
|---|
| 847 | if (is_singular()) |
|---|
| 848 | return true; |
|---|
| 849 | elseif (is_feed()) |
|---|
| 850 | return true; |
|---|
| 851 | elseif ((!empty($post->post_password)) && ($_COOKIE['wp-postpass_' . $cookiehash] != $post->post_password)) |
|---|
| 852 | return true; |
|---|
| 853 | elseif ($action == 'editpost' || $action == 'edit') |
|---|
| 854 | return true; |
|---|
| 855 | elseif ($this->meta == 'disable') |
|---|
| 856 | return true; |
|---|
| 857 | elseif (isset($sem_home_page) && is_home() && function_exists('sem_static_front')) // Semilogic static front page |
|---|
| 858 | return true; |
|---|
| 859 | elseif ($this->home_control && is_home()) { // Must be last in chain of elseif because of nested if |
|---|
| 860 | if ($this->home_disable) |
|---|
| 861 | return true; |
|---|
| 862 | else |
|---|
| 863 | return false; // Skip the rest of the test if it is homepage and showall is selected |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | if ($this->use_disable_filter) { |
|---|
| 867 | if ($this->disable_cat && |
|---|
| 868 | (($this->disable_cat_always == '1' && in_category(array($this->disable_cat))) || |
|---|
| 869 | is_category(array($this->disable_cat)) ) ) { |
|---|
| 870 | if ($this->disable_inverse) |
|---|
| 871 | return false; |
|---|
| 872 | else |
|---|
| 873 | return true; |
|---|
| 874 | } elseif ($this->disable_tag && |
|---|
| 875 | (($this->disable_tag_always == '1' && has_tag(array($this->disable_tag))) || |
|---|
| 876 | is_tag(array($this->disable_tag)) ) ) { |
|---|
| 877 | if ($this->disable_inverse) |
|---|
| 878 | return false; |
|---|
| 879 | else |
|---|
| 880 | return true; |
|---|
| 881 | } |
|---|
| 882 | } |
|---|
| 883 | if ($this->use_disable_filter && $this->disable_inverse) |
|---|
| 884 | return true; |
|---|
| 885 | |
|---|
| 886 | return false; |
|---|
| 887 | } |
|---|
| 888 | |
|---|
| 889 | /*** Where all the conditions for showall are checked here ***/ |
|---|
| 890 | function is_showall() { |
|---|
| 891 | if ($this->meta == 'showall') |
|---|
| 892 | return true; |
|---|
| 893 | elseif ($this->home_control && $this->home_showall && is_home()) |
|---|
| 894 | return true; |
|---|
| 895 | |
|---|
| 896 | if ($this->use_showall_filter) { |
|---|
| 897 | if ($this->showall_cat && |
|---|
| 898 | (($this->showall_cat_always == '1' && in_category(array($this->showall_cat))) || |
|---|
| 899 | is_category(array($this->showall_cat)) ) ) |
|---|
| 900 | if ($this->showall_inverse) |
|---|
| 901 | return false; |
|---|
| 902 | else |
|---|
| 903 | return true; |
|---|
| 904 | elseif ($this->showall_tag && |
|---|
| 905 | (($this->showall_tag_always == '1' && has_tag(array($this->showall_tag))) || |
|---|
| 906 | is_tag(array($this->showall_tag)) ) ) |
|---|
| 907 | if ($this->showall_inverse) |
|---|
| 908 | return false; |
|---|
| 909 | else |
|---|
| 910 | return true; |
|---|
| 911 | } |
|---|
| 912 | if ($this->use_showall_filter && $this->showall_inverse) |
|---|
| 913 | return true; |
|---|
| 914 | |
|---|
| 915 | return false; |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | /*** The real business happens here. Every post is run through this method ***/ |
|---|
| 919 | function process($content) { |
|---|
| 920 | global $post, $pages, $page, $multipage; |
|---|
| 921 | |
|---|
| 922 | $matches = null; |
|---|
| 923 | $matches2 = null; |
|---|
| 924 | $auto_close = array(); |
|---|
| 925 | $this->debug_message = ''; |
|---|
| 926 | $this->meta = get_post_meta($post->ID, 'teaser', true); |
|---|
| 927 | |
|---|
| 928 | /*** Checks for when we don't want to teaser stuff ***/ |
|---|
| 929 | if ($this->is_disabled()) |
|---|
| 930 | return $content; |
|---|
| 931 | |
|---|
| 932 | $this->debug('Starting teaser (got through the checks), version number is ' . $this->version); |
|---|
| 933 | |
|---|
| 934 | $showall = $this->is_showall(); |
|---|
| 935 | |
|---|
| 936 | /*** Deal with <!--more--> and <!--nextpage--> (this is very hackish) ***/ |
|---|
| 937 | $plain_content = $pages[$page-1]; |
|---|
| 938 | if (strstr($plain_content, '<!--more-->')) { |
|---|
| 939 | $this->debug('A "more" tag has been detected... it will be replaced with the teaser text.'); |
|---|
| 940 | $matches[0] = preg_replace('!<a href="'. preg_quote(get_permalink()) . '#more-' . $post->ID . '".+?>.+?</a>!', '', $content); |
|---|
| 941 | |
|---|
| 942 | $matches[0] = preg_replace('!<p>\s+</p>!', '', $matches[0]); |
|---|
| 943 | $matches[0] = preg_replace('!<br />\s*</p>!', '</p>', $matches[0]); |
|---|
| 944 | |
|---|
| 945 | // Get rid of any closing tags at the end of the content as there have |
|---|
| 946 | // been some nesting validation issues (due to WP clashing) and they will be |
|---|
| 947 | // automatically closed in order anyway (see below) |
|---|
| 948 | $matches[0] = preg_replace('!(</([a-zA-Z1-9]+)>\s*)+\s*$!', '', $matches[0]); |
|---|
| 949 | |
|---|
| 950 | $i = 0; |
|---|
| 951 | $content = $plain_content; |
|---|
| 952 | $more = true; |
|---|
| 953 | } |
|---|
| 954 | if ($multipage) { |
|---|
| 955 | $this->debug('A "nextpage" tag has been detected.'); |
|---|
| 956 | if ($more) |
|---|
| 957 | $content_temp = $matches[0]; |
|---|
| 958 | else |
|---|
| 959 | $content_temp = $content; |
|---|
| 960 | $content = ''; |
|---|
| 961 | foreach ($pages as $item) |
|---|
| 962 | $content .= $item; |
|---|
| 963 | } |
|---|
| 964 | if (($more || $multipage) && ($this->doing_reading_time || $this->doing_counts)) { |
|---|
| 965 | remove_filter('the_content', array(&$this, 'process'), 20); |
|---|
| 966 | $content = apply_filters('the_content', $content); |
|---|
| 967 | add_filter('the_content', array(&$this, 'process'), 20); |
|---|
| 968 | $content = str_replace(']]>', ']]>', $content); |
|---|
| 969 | } |
|---|
| 970 | |
|---|
| 971 | /*** Reading time ***/ |
|---|
| 972 | if ($this->doing_reading_time) { |
|---|
| 973 | $this->debug('Start of reading time calculation'); |
|---|
| 974 | $average = $this->word_count($content) / 250 * 60; |
|---|
| 975 | $min = (int) ($average / 60); |
|---|
| 976 | $sec = round(fmod($average, 60)); |
|---|
| 977 | if ($sec < 10) |
|---|
| 978 | $sec = '0' . $sec; |
|---|
| 979 | elseif ($sec == 60) { // Fix seconds round to 60 issue |
|---|
| 980 | $min = $min + 1; |
|---|
| 981 | $sec = 0; |
|---|
| 982 | } |
|---|
| 983 | if ($min == 0) |
|---|
| 984 | $this->reading_time = ($min * 60 + $sec) . ' ' . $this->word_secs; |
|---|
| 985 | else |
|---|
| 986 | $this->reading_time = $min . $this->time_separator . $sec . ' ' . $this->word_mins; |
|---|
| 987 | $this->debug("End of reading time calculation. Result = {$this->reading_time}, sec = $sec, min = $min"); |
|---|
| 988 | } |
|---|
| 989 | |
|---|
| 990 | /*** Word/image count ***/ |
|---|
| 991 | if ($this->doing_counts) { |
|---|
| 992 | $this->debug('Start of word/image count calculation'); |
|---|
| 993 | $word_count = $this->word_count($content); |
|---|
| 994 | if (!$this->zero_counts && $word_count == 0) |
|---|
| 995 | $word_count = ''; |
|---|
| 996 | else |
|---|
| 997 | $word_count .= ($word_count == 1) ? __(' word', 'post-teaser') : __(' words', 'post-teaser'); |
|---|
| 998 | |
|---|
| 999 | $temp = preg_replace('/<img[^>]*class=\'wp-smiley\'[^>]*>/i', '', $content); |
|---|
| 1000 | $image_count = preg_match_all('/<img[^>]*>/i', $temp, $matches2); |
|---|
| 1001 | if (!$this->zero_counts && $image_count == 0) |
|---|
| 1002 | $image_count = ""; |
|---|
| 1003 | else |
|---|
| 1004 | $image_count .= ($image_count == 1) ? __(' image', 'post-teaser') : __(' images', 'post-teaser'); |
|---|
| 1005 | |
|---|
| 1006 | $this->word_image_count = $word_count; |
|---|
| 1007 | if ($word_count && $image_count) |
|---|
| 1008 | $this->word_image_count .= $this->count_separator; |
|---|
| 1009 | $this->word_image_count .= $image_count; |
|---|
| 1010 | $this->debug("End of word/image count calculation. Result = {$this->word_image_count}, words = $word_count, images = $image_count"); |
|---|
| 1011 | } |
|---|
| 1012 | |
|---|
| 1013 | if ($multipage) |
|---|
| 1014 | $content = $content_temp; |
|---|
| 1015 | |
|---|
| 1016 | /*** |
|---|
| 1017 | This is how it works: |
|---|
| 1018 | * Split posts into "blocks" |
|---|
| 1019 | * Find the first block which would produce a cumulative word count greater than the target |
|---|
| 1020 | * Decrement this value if the block before it is closer to the target |
|---|
| 1021 | * Decide whether to make a "teaser" of the post based on whether that chosen block is the last one. |
|---|
| 1022 | Exceptions: |
|---|
| 1023 | * If it has a <!--more--> tag, it's teasered regardless |
|---|
| 1024 | * If the post has a "teaser" custom field with a value of "showall", it will be returned in full regardless (and <!--more--> is over-ridden) |
|---|
| 1025 | * If the post is teasered: |
|---|
| 1026 | * Put all (X)HTML starting tags into an array |
|---|
| 1027 | * From this array, get the actual element names, and exclude self-closing tags (like <br />). What's left goes into $auto_close |
|---|
| 1028 | * Unset each element as a closing tag is found for it |
|---|
| 1029 | * The elements left over must have been chopped in half -- give them a closing tag |
|---|
| 1030 | ***/ |
|---|
| 1031 | if (!$more && !$showall) { |
|---|
| 1032 | preg_match_all("!.*?<({$this->blocks})[^>]*>.+?</\\1>!si", $content, $matches); |
|---|
| 1033 | $matches = $matches[0]; |
|---|
| 1034 | $block_count = count($matches); |
|---|
| 1035 | $this->debug("Number of blocks: $block_count"); |
|---|
| 1036 | |
|---|
| 1037 | $current_word_count = 0; |
|---|
| 1038 | $block_word_count = array(); |
|---|
| 1039 | for ($i = 0; $current_word_count < $this->target && $i < $block_count; /* (increment is conditional, see below) */) { |
|---|
| 1040 | $block_word_count[$i] = $this->word_count($matches[$i]); |
|---|
| 1041 | $current_word_count += $block_word_count[$i]; |
|---|
| 1042 | if ($current_word_count < $this->target) |
|---|
| 1043 | $i++; |
|---|
| 1044 | } |
|---|
| 1045 | $this->debug("Finished looping through on block #$i (starts at zero). Cumulative word count was $current_word_count. Target was {$this->target}."); |
|---|
| 1046 | |
|---|
| 1047 | if ($current_word_count >= $this->target && $i > 0) { // No need if it will definitely not be teasered |
|---|
| 1048 | $this_block_distance = $current_word_count - $this->target; |
|---|
| 1049 | $last_block_distance = $this->target - ($current_word_count - $block_word_count[$i]); |
|---|
| 1050 | $this->debug("Current block is $this_block_distance words from target, previous block is $last_block_distance words from target."); |
|---|
| 1051 | if ($this_block_distance > $last_block_distance) { |
|---|
| 1052 | $i--; |
|---|
| 1053 | $this->debug("Decremented to $i"); |
|---|
| 1054 | } |
|---|
| 1055 | } |
|---|
| 1056 | } |
|---|
| 1057 | |
|---|
| 1058 | if (($i + 1 < $block_count || $more) && !$showall) { |
|---|
| 1059 | $this->debug('Post will be teasered'); |
|---|
| 1060 | $fullpost = false; |
|---|
| 1061 | |
|---|
| 1062 | for ($j = 0; $j <= $i; $j++) { |
|---|
| 1063 | preg_match_all('!<(?:[a-zA-Z1-9]+)[^>]*>!i', $matches[$j], $matches2); |
|---|
| 1064 | $matches2 = $matches2[0]; |
|---|
| 1065 | foreach ($matches2 as $id => $element) { |
|---|
| 1066 | if (preg_match('!^<([a-zA-Z1-9]+)[^>]*/>$!i', $element)) { |
|---|
| 1067 | unset($matches2[$id]); |
|---|
| 1068 | continue; |
|---|
| 1069 | } |
|---|
| 1070 | $element = preg_replace('!^<([a-zA-Z1-9]+)[^>]*>$!i', "$1", $element); |
|---|
| 1071 | $auto_close[] = $element; |
|---|
| 1072 | } |
|---|
| 1073 | } |
|---|
| 1074 | |
|---|
| 1075 | $content = ''; |
|---|
| 1076 | for ($j = 0; $j <= $i; $j++) { |
|---|
| 1077 | $temp = $matches[$j]; |
|---|
| 1078 | |
|---|
| 1079 | foreach ($auto_close as $id => $element) { |
|---|
| 1080 | $pos = strpos(" " . $temp, "</$element>"); // Space at front because 0 == false |
|---|
| 1081 | if ($pos) { |
|---|
| 1082 | $temp = substr_replace($temp, '', $pos, strlen("</$element>")); // Makes sure a closing tag is not counted more than once |
|---|
| 1083 | unset($auto_close[$id]); |
|---|
| 1084 | } |
|---|
| 1085 | } |
|---|
| 1086 | if (!$this->debug) |
|---|
| 1087 | $content .= $matches[$j]; |
|---|
| 1088 | else |
|---|
| 1089 | $content .= "\n<!--[start $j, count: " . $block_word_count[$j] . "]-->\n" . $matches[$j] . "\n<!--[end $j]-->\n"; |
|---|
| 1090 | } |
|---|
| 1091 | $auto_close = array_reverse($auto_close); |
|---|
| 1092 | foreach ($auto_close as $element) |
|---|
| 1093 | $content .= "</$element>"; |
|---|
| 1094 | |
|---|
| 1095 | if ($this->more_link) { |
|---|
| 1096 | $lastp = strrpos($content, "</p>"); |
|---|
| 1097 | |
|---|
| 1098 | if ($lastp) { |
|---|
| 1099 | $more_template =& $this->more_template; |
|---|
| 1100 | $teaser_str = " <span class=\"post-teaser-more\">" . $this->placeholders($more_template) . '</span>'; |
|---|
| 1101 | $content = substr_replace($content, $teaser_str, $lastp, 0); |
|---|
| 1102 | } |
|---|
| 1103 | } |
|---|
| 1104 | |
|---|
| 1105 | $template =& $this->teaser_template; |
|---|
| 1106 | } else { |
|---|
| 1107 | $this->debug('Post is being returned in full'); |
|---|
| 1108 | $fullpost = true; |
|---|
| 1109 | |
|---|
| 1110 | $template =& $this->full_template; |
|---|
| 1111 | } |
|---|
| 1112 | |
|---|
| 1113 | if ($this->block_stats && !($this->omit_fullpost && $fullpost)) { |
|---|
| 1114 | if ($this->block_stats_before) |
|---|
| 1115 | $content = "\n\n<div class=\"post-teaser-block\">" . $this->placeholders($template) . '</div>' . $content; |
|---|
| 1116 | else |
|---|
| 1117 | $content .= "\n\n<div class=\"post-teaser-block\">" . $this->placeholders($template) . '</div>'; |
|---|
| 1118 | } |
|---|
| 1119 | |
|---|
| 1120 | $this->debug('The End.'); |
|---|
| 1121 | if ($this->debug) |
|---|
| 1122 | $content .= "\n\n<!-- \n" . $this->debug_message . "-->\n\n"; |
|---|
| 1123 | return $content; |
|---|
| 1124 | } |
|---|
| 1125 | |
|---|
| 1126 | /*** A fix for invalid code from wpautop() (http://trac.wordpress.org/ticket/1099). ***/ |
|---|
| 1127 | /* Disabled because the bug above have been fixed. Will consider removal at a later date |
|---|
| 1128 | function autopfix($pee) { |
|---|
| 1129 | $pee = preg_replace('!(<(?:div|address|form)[^>]*>)([^<]+)</p>!', "$1<p>$2</p>", $pee); |
|---|
| 1130 | $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee); |
|---|
| 1131 | return $pee; |
|---|
| 1132 | } |
|---|
| 1133 | */ |
|---|
| 1134 | |
|---|
| 1135 | function replace_excerpt($excerpt) { |
|---|
| 1136 | return the_content(); |
|---|
| 1137 | } |
|---|
| 1138 | } |
|---|
| 1139 | $post_teaser = new post_teaser(); |
|---|
| 1140 | //add_filter('the_content', array(&$post_teaser, 'autopfix')); // Disabled because the associated bug have been fixed |
|---|
| 1141 | add_filter('the_content', array(&$post_teaser, 'process'), 20); |
|---|
| 1142 | add_filter('the_excerpt', array(&$post_teaser, 'replace_excerpt'), 20); // Because Post Teaser does the same thing, better |
|---|
| 1143 | add_action('admin_menu', array(&$post_teaser, 'init_option_page')); |
|---|
| 1144 | ?> |
|---|