Plugin Directory

Changeset 143083


Ignore:
Timestamp:
08/05/2009 03:31:26 PM (16 years ago)
Author:
dor
Message:

Added restrinctions to check if user is authenticated (different replaces for authenticated and guests).

Location:
replace/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • replace/trunk/re.place-class.php

    r58154 r143083  
    3636        global $wpdb;
    3737       
    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' ";
    3939        $sql .= " ORDER BY re_order, re_id ASC ";
    4040       
    4141        $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          */
    5042        return $replaces;
    5143    }
     
    7668            ." re_place = '" . $wpdb->escape($re_place["re_place"]) . "', "
    7769            ." 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"]) . "' "
    7973            ." WHERE re_id = '" . $re_place["re_id"] . "' ";
    8074        $wpdb->query($sql);
     
    9589            ." re_place = '" . $wpdb->escape($re_place["re_place"]) . "', "
    9690            ." 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"]) . "'";
    9894        $wpdb->query($sql);
    9995    }
  • replace/trunk/re.place-options.php

    r126899 r143083  
    11<?php
    2 
    32
    43// Check if user can edit themes
     
    87
    98require_once('re.place-class.php');
     9require_once('re.place-restrs.php');
     10
    1011checkInstall();
    1112
     
    4950function showMainMenu() {
    5051    global $options_url;
     52    global $restrictions;
    5153   
    5254    $rePlaceManager = new RePlace();
     
    6769            <th><?php _e('Replace with'); ?></th>
    6870            <th><?php _e('Order'); ?></th>
     71            <th><?php _e('Restriction'); ?></th>
     72            <th><?php _e('Otherwise'); ?></th>
    6973            <th>&nbsp;</th>
    7074            <th>&nbsp;</th>
     
    7579        <tr class='<?php echo $class; ?>'>
    7680            <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>
    7882            <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>
    8185            <td align="center"><?php echo $re_place->re_order;?></td>
    82             <td><a href="<?php echo $options_url; ?>&amp;action=edit&amp;id=<?php echo $re_place->re_id;?>" class="edit"><?php _e('Edit'); ?></a></td>
    83             <td><a href="<?php echo $options_url; ?>&amp;action=delete&amp;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; ?>&amp;action=edit&amp;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; ?>&amp;action=delete&amp;id=<?php echo $re_place->re_id;?>" class="delete"><?php _e('Delete'); ?></a></td>
    8490        </tr>   
    8591        <?php }  ?>
     
    104110function showEdit() {
    105111    global $options_url;
     112    global $restrictions;
    106113
    107114    if ( isset($_REQUEST['id']) ) {
     
    135142            <td>
    136143                <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.
    138145            </td>
    139146        </tr>
     
    142149            <td>
    143150                <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 />
    145172            </td>
    146173        </tr>
     
    148175            <td valign="top">Order</td>
    149176            <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 />
    151178                Order of this entry
    152179            </td>
     
    182209    $re_place["re_order"] = $_REQUEST["re_order"];
    183210    $re_place["re_active"] = $_REQUEST["re_active"];
     211    $re_place["restriction"] = $_REQUEST["restriction"];
     212    $re_place["restr_otherwise"] = $_REQUEST["restr_otherwise"];
    184213    if (get_magic_quotes_gpc()) {
    185214        foreach($re_place as $key => $value) {
     
    199228function showNewRePlace() {
    200229    global $options_url;
     230    global $restrictions;
    201231
    202232?>
     
    218248            <td>
    219249                <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.
    221251            </td>
    222252        </tr>
     
    225255            <td>
    226256                <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 />
    228278            </td>
    229279        </tr>
     
    264314    $re_place["re_place"] = $_REQUEST["re_place"];
    265315    $re_place["re_order"] = $_REQUEST["re_order"];
     316    $re_place["restriction"] = $_REQUEST["restriction"];
     317    $re_place["restr_otherwise"] = $_REQUEST["restr_otherwise"];
    266318    if (get_magic_quotes_gpc()) {
    267319        foreach($re_place as $key => $value) {
     
    309361              `re_place` mediumtext NOT NULL,
    310362              `re_order` int NOT NULL default 0,
     363              `restriction` varchar(32),
     364              `restr_otherwise` mediumtext,
    311365              PRIMARY KEY  (`re_id`)
    312366            ) ENGINE=MyISAM ;
    313367SQL;
    314368        $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();
    316377    }
    317378}
    318379
     380function 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;
     387SQLU;
     388    $wpdb->query($sql);
     389}
     390
     391function updateVersion() {
     392    update_option( 're_place_version', '0.1.3' );
     393}
     394
    319395?>
  • replace/trunk/re.place.php

    r126899 r143083  
    22/*
    33Plugin Name: re.place
    4 Version: 0.1.2
     4Version: 0.1.3
    55Plugin URI: http://brownian.org.ua/?page_id=61
    66Description: Custom regexp search and replace contents.
     
    5757*/
    5858function re_place_content_filter($content) {
     59    global $user_ID;
     60
    5961    $pairs = get_re_pairs();
     62
    6063    $search = array();
    6164    $place  = array();
     65
    6266    foreach ($pairs as $re_place) {
    6367        $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        }
    6573    }
     74
    6675    $content = preg_replace($search, $place, $content);
     76
    6777    return $content;
    6878}
  • replace/trunk/readme.txt

    r133320 r143083  
    22Contributors: dor
    33Donate link: http://brownian.org.ua/?page_id=61
    4 Tags: search and replace, filter, formatting, post, page, template, regular expression, regex, search, replace
     4Tags: custom, filter, formatting, post, page, template, regular expreassion, regex, search, replace
    55Requires at least: 2.0.2
    6 Tested up to: 2.8.0
    7 Stable tag: trunk
     6Tested up to: 2.7.0
     7Stable tag: 0.1.1
    88
    99re.place adds content filter wich searches in posts for specified patterns
     
    3434== Installation ==
    3535
    36 1. Unzip replace-<version>.zip to the `/wp-content/plugins/` directory
     361. Unzip re.place-<version>.zip to the `/wp-content/plugins/` directory
    37371. Activate the plugin through the 'Plugins' menu in WordPress
    38381. Define your search/replacements via mgmt interface
     
    5151
    52521. 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
     532. Edit entry widow
     543. List entries
    5655
    5756== A brief examples ==
    5857
    59 1. As a search field, use '`_&#8212;`' (*space* in place of `_`!),
    60    as a replace -- '`#160;&#8212;`'. This will insert non-breaking space
    61    before every em-dash.
     581. As a search field, use '` &#8212;`', as a replace -- '`#160;&#8212;`'. This will
     59   insert non-breaking space before every em-dash.
    6260
    6361   Mmm... You may wish even use '`<span
     
    7573
    7674   Replace pattern:
     75
    7776    '`<object width="425" height="344" data="http://www.youtube.com/v/\1" type="application/x-shockwave-flash">
    7877      <param name="movie" value="http://www.youtube.com/v/\1"></param>
     
    8281   Youtube video fragments easily.
    8382
    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
     834. Want to insert drop caps easily?.. Use '`<drop>L</drop>orem ipsum...`' in your
    9684   posts and replace it with `<span class="dropcap">\1</span>`'. Use angle brackets,
    9785   and if you (accidentally) deactivate re.place, these "tags" won't mess you page.
    9886
     875. 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.