admin
9 years ago
plugins
9 years ago
widget
9 years ago
fixes-archive.php
9 years ago
fixes-archives.php
9 years ago
fixes-calendar.php
9 years ago
fixes-dates.php
9 years ago
fixes-misc.php
9 years ago
fixes-permalinks.php
9 years ago
general.php
9 years ago
install.php
9 years ago
parsidate.php
9 years ago
settings.php
9 years ago
general.php
172 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 | add_action( 'admin_notices', 'wpp_activation_notice' ); |
| 15 | add_action( 'admin_init', 'wpp_dismiss_notice_action' ); |
| 16 | |
| 17 | /** |
| 18 | * Change Locale WordPress Admin and Front-end user |
| 19 | * @author |
| 20 | * |
| 21 | * @param String $locale |
| 22 | * |
| 23 | * @return String |
| 24 | */ |
| 25 | function wp_parsi_set_locale( $locale ) { |
| 26 | $settings = get_option( 'wpp_settings' ); |
| 27 | if ( $settings['admin_lang'] == 'enable' ) { |
| 28 | $admin_locale = "fa_IR"; |
| 29 | } elseif ( $settings['admin_lang'] == 'disable' ) { |
| 30 | $admin_locale = "en_US"; |
| 31 | } |
| 32 | if ( $settings['user_lang'] == 'enable' ) { |
| 33 | $user_locale = "fa_IR"; |
| 34 | } elseif ( $settings['user_lang'] == 'disable' ) { |
| 35 | $user_locale = "en_US"; |
| 36 | } |
| 37 | |
| 38 | $locale_s = ( is_admin() ) ? $admin_locale : $user_locale; |
| 39 | |
| 40 | if ( ! empty( $locale_s ) ) { |
| 41 | $locale = $locale_s; |
| 42 | } |
| 43 | |
| 44 | setlocale( LC_ALL, $locale ); |
| 45 | |
| 46 | return $locale; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * Detects current page is feed or not |
| 52 | * |
| 53 | * @since 1.0 |
| 54 | * @return bool True when page is feed, false when page isn't feed |
| 55 | */ |
| 56 | function wpp_is_feed() { |
| 57 | if ( is_feed() ) { |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | $path = $_SERVER['REQUEST_URI']; |
| 62 | $exts = array( 'xml', 'gz', 'xsl' ); |
| 63 | $ext = pathinfo( $path, PATHINFO_EXTENSION ); |
| 64 | |
| 65 | return in_array( $ext, $exts ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Converts English digits to Persian digits |
| 70 | * |
| 71 | * @param string $number Numbers |
| 72 | * |
| 73 | * @return string Formatted numbers |
| 74 | */ |
| 75 | function per_number( $number ) { |
| 76 | return str_replace( |
| 77 | range( 0, 9 ), |
| 78 | array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ), |
| 79 | $number |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Converts Persian digits to English digits |
| 85 | * |
| 86 | * @param string $number Numbers |
| 87 | * |
| 88 | * @return string Formatted numbers |
| 89 | */ |
| 90 | function eng_number( $number ) { |
| 91 | return str_replace( |
| 92 | array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ), |
| 93 | range( 0, 9 ), |
| 94 | $number |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Converts English numbers to Persian numbers in post contents |
| 100 | * |
| 101 | * @param string $content Post content |
| 102 | * |
| 103 | * @return string Formatted content |
| 104 | */ |
| 105 | function persian_number( $content ) { |
| 106 | return ( |
| 107 | isset( $content[1] ) ? per_number( $content[1] ) : $content[0] |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Fix numbers and convert them to Persian digits style |
| 113 | * |
| 114 | * @param string $content |
| 115 | * |
| 116 | * @return mixed |
| 117 | */ |
| 118 | function fixnumber( $content ) { |
| 119 | return preg_replace_callback( '/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+[\.\d]*)|<\s*[^>]+>/i', 'persian_number', $content ); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Fix arabic foreign characters |
| 124 | * |
| 125 | * @param string $content |
| 126 | * |
| 127 | * @return mixed |
| 128 | */ |
| 129 | function fixarabic( $content ) { |
| 130 | return str_replace( array( 'ي', 'ك', '٤', '٥', '٦', 'ة' ), array( 'ی', 'ک', '۴', '۵', '۶', 'ه' ), $content ); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Change login header url in wp-login.php |
| 135 | * |
| 136 | * @return string |
| 137 | */ |
| 138 | function wpp_login_headerurl() { |
| 139 | return 'http://wp-parsi.com'; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Notice for the activation. |
| 144 | * Added dismiss feature. |
| 145 | * |
| 146 | * @author Ehsaan |
| 147 | * @return void |
| 148 | */ |
| 149 | function wpp_activation_notice() { |
| 150 | $dismissed = get_option( 'wpp_dismissed', false ); |
| 151 | |
| 152 | if ( ! $dismissed ) { |
| 153 | global $wpp_settings; |
| 154 | |
| 155 | if ( $wpp_settings['persian_date'] != 'enable' ) { |
| 156 | $output = sprintf( __( '<div class="updated wpp-message"><p>ParsiDate activated, you may need to configure it to work properly. <a href="%s">Go to configuartion page</a> – <a href="%s">Dismiss</a></p></div>', 'wp-parsidate' ), admin_url( 'admin.php?page=wp-parsi-settings' ), add_query_arg( 'wpp-action', 'dismiss-notice' ) ); |
| 157 | echo $output; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Dismiss the notice action |
| 164 | * |
| 165 | * @author Ehsaan |
| 166 | * @return void |
| 167 | */ |
| 168 | function wpp_dismiss_notice_action() { |
| 169 | if ( isset( $_GET['wpp-action'] ) && $_GET['wpp-action'] == 'dismiss-notice' ) { |
| 170 | update_option( 'wpp_dismissed', true ); |
| 171 | } |
| 172 | } |