array( Arabic name, country ). * * @return array */ public static function cities() { static $cities = null; if ( null === $cities ) { $cities = include ADAWAT_TOOLS_DIR . 'includes/cities-data.php'; } return $cities; } /** * Effective theme: shortcode attribute wins over the saved setting. * * @param string $att Theme attribute value. * @return string 'light', 'dark' or '' (follow the visitor's system). */ private static function theme( $att ) { $opt = adawat_tools_get_settings(); $theme = '' !== $att ? $att : $opt['theme']; return in_array( $theme, array( 'light', 'dark' ), true ) ? $theme : ''; } /** * Visible credit line "مدعوم من أدوات" linking to the matching tool page. * * Site owners can switch it off from الإعدادات ← أدوات, or via the * `adawat_tools_show_credit` filter. * * @param string $path Path on adawat.org, e.g. '/zakat-calculator.html'. * @param string $anchor Keyword anchor text. * @return string HTML. */ private static function credit( $path, $anchor ) { $opt = adawat_tools_get_settings(); $show = apply_filters( 'adawat_tools_show_credit', ! empty( $opt['credit'] ) ); if ( ! $show ) { return ''; } return '
' . esc_html__( 'مدعوم من', 'adawat-tools' ) . ' ' . esc_html__( 'أدوات', 'adawat-tools' ) . ' — ' . esc_html( $anchor ) . '
'; } /** * Sandboxed, lazy, auto-sizing iframe for an adawat.org widget. * * @param string $widget Widget file name without extension (prayer, hijri, ramadan, zakat). * @param array $args Query args (empty values are dropped). * @param string $title Accessible iframe title. * @param int $height Initial height in px (replaced once the widget reports its real height). * @return string HTML. */ private static function iframe( $widget, $args, $title, $height ) { wp_enqueue_style( 'adawat-tools' ); wp_enqueue_script( 'adawat-tools-embed' ); $src = ADAWAT_TOOLS_SITE . '/widgets/' . $widget . '.html'; $src = add_query_arg( array_filter( $args, 'strlen' ), $src ); return ''; } /** * [adawat_hijri_date gregorian="no"] — today's Hijri date (Umm al-Qura), * computed in PHP in the site's own timezone. gregorian="yes" appends the * Gregorian date. * * @param array $atts Shortcode attributes. * @return string HTML. */ public static function hijri_date( $atts ) { $atts = shortcode_atts( array( 'gregorian' => 'no', ), $atts, 'adawat_hijri_date' ); $h = Adawat_Tools_Hijri::today( wp_timezone() ); if ( false === $h ) { return ''; } wp_enqueue_style( 'adawat-tools' ); $text = Adawat_Tools_Hijri::$days[ $h['wd'] ] . ' ' . Adawat_Tools_Hijri::format_hijri( $h ); $out = '' . esc_html( $text ) . ''; if ( 'yes' === strtolower( $atts['gregorian'] ) ) { $g_months = array( 'يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو', 'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر' ); $now = new DateTime( 'now', wp_timezone() ); $greg = $now->format( 'j' ) . ' ' . $g_months[ (int) $now->format( 'n' ) - 1 ] . ' ' . $now->format( 'Y' ) . ' م'; $out .= ' ' . esc_html( 'الموافق ' . $greg ) . ''; } $out .= ''; return $out . self::credit( '/hijri-converter.html', __( 'التاريخ الهجري اليوم ومحوّل التاريخ', 'adawat-tools' ) ); } /** * [adawat_prayer_times city="riyadh" method="" asr="" theme="" height="300"] * — live prayer times widget for one of 188 cities, computed in the * visitor's browser by adawat.org (no API keys, no accounts). * * @param array $atts Shortcode attributes. * @return string HTML. */ public static function prayer_times( $atts ) { $opt = adawat_tools_get_settings(); $atts = shortcode_atts( array( 'city' => $opt['city'], 'method' => '', 'asr' => '', 'theme' => '', 'height' => 300, ), $atts, 'adawat_prayer_times' ); $city = strtolower( preg_replace( '/[^a-zA-Z0-9\-]/', '', $atts['city'] ) ); $cities = self::cities(); $known = isset( $cities[ $city ] ); $name = $known ? $cities[ $city ][0] : $city; /* translators: %s: city name. */ $title = $known ? sprintf( __( 'مواقيت الصلاة في %s', 'adawat-tools' ), $name ) : __( 'مواقيت الصلاة اليوم', 'adawat-tools' ); $html = self::iframe( 'prayer', array( 'city' => $city, 'method' => preg_replace( '/[^a-z]/', '', strtolower( $atts['method'] ) ), 'asr' => in_array( $atts['asr'], array( '1', '2' ), true ) ? $atts['asr'] : '', 'theme' => self::theme( $atts['theme'] ), ), $title . ' — أدوات', (int) $atts['height'] ); $path = $known ? '/prayer-times-' . $city . '.html' : '/prayer-times.html'; return $html . self::credit( $path, $title ); } /** * [adawat_ramadan_countdown event="ramadan" theme="" height="200"] — * countdown to Ramadan (or fitr/adha/arafah/hijri new year). * * @param array $atts Shortcode attributes. * @return string HTML. */ public static function ramadan_countdown( $atts ) { $atts = shortcode_atts( array( 'event' => 'ramadan', 'theme' => '', 'height' => 200, ), $atts, 'adawat_ramadan_countdown' ); $event = strtolower( $atts['event'] ); if ( ! in_array( $event, array( 'ramadan', 'fitr', 'adha', 'arafah', 'hijri' ), true ) ) { $event = 'ramadan'; } $html = self::iframe( 'ramadan', array( 'event' => 'ramadan' === $event ? '' : $event, 'theme' => self::theme( $atts['theme'] ), ), __( 'كم باقي على رمضان', 'adawat-tools' ) . ' — أدوات', (int) $atts['height'] ); return $html . self::credit( '/ramadan-countdown.html', __( 'كم باقي على رمضان', 'adawat-tools' ) ); } /** * [adawat_zakat gold="" cur="" theme="" height="290"] — mini zakat * calculator. gold = today's price of one gram of 24k gold to prefill, * cur = currency label (e.g. "ر.س"). * * @param array $atts Shortcode attributes. * @return string HTML. */ public static function zakat( $atts ) { $atts = shortcode_atts( array( 'gold' => '', 'cur' => '', 'theme' => '', 'height' => 290, ), $atts, 'adawat_zakat' ); $gold = '' !== $atts['gold'] && is_numeric( $atts['gold'] ) ? (string) (float) $atts['gold'] : ''; $html = self::iframe( 'zakat', array( 'gold' => $gold, 'cur' => sanitize_text_field( substr( $atts['cur'], 0, 12 ) ), 'theme' => self::theme( $atts['theme'] ), ), __( 'حاسبة الزكاة', 'adawat-tools' ) . ' — أدوات', (int) $atts['height'] ); return $html . self::credit( '/zakat-calculator.html', __( 'حاسبة الزكاة', 'adawat-tools' ) ); } }