admin
11 years ago
plugins
11 years ago
widget
11 years ago
fixes-archive.php
11 years ago
fixes-dates.php
11 years ago
fixes-get_archives.php
11 years ago
fixes-get_calendar.php
11 years ago
fixes-misc.php
11 years ago
fixes-permalinks.php
11 years ago
general.php
11 years ago
install.php
11 years ago
parsidate.php
11 years ago
settings.php
11 years ago
general.php
121 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WP-Parsidate general functions |
| 4 | * |
| 5 | * @author Mobin Ghasempoor |
| 6 | * @author Ehsaan |
| 7 | * @package WP-Parsidate |
| 8 | * @subpackage Core/General |
| 9 | */ |
| 10 | global $wpp_settings; |
| 11 | |
| 12 | add_filter( 'login_headerurl', 'wpp_login_headerurl', 10, 2 ); |
| 13 | add_filter( 'locale', 'wp_parsi_set_locale' ); |
| 14 | |
| 15 | /** |
| 16 | * Change Locale WordPress Admin and Front-end user |
| 17 | * @author |
| 18 | * @param String $locale |
| 19 | * @return String |
| 20 | */ |
| 21 | function wp_parsi_set_locale($locale) { |
| 22 | $settings = get_option( 'wpp_settings' ); |
| 23 | if ( $settings['admin_lang'] == 'enable' ) { $admin_locale = "fa_IR"; }elseif($settings['admin_lang'] == 'disable'){ $admin_locale = "en_US"; } |
| 24 | if ( $settings['user_lang'] == 'enable' ) { $user_locale = "fa_IR"; }elseif($settings['user_lang'] == 'disable'){ $user_locale = "en_US"; } |
| 25 | |
| 26 | $locale_s = ( is_admin() ) ? $admin_locale : $user_locale; |
| 27 | |
| 28 | if(! empty($locale_s)) |
| 29 | $locale = $locale_s; |
| 30 | |
| 31 | //setlocale(LC_ALL, $locale ); |
| 32 | return $locale; |
| 33 | } |
| 34 | |
| 35 | |
| 36 | /** |
| 37 | * Detects current page is feed or not |
| 38 | * |
| 39 | * @since 1.0 |
| 40 | * @return bool True when page is feed, false when page isn't feed |
| 41 | */ |
| 42 | function wpp_is_feed() { |
| 43 | if ( is_feed() ) |
| 44 | return true; |
| 45 | |
| 46 | $path = $_SERVER['REQUEST_URI']; |
| 47 | $exts = array( 'xml', 'gz', 'xsl' ); |
| 48 | $ext = pathinfo( $path, PATHINFO_EXTENSION ); |
| 49 | |
| 50 | return in_array( $ext, $exts ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Converts English digits to Persian digits |
| 55 | * |
| 56 | * @param string $number Numbers |
| 57 | * @return string Formatted numbers |
| 58 | */ |
| 59 | function per_number( $number ) { |
| 60 | return str_replace( |
| 61 | range( 0, 9 ), |
| 62 | array( '۰','۱','۲','۳','۴','۵','۶','۷','۸','۹' ), |
| 63 | $number |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Converts Persian digits to English digits |
| 69 | * |
| 70 | * @param string $number Numbers |
| 71 | * @return string Formatted numbers |
| 72 | */ |
| 73 | function eng_number( $number ) { |
| 74 | return str_replace( |
| 75 | array( '۰','۱','۲','۳','۴','۵','۶','۷','۸','۹' ), |
| 76 | range( 0, 9 ), |
| 77 | $number |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Converts English numbers to Persian numbers in post contents |
| 83 | * |
| 84 | * @param string $content Post content |
| 85 | * @return string Formatted content |
| 86 | */ |
| 87 | function persian_number( $content ) { |
| 88 | return( |
| 89 | isset($content[1]) ? per_number( $content[1] ) : $content[0] |
| 90 | ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Fix numbers and convert them to Persian digits style |
| 95 | * |
| 96 | * @param string $content |
| 97 | * @return mixed |
| 98 | */ |
| 99 | function fixnumber( $content ) { |
| 100 | return preg_replace_callback( '/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+[\.\d]*)|<\s*[^>]+>/i','persian_number',$content); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Fix arabic foreign characters |
| 105 | * |
| 106 | * @param string $content |
| 107 | * @return mixed |
| 108 | */ |
| 109 | function fixarabic( $content ) { |
| 110 | return str_replace( array( 'ي','ك','٤','٥','٦','ة' ), array( 'ی','ک','۴','۵','۶','ه' ), $content ); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Change login header url in wp-login.php |
| 115 | * |
| 116 | * @return string |
| 117 | */ |
| 118 | function wpp_login_headerurl() |
| 119 | { |
| 120 | return 'http://wp-parsi.com'; |
| 121 | } |