0, 'mode'=>'maintenance', 'title'=>'', 'description'=>'', 'layout'=>'center', 'text_align'=>'theme', 'logo_align'=>'theme', 'motion'=>'subtle', 'font'=>'vazirmatn', 'logo'=>0, 'background'=>0, 'accent'=>'#2864dc', 'bg_color'=>'#f3f6fc', 'contact'=>'', 'instagram'=>'', 'telegram'=>'', 'linkedin'=>'', 'youtube'=>'', 'countdown'=>0, 'end'=>'', 'exclude'=>array(), 'delete_data'=>0, 'footer_enabled'=>0, 'footer_text'=>'', 'seo_title'=>'', 'seo_description'=>'', 'seo_robots'=>'noindex', 'seo_canonical'=>'', 'wc_exempt'=>array() ); } function negahnama_options() { $value = get_option( 'negahnama_settings', array() ); return wp_parse_args( is_array( $value ) ? $value : array(), negahnama_defaults() ); } function negahnama_layouts() { return array( 'center'=>__( 'Centered', 'negahnama' ), 'split'=>__( 'Split', 'negahnama' ), 'card'=>__( 'Card', 'negahnama' ), 'studio'=>__( 'Studio', 'negahnama' ), 'horizon'=>__( 'Horizon', 'negahnama' ), 'minimal'=>__( 'Minimal', 'negahnama' ), 'orbit'=>__( 'Orbit', 'negahnama' ), 'editorial'=>__( 'Editorial', 'negahnama' ), 'duotone'=>__( 'Duotone', 'negahnama' ), 'aurora'=>__( 'Aurora', 'negahnama' ), 'frame'=>__( 'Frame', 'negahnama' ), 'spotlight'=>__( 'Spotlight', 'negahnama' ), 'wave'=>__( 'Wave', 'negahnama' ), 'glass'=>__( 'Glass', 'negahnama' ), 'ribbon'=>__( 'Ribbon', 'negahnama' ) ); } function negahnama_wc_exempt( $settings ) { if ( ! class_exists( 'WooCommerce' ) || empty( $settings['wc_exempt'] ) || ! is_array( $settings['wc_exempt'] ) ) { return false; } $selected = $settings['wc_exempt']; if ( in_array( 'shop', $selected, true ) && function_exists( 'is_shop' ) && is_shop() ) { return true; } if ( in_array( 'product', $selected, true ) && is_singular( 'product' ) && 'publish' === get_post_status( get_queried_object_id() ) ) { return true; } if ( ! is_page() || 'publish' !== get_post_status( get_queried_object_id() ) ) { return false; } foreach ( array( 'cart'=>'is_cart', 'checkout'=>'is_checkout', 'account'=>'is_account_page' ) as $key=>$condition ) { if ( in_array( $key, $selected, true ) && function_exists( $condition ) && $condition() ) { return true; } } return false; } function negahnama_contact_value( $key, $value ) { if ( ! is_string( $value ) ) { return null; } $value = trim( $value ); if ( '' === $value ) { return ''; } if ( 'contact' === $key ) { $value = strtr( $value, array_combine( preg_split( '//u', '۰۱۲۳۴۵۶۷۸۹٠١٢٣٤٥٦٧٨٩', -1, PREG_SPLIT_NO_EMPTY ), str_split( '01234567890123456789' ) ) ); $value = preg_replace( '/[\s()\-.]/u', '', $value ); return preg_match( '/^\+?[0-9]{3,20}$/D', $value ) ? $value : null; } $value = ltrim( $value, '@' ); $patterns = array( 'instagram'=>'/^[A-Za-z0-9._]{1,30}$/D', 'telegram'=>'/^[A-Za-z0-9_]{1,32}$/D', 'linkedin'=>'/^[\p{L}\p{N}_-]{1,100}$/uD', 'youtube'=>'/^[\p{L}\p{N}_.-]{1,100}$/uD' ); return isset( $patterns[$key] ) && preg_match( $patterns[$key], $value ) ? $value : null; } function negahnama_contact_url( $key, $value ) { if ( ! is_string( $value ) || '' === $value ) { return ''; } if ( preg_match( '~^(https?://|mailto:|tel:)~i', $value ) ) { return esc_url_raw( $value, array( 'http', 'https', 'mailto', 'tel' ) ); } $value = negahnama_contact_value( $key, $value ); if ( ! $value ) { return ''; } $prefixes = array( 'contact'=>'tel:', 'instagram'=>'https://www.instagram.com/', 'telegram'=>'https://t.me/', 'linkedin'=>'https://www.linkedin.com/in/', 'youtube'=>'https://www.youtube.com/@' ); return isset( $prefixes[$key] ) ? $prefixes[$key] . ( 'contact' === $key ? $value : rawurlencode( $value ) ) : ''; } function negahnama_admin_bar( $bar ) { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = negahnama_options(); $label = $settings['enabled'] ? __( 'Negahnama: Active', 'negahnama' ) : __( 'Negahnama: Inactive', 'negahnama' ); $color = $settings['enabled'] ? '#f0b849' : '#a7b4c4'; $bar->add_node( array( 'id'=>'negahnama-status', 'title'=>'● ' . esc_html( $label ), 'href'=>admin_url( 'options-general.php?page=negahnama' ) ) ); } add_action( 'admin_bar_menu', 'negahnama_admin_bar', 90 ); function negahnama_admin_bar_font() { if ( ! is_admin_bar_showing() || ! current_user_can( 'manage_options' ) ) { return; } wp_enqueue_style( 'negahnama-font', NEGAHNAMA_URL . 'assets/font.css', array(), '1.0.1' ); wp_add_inline_style( 'negahnama-font', '#wpadminbar #wp-admin-bar-negahnama-status > .ab-item{font-family:NegahnamaVazirmatn,system-ui,sans-serif}@media screen and (max-width:782px){#wpadminbar #wp-admin-bar-negahnama-status{display:block}#wpadminbar #wp-admin-bar-negahnama-status>.ab-item{font-size:12px;padding:0 6px}}' ); } add_action( 'admin_enqueue_scripts', 'negahnama_admin_bar_font' ); add_action( 'wp_enqueue_scripts', 'negahnama_admin_bar_font' ); function negahnama_timestamp( $value ) { if ( ! is_string( $value ) || ! preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/', $value ) ) { return 0; } $date = DateTimeImmutable::createFromFormat( '!Y-m-d\TH:i', $value, wp_timezone() ); return $date && $date->format( 'Y-m-d\TH:i' ) === $value ? $date->getTimestamp() : 0; } function negahnama_intercept() { $settings = negahnama_options(); $preview = isset( $_GET['negahnama_preview'] ) && current_user_can( 'manage_options' ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'negahnama_preview' ); if ( ! $preview ) { if ( empty( $settings['enabled'] ) || current_user_can( 'manage_options' ) || is_admin() || ( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() ) || ( function_exists( 'wp_doing_cron' ) && wp_doing_cron() ) || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) { return; } if ( is_page() && is_array( $settings['exclude'] ) && in_array( get_queried_object_id(), array_map( 'intval', $settings['exclude'] ), true ) && get_post_status( get_queried_object_id() ) === 'publish' ) { return; } if ( negahnama_wc_exempt( $settings ) ) { return; } } if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( 'DONOTCACHEPAGE', true ); } nocache_headers(); $end = negahnama_timestamp( $settings['end'] ); if ( ! $preview && 'maintenance' === $settings['mode'] ) { status_header( 503 ); if ( $end > time() ) { header( 'Retry-After: ' . gmdate( 'D, d M Y H:i:s', $end ) . ' GMT' ); } } else { status_header( 200 ); } $robots = ! $preview && 'index' === $settings['seo_robots'] ? 'index, follow' : 'noindex, nofollow'; header( 'X-Robots-Tag: ' . $robots, true ); wp_enqueue_style( 'negahnama-font', NEGAHNAMA_URL . 'assets/font.css', array(), '1.0.1' ); wp_enqueue_style( 'negahnama-public', NEGAHNAMA_URL . 'assets/public.css', array(), '1.5.0' ); wp_enqueue_style( 'negahnama-designs', NEGAHNAMA_URL . 'assets/designs.css', array( 'negahnama-public' ), '1.5.0' ); wp_enqueue_style( 'negahnama-effects', NEGAHNAMA_URL . 'assets/effects.css', array( 'negahnama-designs' ), '1.5.0' ); if ( ! empty( $settings['countdown'] ) && $end > time() ) { wp_enqueue_script( 'negahnama-countdown', NEGAHNAMA_URL . 'assets/countdown.js', array(), '1.1.0', true ); } if ( in_array( $settings['motion'], array( 'float', 'drift' ), true ) ) { wp_enqueue_script( 'negahnama-motion', NEGAHNAMA_URL . 'assets/motion.js', array(), '1.5.0', true ); } require NEGAHNAMA_DIR . 'public.php'; negahnama_render_public( $settings, $end, $robots ); exit; }