Herzlich willkommen im Archiv vom ABAKUS Online Marketing Forum
Du befindest Dich im Archiv vom ABAKUS Online Marketing Forum. Hier kannst Du Dich für das Forum mit den aktuellen Beiträgen registrieren.
Code: Alles auswählen
<?php
/*
Plugin Name: 123 HTML
Plugin URI: http://schnurpsel.de/wordpress-plugins/123-html/
Description: Setzt an die URLs ein '.html' hinten dran.
Author: Ingo Henze
Version: 0.18
Author URI: http://putzlowitsch.de/
*/
// Einstellungen für das Plugin
// Einstellungen laden
$plw123htm_options = get_option( 'plw123htm_options' );
// noch keine vorhanden, dann mit Default-Werten vorbelegen
if( !is_array( $plw123htm_options ) ) {
$plw123htm_options = array( // Verwenden ...
'use_post_link' => true, // für Artikel
'use_page_link' => true, // für Seiten
'use_category_link' => false, // für Kategorien
'use_tag_link' => false, // für Tags
'use_year_link' =>false, // für Jahresarchiv
'use_month_link' => false, // für Monatsarchive
'use_day_link' => false, // für Tagesarchiv
'opt_category_link' => false, // Verbindestrichung für Kategorien
'opt_archive_link' => false // Verbindestrichung für Archive
);
}
// wenn vorhanden, gegebenenfalls fehlende mit Default-Werten vorbelegen
else {
if( !array_key_exists( 'use_post_link', $plw123htm_options ) )
$plw123htm_options['use_post_link'] = true;
if( !array_key_exists( 'use_page_link', $plw123htm_options ) )
$plw123htm_options['use_page_link'] = true;
if( !array_key_exists( 'use_category_link', $plw123htm_options ) )
$plw123htm_options['use_category_link'] = false;
if( !array_key_exists( 'use_tag_link', $plw123htm_options ) )
$plw123htm_options['use_tag_link'] = false;
if( !array_key_exists( 'use_year_link', $plw123htm_options ) )
$plw123htm_options['use_year_link'] = false;
if( !array_key_exists( 'use_month_link', $plw123htm_options ) )
$plw123htm_options['use_month_link'] = false;
if( !array_key_exists( 'use_day_link', $plw123htm_options ) )
$plw123htm_options['use_day_link'] = false;
if( !array_key_exists( 'opt_category_link', $plw123htm_options ) )
$plw123htm_options['opt_category_link'] = false;
if( !array_key_exists( 'opt_archive_link', $plw123htm_options ) )
$plw123htm_options['opt_archive_link'] = false;
}
// Die Endung .html aus der Request-URI entfernen
function plw123htm_link_remove_html() {
global $plw123htm_options;
$request_uri = $_SERVER['REQUEST_URI'];
// bestimmte URIs unverändert lassen
if( preg_match( "#/wp-admin/#", $request_uri ) )
return;
$permalink_structure = get_option( 'permalink_structure' );
$use_trailing_slashes = ( substr($permalink_structure, -1, 1) == '/' ) ? true : false;
$request_uri = preg_replace( '/\.html/i', "", $request_uri );
// Bei einem Kategorie-Link die Bindestriche in Schrägstriche umwandeln
$cat_base = get_option( 'category_base' );
if( empty($cat_base) )
$cat_base = '/category';
else
$cat_base = rtrim( $cat_base, '/' );
/* if( $cat_base == '/.' )
$request_uri = '/.'.$request_uri; */
$request_uri = preg_replace( "#^$cat_base(.*)-#i", "$cat_base$2/", $request_uri );
// Ab WP-Version 2.3 müssen auch die Tag-Links behandelt werden
// die Verbindestrichung erfolgt wie bei Kategorien
// Bei einem Tag-Link die Bindestriche in Schrägstriche umwandeln
if( version_compare( get_bloginfo('version'), '2.3', '>=') ) {
$plw_tag_base = get_option('tag_base');
if( empty($plw_tag_base) )
$plw_tag_base = '/tag';
else
$plw_tag_base = rtrim( $plw_tag_base, '/' );
$plw_tag_base = preg_quote( $plw_tag_base, '#' );
$plw_request_uri = preg_replace( "#^$plw_tag_base(.*)-#i", "$plw_tag_base$2/", $plw_request_uri );
}
// Bei einem Archiv (Monat / Tag) die Bindestriche in Schrägstriche umwandeln
if( $plw123htm_options['opt_archive_link'] && preg_match( "#\d{4}-\d{2}(-\d{2}|)#", $request_uri ) ) {
$home = rtrim( get_option( 'home' ), '/' ).'/';
if( preg_match( "#^$home(.*)#", $request_uri, $matches ) )
$request_uri = $matches[1];
else
$home='';
$request_uri = $home.strtr( $request_uri, '-', '/' );
}
if( $use_trailing_slashes )
$request_uri = trailingslashit( $request_uri );
$_SERVER['REQUEST_URI'] = $request_uri;
}
plw123htm_link_remove_html();
// Filter für die Linkerzeugung hinzufügen
function plw123htm_link_append_html( $link ) {
$link = rtrim( $link, '/' );
return $link.'.html';
}
function plw123htm_link_append_html_to_cat( $link ) {
global $plw123htm_options;
$link = rtrim( $link, '/' );
// Bei einem Kategorie-Link die Schrägstriche in Bindestriche umwandeln
if( $plw123htm_options['opt_category_link'] ) {
$home = rtrim( get_option('home'), '/' );
$cat_base = get_option('category_base');
if( empty($cat_base) )
$cat_base = '/category/';
else
$cat_base = rtrim( $cat_base, '/' ).'/';
$home .= $cat_base;
if( preg_match( "#^$home(.*)#", $link, $matches ) )
$link = $matches[1];
else
$home='';
$link = $home.strtr( $link, '/', '-' );
}
return $link.'.html';
}
function plw123htm_link_append_html_to_arc( $link ) {
global $plw123htm_options;
$link = rtrim( $link, '/' );
// Bei einem Archiv (Monat / Tag) die Schrägstriche in Bindestriche umwandeln
if( $plw123htm_options['opt_archive_link'] ) {
$home = rtrim( get_option('home'), '/' ).'/';
if( preg_match( "#^$home(.*)#", $link, $matches ) )
$link = $matches[1];
else
$home='';
$link = $home.strtr( $link, '/', '-' );
}
return $link.'.html';
}
function plw_feed_link( $link ) {
// html in Feedlinks entfernen
if( preg_match( '~(.*)\.html(/feed.*)$~i', $link, $treffer ) ) {
$link = $treffer[1].$treffer[2];
}
return $link;
}
add_filter( 'post_comments_feed_link', 'plw_feed_link' );
add_filter( 'category_feed_link', 'plw_feed_link' );
if( $plw123htm_options['use_post_link'] )
add_filter( 'post_link', 'plw123htm_link_append_html' );
if( $plw123htm_options['use_page_link'] )
add_filter( 'page_link', 'plw123htm_link_append_html' );
if( $plw123htm_options['use_category_link'] )
add_filter( 'category_link', 'plw123htm_link_append_html_to_cat' );
if( $plw123htm_options['use_tag_link'] )
add_filter( 'tag_link', 'plw123htm_link_append_html' );
if( $plw123htm_options['use_year_link'] )
add_filter( 'year_link', 'plw123htm_link_append_html' );
if( $plw123htm_options['use_month_link'] )
add_filter( 'month_link', 'plw123htm_link_append_html_to_arc' );
if( $plw123htm_options['use_day_link'] )
add_filter( 'day_link', 'plw123htm_link_append_html_to_arc' );
// Admin-Panel
function plw123htm_options_subpanel() {
global $plw123htm_options;
if (isset($_POST['plw123htm_update'])) {
// Optionen
$plw123htm_options['use_post_link'] = isset($_POST['plw123htm_opt_upl']);
$plw123htm_options['use_page_link'] = isset($_POST['plw123htm_opt_ual']);
$plw123htm_options['use_category_link'] = isset($_POST['plw123htm_opt_ucl']);
$plw123htm_options['use_tag_link'] = isset($_POST['plw123htm_opt_utl']);
$plw123htm_options['use_year_link'] = isset($_POST['plw123htm_opt_uyl']);
$plw123htm_options['use_month_link'] = isset($_POST['plw123htm_opt_uml']);
$plw123htm_options['use_day_link'] = isset($_POST['plw123htm_opt_udl']);
$plw123htm_options['opt_category_link'] = isset($_POST['plw123htm_opt_ocl']);
$plw123htm_options['opt_archive_link'] = isset($_POST['plw123htm_opt_oal']);
update_option('plw123htm_options', $plw123htm_options );
?><div class="updated"><p><strong>Einstellungen wurden gespeichert.</strong></p></div>
<?php
}
$plugindata = get_plugin_data( __FILE__ );
?>
<div class="wrap" style="height:100%">
<form method="post" id="plw123htm_optform" onsubmit="return createLists()">
<h2><?php echo $plugindata['Title']; ?> Einstellungen</h2>
<p>Plugin-Version <?php echo $plugindata['Version']; ?></p>
<p><?php echo $plugindata['Description']; ?></p>
<fieldset class="options" style="clear:both;"><legend>Optionen:</legend>
<table cellspacing="2" cellpadding="5" class="editform">
<tr><th><label>Verwendung: </label></th><td><input type="checkbox" name="plw123htm_opt_upl" value="1" <?php if($plw123htm_options['use_post_link']) echo 'checked="checked"'; ?> /><label> für Blogbeiträge</label></td></tr>
<tr><td> </td><td><input type="checkbox" name="plw123htm_opt_ual" value="1" <?php if($plw123htm_options['use_page_link']) echo 'checked="checked"'; ?> /><label> für Seiten</label></td></tr>
<tr><td> </td><td><input type="checkbox" name="plw123htm_opt_ucl" value="1" <?php if($plw123htm_options['use_category_link']) echo 'checked="checked"'; ?> /><label> für Kategorien</label></td></tr>
<tr><td> </td><td><input type="checkbox" name="plw123htm_opt_utl" value="1" <?php if($plw123htm_options['use_tag_link']) echo 'checked="checked"'; ?> /><label> für Tags (ab Wordpress 2.3)</label></td></tr>
<tr><td> </td><td><input type="checkbox" name="plw123htm_opt_uyl" value="1" <?php if($plw123htm_options['use_year_link']) echo 'checked="checked"'; ?> /><label> für Jahresarchiv</label></td></tr>
<tr><td> </td><td><input type="checkbox" name="plw123htm_opt_uml" value="1" <?php if($plw123htm_options['use_month_link']) echo 'checked="checked"'; ?> /><label> für Monatsarchiv</label></td></tr>
<tr><td> </td><td><input type="checkbox" name="plw123htm_opt_udl" value="1" <?php if($plw123htm_options['use_day_link']) echo 'checked="checked"'; ?> /><label> für Tagesarchiv</label></td></tr>
<tr><th><label>Optimierung: </label></th><td><input type="checkbox" name="plw123htm_opt_ocl" value="1" <?php if($plw123htm_options['opt_category_link']) echo 'checked="checked"'; ?> /><label> in Kategorielinks '/' durch '-' ersetzen</label></td></tr>
<tr><td> </td><td><input type="checkbox" name="plw123htm_opt_oal" value="1" <?php if($plw123htm_options['opt_archive_link']) echo 'checked="checked"'; ?> /><label> in Archivlinks '/' durch '-' ersetzen</label></td></tr>
</table>
</fieldset>
<div class="submit" style="clear:both;">
<input type="submit" name="plw123htm_update" value="Einstellungen speichern »" />
</div>
</form>
</div><?php
}
function plw123htm_add_admin_panel() {
if (function_exists('add_options_page')) {
add_options_page('123 HTML', '123 HTML', 8, basename(__FILE__), 'plw123htm_options_subpanel');
}
}
add_action( 'admin_menu', 'plw123htm_add_admin_panel' );
?>
Code: Alles auswählen
function plw123htm_link_append_html($link) {
if (preg_match('/^[a-z][a-z0-9.+-]*:/i', $link) != 1) { // Kein Schema, keine absolute URI (siehe RFC 3986, 3 & 3.1).
$link = rtrim($link, '/') . '.html';
}
return $link;
}