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