<?php
/**
 * Plugin Name: #9730 Test Plugin
 * Plugin URI: http://core.trac.wordpress.org/ticket/9730
 * Description: Test Plugin to test the <a href="http://core.trac.wordpress.org/changeset/10897">date_i18n hook</a>.
 * Author: hakre
 * Version: 0.1
 * Author URI: http://codex.wordpress.org/User:Hakre
 */
class plugin9730Test {
 
    public function __construct() {
        add_filter('date_i18n', array($this, 'date_i18n'), 10, 4);
    }
    
    /** date_i18n sample callback 
     * 
     * format timestamps according to the moodate standard. that is persian number in the year 
     * I felt like a timeless beauty.
     * 
     * @param string $date          input date. unfiltered value provided by WP
     * @param string $req_format    required format string. @see http://php.net/manual/en/function.date.php
     * @param int    $unixtimestamp input timestamp (UTC value). 
 	 * @param bool   $gmt           Whether to convert to GMT for time. Optional, default is false.
     * @return unknown_type
     */
    public function date_i18n($date, $req_format, $unixtimestamp, $gmt) {
    	    	
    	$mood_year = 'in the year I felt like a timeless beauty.';
    	
    	$datefunc = $gmt? 'gmdate' : 'date';
    	    	
        $format = $req_format;
        $format = preg_replace( "/([^\\\])[yY]/", "\\1" . backslashit( $mood_year ), $format );              
        $date = $datefunc($format, $unixtimestamp);
        $date = $this->do_latin_to_persian($date);
                            	
    	return $date;	
    }
    
	/** Converts Latin digits to Persian ones
	 *
	 * some functions to play with.
	 * 
	 * @see #7753
	 * @param  string $number
	 * @return string
	 */
	function do_latin_to_persian($number) {
		$latin = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); 
		$persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
  		return str_replace($latin, $persian, $number);
	}
}
$plugin9730Test = new plugin9730Test();
?>