function FormatDate($format="", $timestamp="", $now=false) { global $DB; if($now === false) $now = time(); switch($format) { case "SHORT": $format = $DB->dateFormatToPHP(FORMAT_DATE); break; case "FULL": $format = $DB->dateFormatToPHP(FORMAT_DATETIME); } if(is_array($format)) { $seconds_ago = $now - $timestamp; foreach($format as $format_interval => $format_value) { if($format_interval == "s") { if($seconds_ago < 60) return FormatDate($format_value, $timestamp, $now); } elseif(preg_match('/^s(\d+)/', $format_interval, $match)) { if($seconds_ago < intval($match[1])) return FormatDate($format_value, $timestamp, $now); } elseif($format_interval == "i") { if($seconds_ago < 60*60) return FormatDate($format_value, $timestamp, $now); } elseif(preg_match('/^i(\d+)/', $format_interval, $match)) { if($seconds_ago < intval($match[1])*60) return FormatDate($format_value, $timestamp, $now); } elseif($format_interval == "H") { if($seconds_ago < 24*60*60) return FormatDate($format_value, $timestamp, $now); } elseif(preg_match('/^H(\d+)/', $format_interval, $match)) { if($seconds_ago < intval($match[1])*60*60) return FormatDate($format_value, $timestamp, $now); } elseif($format_interval == "d") { if($seconds_ago < 31*24*60*60) return FormatDate($format_value, $timestamp, $now); } elseif(preg_match('/^d(\d+)/', $format_interval, $match)) { if($seconds_ago < intval($match[1])*60*60) return FormatDate($format_value, $timestamp, $now); } elseif($format_interval == "m") { if($seconds_ago < 365*24*60*60) return FormatDate($format_value, $timestamp, $now); } elseif(preg_match('/^m(\d+)/', $format_interval, $match)) { if($seconds_ago < intval($match[1])*31*24*60*60) return FormatDate($format_value, $timestamp, $now); } elseif($format_interval == "today") { $arNow = localtime($now); //le = number of seconds scince midnight //$le = $arSDate[0]+$arSDate[1]*60+$arSDate[2]*3600; //today_1 = truncate(now) $today_1 = mktime(0, 0, 0, $arNow[4]+1, $arNow[3], $arNow[5]+1900); //today_2 = truncate(now)+1 $today_2 = mktime(0, 0, 0, $arNow[4]+1, $arNow[3]+1, $arNow[5]+1900); if($timestamp >= $today_1 && $timestamp < $today_2) { return FormatDate($format_value, $timestamp, $now); } } elseif($format_interval == "yesterday") { $arNow = localtime($now); //le = number of seconds scince midnight //$le = $arSDate[0]+$arSDate[1]*60+$arSDate[2]*3600; //yesterday_1 = truncate(now)-1 $yesterday_1 = mktime(0, 0, 0, $arNow[4]+1, $arNow[3]-1, $arNow[5]+1900); //yesterday_2 = truncate(now) $yesterday_2 = mktime(0, 0, 0, $arNow[4]+1, $arNow[3], $arNow[5]+1900); if($timestamp >= $yesterday_1 && $timestamp < $yesterday_2) return FormatDate($format_value, $timestamp, $now); } elseif($format_interval == "tommorow") { $arNow = localtime($now); $tommorow_1 = mktime(0, 0, 0, $arNow[4]+1, $arNow[3]+1, $arNow[5]+1900); $tommorow_2 = mktime(0, 0, 0, $arNow[4]+1, $arNow[3]+2, $arNow[5]+1900); if($timestamp >= $tommorow_1 && $timestamp < $tommorow_2) return FormatDate($format_value, $timestamp, $now); } elseif($format_interval == "-") { if($seconds_ago < 0) return FormatDate($format_value, $timestamp, $now); } } return FormatDate(array_pop($format), $timestamp, $now); } $bCutZeroTime = false; if (substr($format, 0, 1) == '^') { $bCutZeroTime = true; $format = substr($format, 1); } $arFormatParts = preg_split("/(sago|iago|isago|Hago|dago|mago|Yago|sdiff|idiff|Hdiff|ddiff|mdiff|Ydiff|yesterday|today|tommorow|X|x|F|f|Q|M|l|D)/", $format, 0, PREG_SPLIT_DELIM_CAPTURE); $result = ""; foreach($arFormatParts as $format_part) { switch($format_part) { case "": break; case "sago": $seconds_ago = intval($now - $timestamp); $result .= _FormatDateMessage($seconds_ago, array( "0" => "FD_SECOND_AGO_0", "1" => "FD_SECOND_AGO_1", "10_20" => "FD_SECOND_AGO_10_20", "MOD_1" => "FD_SECOND_AGO_MOD_1", "MOD_2_4" => "FD_SECOND_AGO_MOD_2_4", "MOD_OTHER" => "FD_SECOND_AGO_MOD_OTHER", )); break; case "sdiff": $seconds_ago = intval($now - $timestamp); $result .= _FormatDateMessage($seconds_ago, array( "0" => "FD_SECOND_DIFF_0", "1" => "FD_SECOND_DIFF_1", "10_20" => "FD_SECOND_DIFF_10_20", "MOD_1" => "FD_SECOND_DIFF_MOD_1", "MOD_2_4" => "FD_SECOND_DIFF_MOD_2_4", "MOD_OTHER" => "FD_SECOND_DIFF_MOD_OTHER", )); break; case "iago": $minutes_ago = intval(($now - $timestamp) / 60); $result .= _FormatDateMessage($minutes_ago, array( "0" => "FD_MINUTE_AGO_0", "1" => "FD_MINUTE_AGO_1", "10_20" => "FD_MINUTE_AGO_10_20", "MOD_1" => "FD_MINUTE_AGO_MOD_1", "MOD_2_4" => "FD_MINUTE_AGO_MOD_2_4", "MOD_OTHER" => "FD_MINUTE_AGO_MOD_OTHER", )); break; case "idiff": $minutes_ago = intval(($now - $timestamp) / 60); $result .= _FormatDateMessage($minutes_ago, array( "0" => "FD_MINUTE_DIFF_0", "1" => "FD_MINUTE_DIFF_1", "10_20" => "FD_MINUTE_DIFF_10_20", "MOD_1" => "FD_MINUTE_DIFF_MOD_1", "MOD_2_4" => "FD_MINUTE_DIFF_MOD_2_4", "MOD_OTHER" => "FD_MINUTE_DIFF_MOD_OTHER", )); break; case "isago": $minutes_ago = intval(($now - $timestamp) / 60); $result .= _FormatDateMessage($minutes_ago, array( "0" => "FD_MINUTE_0", "1" => "FD_MINUTE_1", "10_20" => "FD_MINUTE_10_20", "MOD_1" => "FD_MINUTE_MOD_1", "MOD_2_4" => "FD_MINUTE_MOD_2_4", "MOD_OTHER" => "FD_MINUTE_MOD_OTHER", )); $result .= " "; $seconds_ago = intval($now - $timestamp)-($minutes_ago*60); $result .= _FormatDateMessage($seconds_ago, array( "0" => "FD_SECOND_AGO_0", "1" => "FD_SECOND_AGO_1", "10_20" => "FD_SECOND_AGO_10_20", "MOD_1" => "FD_SECOND_AGO_MOD_1", "MOD_2_4" => "FD_SECOND_AGO_MOD_2_4", "MOD_OTHER" => "FD_SECOND_AGO_MOD_OTHER", )); break; case "Hago": $hours_ago = intval(($now - $timestamp) / 60 / 60); $result .= _FormatDateMessage($hours_ago, array( "0" => "FD_HOUR_AGO_0", "1" => "FD_HOUR_AGO_1", "10_20" => "FD_HOUR_AGO_10_20", "MOD_1" => "FD_HOUR_AGO_MOD_1", "MOD_2_4" => "FD_HOUR_AGO_MOD_2_4", "MOD_OTHER" => "FD_HOUR_AGO_MOD_OTHER", )); break; case "Hdiff": $hours_ago = intval(($now - $timestamp) / 60 / 60); $result .= _FormatDateMessage($hours_ago, array( "0" => "FD_HOUR_DIFF_0", "1" => "FD_HOUR_DIFF_1", "10_20" => "FD_HOUR_DIFF_10_20", "MOD_1" => "FD_HOUR_DIFF_MOD_1", "MOD_2_4" => "FD_HOUR_DIFF_MOD_2_4", "MOD_OTHER" => "FD_HOUR_DIFF_MOD_OTHER", )); break; case "yesterday": $result .= GetMessage("FD_YESTERDAY"); break; case "today": $result .= GetMessage("FD_TODAY"); break; case "tommorow": $result .= GetMessage("FD_TOMORROW"); break; case "dago": $days_ago = intval(($now - $timestamp) / 60 / 60 / 24); $result .= _FormatDateMessage($days_ago, array( "0" => "FD_DAY_AGO_0", "1" => "FD_DAY_AGO_1", "10_20" => "FD_DAY_AGO_10_20", "MOD_1" => "FD_DAY_AGO_MOD_1", "MOD_2_4" => "FD_DAY_AGO_MOD_2_4", "MOD_OTHER" => "FD_DAY_AGO_MOD_OTHER", )); break; case "ddiff": $days_ago = intval(($now - $timestamp) / 60 / 60 / 24); $result .= _FormatDateMessage($days_ago, array( "0" => "FD_DAY_DIFF_0", "1" => "FD_DAY_DIFF_1", "10_20" => "FD_DAY_DIFF_10_20", "MOD_1" => "FD_DAY_DIFF_MOD_1", "MOD_2_4" => "FD_DAY_DIFF_MOD_2_4", "MOD_OTHER" => "FD_DAY_DIFF_MOD_OTHER", )); break; case "mago": $months_ago = intval(($now - $timestamp) / 60 / 60 / 24 / 31); $result .= _FormatDateMessage($months_ago, array( "0" => "FD_MONTH_AGO_0", "1" => "FD_MONTH_AGO_1", "10_20" => "FD_MONTH_AGO_10_20", "MOD_1" => "FD_MONTH_AGO_MOD_1", "MOD_2_4" => "FD_MONTH_AGO_MOD_2_4", "MOD_OTHER" => "FD_MONTH_AGO_MOD_OTHER", )); break; case "mdiff": $months_ago = intval(($now - $timestamp) / 60 / 60 / 24 / 31); $result .= _FormatDateMessage($months_ago, array( "0" => "FD_MONTH_DIFF_0", "1" => "FD_MONTH_DIFF_1", "10_20" => "FD_MONTH_DIFF_10_20", "MOD_1" => "FD_MONTH_DIFF_MOD_1", "MOD_2_4" => "FD_MONTH_DIFF_MOD_2_4", "MOD_OTHER" => "FD_MONTH_DIFF_MOD_OTHER", )); break; case "Yago": $years_ago = intval(($now - $timestamp) / 60 / 60 / 24 / 365); $result .= _FormatDateMessage($years_ago, array( "0" => "FD_YEARS_AGO_0", "1" => "FD_YEARS_AGO_1", "10_20" => "FD_YEARS_AGO_10_20", "MOD_1" => "FD_YEARS_AGO_MOD_1", "MOD_2_4" => "FD_YEARS_AGO_MOD_2_4", "MOD_OTHER" => "FD_YEARS_AGO_MOD_OTHER", )); break; case "Ydiff": $years_ago = intval(($now - $timestamp) / 60 / 60 / 24 / 365); $result .= _FormatDateMessage($years_ago, array( "0" => "FD_YEARS_DIFF_0", "1" => "FD_YEARS_DIFF_1", "10_20" => "FD_YEARS_DIFF_10_20", "MOD_1" => "FD_YEARS_DIFF_MOD_1", "MOD_2_4" => "FD_YEARS_DIFF_MOD_2_4", "MOD_OTHER" => "FD_YEARS_DIFF_MOD_OTHER", )); break; case "F": if(LANGUAGE_ID == "en") $result .= date($format_part, $timestamp); else $result .= GetMessage("MONTH_".date("n", $timestamp)."_S"); break; case "f": if(LANGUAGE_ID == "en") $result .= date($format_part, $timestamp); else $result .= GetMessage("MONTH_".date("n", $timestamp)); break; case "M": if(LANGUAGE_ID == "en") $result .= date($format_part, $timestamp); else $result .= GetMessage("MON_".date("n", $timestamp)); break; case "l": if(LANGUAGE_ID == "en") $result .= date($format_part, $timestamp); else $result .= GetMessage("DAY_OF_WEEK_".date("w", $timestamp)); break; case "D": if(LANGUAGE_ID == "en") $result .= date($format_part, $timestamp); else $result .= GetMessage("DOW_".date("w", $timestamp)); break; case "x": $formats = array(); $formats["tommorow"] = "tommorow, ".(IsAmPmMode() ? "g:i a" : "H:i"); $formats["-"] = preg_replace('/:s$/', '', $DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))); $formats["s"] = "sago"; $formats["i"] = "iago"; $formats["today"] = "today, ".(IsAmPmMode() ? "g:i a" : "H:i"); $formats["yesterday"] = "yesterday, ".(IsAmPmMode() ? "g:i a" : "H:i"); $formats[""] = preg_replace('/:s$/', '', $DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))); $result .= FormatDate($formats, $timestamp, $now); break; case "X": $day = FormatDate(array( "tommorow" => "tommorow", "-" => $DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), "today" => "today", "yesterday" => "yesterday", "" => $DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")), ), $timestamp, $now); $formats = array(); $formats["tommorow"] = IsAmPmMode() ? "g:i a" : "H:i"; $formats["today"] = IsAmPmMode() ? "g:i a" : "H:i"; $formats["yesterday"] = IsAmPmMode() ? "g:i a" : "H:i"; $formats[""] = ""; $time = FormatDate($formats, $timestamp, $now); if(strlen($time)) $result .= GetMessage("FD_DAY_AT_TIME", array("#DAY#" => $day, "#TIME#" => $time)); else $result .= $day; break; case "Q": $days_ago = intval(($now - $timestamp) / 60 / 60 / 24); if($days_ago == 0) $result .= GetMessage("FD_DAY_DIFF_1", array("#VALUE#" => 1)); else $result .= FormatDate(array( "d" => "ddiff", "m" => "mdiff", "" => "Ydiff", ), $timestamp, $now); break; default: $result .= date($format_part, $timestamp); break; } } if ($bCutZeroTime) $result = preg_replace( array("/\\s*00:00:00\\s*/", "/(\\d\\d:\\d\\d)(:00)/", "/(\\s*00:00\\s*)(?!:)/"), array("", "\\1", ""), $result ); return $result; }
$arChildren[$k] = $tmp; } } if (!empty($arChildren)) { $versions = array("0" => "WD_VERSIONS_0", "1" => "WD_VERSIONS_1", "10_20" => "WD_VERSIONS_10_20", "MOD_1" => "WD_VERSIONS_MOD_1", "MOD_2_4" => "WD_VERSIONS_MOD_2_4", "MOD_OTHER" => "WD_VERSIONS_MOD_OTHER"); $arVerLines = array(); foreach ($arChildren as $k => $tmp) { $arVerLines[] = '{text : \'' . $tmp . '\', title : \'\', className : "wd-version-popup", href : "" }'; } $aCols["NAME"] .= ' <script type="text/javascript"> if(!window.versionPopup){var versionPopup = {};} versionPopup["' . $res["ID"] . '"] = [ ' . implode(",\n", $arVerLines) . ' ]; </script> '; $aCols["NAME"] .= "<div class=\"wd-bp-versions\" id=\"wd_versions_" . $res["ID"] . "\">(<span onclick='return WDShowVersionsPopup(" . $res["ID"] . ", this);'>" . GetMessage("WD_VERSIONS_COUNT", array('#NUM#' => count($arChildren), '#VERSIONS#' => _FormatDateMessage(count($arChildren), $versions))) . "</span>)</div>"; } else { unset($arActions["element_versions"]); } } $editable = $res["TYPE"] == "S" && sizeof($arActions) > 1 || $res["TYPE"] == "E" && ($res["SHOW"]["EDIT"] === "Y" || $res["SHOW"]["DELETE"] === "Y"); $res["BASE_URL_FOR_EXT_LINK"] = $arParams["OBJECT"]->base_url; $res["URL_FOR_EXT_LINK"] = $res["PATH"]; $arIconHash[] = md5($res["BASE_URL_FOR_EXT_LINK"] . $res["URL_FOR_EXT_LINK"]); $arResult["GRID_DATA"][] = array("id" => $res["TYPE"] . $res["ID"], "data" => $res, "actions" => array_values($arActions), "columns" => $aCols, "editable" => $editable); /************** Grid Data/******************************************/ } unset($dataNavResults, $selfSharedSections, $res); if (!empty($arResult['preview'])) { CJSCore::Init(array('viewer')); }