예제 #1
0
파일: component.php 프로젝트: ASDAFF/mp
function getComments($PARENT_ID, $DEPTH_LEVEL, &$comments, &$left_margin, $date_format, $userlink, $commentLink, $max_depth_level, $asName, &$arIDs, $templateFolder, $canModify)
{
  $arFilter = array("OBJECT_ID_NUMBER" => OBJECT_ID, "PARENT_ID" => $PARENT_ID);
	$res = CTreelikeComments::GetList(array("ID" => "DESC"), $arFilter);

	while ($ob = $res->GetNext())
	{
		if ($ob['USER_ID'] != NULL)
		{
			$link = $userlink;

			if (preg_match('/USER_LOGIN/i', $link))
			{
				$userlogin_before = "#USER_LOGIN#";
				$userlogin_after = $ob['LOGIN'];

				$link = str_replace($userlogin_before, $userlogin_after, $link);
			}
			if (preg_match('/USER_ID/i', $link))
			{
				$id_before = "#USER_ID#";
				$id_after = $ob['USER_ID'];

				$link = str_replace($id_before, $id_after, $link);
			}
			if (preg_match('/PERSONAL_WWW/i', $link))
			{
				$id_before = "#PERSONAL_WWW#";
				$id_after = "";
				$arFilter = array(
					"ID" => $ob['USER_ID']
				);
				$arSelectParams = array(
					"FIELDS" => array(
						"ID", "PERSONAL_WWW"
					)
				);
				$rsUser = CUser::GetList($by = "ID", $order = "DESC", $arFilter, $arSelectParams);
				if ($arUser = $rsUser->Fetch())
				{
					$id_after = $arUser['PERSONAL_WWW'];
				}

				$link = str_replace($id_before, $id_after, $link);
			}
		}

		$user = array(
			"ID" => $ob['USER_ID'],
			"LOGIN" => $ob['LOGIN'],
			"NAME" => $ob['NAME'],
			"LAST_NAME" => $ob['LAST_NAME'],
			"PERSONAL_PHOTO" => CFile::GetPath($ob['PERSONAL_PHOTO']),
			"USERLINK" => $link
		);

		switch ($asName)
		{
			case "name_lastname":
				if ($user['NAME'] != "" && $user['LAST_NAME'] != "")
					$user['LOGIN'] = $user['NAME'] . " " . $user['LAST_NAME'];
				break;

			case "name":
				if ($user['NAME'] != "")
					$user['LOGIN'] = $user['NAME'];
				break;
		}

		if ($DEPTH_LEVEL > $max_depth_level - 1)
			$DEPTH_LEVEL = $max_depth_level - 1;

		if ($commentLink == "Y")
			$cLink = "comment_" . $ob["ID"];
		else
			$cLink = "N";

		$arIDs[] = $ob['ID'];

		// add modification date
		$commentText = $ob['~COMMENT'];
		$commentModify = "";

		if (!empty($ob['DATE_MODIFY']) && $canModify == "Y")
		{
			$commentModify = GetMessage('CHANGE_COMMENT_MSG');
			$commentDateTime = explode(" ", $ob['DATE_MODIFY']);
			$commentModify = str_replace("#DATE#", $commentDateTime[0], $commentModify);
			$commentModify = str_replace("#TIME#", $commentDateTime[1], $commentModify);
		}

		// if user is author add modification link
		$canEdit = "N";
		if (!empty($ob['USER_ID']) && $ob['USER_ID'] == CUser::GetID() && $canModify == "Y")
		{
			$canEdit = "Y";
		}

		$commentHiddenContent = TreelikeCommentsGetSmiles($ob['~COMMENT'],
			array(
				":)" => "smile.png",
				":D" => "xd.png",
				":(" => "sad.png",
				"x_x" => "x_x.png",
				"0_0" => "0_0.png",
			),
			array("FOLDER" => $templateFolder)
		);
		$commentHiddenContent = CTreelikeComments::ParseTextBack($commentHiddenContent);
		$commentHiddenContent = strip_tags($commentHiddenContent);


		$comments[$ob['ID']] = array(
			"ID" => $ob['ID'],
			"DEPTH_LEVEL" => $DEPTH_LEVEL,
			"PARENT_ID" => $ob['PARENT_ID'],
			"LEFT_MARGIN" => $DEPTH_LEVEL * $left_margin,
			"USER" => $user,
			"COMMENT_LINK" => $cLink,
			"COMMENT" => $commentText,
			"AUTHOR_NAME" => $ob['AUTHOR_NAME'],
			"DATE_CREATE" => FormatDate($date_format, strtotime($ob['NEW_DATE'])),
			"ACTIVATED" => $ob['ACTIVATED'],
			"VoteUp" => 0,
			"VoteDown" => 0,
			"TOTAL_VOTE" => 0,
			"COMMENT_HIDDEN_CONTENT" => $commentHiddenContent,
			"MODIFY_STRING" => $commentModify,
			"DATE_MODIFY" => $ob['DATE_MODIFY'],
			"CAN_EDIT" => $canEdit
		);

		getComments($ob['ID'], $DEPTH_LEVEL + 1, $comments, $left_margin, $date_format, $userlink, $commentLink, $max_depth_level, $asName, $arIDs, $templateFolder, $canModify);
	}

}