Changeset 143083
- Timestamp:
- 08/05/2009 03:31:26 PM (16 years ago)
- Location:
- replace/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
replace/trunk/re.place-class.php
r58154 r143083 36 36 global $wpdb; 37 37 38 $sql = "SELECT re_search, re_place FROM ".$this->re_table." WHERE re_active='Y' ";38 $sql = "SELECT re_search, re_place, restriction, restr_otherwise FROM ".$this->re_table." WHERE re_active='Y' "; 39 39 $sql .= " ORDER BY re_order, re_id ASC "; 40 40 41 41 $replaces = $wpdb->get_results($sql); 42 /*43 global $post;44 if ($post->ID == 60) {45 foreach ($replaces as $repl){46 print $repl->re_search . ", " . $repl->re_place . "<BR>";47 }48 }49 */50 42 return $replaces; 51 43 } … … 76 68 ." re_place = '" . $wpdb->escape($re_place["re_place"]) . "', " 77 69 ." re_active = '" . $re_place["re_active"] . "', " 78 ." re_order = '" . $re_place["re_order"] . "' " 70 ." re_order = '" . $re_place["re_order"] . "', " 71 ." restriction = '" . $re_place["restriction"] . "', " 72 ." restr_otherwise = '" . $wpdb->escape($re_place["restr_otherwise"]) . "' " 79 73 ." WHERE re_id = '" . $re_place["re_id"] . "' "; 80 74 $wpdb->query($sql); … … 95 89 ." re_place = '" . $wpdb->escape($re_place["re_place"]) . "', " 96 90 ." re_order = '" . $re_place["re_order"] . "', " 97 ." re_active = '" . $re_place["re_active"] . "'"; 91 ." re_active = '" . $re_place["re_active"] . "', " 92 ." restriction = '" . $re_place["restriction"] . "', " 93 ." restr_otherwise = '" . $wpdb->escape($re_place["restr_otherwise"]) . "'"; 98 94 $wpdb->query($sql); 99 95 } -
replace/trunk/re.place-options.php
r126899 r143083 1 1 <?php 2 3 2 4 3 // Check if user can edit themes … … 8 7 9 8 require_once('re.place-class.php'); 9 require_once('re.place-restrs.php'); 10 10 11 checkInstall(); 11 12 … … 49 50 function showMainMenu() { 50 51 global $options_url; 52 global $restrictions; 51 53 52 54 $rePlaceManager = new RePlace(); … … 67 69 <th><?php _e('Replace with'); ?></th> 68 70 <th><?php _e('Order'); ?></th> 71 <th><?php _e('Restriction'); ?></th> 72 <th><?php _e('Otherwise'); ?></th> 69 73 <th> </th> 70 74 <th> </th> … … 75 79 <tr class='<?php echo $class; ?>'> 76 80 <td><?php echo $re_place->re_id;?></td> 77 <td ><?php echo $re_place->re_description;?></td>81 <td style="font-size: 80%;"><?php echo $re_place->re_description;?></td> 78 82 <td align="center"><?php echo $re_place->re_active;?></td> 79 <td ><?php echo $re_place->re_search;?></td>80 <td ><?php echo $re_place->re_place;?></td>83 <td style="font-size: 80%;"><?php echo $re_place->re_search;?></td> 84 <td style="font-size: 80%;"><?php echo $re_place->re_place;?></td> 81 85 <td align="center"><?php echo $re_place->re_order;?></td> 82 <td><a href="<?php echo $options_url; ?>&action=edit&id=<?php echo $re_place->re_id;?>" class="edit"><?php _e('Edit'); ?></a></td> 83 <td><a href="<?php echo $options_url; ?>&action=delete&id=<?php echo $re_place->re_id;?>" class="delete"><?php _e('Delete'); ?></a></td> 86 <td style="font-size: 80%;"><?php echo $restrictions[$re_place->restriction]; ?></td> 87 <td style="font-size: 80%;"><?php echo $re_place->restr_otherwise; ?></td> 88 <td style="font-size: 80%;"><a href="<?php echo $options_url; ?>&action=edit&id=<?php echo $re_place->re_id;?>" class="edit"><?php _e('Edit'); ?></a></td> 89 <td style="font-size: 80%;"><a href="<?php echo $options_url; ?>&action=delete&id=<?php echo $re_place->re_id;?>" class="delete"><?php _e('Delete'); ?></a></td> 84 90 </tr> 85 91 <?php } ?> … … 104 110 function showEdit() { 105 111 global $options_url; 112 global $restrictions; 106 113 107 114 if ( isset($_REQUEST['id']) ) { … … 135 142 <td> 136 143 <textarea name="re_search" rows="6" cols="80"><?php echo htmlspecialchars($re_place->re_search);?></textarea><br /> 137 What is re.place should search for 144 What is re.place should search for. 138 145 </td> 139 146 </tr> … … 142 149 <td> 143 150 <textarea name="re_place" rows="6" cols="80"><?php echo htmlspecialchars($re_place->re_place);?></textarea><br /> 144 What re.place should place instead 151 What re.place should place instead. 152 </td> 153 </tr> 154 <tr> 155 <td valign="top">Restriction</td> 156 <td> 157 Replace only if... 158 <select name="restriction"> 159 <?php foreach ( $restrictions as $r => $restr ) { 160 $sel = $re_place->restriction ? 161 ( $r == $re_place->restriction ? ' selected' : '' ) : 162 ( $r == 'none' ? ' selected' : '' ); 163 echo '<option' . $sel . ' value="' . $r . '">' . __($restr) . '</option>' ."\n"; 164 } ?> 165 </select> 166 </td> 167 </tr> 168 <tr> 169 <td valign="top">Otherwise replace with:</td> 170 <td> 171 <textarea name="restr_otherwise" rows="6" cols="80"><?php echo htmlspecialchars($re_place->restr_otherwise);?></textarea><br /> 145 172 </td> 146 173 </tr> … … 148 175 <td valign="top">Order</td> 149 176 <td> 150 <input name="re_order" type="text" size="5" value="<?php echo htmlspecialchars($re_place->re_order);?>" <br />177 <input name="re_order" type="text" size="5" value="<?php echo htmlspecialchars($re_place->re_order);?>"><br /> 151 178 Order of this entry 152 179 </td> … … 182 209 $re_place["re_order"] = $_REQUEST["re_order"]; 183 210 $re_place["re_active"] = $_REQUEST["re_active"]; 211 $re_place["restriction"] = $_REQUEST["restriction"]; 212 $re_place["restr_otherwise"] = $_REQUEST["restr_otherwise"]; 184 213 if (get_magic_quotes_gpc()) { 185 214 foreach($re_place as $key => $value) { … … 199 228 function showNewRePlace() { 200 229 global $options_url; 230 global $restrictions; 201 231 202 232 ?> … … 218 248 <td> 219 249 <textarea name="re_search" rows="6" cols="80"></textarea><br /> 220 What is re.place should search for 250 What is re.place should search for. 221 251 </td> 222 252 </tr> … … 225 255 <td> 226 256 <textarea name="re_place" rows="6" cols="80"></textarea><br /> 227 What re.place should place instead 257 What re.place should place instead. 258 </td> 259 </tr> 260 <tr> 261 <td valign="top">Restriction</td> 262 <td> 263 Replace only if... 264 <select name="restriction"> 265 <?php foreach ( $restrictions as $r => $restr ) { 266 $sel = // $re_place->restriction ? 267 // ( $r == $re_place->restriction ? ' selected' : '' ) : 268 ( $r == 'none' ? ' selected' : '' ); 269 echo '<option' . $sel . ' value="' . $r . '">' . __($restr) . '</option>' ."\n"; 270 } ?> 271 </select> 272 </td> 273 </tr> 274 <tr> 275 <td valign="top">Otherwise replace with:</td> 276 <td> 277 <textarea name="restr_otherwise" rows="6" cols="80"></textarea><br /> 228 278 </td> 229 279 </tr> … … 264 314 $re_place["re_place"] = $_REQUEST["re_place"]; 265 315 $re_place["re_order"] = $_REQUEST["re_order"]; 316 $re_place["restriction"] = $_REQUEST["restriction"]; 317 $re_place["restr_otherwise"] = $_REQUEST["restr_otherwise"]; 266 318 if (get_magic_quotes_gpc()) { 267 319 foreach($re_place as $key => $value) { … … 309 361 `re_place` mediumtext NOT NULL, 310 362 `re_order` int NOT NULL default 0, 363 `restriction` varchar(32), 364 `restr_otherwise` mediumtext, 311 365 PRIMARY KEY (`re_id`) 312 366 ) ENGINE=MyISAM ; 313 367 SQL; 314 368 $wpdb->query($sql); 315 add_option( 're_place_version', '0.1.1', 're.place version number', 'yes' ); 369 add_option( 're_place_version', '0.1.2', 're.place version number', 'yes' ); 370 } else { 371 switch ( $version ) { 372 case '0.1.1': 373 case '0.1.2': 374 addRestrColumns(); 375 } 376 updateVersion(); 316 377 } 317 378 } 318 379 380 function addRestrColumns() { 381 global $wpdb; 382 global $table_prefix; 383 $sql = <<<SQLU 384 ALTER TABLE `{$table_prefix}re_place` 385 ADD COLUMN `restriction` varchar(32), 386 ADD COLUMN `restr_otherwise` mediumtext; 387 SQLU; 388 $wpdb->query($sql); 389 } 390 391 function updateVersion() { 392 update_option( 're_place_version', '0.1.3' ); 393 } 394 319 395 ?> -
replace/trunk/re.place.php
r126899 r143083 2 2 /* 3 3 Plugin Name: re.place 4 Version: 0.1. 24 Version: 0.1.3 5 5 Plugin URI: http://brownian.org.ua/?page_id=61 6 6 Description: Custom regexp search and replace contents. … … 57 57 */ 58 58 function re_place_content_filter($content) { 59 global $user_ID; 60 59 61 $pairs = get_re_pairs(); 62 60 63 $search = array(); 61 64 $place = array(); 65 62 66 foreach ($pairs as $re_place) { 63 67 $search[] = "/" . $re_place->re_search . "/"; 64 $place[] = $re_place->re_place; 68 if ( $re_place->restriction == 'auth' && !$user_ID ) { 69 $place[] = $re_place->restr_otherwise; 70 } else { 71 $place[] = $re_place->re_place; 72 } 65 73 } 74 66 75 $content = preg_replace($search, $place, $content); 76 67 77 return $content; 68 78 } -
replace/trunk/readme.txt
r133320 r143083 2 2 Contributors: dor 3 3 Donate link: http://brownian.org.ua/?page_id=61 4 Tags: search and replace, filter, formatting, post, page, template, regular expression, regex, search, replace4 Tags: custom, filter, formatting, post, page, template, regular expreassion, regex, search, replace 5 5 Requires at least: 2.0.2 6 Tested up to: 2. 8.07 Stable tag: trunk6 Tested up to: 2.7.0 7 Stable tag: 0.1.1 8 8 9 9 re.place adds content filter wich searches in posts for specified patterns … … 34 34 == Installation == 35 35 36 1. Unzip re place-<version>.zip to the `/wp-content/plugins/` directory36 1. Unzip re.place-<version>.zip to the `/wp-content/plugins/` directory 37 37 1. Activate the plugin through the 'Plugins' menu in WordPress 38 38 1. Define your search/replacements via mgmt interface … … 51 51 52 52 1. Insert new entry window 53 2. Edit entry window 54 3. Entry with regular expression search and replace (to insert YouTube video) 55 4. List entries 53 2. Edit entry widow 54 3. List entries 56 55 57 56 == A brief examples == 58 57 59 1. As a search field, use '`_—`' (*space* in place of `_`!), 60 as a replace -- '`#160;—`'. This will insert non-breaking space 61 before every em-dash. 58 1. As a search field, use '` —`', as a replace -- '`#160;—`'. This will 59 insert non-breaking space before every em-dash. 62 60 63 61 Mmm... You may wish even use '`<span … … 75 73 76 74 Replace pattern: 75 77 76 '`<object width="425" height="344" data="http://www.youtube.com/v/\1" type="application/x-shockwave-flash"> 78 77 <param name="movie" value="http://www.youtube.com/v/\1"></param> … … 82 81 Youtube video fragments easily. 83 82 84 4. How to Mass Remove Link (mass deactivate URL Linked text inside posts)? 85 (http://wordpress.org/support/topic/288020) 86 87 Search pattern: `<a [^>]*>([^<]*)<\/a>` 88 89 Replace pattern: `\1` 90 91 This will "deactivate" all links in all posts 92 (e.g. replace `<a href="...">Try!</a>` with just `Try!`). 93 Note, you can activate them back, deactivating this `re.place` entry. 94 95 5. Want to insert drop caps easily?.. Use '`<drop>L</drop>orem ipsum...`' in your 83 4. Want to insert drop caps easily?.. Use '`<drop>L</drop>orem ipsum...`' in your 96 84 posts and replace it with `<span class="dropcap">\1</span>`'. Use angle brackets, 97 85 and if you (accidentally) deactivate re.place, these "tags" won't mess you page. 98 86 87 5. New --- in v0.1.3 --- [beta-] feature: you can specify different replace patterns 88 for authenticated users and "guests". Sorry, i'll update screenshots and doc 89 ASAP. :-)
Note: See TracChangeset
for help on using the changeset viewer.