This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Plugin Name: WP Translit Plugin URI: http://blog.urosevic.net/wordpress/wp-translit/ Description: Transliterate text from Serbian Cyrillic to Latin script in posts, pages and feeds. After installation check Settings. Author: Aleksandar Urošević Version: 0.3.9 Author URI: http://urosevic.net Thanks to: http://www.emanueleferonato.com/2008/02/15/how-to-create-a-wordpress-widget/ http://lonewolf-online.net/computers/wordpress/create-widgets-control-panels/ http://kimmo.suominen.com/sw/srlatin/ http://us3.php.net/ob_start */ define( 'WPT_VER', "0.3.9" ); add_action('init', 'wpt_init'); add_action('plugins_loaded', 'wpt_register_widget'); add_action('admin_menu', 'wpt_menu'); add_action('do_translit', 'wp_translit'); add_action('wptranslit', 'wpt_inline'); if ( function_exists('wp_translit') ) { $blog_url = get_bloginfo('url'); $wpt_dir = PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)); } if ( is_admin() ) { $plugin = plugin_basename(__FILE__); add_filter("plugin_action_links_$plugin", 'wptConfigLink' ); } function wpt_init() { load_plugin_textdomain( 'wpt', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' ); hdr_lang(); // get default language from HTTP headers wpt_set_lang(); // determine output script } function wptConfigLink( $links ) { $settings_link = ''.__('Settings').''; array_unshift( $links, $settings_link ); return $links; } function wpt_menu() { add_options_page(__('WP Translit Options', 'wpt'), __('WP Translit', 'wpt'), 'manage_options', 'wp-translit', 'wpt_options'); } function wpt_options() { if ( isset($_POST['wpt-submit']) ) { $options['widget_title'] = htmlspecialchars($_POST['wpt-wtitle']); $options['widget_style'] = $_POST['wpt-wstyle']; $options['gt_show'] = isset($_POST['wpt-gtshow']); $options['gt_lang'] = $_POST['wpt-gtlang']; $options['gt_text'] = htmlspecialchars($_POST['wpt-gttext']); $options['inline_class'] = strip_tags($_POST['wpt-iclass']); $options['inline_delimiter'] = htmlspecialchars($_POST['wpt-idelim']); $options['inline_prefix'] = htmlspecialchars($_POST['wpt-iprefix']); $options['inline_suffix'] = htmlspecialchars($_POST['wpt-isuffix']); $options['inline_ashow'] = isset($_POST['wpt-ashow']); update_option("wptranslit", $options); } // inicijalizujem opcije dodatka $options = get_option("wptranslit"); if ( !is_array( $options ) ) { $options = array( "widget_title" => "Избор писма", "widget_style" => "list", "gt_show" => true, "gt_lang" => "en", "gt_text" => "Read in bad English", "inline_delimiter" => " | ", "inline_prefix" => "", "inline_suffix" => "", "inline_class" => "wpt_inline", "inline_ashow" => true ); update_option("wptranslit", $options); } ?>

".WPT_VER.""; ?>

<?php do_action("wptranslit"); ?>

/>
/>

name="wpt-ashow" id="wpt-ashow" />

name="wpt-gtshow" id="wpt-gtshow" />
/>
/>
/>
/>
/>

support forum.', 'wpt'), "http://wordpress.org/tags/wp-translit?forum_id=10"); ?>

WP Translit and my other WordPress extensions, feel free to support my work with donation.', 'wpt'), "http://wordpress.org/extend/plugins/wp-translit/", "http://profiles.wordpress.org/users/urkekg/", "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q6Q762MQ97XJ6"); ?>

".__("This widget will display WP Translit in sidebar.", "wpt")."

"; echo "

".sprintf(__("Go to %s to configure it.", "wpt"), ''.__("Settings").'')."

"; } // function wpt_widget_control // Functions to print widget in sidebar function wpt_widget($args) { extract($args); // inicijalizujem opcije dodatka $options = get_option("wptranslit"); if ( !is_array( $options ) ) { $options = array( "widget_title" => "Избор писма", "widget_style" => "list", "gt_show" => true, "gt_lang" => "en", "gt_text" => "Read in bad English", "inline_delimiter" => " | ", "inline_prefix" => "", "inline_suffix" => "", "inline_class" => "wpt_inline", "inline_ashow" => true ); update_option("wptranslit", $options); } echo $before_widget; echo $before_title; echo strip_tags(stripslashes($options['widget_title'])); echo $after_title; // Which wiget style to print out? if ( $options['widget_style'] == "list" ) { wpt_widget_list(); } else { wpt_widget_drop(); } echo $after_widget; } function wpt_widget_list() { $current_uri = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; $this_page_url = "http://" . $current_uri; $gtlink = ""; if ( isset($_REQUEST['lng']) ) { $wpt_lang = $_REQUEST['lng']; } elseif ( isset($_COOKIE['wpt_lang']) ) { $wpt_lang = $_COOKIE['wpt_lang']; } else { $wpt_lang = $GLOBALS['hdr_lang']; } // check if exist $_GET if ( count($_GET) > 0 ) { if ( !isset($_GET['lng']) ) { $cc1 = ''; $lc1 = ''; } else { $cc1 = ''; $lc1 = ''; } } else { $cc1 = ''; $lc1 = ''; } $lc2 = $cc2 = ""; switch($wpt_lang) { case "lat": $lc1 = ""; $lc2 = ""; break; default: $cc1 = ""; $cc2 = ""; } // Display GT link? $options = get_option("wptranslit"); if ( $options['gt_show'] ) { $gtlink = '
  • '.$options['gt_text'].'
  • '; } print << EOF; } // wpt_widget_list() function wpt_widget_drop() { if ( isset($_REQUEST['lng']) ) { $wpt_lang = $_REQUEST['lng']; } elseif ( isset( $_COOKIE['wpt_lang'] ) ) { $wpt_lang = $_COOKIE['wpt_lang']; } else { $wpt_lang = $GLOBALS['hdr_lang']; } $lc = $cc = false; switch($wpt_lang) { case "lat": $lc = 'selected="selected"'; break; default: $cc = 'selected="selected"'; } print <<
    EOF; } // wpt_widget_drop() function wpt_inline() { $current_uri = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; $this_page_url = "http://" . $current_uri; $cirt = "ћирилица"; $latt = "latinica"; $gtlink = ""; if ( isset($_REQUEST['lng']) ) { $wpt_lang = $_REQUEST['lng']; } elseif ( isset($_COOKIE['wpt_lang']) ) { $wpt_lang = $_COOKIE['wpt_lang']; } else { $wpt_lang = $GLOBALS['hdr_lang']; } // check if exist $_GET if ( count($_GET) > 0 ) { if ( !isset($_GET['lng']) ) { $cirl = "http://${current_uri}&lng=cir"; $latl = "http://${current_uri}&lng=lat"; } else { $cirl = "http://".str_replace( array("lng=lat", "lng=cir"), 'lng=cir', $current_uri); $latl = "http://".str_replace( array("lng=lat", "lng=cir"), 'lng=lat', $current_uri); } } else { $cirl = "?lng=cir"; $latl = "?lng=lat"; } $cir = ''.$cirt.''; $lat = ''.$latt.''; // Get inline options $options = get_option("wptranslit"); $iclass = strip_tags(stripslashes($options['inline_class'])); if ( $iclass ) { $iclass = 'class="'.$iclass.'"'; } // get delimiter $idelim = stripslashes($options['inline_delimiter']); // get prefix & suffix $iprefix = htmlspecialchars_decode(stripslashes($options['inline_prefix'])); $isuffix = htmlspecialchars_decode(stripslashes($options['inline_suffix'])); if ( $isuffix ) { $isuffix = $idelim.$isuffix; } // Display active script? switch($wpt_lang) { case "lat": if ( $options['inline_ashow'] ) { $lat = "$idelim$lat"; } else { $lat = ""; } break; case "cir": if ( $options['inline_ashow'] ) { $cir = "$cir$idelim"; } else { $cir = ""; } break; } // Display GT link? if ( $options['gt_show'] ) { $gtlink = $idelim.''.$options['gt_text'].''; } //
    ${iprefix}${cc1}ћирилица${cc2}${idelim}${lc1}latinica${lc2}${gtlink}${isuffix}
    print <<
    ${iprefix}${cir}${lat}${gtlink}${isuffix}
    EOF; } // Function to get language from Accept Language headers function hdr_lang() { // get language from HTTP headers and split it to array $languages = split(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]); $hdr_lang = ""; // check first defined Accept Language $hlang = $languages[0]; if ( ereg("^(sr|mk|bg|ru)", $hlang) ) // && $hbr == 0 ) { // for Serbian, Macedonian, Bulgarian and Russian set 'cir' $hdr_lang = "cir"; } else { // for all other set to 'lat' $hdr_lang = "lat"; } // set global variable $GLOBALS['hdr_lang'] = $hdr_lang; } // Function to set language from request headers to cookies function wpt_set_lang() { $lng = ""; $wpt_lang = ""; if ( isset($_REQUEST['lng']) ) { $wpt_lang = $_REQUEST['lng']; if ( $wpt_lang == "cir" || $wpt_lang == "lat" ) { setcookie("wpt_lang", $wpt_lang, strtotime("+3 months"), "/"); } } } /* WP Translit Master Kung-Fu */ class wp_translit { function wp_translit() { add_action('wp_head', array(&$this,'buffer_start')); add_action('wp_footer', array(&$this,'buffer_end')); // add transliteration to feed add_action('feed_head', array(&$this,'buffer_start'), 1); add_action('feed_footer', array(&$this,'buffer_end'), 1); add_action('rss_head', array(&$this,'buffer_start'), 1); add_action('rss_footer', array(&$this,'buffer_end'), 1); add_action('rss2_head', array(&$this,'buffer_start'), 1); add_action('rss2_footer', array(&$this,'buffer_end'), 1); } function buffer_start() { ob_start( array(&$this,"do_wptranslit") ); } function buffer_end() { ob_end_flush(); } // Function to do replace of text function do_wptranslit($text) { // set default script to 'cir' (put in widget setup?) $wpt_lang = "cir"; // get language from REQUEST (if 'lng' exists) if ( isset($_REQUEST['lng']) ) { $wpt_lang = $_REQUEST['lng']; } // if no language in REQUEST, get language from cookies (if cookie 'wpt_lang' exists) elseif ( isset($_COOKIE['wpt_lang']) ) { $wpt_lang = $_COOKIE['wpt_lang']; } // if no wpt_lang in cookies, get Accept Language from headers elseif ( $GLOBALS['hdr_lang'] ) { $wpt_lang = $GLOBALS['hdr_lang']; } // Do we even need to do transliteration (wpt_lang is 'lat')? if ( $wpt_lang == "lat" ) { $wpt_izlaz = ""; // set source script - Cyrillic $str_from = array ("Џа", "Џе", "Џи", "Џо", "Џу", "Ња", "Ње", "Њи", "Њо", "Њу", "Ља", "Ље", "Љи", "Љо", "Љу", "а","б","в","г","д","ђ","е","ж","з","и","ј","к","л","љ","м","н","њ","о","п","р","с","т","ћ","у","ф","х","ц","ч","џ","ш","А","Б","В","Г","Д","Ђ","Е","Ж","З","И","Ј","К","Л","Љ","М","Н","Њ","О","П","Р","С","Т","Ћ","У","Ф","Х","Ц","Ч","Џ","Ш","č","Č","ć","Ć","ž","Ž","đ","Đ","š","Š"); // set destination script to UTF-8 Serbian Latin $str_to = array ("Dža", "Dže", "Dži", "Džo", "Džu", "Nja", "Nje", "Nji", "Njo", "Nju", "Lja", "Lje", "Lji", "Ljo", "Lju", "a","b","v","g","d","đ","e","ž","z","i","j","k","l","lj","m","n","nj","o","p","r","s","t","ć","u","f","h","c","č","dž","š","A","B","V","G","D","Đ","E","Ž","Z","I","J","K","L","Lj","M","N","Nj","O","P","R","S","T","Ć","U","F","H","C","Č","Dž","Š","č","Č","ć","Ć","ž","Ž","đ","Đ","š","Š"); // do simple string replace return str_replace($str_from, $str_to, $text); } else { // if there no need for transliteration, print out unchanged text return $text; } // wpt_lang == lat } // function do_wptranslit() } // class wp_translit $_wp_wp_translit =& new wp_translit; ?>