Charset Konvertieren

Java unterstützt auf einfache Art und Weise die Konvertierung von Zeichensätzen:

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

Charset utf8 = Charset.forName("UTF-8");
Charset iso88591 = Charset.forName("ISO-8859-1");

//get byte array from string
ByteBuffer utf8Buffer = ByteBuffer.wrap( utf8String.getBytes() );

//convert byte array from UTF-8 to ISO-8859-1
ByteBuffer iso88591Buffer = iso88591.encode( utf8.decode( utf8Buffer ) );

//parse byte array to ISO-8859-1 string
String iso88591String = new String( iso88591Buffer.array(), "ISO-8859-1" ); 

Nähere Angaben zu den unterstützten Zeichensätzen findet sich in der Dokumentation der Klasse Charset.

Um mit Java die Daten aus einer Oracle Datenbank von ISO-8859-1 in UTF-8 konvertieren kann man folgendermassen vorgehen:

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@server:port:sid", "username", "password");

PreparedStatement selectStmt = connection.prepareStatement("SELECT id,subject FROM messages");
ResultSet resultSet = selectStmt.executeQuery();

Charset utf8 = Charset.forName("UTF-8");
Charset iso88591 = Charset.forName("ISO-8859-1");

System.out.println( "Converting Records..." );

while( resultSet.next() ){
    byte[] raw = resultSet.getBytes("subject");
    ByteBuffer iso88591Buffer = ByteBuffer.wrap(raw);

    //do the actual charset conversion
    ByteBuffer utf8Buffer = utf8.encode( iso88591.decode(iso88591Buffer) );
    
    try{
        String iso88591Str = new String(iso88591Buffer.array(),"UTF8");
        String utf8Str = new String(utf8Buffer.array(),"UTF8");
        
        System.out.println("UTF8: '" + iso88591Str + "' => '" + utf8Str + "'");
        
        PreparedStatement updateStmt = connection.prepareStatement("UPDATE messages SET subject = ? WHERE id = ?");
        updateStmt.setString(1,utf8Str);
        updateStmt.setInt(2, resultSet.getInt("id"));
        updateStmt.executeUpdate();
        updateStmt.close();
        
    } catch( UnsupportedEncodingException e ){}
}

if( selectStmt != null ){
    selectStmt.close();
}

WooCommerce: E-Mail Adresse bestätigen

Im WooCommerce Checkout Prozess lässt sich ganz einfach ein zusätzliches Feld für die Validierung der eingegebenen E-Mail-Adresse hinzufügen:

billing_email_confirm

add_filter('woocommerce_checkout_fields',function($fields){
    $billing_email_confirm = array(
        'label'            => 'E-Mail-Adresse bestätigen',
        'placeholder'    => '',
        'required'        => true,
        'class'            => apply_filters('woocommerce_billing_email_confirm_field_class',array('form-row-first')),
        'clear'            => true,
        'validate'        => array('email'),
    );
    $billing_email_index = array_search('billing_email', array_keys($fields['billing']));
  
    if( $billing_email_index ){
        $fields['billing'] = array_slice($fields['billing'],0,$billing_email_index + 1,true) +
            array( 'billing_email_confirm' => $billing_email_confirm ) +
            array_slice($fields['billing'],$billing_email_index + 1,null,true);
    } else {
        $fields['billing']['billing_email_confirm'] = $billing_email_confirm;
    }

    return $fields;
});

add_filter('woocommerce_process_checkout_field_billing_email_confirm',function($email_confirm=''){
    global $woocommerce;
    $billing_email = $woocommerce->checkout->posted['billing_email'];

    if( strtolower($email_confirm) != strtolower($billing_email) ){
        $notice = '<strong>E-Mail-Adressen stimmen nicht überein</strong>';

        if ( version_compare( WC_VERSION, '2.3', '<' ) ) {
            $woocommerce->add_error($notice);
        } else {
            wc_add_notice($notice,'error');
        }
    }

    return $email_confirm;
});

add_filter('default_checkout_billing_email_confirm',function($value=null,$field='billing_email_confirm'){
    if( is_user_logged_in() ){
        global $current_user;
        $value = $current_user->user_email;
    }
    return $value;
},10,2);

Oracle XE: Change Ports

Um die Standartports von Oracle XE zu ändern, einfach folgende Schritte ausführen:

  1. Verbindung zu Oracle XE mit SQLPlus aufbauen
    $: sqlplus system
    SQL*Plus: Release 11.2.0.2.0 Production on Mo Dez 21 18:59:09 2015
    Copyright (c) 1982, 2014, Oracle.  All rights reserved.
    
    Enter password:
    
    Connected to:
    Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
    
    SQL>
  2. Aktuelle Ports anzeigen
    SQL> SELECT DBMS_XDB.getHttpPort AS "HTTP-Port"
    ,DBMS_XDB.getFtpPort AS "FTP-Port" FROM dual;
    
    HTTP-Port FTP-Port
    --------- ----------
         8080          0
  3. Ports anpassen
    SQL> BEGIN
      DBMS_XDB.setHttpPort('3030');
      DBMS_XDB.setFtpPort('2100');
    END;
    /
    
    PL/SQL procedure successfully completed.
  4. Extra: Dienst Deaktivieren
    Wenn der Port auf 0 gesetzt wird, deaktiviert das den Dienst.

Really Simple SSL

SSL für die gesamte WordPress Webseite – mit nur einem Klick!

SSL für die gesamte WordPress Webseite – mit nur einem Klick!

  • The plugin handles most issues that WordPress has with ssl, like the much discussed loadbalancer issue, or when there are no server variables set at all.
  • All incoming requests are redirected to https. If possible with .htaccess, or else with javascript.
  • The site url and home url are changed to https.
  • Your insecure content is fixed by replacing all http:// urls with the protocol-independent //. Dynamically, so no database changes are made (except for the siteurl and homeurl).

Really Simple SSL – Plugin Seite

404 Seite leicht gemacht

Create your custom 404 Page as a normal WordPress Page using the full power of WordPress. You can use a Custom Page Template or Custom Fields, you can set a Featured Image – everything like on every other Page. Then go to ‚Settings‘ -> ‚404 Error Page‘ from your WordPress Dashbord and select the created Page as your 404 error page. That’s it!

Plugin Homepage

The easiest way to create a custom 404 error page in WordPress

The free WordPress 404page Plugin allows you to define any desired WordPress Page as your custom 404 file not found error page. No programming skills needed. Works with every theme! Plugin Homepage: http://smartware.cc/free-wordpress-plugins/404page/ Download: http://wordpress.org/plugins/404page/

Product URL without Type

Produkte in WooCommerce aufrufen, ohne den /product Slug in der URL.

Um Produkte in WooCommerce direkt aufzurufen, ohne den /product Slug in der URL zu haben, kann folgender Schnipsel verwendet werden:

add_filter('post_type_link',function($permalink, $post, $leavename){
    if (!gettype($post) == 'post') {
        return $permalink;
    }
  
    switch ($post->post_type) {
        case 'product':
            if( !strpos($permalink,'?') ){
                $permalink = get_home_url() . '/' . $post->post_name . '/';
            }
            break;
    }
 
    return $permalink;
},10,3);

add_action('pre_get_posts',function( $query ){
    global $wpdb;
 
    if(!$query->is_main_query()) {
        return;
    }
    $post_name = $query->get('pagename');

    $post_type = $wpdb->get_var(
        $wpdb->prepare(
            'SELECT post_type FROM ' . $wpdb->posts . ' WHERE post_name = %s AND post_type != \'attachment\' LIMIT 1',
            $post_name
        )
    );
 
    switch($post_type) {
        case 'product':
            $query->set('product', $post_name);
            $query->set('post_type', $post_type);
            $query->is_single = true;
            $query->is_page = false;
            break;
    }
});

Posts „Privat“ by Default – iOS App

Die Sichtbarkeit neuer Posts die aus der WordPress App erstellt werden automatisch auf Privat setzen:

add_action('post_submitbox_misc_actions',function(){
  global $post;
  
  if( 'publish' == $post->post_status ){
    $visibility = 'public';
    $i18n = __('Public');
    
  } elseif( !empty( $post->post_password ) ){
    $visibility = 'password';
    $i18n = __('Password protected');
    
  } elseif ( $post_type == 'post' && is_sticky( $post->ID ) ) {
    $visibility = 'public';
    $i18n = __('Public, Sticky');

  } else {
    $post->post_password = '';
    $visibility = 'private';
    $i18n = __('Private');
  }
  
  echo '<script type="text/javascript">(function($){'.
    'try{'.
      '$("#post-visibility-display").text("'.$i18n.'");'.
      '$("#hidden-post-visibility").val("'.$visibility.'");'.
      '$("#visibility-radio-'.$visibility.'").prop("checked", true);'.
    '} catch(err){}'.
  '})(jQuery);</script>';
});