PageRenderTime 23ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/forum/tools/components_lib.php

https://gitlab.com/alexprowars/bitrix
PHP | 417 lines | 341 code | 29 blank | 47 comment | 40 complexity | 1b47e48dda8810d4cb8bfa57f4500cc7 MD5 | raw file
  1. <?
  2. IncludeModuleLangFile(__FILE__);
  3. class CForumParameters
  4. {
  5. public static function GetDateTimeFormat($name="", $parent="")
  6. {
  7. $timestamp = mktime(7,30,45,2,22,2007);
  8. return array(
  9. "PARENT" => $parent,
  10. "NAME" => $name,
  11. "TYPE" => "LIST",
  12. "VALUES" => array(
  13. "d-m-Y H:i:s" => CForumFormat::DateFormat("d-m-Y H:i:s", $timestamp),//"22-02-2007 7:30",
  14. "m-d-Y H:i:s" => CForumFormat::DateFormat("m-d-Y H:i:s", $timestamp),//"02-22-2007 7:30",
  15. "Y-m-d H:i:s" => CForumFormat::DateFormat("Y-m-d H:i:s", $timestamp),//"2007-02-22 7:30",
  16. "d.m.Y H:i:s" => CForumFormat::DateFormat("d.m.Y H:i:s", $timestamp),//"22.02.2007 7:30",
  17. "m.d.Y H:i:s" => CForumFormat::DateFormat("m.d.Y H:i:s", $timestamp),//"02.22.2007 7:30",
  18. "j M Y H:i:s" => CForumFormat::DateFormat("j M Y H:i:s", $timestamp),//"22 Feb 2007 7:30",
  19. "M j, Y H:i:s" => CForumFormat::DateFormat("M j, Y H:i:s", $timestamp),//"Feb 22, 2007 7:30",
  20. "j F Y H:i:s" => CForumFormat::DateFormat("j F Y H:i:s", $timestamp),//"22 February 2007 7:30",
  21. "F j, Y H:i:s" => CForumFormat::DateFormat("F j, Y H:i:s", $timestamp),//"February 22, 2007",
  22. "d.m.y g:i A" => CForumFormat::DateFormat("d.m.y g:i A", $timestamp),//"22.02.07 1:30 PM",
  23. "d.m.y G:i" => CForumFormat::DateFormat("d.m.y G:i", $timestamp),//"22.02.07 7:30",
  24. "d.m.Y H:i:s" => CForumFormat::DateFormat("d.m.Y H:i:s", $timestamp),//"22.02.2007 07:30",
  25. ),
  26. "DEFAULT" => $GLOBALS["DB"]->DateFormatToPHP(CSite::GetDateFormat("FULL")),
  27. "ADDITIONAL_VALUES" => "Y",
  28. );
  29. }
  30. public static function GetDateFormat($name="", $parent="")
  31. {
  32. $timestamp = mktime(7,30,45,2,22,2007);
  33. return array(
  34. "PARENT" => $parent,
  35. "NAME" => $name,
  36. "TYPE" => "LIST",
  37. "VALUES" => array(
  38. "d-m-Y" => CForumFormat::DateFormat("d-m-Y", $timestamp),//"22-02-2007 7:30",
  39. "m-d-Y" => CForumFormat::DateFormat("m-d-Y", $timestamp),//"02-22-2007 7:30",
  40. "Y-m-d" => CForumFormat::DateFormat("Y-m-d", $timestamp),//"2007-02-22 7:30",
  41. "d.m.Y" => CForumFormat::DateFormat("d.m.Y", $timestamp),//"22.02.2007 7:30",
  42. "m.d.Y" => CForumFormat::DateFormat("m.d.Y", $timestamp),//"02.22.2007 7:30",
  43. "j M Y" => CForumFormat::DateFormat("j M Y", $timestamp),//"22 Feb 2007 7:30",
  44. "M j, Y" => CForumFormat::DateFormat("M j, Y", $timestamp),//"Feb 22, 2007 7:30",
  45. "j F Y" => CForumFormat::DateFormat("j F Y", $timestamp),//"22 February 2007 7:30",
  46. "F j, Y" => CForumFormat::DateFormat("F j, Y", $timestamp),//"February 22, 2007",
  47. "d.m.y" => CForumFormat::DateFormat("d.m.y", $timestamp),//"22.02.07 1:30 PM",
  48. ),
  49. "DEFAULT" => $GLOBALS["DB"]->DateFormatToPHP(CSite::GetDateFormat("SHORT")),
  50. "ADDITIONAL_VALUES" => "Y",
  51. );
  52. }
  53. public static function GetForumsMultiSelect($name="", $parent="")
  54. {
  55. return array(
  56. "PARENT" => $parent,
  57. "NAME" => $name,
  58. "TYPE" => "LIST",
  59. "MULTIPLE" => "Y",
  60. "VALUES" => CForumParameters::GetForumsList(),
  61. "DEFAULT" => "",
  62. );
  63. }
  64. public static function GetForumsList()
  65. {
  66. $arGroup = array();
  67. $arForum = array();
  68. $db_res = CForumGroup::GetListEx(array(), array("LID" => LANG));
  69. if ($db_res && ($res = $db_res->GetNext()))
  70. {
  71. do
  72. {
  73. $arGroup[intval($res["ID"])] = $res["~NAME"];
  74. }while ($res = $db_res->GetNext());
  75. }
  76. $db_res = CForumNew::GetListEx(array("FORUM_GROUP_SORT"=>"ASC", "FORUM_GROUP_ID"=>"ASC", "SORT"=>"ASC", "NAME"=>"ASC"), array());
  77. if ($db_res && ($res = $db_res->GetNext()))
  78. {
  79. do
  80. {
  81. $arForum[intval($res["ID"])] = $res["~NAME"];
  82. if ((intval($res["FORUM_GROUP_ID"]) > 0) && array_key_exists($res["FORUM_GROUP_ID"], $arGroup))
  83. {
  84. $arForum[intval($res["ID"])] .= " [".$arGroup[$res["FORUM_GROUP_ID"]]."]";
  85. }
  86. if ($res["ACTIVE"] != "Y")
  87. {
  88. $arForum[intval($res["ID"])] .= " N/A";
  89. }
  90. }while ($res = $db_res->GetNext());
  91. }
  92. return $arForum;
  93. }
  94. public static function GetSendMessageRights($name="", $parent="", $default = "A", $object = "MAIL")
  95. {
  96. if ($object == "ICQ")
  97. {
  98. if ((COption::GetOptionString("forum", "SHOW_ICQ_CONTACT", "N") != "Y")):
  99. return array(
  100. "PARENT" => $parent,
  101. "NAME" => $name,
  102. "TYPE" => "LIST",
  103. "VALUES" => array(
  104. "A" => GetMessage("FORUM_NO_ONE")
  105. ),
  106. "DEFAULT" => "A"
  107. );
  108. else:
  109. return array(
  110. "PARENT" => $parent,
  111. "NAME" => $name,
  112. "TYPE" => "LIST",
  113. "VALUES" => array(
  114. "A" => GetMessage("FORUM_NO_ONE"),
  115. "E" => GetMessage("FORUM_AUTHORIZED_USERS"),
  116. "Y" => GetMessage("FORUM_ALL"),
  117. ),
  118. "DEFAULT" => $default
  119. );
  120. endif;
  121. }
  122. return array(
  123. "PARENT" => $parent,
  124. "NAME" => $name,
  125. "TYPE" => "LIST",
  126. "VALUES" => array(
  127. "A" => GetMessage("FORUM_NO_ONE"),
  128. "E" => GetMessage("FORUM_AUTHORIZED_USERS"),
  129. "U" => GetMessage("FORUM_ALL_WITH_CAPTCHA"),
  130. "Y" => GetMessage("FORUM_ALL"),
  131. ),
  132. "DEFAULT" => $default
  133. );
  134. }
  135. public static function GetSetNavigation($name="", $parent="")
  136. {
  137. return array(
  138. "PARENT" => $parent,
  139. "NAME" => $name,
  140. "TYPE" => "CHECKBOX",
  141. "MULTIPLE" => "N",
  142. "DEFAULT" => "Y"
  143. );
  144. }
  145. public static function GetWordLength($name="", $parent="ADDITIONAL_SETTINGS")
  146. {
  147. if (empty($name))
  148. $name = GetMessage("F_WORD_LENGTH");
  149. return array(
  150. "PARENT" => $parent,
  151. "NAME" => $name,
  152. "TYPE" => "STRING",
  153. "DEFAULT" => "50"
  154. );
  155. }
  156. public static function GetWordWrapCut($name="", $parent="ADDITIONAL_SETTINGS")
  157. {
  158. if (empty($name))
  159. $name = GetMessage("F_WORD_WRAP_CUT");
  160. return array(
  161. "PARENT" => $parent,
  162. "NAME" => $name,
  163. "TYPE" => "LIST",
  164. "MULTIPLE" => "N",
  165. "VALUES" => array(
  166. "0" => GetMessage("F_WORD_WRAP"),
  167. "23" => GetMessage("F_WORD_CUT")." (23)",
  168. ),
  169. "DEFAULT" => "23",
  170. "ADDITIONAL_VALUES" => "Y",
  171. );
  172. }
  173. public static function GetAjaxType($name="", $parent="ADDITIONAL_SETTINGS")
  174. {
  175. if (empty($name))
  176. $name = GetMessage("F_AJAX_TYPE");
  177. return array(
  178. "PARENT" => $parent,
  179. "NAME" => $name,
  180. "TYPE" => "CHECKBOX",
  181. "DEFAULT" => "Y");
  182. }
  183. public static function AddPagerSettings(&$arComponentParameters, $sTitle = "", $arParams = array(
  184. // "bAddGroupOnly" => false,
  185. // "bDescNumbering" => true
  186. ))
  187. {
  188. $arParams = (!is_array($arParams) ? array($arParams) : $arParams);
  189. $arParamsDefault = array(
  190. "bAddGroupOnly" => false,
  191. "bDescNumbering" => true);
  192. foreach ($arParamsDefault as $key => $val)
  193. $arParams[$key] = ((is_set($arParams, $key) ? $arParams[$key]: $arParamsDefault[$key]) == true);
  194. $arComponentParameters["GROUPS"]["PAGER_SETTINGS"] = array(
  195. "NAME" => GetMessage("FORUM_PAGER_SETTINGS"));
  196. if (!$arParams["bAddGroupOnly"])
  197. {
  198. if ($arParams["bDescNumbering"])
  199. {
  200. $arComponentParameters["PARAMETERS"]["PAGER_DESC_NUMBERING"] = Array(
  201. "PARENT" => "PAGER_SETTINGS",
  202. "NAME" => GetMessage("FORUM_PAGER_DESC_NUMBERING"),
  203. "TYPE" => "CHECKBOX",
  204. "DEFAULT" => "Y");
  205. }
  206. $arComponentParameters["PARAMETERS"]["PAGER_SHOW_ALWAYS"] = Array(
  207. "PARENT" => "PAGER_SETTINGS",
  208. "NAME" => GetMessage("FORUM_PAGER_SHOW_ALWAYS"),
  209. "TYPE" => "CHECKBOX",
  210. "DEFAULT" => "N");
  211. $arComponentParameters["PARAMETERS"]["PAGER_TITLE"] = Array(
  212. "PARENT" => "PAGER_SETTINGS",
  213. "NAME" => GetMessage("FORUM_PAGER_TITLE"),
  214. "TYPE" => "STRING",
  215. "DEFAULT" => $sTitle);
  216. $arComponentParameters["PARAMETERS"]["PAGER_TEMPLATE"] = Array(
  217. "PARENT" => "PAGER_SETTINGS",
  218. "NAME" => GetMessage("FORUM_PAGER_TEMPLATE"),
  219. "TYPE" => "STRING",
  220. "DEFAULT" => "");
  221. }
  222. }
  223. }
  224. class CForumFormat
  225. {
  226. public static function DateFormat($format="", $timestamp="")
  227. {
  228. global $DB;
  229. switch($format)
  230. {
  231. case "SHORT":
  232. return FormatDate($DB->dateFormatToPHP(FORMAT_DATE), $timestamp);
  233. case "FULL":
  234. return FormatDate($DB->dateFormatToPHP(FORMAT_DATETIME), $timestamp);
  235. default:
  236. return FormatDate($format, $timestamp);
  237. }
  238. }
  239. public static function FormatDate($strDate, $format="DD.MM.YYYY HH:MI:SS", $new_format="DD.MM.YYYY HH:MI:SS")
  240. {
  241. global $DB;
  242. $strDate = trim($strDate);
  243. $new_format = str_replace("MI","I", $new_format);
  244. $new_format = preg_replace("/([DMYIHS])\\1+/is".BX_UTF_PCRE_MODIFIER, "\\1", $new_format);
  245. $arFormat = preg_split("/[^0-9a-z]/is", mb_strtoupper($format));
  246. $arDate = preg_split("/[^0-9]/", $strDate);
  247. $arParsedDate=Array();
  248. $bound = min(count($arFormat), count($arDate));
  249. for($i=0; $i<$bound; $i++)
  250. {
  251. //if ($intval) $r = IntVal($arDate[$i]); else
  252. if (preg_match("/^[0-9]/", $arDate[$i]))
  253. $r = $DB->ForSql($arDate[$i], 4);
  254. else
  255. $r = intval($arDate[$i]);
  256. $arParsedDate[mb_substr($arFormat[$i], 0, 2)] = $r;
  257. }
  258. if (intval($arParsedDate["DD"])<=0 || intval($arParsedDate["MM"])<=0 || intval($arParsedDate["YY"])<=0)
  259. return false;
  260. $strResult = "";
  261. if(intval($arParsedDate["YY"])>1970 && intval($arParsedDate["YY"])<2038)
  262. {
  263. $ux_time = mktime(
  264. intval($arParsedDate["HH"]),
  265. intval($arParsedDate["MI"]),
  266. intval($arParsedDate["SS"]),
  267. intval($arParsedDate["MM"]),
  268. intval($arParsedDate["DD"]),
  269. intval($arParsedDate["YY"])
  270. );
  271. for ($i=0; $i < mb_strlen($new_format); $i++)
  272. {
  273. $simbol = mb_substr($new_format, $i, 1);
  274. switch ($simbol)
  275. {
  276. case "F":$match=GetMessage("FORUM_MONTH_".date("n", $ux_time));break;
  277. case "M":$match=GetMessage("FORUM_MON_".date("n", $ux_time));break;
  278. case "l":$match=GetMessage("FORUM_DAY_OF_WEEK_".date("w", $ux_time));break;
  279. case "D":$match=GetMessage("FORUM_DOW_".date("w", $ux_time));break;
  280. default: $match = date(mb_substr($new_format, $i, 1), $ux_time); break;
  281. }
  282. $strResult .= $match;
  283. }
  284. }
  285. else
  286. {
  287. if($arParsedDate["MM"]<1 || $arParsedDate["MM"]>12)
  288. $arParsedDate["MM"] = 1;
  289. for ($i=0; $i < mb_strlen($new_format); $i++)
  290. {
  291. $simbol = mb_substr($new_format, $i, 1);
  292. switch ($simbol)
  293. {
  294. case "F":
  295. $match = str_pad($arParsedDate["MM"], 2, "0", STR_PAD_LEFT);
  296. if (intval($arParsedDate["MM"]) > 0)
  297. $match=GetMessage("FORUM_MONTH_".intval($arParsedDate["MM"]));
  298. break;
  299. case "M":
  300. $match = str_pad($arParsedDate["MM"], 2, "0", STR_PAD_LEFT);
  301. if (intval($arParsedDate["MM"]) > 0)
  302. $match=GetMessage("FORUM_MON_".intval($arParsedDate["MM"]));
  303. break;
  304. case "l":
  305. $match = str_pad($arParsedDate["DD"], 2, "0", STR_PAD_LEFT);
  306. if (intval($arParsedDate["DD"]) > 0)
  307. $match = GetMessage("FORUM_DAY_OF_WEEK_".intval($arParsedDate["DD"]));
  308. break;
  309. case "D":
  310. $match = str_pad($arParsedDate["DD"], 2, "0", STR_PAD_LEFT);
  311. if (intval($arParsedDate["DD"]) > 0)
  312. $match = GetMessage("FORUM_DOW_".intval($arParsedDate["DD"]));
  313. break;
  314. case "d": $match = str_pad($arParsedDate["DD"], 2, "0", STR_PAD_LEFT); break;
  315. case "m": $match = str_pad($arParsedDate["MM"], 2, "0", STR_PAD_LEFT); break;
  316. case "j": $match = str_pad($arParsedDate["DD"], 2, "0", STR_PAD_LEFT); break;
  317. case "Y": $match = str_pad($arParsedDate["YY"], 4, "0", STR_PAD_LEFT); break;
  318. case "y":
  319. $match = mb_substr($arParsedDate["YY"], 2);break;
  320. case "H": $match = str_pad($arParsedDate["HH"], 2, "0", STR_PAD_LEFT); break;
  321. case "i": $match = str_pad($arParsedDate["MI"], 2, "0", STR_PAD_LEFT); break;
  322. case "S": $match = str_pad($arParsedDate["SS"], 2, "0", STR_PAD_LEFT); break;
  323. case "g":
  324. $match = intval($arParsedDate["HH"]);
  325. if ($match > 12)
  326. $match = $match-12;
  327. case "a":
  328. case "A":
  329. $match = intval($arParsedDate["HH"]);
  330. if ($match > 12)
  331. $match = ($match-12)." PM";
  332. else
  333. $match .= " AM";
  334. if (mb_substr($new_format, $i, 1) == "a")
  335. $match = mb_strtolower($match);
  336. default:
  337. $match = mb_substr($new_format, $i, 1); break;
  338. }
  339. $strResult .= $match;
  340. }
  341. }
  342. return $strResult;
  343. }
  344. }
  345. /*
  346. GetMessage("FORUM_BOTTOM_PAGER");
  347. GetMessage("FORUM_DAY_OF_WEEK_0");
  348. GetMessage("FORUM_DAY_OF_WEEK_1");
  349. GetMessage("FORUM_DAY_OF_WEEK_2");
  350. GetMessage("FORUM_DAY_OF_WEEK_3");
  351. GetMessage("FORUM_DAY_OF_WEEK_4");
  352. GetMessage("FORUM_DAY_OF_WEEK_5");
  353. GetMessage("FORUM_DAY_OF_WEEK_6");
  354. GetMessage("FORUM_DOW_0");
  355. GetMessage("FORUM_DOW_1");
  356. GetMessage("FORUM_DOW_2");
  357. GetMessage("FORUM_DOW_3");
  358. GetMessage("FORUM_DOW_4");
  359. GetMessage("FORUM_DOW_5");
  360. GetMessage("FORUM_DOW_6");
  361. GetMessage("FORUM_MONTH_1");
  362. GetMessage("FORUM_MONTH_10");
  363. GetMessage("FORUM_MONTH_11");
  364. GetMessage("FORUM_MONTH_12");
  365. GetMessage("FORUM_MONTH_2");
  366. GetMessage("FORUM_MONTH_3");
  367. GetMessage("FORUM_MONTH_4");
  368. GetMessage("FORUM_MONTH_5");
  369. GetMessage("FORUM_MONTH_6");
  370. GetMessage("FORUM_MONTH_7");
  371. GetMessage("FORUM_MONTH_8");
  372. GetMessage("FORUM_MONTH_9");
  373. GetMessage("FORUM_MON_1");
  374. GetMessage("FORUM_MON_10");
  375. GetMessage("FORUM_MON_11");
  376. GetMessage("FORUM_MON_12");
  377. GetMessage("FORUM_MON_2");
  378. GetMessage("FORUM_MON_3");
  379. GetMessage("FORUM_MON_4");
  380. GetMessage("FORUM_MON_5");
  381. GetMessage("FORUM_MON_6");
  382. GetMessage("FORUM_MON_7");
  383. GetMessage("FORUM_MON_8");
  384. GetMessage("FORUM_MON_9");
  385. GetMessage("FORUM_NAVIGATION");
  386. GetMessage("FORUM_TOP_PAGER");
  387. */