| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Zalomení |
| 4 |
Plugin URI: http://wordpress.org/plugins/zalomeni/ |
| 5 |
Description: Puts non-breakable space after one-letter Czech prepositions like 'k', 's', 'v' or 'z'. |
| 6 |
Version: 1.4.7 |
| 7 |
Author: Honza Skypala |
| 8 |
Author URI: http://www.honza.info/ |
| 9 |
*/ |
| 10 |
|
| 11 |
include_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 12 |
|
| 13 |
class Zalomeni { |
| 14 |
const version = '1.4.7'; |
| 15 |
|
| 16 |
public function __construct() { |
| 17 |
register_activation_hook(__FILE__, array($this, 'activate')); |
| 18 |
if (is_admin()){ |
| 19 |
add_action('admin_init', array($this, 'admin_init')); |
| 20 |
} else { |
| 21 |
add_action('init', array($this, 'add_filters')); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
public function add_filters() { |
| 26 |
$zalomeni_matches = get_option('zalomeni_matches'); |
| 27 |
if (!empty($zalomeni_matches)) { |
| 28 |
$filters = array('comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title', 'term_description', 'the_title', 'the_content', 'the_excerpt', 'comment_text', 'single_post_title', 'list_cats'); |
| 29 |
$filters = array_combine($filters, $filters); |
| 30 |
$filters = apply_filters('zalomeni_filtry', $filters); |
| 31 |
foreach ($filters as $filter) { |
| 32 |
add_filter($filter, array($this, 'texturize')); // content filter |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
static function activate() { |
| 38 |
$required_php_version = '5.3'; |
| 39 |
if (version_compare(phpversion(), $required_php_version, '<')) |
| 40 |
die(str_replace(array("%1", "%2"), array($required_php_version, phpversion()), __("Plugin Zalomení vyžaduje PHP verze %1 nebo vyšší. Na tomto webu je nainstalováno PHP verze %2", "zalomeni"))); |
| 41 |
|
| 42 |
self::add_options(); |
| 43 |
} |
| 44 |
|
| 45 |
const default_prepositions = 'on'; |
| 46 |
const default_prepositions_list = 'k, s, v, z'; |
| 47 |
const default_conjunctions = ''; |
| 48 |
const default_conjunctions_list = 'a, i, o, u'; |
| 49 |
const default_abbreviations = ''; |
| 50 |
const default_abbreviations_list = 'cca., č., čís., čj., čp., fa, fě, fy, kupř., mj., např., p., pí, popř., př., přib., přibl., sl., str., sv., tj., tzn., tzv., zvl.'; |
| 51 |
const default_between_number_and_unit = 'on'; |
| 52 |
const default_between_number_and_unit_list = 'm, m², l, kg, h, °C, Kč, lidí, dní, %'; |
| 53 |
const default_spaces_in_scales = 'on'; |
| 54 |
const default_space_between_numbers = 'on'; |
| 55 |
const default_space_after_ordered_number = 'on'; |
| 56 |
const default_custom_terms = "Formule 1\nWindows \d\niPhone \d\niPhone S\d\niPad \d\nWii U\nPlayStation \d\nXBox 360"; |
| 57 |
|
| 58 |
static function add_options() { |
| 59 |
add_option('zalomeni_version', self::version); |
| 60 |
|
| 61 |
add_option('zalomeni_prepositions', Zalomeni::default_prepositions); |
| 62 |
add_option('zalomeni_prepositions_list', Zalomeni::default_prepositions_list); |
| 63 |
add_option('zalomeni_conjunctions', Zalomeni::default_conjunctions); |
| 64 |
add_option('zalomeni_conjunctions_list', Zalomeni::default_conjunctions_list); |
| 65 |
add_option('zalomeni_abbreviations', Zalomeni::default_abbreviations); |
| 66 |
add_option('zalomeni_abbreviations_list', Zalomeni::default_abbreviations_list); |
| 67 |
add_option('zalomeni_between_number_and_unit', Zalomeni::default_between_number_and_unit); |
| 68 |
add_option('zalomeni_between_number_and_unit_list', Zalomeni::default_between_number_and_unit_list); |
| 69 |
add_option('zalomeni_spaces_in_scales', Zalomeni::default_spaces_in_scales); |
| 70 |
add_option('zalomeni_space_between_numbers', Zalomeni::default_space_between_numbers); |
| 71 |
add_option('zalomeni_space_after_ordered_number', Zalomeni::default_space_after_ordered_number); |
| 72 |
add_option('zalomeni_custom_terms', Zalomeni::default_custom_terms); |
| 73 |
|
| 74 |
self::update_matches_and_replacements(); |
| 75 |
} |
| 76 |
|
| 77 |
private function update_plugin_version() { |
| 78 |
$registered_version = get_option('zalomeni_version', '0'); |
| 79 |
if ($registered_version == '0') return; |
| 80 |
|
| 81 |
if (version_compare($registered_version, self::version, '<')) { |
| 82 |
if (version_compare($registered_version, '1.3', '<')) { |
| 83 |
$old_options = get_option('zalomeni_options'); |
| 84 |
update_option('zalomeni_prepositions', $old_options['zalomeni_prepositions']); |
| 85 |
update_option('zalomeni_prepositions_list', $old_options['zalomeni_prepositions_list']); |
| 86 |
update_option('zalomeni_conjunctions', $old_options['zalomeni_conjunctions']); |
| 87 |
update_option('zalomeni_conjunctions_list', $old_options['zalomeni_conjunctions_list']); |
| 88 |
if (!version_compare($registered_version, '1.1', '<')) { |
| 89 |
// these options were introduced in version 1.1 |
| 90 |
update_option('zalomeni_abbreviations', $old_options['zalomeni_abbreviations']); |
| 91 |
update_option('zalomeni_abbreviations_list', $old_options['zalomeni_abbreviations_list']); |
| 92 |
update_option('zalomeni_space_between_numbers', $old_options['zalomeni_numbers']); |
| 93 |
} |
| 94 |
delete_option('zalomeni_options'); |
| 95 |
} |
| 96 |
|
| 97 |
self::add_options(); |
| 98 |
update_option('zalomeni_version', self::version); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
protected static $this_plugin; |
| 103 |
function add_settings_to_plugin_actions($links, $file) { |
| 104 |
// Add settings link to plugin list for this plugin |
| 105 |
if (!self::$this_plugin) self::$this_plugin = plugin_basename(__FILE__); |
| 106 |
if ($file == self::$this_plugin) { |
| 107 |
$settings_link = '<a href="options-reading.php#zalomeni_options_desc">' . __('Settings') . '</a>'; |
| 108 |
array_unshift( $links, $settings_link ); // before other links |
| 109 |
} |
| 110 |
return $links; |
| 111 |
} |
| 112 |
|
| 113 |
function admin_init() { |
| 114 |
$this->update_plugin_version(); |
| 115 |
add_filter('plugin_action_links', array($this, 'add_settings_to_plugin_actions'), 10, 2); // link from Plugins list admin page to settings of this plugin |
| 116 |
|
| 117 |
register_setting('reading', 'zalomeni_prepositions'); |
| 118 |
register_setting('reading', 'zalomeni_prepositions_list'); |
| 119 |
register_setting('reading', 'zalomeni_conjunctions'); |
| 120 |
register_setting('reading', 'zalomeni_conjunctions_list'); |
| 121 |
register_setting('reading', 'zalomeni_abbreviations'); |
| 122 |
register_setting('reading', 'zalomeni_abbreviations_list'); |
| 123 |
register_setting('reading', 'zalomeni_between_number_and_unit'); |
| 124 |
register_setting('reading', 'zalomeni_between_number_and_unit_list'); |
| 125 |
register_setting('reading', 'zalomeni_space_between_numbers'); |
| 126 |
register_setting('reading', 'zalomeni_space_after_ordered_number'); |
| 127 |
register_setting('reading', 'zalomeni_spaces_in_scales'); |
| 128 |
register_setting('reading', 'zalomeni_custom_terms'); |
| 129 |
|
| 130 |
add_settings_section('zalomeni_section', $this->texturize(__('Nevhodná slova a zalomení na konci řádku', 'zalomeni')), 'Zalomeni::settings_section_description', 'reading'); |
| 131 |
|
| 132 |
add_settings_field('zalomeni_prepositions', __('Předložky', 'zalomeni'), 'Zalomeni::settings_field_checkbox', 'reading', 'zalomeni_section', array('option'=>'prepositions', 'description'=>"Vkládat pevnou mezeru za následující předložky.", 'toggle_list_read_only'=>true)); |
| 133 |
add_settings_field('zalomeni_prepositions_list', '', 'Zalomeni::settings_field_textlist', 'reading', 'zalomeni_section', array('option'=>'prepositions', 'description'=>"(oddělte jednotlivé předložky čárkou)")); |
| 134 |
add_settings_field('zalomeni_conjunctions', __('Spojky', 'zalomeni'), 'Zalomeni::settings_field_checkbox', 'reading', 'zalomeni_section', array('option'=>'conjunctions', 'description'=>"Vkládat pevnou mezeru za následující spojky.", 'toggle_list_read_only'=>true)); |
| 135 |
add_settings_field('zalomeni_conjunctions_list', '', 'Zalomeni::settings_field_textlist', 'reading', 'zalomeni_section', array('option'=>'conjunctions', 'description'=>"(oddělte jednotlivé spojky čárkou)")); |
| 136 |
add_settings_field('zalomeni_abbreviations', __('Zkratky', 'zalomeni'), 'Zalomeni::settings_field_checkbox', 'reading', 'zalomeni_section', array('option'=>'abbreviations', 'description'=>"Vkládat pevnou mezeru za následující zkratky.", 'toggle_list_read_only'=>true)); |
| 137 |
add_settings_field('zalomeni_abbreviations_list', '', 'Zalomeni::settings_field_textlist', 'reading', 'zalomeni_section', array('option'=>'abbreviations', 'description'=>"(oddělte jednotlivé zkratky čárkou)")); |
| 138 |
add_settings_field('zalomeni_between_number_and_unit', __('Jednotky a míry', 'zalomeni'), 'Zalomeni::settings_field_checkbox', 'reading', 'zalomeni_section', array('option'=>'between_number_and_unit', 'description'=>"Vkládat pevnou mezeru mezi číslovku a jednotku míry (měrné jednotky, měna apod., např. <em>5 m</em> nebo <em>10 kg</em>).", 'toggle_list_read_only'=>true)); |
| 139 |
add_settings_field('zalomeni_between_number_and_unit_list', '', 'Zalomeni::settings_field_textlist', 'reading', 'zalomeni_section', array('option'=>'between_number_and_unit', 'description'=>"(oddělte jednotlivé míry čárkou)")); |
| 140 |
add_settings_field('zalomeni_space_between_numbers', __('Mezery uprostřed čísel', 'zalomeni'), 'Zalomeni::settings_field_checkbox', 'reading', 'zalomeni_section', array('option'=>'space_between_numbers', 'description'=>"Pokud jsou dvě čísla oddělena mezerou, předpokládat, že se jedná o formátování čísla pomocí mezery (např. telefonní číslo <em>800 123 456</em>) a nahrazovat mezeru pevnou mezerou, aby nedošlo k zalomení řádku uprostřed čísla.")); |
| 141 |
add_settings_field('zalomeni_space_after_ordered_number', __('Řadové číslovky', 'zalomeni'), 'Zalomeni::settings_field_checkbox', 'reading', 'zalomeni_section', array('option'=>'space_after_ordered_number', 'description'=>"Zabránit zalomení řádku za řadovou číslovkou; díky tomu nedojde k zalomení řádku uprostřed data (např. <em>1. ledna</em>) a v podobných případech (<em>19. ročník</em>, <em>3. svazek</em>, <em>5. kapitola</em> apod.)")); |
| 142 |
add_settings_field('zalomeni_spaces_in_scales', __('Měřítka a poměry', 'zalomeni'), 'Zalomeni::settings_field_checkbox', 'reading', 'zalomeni_section', array('option'=>'spaces_in_scales', 'description'=>"Pevné mezery v měřítkách a poměrech (např. <em>1 : 50 000</em>)")); |
| 143 |
add_settings_field('zalomeni_custom_terms', __('Vlastní výrazy', 'zalomeni'), 'Zalomeni::settings_field_custom_terms', 'reading', 'zalomeni_section'); |
| 144 |
|
| 145 |
if (get_option('zalomeni_matches') == '') { |
| 146 |
Zalomeni::update_matches_and_replacements(); |
| 147 |
} |
| 148 |
|
| 149 |
$this->add_update_option_hooks(); |
| 150 |
} |
| 151 |
|
| 152 |
static public function settings_field_checkbox(array $args) { |
| 153 |
echo( |
| 154 |
'<input type="checkbox" name="zalomeni_' . $args['option'] . '" id="zalomeni_' . $args['option'] . '" value="on" ' |
| 155 |
. checked('on', get_option("zalomeni_" . $args['option'], constant('Zalomeni::default_' . $args['option'])), false) |
| 156 |
. (array_key_exists('toggle_list_read_only', $args) ? ' onchange="document.getElementById(\'zalomeni_' . $args['option'] . '_list\').readOnly = this.checked?\'\':\'1\';"' : '') |
| 157 |
. ' /> ' |
| 158 |
. Zalomeni::texturize(__($args['description'], 'zalomeni')) |
| 159 |
); |
| 160 |
} |
| 161 |
|
| 162 |
static public function settings_field_textlist(array $args) { |
| 163 |
echo( |
| 164 |
'<input type="text" name="zalomeni_' . $args['option'] . '_list" id="zalomeni_' . $args['option'] . '_list" class="regular-text" value="' . get_option('zalomeni_' . $args['option'] . '_list', constant('Zalomeni::default_' . $args['option'] . '_list')) . '"' |
| 165 |
. ((get_option("zalomeni_" . $args['option'], constant('Zalomeni::default_' . $args['option'])) != 'on') ? ' readonly="1"' : '') |
| 166 |
. ' /> ' |
| 167 |
. Zalomeni::texturize(__($args['description'], 'zalomeni')) |
| 168 |
); |
| 169 |
} |
| 170 |
|
| 171 |
static public function settings_field_custom_terms() { |
| 172 |
echo( |
| 173 |
Zalomeni::texturize(__('Zde můžete uvést vlastní termíny, v nichž mají být mezery nahrazeny pevnými mezerami tak, aby nedošlo k zalomení uvnitř těchto výrazů. Uveďte vždy každý výraz na samostatný řádek; pokud je výraz složen z více jak dvou slov, tedy je v něm více jak jedna mezera, pak všechny mezery budou nahrazeny za pevné mezery. Lze použít výrazu \\d pro libovolnou číslici (pro pokročilé administrátory: algoritmus používá <a href="http://www.php.net/manual/en/reference.pcre.pattern.syntax.php" target="_blank">Perl Compatible Regular Expressions</a>, lze využít syntaxe této specifikace).', 'zalomeni')) |
| 174 |
. '<p><textarea name="zalomeni_custom_terms" id="zalomeni_custom_terms" rows="10" cols="50" class="regular-text">' |
| 175 |
. get_option('zalomeni_custom_terms', Zalomeni::default_custom_terms) |
| 176 |
. '</textarea></p>' |
| 177 |
); |
| 178 |
} |
| 179 |
|
| 180 |
private function add_update_option_hooks() { |
| 181 |
foreach (array('update_option_zalomeni_prepositions', |
| 182 |
'update_option_zalomeni_prepositions_list', |
| 183 |
'update_option_zalomeni_conjunctions', |
| 184 |
'update_option_zalomeni_conjunctions_list', |
| 185 |
'update_option_zalomeni_abbreviations', |
| 186 |
'update_option_zalomeni_abbreviations_list', |
| 187 |
'update_option_zalomeni_between_number_and_unit', |
| 188 |
'update_option_zalomeni_between_number_and_unit_list', |
| 189 |
'update_option_zalomeni_space_between_numbers', |
| 190 |
'update_option_zalomeni_space_after_ordered_number', |
| 191 |
'update_option_zalomeni_spaces_in_scales', |
| 192 |
'update_option_zalomeni_custom_terms') as $i) { |
| 193 |
add_action($i, array($this, 'update_matches_and_replacements')); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
public function update_matches_and_replacements() { |
| 198 |
update_option('zalomeni_matches', Zalomeni::prepare_matches()); |
| 199 |
update_option('zalomeni_replacements', Zalomeni::prepare_replacements()); |
| 200 |
} |
| 201 |
|
| 202 |
private function prepare_matches() { |
| 203 |
$return_array = array(); |
| 204 |
|
| 205 |
$word_matches = ''; |
| 206 |
foreach (array('prepositions', 'conjunctions', 'abbreviations') as $i) { |
| 207 |
if (get_option('zalomeni_'.$i, constant('Zalomeni::default_'.$i)) == 'on') { |
| 208 |
$temp_array = explode(',', get_option('zalomeni_'.$i.'_list', constant('Zalomeni::default_'.$i.'_list'))); |
| 209 |
foreach ($temp_array as $j) { |
| 210 |
$j = mb_strtolower(trim($j)); |
| 211 |
$word_matches .= ($word_matches == '' ? '' : '|') . $j; |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
if ($word_matches != '') { |
| 216 |
$return_array['words'] = '@($|;| | |\(|\n)('.$word_matches.') @i'; |
| 217 |
} |
| 218 |
|
| 219 |
$word_matches = ''; |
| 220 |
if (get_option('zalomeni_between_number_and_unit', Zalomeni::default_between_number_and_unit) == 'on') { |
| 221 |
$temp_array = explode(',', get_option('zalomeni_between_number_and_unit_list', Zalomeni::default_between_number_and_unit_list)); |
| 222 |
foreach ($temp_array as $j) { |
| 223 |
$j = mb_strtolower(trim($j)); |
| 224 |
$word_matches .= ($word_matches == '' ? '' : '|') . $j; |
| 225 |
} |
| 226 |
} |
| 227 |
if ($word_matches != '') { |
| 228 |
$return_array['units'] = '@(\d) ('.$word_matches.')(^|[;\.!:]| | |\?|\n|\)|<|\010|\013|$)@i'; |
| 229 |
} |
| 230 |
|
| 231 |
if (get_option('zalomeni_space_between_numbers', Zalomeni::default_space_between_numbers) == 'on') { |
| 232 |
$return_array['numbers'] = '@(\d) (\d)@i'; |
| 233 |
} |
| 234 |
|
| 235 |
if (get_option('zalomeni_spaces_in_scales', Zalomeni::default_spaces_in_scales) == 'on') { |
| 236 |
$return_array['scales'] = '@(\d) : (\d)@i'; |
| 237 |
} |
| 238 |
|
| 239 |
if (get_option('zalomeni_space_after_ordered_number', Zalomeni::default_space_after_ordered_number) == 'on') { |
| 240 |
$return_array['orders'] = '@(\d\.) ([0-9a-záčďéěíňóřšťúýž])@'; |
| 241 |
} |
| 242 |
|
| 243 |
if (get_option('zalomeni_custom_terms', Zalomeni::default_custom_terms) != '') { |
| 244 |
$term_counter = 1; |
| 245 |
$custom_terms = explode(chr(10), str_replace(chr(13), '', get_option('zalomeni_custom_terms', Zalomeni::default_custom_terms))); |
| 246 |
foreach ($custom_terms as $i) { |
| 247 |
if (strpos($i, ' ') !== false) { |
| 248 |
$term = ''; |
| 249 |
$words_split = explode(' ', $i); |
| 250 |
foreach ($words_split as $j) { |
| 251 |
$term .= ($term == '' ? '(' : ' (') . str_replace(array('/', '(', ')'), array('\\/', '\\(', '\\)'), $j) . ')'; |
| 252 |
} |
| 253 |
$term = '/' . $term . '/i'; |
| 254 |
$return_array['customterm' . $term_counter++] = $term; |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
return $return_array; |
| 260 |
} |
| 261 |
|
| 262 |
private function prepare_replacements() { |
| 263 |
$return_array = array(); |
| 264 |
|
| 265 |
foreach (array('prepositions', 'conjunctions', 'abbreviations') as $i) { |
| 266 |
if (get_option('zalomeni_'.$i, constant('Zalomeni::default_'.$i)) == 'on') { |
| 267 |
$return_array['words'] = '$1$2 '; |
| 268 |
break; |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
if (get_option('zalomeni_between_number_and_unit', Zalomeni::default_between_number_and_unit) == 'on') { |
| 273 |
$return_array['units'] = '$1 $2$3'; |
| 274 |
} |
| 275 |
|
| 276 |
if (get_option('zalomeni_space_between_numbers', Zalomeni::default_space_between_numbers) == 'on') { |
| 277 |
$return_array['numbers'] = '$1 $2'; |
| 278 |
} |
| 279 |
|
| 280 |
if (get_option('zalomeni_spaces_in_scales', Zalomeni::default_spaces_in_scales) == 'on') { |
| 281 |
$return_array['scales'] = '$1 : $2'; |
| 282 |
} |
| 283 |
|
| 284 |
if (get_option('zalomeni_space_after_ordered_number', Zalomeni::default_space_after_ordered_number) == 'on') { |
| 285 |
$return_array['orders'] = '$1 $2'; |
| 286 |
} |
| 287 |
|
| 288 |
if (get_option('zalomeni_custom_terms', Zalomeni::default_custom_terms) != '') { |
| 289 |
$term_counter = 1; |
| 290 |
$custom_terms = explode(chr(10), str_replace(chr(13), '', get_option('zalomeni_custom_terms', Zalomeni::default_custom_terms))); |
| 291 |
foreach ($custom_terms as $i) { |
| 292 |
if (strpos($i, ' ') !== false) { |
| 293 |
$term = ''; |
| 294 |
$words_split = explode(' ', $i); |
| 295 |
$word_counter = 1; |
| 296 |
foreach ($words_split as $j) { |
| 297 |
$term .= ($term == '' ? '' : ' ') . '$' . $word_counter++; |
| 298 |
} |
| 299 |
$return_array['customterm' . $term_counter++] = $term; |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
return $return_array; |
| 305 |
} |
| 306 |
|
| 307 |
static public function settings_section_description() { |
| 308 |
echo( |
| 309 |
'<div id="zalomeni_options_desc" style="margin:0 0 15px 10px;-webkit-border-radius:3px;border-radius:3px;border-width:1px;border-color:#e6db55;border-style:solid;float:right;background:#FFFBCC;text-align:center;width:200px">' |
| 310 |
. '<p style="line-height:1.5em;">Plugin <strong>Zalomení</strong><br />Autor: <a href="http://www.honza.info/" class="external" target="_blank" title="http://www.honza.info/">Honza Skýpala</a></p>' |
| 311 |
. '</div>' |
| 312 |
. '<p>' . Zalomeni::texturize(__('Upravujeme-li písemný dokument, radí nám <strong>Pravidla českého pravopisu</strong> nepsat neslabičné předložky <em>v, s, z, k</em> na konec řádku, ale psát je na stejný řádek se slovem, které nese přízvuk (např. ve spojení <em>k mostu</em>, <em>s bratrem</em>, <em>v Plzni</em>, <em>z nádraží</em>). Typografické normy jsou ještě přísnější: podle některých je nepatřičné ponechat na konci řádku jakékoli jednopísmenné slovo, tedy také předložky a spojky <em>a, i, o, u</em>;. Někteří pisatelé dokonce nechtějí z estetických důvodů ponechávat na konci řádků jakékoli jednoslabičné výrazy (např. <em>ve, ke, ku, že, na, do, od, pod</em>).', 'zalomeni')) . '</p>' |
| 313 |
. '<p>' . Zalomeni::texturize(__('<a href="http://prirucka.ujc.cas.cz/?id=880" class="external" target="_blank">Více informací</a> na webu Ústavu pro jazyk český, Akademie věd ČR.', 'zalomeni')) . '</p>' |
| 314 |
. '<p>' . Zalomeni::texturize(__('Tento plugin řeší některé z uvedených příkladů: v textu nahrazuje běžné mezery za pevné tak, aby nedošlo k zalomení řádku v nevhodném místě.', 'zalomeni')) . '</p>' |
| 315 |
); |
| 316 |
} |
| 317 |
|
| 318 |
static public function texturize($text) { |
| 319 |
if (get_option('zalomeni_matches') == '') return $text; // no settings? then fall-back to just return the content |
| 320 |
$output = ''; |
| 321 |
$curl = ''; |
| 322 |
$textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 323 |
$stop = count($textarr); |
| 324 |
|
| 325 |
$no_texturize_tags = apply_filters('no_texturize_tags', array('pre', 'code', 'kbd', 'style', 'script', 'tt')); |
| 326 |
$no_texturize_shortcodes = apply_filters('no_texturize_shortcodes', array('code')); |
| 327 |
$no_texturize_tags_stack = array(); |
| 328 |
$no_texturize_shortcodes_stack = array(); |
| 329 |
|
| 330 |
for ($i = 0; $i < $stop; $i++) { |
| 331 |
$curl = $textarr[$i]; |
| 332 |
|
| 333 |
if (!empty($curl)) { |
| 334 |
global $wp_version; |
| 335 |
if ('<' != $curl{0} && '[' != $curl{0} |
| 336 |
&& empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) { // If it's not a tag |
| 337 |
$curl = preg_replace(get_option('zalomeni_matches'), get_option('zalomeni_replacements'), $curl); |
| 338 |
$curl = preg_replace(get_option('zalomeni_matches'), get_option('zalomeni_replacements'), $curl); |
| 339 |
} else if (version_compare($wp_version, '2.9', '<')) { |
| 340 |
wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); |
| 341 |
wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); |
| 342 |
} else { |
| 343 |
_wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); |
| 344 |
_wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
$output .= $curl; |
| 349 |
} |
| 350 |
|
| 351 |
return $output; |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
$wpZalomeni = new Zalomeni(); |
| 356 |
?> |