function GeneralDateToPersianDate($str) { $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $str = preg_split('/ /', $str, -1, PREG_SPLIT_OFFSET_CAPTURE); $date = $str[0][0]; $time = $str[1][0]; $date = preg_split('/-/', $date, -1, PREG_SPLIT_OFFSET_CAPTURE); $time = preg_split('/:/', $time, -1, PREG_SPLIT_OFFSET_CAPTURE); // echo "H: ".$time[0][0]."<br>"; // echo "M: ".$time[1][0]."<br>"; // echo "S: ".$time[2][0]."<br>"; // echo "Y: ".$date[0][0]."<br>"; // echo "M: ".$date[1][0]."<br>"; // echo "D: ".$date[2][0]."<br>"; $time[0][0] = $time[0][0] + 8; $time[1][0] = $time[1][0] + 30; if ($time[1][0] >= 60) { $time[1][0] -= 60; $time[0][0] += 1; } if ($time[0][0] >= 24) { $time[0][0] -= 24; $date[2][0] += 1; if ($date[2][0] >= $g_days_in_month[intval($date[1][0])]) { $date[2][0] -= $g_days_in_month[intval($date[1][0])]; $date[1][0] += 1; if ($date[1][0] >= 12) { $date[1][0] = 1; $date[0][0] += 1; } } } $date = gregorian_to_jalali($date[0][0], $date[1][0], $date[2][0]); return $date[0] . "-" . $date[1] . "-" . $date[2] . " " . $time[0][0] . ":" . $time[1][0] . ":" . $time[2][0]; }
/** * Find Number Of Days In This Month<br/> * use <b>jday_of_month()</b> instead lastday() * @deprecated since 5.0.0 */ function lastday($month, $day, $year) { $lastdayen = date("d", mktime(0, 0, 0, $month + 1, 0, $year)); list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $lastdatep = $jday; $jday = $jday2; while ($jday2 != "1") { if ($day < $lastdayen) { $day++; list($jyear, $jmonth, $jday2) = gregorian_to_jalali($year, $month, $day); if ($jdate2 == "1") { break; } if ($jdate2 != "1") { $lastdatep++; } } else { $day = 0; $month++; if ($month == 13) { $month = "1"; $year++; } } } return $lastdatep - 1; }
function Set_date() { $year = date("Y"); $mount = date("m") - 3; $day = date("d"); if ($mount <= 0) { $mount = $mount + 12; $year = $year - 1; } return gregorian_to_jalali($year, $mount, $day); }
function date_format2($datestamp) { $tzoffset = 0; list($date, $time) = explode(" ", $datestamp); list($year, $month, $day) = explode("-", $date); list($hour, $minute, $second) = explode(":", $time); $hour = $hour + $tzoffset; list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $sDate = farsinum($jyear - 1300) . "/" . farsinum($jmonth) . "/" . farsinum($jday) . " " . farsinum($hour) . ":" . farsinum($minute); return "<span lang='fa' dir='rtl'>" . $sDate . "</span>"; }
function dateToJalali($date, $sep = '/', $convert = null) { $datetime = strtotime($date); $year = date('Y', $datetime); $month = date('m', $datetime); $day = date('d', $datetime); $jdate = gregorian_to_jalali($year, $month, $day); // uses jdf.php functions if (isset($convert) && $convert != false) { $farsi_array = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'); $english_array = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); $jdate = str_replace($english_array, $farsi_array, $jdate); } return $jdate[0] . $sep . $jdate[1] . $sep . $jdate[2]; }
function jstrftime($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { $T_sec = 0; /* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ if ($time_zone != 'local') { date_default_timezone_set($time_zone == '' ? 'Asia/Tehran' : $time_zone); } $ts = $T_sec + (($timestamp == '' or $timestamp == 'now') ? time() : tr_num($timestamp)); $date = explode('_', date('h_H_i_j_n_s_w_Y', $ts)); list($j_y, $j_m, $j_d) = gregorian_to_jalali($date[7], $date[4], $date[3]); $doy = $j_m < 7 ? ($j_m - 1) * 31 + $j_d - 1 : ($j_m - 7) * 30 + $j_d + 185; $kab = $j_y % 33 % 4 - 1 == (int) ($j_y % 33 * 0.05) ? 1 : 0; $sl = strlen($format); $out = ''; for ($i = 0; $i < $sl; $i++) { $sub = substr($format, $i, 1); if ($sub == '%') { $sub = substr($format, ++$i, 1); } else { $out .= $sub; continue; } switch ($sub) { /* Day */ case 'a': $out .= jdate_words(array('kh' => $date[6]), ' '); break; case 'A': $out .= jdate_words(array('rh' => $date[6]), ' '); break; case 'd': $out .= $j_d < 10 ? '0' . $j_d : $j_d; break; case 'e': $out .= $j_d < 10 ? ' ' . $j_d : $j_d; break; case 'j': $out .= str_pad($doy + 1, 3, 0, STR_PAD_LEFT); break; case 'u': $out .= $date[6] + 1; break; case 'w': $out .= $date[6] == 6 ? 0 : $date[6] + 1; break; /* Week */ /* Week */ case 'U': $avs = ($date[6] < 5 ? $date[6] + 2 : $date[6] - 5) - $doy % 7; if ($avs < 0) { $avs += 7; } $num = (int) (($doy + $avs) / 7) + 1; if ($avs > 3 or $avs == 1) { $num--; } $out .= $num < 10 ? '0' . $num : $num; break; case 'V': $avs = ($date[6] == 6 ? 0 : $date[6] + 1) - $doy % 7; if ($avs < 0) { $avs += 7; } $num = (int) (($doy + $avs) / 7); if ($avs < 4) { $num++; } elseif ($num < 1) { $num = ($avs == 4 or $avs == ($j_y % 33 % 4 - 2 == (int) ($j_y % 33 * 0.05) ? 5 : 4)) ? 53 : 52; } $aks = $avs + $kab; if ($aks == 7) { $aks = 0; } $out .= ($kab + 363 - $doy < $aks and $aks < 3) ? '01' : ($num < 10 ? '0' . $num : $num); break; case 'W': $avs = ($date[6] == 6 ? 0 : $date[6] + 1) - $doy % 7; if ($avs < 0) { $avs += 7; } $num = (int) (($doy + $avs) / 7) + 1; if ($avs > 3) { $num--; } $out .= $num < 10 ? '0' . $num : $num; break; /* Month */ /* Month */ case 'b': case 'h': $out .= jdate_words(array('km' => $j_m), ' '); break; case 'B': $out .= jdate_words(array('mm' => $j_m), ' '); break; case 'm': $out .= $j_m > 9 ? $j_m : '0' . $j_m; break; /* Year */ /* Year */ case 'C': $out .= substr($j_y, 0, 2); break; case 'g': $jdw = $date[6] == 6 ? 0 : $date[6] + 1; $dny = 364 + $kab - $doy; $out .= substr(($jdw > $doy + 3 and $doy < 3) ? $j_y - 1 : ((3 - $dny > $jdw and $dny < 3) ? $j_y + 1 : $j_y), 2, 2); break; case 'G': $jdw = $date[6] == 6 ? 0 : $date[6] + 1; $dny = 364 + $kab - $doy; $out .= ($jdw > $doy + 3 and $doy < 3) ? $j_y - 1 : ((3 - $dny > $jdw and $dny < 3) ? $j_y + 1 : $j_y); break; case 'y': $out .= substr($j_y, 2, 2); break; case 'Y': $out .= $j_y; break; /* Time */ /* Time */ case 'H': $out .= $date[1]; break; case 'I': $out .= $date[0]; break; case 'l': $out .= $date[0] > 9 ? $date[0] : ' ' . (int) $date[0]; break; case 'M': $out .= $date[2]; break; case 'p': $out .= $date[1] < 12 ? 'قبل از ظهر' : 'بعد از ظهر'; break; case 'P': $out .= $date[1] < 12 ? 'ق.ظ' : 'ب.ظ'; break; case 'r': $out .= $date[0] . ':' . $date[2] . ':' . $date[5] . ' ' . ($date[1] < 12 ? 'قبل از ظهر' : 'بعد از ظهر'); break; case 'R': $out .= $date[1] . ':' . $date[2]; break; case 'S': $out .= $date[5]; break; case 'T': $out .= $date[1] . ':' . $date[2] . ':' . $date[5]; break; case 'X': $out .= $date[0] . ':' . $date[2] . ':' . $date[5]; break; case 'z': $out .= date('O', $ts); break; case 'Z': $out .= date('T', $ts); break; /* Time and Date Stamps */ /* Time and Date Stamps */ case 'c': $key = jdate_words(array('rh' => $date[6], 'mm' => $j_m)); $out .= $date[1] . ':' . $date[2] . ':' . $date[5] . ' ' . date('P', $ts) . ' ' . $key['rh'] . '، ' . $j_d . ' ' . $key['mm'] . ' ' . $j_y; break; case 'D': $out .= substr($j_y, 2, 2) . '/' . ($j_m > 9 ? $j_m : '0' . $j_m) . '/' . ($j_d < 10 ? '0' . $j_d : $j_d); break; case 'F': $out .= $j_y . '-' . ($j_m > 9 ? $j_m : '0' . $j_m) . '-' . ($j_d < 10 ? '0' . $j_d : $j_d); break; case 's': $out .= $ts; break; case 'x': $out .= substr($j_y, 2, 2) . '/' . ($j_m > 9 ? $j_m : '0' . $j_m) . '/' . ($j_d < 10 ? '0' . $j_d : $j_d); break; /* Miscellaneous */ /* Miscellaneous */ case 'n': $out .= "\n"; break; case 't': $out .= "\t"; break; case '%': $out .= '%'; break; default: $out .= $sub; } } return $tr_num != 'en' ? tr_num($out, 'fa', '.') : $out; }
function jdate($type, $maket = 'now') { global $icmsConfig; icms_loadLanguageFile('core', 'calendar'); $result = ''; if ($maket == 'now') { $year = date('Y'); $month = date('m'); $day = date('d'); list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $maket = jmaketime(date('h'), date('i'), date('s'), $jmonth, $jday, $jyear); } else { $date = date('Y-m-d', $maket); list($year, $month, $day) = preg_split('/-/', $date); list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); } $need = $maket; $year = date('Y', $need); $month = date('m', $need); $day = date('d', $need); $i = 0; while ($i < strlen($type)) { $subtype = substr($type, $i, 1); switch ($subtype) { case 'A': $result1 = date('a', $need); if ($result1 == 'pm') { $result .= _CAL_PM_LONG; } else { $result .= _CAL_AM_LONG; } break; case 'a': $result1 = date('a', $need); if ($result1 == 'pm') { $result .= _CAL_PM; } else { $result .= _CAL_AM; } break; case 'd': list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); if ($jday < 10) { $result1 = '0' . $jday; } else { $result1 = $jday; } $result .= $result1; break; case 'D': $result1 = date('D', $need); if ($result1 == 'Sat') { $result1 = _CAL_SAT; } else { if ($result1 == 'Sun') { $result1 = _CAL_SUN; } else { if ($result1 == 'Mon') { $result1 = _CAL_MON; } else { if ($result1 == 'Tue') { $result1 = _CAL_TUE; } else { if ($result1 == 'Wed') { $result1 = _CAL_WED; } else { if ($result1 == 'Thu') { $result1 = _CAL_THU; } else { if ($result1 == 'Fri') { $result1 = _CAL_FRI; } } } } } } } $result .= $result1; break; case 'F': list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $result .= Icms_getMonthNameById($jmonth); break; case 'g': $result .= date('g', $need); break; case 'G': $result .= date('G', $need); break; case 'h': $result .= date('h', $need); break; case 'H': $result .= date('H', $need); break; case 'i': $result .= date('i', $need); break; case 'j': list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $result .= $jday; break; case 'l': $result1 = date('l', $need); if ($result1 == 'Saturday') { $result1 = _CAL_SATURDAY; } else { if ($result1 == 'Sunday') { $result1 = _CAL_SUNDAY; } else { if ($result1 == 'Monday') { $result1 = _CAL_MONDAY; } else { if ($result1 == 'Tuesday') { $result1 = _CAL_TUESDAY; } else { if ($result1 == 'Wednesday') { $result1 = _CAL_WEDNESDAY; } else { if ($result1 == 'Thursday') { $result1 = _CAL_THURSDAY; } else { if ($result1 == 'Friday') { $result1 = _CAL_FRIDAY; } } } } } } } $result .= $result1; break; case 'm': list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); if ($jmonth < 10) { $result1 = '0' . $jmonth; } else { $result1 = $jmonth; } $result .= $result1; break; case 'M': list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $result .= Icms_getMonthNameById($jmonth); break; case 'n': list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $result .= $jmonth; break; case 's': $result .= date('s', $need); break; case 'S': $result .= _CAL_SUFFIX; break; case 't': $result .= lastday($month, $day, $year); break; case 'w': $result .= date('w', $need); break; case 'y': list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $result .= substr($jyear, 2, 4); break; case 'Y': list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $result .= $jyear; break; default: $result .= $subtype; } $i++; } return $result; }
/** * own widget function */ function ztjalali_archive_widget($type = 'monthly', $format = 'html', $show_post_count = false, $limit = 12, $before = '', $after = '') { global $wpdb, $jdate_month_name, $ztjalali_option; if ($type === "yearly") { $YearlyQry = $wpdb->get_results("SELECT DATE_FORMAT( post_date ,'%Y-%m-%d' ) as date,\n count(ID) as count,\n YEAR(post_date) AS `year`, \n MONTH(post_date) AS `month`, \n DAYOFMONTH(post_date) AS `dayofmonth` \n FROM {$wpdb->posts} \n WHERE post_date < NOW() \n AND post_type = 'post' \n AND post_status = 'publish' \n GROUP BY date ORDER BY post_date DESC"); if (!empty($YearlyQry)) { $jYears = array(); $i = 1; foreach ($YearlyQry as $res) { $jalali_year = gregorian_to_jalali($res->year, $res->month, $res->dayofmonth); $jYears[$jalali_year[0]]['year'] = $res->year; if (!array_key_exists('count', $jYears[$jalali_year[0]])) { $jYears[$jalali_year[0]]['count'] = 0; } $jYears[$jalali_year[0]]['count'] += $res->count; } foreach ($jYears as $jYear => $data) { if ($ztjalali_option['change_url_date_to_jalali']) { $url = get_year_link($jYear); } else { $url = get_year_link($data['year']); } $jYear = ztjalali_persian_num($jYear); $c_after = $show_post_count ? ' (' . ztjalali_persian_num($data['count']) . ')' . $after : ''; echo get_archives_link($url, $jYear, $format, $before, $c_after); if ($i == $limit) { break; } $i++; } } } elseif ("monthly" == $type or empty($type)) { $MonthlyQry = $wpdb->get_results("SELECT DATE_FORMAT( post_date ,'%Y-%m-%d' ) as date,\n count(ID) as count,\n YEAR(post_date) AS `year`, \n MONTH(post_date) AS `month`, \n DAYOFMONTH(post_date) AS `dayofmonth` \n FROM {$wpdb->posts} \n WHERE post_date < NOW() \n AND post_type = 'post' \n AND post_status = 'publish' \n GROUP BY date ORDER BY post_date DESC"); if (!empty($MonthlyQry)) { $jMonths = array(); foreach ($MonthlyQry as $res) { $jalali_month = gregorian_to_jalali($res->year, $res->month, $res->dayofmonth); $jMonths[$jalali_month[0] . '-' . $jalali_month[1]]['year'] = $res->year; $jMonths[$jalali_month[0] . '-' . $jalali_month[1]]['month'] = $res->month; if (!array_key_exists('count', $jMonths[$jalali_month[0] . '-' . $jalali_month[1]])) { $jMonths[$jalali_month[0] . '-' . $jalali_month[1]]['count'] = 0; } $jMonths[$jalali_month[0] . '-' . $jalali_month[1]]['count'] += $res->count; } $i = 1; foreach ($jMonths as $jMonth => $data) { list($jY, $jM) = explode('-', $jMonth); if ($ztjalali_option['change_url_date_to_jalali']) { $url = get_month_link($jY, $jM); } else { $url = get_month_link($data['year'], $data['month']); } $jY = ztjalali_persian_num($jY); $jM = $jdate_month_name[$jM]; $c_after = $show_post_count ? ' (' . ztjalali_persian_num($data['count']) . ')' . $after : ''; echo get_archives_link($url, $jM . ' ' . $jY, $format, $before, $c_after); if ($i == $limit) { break; } $i++; } } } elseif ("daily" == $type) { $limStr = ''; if (!empty($limit)) { $limit = (int) $limit; $limStr = ' LIMIT ' . $limit; } $DailyQry = $wpdb->get_results("SELECT DATE_FORMAT( post_date ,'%Y-%m-%d' ) as date,\n count(ID) as count,\n YEAR(post_date) AS `year`, \n MONTH(post_date) AS `month`, \n DAYOFMONTH(post_date) AS `dayofmonth` \n FROM {$wpdb->posts} \n WHERE post_date < NOW() \n AND post_type = 'post' \n AND post_status = 'publish' \n GROUP BY date ORDER BY post_date DESC " . $limStr); if (!empty($DailyQry)) { foreach ($DailyQry as $Daily) { list($jY, $jM, $jD) = gregorian_to_jalali($Daily->year, $Daily->month, $Daily->dayofmonth); if ($ztjalali_option['change_url_date_to_jalali']) { $url = get_day_link($jY, $jM, $jD); } else { $url = get_day_link($Daily->year, $Daily->month, $Daily->dayofmonth); } $date = mktime(0, 0, 0, $Daily->month, $Daily->dayofmonth, $Daily->year); $text = jdate(get_option('date_format'), $date); if ($show_post_count) { $c_after = ' (' . ztjalali_persian_num($Daily->count) . ')' . $after; } echo get_archives_link($url, $text, $format, $before, $c_after); } } } elseif ('postbypost' == $type) { $limStr = ''; if (!empty($limit)) { $limit = (int) $limit; $limStr = ' LIMIT ' . $limit; } $byPosts = $wpdb->get_results("SELECT ID, post_date, post_title FROM {$wpdb->posts} WHERE post_type='post' AND post_date < NOW() AND post_status = 'publish' ORDER BY post_date DESC" . $limStr); if (!empty($byPosts)) { foreach ($byPosts as $aPost) { if ($aPost->post_date != '0000-00-00 00:00:00') { $url = get_permalink($aPost->ID); echo get_archives_link($url, strip_tags($aPost->post_title), $format, $before, $after); } } } } }
function sql2checkdate($date_) { global $date_system; //for MySQL dates are in the format YYYY-mm-dd if ($date_ == null || strlen($date_) == 0) { return ""; } if (strpos($date_, "/")) { // In MySQL it could be either / or - list($year, $month, $day) = explode("/", $date_); } elseif (strpos($date_, "-")) { list($year, $month, $day) = explode("-", $date_); } if (strlen($day) > 4) { /*chop off the time stuff */ $day = substr($day, 0, 2); } if ($date_system == 1) { list($year, $month, $day) = gregorian_to_jalali($year, $month, $day); } elseif ($date_system == 2) { list($year, $month, $day) = gregorian_to_islamic($year, $month, $day); } return $day . $month . $year; }
/** * return link of jalali day * @param int $year year * @param int $month month * @param int $day day * @return string * @since 5.0.0 * @see wp-includes\link-template.php line 508 */ function ztjalali_day_link($year, $month, $day) { global $ztjalali_option; if ($ztjalali_option['change_url_date_to_jalali']) { $jdate = gregorian_to_jalali($year, $month, $day); return get_day_link($jdate[0], $jdate[1], $jdate[2]); } return get_day_link($year, $month, $day); }
</div> <div class="data-row hotel-name two-cols"> <div class="title">تاریخ ورود</div> <div class="value text-center first-value"> <?php $arr = explode('-', $invoce_data['date_in']); echo jdate('l', $invoce_data['date_in']) . ' '; echo gregorian_to_jalali($arr[0], $arr[1], $arr[2], '/'); ?> </div> <div class="title">تاریخ خروج</div> <div class="value text-center"> <?php $arr = explode('-', $invoce_data['date_out']); echo jdate('l', $invoce_data['date_out']) . ' '; echo gregorian_to_jalali($arr[0], $arr[1], $arr[2], '/'); ?> </div> </div> <div class="data-row description"> <div class="title">توضیحات</div> <div class="value"> <?php echo ''; ?> </div> </div> <?php } ?> </div>
<?php } ?> <li><?php echo osc_draw_label($osC_Language->get('field_customer_first_name'), 'firstname', null, true) . ' ' . osc_draw_input_field('firstname', $Qaccount->value('customers_firstname')); ?> </li> <li><?php echo osc_draw_label($osC_Language->get('field_customer_last_name'), 'lastname', null, true) . ' ' . osc_draw_input_field('lastname', $Qaccount->value('customers_lastname')); ?> </li> <?php if (ACCOUNT_DATE_OF_BIRTH == '1') { $g_t_j = gregorian_to_jalali($Qaccount->value('customers_dob_year'), $Qaccount->value('customers_dob_month'), $Qaccount->value('customers_dob_date')); ?> <li><?php echo osc_draw_label($osC_Language->get('field_customer_date_of_birth'), 'dob_days', null, true) . ' ' . osc_draw_jdate_pull_down_menu('dob', array('year' => $g_t_j['0'], 'month' => $g_t_j['1'], 'date' => $g_t_j['2']), false, null, null, date('Y') - 1921, -5); ?> </li> <?php } ?> <li><?php echo osc_draw_label($osC_Language->get('field_customer_email_address'), 'email_address', null, true) . ' ' . osc_draw_input_field('email_address', $Qaccount->value('customers_email_address'), 'dir="ltr"'); ?> </li>
/** * jalali link filter handlers * @param string $perma * @param string $post * @param string $leavename * @see wp-includes\link-template.php line 112 */ function ztjalali_permalink_filter_fn($perma, $post, $leavename = false) { $permalink = get_option('permalink_structure'); if (empty($permalink)) { return $perma; } if (!preg_match('/%year%|%monthnum%|%day%/', $permalink)) { return $perma; } /* ------------------------------------------------------ */ if (empty($post->ID)) { return $perma; } /* ------------------------------------------------------ */ if (in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) { return $perma; } /* ------------------------------------------------------ */ $illegal_post_types = get_post_types(array('_builtin' => false)); $illegal_post_types[] = 'page'; $illegal_post_types[] = 'attachment'; if (in_array($post->post_type, $illegal_post_types)) { return $perma; } /* ------------------------------------------------------ */ $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', $leavename ? '' : '%pagename%'); $unixtime = strtotime($post->post_date); $category = ""; if (strpos($permalink, '%category%') !== false) { $cats = get_the_category($post->ID); if ($cats) { usort($cats, '_usort_terms_by_ID'); // order by ID $category_object = get_term(reset($cats), 'category'); $category = $category_object->slug; if ($parent = $category_object->parent) { $category = get_category_parents($parent, false, '/', true) . $category; } } if (empty($category)) { $default_category = get_term(get_option('default_category'), 'category'); $category = is_wp_error($default_category) ? '' : $default_category->slug; } } $author = ""; if (strpos($permalink, '%author%') !== false) { $authordata = get_user_by('id', $post->post_author); if (!empty($authordata)) { $author = $authordata->user_nicename; } } $date = explode("-", date('Y-m-d-H-i-s', $unixtime)); $jdate = gregorian_to_jalali($date[0], $date[1], $date[2]); $rewritereplace = array($jdate[0], sprintf('%02d', $jdate[1]), sprintf('%02d', $jdate[2]), $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name); $permalink = home_url(str_replace($rewritecode, $rewritereplace, $permalink)); return user_trailingslashit($permalink, 'single'); }
function pstrftime($format, $timestamp = "") { global $pdateMonthName, $pdateWeekName, $MonthDays; if ($timestamp === "") { $timestamp = time(); } // Create need date parametrs $date = date("Y-m-d-w", $timestamp); list($gYear, $gMonth, $gDay, $gWeek) = explode('-', $date); list($pYear, $pMonth, $pDay) = gregorian_to_jalali($gYear, $gMonth, $gDay); $pWeek = $gWeek + 1; if ($pWeek == 7) { $pWeek = 0; } $lenghFormat = strlen($format); $i = 0; $result = ""; while ($i < $lenghFormat) { $par = $format[$i]; if ($par == "%") { $type = $format[++$i]; switch ($type) { //Day case 'a': $result .= substr($pdateWeekName[$pWeek], 0, 2); break; case 'A': $result .= $pdateWeekName[$pWeek]; break; case 'd': $result .= $pDay < 10 ? "0" . $pDay : $pDay; break; case 'e': $result .= $pDay; break; case 'j': $dayinM = DayOfYear($pYear, $pMonth, $pDay); $result .= $dayinM < 10 ? "00" . $dayinM : ($dayinM < 100 ? "0" . $dayinM : $dayinM); break; case 'u': $result .= $pWeek + 1; break; case 'w': $result .= $pWeek; break; //Week //Week case 'U': $result .= floor(DayOfYear($pYear, $pMonth, $pDay) / 7); break; case 'V': case 'W': $result .= ceil(DayOfYear($pYear, $pMonth, $pDay) / 7); break; //Month //Month case 'b': case 'h': $result .= substr($pdateMonthName[$pMonth], 0, 6); break; case 'B': $result .= $pdateMonthName[$pMonth]; break; case 'm': $result .= $pMonth < 10 ? "0" . $pMonth : $pMonth; break; //Year //Year case 'C': $result .= ceil($pYear / 100); break; case 'g': case 'y': $result .= substr($pYear, 2); break; case 'G': case 'Y': $result .= $pYear; break; //Time //Time case 'H': case 'I': case 'l': case 'M': case 'R': case 'S': case 'T': case 'X': case 'z': case 'Z': $result .= strftime("%" . $type, $timestamp); break; case 'p': case 'P': case 'r': if (date('a', $timestamp) == 'am') { $result .= $type == 'p' ? 'ق.ظ' : ($type == 'P' ? 'قبل از ظهر' : strftime("%I:%M:%S قبل از ظهر", $timestamp)); } else { $result .= $type == 'p' ? 'ب.ظ' : ($type == 'P' ? 'بعد از ظهر' : strftime("%I:%M:%S بعد از ظهر", $timestamp)); } break; //Time and Date Stamps //Time and Date Stamps case 'c': $result .= substr($pdateWeekName[$pWeek], 0, 2) . " " . substr($pdateMonthName[$pMonth], 0, 6) . " " . $pDay . " " . strftime("%T", $timestamp) . " " . $pYear; break; case 'D': case 'x': $result .= ($pMonth < 10 ? "0" . $pMonth : $pMonth) . "/" . ($pDay < 10 ? "0" . $pDay : $pDay) . "/" . substr($pYear, 2); break; case 'F': $result .= $pYear . "-" . ($pMonth < 10 ? "0" . $pMonth : $pMonth) . "-" . ($pDay < 10 ? "0" . $pDay : $pDay); break; case 's': $result .= $timestamp; break; //Miscellaneous //Miscellaneous case 'n': $result .= "\n"; break; case 't': $result .= "\t"; break; case '%': $result .= "%"; break; default: $result .= "%" . $type; } } else { $result .= $par; } $i++; } return $result; }
function formated_to_jalali($source, $date_divider = '/', $time_sep = ' ') { $source = number_to_en($source); if ($time_sep !== FALSE and strpos($source, $time_sep)) { list($jdate, $time) = explode($time_sep, $source); } else { $time = ''; $jdate = $source; $time_sep = ''; } list($gY, $gM, $gD) = explode($date_divider, $jdate); list($y, $m, $d) = gregorian_to_jalali($gY, $gM, $gD); return $y . $date_divider . $m . $date_divider . $d . $time_sep . $time; }
/** * own widget function */ function ztjalali_calendar_widget($shortname = TRUE, $echo = TRUE, $thisyear = 0, $thismonth = 0) { global $wpdb, $posts, $wp; global $jdate_month_name, $ztjalali_option; if (isset($wp->query_vars['m'])) { $m_year = (int) substr($wp->query_vars['m'], 0, 4); $m_month = (int) substr($wp->query_vars['m'], 4, 2); if ($m_year < 1700) { list($m_year, $m_month, $tmp_day) = jalali_to_gregorian($m_year, $m_month, 15); } } elseif (isset($wp->query_vars['m'])) { $thisyear = (int) substr($wp->query_vars['m'], 0, 4); } if (empty($thisyear)) { if (isset($wp->query_vars['year'])) { $thisyear = (int) $wp->query_vars['year']; } elseif (isset($m_year)) { $thisyear = $m_year; } else { $thisyear = date('Y', time()); } } if (empty($thismonth)) { if (isset($wp->query_vars['monthnum'])) { $thismonth = (int) $wp->query_vars['monthnum']; } elseif (isset($m_month)) { $thismonth = $m_month; } else { $thismonth = date('m', time()); } } //doing: support $_GET['w'] // if (isset($_GET['w'])) // $w = '' . (int)($_GET['w']); // if (!empty($w)) { //// We need to get the month from MySQL // $thisyear = '' . (int)(substr($m, 0, 4)); // $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's // $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); // } /* doing : cache */ $cache = array(); $key = md5($thismonth . $thisyear); if ($cache = wp_cache_get('ztjalali_calendar', 'calendar')) { if (is_array($cache) && isset($cache[$key])) { if ($echo) { /** This filter is documented in wp-includes/general-template.php */ echo apply_filters('ztjalali_calendar', $cache[$key]); return; } else { /** This filter is documented in wp-includes/general-template.php */ return apply_filters('ztjalali_calendar', $cache[$key]); } } } if (!is_array($cache)) { $cache = array(); } // Quick check. If we have no posts at all, abort! if (!$posts) { $gotsome = $wpdb->get_var("SELECT 1 as test FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); if (!$gotsome) { $cache[$key] = ''; wp_cache_set('ztjalali_calendar', $cache, 'calendar'); return; } } if ($thisyear > 1700) { list($thisyear, $thismonth, $thisday) = gregorian_to_jalali($thisyear, $thismonth, 1); } $unixmonth = jmktime(0, 0, 0, $thismonth, 1, $thisyear); $jthisyear = $thisyear; $jthismonth = $thismonth; list($thisyear, $thismonth, $jthisday) = jalali_to_gregorian($jthisyear, $jthismonth, 1); $last_day = jdate('t', $unixmonth, FALSE, FALSE); // Get the next and previous month and year with at least one post $startdate = date("Y:m:d", jmktime(0, 0, 0, $jthismonth, 1, $jthisyear)); $enddate = date("Y:m:d", jmktime(23, 59, 59, $jthismonth, $last_day, $jthisyear)); $previous = $wpdb->get_row("SELECT DAYOFMONTH(post_date) AS `dayofmonth`,MONTH(post_date) AS month, YEAR(post_date) AS year\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_date < '{$startdate}'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\t\tORDER BY post_date DESC\n\t\t\tLIMIT 1"); $next = $wpdb->get_row("SELECT DAYOFMONTH(post_date) AS `dayofmonth`,MONTH(post_date) AS month, YEAR(post_date) AS year\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_date > '{$enddate} 23:59:59'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\t\tORDER BY post_date ASC\n\t\t\tLIMIT 1"); /* translators: Calendar caption: 1: month name, 2: 4-digit year */ $calendar_caption = _x('%1$s %2$s', 'calendar caption'); $calendar_output = '<table id="wp-calendar" class="widget_calendar"> <caption>' . sprintf($calendar_caption, $jdate_month_name[(int) $jthismonth], jdate('Y', $unixmonth)) . '</caption> <thead> <tr>'; $myweek = $myshortweek = array(); $week_begins = (int) get_option('start_of_week'); for ($wdcount = 0; $wdcount <= 6; $wdcount++) { $myweek[] = ztjalali_get_week_name(($wdcount + $week_begins) % 7); $myshortweek[] = ztjalali_get_short_week_name(($wdcount + $week_begins) % 7); } foreach ($myweek as $k => $wd) { $day_name = true == $shortname ? $myshortweek[$k] : $wd; $wd = esc_attr($wd); $calendar_output .= "\n\t\t<th scope=\"col\" title=\"{$wd}\">{$day_name}</th>"; } $calendar_output .= ' </tr> </thead> <tfoot> <tr>'; if ($previous) { $jprevious = gregorian_to_jalali($previous->year, $previous->month, $previous->dayofmonth); if ($ztjalali_option['change_url_date_to_jalali']) { $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev"><a href="' . get_month_link($jprevious[0], $jprevious[1]) . '" title="' . esc_attr(sprintf(__('View posts for %1$s %2$s', 'ztjalali'), $jdate_month_name[$jprevious[1]], jdate('Y', mktime(0, 0, 0, $previous->month, 1, $previous->year)))) . '">« ' . $jdate_month_name[$jprevious[1]] . '</a></td>'; } else { $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr(sprintf(__('View posts for %1$s %2$s', 'ztjalali'), $jdate_month_name[$jprevious[1]], jdate('Y', mktime(0, 0, 0, $previous->month, 1, $previous->year)))) . '">« ' . $jdate_month_name[$jprevious[1]] . '</a></td>'; } } else { $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev" class="pad"> </td>'; } $calendar_output .= "\n\t\t" . '<td class="pad"> </td>'; if ($next) { $jnext = gregorian_to_jalali($next->year, $next->month, $next->dayofmonth); if ($ztjalali_option['change_url_date_to_jalali']) { $calendar_output .= "\n\t\t" . '<td colspan="3" id="next"><a href="' . get_month_link($jnext[0], $jnext[1]) . '" title="' . esc_attr(sprintf(__('View posts for %1$s %2$s', 'ztjalali'), $jdate_month_name[$jnext[1]], jdate('Y', mktime(0, 0, 0, $next->month, 1, $next->year)))) . '">' . $jdate_month_name[$jnext[1]] . ' »</a></td>'; } else { $calendar_output .= "\n\t\t" . '<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr(sprintf(__('View posts for %1$s %2$s', 'ztjalali'), $jdate_month_name[$jnext[1]], jdate('Y', mktime(0, 0, 0, $next->month, 1, $next->year)))) . '">' . $jdate_month_name[$jnext[1]] . ' »</a></td>'; } } else { $calendar_output .= "\n\t\t" . '<td colspan="3" id="next" class="pad"> </td>'; } $calendar_output .= ' </tr> </tfoot> <tbody> <tr>'; // Get days with posts $dayswithposts = $wpdb->get_results("SELECT DISTINCT post_date\n\t\tFROM {$wpdb->posts} WHERE post_date >= '{$startdate} 00:00:00'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\tAND post_date <= '{$enddate} 23:59:59'", ARRAY_N); if ($dayswithposts) { foreach ((array) $dayswithposts as $daywith) { $jdaywithpost[] = jdate('j', strtotime($daywith[0]), FALSE, FALSE); } } else { $jdaywithpost = array(); } if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) { $ak_title_separator = "\n"; } else { $ak_title_separator = ', '; } $ak_titles_for_day = array(); $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, post_date as dom " . "FROM {$wpdb->posts} " . "WHERE post_date >= '{$startdate} 00:00:00' " . "AND post_date <= '{$enddate} 23:59:59' " . "AND post_type = 'post' AND post_status = 'publish'"); if ($ak_post_titles) { foreach ((array) $ak_post_titles as $ak_post_title) { /** This filter is documented in wp-includes/post-template.php */ $post_title = esc_attr(apply_filters('the_title', $ak_post_title->post_title, $ak_post_title->ID)); $jdom = $jdaywithpost[] = jdate('j', strtotime($ak_post_title->dom), FALSE, FALSE); if (empty($ak_titles_for_day['day_' . $jdom])) { $ak_titles_for_day['day_' . $jdom] = ''; } if (empty($ak_titles_for_day["{$jdom}"])) { // first one $ak_titles_for_day["{$jdom}"] = $post_title; } else { $ak_titles_for_day["{$jdom}"] .= $ak_title_separator . $post_title; } } } // See how much we should pad in the beginning $pad = calendar_week_mod(jdate('w', $unixmonth, false, false) - $week_begins); $pad--; if ($pad < 0) { $pad = 6; } if (0 != $pad) { $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr($pad) . '" class="pad"> </td>'; } $jdaysinmonth = (int) jdate('t', $unixmonth, FALSE, FALSE); for ($jday = 1; $jday <= $jdaysinmonth; ++$jday) { if (isset($newrow) && $newrow) { $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; } $newrow = false; if ($jday == jdate('j', time(), FALSE, FALSE) && $jthismonth == jdate('m', time(), FALSE, FALSE) && $jthisyear == jdate('Y', time(), FALSE, FALSE)) { $calendar_output .= '<td id="today">'; } else { $calendar_output .= '<td>'; } if (in_array($jday, $jdaywithpost)) { // any posts today? $day = jalali_to_gregorian($jthisyear, $jthismonth, $jday); if ($ztjalali_option['change_url_date_to_jalali']) { $calendar_output .= '<a href="' . get_day_link($jthisyear, $jthismonth, $jday) . '" title="' . esc_attr($ak_titles_for_day[$jday]) . "\">{$jday}</a>"; } else { $calendar_output .= '<a href="' . get_day_link($day[0], $day[1], $day[2]) . '" title="' . esc_attr($ak_titles_for_day[$jday]) . "\">{$jday}</a>"; } } else { $calendar_output .= $jday; } $calendar_output .= '</td>'; jdate('w', jmktime(0, 0, 0, $jthismonth, $jday, $jthisyear), FALSE, FALSE); if (6 == calendar_week_mod(date('w', jmktime(0, 0, 0, $jthismonth, $jday, $jthisyear)) - $week_begins)) { $newrow = true; } } $pad = 7 - calendar_week_mod(date('w', jmktime(0, 0, 0, $jthismonth, $jday, $jthisyear)) - $week_begins); if ($pad != 0 && $pad != 7) { $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr($pad) . '"> </td>'; } $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>"; $cache[$key] = $calendar_output; wp_cache_set('ztjalali_calendar', $cache, 'calendar'); if ($ztjalali_option['change_jdate_number_to_persian']) { $calendar_output = ztjalali_persian_num($calendar_output); } if ($echo) { /** * Filter the HTML calendar output. * * @since 3.0.0 * * @param string $calendar_output HTML output of the calendar. */ echo apply_filters('ztjalali_calendar', $calendar_output); } else { /** This filter is documented in wp-includes/general-template.php */ return apply_filters('ztjalali_calendar', $calendar_output); } }
function showdate() { date_default_timezone_set('Asia/Tehran'); list($gyear, $gmonth, $gday) = preg_split('/-/', date("Y-m-d")); list($jyear, $jmonth, $jday) = gregorian_to_jalali($gyear, $gmonth, $gday); $day = date("w"); switch ($day) { case "0": $dname = "یکشنبه"; break; case "1": $dname = "دوشنبه"; break; case "2": $dname = "سه شنبه"; break; case "3": $dname = "چهارشنبه"; break; case "4": $dname = "پنج شنبه"; break; case "5": $dname = "جمعه"; break; case "6": $dname = "شنبه"; break; } switch ($jmonth) { case "1": $mname = "فروردین"; break; case "2": $mname = "اردیبهشت"; break; case "3": $mname = "خرداد"; break; case "4": $mname = "تیر"; break; case "5": $mname = "مرداد"; break; case "6": $mname = "شهریور"; break; case "7": $mname = "مهر"; break; case "8": $mname = "آبان"; break; case "9": $mname = "آذر"; break; case "10": $mname = "دی"; break; case "11": $mname = "بهمن"; break; case "12": $mname = "اسفند"; break; } echo $dname . " " . $jday . " " . $mname . " " . $jyear; }
/** * Format a local time/date according to locale settings (jalali equivalent of php strftime() function) * @global array $jdate_month_name * @param string $format for example 'Y-m-d H:i:s' * @param timestamp $timestamp [optional] * @param bool $fanum [optional]<br/>convert number to persian ?<br/> * default : get from plugin option * @return type * @since 5.0.0 */ function jstrftime($format, $timestamp = NULL, $fanum = false) { global $jdate_month_name; static $jdate_month_days = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); static $jdate_week_name = array('شنبه', 'یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنج شنبه', 'جمعه'); if (!$timestamp) { $timestamp = time(); } # Create need date parametrs list($gYear, $gMonth, $gDay, $gWeek) = explode('-', date('Y-m-d-w', $timestamp)); list($pYear, $pMonth, $pDay) = gregorian_to_jalali($gYear, $gMonth, $gDay); $pWeek = $gWeek + 1; if ($pWeek >= 7) { $pWeek = 0; } $lenghFormat = strlen($format); $i = 0; $result = ''; while ($i < $lenghFormat) { $par = $format[$i]; if ($par == '%') { $type = $format[++$i]; switch ($type) { # Day case 'a': $result .= substr($jdate_week_name[$pWeek], 0, 2); break; case 'A': $result .= $jdate_week_name[$pWeek]; break; case 'd': $result .= $pDay < 10 ? '0' . $pDay : $pDay; break; case 'e': $result .= $pDay; break; case 'j': $dayinM = jday_of_year($pMonth, $pDay); $result .= $dayinM < 10 ? '00' . $dayinM : $dayinM < 100 ? '0' . $dayinM : $dayinM; break; case 'u': $result .= $pWeek + 1; break; case 'w': $result .= $pWeek; break; # Week # Week case 'U': $result .= floor(jday_of_year($pMonth, $pDay) / 7); break; case 'V': case 'W': $result .= ceil(jday_of_year($pMonth, $pDay) / 7); break; # Month # Month case 'b': case 'h': $result .= substr($jdate_month_name[$pMonth], 0, 6); break; case 'B': $result .= $jdate_month_name[$pMonth]; break; case 'm': $result .= $pMonth < 10 ? '0' . $pMonth : $pMonth; break; # Year # Year case 'C': $result .= ceil($pYear / 100); break; case 'g': case 'y': $result .= substr($pYear, 2); break; case 'G': case 'Y': $result .= $pYear; break; # Time # Time case 'H': case 'I': case 'l': case 'M': case 'R': case 'S': case 'T': case 'X': case 'z': case 'Z': $result .= strftime('%' . $type, $timestamp); break; case 'p': case 'P': case 'r': if (date('a', $timestamp) == 'am') { $result .= $type == 'p' ? 'ق.ظ' : $type == 'P' ? 'قبل از ظهر' : strftime("%I:%M:%S قبل از ظهر", $timestamp); } else { $result .= $type == 'p' ? 'ب.ظ' : $type == 'P' ? 'بعد از ظهر' : strftime("%I:%M:%S بعد از ظهر", $timestamp); } break; # Time and Date Stamps # Time and Date Stamps case 'c': $result .= substr($jdate_week_name[$pWeek], 0, 2) . ' ' . substr($jdate_month_name[$pMonth], 0, 6) . ' ' . $pDay . ' ' . strftime("%T", $timestamp) . ' ' . $pYear; break; case 'D': case 'x': $result .= ($pMonth < 10 ? '0' . $pMonth : $pMonth) . '-' . ($pDay < 10 ? '0' . $pDay : $pDay) . '-' . substr($pYear, 2); break; case 'F': $result .= $pYear . '-' . ($pMonth < 10 ? '0' . $pMonth : $pMonth) . '-' . ($pDay < 10 ? '0' . $pDay : $pDay); break; case 's': $result .= $timestamp; break; # Miscellaneous # Miscellaneous case 'n': $result .= "\n"; break; case 't': $result .= "\t"; break; case '%': $result .= '%'; break; default: $result .= '%' . $type; } } else { $result .= $par; } $i++; } if ($fanum) { return ztjalali_persian_num($result); } return $result; }
function date_format($datestamp) { $tzoffset = 0; list($date, $time) = explode(" ", $datestamp); list($year, $month, $day) = explode("-", $date); list($hour, $minute, $second) = explode(":", $time); $hour = $hour + $tzoffset; list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $sDate = $jyear - 1300 . "/" . $jmonth . "/" . $jday . " - " . $hour . ":" . $minute; return $sDate; }
$tax = $r['tax']; $fname = $r['fname_en']; $lname = $r['lname_en']; $airline = $r['airline']; $flight_id = $r['flight_number']; $class = $r['class']; $from_str = get_iata_strname($r['from_city']); $to_str = get_iata_strname($r['to_city']); $iata_from = $r['from_city']; $iata_to = $r['to_city']; $day = jdate('l', $r['fdate']); $arr = explode('-', $r['fdate']); $date = date_format(date_create($r['fdate']), 'dMy'); $issue_date = date_format(date_create($r['tarikh']), 'dMy'); //var_dump($arr); $jdate = gregorian_to_jalali($arr[0], $arr[1], $arr[2], '/'); $gender = $r['gender']; $airline_name = $r['airline_name']; $airline_en_name = $r['airline_en_name']; $agency_name = $r['agencyname']; $agency_tel = $r['tel']; $agency_code = $r['code']; $agency_addr = $r['address']; $tik = file_get_contents("system_template.html"); $tik = str_replace("#voucher_id#", $voucher_id, $tik); $tik = str_replace("#ticket_number#", $ticket_number, $tik); $tik = str_replace("#PRICE#", number_format($total_price), $tik); $tik = str_replace("#BASE_PRICE#", number_format($base_price), $tik); $tik = str_replace("#TAX#", $tax, $tik); $tik = str_replace("#AIRLINE_NAME#", $airline_name, $tik); $tik = str_replace("#AIRLINE_EN_NAME#", $airline_en_name, $tik);