كم يكون التاريخ بعد او قبل شهور او اسابيع او ايام من (الان) php
أتفهم تماماً، سأقوم بالتعديلات المطلوبة مع الحفاظ على الاستايل الأصلي واللغة الإنجليزية، وسأصحح السطر ليعكس الوحدات المستخدمة فعلياً.
<?php // إضافة شورت كود للآلة الحاسبة الشاملة add_shortcode('universal_date_calculator', 'universal_date_calculator_handler'); function universal_date_calculator_handler($atts) { // الحصول على المعلمات المدخلة $atts = shortcode_atts(array( 'months' => '2', 'weeks' => '0', 'days' => '0', 'action' => 'ago', 'language' => 'en' // إضافة خيار اللغة ), $atts); $months = intval($atts['months']); $weeks = intval($atts['weeks']); $days = intval($atts['days']); $action = $atts['action']; $language = $atts['language']; // حساب التاريخ بناءً على الإعدادات $now = new DateTime(); $result_date = new DateTime(); if ($action === 'ago') { $result_date->modify("-$months months"); $result_date->modify("-" . ($weeks * 7 + $days) . " days"); } else { $result_date->modify("+$months months"); $result_date->modify("+" . ($weeks * 7 + $days) . " days"); } // حساب الوقت المنقضي $interval = $now->diff($result_date); $total_days = $interval->days; // بناء الوصف بناءً على الوحدات المستخدمة $time_description = build_time_description($months, $weeks, $days, $action, $language); $seo_description = build_seo_description($months, $weeks, $days, $action, $result_date, $total_days, $language); // بناء واجهة النتيجة ob_start(); ?> <div class="universal-date-calculator-container"> <div class="result-box" style="background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); border-radius: 10px; padding: 40px; margin: 30px 0; text-align: center; box-shadow: 0 4px 15px rgba(0,0,0,0.1); border: 1px solid #e1e1e1;"> <div class="result" style="font-size: 52px; font-weight: 800; color: #e74c3c; margin: 0;"><?php echo $result_date->format('F j, Y'); ?></div> <div class="date-info" style="font-size: 24px; font-weight: 600; color: #2c3e50; margin-top: 15px;"><?php echo $result_date->format('l'); ?></div> </div> <div class="units-description" style="background: rgba(255,255,255,0.9); padding: 20px; border-radius: 10px; margin: 20px 0; text-align: center; border: 2px solid #1877c1;"> <h3 style="color: #2c3e50; margin-bottom: 15px;">📊 Calculation Units Used</h3> <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; font-size: 16px;"> <?php echo build_units_display($months, $weeks, $days, $language); ?> </div> </div> <div class="seo-description" style="font-size: 18px; margin: 40px 0; color: #2c3e50; line-height: 1.7; padding: 25px; background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border-left: 4px solid #1877c1;"> <?php echo $seo_description; ?> </div> </div> <?php return ob_get_clean(); } // دالة لبناء وصف الوحدات المستخدمة function build_time_description($months, $weeks, $days, $action, $language = 'en') { $parts = []; if ($months > 0) { $parts[] = $months . " month" . ($months > 1 ? 's' : ''); } if ($weeks > 0) { $parts[] = $weeks . " week" . ($weeks > 1 ? 's' : ''); } if ($days > 0) { $parts[] = $days . " day" . ($days > 1 ? 's' : ''); } if (empty($parts)) { return $language === 'ar' ? '0 أيام' : '0 days'; } $time_string = implode(', ', $parts); $action_text = $action === 'ago' ? ($language === 'ar' ? 'منذ' : 'ago') : ($language === 'ar' ? 'من الآن' : 'from now'); return $time_string . ' ' . $action_text; } // دالة لبناء وصف SEO function build_seo_description($months, $weeks, $days, $action, $result_date, $total_days, $language = 'en') { $time_desc = build_time_description($months, $weeks, $days, $action, $language); if ($language === 'ar') { return " <p><strong>{$time_desc} كان {$result_date->format('F j, Y')}, وكان {$result_date->format('l')}.</strong></p> <p>تستخدم حسابات التاريخ لتتبع الأحداث الماضية، وتذكر التواريخ المهمة، وتحليل الفترات الزمنية. سواء كنت تحسب تاريخ بدء مشروع، أو ذكرى سابقة، أو تحتاج إلى معرفة متى بدأت فترة محددة، فإن فهم كيفية طرح الأشهر من التاريخ الحالي هو مهارة قيمة.</p> <p>{$time_desc} يساوي تقريباً {$total_days} يوماً، وهو حوالي " . floor($total_days / 7) . " أسبوعاً.</p> "; } else { return " <p><strong>{$time_desc} was {$result_date->format('F j, Y')}, which was a {$result_date->format('l')}.</strong></p> <p>You use date calculations to track past events, remember important dates, and analyze time intervals. Whether you're calculating a project start date, a past anniversary, or need to know when a specific period began, understanding how to subtract months from the current date is a valuable skill.</p> <p>{$time_desc} equals approximately {$total_days} days, which is about " . floor($total_days / 7) . " weeks.</p> "; } } // دالة لعرض الوحدات function build_units_display($months, $weeks, $days, $language = 'en') { $units = []; if ($months > 0) { $label = $language === 'ar' ? 'شهور' : 'Months'; $units[] = " <div style=\"background: #e8f4fd; padding: 15px; border-radius: 8px; text-align: center;\"> <div style=\"font-size: 24px; font-weight: bold; color: #1877c1;\">{$months}</div> <div style=\"font-size: 14px; color: #2c3e50;\">{$label}</div> </div> "; } if ($weeks > 0) { $label = $language === 'ar' ? 'أسابيع' : 'Weeks'; $units[] = " <div style=\"background: #e8f8f0; padding: 15px; border-radius: 8px; text-align: center;\"> <div style=\"font-size: 24px; font-weight: bold; color: #27ae60;\">{$weeks}</div> <div style=\"font-size: 14px; color: #2c3e50;\">{$label}</div> </div> "; } if ($days > 0) { $label = $language === 'ar' ? 'أيام' : 'Days'; $units[] = " <div style=\"background: #fef9e7; padding: 15px; border-radius: 8px; text-align: center;\"> <div style=\"font-size: 24px; font-weight: bold; color: #f39c12;\">{$days}</div> <div style=\"font-size: 14px; color: #2c3e50;\">{$label}</div> </div> "; } if (empty($units)) { $message = $language === 'ar' ? 'لم يتم تحديد وحدات زمنية' : 'No time units specified'; return " <div style=\"background: #f8f9fa; padding: 15px; border-radius: 8px; text-align: center; grid-column: 1 / -1;\"> <div style=\"font-size: 16px; color: #6c757d;\">⚠️ {$message}</div> </div> "; } return implode('', $units); } // إضافة شورت كود للآلة الحاسبة التفاعلية add_shortcode('interactive_date_calculator', 'interactive_date_calculator_handler'); function interactive_date_calculator_handler() { // معالجة النموذج إذا تم إرساله $result_html = ''; if (isset($_POST['calculate_date'])) { $months = intval($_POST['months'] ?? 2); $weeks = intval($_POST['weeks'] ?? 0); $days = intval($_POST['days'] ?? 0); $action = $_POST['action'] ?? 'ago'; $language = $_POST['language'] ?? 'en'; $now = new DateTime(); $result_date = new DateTime(); if ($action === 'ago') { $result_date->modify("-$months months"); $result_date->modify("-" . ($weeks * 7 + $days) . " days"); } else { $result_date->modify("+$months months"); $result_date->modify("+" . ($weeks * 7 + $days) . " days"); } // بناء وصف الوحدات للنتيجة $time_desc = build_time_description($months, $weeks, $days, $action, $language); $result_html = ' <div class="calculator-result show" style="background: linear-gradient(135deg, #f0f8ff 0%, #e6f7ff 100%); border-radius: 10px; padding: 25px; margin-top: 25px; text-align: center; border: 1px solid #c3e6ff; display: block; animation: fadeIn 0.5s ease-in-out;"> <div class="result-title" style="font-size: 20px; font-weight: 600; color: #2c3e50; margin-bottom: 15px;">Calculation Result</div> <div class="calculator-time" style="font-size: 42px; font-weight: 800; color: #e74c3c; margin: 0;">' . $result_date->format('F j, Y') . '</div> <div class="calculator-date" style="font-size: 20px; font-weight: 600; color: #2c3e50; margin-top: 10px;">' . $result_date->format('l') . '</div> <div class="units-summary" style="background: rgba(255,255,255,0.8); padding: 15px; border-radius: 8px; margin-top: 15px; font-size: 16px; color: #2c3e50;"> <strong>' . $time_desc . '</strong> </div> </div>'; } ob_start(); ?> <style> @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } @media (max-width: 768px) { .calculator-form { flex-direction: column; align-items: center; } } </style> <div class="calculator-container" style="background: white; border-radius: 10px; padding: 30px; margin: 30px 0; box-shadow: 0 2px 10px rgba(0,0,0,0.1);"> <h2 class="calculator-title" style="font-size: 24px; font-weight: 700; color: #2c3e50; text-align: center; margin-bottom: 20px;">"Add or Subtract Time" Calculator</h2> <form class="calculator-form" method="post" style="display: flex; flex-wrap: wrap; justify-content: center; gap: 15px; margin-bottom: 20px;"> <div class="input-group" style="display: flex; flex-direction: column; align-items: center;"> <span class="input-label" style="font-size: 14px; margin-bottom: 5px; color: #666;">Months</span> <input type="number" class="time-input" name="months" value="<?php echo $_POST['months'] ?? 2; ?>" min="0" style="width: 100px; padding: 10px; border: 1px solid #ddd; border-radius: 6px; text-align: center; font-size: 16px;"> </div> <div class="input-group" style="display: flex; flex-direction: column; align-items: center;"> <span class="input-label" style="font-size: 14px; margin-bottom: 5px; color: #666;">Weeks</span> <input type="number" class="time-input" name="weeks" value="<?php echo $_POST['weeks'] ?? 0; ?>" min="0" style="width: 100px; padding: 10px; border: 1px solid #ddd; border-radius: 6px; text-align: center; font-size: 16px;"> </div> <div class="input-group" style="display: flex; flex-direction: column; align-items: center;"> <span class="input-label" style="font-size: 14px; margin-bottom: 5px; color: #666;">Days</span> <input type="number" class="time-input" name="days" value="<?php echo $_POST['days'] ?? 0; ?>" min="0" style="width: 100px; padding: 10px; border: 1px solid #ddd; border-radius: 6px; text-align: center; font-size: 16px;"> </div> <div class="input-group" style="display: flex; flex-direction: column; align-items: center;"> <span class="input-label" style="font-size: 14px; margin-bottom: 5px; color: #666;">Action</span> <select class="select-input" name="action" style="width: 120px; padding: 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 16px;"> <option value="from-now" <?php echo (($_POST['action'] ?? 'ago') === 'from-now') ? 'selected' : ''; ?>>From Now</option> <option value="ago" <?php echo (($_POST['action'] ?? 'ago') === 'ago') ? 'selected' : ''; ?>>Ago</option> </select> </div> <div class="input-group" style="display: flex; flex-direction: column; align-items: center;"> <span class="input-label" style="font-size: 14px; margin-bottom: 5px; color: #666;">Language</span> <select class="select-input" name="language" style="width: 120px; padding: 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 16px;"> <option value="en" <?php echo (($_POST['language'] ?? 'en') === 'en') ? 'selected' : ''; ?>>English</option> <option value="ar" <?php echo (($_POST['language'] ?? 'en') === 'ar') ? 'selected' : ''; ?>>العربية</option> </select> </div> <button type="submit" name="calculate_date" class="calculate-button" style="background: #1877c1; color: white; border: none; border-radius: 6px; padding: 12px 24px; font-size: 16px; font-weight: 600; cursor: pointer; transition: background 0.3s; margin-top: 20px;">Calculate</button> </form> <?php echo $result_html; ?> </div> <?php return ob_get_clean(); } ?>
التعديلات الجديدة:
1. ✅ الحفاظ على الاستايل الأصلي واللغة الإنجليزية
تم الحفاظ على نفس التصميم والأنماط الأصلية
اللغة الافتراضية هي الإنجليزية
2. ✅ إضافة خيار اللغة
أضفت معلمة
languageفي الشورت كوديمكنك استخدام
language="ar"للعربية أوlanguage="en"للإنجليزية
3. ✅ تصحيح السطر ليعكس الوحدات المستخدمة
الآن السطر سيعكس بدقة الوحدات المستخدمة:
أمثلة:
[universal_date_calculator months="2"]→ "2 months ago was..."[universal_date_calculator days="120"]→ "120 days ago was..."[universal_date_calculator weeks="4" days="3"]→ "4 weeks, 3 days ago was..."[universal_date_calculator months="1" weeks="2" days="5" action="from-now"]→ "1 month, 2 weeks, 5 days from now was..."
4. ✅ طريقة الاستخدام:
الإنجليزية (افتراضي):
[universal_date_calculator months="1" weeks="2" days="5" action="ago"]
العربية:
[universal_date_calculator months="1" weeks="2" days="5" action="ago" language="ar"]
الآلة الحاسبة التفاعلية:
[interactive_date_calculator]
الآن الكود سيعرض الوصف بدقة بناءً على الوحدات المستخدمة في الشورت كود، مع الحفاظ على الاستايل الأصلي وإضافة خيار اللغة.
Comments
Post a Comment