Plugin Directory

Changeset 3102339


Ignore:
Timestamp:
06/13/2024 01:47:03 PM (20 months ago)
Author:
d3395
Message:
  • main code rewritten as class to prevent problems with WordPress or other plugin functions.
  • added documentation blocks to class methods for better readability.
  • renamed methods for better readability.
  • fixed some bugs
Location:
cryptx/tags/3.4
Files:
3 added
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • cryptx/tags/3.4/cryptx.php

    r2530154 r3102339  
    44 * Plugin URI: http://weber-nrw.de/wordpress/cryptx/
    55 * Description: No more SPAM by spiders scanning you site for email adresses. With CryptX you can hide all your email adresses, with and without a mailto-link, by converting them using javascript or UNICODE. Although you can choose to add a mailto-link to all unlinked email adresses with only one klick at the settings. That's great, isn't it?
    6  * Version: 3.3.3.2
    7  * Requires at least: 4.6
     6 * Version: 3.4
     7 * Requires at least: 6.0
    88 * Author: Ralf Weber
    99 * Author URI: http://weber-nrw.de/
     
    1414
    1515//avoid direct calls to this file, because now WP core and framework has been used
    16 if ( ! function_exists('add_action') ) {
    17     header('Status: 403 Forbidden');
    18     header('HTTP/1.1 403 Forbidden');
    19     exit();
     16if ( ! function_exists( 'add_action' ) ) {
     17    header( 'Status: 403 Forbidden' );
     18    header( 'HTTP/1.1 403 Forbidden' );
     19    exit();
    2020}
    2121
    22 /**
    23  * some basics
    24  */
    25 global $wp_version;
    2622/** @const CryptX version */
    27 define( 'CRYPTX_VERSION', "3.3.2");
     23define( 'CRYPTX_VERSION', "3.4" );
    2824define( 'CRYPTX_BASENAME', plugin_basename( __FILE__ ) );
    2925define( 'CRYPTX_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
    30 define( 'CRYPTX_DIR_URL', rtrim( plugin_dir_url( __FILE__ ), "/" )."/" );
     26define( 'CRYPTX_DIR_URL', rtrim( plugin_dir_url( __FILE__ ), "/" ) . "/" );
    3127define( 'CRYPTX_DIR_PATH', plugin_dir_path( __FILE__ ) );
    32 define( 'CRYPTX_FILENAME', str_replace( CRYPTX_BASEFOLDER.'/', '', plugin_basename(__FILE__) ) );
     28define( 'CRYPTX_FILENAME', str_replace( CRYPTX_BASEFOLDER . '/', '', plugin_basename( __FILE__ ) ) );
    3329
    34 require_once(CRYPTX_DIR_PATH . 'include/functions.php');
     30require_once( CRYPTX_DIR_PATH . 'classes/CryptX.php' );
     31require_once( CRYPTX_DIR_PATH . 'include/admin_option_page.php' );
    3532
    36 require_once(CRYPTX_DIR_PATH . 'include/admin_option_page.php');
     33$CryptX_instance = Cryptx\CryptX::getInstance();
     34$CryptX_instance->startCryptX();
    3735
    38 $cryptX_var = get_option('cryptX');
    3936/**
    40  *  check for needed updates
     37 * Encrypts the given content using the Cryptx shortcode.
     38 *
     39 * @param string $content The content to be encrypted.
     40 * @param string $args (optional) Additional arguments is deprecated and are not used anymore.
     41 *
     42 * @return string The encrypted content wrapped in the Cryptx shortcode.
    4143 */
    42 if( isset( $cryptX_var['version'] ) && version_compare(CRYPTX_VERSION, $cryptX_var['version']) > 0 ) {
    43     cryptx_do_updates();
     44function encryptx( string $content, string $args = "" ): string {
     45    return do_shortcode( '[cryptx]' . $content . '[/cryptx]' );
    4446}
    45 $cryptX_var = rw_loadDefaults();
    46 
    47 $is_js_needed = false;
    48 
    49 foreach($cryptX_var['filter'] as $filter) {
    50     if (@$cryptX_var[$filter]) {
    51         rw_cryptx_filter($filter);
    52     }
    53 }
    54 
    55 add_action( 'activate_' . CRYPTX_BASENAME, 'rw_cryptx_install' );
    56 
    57 // Hook into the 'wp_enqueue_scripts' action
    58 add_action( 'wp_enqueue_scripts', 'cryptx_javascripts_load' );
    59 
    60 
    61 if (@$cryptX_var['metaBox']) {
    62     add_action('admin_menu',         'rw_cryptx_meta_box');
    63     add_action('wp_insert_post',     'rw_cryptx_insert_post' );
    64     add_action('wp_update_post',     'rw_cryptx_insert_post' );
    65 }
    66 
    67 add_filter( 'plugin_row_meta', 'rw_cryptx_init_row_meta', 10, 2 );
    68 
    69 add_filter( 'init', 'rw_cryptx_init_tinyurl');
    70 // add_action( 'parse_request', 'rw_cryptx_parse_request');
    71 
    72 add_shortcode( 'cryptx', 'rw_cryptx_shortcode');
  • cryptx/tags/3.4/include/admin_changelog.php

    r2159075 r3102339  
    44 */
    55function rw_cryptx_settings_tab_content_changelog() {
    6     global $cryptX_var, $rw_cryptx_active_tab;
    7     if ( 'changelog' != $rw_cryptx_active_tab )
     6    if ( 'changelog' != rw_cryptx_getActiveTab() ) {
    87        return;
     8    }
    99
    10 /**
    11  *  the following code is quick and dirty to parse the changelog content of the readme.txt file
    12 */
    13 $file_contents = @implode('', @file(CRYPTX_DIR_PATH . '/readme.txt'));
    14 $file_contents = str_replace(array("\r\n", "\r"), "\n", $file_contents);
    15 $file_contents = trim($file_contents);
    16 // split $file_content into sections
    17 $_sections = preg_split('/^[\s]*==[\s]*(.+?)[\s]*==/m', $file_contents, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
    18 $sections = array();
    19         for ( $i=1; $i <= count($_sections); $i +=2 ) {
    20             $_sections[$i] = $_sections[$i];
    21             $title = $_sections[$i-1];
    22             $sections[str_replace(' ', '_', strtolower($title))] = array('title' => $title, 'content' => $_sections[$i]);
    23         }
    24 // split changelog section into single version entries
    25 $_changelogs = preg_split('/^[\s]*=[\s]*(.+?)[\s]*=/m', $sections['changelog']['content'], -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
    26 $entries = array();
    27 for ( $i=1; $i <= count($_changelogs); $i +=2 ) {
    28     $_changelogs[$i] = $_changelogs[$i];
    29     $version = $_changelogs[$i-1];
    30     $entries[str_replace(' ', '_', strtolower($version))] = array('version' => $version, 'content' => $_changelogs[$i]);
     10    /**
     11     *  the following code is quick and dirty to parse the changelog content of the readme.txt file
     12     */
     13    $file_contents = @implode( '', @file( CRYPTX_DIR_PATH . '/readme.txt' ) );
     14    $file_contents = str_replace( array( "\r\n", "\r" ), "\n", $file_contents );
     15    $file_contents = trim( $file_contents );
     16    // split $file_content into sections
     17    $_sections = preg_split( '/^[\s]*==[\s]*(.+?)[\s]*==/m', $file_contents, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
     18    $sections  = array();
     19    for ( $i = 1; $i <= count( $_sections ); $i += 2 ) {
     20        $_sections[ $i ]                                           = $_sections[ $i ];
     21        $title                                                     = $_sections[ $i - 1 ];
     22        $sections[ str_replace( ' ', '_', strtolower( $title ) ) ] = array(
     23            'title'   => $title,
     24            'content' => $_sections[ $i ]
     25        );
     26    }
     27    // split changelog section into single version entries
     28    $_changelogs = preg_split( '/^[\s]*=[\s]*(.+?)[\s]*=/m', $sections['changelog']['content'], - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
     29    $entries     = array();
     30    for ( $i = 1; $i <= count( $_changelogs ); $i += 2 ) {
     31        $_changelogs[ $i ]                                          = $_changelogs[ $i ];
     32        $version                                                    = $_changelogs[ $i - 1 ];
     33        $entries[ str_replace( ' ', '_', strtolower( $version ) ) ] = array(
     34            'version' => $version,
     35            'content' => $_changelogs[ $i ]
     36        );
     37    }
     38    // rearrange version entries as html
     39    $changelogs = array();
     40    foreach ( $entries as $entry ) {
     41        $content      = $entry['content'];
     42        $content      = ltrim( $content, "\n" );
     43        $content      = str_replace( "* ", "<li>", $content );
     44        $content      = str_replace( "\n", " </li>\n", $content );
     45        $changelogs[] = array(
     46            'version' => "<dt>" . $entry['version'] . "</dt>",
     47            'content' => "<dd><ul>" . $content . "</ul></dd>"
     48        );
     49    }
     50    unset( $file_contents, $_sections, $sections, $_changelogs, $entries );
     51    ?>
     52    <h4><?php _e( "Changelog", 'cryptx' ); ?></h4>
     53    <?php
     54    foreach ( $changelogs as $log ) {
     55        echo "<dl>" . implode( "", $log ) . "</dl>";
     56    }
     57    unset( $changelogs );
    3158}
    32 // rearrange version entries as html
    33 $changelogs = array();
    34 foreach($entries as $entry) {
    35     $content = $entry['content'];
    36     $content = ltrim( $content, "\n");
    37     $content = str_replace("* ", "<li>", $content);
    38     $content = str_replace("\n", " </li>\n", $content);
    39     $changelogs[]= array('version' => "<dt>".$entry['version']."</dt>", 'content' => "<dd><ul>".$content."</ul></dd>");
    40 }
    41 unset( $file_contents, $_sections, $sections, $_changelogs, $entries);
    42     ?>
    43     <h4><?php _e( "Changelog",'cryptx' ); ?></h4>
    44     <?php
    45     foreach($changelogs as $log) {
    46         echo "<dl>".implode("",$log)."</dl>";
    47     }
    48     unset( $changelogs );
    49 }
     59
    5060add_action( 'rw_cryptx_settings_content', 'rw_cryptx_settings_tab_content_changelog' );
  • cryptx/tags/3.4/include/admin_general.php

    r2159075 r3102339  
    44 */
    55function rw_cryptx_settings_tab_content_general() {
    6     global $cryptX_var, $rw_cryptx_active_tab;
    7     if ( 'general' != $rw_cryptx_active_tab )
     6    $CryptX_instance = Cryptx\CryptX::getInstance();
     7    $cryptXOptions = $CryptX_instance->loadCryptXOptionsWithDefaults();
     8    if ( 'general' != rw_cryptx_getActiveTab() )
    89        return;
    910    ?>
     
    1415            <th scope="row"><?php _e("Apply CryptX to...",'cryptx'); ?></th>
    1516            <td>
    16                 <input name="cryptX_var[the_content]"    type="checkbox" value="1" <?php checked( $cryptX_var['the_content'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Content",'cryptx'); ?> <?php _e("(<i>this can be disabled per Post by an Option</i>)",'cryptx'); ?><br/>
    17                 <input name="cryptX_var[the_meta_key]"    type="checkbox" value="1" <?php checked( $cryptX_var['the_meta_key'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Custom fields (<strong>works only with the_meta()!</strong>)",'cryptx'); ?><br/>
    18                 <input name="cryptX_var[the_excerpt]"    type="checkbox" value="1" <?php checked( $cryptX_var['the_excerpt'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Excerpt",'cryptx'); ?><br/>
    19                 <input name="cryptX_var[comment_text]"    type="checkbox" value="1" <?php checked( $cryptX_var['comment_text'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Comments",'cryptx'); ?><br/>
    20                 <input name="cryptX_var[widget_text]"    type="checkbox" value="1" <?php checked( $cryptX_var['widget_text'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Widgets",'cryptx'); ?> <?php _e("(<i>works only on all widgets, not on a single widget</i>!)",'cryptx'); ?>
     17                <input name="cryptX_var[the_content]"    type="checkbox" value="1" <?php checked( $cryptXOptions['the_content'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Content",'cryptx'); ?> <?php _e("(<i>this can be disabled per Post by an Option</i>)",'cryptx'); ?><br/>
     18                <input name="cryptX_var[the_meta_key]"    type="checkbox" value="1" <?php checked( $cryptXOptions['the_meta_key'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Custom fields (<strong>works only with the_meta()!</strong>)",'cryptx'); ?><br/>
     19                <input name="cryptX_var[the_excerpt]"    type="checkbox" value="1" <?php checked( $cryptXOptions['the_excerpt'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Excerpt",'cryptx'); ?><br/>
     20                <input name="cryptX_var[comment_text]"    type="checkbox" value="1" <?php checked( $cryptXOptions['comment_text'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Comments",'cryptx'); ?><br/>
     21                <input name="cryptX_var[widget_text]"    type="checkbox" value="1" <?php checked( $cryptXOptions['widget_text'],    1 ); ?> />&nbsp;&nbsp;<?php _e("Widgets",'cryptx'); ?> <?php _e("(<i>works only on all widgets, not on a single widget</i>!)",'cryptx'); ?>
    2122            </td>
    2223        </tr>
     
    2829        <tr>
    2930            <th scope="row"><?php _e("Excluded ID's...",'cryptx'); ?></th>
    30             <td><input name="cryptX_var[excludedIDs]" value="<?php echo $cryptX_var['excludedIDs']; ?>" type="text" class="regular-text" />
     31            <td><input name="cryptX_var[excludedIDs]" value="<?php echo $cryptXOptions['excludedIDs']; ?>" type="text" class="regular-text" />
    3132            <br/><span class="setting-description"><?php _e("Enter all Page/Post ID's to exclude from CryptX as comma seperated list.",'cryptx'); ?></span>
    32             <br/><input name="cryptX_var[metaBox]" type="checkbox" value="1" <?php checked( $cryptX_var['metaBox'], 1 ); ?> />&nbsp;&nbsp;<?php _e("Enable the CryptX Widget on editing a post or page.",'cryptx'); ?></td>
     33            <br/><input name="cryptX_var[metaBox]" type="checkbox" value="1" <?php checked( $cryptXOptions['metaBox'], 1 ); ?> />&nbsp;&nbsp;<?php _e("Enable the CryptX Widget on editing a post or page.",'cryptx'); ?></td>
    3334        </tr>
    3435
     
    3940        <tr>
    4041            <th scope="row"><?php _e("Type of decryption",'cryptx'); ?></th>
    41             <td><input name="cryptX_var[java]" type="radio" value="1" <?php checked( $cryptX_var['java'], 1 ); ?>/>&nbsp;&nbsp;<?php _e("Use javascript to hide the Email-Link.",'cryptx'); ?><br/>
    42                 <input name="cryptX_var[java]" type="radio" value="0" <?php checked( $cryptX_var['java'], 0 ); ?>/>&nbsp;&nbsp;<?php _e("Use Unicode to hide the Email-Link.",'cryptx'); ?></td>
     42            <td><input name="cryptX_var[java]" type="radio" value="1" <?php checked( $cryptXOptions['java'], 1 ); ?>/>&nbsp;&nbsp;<?php _e("Use javascript to hide the Email-Link.",'cryptx'); ?><br/>
     43                <input name="cryptX_var[java]" type="radio" value="0" <?php checked( $cryptXOptions['java'], 0 ); ?>/>&nbsp;&nbsp;<?php _e("Use Unicode to hide the Email-Link.",'cryptx'); ?></td>
    4344        </tr>
    4445
     
    4950        <tr>
    5051            <th scope="row"><?php _e("Where to load the needed javascript...",'cryptx'); ?></th>
    51             <td><input name="cryptX_var[load_java]" type="radio" value="0"  <?php checked( $cryptX_var['load_java'], 0 ); ?>/>&nbsp;&nbsp;<?php _e("Load the javascript in the <b>header</b> of the page.",'cryptx'); ?><br/>
    52                 <input name="cryptX_var[load_java]" type="radio" value="1"  <?php checked( $cryptX_var['load_java'], 1 ); ?>/>&nbsp;&nbsp;<?php _e("Load the javascript in the <b>footer</b> of the page.",'cryptx'); ?></td>
     52            <td><input name="cryptX_var[load_java]" type="radio" value="0"  <?php checked( $cryptXOptions['load_java'], 0 ); ?>/>&nbsp;&nbsp;<?php _e("Load the javascript in the <b>header</b> of the page.",'cryptx'); ?><br/>
     53                <input name="cryptX_var[load_java]" type="radio" value="1"  <?php checked( $cryptXOptions['load_java'], 1 ); ?>/>&nbsp;&nbsp;<?php _e("Load the javascript in the <b>footer</b> of the page.",'cryptx'); ?></td>
    5354        </tr>
    5455
     
    5859
    5960        <tr>
    60             <th scope="row" colspan="2"><input name="cryptX_var[autolink]" type="checkbox" value="1"  <?php checked( $cryptX_var['autolink'], 1 ); ?>/>&nbsp;&nbsp;<?php _e("Add mailto to all unlinked email addresses",'cryptx'); ?></th>
     61            <th scope="row" colspan="2"><input name="cryptX_var[autolink]" type="checkbox" value="1"  <?php checked( $cryptXOptions['autolink'], 1 ); ?>/>&nbsp;&nbsp;<?php _e("Add mailto to all unlinked email addresses",'cryptx'); ?></th>
    6162        </tr>
    6263
     
    6768        <tr>
    6869            <th scope="row"><?php _e("Whitelist of extensions",'cryptx'); ?></th>
    69             <td><input name="cryptX_var[whiteList]" value="<?php echo $cryptX_var['whiteList']; ?>" type="text" class="regular-text" />
     70            <td><input name="cryptX_var[whiteList]" value="<?php echo $cryptXOptions['whiteList']; ?>" type="text" class="regular-text" />
    7071            <br/><span class="setting-description"><?php _e("<strong>This is a workaround for the 'retina issue'.</strong><br/>You can provide a comma seperated list of extensions like 'jpeg,jpg,png,gif' which will be ignored by CryptX.",'cryptx'); ?></span>
    7172        </tr>
  • cryptx/tags/3.4/include/admin_howto.php

    r2186829 r3102339  
    44 */
    55function rw_cryptx_settings_tab_content_howto() {
    6     global $cryptX_var, $rw_cryptx_active_tab;
    7     if ( 'howto' != $rw_cryptx_active_tab )
     6    if ( 'howto' != rw_cryptx_getActiveTab() )
    87        return;
    98    ?>
  • cryptx/tags/3.4/include/admin_option_page.php

    r2530154 r3102339  
    7474 * save options
    7575 */
    76 function rw_cryptx_saveOptions() {
    77     global $cryptX_var, $data, $rw_cryptx_active_tab;
    78 
    79     if (isset($_POST) && !empty($_POST)) {
    80         if (function_exists('current_user_can') === true && current_user_can('manage_options') === false) {
    81             wp_die("You don't have permission to access!");
    82         }
    83         $saveOptions = cryptx_sanitize_data($_POST['cryptX_var']);
    84         check_admin_referer('cryptX');
    85         if(isset($_POST['cryptX_var_reset'])) {
    86             delete_option('cryptX');
    87             $saveOptions = rw_loadDefaults();
    88         }
    89         if(isset($_POST['cryptX_save_general_settings'])) {
    90             $checkboxes = array(
    91                 'the_content' => 0,
    92                 'the_meta_key' => 0,
    93                 'the_excerpt' => 0,
    94                 'comment_text' => 0,
    95                 'widget_text' => 0,
    96                 'autolink' => 0,
    97                 'metaBox' => 0,
    98             );
    99             $saveOptions = wp_parse_args( $saveOptions, $checkboxes );
    100         }
    101         $saveOptions = wp_parse_args( $saveOptions, rw_loadDefaults() );
    102         update_option( 'cryptX', $saveOptions);
    103         $cryptX_var = rw_loadDefaults();
    104         ?>
    105         <div id="message" class="updated fade">
    106             <p><strong><?php _e('Settings saved.') ?></strong></p>
    107         </div>
    108         <?php
    109     }
     76function rw_cryptx_saveOptions(): void {
     77    if ( isValidPostRequest() ) {
     78        $CryptX_instance = Cryptx\CryptX::getInstance();
     79        $saveOptions = sanitizePostData();
     80
     81        check_admin_referer( 'cryptX' );
     82
     83        if ( isResetPost() ) {
     84            // $saveOptions = rw_Defaults();
     85            $saveOptions = $CryptX_instance->getCryptXOptionsDefaults();
     86        }
     87
     88        if ( isSaveGeneralSettingsPost() ) {
     89            $saveOptions = parseGeneralSettings( $saveOptions );
     90        }
     91
     92        // $saveOptions = wp_parse_args( $saveOptions, rw_loadCryptXOptionsWithDefaults() );
     93        $CryptX_instance->saveCryptXOptions($saveOptions);
     94        // $saveOptions = wp_parse_args( $saveOptions, $CryptX_instance->loadCryptXOptionsWithDefaults() );
     95        // update_option( 'cryptX', $saveOptions );
     96        // $cryptXOptions = rw_loadCryptXOptionsWithDefaults();
     97
     98        displaySuccessMessage();
     99    }
     100}
     101
     102function isValidPostRequest(): bool {
     103    if ( function_exists( 'current_user_can' ) === true && current_user_can( 'manage_options' ) === false ) {
     104        wp_die( "You don't have permission to access!" );
     105    }
     106
     107    return ! empty( $_POST['cryptX_var'] );
     108}
     109
     110function sanitizePostData() {
     111    return cryptx_sanitize_data( $_POST['cryptX_var'] );
     112}
     113
     114function isResetPost(): bool {
     115    return isset( $_POST['cryptX_var_reset'] );
     116}
     117
     118function isSaveGeneralSettingsPost(): bool {
     119    return isset( $_POST['cryptX_save_general_settings'] );
     120}
     121
     122function parseGeneralSettings( $saveOptions ): array {
     123    $checkboxes = [
     124        'the_content'  => 0,
     125        'the_meta_key' => 0,
     126        'the_excerpt'  => 0,
     127        'comment_text' => 0,
     128        'widget_text'  => 0,
     129        'autolink'     => 0,
     130        'metaBox'      => 0,
     131    ];
     132
     133    return wp_parse_args( $saveOptions, $checkboxes );
     134}
     135
     136function displaySuccessMessage(): void {
     137    echo "<div id='message' class='updated fade'><p><strong>";
     138    _e( 'Settings saved.' );
     139    echo "</strong></p></div>";
    110140}
    111141
     
    113143 * sanitize given options
    114144 */
    115 function cryptx_sanitize_data($data) {
    116     if( isset( $data['version']) ) $data['version'] = sanitize_text_field($data['version']);
    117     if( isset( $data['at']) ) $data['at'] = sanitize_text_field($data['at']);
    118     if( isset( $data['dot']) ) $data['dot'] = sanitize_text_field($data['dot']);
    119     if( isset( $data['css_id']) ) $data['css_id'] = sanitize_text_field($data['css_id']);
    120     if( isset( $data['css_class']) ) $data['css_class'] = sanitize_text_field($data['css_class']);
    121     if( isset( $data['the_content']) ) $data['the_content'] = (int) $data['the_content'];
    122     if( isset( $data['the_meta_key']) ) $data['the_meta_key'] = (int) $data['the_meta_key'];
    123     if( isset( $data['the_excerpt']) ) $data['the_excerpt'] = (int) $data['the_excerpt'];
    124     if( isset( $data['comment_text']) ) $data['comment_text'] = (int) $data['comment_text'];
    125     if( isset( $data['java']) ) $data['java'] = (int) $data['java'];
    126     if( isset( $data['load_java']) ) $data['load_java'] = (int) $data['load_java'];
    127     if( isset( $data['opt_linktext']) ) $data['opt_linktext'] = (int) $data['opt_linktext'];
    128     if( isset( $data['autolink']) ) $data['autolink'] = (int) $data['autolink'];
    129     if( isset( $data['alt_linktext']) ) $data['alt_linktext'] = sanitize_text_field($data['alt_linktext']);
    130     if( isset( $data['http_linkimage_title']) ) $data['http_linkimage_title'] = sanitize_text_field($data['http_linkimage_title']);
    131     if( isset( $data['alt_linkimage_title']) ) $data['alt_linkimage_title'] = sanitize_text_field($data['alt_linkimage_title']);
    132     if( isset( $data['excludedIDs']) ) $data['excludedIDs'] = sanitize_text_field($data['excludedIDs']);
    133     if( isset( $data['metaBox']) ) $data['metaBox'] = (bool) $data['metaBox'];
    134     if( isset( $data['excludedIDs']) ) $data['excludedIDs'] = sanitize_text_field($data['excludedIDs']);
    135     if( isset( $data['alt_uploadedimage']) ) $data['alt_uploadedimage'] = sanitize_text_field($data['alt_uploadedimage']);
    136     if( isset( $data['c2i_font']) ) $data['c2i_font'] = sanitize_text_field($data['c2i_font']);
    137     if( isset( $data['c2i_fontSize']) ) $data['c2i_fontSize'] = (int) $data['c2i_fontSize'];
    138     if( isset( $data['c2i_fontRGB']) ) $data['c2i_fontRGB'] = sanitize_text_field($data['c2i_fontRGB']);
    139     if( isset( $data['echo']) ) $data['echo'] = (int) $data['echo'];
    140     if( isset( $data['whiteList']) ) $data['whiteList'] = sanitize_text_field($data['whiteList']);
    141     return $data;
     145function cryptx_sanitize_data( $data ) {
     146    $textFields = [
     147        'version',
     148        'at',
     149        'dot',
     150        'css_id',
     151        'css_class',
     152        'alt_linktext',
     153        'http_linkimage_title',
     154        'alt_linkimage_title',
     155        'excludedIDs',
     156        'alt_uploadedimage',
     157        'c2i_font',
     158        'c2i_fontRGB',
     159        'whiteList'
     160    ];
     161
     162    $intFields = [
     163        'the_content',
     164        'the_meta_key',
     165        'the_excerpt',
     166        'comment_text',
     167        'java',
     168        'load_java',
     169        'opt_linktext',
     170        'autolink',
     171        'c2i_fontSize',
     172        'echo'
     173    ];
     174
     175    $boolFields = [ 'metaBox' ];
     176
     177    foreach ( $textFields as $field ) {
     178        if ( isset( $data[ $field ] ) ) {
     179            $data[ $field ] = sanitize_text_field( $data[ $field ] );
     180        }
     181    }
     182
     183    foreach ( $intFields as $field ) {
     184        if ( isset( $data[ $field ] ) ) {
     185            $data[ $field ] = (int) $data[ $field ];
     186        }
     187    }
     188
     189    foreach ( $boolFields as $field ) {
     190        if ( isset( $data[ $field ] ) ) {
     191            $data[ $field ] = (bool) $data[ $field ];
     192        }
     193    }
     194
     195    return $data;
    142196}
    143197
     
    146200 */
    147201function rw_cryptx_submenu() {
    148     global $cryptX_var, $data, $rw_cryptx_active_tab;
    149     rw_cryptx_saveOptions();
    150     $rw_cryptx_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
    151     ?>
     202    // global $cryptXOptions, $data, $rw_cryptx_active_tab;
     203    rw_cryptx_saveOptions();
     204
     205    // Give meaningful name to tab variable
     206    rw_cryptx_generateHtml();
     207}
     208
     209function rw_cryptx_generateHtml(): void {
     210    ?>
    152211    <div class="cryptx-option-page">
    153         <h1><?php _e("CryptX settings",'cryptx'); ?></h1>
     212        <h1><?php _e("CryptX settings", 'cryptx'); ?></h1>
    154213        <form method="post" action="">
    155         <?php wp_nonce_field('cryptX') ?>
    156 
    157         <h2 class="nav-tab-wrapper">
    158         <?php
    159             do_action( 'rw_cryptx_settings_tab' );
    160         ?>
    161         </h2>
    162         <div class="cryptx-tab-content-wrapper">
    163         <?php
    164             do_action( 'rw_cryptx_settings_content' );
    165         ?>
    166         </div><!-- /.cryptx-tab-content-wrapper -->
     214            <?php wp_nonce_field('cryptX') ?>
     215            <h2 class="nav-tab-wrapper">
     216                <?php
     217                do_action('rw_cryptx_settings_tab');
     218                ?>
     219            </h2>
     220            <div class="cryptx-tab-content-wrapper">
     221                <?php
     222                do_action('rw_cryptx_settings_content');
     223                ?>
     224            </div><!-- /.cryptx-tab-content-wrapper -->
    167225        </form>
    168226    </div><!-- /.cryptx-option-page -->
    169     <?php
    170 }
    171 
     227    <?php
     228}
     229
     230function rw_cryptx_getActiveTab() {
     231    $allowedTabs = ['general', 'presentation', 'howto', 'changelog'];
     232    $tab = $_GET['tab'] ?? 'general';
     233    return in_array($tab, $allowedTabs) ? $tab : 'general';
     234}
    172235/**
    173236 * Option page navigation
    174237 */
    175 function rw_cryptx_settings_tab_presentation(){
    176     global $rw_cryptx_active_tab; ?>
    177     <a class="nav-tab <?php echo $rw_cryptx_active_tab == 'general' || '' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=general' ); ?>">
     238function rw_cryptx_settings_tab_presentation(): void {
     239    //global $rw_cryptx_active_tab;
     240    ?>
     241    <a class="nav-tab <?php echo rw_cryptx_getActiveTab() == 'general' || '' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=general' ); ?>">
    178242        <?php _e("General",'cryptx'); ?>
    179243    </a>
    180     <a class="nav-tab <?php echo $rw_cryptx_active_tab == 'presentation' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=presentation' ); ?>">
     244    <a class="nav-tab <?php echo rw_cryptx_getActiveTab() == 'presentation' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=presentation' ); ?>">
    181245        <?php _e("Presentation",'cryptx'); ?>
    182246    </a>
    183     <a class="nav-tab <?php echo $rw_cryptx_active_tab == 'howto' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=howto' ); ?>">
     247    <a class="nav-tab <?php echo rw_cryptx_getActiveTab() == 'howto' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=howto' ); ?>">
    184248        <?php _e("How to&hellip;",'cryptx'); ?>
    185249    </a>
    186     <a class="nav-tab <?php echo $rw_cryptx_active_tab == 'changelog' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=changelog' ); ?>">
     250    <a class="nav-tab <?php echo rw_cryptx_getActiveTab() == 'changelog' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=changelog' ); ?>">
    187251        <?php _e("Changelog",'cryptx'); ?>
    188252    </a>
    189253    <?php
    190254}
    191 add_action( 'rw_cryptx_settings_tab', 'rw_cryptx_settings_tab_presentation' );
     255add_action( 'rw_cryptx_settings_tab', 'rw_cryptx_settings_tab_presentation');
  • cryptx/tags/3.4/include/admin_presentation.php

    r2159075 r3102339  
    44 */
    55function rw_cryptx_settings_tab_content_presentation() {
    6     global $cryptX_var, $rw_cryptx_active_tab;
    7     if ( 'presentation' != $rw_cryptx_active_tab )
     6    $CryptX_instance = Cryptx\CryptX::getInstance();
     7    $cryptXOptions = $CryptX_instance->loadCryptXOptionsWithDefaults();
     8    if ( 'presentation' != rw_cryptx_getActiveTab() )
    89        return;
    910    ?>
     
    1415        <tr>
    1516            <th><label for="cryptX_var[css_id]"><?php _e("CSS ID",'cryptx'); ?></label></th>
    16             <td><input name="cryptX_var[css_id]" value="<?php echo $cryptX_var['css_id']; ?>" type="text" class="regular-text" /><br /><?php _e("Please be careful using this feature! IDs should be unique. You should prefer of using a css class instead.",'cryptx'); ?></td>
     17            <td><input name="cryptX_var[css_id]" value="<?php echo $cryptXOptions['css_id']; ?>" type="text" class="regular-text" /><br /><?php _e("Please be careful using this feature! IDs should be unique. You should prefer of using a css class instead.",'cryptx'); ?></td>
    1718        </tr>
    1819        <tr>
    1920            <th><label for="cryptX_var[css_class]"><?php _e("CSS Class",'cryptx'); ?></label></th>
    20             <td><input name="cryptX_var[css_class]" value="<?php echo $cryptX_var['css_class']; ?>" type="text" class="regular-text" /></td>
     21            <td><input name="cryptX_var[css_class]" value="<?php echo $cryptXOptions['css_class']; ?>" type="text" class="regular-text" /></td>
    2122        </tr>
    2223    </table>
     
    2728        <tbody>
    2829            <tr>
    29                 <td><input name="cryptX_var[opt_linktext]" type="radio" id="opt_linktext" value="0" <?php checked( $cryptX_var['opt_linktext'], 0 ); ?> /></td>
     30                <td><input name="cryptX_var[opt_linktext]" type="radio" id="opt_linktext" value="0" <?php checked( $cryptXOptions['opt_linktext'], 0 ); ?> /></td>
    3031                <th scope="row"><label for="cryptX_var[at]"><?php _e("Replacement for '@'",'cryptx'); ?></label></th>
    31                 <td><input name="cryptX_var[at]" value="<?php echo $cryptX_var['at']; ?>" type="text" class="regular-text" /></td>
     32                <td><input name="cryptX_var[at]" value="<?php echo $cryptXOptions['at']; ?>" type="text" class="regular-text" /></td>
    3233            </tr>
    3334            <tr>
    3435                <td>&nbsp;</td>
    3536                <th scope="row"><label for="cryptX_var[dot]"><?php _e("Replacement for '.'",'cryptx'); ?></label></th>
    36                 <td><input name="cryptX_var[dot]" value="<?php echo $cryptX_var['dot']; ?>" type="text" class="regular-text" /></td>
     37                <td><input name="cryptX_var[dot]" value="<?php echo $cryptXOptions['dot']; ?>" type="text" class="regular-text" /></td>
    3738            </tr>
    3839
     
    4243
    4344            <tr>
    44                 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext2" value="1" <?php checked( $cryptX_var['opt_linktext'], 1 ); ?> /></td>
     45                <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext2" value="1" <?php checked( $cryptXOptions['opt_linktext'], 1 ); ?> /></td>
    4546                <th><label for="cryptX_var[alt_linktext]"><?php _e("Text for link",'cryptx'); ?></label></th>
    46                 <td><input name="cryptX_var[alt_linktext]" value="<?php echo $cryptX_var['alt_linktext']; ?>" type="text" class="regular-text" /></td>
     47                <td><input name="cryptX_var[alt_linktext]" value="<?php echo $cryptXOptions['alt_linktext']; ?>" type="text" class="regular-text" /></td>
    4748            </tr>
    4849
     
    5253
    5354            <tr>
    54                 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext3" value="2" <?php checked( $cryptX_var['opt_linktext'], 2 ); ?> /></td>
     55                <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext3" value="2" <?php checked( $cryptXOptions['opt_linktext'], 2 ); ?> /></td>
    5556                <th><label for="cryptX_var[alt_linkimage]"><?php _e("Image-URL",'cryptx'); ?></label></th>
    56                 <td><input name="cryptX_var[alt_linkimage]" value="<?php echo $cryptX_var['alt_linkimage']; ?>" type="text" class="regular-text" /></td>
     57                <td><input name="cryptX_var[alt_linkimage]" value="<?php echo $cryptXOptions['alt_linkimage']; ?>" type="text" class="regular-text" /></td>
    5758            </tr>
    5859            <tr>
    5960                <td scope="row">&nbsp;</td>
    6061                <th><label for="cryptX_var[http_linkimage_title]"><?php _e("Title-Tag for the Image",'cryptx'); ?></label></th>
    61                 <td><input name="cryptX_var[http_linkimage_title]" value="<?php echo $cryptX_var['http_linkimage_title']; ?>" type="text" class="regular-text" /></td>
     62                <td><input name="cryptX_var[http_linkimage_title]" value="<?php echo $cryptXOptions['http_linkimage_title']; ?>" type="text" class="regular-text" /></td>
    6263            </tr>
    6364
     
    6768
    6869            <tr>
    69                 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext4" value="3" <?php checked( $cryptX_var['opt_linktext'], 3 ); ?>/></td>
     70                <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext4" value="3" <?php checked( $cryptXOptions['opt_linktext'], 3 ); ?>/></td>
    7071                <th><label for="upload_image_button"><?php _e("Select an uploaded image",'cryptx'); ?></label></th>
    7172                <td>
     
    7374                    <input id="remove_image_button" type="button" class="button button-link-delete hidden" value="<?php _e( 'Delete image' ); ?>" />
    7475                    <span id="opt_linktext4_notice"><?php _e("You have to upload an image first before this option can be activated.",'cryptx'); ?></span>
    75                     <input type='hidden' name='cryptX_var[alt_uploadedimage]' id='image_attachment_id' value='<?php echo $cryptX_var['alt_uploadedimage']; ?>'>
     76                    <input type='hidden' name='cryptX_var[alt_uploadedimage]' id='image_attachment_id' value='<?php echo $cryptXOptions['alt_uploadedimage']; ?>'>
    7677                    <div>
    77                         <img id='image-preview' src='<?php echo wp_get_attachment_url( $cryptX_var['alt_uploadedimage'] ); ?>'>
     78                        <img id='image-preview' src='<?php echo wp_get_attachment_url( $cryptXOptions['alt_uploadedimage'] ); ?>'>
    7879                    </div>
    7980                </td>
     
    8283                <td>&nbsp;</td>
    8384                <th><label for="cryptX_var[alt_linkimage_title]"><?php _e("Title-Tag for the Image",'cryptx'); ?></label></th>
    84                 <td><input name="cryptX_var[alt_linkimage_title]" value="<?php echo $cryptX_var['alt_linkimage_title']; ?>" type="text" class="regular-text" /></td>
     85                <td><input name="cryptX_var[alt_linkimage_title]" value="<?php echo $cryptXOptions['alt_linkimage_title']; ?>" type="text" class="regular-text" /></td>
    8586            </tr>
    8687
     
    9091
    9192            <tr>
    92                 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext4" value="4" <?php checked( $cryptX_var['opt_linktext'], 4 ); ?> /></td>
     93                <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext4" value="4" <?php checked( $cryptXOptions['opt_linktext'], 4 ); ?> /></td>
    9394                <th colspan="2"><?php _e("Text scrambled by AntiSpamBot (<small>Try it and look at your site and check the html source!</small>)",'cryptx'); ?></th>
    9495            </tr>
     
    99100
    100101            <tr>
    101                 <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext5" value="5" <?php checked( $cryptX_var['opt_linktext'], 5 ); ?> /></td>
     102                <td scope="row"><input type="radio" name="cryptX_var[opt_linktext]" id="opt_linktext5" value="5" <?php checked( $cryptXOptions['opt_linktext'], 5 ); ?> /></td>
    102103                <th><?php _e("Convert Email to PNG-image",'cryptx'); ?></th>
    103                 <td><?php _e("Example with the saved options: ",'cryptx'); ?> <img src="<?php echo get_bloginfo('url'); ?>/<?php echo md5( get_bloginfo('url') ); ?>/<?php echo antispambot("CryptX@".rw_cryptx_getDomain()); ?>" align="absmiddle" alt="<?php echo antispambot("CryptX@".rw_cryptx_getDomain()); ?>" title="<?php echo antispambot("CryptX@".rw_cryptx_getDomain()); ?>"></td>
     104                <td><?php _e("Example with the saved options: ",'cryptx'); ?> <img src="<?php echo get_bloginfo('url'); ?>/<?php echo md5( get_bloginfo('url') ); ?>/<?php echo antispambot("CryptX@".$CryptX_instance->getDomain()); ?>" align="absmiddle" alt="<?php echo antispambot("CryptX@".$CryptX_instance->getDomain()); ?>" title="<?php echo antispambot("CryptX@".$CryptX_instance->getDomain()); ?>"></td>
    104105            </tr>
    105106            <tr>
     
    108109                <td><select name="cryptX_var[c2i_font]">
    109110                    <?php
    110                         foreach(rw_cryptx_listDir(CRYPTX_DIR_PATH.'fonts', "ttf") as $font) {
     111                        foreach($CryptX_instance->getFilesInDirectory( CRYPTX_DIR_PATH . 'fonts', "ttf") as $font) {
    111112                            printf('<option value="%1$s" %3$s>%2$s</option>',
    112113                                    $font,
    113114                                    str_replace(".ttf", "", $font),
    114                                     ($cryptX_var['c2i_font'] == $font)? "selected" : ""
     115                                    ($cryptXOptions['c2i_font'] == $font)? "selected" : ""
    115116                                    );
    116117                        }
     
    121122                <td>&nbsp;</td>
    122123                <th><label for="cryptX_var[c2i_fontSize]"><?php _e("Font size (pixel)",'cryptx'); ?></label></th>
    123                 <td><input name="cryptX_var[c2i_fontSize]" value="<?php echo $cryptX_var['c2i_fontSize']; ?>" type="number" class="regular-text" /></td>
     124                <td><input name="cryptX_var[c2i_fontSize]" value="<?php echo $cryptXOptions['c2i_fontSize']; ?>" type="number" class="regular-text" /></td>
    124125            </tr>
    125126            <tr>
    126127                <td>&nbsp;</td>
    127128                <th><label for="cryptX_var[c2i_fontRGB]"><?php _e("Font color (RGB)",'cryptx'); ?></label></th>
    128                 <td><input name="cryptX_var[c2i_fontRGB]" value="<?php echo $cryptX_var['c2i_fontRGB']; ?>" type="text" class="color-field regular-text" /></td>
     129                <td><input name="cryptX_var[c2i_fontRGB]" value="<?php echo $cryptXOptions['c2i_fontRGB']; ?>" type="text" class="color-field regular-text" /></td>
    129130            </tr>
    130131        </tbody>
  • cryptx/tags/3.4/js/cryptx.js

    r1111020 r3102339  
    1 function DeCryptString( s )
    2 {
    3     var n = 0;
    4     var r = "mailto:";
    5     var z = 0;
    6     for( var i = 0; i < s.length/2; i++)
    7     {
    8         z = s.substr(i*2, 1);
    9         n = s.charCodeAt( i*2+1 );
    10         if( n >= 8364 )
    11         {
    12         n = 128;
    13         }
    14         r += String.fromCharCode( n - z );
     1const UPPER_LIMIT = 8364;
     2const DEFAULT_VALUE = 128;
     3
     4/**
     5 * Decrypts an encrypted string using a specific encryption algorithm.
     6 *
     7 * @param {string} encryptedString - The encrypted string to be decrypted.
     8 * @returns {string} The decrypted string.
     9 */
     10function DeCryptString(encryptedString) {
     11    let charCode = 0;
     12    let decryptedString = "mailto:";
     13    let encryptionKey = 0;
     14
     15    for (let i = 0; i < encryptedString.length; i += 2) {
     16        encryptionKey = encryptedString.substr(i, 1);
     17        charCode = encryptedString.charCodeAt(i + 1);
     18
     19        if (charCode >= UPPER_LIMIT) {
     20            charCode = DEFAULT_VALUE;
     21        }
     22
     23        decryptedString += String.fromCharCode(charCode - encryptionKey);
    1524    }
    16     return r;
     25
     26    return decryptedString;
    1727}
    1828
    19 function DeCryptX( s )
     29/**
     30 * Redirects the current page to the decrypted URL.
     31 *
     32 * @param {string} encryptedUrl - The encrypted URL to be decrypted and redirected to.
     33 * @return {void}
     34 */
     35function DeCryptX( encryptedUrl )
    2036{
    21     location.href=DeCryptString( s );
     37    location.href=DeCryptString( encryptedUrl );
    2238}
  • cryptx/tags/3.4/readme.txt

    r2949844 r3102339  
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4026696
    44Tags: encode, antispam, email, spam, spider, unicode, mailto, filter, spam bot, decrypt, encrypt, mail, javascript, post, page, widget, image, comment, excerpt, custom fields
    5 Requires at least: 4.6
    6 Tested up to: 6.3
    7 Stable tag: 3.3.3.2
    8 Requires PHP: 5.6
     5Requires at least: 6.0
     6Tested up to: 6.5.4
     7Stable tag: 3.4
     8Requires PHP: 8.2
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2222
    2323== Changelog ==
     24= 3.4 =
     25* main code rewritten as class to prevent problems with WordPress or other plugin functions.
     26* added documentation blocks to class methods for better readability.
     27* renamed methods for better readability.
     28* fixed some bugs
    2429= 3.3.3.2 =
    2530* fixed the "Double Slashes in cryptx-asset-URL" issue
Note: See TracChangeset for help on using the changeset viewer.